diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index a8062e80..62882888 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -3391,13 +3391,122 @@ NAN_METHOD(HookPackets) { poll_packets_mutex.lock(); for (cur = packets_queue_head; cur; cur = next) { - // std::string strCommand(cur->strCommand); + std::string strCommand(cur->strCommand); Local o = NanNew(); o->Set(NanNew("name"), NanNew(cur->strCommand)); o->Set(NanNew("received"), NanNew((int64_t)cur->nTimeReceived)); + if (strCommand == "version") { +#if 0 + // Each connection can only send one version message + if (cur->pfrom->nVersion != 0) { + // reject + return false; + } + + bool fRelayTxes = false; + int nStartingHeight = 0; + int cleanSubVer = 0; + std::string strSubVer(""); + int nVersion = cur->pfrom->nVersion; + uint64_t nServices = cur->pfrom->nServices; + + int64_t nTime; + CAddress addrMe; + CAddress addrFrom; + uint64_t nNonce = 1; + *cur->vRecv >> nVersion >> nServices >> nTime >> addrMe; + if (cur->pfrom->nVersion < MIN_PEER_PROTO_VERSION) { + // disconnect from peers older than this proto version + // reject + return false; + } + + if (nVersion == 10300) { + nVersion = 300; + } + if (!cur->vRecv->empty()) { + *cur->vRecv >> addrFrom >> nNonce; + } + if (!cur->vRecv->empty()) { + *cur->vRecv >> LIMITED_STRING(strSubVer, 256); + cleanSubVer = SanitizeString(strSubVer); + } + if (!cur->vRecv->empty()) { + *cur->vRecv >> nStartingHeight; + } + if (!cur->vRecv->empty()) { + fRelayTxes = false; + } else { + fRelayTxes = true; + } + + // Disconnect if we connected to ourself + if (nNonce == nLocalHostNonce && nNonce > 1) { + return true; + } + + o->Set(NanNew("receiveVersion"), NanNew(cleanSubVer)); + 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 + } else if (cur->pfrom->nVersion == 0) { + ; + } else if (strCommand == "verack") { + ; + } else if (strCommand == "addr") { + ; + } else if (strCommand == "inv") { + ; + } else if (strCommand == "getdata") { + ; + } else if (strCommand == "getblocks") { + ; + } else if (strCommand == "getheaders") { + ; + } else if (strCommand == "tx") { + ; + } else if (strCommand == "block" && !fImporting && !fReindex) { + ; + } else if (strCommand == "getaddr") { + ; + } else if (strCommand == "mempool") { + ; + } else if (strCommand == "ping") { + ; + } else if (strCommand == "pong") { + ; + } else if (strCommand == "alert") { + ; + } else if (strCommand == "filterload") { + ; + } else if (strCommand == "filteradd") { + ; + } else if (strCommand == "filterclear") { + ; + } else if (strCommand == "reject") { + ; + } else { + ; + } + + // Update the last seen time for this node's address + if (cur->pfrom->fNetworkNode) { + if (strCommand == "version" + || strCommand == "addr" + || strCommand == "inv" + || strCommand == "getdata" + || strCommand == "ping") { + ; + } + } + obj->Set(i, o); i++;