Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new bootstrap nodes; sort order for dialing discovered ma's #246

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 =
/(^127\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^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;
trungnotchung marked this conversation as resolved.
Show resolved Hide resolved
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.