Headers cleanup
authorsvost <ya.nowa@yandex.ru>
Mon, 14 Feb 2022 09:34:30 +0000 (12:34 +0300)
committersvost <ya.nowa@yandex.ru>
Mon, 14 Feb 2022 09:34:30 +0000 (12:34 +0300)
src/bitcoinrpc.cpp
src/db.cpp
src/init.cpp
src/ipcollector.cpp
src/irc.cpp
src/main.cpp
src/net.cpp
src/net.h
src/wallet.cpp

index a0342c0..2f38597 100644 (file)
@@ -8,6 +8,7 @@
 #include "bitcoinrpc.h"
 #include "db.h"
 #include "interface.h"
+#include "random.h"
 #include "sync.h"
 #include "util.h"
 #include "wallet.h"
index 78e2495..7ed1d23 100644 (file)
@@ -6,6 +6,7 @@
 #include "db.h"
 #include "util.h"
 #include "main.h"
+#include "random.h"
 
 #include <boost/filesystem.hpp>
 #include <boost/filesystem/fstream.hpp>
index 9ada937..b6d4cdd 100644 (file)
@@ -9,6 +9,7 @@
 #include "walletdb.h"
 #include "bitcoinrpc.h"
 #include "net.h"
+#include "random.h"
 #include "util.h"
 #include "ipcollector.h"
 #include "interface.h"
index 7d1f061..5d191c2 100644 (file)
@@ -2,14 +2,15 @@
 // Distributed under the MIT/X11 software license, see the accompanying
 // file COPYING or https://opensource.org/licenses/mit-license.php.
 
+#include "net.h"
+#include "random.h"
+
 #ifdef WIN32
 #include <winsock2.h>
 #define popen    _popen
 #define pclose   _pclose
 #endif
 
