framer: refactor.

Signed-off-by: Fedor Indutny <fedor@indutny.com>
This commit is contained in:
Christopher Jeffrey 2014-05-19 19:36:02 -05:00 committed by Fedor Indutny
parent 44fab2b58a
commit 793fed1974
3 changed files with 12 additions and 12 deletions

View File

@ -18,6 +18,7 @@ function Peer(pool, createSocket, options) {
EventEmitter.call(this);
this.options = options || {};
this.pool = pool;
this.socket = null;
this.parser = new bcoin.protocol.parser();
@ -27,9 +28,8 @@ function Peer(pool, createSocket, options) {
this.version = null;
this.destroyed = false;
this.ack = false;
this.ts = null;
this.ts = this.options.ts || 0;
this.options = options || {};
if (this.options.backoff) {
var self = this;
setTimeout(function() {

View File

@ -325,32 +325,32 @@ Framer.prototype.merkleBlock = function merkleBlock(block) {
Framer.prototype.addr = function addr(peers) {
var p = [];
var i = 0;
var c = 0;
var off = 0;
var peer;
var start = (Date.now() / 1000 | 0) - process.uptime();
// count
c += varint(p, peers.length, c);
off += varint(p, peers.length, off);
for (; i < peers.length; i++) {
peer = peers[i];
// timestamp
c += utils.writeU32(p, peer.ts || start, c);
off += utils.writeU32(p, peer.ts || start, off);
// NODE_NETWORK service
c += utils.writeU64(p, 1, c);
off += utils.writeU64(p, 1, off);
// ipv6
c += utils.writeU32BE(p, utils.readU32BE(peer.ipv6, 4), c);
c += utils.writeU32BE(p, utils.readU32BE(peer.ipv6, 8), c);
c += utils.writeU32BE(p, utils.readU32BE(peer.ipv6, 12), c);
off += utils.writeU32BE(p, utils.readU32BE(peer.ipv6, 4), off);
off += utils.writeU32BE(p, utils.readU32BE(peer.ipv6, 8), off);
off += utils.writeU32BE(p, utils.readU32BE(peer.ipv6, 12), off);
// ipv4
c += utils.writeU32BE(p, utils.readU32BE(peer.ipv4, 0), c);
off += utils.writeU32BE(p, utils.readU32BE(peer.ipv4, 0), off);
// port
c += utils.writeU16BE(p, peer.port, c);
off += utils.writeU16BE(p, peer.port, off);
}
return this.packet('addr', p);

View File

@ -365,7 +365,7 @@ Parser.prototype.parseAddr = function parseAddr(p) {
p = p.slice(off);
for (i = 0; i < count; i++) {
// ts - LE
// timestamp - LE
ts = utils.readU32(p, 0);
// NODE_NETWORK service - LE