net: treat services as a u32.

This commit is contained in:
Christopher Jeffrey 2016-12-27 15:22:55 -08:00
parent dd6bd8db4a
commit 943c5d2d12
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 26 additions and 5 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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);