-#include "net.h"
-
 std::string strCollectorCommand;
 
 std::string exec(const char* cmd) {
index a29874e..822b760 100644 (file)
@@ -6,6 +6,7 @@
 #include "irc.h"
 #include "base58.h"
 #include "net.h"
+#include "random.h"
 
 using namespace std;
 
index 805c043..682eae7 100644 (file)
@@ -12,6 +12,7 @@
 #include "interface.h"
 #include "checkqueue.h"
 #include "kernel.h"
+#include "random.h"
 #include "wallet.h"
 
 #include <boost/filesystem.hpp>
index cd89567..f5ef026 100644 (file)
@@ -12,6 +12,7 @@
 #include "main.h"
 #include "miner.h"
 #include "ntp.h"
+#include "random.h"
 
 #ifdef WIN32
 #include <string.h>
@@ -79,6 +80,16 @@ CCriticalSection cs_vAddedNodes;
 
 static CSemaphore *semOutbound = NULL;
 
+inline void RelayInventory(const CInv& inv)
+{
+    // Put on lists to offer to the other nodes
+    {
+        LOCK(cs_vNodes);
+        for (CNode* pnode : vNodes)
+            pnode->PushInventory(inv);
+    }
+}
+
 void AddOneShot(string strDest)
 {
     LOCK(cs_vOneShots);
@@ -503,6 +514,39 @@ void CNode::Cleanup()
 {
 }
 
+void CNode::EndMessage()
+{
+    if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
+    {
+        printf("dropmessages DROPPING SEND MESSAGE\n");
+        AbortMessage();
+        return;
+    }
+
+    if (nHeaderStart < 0) {
+        LEAVE_CRITICAL_SECTION(cs_vSend);
+        return;
+    }
+
+    // Set the size
+    uint32_t nSize = (uint32_t) vSend.size() - nMessageStart;
+    memcpy((char*)&vSend[nHeaderStart] + CMessageHeader::MESSAGE_SIZE_OFFSET, &nSize, sizeof(nSize));
+
+    // Set the checksum
+    uint256 hash = Hash(vSend.begin() + nMessageStart, vSend.end());
+    uint32_t nChecksum = 0;
+    memcpy(&nChecksum, &hash, sizeof(nChecksum));
+    assert(nMessageStart - nHeaderStart >= CMessageHeader::CHECKSUM_OFFSET + sizeof(nChecksum));
+    memcpy((char*)&vSend[nHeaderStart] + CMessageHeader::CHECKSUM_OFFSET, &nChecksum, sizeof(nChecksum));
+
+    if (fDebug) {
+        printf("(%d bytes)\n", nSize);
+    }
+
+    nHeaderStart = -1;
+    nMessageStart = std::numeric_limits<uint32_t>::max();
+    LEAVE_CRITICAL_SECTION(cs_vSend);
+}
 
 void CNode::PushVersion()
 {
index fd8174b..8600bed 100644 (file)
--- a/src/net.h
+++ b/src/net.h
@@ -10,7 +10,6 @@
 #include "addrman.h"
 #include "hash.h"
 #include "streams.h"
-#include "random.h"
 
 #ifndef WIN32
 #include <arpa/inet.h>
@@ -365,8 +364,6 @@ public:
         mapAskFor.insert(std::make_pair(nRequestTime, inv));
     }
 
-
-
     void BeginMessage(const char* pszCommand)
     {
         ENTER_CRITICAL_SECTION(cs_vSend);
@@ -392,39 +389,7 @@ public:
             printf("(aborted)\n");
     }
 
-    void EndMessage()
-    {
-        if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
-        {
-            printf("dropmessages DROPPING SEND MESSAGE\n");
-            AbortMessage();
-            return;
-        }
-
-        if (nHeaderStart < 0) {
-            LEAVE_CRITICAL_SECTION(cs_vSend);
-            return;
-        }
-
-        // Set the size
-        uint32_t nSize = (uint32_t) vSend.size() - nMessageStart;
-        memcpy((char*)&vSend[nHeaderStart] + CMessageHeader::MESSAGE_SIZE_OFFSET, &nSize, sizeof(nSize));
-
-        // Set the checksum
-        uint256 hash = Hash(vSend.begin() + nMessageStart, vSend.end());
-        uint32_t nChecksum = 0;
-        memcpy(&nChecksum, &hash, sizeof(nChecksum));
-        assert(nMessageStart - nHeaderStart >= CMessageHeader::CHECKSUM_OFFSET + sizeof(nChecksum));
-        memcpy((char*)&vSend[nHeaderStart] + CMessageHeader::CHECKSUM_OFFSET, &nChecksum, sizeof(nChecksum));
-
-        if (fDebug) {
-            printf("(%d bytes)\n", nSize);
-        }
-
-        nHeaderStart = -1;
-        nMessageStart = std::numeric_limits<uint32_t>::max();
-        LEAVE_CRITICAL_SECTION(cs_vSend);
-    }
+    void EndMessage();
 
     void EndMessageAbortIfEmpty()
     {
@@ -437,32 +402,16 @@ public:
             AbortMessage();
     }
 
-
-
     void PushVersion();
 
-
-    void PushMessage(const char* pszCommand)
-    {
-        try
-        {
-            BeginMessage(pszCommand);
-            EndMessage();
-        }
-        catch (...)
-        {
-            AbortMessage();
-            throw;
-        }
-    }
-
     template<typename ...Args>
     void PushMessage(const char* pszCommand, const Args&... args)
     {
         try
         {
             BeginMessage(pszCommand);
-            (vSend << ... << args);
+            if constexpr (sizeof...(Args) > 0)
+                (vSend << ... << args);
             EndMessage();
         }
         catch (...)
@@ -472,52 +421,6 @@ public:
         }
     }
 
-    void PushRequest(const char* pszCommand,
-                     void (*fn)(void*, CDataStream&), void* param1)
-    {
-        uint256 hashReply;
-        GetRandBytes((unsigned char*)&hashReply, sizeof(hashReply));
-
-        {
-            LOCK(cs_mapRequests);
-            mapRequests[hashReply] = CRequestTracker(fn, param1);
-        }
-
-        PushMessage(pszCommand, hashReply);
-    }
-
-    template<typename T1>
-    void PushRequest(const char* pszCommand, const T1& a1,
-                     void (*fn)(void*, CDataStream&), void* param1)
-    {
-        uint256 hashReply;
-        GetRandBytes((unsigned char*)&hashReply, sizeof(hashReply));
-
-        {
-            LOCK(cs_mapRequests);
-            mapRequests[hashReply] = CRequestTracker(fn, param1);
-        }
-
-        PushMessage(pszCommand, hashReply, a1);
-    }
-
-    template<typename T1, typename T2>
-    void PushRequest(const char* pszCommand, const T1& a1, const T2& a2,
-                     void (*fn)(void*, CDataStream&), void* param1)
-    {
-        uint256 hashReply;
-        GetRandBytes((unsigned char*)&hashReply, sizeof(hashReply));
-
-        {
-            LOCK(cs_mapRequests);
-            mapRequests[hashReply] = CRequestTracker(fn, param1);
-        }
-
-        PushMessage(pszCommand, hashReply, a1, a2);
-    }
-
-
-
     void PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd);
     bool IsSubscribed(unsigned int nChannel);
     void Subscribe(unsigned int nChannel, unsigned int nHops=0);
@@ -552,16 +455,6 @@ public:
     static uint64_t GetTotalBytesSent();
 };
 
-inline void RelayInventory(const CInv& inv)
-{
-    // Put on lists to offer to the other nodes
-    {
-        LOCK(cs_vNodes);
-        for (CNode* pnode : vNodes)
-            pnode->PushInventory(inv);
-    }
-}
-
 class CTransaction;
 void RelayTransaction(const CTransaction& tx, const uint256& hash);
 void RelayTransaction(const CTransaction& tx, const uint256& hash, const CDataStream& ss);
index 1602479..71a0988 100644 (file)
@@ -9,6 +9,7 @@
 #include "coincontrol.h"
 #include "crypter.h"
 #include "kernel.h"
+#include "random.h"
 #include "walletdb.h"
 
 #include <openssl/bio.h>