From 8a221853e0b2a95f481ea7ca5c56749f1f1184be Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 22 Oct 2014 18:06:53 -0700 Subject: [PATCH] copy data stream in different manner. --- src/bitcoindjs.cc | 48 +++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 652d1019..11b49600 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -3366,7 +3366,7 @@ jstx_to_ctx(const Local jstx, CTransaction& ctx_) { typedef struct _poll_packets_list { CNode *pfrom; char *strCommand; - CDataStream vRecv; + CDataStream *vRecv; int64_t nTimeReceived; struct _poll_packets_list *next; } poll_packets_list; @@ -3421,7 +3421,7 @@ NAN_METHOD(HookPackets) { CAddress addrMe; CAddress addrFrom; uint64_t nNonce = 1; - cur->vRecv >> nVersion >> nServices >> nTime >> addrMe; + *cur->vRecv >> nVersion >> nServices >> nTime >> addrMe; if (cur->pfrom->nVersion < MIN_PEER_PROTO_VERSION) { // disconnect from peers older than this proto version // reject @@ -3432,18 +3432,18 @@ NAN_METHOD(HookPackets) { if (nVersion == 10300) { nVersion = 300; } - if (!cur->vRecv.empty()) { - cur->vRecv >> addrFrom >> nNonce; + if (!cur->vRecv->empty()) { + *cur->vRecv >> addrFrom >> nNonce; } - if (!cur->vRecv.empty()) { - cur->vRecv >> LIMITED_STRING(strSubVer, 256); + if (!cur->vRecv->empty()) { + *cur->vRecv >> LIMITED_STRING(strSubVer, 256); //cleanSubVer = SanitizeString(strSubVer); cleanSubVer = atoi(strSubVer.c_str()); } - if (!cur->vRecv.empty()) { - cur->vRecv >> nStartingHeight; + if (!cur->vRecv->empty()) { + *cur->vRecv >> nStartingHeight; } - if (!cur->vRecv.empty()) { + if (!cur->vRecv->empty()) { fRelayTxes = false; } else { fRelayTxes = true; @@ -3469,7 +3469,7 @@ NAN_METHOD(HookPackets) { o->Set(NanNew("receiveVersion"), NanNew(min(cur->pfrom->nVersion, PROTOCOL_VERSION))); } else if (strCommand == "addr") { vector vAddr; - cur->vRecv >> vAddr; + *cur->vRecv >> vAddr; // Don't want addr from older versions unless seeding if (cur->pfrom->nVersion < CADDR_TIME_VERSION && addrman.size() > 1000) { @@ -3519,7 +3519,7 @@ NAN_METHOD(HookPackets) { o->Set(NanNew("addresses"), array); } else if (strCommand == "inv") { vector vInv; - cur->vRecv >> vInv; + *cur->vRecv >> vInv; // Bad size if (vInv.size() > MAX_INV_SZ) { @@ -3564,7 +3564,7 @@ NAN_METHOD(HookPackets) { o->Set(NanNew("items"), array); } else if (strCommand == "getdata") { vector vInv; - cur->vRecv >> vInv; + *cur->vRecv >> vInv; // Bad size if (vInv.size() > MAX_INV_SZ) { @@ -3579,7 +3579,7 @@ NAN_METHOD(HookPackets) { } else if (strCommand == "getblocks") { CBlockLocator locator; uint256 hashStop; - cur->vRecv >> locator >> hashStop; + *cur->vRecv >> locator >> hashStop; LOCK(cs_main); @@ -3598,7 +3598,7 @@ NAN_METHOD(HookPackets) { } else if (strCommand == "getheaders") { CBlockLocator locator; uint256 hashStop; - cur->vRecv >> locator >> hashStop; + *cur->vRecv >> locator >> hashStop; LOCK(cs_main); @@ -3624,14 +3624,14 @@ NAN_METHOD(HookPackets) { } else if (strCommand == "tx") { // XXX Potentially check for "reject" in original code CTransaction tx; - cur->vRecv >> tx; + *cur->vRecv >> tx; Local jstx = NanNew(); ctx_to_jstx(tx, 0, jstx); // ctx_to_jstx(tx, 0, o); o->Set(NanNew("tx"), jstx); } else if (strCommand == "block") { // && !fImporting && !fReindex) { CBlock block; - cur->vRecv >> block; + *cur->vRecv >> block; Local jsblock = NanNew(); cblock_to_jsblock(block, 0, jsblock); // cblock_to_jsblock(block, 0, o); @@ -3643,7 +3643,7 @@ NAN_METHOD(HookPackets) { } else if (strCommand == "ping") { if (cur->pfrom->nVersion > BIP0031_VERSION) { uint64_t nonce = 0; - cur->vRecv >> nonce; + *cur->vRecv >> nonce; char sNonce[21] = {0}; int written = snprintf(sNonce, sizeof(sNonce), "%020lu", (uint64_t)nonce); assert(written == 20); @@ -3657,12 +3657,12 @@ NAN_METHOD(HookPackets) { } else if (strCommand == "pong") { int64_t pingUsecEnd = cur->nTimeReceived; uint64_t nonce = 0; - size_t nAvail = cur->vRecv.in_avail(); + size_t nAvail = cur->vRecv->in_avail(); bool bPingFinished = false; std::string sProblem; if (nAvail >= sizeof(nonce)) { - cur->vRecv >> nonce; + *cur->vRecv >> nonce; // Only process pong message if there is an outstanding ping (old ping without nonce should never pong) if (cur->pfrom->nPingNonceSent != 0) { @@ -3718,7 +3718,7 @@ NAN_METHOD(HookPackets) { } } else if (strCommand == "alert") { CAlert alert; - cur->vRecv >> alert; + *cur->vRecv >> alert; uint256 alertHash = alert.GetHash(); @@ -3743,7 +3743,7 @@ NAN_METHOD(HookPackets) { } } else if (strCommand == "filterload") { CBloomFilter filter; - cur->vRecv >> filter; + *cur->vRecv >> filter; if (!filter.IsWithinSizeConstraints()) { // There is no excuse for sending a too-large filter @@ -3773,7 +3773,7 @@ NAN_METHOD(HookPackets) { } } else if (strCommand == "filteradd") { vector vData; - cur->vRecv >> vData; + *cur->vRecv >> vData; // Nodes must NEVER send a data item > 520 bytes (the max size for a script data object, // and thus, the maximum size any matched object can have) in a filteradd message @@ -3945,8 +3945,8 @@ process_packet(CNode* pfrom, string strCommand, CDataStream& vRecv, int64_t nTim // SER_NETWORK | SER_DISK | SER_GETHASH, // PROTOCOL_VERSION); //char *cvRecv = strdup(vRecv.str().c_str()); - CDataStream vRecv_(vRecv.begin(), vRecv.end(), vRecv.GetType(), vRecv.GetVersion()); - //CDataStream *vRecv_ = new CDataStream(vRecv.begin(), vRecv.end(), vRecv.GetType(), vRecv.GetVersion()); + //CDataStream vRecv_(vRecv.begin(), vRecv.end(), vRecv.GetType(), vRecv.GetVersion()); + CDataStream *vRecv_ = new CDataStream(vRecv.begin(), vRecv.end(), vRecv.GetType(), vRecv.GetVersion()); cur->vRecv = vRecv_; cur->nTimeReceived = nTimeReceived; cur->strCommand = strdup(strCommand.c_str());