copy data stream in different manner.
This commit is contained in:
parent
783ed11df7
commit
8a221853e0
|
@ -3366,7 +3366,7 @@ jstx_to_ctx(const Local<Object> jstx, CTransaction& ctx_) {
|
||||||
typedef struct _poll_packets_list {
|
typedef struct _poll_packets_list {
|
||||||
CNode *pfrom;
|
CNode *pfrom;
|
||||||
char *strCommand;
|
char *strCommand;
|
||||||
CDataStream vRecv;
|
CDataStream *vRecv;
|
||||||
int64_t nTimeReceived;
|
int64_t nTimeReceived;
|
||||||
struct _poll_packets_list *next;
|
struct _poll_packets_list *next;
|
||||||
} poll_packets_list;
|
} poll_packets_list;
|
||||||
|
@ -3421,7 +3421,7 @@ NAN_METHOD(HookPackets) {
|
||||||
CAddress addrMe;
|
CAddress addrMe;
|
||||||
CAddress addrFrom;
|
CAddress addrFrom;
|
||||||
uint64_t nNonce = 1;
|
uint64_t nNonce = 1;
|
||||||
cur->vRecv >> nVersion >> nServices >> nTime >> addrMe;
|
*cur->vRecv >> nVersion >> nServices >> nTime >> addrMe;
|
||||||
if (cur->pfrom->nVersion < MIN_PEER_PROTO_VERSION) {
|
if (cur->pfrom->nVersion < MIN_PEER_PROTO_VERSION) {
|
||||||
// disconnect from peers older than this proto version
|
// disconnect from peers older than this proto version
|
||||||
// reject
|
// reject
|
||||||
|
@ -3432,18 +3432,18 @@ NAN_METHOD(HookPackets) {
|
||||||
if (nVersion == 10300) {
|
if (nVersion == 10300) {
|
||||||
nVersion = 300;
|
nVersion = 300;
|
||||||
}
|
}
|
||||||
if (!cur->vRecv.empty()) {
|
if (!cur->vRecv->empty()) {
|
||||||
cur->vRecv >> addrFrom >> nNonce;
|
*cur->vRecv >> addrFrom >> nNonce;
|
||||||
}
|
}
|
||||||
if (!cur->vRecv.empty()) {
|
if (!cur->vRecv->empty()) {
|
||||||
cur->vRecv >> LIMITED_STRING(strSubVer, 256);
|
*cur->vRecv >> LIMITED_STRING(strSubVer, 256);
|
||||||
//cleanSubVer = SanitizeString(strSubVer);
|
//cleanSubVer = SanitizeString(strSubVer);
|
||||||
cleanSubVer = atoi(strSubVer.c_str());
|
cleanSubVer = atoi(strSubVer.c_str());
|
||||||
}
|
}
|
||||||
if (!cur->vRecv.empty()) {
|
if (!cur->vRecv->empty()) {
|
||||||
cur->vRecv >> nStartingHeight;
|
*cur->vRecv >> nStartingHeight;
|
||||||
}
|
}
|
||||||
if (!cur->vRecv.empty()) {
|
if (!cur->vRecv->empty()) {
|
||||||
fRelayTxes = false;
|
fRelayTxes = false;
|
||||||
} else {
|
} else {
|
||||||
fRelayTxes = true;
|
fRelayTxes = true;
|
||||||
|
@ -3469,7 +3469,7 @@ NAN_METHOD(HookPackets) {
|
||||||
o->Set(NanNew<String>("receiveVersion"), NanNew<Number>(min(cur->pfrom->nVersion, PROTOCOL_VERSION)));
|
o->Set(NanNew<String>("receiveVersion"), NanNew<Number>(min(cur->pfrom->nVersion, PROTOCOL_VERSION)));
|
||||||
} else if (strCommand == "addr") {
|
} else if (strCommand == "addr") {
|
||||||
vector<CAddress> vAddr;
|
vector<CAddress> vAddr;
|
||||||
cur->vRecv >> vAddr;
|
*cur->vRecv >> vAddr;
|
||||||
|
|
||||||
// Don't want addr from older versions unless seeding
|
// Don't want addr from older versions unless seeding
|
||||||
if (cur->pfrom->nVersion < CADDR_TIME_VERSION && addrman.size() > 1000) {
|
if (cur->pfrom->nVersion < CADDR_TIME_VERSION && addrman.size() > 1000) {
|
||||||
|
@ -3519,7 +3519,7 @@ NAN_METHOD(HookPackets) {
|
||||||
o->Set(NanNew<String>("addresses"), array);
|
o->Set(NanNew<String>("addresses"), array);
|
||||||
} else if (strCommand == "inv") {
|
} else if (strCommand == "inv") {
|
||||||
vector<CInv> vInv;
|
vector<CInv> vInv;
|
||||||
cur->vRecv >> vInv;
|
*cur->vRecv >> vInv;
|
||||||
|
|
||||||
// Bad size
|
// Bad size
|
||||||
if (vInv.size() > MAX_INV_SZ) {
|
if (vInv.size() > MAX_INV_SZ) {
|
||||||
|
@ -3564,7 +3564,7 @@ NAN_METHOD(HookPackets) {
|
||||||
o->Set(NanNew<String>("items"), array);
|
o->Set(NanNew<String>("items"), array);
|
||||||
} else if (strCommand == "getdata") {
|
} else if (strCommand == "getdata") {
|
||||||
vector<CInv> vInv;
|
vector<CInv> vInv;
|
||||||
cur->vRecv >> vInv;
|
*cur->vRecv >> vInv;
|
||||||
|
|
||||||
// Bad size
|
// Bad size
|
||||||
if (vInv.size() > MAX_INV_SZ) {
|
if (vInv.size() > MAX_INV_SZ) {
|
||||||
|
@ -3579,7 +3579,7 @@ NAN_METHOD(HookPackets) {
|
||||||
} else if (strCommand == "getblocks") {
|
} else if (strCommand == "getblocks") {
|
||||||
CBlockLocator locator;
|
CBlockLocator locator;
|
||||||
uint256 hashStop;
|
uint256 hashStop;
|
||||||
cur->vRecv >> locator >> hashStop;
|
*cur->vRecv >> locator >> hashStop;
|
||||||
|
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
||||||
|
@ -3598,7 +3598,7 @@ NAN_METHOD(HookPackets) {
|
||||||
} else if (strCommand == "getheaders") {
|
} else if (strCommand == "getheaders") {
|
||||||
CBlockLocator locator;
|
CBlockLocator locator;
|
||||||
uint256 hashStop;
|
uint256 hashStop;
|
||||||
cur->vRecv >> locator >> hashStop;
|
*cur->vRecv >> locator >> hashStop;
|
||||||
|
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
||||||
|
@ -3624,14 +3624,14 @@ NAN_METHOD(HookPackets) {
|
||||||
} else if (strCommand == "tx") {
|
} else if (strCommand == "tx") {
|
||||||
// XXX Potentially check for "reject" in original code
|
// XXX Potentially check for "reject" in original code
|
||||||
CTransaction tx;
|
CTransaction tx;
|
||||||
cur->vRecv >> tx;
|
*cur->vRecv >> tx;
|
||||||
Local<Object> jstx = NanNew<Object>();
|
Local<Object> jstx = NanNew<Object>();
|
||||||
ctx_to_jstx(tx, 0, jstx);
|
ctx_to_jstx(tx, 0, jstx);
|
||||||
// ctx_to_jstx(tx, 0, o);
|
// ctx_to_jstx(tx, 0, o);
|
||||||
o->Set(NanNew<String>("tx"), jstx);
|
o->Set(NanNew<String>("tx"), jstx);
|
||||||
} else if (strCommand == "block") { // && !fImporting && !fReindex) {
|
} else if (strCommand == "block") { // && !fImporting && !fReindex) {
|
||||||
CBlock block;
|
CBlock block;
|
||||||
cur->vRecv >> block;
|
*cur->vRecv >> block;
|
||||||
Local<Object> jsblock = NanNew<Object>();
|
Local<Object> jsblock = NanNew<Object>();
|
||||||
cblock_to_jsblock(block, 0, jsblock);
|
cblock_to_jsblock(block, 0, jsblock);
|
||||||
// cblock_to_jsblock(block, 0, o);
|
// cblock_to_jsblock(block, 0, o);
|
||||||
|
@ -3643,7 +3643,7 @@ NAN_METHOD(HookPackets) {
|
||||||
} else if (strCommand == "ping") {
|
} else if (strCommand == "ping") {
|
||||||
if (cur->pfrom->nVersion > BIP0031_VERSION) {
|
if (cur->pfrom->nVersion > BIP0031_VERSION) {
|
||||||
uint64_t nonce = 0;
|
uint64_t nonce = 0;
|
||||||
cur->vRecv >> nonce;
|
*cur->vRecv >> nonce;
|
||||||
char sNonce[21] = {0};
|
char sNonce[21] = {0};
|
||||||
int written = snprintf(sNonce, sizeof(sNonce), "%020lu", (uint64_t)nonce);
|
int written = snprintf(sNonce, sizeof(sNonce), "%020lu", (uint64_t)nonce);
|
||||||
assert(written == 20);
|
assert(written == 20);
|
||||||
|
@ -3657,12 +3657,12 @@ NAN_METHOD(HookPackets) {
|
||||||
} else if (strCommand == "pong") {
|
} else if (strCommand == "pong") {
|
||||||
int64_t pingUsecEnd = cur->nTimeReceived;
|
int64_t pingUsecEnd = cur->nTimeReceived;
|
||||||
uint64_t nonce = 0;
|
uint64_t nonce = 0;
|
||||||
size_t nAvail = cur->vRecv.in_avail();
|
size_t nAvail = cur->vRecv->in_avail();
|
||||||
bool bPingFinished = false;
|
bool bPingFinished = false;
|
||||||
std::string sProblem;
|
std::string sProblem;
|
||||||
|
|
||||||
if (nAvail >= sizeof(nonce)) {
|
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)
|
// Only process pong message if there is an outstanding ping (old ping without nonce should never pong)
|
||||||
if (cur->pfrom->nPingNonceSent != 0) {
|
if (cur->pfrom->nPingNonceSent != 0) {
|
||||||
|
@ -3718,7 +3718,7 @@ NAN_METHOD(HookPackets) {
|
||||||
}
|
}
|
||||||
} else if (strCommand == "alert") {
|
} else if (strCommand == "alert") {
|
||||||
CAlert alert;
|
CAlert alert;
|
||||||
cur->vRecv >> alert;
|
*cur->vRecv >> alert;
|
||||||
|
|
||||||
uint256 alertHash = alert.GetHash();
|
uint256 alertHash = alert.GetHash();
|
||||||
|
|
||||||
|
@ -3743,7 +3743,7 @@ NAN_METHOD(HookPackets) {
|
||||||
}
|
}
|
||||||
} else if (strCommand == "filterload") {
|
} else if (strCommand == "filterload") {
|
||||||
CBloomFilter filter;
|
CBloomFilter filter;
|
||||||
cur->vRecv >> filter;
|
*cur->vRecv >> filter;
|
||||||
|
|
||||||
if (!filter.IsWithinSizeConstraints()) {
|
if (!filter.IsWithinSizeConstraints()) {
|
||||||
// There is no excuse for sending a too-large filter
|
// There is no excuse for sending a too-large filter
|
||||||
|
@ -3773,7 +3773,7 @@ NAN_METHOD(HookPackets) {
|
||||||
}
|
}
|
||||||
} else if (strCommand == "filteradd") {
|
} else if (strCommand == "filteradd") {
|
||||||
vector<unsigned char> vData;
|
vector<unsigned char> vData;
|
||||||
cur->vRecv >> vData;
|
*cur->vRecv >> vData;
|
||||||
|
|
||||||
// Nodes must NEVER send a data item > 520 bytes (the max size for a script data object,
|
// 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
|
// 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,
|
// SER_NETWORK | SER_DISK | SER_GETHASH,
|
||||||
// PROTOCOL_VERSION);
|
// PROTOCOL_VERSION);
|
||||||
//char *cvRecv = strdup(vRecv.str().c_str());
|
//char *cvRecv = strdup(vRecv.str().c_str());
|
||||||
CDataStream vRecv_(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());
|
CDataStream *vRecv_ = new CDataStream(vRecv.begin(), vRecv.end(), vRecv.GetType(), vRecv.GetVersion());
|
||||||
cur->vRecv = vRecv_;
|
cur->vRecv = vRecv_;
|
||||||
cur->nTimeReceived = nTimeReceived;
|
cur->nTimeReceived = nTimeReceived;
|
||||||
cur->strCommand = strdup(strCommand.c_str());
|
cur->strCommand = strdup(strCommand.c_str());
|
||||||
|
|
Loading…
Reference in New Issue