net: treat services as a u32.
This commit is contained in:
parent
dd6bd8db4a
commit
943c5d2d12
@ -280,6 +280,7 @@ HostList.prototype.add = function add(addr, src) {
|
|||||||
|
|
||||||
// Update services.
|
// Update services.
|
||||||
entry.addr.services |= addr.services;
|
entry.addr.services |= addr.services;
|
||||||
|
entry.addr.services >>>= 0;
|
||||||
|
|
||||||
// Online?
|
// Online?
|
||||||
if (now - addr.ts < 24 * 60 * 60)
|
if (now - addr.ts < 24 * 60 * 60)
|
||||||
@ -509,6 +510,8 @@ HostList.prototype.markAck = function markAck(hostname, services) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
entry.addr.services |= services;
|
entry.addr.services |= services;
|
||||||
|
entry.addr.services >>>= 0;
|
||||||
|
|
||||||
entry.lastSuccess = now;
|
entry.lastSuccess = now;
|
||||||
entry.lastAttempt = now;
|
entry.lastAttempt = now;
|
||||||
entry.attempts = 0;
|
entry.attempts = 0;
|
||||||
@ -1025,12 +1028,14 @@ HostEntry.prototype.fromJSON = function fromJSON(json, network) {
|
|||||||
if (json.services != null) {
|
if (json.services != null) {
|
||||||
assert(typeof json.services === 'string');
|
assert(typeof json.services === 'string');
|
||||||
assert(json.services.length > 0);
|
assert(json.services.length > 0);
|
||||||
assert(json.services.length < 64);
|
assert(json.services.length <= 32);
|
||||||
this.addr.services = parseInt(json.services, 2);
|
this.addr.services = parseInt(json.services, 2);
|
||||||
|
assert(util.isUInt32(this.addr.services));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.ts != null) {
|
if (json.ts != null) {
|
||||||
assert(util.isNumber(json.ts));
|
assert(util.isNumber(json.ts));
|
||||||
|
assert(json.ts >= 0);
|
||||||
this.addr.ts = json.ts;
|
this.addr.ts = json.ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1041,16 +1046,19 @@ HostEntry.prototype.fromJSON = function fromJSON(json, network) {
|
|||||||
|
|
||||||
if (json.attempts != null) {
|
if (json.attempts != null) {
|
||||||
assert(util.isNumber(json.attempts));
|
assert(util.isNumber(json.attempts));
|
||||||
|
assert(json.attempts >= 0);
|
||||||
this.attempts = json.attempts;
|
this.attempts = json.attempts;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.lastSuccess != null) {
|
if (json.lastSuccess != null) {
|
||||||
assert(util.isNumber(json.lastSuccess));
|
assert(util.isNumber(json.lastSuccess));
|
||||||
|
assert(json.lastSuccess >= 0);
|
||||||
this.lastSuccess = json.lastSuccess;
|
this.lastSuccess = json.lastSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.lastAttempt != null) {
|
if (json.lastAttempt != null) {
|
||||||
assert(util.isNumber(json.lastAttempt));
|
assert(util.isNumber(json.lastAttempt));
|
||||||
|
assert(json.lastAttempt >= 0);
|
||||||
this.lastAttempt = json.lastAttempt;
|
this.lastAttempt = json.lastAttempt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -250,7 +250,8 @@ VersionPacket.prototype.getSize = function getSize() {
|
|||||||
|
|
||||||
VersionPacket.prototype.toWriter = function toWriter(bw) {
|
VersionPacket.prototype.toWriter = function toWriter(bw) {
|
||||||
bw.write32(this.version);
|
bw.write32(this.version);
|
||||||
bw.writeU64(this.services);
|
bw.writeU32(this.services);
|
||||||
|
bw.writeU32(0);
|
||||||
bw.write64(this.ts);
|
bw.write64(this.ts);
|
||||||
this.recv.toWriter(bw, false);
|
this.recv.toWriter(bw, false);
|
||||||
this.from.toWriter(bw, false);
|
this.from.toWriter(bw, false);
|
||||||
@ -344,7 +345,12 @@ VersionPacket.prototype.hasCompact = function hasCompact() {
|
|||||||
|
|
||||||
VersionPacket.prototype.fromReader = function fromReader(br) {
|
VersionPacket.prototype.fromReader = function fromReader(br) {
|
||||||
this.version = br.read32();
|
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.ts = br.read53();
|
||||||
this.recv.fromReader(br, false);
|
this.recv.fromReader(br, false);
|
||||||
|
|
||||||
|
|||||||
@ -302,10 +302,16 @@ NetAddress.fromSocket = function fromSocket(hostname, network) {
|
|||||||
|
|
||||||
NetAddress.prototype.fromReader = function fromReader(br, full) {
|
NetAddress.prototype.fromReader = function fromReader(br, full) {
|
||||||
this.ts = full ? br.readU32() : 0;
|
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.host = IP.toString(br.readBytes(16, true));
|
||||||
this.port = br.readU16BE();
|
this.port = br.readU16BE();
|
||||||
this.hostname = IP.hostname(this.host, this.port);
|
this.hostname = IP.hostname(this.host, this.port);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -353,7 +359,8 @@ NetAddress.prototype.toWriter = function toWriter(bw, full) {
|
|||||||
if (full)
|
if (full)
|
||||||
bw.writeU32(this.ts);
|
bw.writeU32(this.ts);
|
||||||
|
|
||||||
bw.writeU64(this.services);
|
bw.writeU32(this.services);
|
||||||
|
bw.writeU32(0);
|
||||||
bw.writeBytes(IP.toBuffer(this.host));
|
bw.writeBytes(IP.toBuffer(this.host));
|
||||||
bw.writeU16BE(this.port);
|
bw.writeU16BE(this.port);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user