diff --git a/lib/net/hostlist.js b/lib/net/hostlist.js index 8e035e16..6e2a8dbe 100644 --- a/lib/net/hostlist.js +++ b/lib/net/hostlist.js @@ -280,6 +280,7 @@ HostList.prototype.add = function add(addr, src) { // Update services. entry.addr.services |= addr.services; + entry.addr.services >>>= 0; // Online? if (now - addr.ts < 24 * 60 * 60) @@ -509,6 +510,8 @@ HostList.prototype.markAck = function markAck(hostname, services) { return; entry.addr.services |= services; + entry.addr.services >>>= 0; + entry.lastSuccess = now; entry.lastAttempt = now; entry.attempts = 0; @@ -1025,12 +1028,14 @@ HostEntry.prototype.fromJSON = function fromJSON(json, network) { if (json.services != null) { assert(typeof json.services === 'string'); assert(json.services.length > 0); - assert(json.services.length < 64); + assert(json.services.length <= 32); this.addr.services = parseInt(json.services, 2); + assert(util.isUInt32(this.addr.services)); } if (json.ts != null) { assert(util.isNumber(json.ts)); + assert(json.ts >= 0); this.addr.ts = json.ts; } @@ -1041,16 +1046,19 @@ HostEntry.prototype.fromJSON = function fromJSON(json, network) { if (json.attempts != null) { assert(util.isNumber(json.attempts)); + assert(json.attempts >= 0); this.attempts = json.attempts; } if (json.lastSuccess != null) { assert(util.isNumber(json.lastSuccess)); + assert(json.lastSuccess >= 0); this.lastSuccess = json.lastSuccess; } if (json.lastAttempt != null) { assert(util.isNumber(json.lastAttempt)); + assert(json.lastAttempt >= 0); this.lastAttempt = json.lastAttempt; } diff --git a/lib/net/packets.js b/lib/net/packets.js index f2c3132f..1fbabf4f 100644 --- a/lib/net/packets.js +++ b/lib/net/packets.js @@ -250,7 +250,8 @@ VersionPacket.prototype.getSize = function getSize() { VersionPacket.prototype.toWriter = function toWriter(bw) { bw.write32(this.version); - bw.writeU64(this.services); + bw.writeU32(this.services); + bw.writeU32(0); bw.write64(this.ts); this.recv.toWriter(bw, false); this.from.toWriter(bw, false); @@ -344,7 +345,12 @@ VersionPacket.prototype.hasCompact = function hasCompact() { VersionPacket.prototype.fromReader = function fromReader(br) { this.version = br.read32(); - this.services = br.readU53(); + this.services = br.readU32(); + + // Note: hi service bits + // are currently unused. + br.readU32(); + this.ts = br.read53(); this.recv.fromReader(br, false); diff --git a/lib/primitives/netaddress.js b/lib/primitives/netaddress.js index 648f3fd1..47a4bb8c 100644 --- a/lib/primitives/netaddress.js +++ b/lib/primitives/netaddress.js @@ -302,10 +302,16 @@ NetAddress.fromSocket = function fromSocket(hostname, network) { NetAddress.prototype.fromReader = function fromReader(br, full) { this.ts = full ? br.readU32() : 0; - this.services = br.readU53(); + this.services = br.readU32(); + + // Note: hi service bits + // are currently unused. + br.readU32(); + this.host = IP.toString(br.readBytes(16, true)); this.port = br.readU16BE(); this.hostname = IP.hostname(this.host, this.port); + return this; }; @@ -353,7 +359,8 @@ NetAddress.prototype.toWriter = function toWriter(bw, full) { if (full) bw.writeU32(this.ts); - bw.writeU64(this.services); + bw.writeU32(this.services); + bw.writeU32(0); bw.writeBytes(IP.toBuffer(this.host)); bw.writeU16BE(this.port);