more packet polling.

This commit is contained in:
Christopher Jeffrey 2014-10-21 18:51:05 -07:00
parent 5c6b4e11fb
commit 677df7f787
3 changed files with 27 additions and 8 deletions

View File

@ -113,6 +113,12 @@ bitcoind.on('open', function(status) {
}); });
} }
bitcoind.on('packets', function(packets) {
bitcoind.log(packets);
});
return;
argv['on-block'] = true; argv['on-block'] = true;
setTimeout(function() { setTimeout(function() {
bitcoind.on('block', function callee(block) { bitcoind.on('block', function callee(block) {

View File

@ -140,8 +140,15 @@ Bitcoin.prototype.start = function(options, callback) {
setInterval(function() { setInterval(function() {
var packets = bitcoindjs.hookPackets(); var packets = bitcoindjs.hookPackets();
console.log(packets); if (!packets.length) return;
}, 20); self.emit('packets', packets);
packets.forEach(function(packet) {
setImmediate(function() {
self.emit('packet:' + packet.name, packet);
self.emit('packet', packet);
});
});
}, 50);
[sigint, sighup, sigquit].forEach(function(signal) { [sigint, sighup, sigquit].forEach(function(signal) {
process.on(signal.name, signal.listener = function() { process.on(signal.name, signal.listener = function() {

View File

@ -3378,7 +3378,6 @@ boost::mutex poll_packets_mutex;
/** /**
* HookPackets() * HookPackets()
* bitcoind.hookPackets(callback) * bitcoind.hookPackets(callback)
* NOTE: THIS NEEDS A MUTEX XXXXXXXXXX
*/ */
NAN_METHOD(HookPackets) { NAN_METHOD(HookPackets) {
@ -3392,15 +3391,22 @@ NAN_METHOD(HookPackets) {
poll_packets_mutex.lock(); poll_packets_mutex.lock();
for (cur = packets_queue_head; cur; cur = next) { for (cur = packets_queue_head; cur; cur = next) {
//obj->Set(i, NanNew<String>(cur->strCommand.c_str())); Local<Object> o = NanNew<Object>();
obj->Set(i, NanNew<String>(cur->strCommand));
o->Set(NanNew<String>("name"), NanNew<String>(cur->strCommand));
o->Set(NanNew<String>("received"), NanNew<Number>((int64_t)cur->nTimeReceived));
obj->Set(i, o);
i++; i++;
if (cur == packets_queue_head) { if (cur == packets_queue_head) {
packets_queue_head = NULL; packets_queue_head = NULL;
} }
if (cur == packets_queue_tail) { if (cur == packets_queue_tail) {
packets_queue_tail = NULL; packets_queue_tail = NULL;
} }
next = cur->next; next = cur->next;
// delete cur->pfrom; // cleaned up elsewhere? C++ I DON'T UNDERSTAND YOU // delete cur->pfrom; // cleaned up elsewhere? C++ I DON'T UNDERSTAND YOU
free(cur->strCommand); free(cur->strCommand);
@ -3427,9 +3433,9 @@ static bool
process_packets(CNode* pfrom) { process_packets(CNode* pfrom) {
bool fOk = true; bool fOk = true;
if (!pfrom->vRecvGetData.empty()) { // if (!pfrom->vRecvGetData.empty()) {
return process_getdata(pfrom); // return process_getdata(pfrom);
} // }
std::deque<CNetMessage>::iterator it = pfrom->vRecvMsg.begin(); std::deque<CNetMessage>::iterator it = pfrom->vRecvMsg.begin();
while (!pfrom->fDisconnect && it != pfrom->vRecvMsg.end()) { while (!pfrom->fDisconnect && it != pfrom->vRecvMsg.end()) {