Skip to content

Commit

Permalink
Merge pull request #2366 from div72/net-cleanup
Browse files Browse the repository at this point in the history
net: remove obsolete "reply" command
  • Loading branch information
jamescowens authored Nov 24, 2021
2 parents 48efa75 + ba1fafd commit 248fc25
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 99 deletions.
2 changes: 0 additions & 2 deletions src/addrman.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include <map>
#include <vector>

#include <openssl/rand.h>


/** Extended statistics about a CAddress */
class CAddrInfo : public CAddress
Expand Down
19 changes: 0 additions & 19 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3571,25 +3571,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
if (vInv.size() > 0)
pfrom->PushMessage("inv", vInv);
}

else if (strCommand == "reply")
{
uint256 hashReply;
vRecv >> hashReply;

CRequestTracker tracker;
{
LOCK(pfrom->cs_mapRequests);
map<uint256, CRequestTracker>::iterator mi = pfrom->mapRequests.find(hashReply);
if (mi != pfrom->mapRequests.end())
{
tracker = mi->second;
pfrom->mapRequests.erase(mi);
}
}
if (!tracker.IsNull())
tracker.fn(tracker.param1, vRecv);
}
else if (strCommand == "ping")
{
uint64_t nonce = 0;
Expand Down
10 changes: 3 additions & 7 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,13 +825,9 @@ void ThreadSocketHandler2(void* parg)
TRY_LOCK(pnode->cs_vRecvMsg, lockRecv);
if (lockRecv)
{
TRY_LOCK(pnode->cs_mapRequests, lockReq);
if (lockReq)
{
TRY_LOCK(pnode->cs_inventory, lockInv);
if (lockInv)
fDelete = true;
}
TRY_LOCK(pnode->cs_inventory, lockInv);
if (lockInv)
fDelete = true;
}
}
}
Expand Down
71 changes: 0 additions & 71 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <arpa/inet.h>
#endif

class CRequestTracker;
class CNode;
class CBlockIndex;
extern int nBestHeight;
Expand Down Expand Up @@ -95,25 +94,6 @@ enum
};



class CRequestTracker
{
public:
void (*fn)(void*, CDataStream&);
void* param1;

explicit CRequestTracker(void (*fnIn)(void*, CDataStream&) = nullptr, void* param1In = nullptr)
{
fn = fnIn;
param1 = param1In;
}

bool IsNull()
{
return fn == nullptr;
}
};

extern bool fDiscover;
void Discover(boost::thread_group& threadGroup);
extern bool fUseUPnP;
Expand Down Expand Up @@ -259,8 +239,6 @@ class CNode
// int nMisbehavior;

public:
std::map<uint256, CRequestTracker> mapRequests;
CCriticalSection cs_mapRequests;
uint256 hashContinue;
CBlockIndex* pindexLastGetBlocksBegin;
uint256 hashLastGetBlocksEnd;
Expand Down Expand Up @@ -550,55 +528,6 @@ class CNode
}
}

void PushRequest(const char* pszCommand,
void (*fn)(void*, CDataStream&), void* param1)
{
uint256 hashReply;
RAND_bytes((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;
RAND_bytes((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;
RAND_bytes((unsigned char*)&hashReply, sizeof(hashReply));

{
LOCK(cs_mapRequests);
mapRequests[hashReply] = CRequestTracker(fn, param1);
}

PushMessage(pszCommand, hashReply, a1, a2);
}






void PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd);
void CloseSocketDisconnect();

Expand Down

0 comments on commit 248fc25

Please sign in to comment.