|
|
var log=require("../util/log"),networks=require("../networks"),Address=require("./Address"),Peer=require("./Peer"),PeerManager=require("./PeerManager"),util=require("util"),EventEmitter=require("events").EventEmitter,preconditions=require("preconditions").singleton(),NetworkMonitor=function(e){preconditions.checkArgument(e),this.peerman=e,this.networkName=e.config.network,this.init()};util.inherits(NetworkMonitor,EventEmitter),NetworkMonitor.create=function(e){var t=new PeerManager({network:e.networkName});return t.addPeer(new Peer(e.host,e.port)),new NetworkMonitor(t)},NetworkMonitor.prototype.init=function(){var e=this,t=function(e){var t=e.message.invs;e.conn.sendGetData(t)},n=function(t){e.emit("block",t.message)},o=function(t){var n=t.message.tx;e.emit("tx",n);for(var o=n.getSendingAddresses(e.networkName),r=0;r<o.length;r++){var i=o[r];e.emit("out:"+i,n)}for(var s=n.getReceivingAddresses(e.networkName),r=0;r<s.length;r++){var i=s[r];e.emit("in:"+i,n)}};this.peerman.on("connection",function(r){if(e.connection)throw new Error("Cant handle more than one connection");e.connection=r,r.on("inv",t),r.on("block",n),r.on("tx",o)})},NetworkMonitor.prototype.incoming=function(e,t){preconditions.checkArgument(Address.validate(e)),this.on("in:"+e,t)},NetworkMonitor.prototype.outgoing=function(e,t){preconditions.checkArgument(Address.validate(e)),this.on("out:"+e,t)},NetworkMonitor.prototype.start=function(){this.peerman.start()},NetworkMonitor.prototype.stop=function(){this.peerman.stop()},module.exports=NetworkMonitor; |
|
|
var log=require("../util/log"),networks=require("../networks"),Address=require("./Address"),Peer=require("./Peer"),PeerManager=require("./PeerManager"),util=require("util"),EventEmitter=require("events").EventEmitter,preconditions=require("preconditions").singleton(),NetworkMonitor=function(e){preconditions.checkArgument(e),this.peerman=e,this.networkName=e.config.network,this.init()};util.inherits(NetworkMonitor,EventEmitter),NetworkMonitor.create=function(e){this.config=e;var t=new PeerManager({network:e.networkName});return t.addPeer(new Peer(e.host,e.port)),new NetworkMonitor(t)},NetworkMonitor.prototype.init=function(){var e=this,t=function(e){var t=e.message.invs;e.conn.sendGetData(t)},n=function(t){e.emit("block",t.message)},o=function(t){var n=t.message.tx;e.emit("tx",n);for(var o=n.getSendingAddresses(e.config.networkName),r=0;r<o.length;r++){var i=o[r];e.emit("out:"+i,n)}for(var s=n.getReceivingAddresses(e.config.networkName),r=0;r<s.length;r++){var i=s[r];e.emit("in:"+i,n)}};this.peerman.on("connection",function(r){if(e.connection)throw new Error("Cant handle more than one connection");e.connection=r,r.on("inv",t),r.on("block",n),r.on("tx",o)})},NetworkMonitor.prototype.incoming=function(e,t){preconditions.checkArgument(Address.validate(e)),this.on("in:"+e,t)},NetworkMonitor.prototype.outgoing=function(e,t){preconditions.checkArgument(Address.validate(e)),this.on("out:"+e,t)},NetworkMonitor.prototype.start=function(){this.peerman.start()},NetworkMonitor.prototype.stop=function(){this.peerman.stop()},module.exports=NetworkMonitor; |
|
|
},{"../networks":"ULNIu2","../util/log":"AdF7pF","./Address":"G+CcXD","./Peer":"oolY81","./PeerManager":"nsqKeP","events":"T9Wsc/","preconditions":161,"util":126}],"./lib/NetworkMonitor":[function(require,module,exports){ |
|
|
},{"../networks":"ULNIu2","../util/log":"AdF7pF","./Address":"G+CcXD","./Peer":"oolY81","./PeerManager":"nsqKeP","events":"T9Wsc/","preconditions":161,"util":126}],"./lib/NetworkMonitor":[function(require,module,exports){ |