Skip to content

Commit

Permalink
feat: add new bootstrap nodes; sort order for dialing discovered ma's (
Browse files Browse the repository at this point in the history
  • Loading branch information
d-roak authored Nov 12, 2024
1 parent 2fc751a commit 02a2e65
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
23 changes: 20 additions & 3 deletions packages/network/src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export class TopologyNetworkNode {
const _bootstrapNodesList = this._config?.bootstrap_peers
? this._config.bootstrap_peers
: [
"/dns4/relay.droak.sh/tcp/443/wss/p2p/Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP",
"/dns4/bootstrap1.topology.gg/tcp/443/wss/p2p/12D3KooWBu1pZ3v2u6tXSmkN35kiMLENpv3bEXcyT1GJTVhipAkG",
"/dns4/bootstrap2.topology.gg/tcp/443/wss/p2p/12D3KooWLGuTtCHLpd1SBHeyvzT3kHVe2dw8P7UdoXsfQHu8qvkf",
];

const _pubsubPeerDiscovery = pubsubPeerDiscovery({
Expand Down Expand Up @@ -149,9 +150,25 @@ export class TopologyNetworkNode {
);
this._node.addEventListener("peer:discovery", (e) => {
// current bug in v11.0.0 requires manual dial (https://github.com/libp2p/js-libp2p-pubsub-peer-discovery/issues/149)
for (const ma of e.detail.multiaddrs) {
this._node?.dial(ma);
const sortedAddrs = e.detail.multiaddrs.sort((a, b) => {
const localRegex =
/(^\/ip4\/127\.)|(^\/ip4\/10\.)|(^\/ip4\/172\.1[6-9]\.)|(^\/ip4\/172\.2[0-9]\.)|(^\/ip4\/172\.3[0-1]\.)|(^\/ip4\/192\.168\.)/;
const aLocal = localRegex.test(a.toString());
const bLocal = localRegex.test(b.toString());
const aWebrtc = a.toString().includes("/webrtc/");
const bWebrtc = b.toString().includes("/webrtc/");
if (aLocal && !bLocal) return 1;
if (!aLocal && bLocal) return -1;
if (aWebrtc && !bWebrtc) return -1;
if (!aWebrtc && bWebrtc) return 1;
return 0;
});

// Dial non-local multiaddrs, then WebRTC multiaddrs
for (const address of sortedAddrs) {
this._node?.dial(address);
}

log.info("::start::peer::discovery", e.detail);
});
this._node.addEventListener("peer:identify", (e) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = "0.2.1";
export const VERSION = "0.3.0";
44 changes: 22 additions & 22 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 02a2e65

Please sign in to comment.