mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2026-10-06 03:28:05 +00:00
recoonect peers from different torrents after random intervals
This commit is contained in:
@@ -344,7 +344,7 @@ namespace torrents
|
||||
|
||||
Torrent::Torrent ():
|
||||
m_Length (0), m_PieceLength (0), m_IsComplete (false), m_IsStopped (false),
|
||||
m_Uploaded (0), m_Downloaded (0), m_NextUpdateStatusTime (0)
|
||||
m_Uploaded (0), m_Downloaded (0), m_NextUpdateStatusTime (0), m_NextReconnectTime (0)
|
||||
{
|
||||
ResetStats ();
|
||||
}
|
||||
|
||||
@@ -220,6 +220,8 @@ namespace torrents
|
||||
bool UpdateStatus (uint64_t ts); // return true if complete
|
||||
uint64_t GetNextUpdateStatusTime () { return m_NextUpdateStatusTime; }
|
||||
void SetNextUpdateStatusTime (uint64_t nextUpdateStatusTime) { m_NextUpdateStatusTime = nextUpdateStatusTime; }
|
||||
uint64_t GetNextReconnectTime () { return m_NextReconnectTime; }
|
||||
void SetNextReconnectTime (uint64_t nextReconnectTime) { m_NextReconnectTime = nextReconnectTime; }
|
||||
bool AddConnection (std::shared_ptr<PeerConnection> conn);
|
||||
void RemoveConnection (std::shared_ptr<PeerConnection> conn);
|
||||
std::list<std::shared_ptr<PeerConnection> > GetConnections ();
|
||||
@@ -277,7 +279,7 @@ namespace torrents
|
||||
bool m_IsComplete, m_IsStopped;
|
||||
std::list<std::pair<std::filesystem::path, size_t> > m_Files; // list of (path, length)
|
||||
size_t m_Uploaded, m_Downloaded;
|
||||
uint64_t m_NextUpdateStatusTime; // in monotonic seconds
|
||||
uint64_t m_NextUpdateStatusTime, m_NextReconnectTime; // in monotonic seconds
|
||||
// stats
|
||||
uint64_t m_DownloadRate, m_UploadRate; // B/sec
|
||||
int m_NumDownloadingFromPeers, m_NumUploadingToPeers; // by us
|
||||
|
||||
@@ -801,15 +801,19 @@ namespace torrents
|
||||
{
|
||||
if (ecode != boost::asio::error::operation_aborted)
|
||||
{
|
||||
auto ts = i2p::util::GetMonotonicSeconds ();
|
||||
for (auto it: m_Torrents)
|
||||
{
|
||||
if (!it.second->IsComplete () && !it.second->IsStopped ())
|
||||
if (ts > it.second->GetNextReconnectTime ())
|
||||
{
|
||||
auto numPeers = ConnectToPeers (it.second);
|
||||
if (numPeers)
|
||||
LogPrint (eLogDebug, "TorrentsTunnel: Reconnecting to ", numPeers, " peers");
|
||||
if (!it.second->IsComplete () && !it.second->IsStopped ())
|
||||
{
|
||||
auto numPeers = ConnectToPeers (it.second);
|
||||
if (numPeers)
|
||||
LogPrint (eLogDebug, "TorrentsTunnel: Reconnecting to ", numPeers, " peers");
|
||||
}
|
||||
it.second->SetNextReconnectTime (ts + RECONNECT_INTERVAL + GetLocalDestination ()->GetRng ()() % RECONNECT_INTERVAL_VARIANCE);
|
||||
}
|
||||
}
|
||||
|
||||
ScheduleReconnectCheck ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,9 @@ namespace torrents
|
||||
constexpr int DATAGRAM_TRACKER_TRANSACTION_TIMEOUT = 10000; // in milliseconds
|
||||
constexpr int DATAGRAM_TRACKER_CONNECTION_EXPIRATION = 60000; // in milliseconds
|
||||
constexpr int TRACKER_REQUESTS_CHECK_TIMEOUT = 1900; // in milliseconds
|
||||
constexpr int RECONNECT_CHECK_INTERVAL = 70; // in seconds
|
||||
constexpr int RECONNECT_INTERVAL = 45; // in seconds
|
||||
constexpr int RECONNECT_INTERVAL_VARIANCE = 30; // in seconds
|
||||
constexpr int RECONNECT_CHECK_INTERVAL = 30; // in seconds
|
||||
constexpr int TRACKER_REQUESTS_INTERVAL_VARIANCE = 3000; // in milliseconds
|
||||
constexpr int TRACKER_INITIAL_REQUEST_INTERVAL_VARIANCE = 31000; // in milliseconds
|
||||
constexpr int PEER_KEEP_ALIVE_CHECK_INTERVAL = 15; // in seconds
|
||||
|
||||
Reference in New Issue
Block a user