@@ -54,6 +54,8 @@ static SessionThreadGroup arraySessions;
54
54
static std::shared_ptr<std::thread> pDHTTorrentThread;
55
55
static std::shared_ptr<boost::thread> pReannounceThread = nullptr ;
56
56
static std::map<HashRecordKey, uint32_t > mPutCommands ;
57
+ // <InfoHash , pair<seq , epoch>
58
+ static std::map<std::string, std::pair<int64_t , int64_t >> mReannouceInfoHashes ;
57
59
static uint64_t nPutRecords = 0 ;
58
60
static uint64_t nPutPieces = 0 ;
59
61
static uint64_t nPutBytes = 0 ;
@@ -220,12 +222,30 @@ void ReannounceEntries()
220
222
if (InitMemoryMap ()) {
221
223
try {
222
224
while (fReannounceStarted ) {
225
+ // cleanup mReannouceInfoHashes map, make sure it doesn't get too big.
223
226
MilliSleep (nReannouceSleepMilliSleep);
224
227
boost::this_thread::interruption_point ();
225
228
CMutableData randomMutableItem;
226
229
// select one local item at random.
227
230
if (SelectRandomMutableItem (randomMutableItem)) {
228
231
// Check if already re-annouced item
232
+ int64_t nCurrentTime = GetTime ();
233
+ std::map<std::string, std::pair<int64_t , int64_t >>::iterator it = mReannouceInfoHashes .find (randomMutableItem.InfoHash ());
234
+ if (it == mReannouceInfoHashes .end ()) {
235
+ mReannouceInfoHashes [randomMutableItem.InfoHash ()] = std::make_pair (randomMutableItem.SequenceNumber , nCurrentTime);
236
+ } else {
237
+ // check if we have a higher sequence number
238
+ if (randomMutableItem.SequenceNumber > it->second .first ) {
239
+ mReannouceInfoHashes [randomMutableItem.InfoHash ()] = std::make_pair (randomMutableItem.SequenceNumber , nCurrentTime);
240
+ // check if we re-annouced over an hour ago
241
+ } else if (nCurrentTime - it->second .second > (60 * 60 )) {
242
+ mReannouceInfoHashes [randomMutableItem.InfoHash ()] = std::make_pair (randomMutableItem.SequenceNumber , nCurrentTime);
243
+ } else {
244
+ // already re-annouced entry within the hour with the same sequence number. Do not re-annouce entry.
245
+ continue ;
246
+ }
247
+ }
248
+ // TODO: Remove debug.log printing below.
229
249
// Check if fewer than 8 nodes returned the item with the most recent sequence number
230
250
LogPrintf (" %s -- Re-annoucing item %s\n " , __func__, randomMutableItem.ToString ());
231
251
libtorrent::dht::item mut_item;
0 commit comments