mirror of
https://github.com/waku-org/js-waku.git
synced 2025-02-13 12:56:43 +00:00
chore: refactor dns-discovery & add tests (#1084)
* temp-add: debugging * fix: ENR root signature verification the nodes in the TXT/fleet were updated causing the publicKey to change and verification to fail * add: libp2p compliance tests * fix: bind function `bind` was being passed an empty object reference * fix: tests * merge with master * chore: address review - move compliance test to dev dependency - move global mocha timeout to test specific timeout * chore: update enrtree pubkey and fqdn ref: https://github.com/status-im/infra-nim-waku/issues/64 * chore: update libp2p-peer-discovery-compliance-tests ref: https://github.com/libp2p/js-libp2p-interfaces/pull/328 * chore: fix typedoc errors * add: dns-discovery to dependencies
This commit is contained in:
parent
938e7fb962
commit
0b083201c6
14
package-lock.json
generated
14
package-lock.json
generated
@ -2756,9 +2756,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@libp2p/interface-peer-discovery-compliance-tests": {
|
"node_modules/@libp2p/interface-peer-discovery-compliance-tests": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/@libp2p/interface-peer-discovery-compliance-tests/-/interface-peer-discovery-compliance-tests-2.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/@libp2p/interface-peer-discovery-compliance-tests/-/interface-peer-discovery-compliance-tests-2.0.4.tgz",
|
||||||
"integrity": "sha512-tYz2HZ2OWZTxn6E37LSmbomJIyRXs6gDb2RCVhJSQN6Md8pL50rrDNEUNlzjdhkp8NF/3uc+0JaVTg35IVJs6w==",
|
"integrity": "sha512-RxcyOUG0pwV/kCQyQSc0FzUvgg6GMjkBx1obIi3t1E9Bmsc08MPs8uWLAl+QNTB8U0iUkUcyZc94Ek9QPEzeSg==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@libp2p/interface-compliance-tests": "^3.0.0",
|
"@libp2p/interface-compliance-tests": "^3.0.0",
|
||||||
"@libp2p/interface-peer-discovery": "^1.0.0",
|
"@libp2p/interface-peer-discovery": "^1.0.0",
|
||||||
@ -27561,6 +27561,7 @@
|
|||||||
"uint8arrays": "^4.0.2"
|
"uint8arrays": "^4.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@libp2p/interface-peer-discovery-compliance-tests": "^2.0.4",
|
||||||
"@libp2p/peer-id-factory": "^1.0.15",
|
"@libp2p/peer-id-factory": "^1.0.15",
|
||||||
"@multiformats/multiaddr": "^11.0.6",
|
"@multiformats/multiaddr": "^11.0.6",
|
||||||
"@rollup/plugin-commonjs": "^22.0.0",
|
"@rollup/plugin-commonjs": "^22.0.0",
|
||||||
@ -29762,9 +29763,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@libp2p/interface-peer-discovery-compliance-tests": {
|
"@libp2p/interface-peer-discovery-compliance-tests": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/@libp2p/interface-peer-discovery-compliance-tests/-/interface-peer-discovery-compliance-tests-2.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/@libp2p/interface-peer-discovery-compliance-tests/-/interface-peer-discovery-compliance-tests-2.0.4.tgz",
|
||||||
"integrity": "sha512-tYz2HZ2OWZTxn6E37LSmbomJIyRXs6gDb2RCVhJSQN6Md8pL50rrDNEUNlzjdhkp8NF/3uc+0JaVTg35IVJs6w==",
|
"integrity": "sha512-RxcyOUG0pwV/kCQyQSc0FzUvgg6GMjkBx1obIi3t1E9Bmsc08MPs8uWLAl+QNTB8U0iUkUcyZc94Ek9QPEzeSg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@libp2p/interface-compliance-tests": "^3.0.0",
|
"@libp2p/interface-compliance-tests": "^3.0.0",
|
||||||
"@libp2p/interface-peer-discovery": "^1.0.0",
|
"@libp2p/interface-peer-discovery": "^1.0.0",
|
||||||
@ -31761,6 +31762,7 @@
|
|||||||
"version": "file:packages/dns-discovery",
|
"version": "file:packages/dns-discovery",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@libp2p/interface-peer-discovery": "^1.0.0",
|
"@libp2p/interface-peer-discovery": "^1.0.0",
|
||||||
|
"@libp2p/interface-peer-discovery-compliance-tests": "^2.0.4",
|
||||||
"@libp2p/interface-peer-info": "^1.0.1",
|
"@libp2p/interface-peer-info": "^1.0.1",
|
||||||
"@libp2p/interfaces": "^3.0.2",
|
"@libp2p/interfaces": "^3.0.2",
|
||||||
"@libp2p/peer-id": "^1.1.10",
|
"@libp2p/peer-id": "^1.1.10",
|
||||||
|
@ -82,6 +82,7 @@
|
|||||||
"cspell": "^6.17.0",
|
"cspell": "^6.17.0",
|
||||||
"eslint": "^8.6.0",
|
"eslint": "^8.6.0",
|
||||||
"eslint-config-prettier": "^8.3.0",
|
"eslint-config-prettier": "^8.3.0",
|
||||||
|
"@libp2p/interface-peer-discovery-compliance-tests": "^2.0.4",
|
||||||
"eslint-plugin-eslint-comments": "^3.2.0",
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
||||||
"eslint-plugin-functional": "^4.0.2",
|
"eslint-plugin-functional": "^4.0.2",
|
||||||
"eslint-plugin-import": "^2.25.3",
|
"eslint-plugin-import": "^2.25.3",
|
||||||
|
@ -260,7 +260,7 @@ describe("DNS Node Discovery w/ capabilities", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("DNS Node Discovery [live data]", function () {
|
describe("DNS Node Discovery [live data]", function () {
|
||||||
const publicKey = "AOFTICU2XWDULNLZGRMQS4RIZPAZEHYMV4FYHAPW563HNRAOERP7C";
|
const publicKey = "AOGECG2SPND25EEFMAJ5WF3KSGJNSGV356DSTL2YVLLZWIV6SAYBM";
|
||||||
const fqdn = "test.waku.nodes.status.im";
|
const fqdn = "test.waku.nodes.status.im";
|
||||||
const enrTree = `enrtree://${publicKey}@${fqdn}`;
|
const enrTree = `enrtree://${publicKey}@${fqdn}`;
|
||||||
const maxQuantity = 3;
|
const maxQuantity = 3;
|
||||||
|
@ -42,10 +42,10 @@ export class DnsNodeDiscovery {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of verified peers listed in an EIP-1459 DNS tree. Method may
|
* Returns a list of verified peers listed in an EIP-1459 DNS tree. Method may
|
||||||
* return fewer peers than requested if [[wantedNodeCapabilityCount]] requires
|
* return fewer peers than requested if @link wantedNodeCapabilityCount requires
|
||||||
* larger quantity of peers than available or the number of errors/duplicate
|
* larger quantity of peers than available or the number of errors/duplicate
|
||||||
* peers encountered by randomized search exceeds the sum of the fields of
|
* peers encountered by randomized search exceeds the sum of the fields of
|
||||||
* [[wantedNodeCapabilityCount]] plus the [[_errorTolerance]] factor.
|
* @link wantedNodeCapabilityCount plus the @link _errorTolerance factor.
|
||||||
*/
|
*/
|
||||||
async getPeers(
|
async getPeers(
|
||||||
enrTreeUrls: string[],
|
enrTreeUrls: string[],
|
||||||
@ -82,7 +82,7 @@ export class DnsNodeDiscovery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@docInherit getPeers}
|
* {@inheritDoc getPeers}
|
||||||
*/
|
*/
|
||||||
async *getNextPeer(
|
async *getNextPeer(
|
||||||
enrTreeUrls: string[],
|
enrTreeUrls: string[],
|
||||||
|
@ -39,6 +39,7 @@ export class ENRTree {
|
|||||||
// of the record content, excluding the `sig=` part, encoded as URL-safe base64 string
|
// of the record content, excluding the `sig=` part, encoded as URL-safe base64 string
|
||||||
// (Trailing recovery bit must be trimmed to pass `ecdsaVerify` method)
|
// (Trailing recovery bit must be trimmed to pass `ecdsaVerify` method)
|
||||||
const signedComponent = root.split(" sig")[0];
|
const signedComponent = root.split(" sig")[0];
|
||||||
|
|
||||||
const signedComponentBuffer = utf8ToBytes(signedComponent);
|
const signedComponentBuffer = utf8ToBytes(signedComponent);
|
||||||
const signatureBuffer = fromString(rootValues.signature, "base64url").slice(
|
const signatureBuffer = fromString(rootValues.signature, "base64url").slice(
|
||||||
0,
|
0,
|
||||||
|
@ -42,7 +42,7 @@ export class PeerDiscoveryDns
|
|||||||
const dns = DnsNodeDiscovery.dnsOverHttp();
|
const dns = DnsNodeDiscovery.dnsOverHttp();
|
||||||
|
|
||||||
this.nextPeer = dns.getNextPeer.bind(
|
this.nextPeer = dns.getNextPeer.bind(
|
||||||
{},
|
dns,
|
||||||
[enrUrl],
|
[enrUrl],
|
||||||
wantedNodeCapabilityCount
|
wantedNodeCapabilityCount
|
||||||
);
|
);
|
||||||
@ -81,3 +81,12 @@ export class PeerDiscoveryDns
|
|||||||
return "@waku/bootstrap";
|
return "@waku/bootstrap";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function wakuDnsDiscovery(
|
||||||
|
enrUrl: string,
|
||||||
|
wantedNodeCapabilityCount: Partial<NodeCapabilityCount>
|
||||||
|
): () => PeerDiscoveryDns {
|
||||||
|
return () => new PeerDiscoveryDns(enrUrl, wantedNodeCapabilityCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { DnsNodeDiscovery, SearchContext, DnsClient } from "./dns.js";
|
||||||
|
@ -68,7 +68,8 @@
|
|||||||
"@waku/enr": "*",
|
"@waku/enr": "*",
|
||||||
"@waku/interfaces": "*",
|
"@waku/interfaces": "*",
|
||||||
"@waku/message-encryption": "*",
|
"@waku/message-encryption": "*",
|
||||||
"@waku/peer-exchange": "*"
|
"@waku/peer-exchange": "*",
|
||||||
|
"@waku/dns-discovery": "*"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@libp2p/bootstrap": "^5.0.0",
|
"@libp2p/bootstrap": "^5.0.0",
|
||||||
|
78
packages/tests/tests/dns-peer-discovery.spec.ts
Normal file
78
packages/tests/tests/dns-peer-discovery.spec.ts
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
import tests from "@libp2p/interface-peer-discovery-compliance-tests";
|
||||||
|
import { createLightNode } from "@waku/create";
|
||||||
|
import { DnsNodeDiscovery, wakuDnsDiscovery } from "@waku/dns-discovery";
|
||||||
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
const publicKey = "AOGECG2SPND25EEFMAJ5WF3KSGJNSGV356DSTL2YVLLZWIV6SAYBM";
|
||||||
|
const fqdn = "test.waku.nodes.status.im";
|
||||||
|
const enrTree = `enrtree://${publicKey}@${fqdn}`;
|
||||||
|
const maxQuantity = 3;
|
||||||
|
|
||||||
|
describe("DNS Discovery: Compliance Test", async function () {
|
||||||
|
this.timeout(5000);
|
||||||
|
tests({
|
||||||
|
async setup() {
|
||||||
|
return wakuDnsDiscovery(enrTree, {
|
||||||
|
filter: 1,
|
||||||
|
})();
|
||||||
|
},
|
||||||
|
async teardown() {
|
||||||
|
//
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("DNS Node Discovery [live data]", function () {
|
||||||
|
before(function () {
|
||||||
|
if (process.env.CI) {
|
||||||
|
this.skip();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should use DNS peer discovery with light client`, async function () {
|
||||||
|
this.timeout(100000);
|
||||||
|
const maxQuantity = 3;
|
||||||
|
|
||||||
|
const nodeRequirements = {
|
||||||
|
relay: maxQuantity,
|
||||||
|
store: maxQuantity,
|
||||||
|
filter: maxQuantity,
|
||||||
|
lightPush: maxQuantity,
|
||||||
|
};
|
||||||
|
|
||||||
|
const waku = await createLightNode({
|
||||||
|
libp2p: {
|
||||||
|
peerDiscovery: [wakuDnsDiscovery(enrTree, nodeRequirements)],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await waku.start();
|
||||||
|
|
||||||
|
const peersFound = await waku.libp2p.peerStore.all();
|
||||||
|
expect(peersFound.length).to.eq(maxQuantity);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should retrieve ${maxQuantity} multiaddrs for prod.nodes.status.im`, async function () {
|
||||||
|
this.timeout(10000);
|
||||||
|
// Google's dns server address. Needs to be set explicitly to run in CI
|
||||||
|
const dnsNodeDiscovery = DnsNodeDiscovery.dnsOverHttp();
|
||||||
|
|
||||||
|
const peers = await dnsNodeDiscovery.getPeers([enrTree], {
|
||||||
|
relay: maxQuantity,
|
||||||
|
store: maxQuantity,
|
||||||
|
filter: maxQuantity,
|
||||||
|
lightPush: maxQuantity,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(peers.length).to.eq(maxQuantity);
|
||||||
|
|
||||||
|
const multiaddrs = peers.map((peer) => peer.multiaddrs).flat();
|
||||||
|
|
||||||
|
const seen: string[] = [];
|
||||||
|
for (const ma of multiaddrs) {
|
||||||
|
expect(ma).to.not.be.undefined;
|
||||||
|
expect(seen).to.not.include(ma!.toString());
|
||||||
|
seen.push(ma!.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user