Created
June 26, 2020 20:25
-
-
Save pinheadmz/4cc2a69f537c1235dfbddbb5b627e018 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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) => { | |
peer.SEND = peer.send; | |
peer.send = (packet) => { | |
console.log('<--', packet); | |
peer.SEND(packet); | |
}; | |
}); | |
this.pool.on('peer connect', (peer) => { | |
peer.SEND = peer.send; | |
peer.send = (packet) => { | |
console.log('<-- peer cnct <--', 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