diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index c1e8b439..2ea0d2a7 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -3481,7 +3481,7 @@ NAN_METHOD(HookPackets) { // Get the new addresses int64_t nNow = GetAdjustedTime(); BOOST_FOREACH(CAddress& addr, vAddr) { - // boost::this_thread::interruption_point(); + boost::this_thread::interruption_point(); unsigned int nTime = addr.nTime; if (nTime <= 100000000 || nTime > nNow + 10 * 60) { @@ -3510,7 +3510,50 @@ NAN_METHOD(HookPackets) { o->Set(NanNew("addresses"), array); } else if (strCommand == "inv") { - ; + vector vInv; + cur->vRecv >> vInv; + + // Bad size + if (vInv.size() > MAX_INV_SZ) { + return false; + } + + LOCK(cs_main); + + Local array = NanNew(); + int i = 0; + + for (unsigned int nInv = 0; nInv < vInv.size(); nInv++) { + const CInv &inv = vInv[nInv]; + + boost::this_thread::interruption_point(); + + bool fAlreadyHave = AlreadyHave(inv); + + // Bad size + if (pfrom->nSendSize > (SendBufferSize() * 2)) { + return false; + } + + Local item = NanNew(); + item->Set(NanNew("have"), NanNew(fAlreadyHave)); + item->Set(NanNew("hash"), NanNew(inv.hash.GetHex().c_str())); + item->Set(NanNew("type"), NanNew( + inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK + ? "block" : "tx")); + if (inv.type == MSG_FILTERED_BLOCK) { + item->Set(NanNew("filtered"), NanNew(true)); + } else if (inv.type == MSG_BLOCK) { + item->Set(NanNew("filtered"), NanNew(false)); + } + + array->Set(i, item); + i++; + } + + o->Set(NanNew("peerId"), NanNew(pfrom->id)); + //o->Set(NanNew("peerId"), NanNew(pfrom->GetId())); + o->Set(NanNew("items"), array); } else if (strCommand == "getdata") { ; } else if (strCommand == "getblocks") {