Skip to content

Instantly share code, notes, and snippets.

@pinheadmz
Created March 5, 2019 23:34
Show Gist options
  • Save pinheadmz/13cf27ce7b58a526bb2cf8dc9d0da17b to your computer and use it in GitHub Desktop.
Save pinheadmz/13cf27ce7b58a526bb2cf8dc9d0da17b to your computer and use it in GitHub Desktop.
/*
* Packet sniffer plgin for bcoin
* USAGE:
* bcoin --log-console=false --plugins <path/to/packetsniffer.js>
*/
'use strict';
const EventEmitter = require('events');
const plugin = exports;
class Plugin extends EventEmitter {
constructor(node) {
super();
this.pool = node.pool;
this.init();
}
init() {
this.pool.on('packet', (packet) => {
console.log('-->', packet);
});
this.pool.on('peer open', (peer) => {
console.log(peer);
peer.SEND = peer.send;
peer.send = (packet) => {
console.log('<--', packet);
peer.SEND(packet);
};
});
}
}
plugin.id = 'packetsnoop';
plugin.init = function init(node) {
return new Plugin(node);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment