net: Fix connectedGroup filter.
This commit is contained in:
parent
5fc3122307
commit
c96b6ecda9
3 changed files with 20 additions and 14 deletions
|
|
@ -249,12 +249,12 @@ class NetAddress extends bio.Struct {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the canonical identifier of our network group
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
* Get the canonical identifier of our network group
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
getGroup() {
|
||||
return groupKey(this.raw);
|
||||
return groupKey(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -542,7 +542,14 @@ NetAddress.DEFAULT_SERVICES = 0
|
|||
* Helpers
|
||||
*/
|
||||
|
||||
function groupKey(raw) {
|
||||
/**
|
||||
* @param {NetAddress} addr
|
||||
* @returns {Number}
|
||||
*/
|
||||
|
||||
function groupKey(addr) {
|
||||
const raw = addr.raw;
|
||||
|
||||
// See: https://github.com/bitcoin/bitcoin/blob/e258ce7/src/netaddress.cpp#L413
|
||||
// Todo: Use IP->ASN mapping, see:
|
||||
// https://github.com/bitcoin/bitcoin/blob/adea5e1/src/addrman.h#L274
|
||||
|
|
@ -551,25 +558,25 @@ function groupKey(raw) {
|
|||
let bits = 16;
|
||||
let i = 0;
|
||||
|
||||
if (IP.isLocal(raw)) {
|
||||
if (addr.isLocal()) {
|
||||
type = 255; // NET_LOCAL
|
||||
bits = 0;
|
||||
} else if (!IP.isRoutable(raw)) {
|
||||
} else if (!addr.isRoutable()) {
|
||||
type = IP.networks.NONE; // NET_UNROUTABLE
|
||||
bits = 0;
|
||||
} else if (IP.isIPv4(raw) || IP.isRFC6145(raw) || IP.isRFC6052(raw)) {
|
||||
} else if (addr.isIPv4() || addr.isRFC6145() || addr.isRFC6052()) {
|
||||
type = IP.networks.INET4; // NET_IPV4
|
||||
start = 12;
|
||||
} else if (IP.isRFC3964(raw)) {
|
||||
} else if (addr.isRFC3964()) {
|
||||
type = IP.networks.INET4; // NET_IPV4
|
||||
start = 2;
|
||||
} else if (IP.isRFC4380(raw)) {
|
||||
} else if (addr.isRFC4380()) {
|
||||
const buf = Buffer.alloc(3);
|
||||
buf[0] = IP.networks.INET4; // NET_IPV4
|
||||
buf[1] = raw[12] ^ 0xff;
|
||||
buf[2] = raw[13] ^ 0xff;
|
||||
return buf;
|
||||
} else if (IP.isOnion(raw)) {
|
||||
} else if (addr.isOnion()) {
|
||||
type = IP.networks.ONION; // NET_ONION
|
||||
start = 6;
|
||||
bits = 4;
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class Pool extends EventEmitter {
|
|||
this.pendingFilter = null;
|
||||
this.refillTimer = null;
|
||||
this.discoverTimer = null;
|
||||
this.connectedGroups = new Set();
|
||||
this.connectedGroups = new BufferSet();
|
||||
|
||||
this.checkpoints = false;
|
||||
this.headerChain = new List();
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ const main = Network.get('main');
|
|||
const notAHost = 'not-a-domain.not-a-domain';
|
||||
|
||||
describe('Lookup', function() {
|
||||
this.timeout(10000);
|
||||
it('should lookup seed', async () => {
|
||||
for (const host of main.seeds) {
|
||||
const addresses = await lookup(host);
|
||||
|
|
@ -30,8 +31,6 @@ describe('Lookup', function() {
|
|||
});
|
||||
|
||||
it('should lookup seed', async () => {
|
||||
this.timeout(10000);
|
||||
|
||||
for (const host of main.seeds) {
|
||||
const addresses = await resolve(host);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue