Created
March 5, 2019 23:34
-
-
Save pinheadmz/13cf27ce7b58a526bb2cf8dc9d0da17b 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) => { | |
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