]> Git Repo - VerusCoin.git/commitdiff
Prevent duplicate headers
authorjl777 <[email protected]>
Mon, 18 Sep 2017 14:57:31 +0000 (16:57 +0200)
committerjl777 <[email protected]>
Mon, 18 Sep 2017 14:57:31 +0000 (16:57 +0200)
src/main.cpp
src/net.h

index bc0ff9dfad5b9dff7e545c52df9cf4fa9cab2999..57e69289302b03540c3c6b4950de21e9ad9f6ca3 100644 (file)
@@ -4964,14 +4964,18 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
         vector<CBlock> vHeaders;
         int nLimit = MAX_HEADERS_RESULTS;
         LogPrint("net", "getheaders %d to %s from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString(), pfrom->id);
-        //fprintf(stderr,"getheaders from %d\n",(int32_t)(pindex ? pindex->nHeight : -1));
-        for (; pindex; pindex = chainActive.Next(pindex))
+        fprintf(stderr,"getheaders from %d prev.%d\n",(int32_t)(pindex ? pindex->nHeight : -1),pfrom->lasthdrsreq);
+        if ( pfrom->lasthdrsreq != (int32_t)(pindex ? pindex->nHeight : -1) )
         {
-            vHeaders.push_back(pindex->GetBlockHeader());
-            if (--nLimit <= 0 || pindex->GetBlockHash() == hashStop)
-                break;
+            for (; pindex; pindex = chainActive.Next(pindex))
+            {
+                vHeaders.push_back(pindex->GetBlockHeader());
+                if (--nLimit <= 0 || pindex->GetBlockHash() == hashStop)
+                    break;
+            }
+            pfrom->PushMessage("headers", vHeaders);
+            pfrom->lasthdrsreq = (int32_t)(pindex ? pindex->nHeight : -1);
         }
-        pfrom->PushMessage("headers", vHeaders);
     }
 
 
index f7ebf11f61916d9296efb036e522753e88258cba..5674bd40df76b532c2fd0d66d6d1ad5415c15d07 100644 (file)
--- a/src/net.h
+++ b/src/net.h
@@ -264,6 +264,7 @@ public:
     std::string addrName;
     CService addrLocal;
     int nVersion;
+    int lasthdrsreq;
     // strSubVer is whatever byte array we read from the wire. However, this field is intended
     // to be printed out, displayed to humans in various forms and so on. So we sanitize it and
     // store the sanitized version in cleanSubVer. The original should be used when dealing with
This page took 0.03634 seconds and 4 git commands to generate.