Comparing version 0.0.1 to 0.0.2
@@ -131,3 +131,3 @@ var crypto = require('crypto'); | ||
var signature = decypted.slice(0, 64); | ||
var recId = decypted.slice(64, 65); | ||
const recId = decypted.slice(64, 65); | ||
var hepubk = decypted.slice(65, 65 + 32); | ||
@@ -134,0 +134,0 @@ var pubKey = this.remotePubKey = decypted.slice(65 + 32, 65 + 32 + 64); |
@@ -65,4 +65,9 @@ const net = require('net'); | ||
this.dpt.on('error', function(a, e){ | ||
console.log('dpt errot'); | ||
console.log(e); | ||
console.log('dpt error'); | ||
console.log(a); | ||
console.log(e.stack); | ||
}); | ||
this.dpt.on('newPeer', function(peer){ | ||
self.connect(peer); | ||
}) | ||
@@ -102,8 +107,7 @@ | ||
* @param {Function} cb the callback | ||
* TODO: fix `cb` | ||
*/ | ||
Network.prototype.connect = function(peer, cb) { | ||
if (!cb) { | ||
cb = function() {}; | ||
} | ||
if (!cb) cb = function() {}; | ||
@@ -122,3 +126,4 @@ var self = this; | ||
} | ||
socket.setTimeout(this.timeout); | ||
socket.setTimeout(self.timeout); | ||
socket.on('timeout', onError); | ||
@@ -128,2 +133,3 @@ socket.on('error', onError); | ||
self._onConnect(socket, peer.id, true); | ||
socket.removeListener('error', onError); | ||
cb(); | ||
@@ -143,3 +149,3 @@ }); | ||
port: peer.port | ||
}, onId); | ||
}, cb); | ||
} else { | ||
@@ -155,3 +161,2 @@ onId(null, peer); | ||
Network.prototype._onConnect = function(socket, id, outgoing) { | ||
var self = this; | ||
@@ -166,4 +171,11 @@ var openSlots = this.maxPeers - this.peers.length; | ||
var peer = new Peer(socket, self, id); | ||
self._peers[id] = peer; | ||
if(!id){ | ||
peer.on('connection', function(){ | ||
self._peers[peer.id.toString('hex')] = peer; | ||
}); | ||
}else{ | ||
self._peers[id.toString('hex')] = peer; | ||
} | ||
//disconnect delete peers | ||
@@ -173,4 +185,4 @@ socket.on('close', function() { | ||
//delete refrances to the peer | ||
delete self._peers[id]; | ||
self._popPeerList(); | ||
delete self._peers[peer.id.toString('hex')]; | ||
}); | ||
@@ -202,3 +214,3 @@ | ||
//0x08 Client quitting. | ||
peer.disconnect(0x08, function() { | ||
peer.sendDisconnect(0x08, function() { | ||
peer.socket.end(); | ||
@@ -228,19 +240,23 @@ }); | ||
// if (openSlots > 0 && !this._stopping) { | ||
// //tough; | ||
// var peers = self.dpt.kBucket.toArray(); | ||
// var i = openSlots; | ||
// var q = async.queue(function (peer, cb) { | ||
// self.connect(peer, function(err){ | ||
// if(err){ | ||
// i++; | ||
// q.push(peers[i]) | ||
// } | ||
// cb(); | ||
// }) | ||
// }, openSlots); | ||
if (openSlots > 0 && !this._stopping) { | ||
//find peer that we are not already connected to | ||
var peers = self.dpt.kBucket.toArray().filter(function(p){ | ||
return !self._peers[p.id.toString('hex')]; | ||
}); | ||
// q.push(peers.slice(0, openSlots)); | ||
// } | ||
var i = openSlots; | ||
var q = async.queue(function (peer, cb) { | ||
self.connect(peer, function(err){ | ||
if(err){ | ||
i++; | ||
if(peers[i]){ | ||
q.push(peers[i]) | ||
} | ||
} | ||
cb(); | ||
}) | ||
}, openSlots); | ||
q.push(peers.slice(0, openSlots)); | ||
} | ||
}; |
@@ -34,2 +34,3 @@ const util = require('util'); | ||
this.initiator = true; //did this peer start the connection | ||
this.DISCONNECT_REASONS = Peer.disconnectReasons; | ||
@@ -79,5 +80,3 @@ this.eciesSession = new ECIES( | ||
socket.on('data', function(newData) { | ||
var more = true; | ||
data = Buffer.concat([data, newData]); | ||
@@ -121,3 +120,2 @@ while (more) { | ||
self._nextPacketSize = 210; | ||
console.log('data sent!'); | ||
}); | ||
@@ -141,2 +139,3 @@ }; | ||
this.eciesSession.parseAuth(data); | ||
this.id = this.eciesSession.remotePubKey.slice(1); | ||
this.sendAck(); | ||
@@ -152,3 +151,2 @@ this.state = 'Header'; | ||
this.sendHello(); | ||
console.log('got ack'); | ||
break; | ||
@@ -159,5 +157,8 @@ | ||
this.state = 'Body'; | ||
this._bodySize = size; | ||
this._nextPacketSize = (32 - (size % 16)) + size; | ||
var remainder = size % 16; | ||
if(remainder){ | ||
this._nextPacketSize = (16 - remainder) + size + 16; | ||
}else{ | ||
this._nextPacketSize = size + 16; | ||
} | ||
break; | ||
@@ -173,6 +174,6 @@ | ||
var type = body.slice(0, 1); | ||
//check for base types | ||
if (type[0] < 0x10 || type[0] === 0x80) { | ||
this.parseBasePacket(type, body.slice(1)); | ||
}else{ | ||
console.log('data!!!'); | ||
this.emit('data', body); | ||
@@ -193,2 +194,3 @@ } | ||
this.hello = this.parseHello(decoded); | ||
this.caps = this.hello.capabilities; | ||
var ourCaps = this.network.capabilities; | ||
@@ -205,2 +207,3 @@ var sharedProto = []; | ||
} | ||
this.emit('connection', this); | ||
this.network.emit('connection', this); | ||
@@ -211,3 +214,2 @@ break; | ||
case 1: | ||
console.log('clse'); | ||
this.emit('close'); | ||
@@ -251,5 +253,3 @@ this.socket.end(); | ||
Peer.prototype.createHello = function() { | ||
var caps = []; | ||
console.log(this.network.capabilities); | ||
for (var cap in this.network.capabilities) { | ||
@@ -267,4 +267,2 @@ caps.push([cap, new Buffer([Number(this.network.capabilities[cap])])]); | ||
var msg = this.parseHello(rlp.decode( rlp.encode(message) ) ); | ||
console.log(msg); | ||
return Buffer.concat([new Buffer([0x80]), rlp.encode(message)]); | ||
@@ -271,0 +269,0 @@ }; |
@@ -12,5 +12,13 @@ const Duplex = require('stream').Duplex; | ||
Duplex.call(this, opts); | ||
this.peer.on('disconnect', function(){ | ||
this.peer.socket.on('end', function(){ | ||
console.log('closeing stream, socket ended'); | ||
self._closed = true; | ||
self.push(null); | ||
}); | ||
this.peer.socket.on('error', function(){ | ||
console.log('closeing stream,error'); | ||
self._closed = true; | ||
self.push(null); | ||
}); | ||
} | ||
@@ -39,7 +47,6 @@ | ||
}) | ||
} else { // we are done, push null to end stream | ||
self.push(null); | ||
} | ||
} | ||
}; | ||
Stream.prototype._write = function(chunk, enc, cb) { | ||
@@ -46,0 +53,0 @@ if(this._prefix){ |
{ | ||
"name": "devp2p", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A javascript libary implementing RPLx the ethereum p2p protocol", | ||
@@ -28,3 +28,3 @@ "main": "index.js", | ||
"bitwise-xor": "0.0.0", | ||
"devp2p-dpt": "0.0.1", | ||
"devp2p-dpt": "0.0.2", | ||
"ecurve": "^1.0.1", | ||
@@ -31,0 +31,0 @@ "ethereumjs-util": "0.1.0", |
@@ -10,3 +10,3 @@ var Network = require('../index.js'); | ||
port: 4447, | ||
host: '0.0.0.0' | ||
host: '127.0.0.1' | ||
}; | ||
@@ -13,0 +13,0 @@ |
@@ -9,6 +9,7 @@ var Network = require('../index.js'); | ||
var stream2; | ||
var internals = { | ||
//test port and host | ||
port: 4447, | ||
host: '0.0.0.0' | ||
host: '127.0.0.1' | ||
}; | ||
@@ -15,0 +16,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36754
1037
+ Addeddevp2p-dpt@0.0.2(transitive)
- Removeddevp2p-dpt@0.0.1(transitive)
Updateddevp2p-dpt@0.0.2