diff --git a/lib/bitcoind.js b/lib/bitcoind.js index be51a52c..29618468 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -180,6 +180,19 @@ Bitcoin.prototype.start = function(options, callback) { setInterval(function() { var packets = bitcoindjs.hookPackets(); + // bitcoindjs.hookPackets(function(err, packets) { + // if (err || !packets) { + // if (self.debug) { + // self.error('Error polling packet queue.'); + // } + // return; + // } + // if (!packets.length) { + // return; + // } + // ; + // }); + if (!packets) { if (self.debug) { self.error('Error polling packet queue.'); diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index cd59f791..1bd43310 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -391,6 +391,14 @@ jsblock_to_cblock(const Local jsblock, CBlock& cblock); static inline void jstx_to_ctx(const Local jstx, CTransaction& ctx); +#if 0 +static void +async_hook_packets(uv_work_t *req); + +static void +async_hook_packets_after(uv_work_t *req); +#endif + static void hook_packets(void); @@ -577,6 +585,64 @@ struct async_dump_wallet_data { Persistent callback; }; +/** + * async_hook_packets_data + */ + +#if 0 +struct async_hook_packets_data { + std::string err_msg; + Persistent callback; + // NOTE: Could use a union here + std::string strCommand; + std::string name; + int64_t received; + int64_t /*?*/ peerId; + std::string userAgent; + int64_t /*?*/ receiveVersion; + int64_t /*?*/ version; + int64_t /*?*/ height; + std::string us; + std::string address; + bool relay; + std::string services; + int64_t /*?*/ time; + int64_t /*?*/ last; + std::string ip; + int64_t /*?*/ port; + bool reachable; + packet_addresses_list addresses; + bool have; + std::string hash; + std::string type; + bool filtered; + packet_items_list items; + int64_t /*?*/ size; + std::string first; + int64_t /*?*/ fromHeight; + std::string toHash; + int64_t /*?*/ limit; + CTransaction tx; + CBlock block; + std::string nonce; + std::string expected; + int64_t /*?*/ bytes; + std::string problem; + bool finished; + std::string message; + std::string signature; + bool misbehaving; + std::string data; + bool full; + bool empty; + int64_t /*?*/ hashFuncs; + int64_t /*?*/ tweaks; + int64_t /*?*/ flags; + bool unknown; + bool connected; +}; +#endif + /** * Read Raw DB */ @@ -2757,9 +2823,68 @@ NAN_METHOD(HookPackets) { poll_packets_mutex.unlock(); +#if 0 + Local callback = Local::Cast(args[0]); + async_hook_packets_data *data = new async_hook_packets_data(); + data->err_msg = std::string(""); + data->callback = Persistent::New(callback); + + uv_work_t *req = new uv_work_t(); + req->data = data; + + int status = uv_queue_work(uv_default_loop(), + req, async_hook_packets, + (uv_after_work_cb)async_hook_packets_after); + + assert(status == 0); + + NanReturnValue(Undefined()); +#endif + NanReturnValue(obj); } +#if 0 +static void +async_hook_packets(uv_work_t *req) { + async_hook_packets_data* data = static_cast(req->data); +} + +static void +async_hook_packets_after(uv_work_t *req) { + NanScope(); + async_hook_packets_data* data = static_cast(req->data); + + if (data->err_msg != "") { + Local err = Exception::Error(NanNew(data->err_msg)); + const unsigned argc = 1; + Local argv[argc] = { err }; + TryCatch try_catch; + data->callback->Call(Context::GetCurrent()->Global(), argc, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + } else { + Local packets = NanNew(); + const unsigned argc = 2; + Local argv[argc] = { + Local::New(Null()), + Local::New(packets) + }; + TryCatch try_catch; + data->callback->Call(Context::GetCurrent()->Global(), argc, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + } + + data->callback.Dispose(); + + delete data; + delete req; +} +#endif + static void hook_packets(void) { CNodeSignals& nodeSignals = GetNodeSignals();