From ddaa6b2698fb8e2e7899afbf80fa7156a0b9132a Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 22 Oct 2014 15:45:51 -0700 Subject: [PATCH] add "getaddr", "mempool", and "ping" handlers. --- src/bitcoindjs.cc | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index fa97a23a..66163477 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -3397,6 +3397,8 @@ NAN_METHOD(HookPackets) { o->Set(NanNew("name"), NanNew(cur->strCommand)); o->Set(NanNew("received"), NanNew((int64_t)cur->nTimeReceived)); + o->Set(NanNew("peerId"), NanNew(pfrom->id)); + //o->Set(NanNew("peerId"), NanNew(pfrom->GetId())); if (strCommand == "version") { #if 0 @@ -3452,7 +3454,6 @@ NAN_METHOD(HookPackets) { o->Set(NanNew("version"), NanNew(nVersion)); o->Set(NanNew("height"), NanNew(nStartingHeight)); o->Set(NanNew("us"), NanNew(addrMe.ToString())); - o->Set(NanNew("peerId"), NanNew(pfrom->id)); o->Set(NanNew("address"), NanNew(pfrom->addr.ToString())); o->Set(NanNew("relay"), NanNew(fRelayTxes)); #endif @@ -3551,8 +3552,6 @@ NAN_METHOD(HookPackets) { i++; } - o->Set(NanNew("peerId"), NanNew(pfrom->id)); - //o->Set(NanNew("peerId"), NanNew(pfrom->GetId())); o->Set(NanNew("items"), array); } else if (strCommand == "getdata") { vector vInv; @@ -3563,7 +3562,6 @@ NAN_METHOD(HookPackets) { return false; } - o->Set(NanNew("peerId"), NanNew(pfrom->id)); o->Set(NanNew("size"), NanNew(vInv.size())); if (vInv.size() > 0) { o->Set(NanNew("first"), NanNew(vInv[0].ToString().c_str())); @@ -3583,7 +3581,6 @@ NAN_METHOD(HookPackets) { pindex = chainActive.Next(pindex); } - o->Set(NanNew("peerId"), NanNew(pfrom->id)); o->Set(NanNew("fromHeight"), NanNew(pindex ? pindex->nHeight : -1); o->Set(NanNew("toHash"), NanNew( hashStop == uint256(0) ? "end" : hashStop.GetHex().c_str())); @@ -3629,11 +3626,20 @@ NAN_METHOD(HookPackets) { // cblock_to_jsblock(block, 0, o); o->Set(NanNew("tx"), jstx); } else if (strCommand == "getaddr") { - ; + ; // not much other information in getaddr as long as we know we got a getaddr } else if (strCommand == "mempool") { - ; + ; // not much other information in getaddr as long as we know we got a getaddr } else if (strCommand == "ping") { - ; + if (pfrom->nVersion > BIP0031_VERSION) { + uint64_t nonce = 0; + cur->vRecv >> nonce; + char snonce[21] = {0}; + int written = snprintf(snonce, sizeof(snonce), "%020lu", (uint64_t)nonce); + assert(written == 20); + o->Set(NanNew("nonce"), NanNew(snonce)); + } else { + o->Set(NanNew("nonce"), NanNew("0")); + } } else if (strCommand == "pong") { ; } else if (strCommand == "alert") {