From 19cc3f7b786adde19a758df076f32f7a5bee8174 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Mon, 28 Oct 2024 23:25:35 +0200 Subject: [PATCH 01/61] Adding the protocol --- packages/network/package.json | 1 + packages/network/src/node.ts | 15 ++++++++-- pnpm-lock.yaml | 53 +++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/packages/network/package.json b/packages/network/package.json index f013867c..79a0cf62 100644 --- a/packages/network/package.json +++ b/packages/network/package.json @@ -42,6 +42,7 @@ "@libp2p/dcutr": "^2.0.6", "@libp2p/devtools-metrics": "^1.1.5", "@libp2p/identify": "^3.0.6", + "@libp2p/kad-dht": "14.0.0", "@libp2p/mdns": "^11.0.8", "@libp2p/peer-id": "^5.0.4", "@libp2p/pubsub-peer-discovery": "^11.0.0", diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 3ac8ead7..1dc44107 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -31,6 +31,7 @@ import { type Libp2p, createLibp2p } from "libp2p"; import { fromString as uint8ArrayFromString } from "uint8arrays/from-string"; import { Message } from "./proto/messages_pb.js"; import { uint8ArrayToStream } from "./stream.js"; +import { kadDHT } from "@libp2p/kad-dht"; export * from "./stream.js"; @@ -67,7 +68,8 @@ export class TopologyNetworkNode { const _bootstrapNodesList = this._config?.bootstrap_peers ? this._config.bootstrap_peers : [ - "/dns4/relay.droak.sh/tcp/443/wss/p2p/Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP", + // "/dns4/relay.droak.sh/tcp/443/wss/p2p/Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP", + "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", ]; const _pubsubPeerDiscovery = pubsubPeerDiscovery({ @@ -77,18 +79,25 @@ export class TopologyNetworkNode { const _peerDiscovery = _bootstrapNodesList.length ? [ - _pubsubPeerDiscovery, + // _pubsubPeerDiscovery, bootstrap({ list: _bootstrapNodesList, }), ] - : [_pubsubPeerDiscovery]; + : [ + // _pubsubPeerDiscovery + ]; const _node_services = { autonat: autoNAT(), dcutr: dcutr(), identify: identify(), pubsub: gossipsub(), + kadDHT: kadDHT({ + protocol : "/topology/dht/1.0.0", + kBucketSize : 50, + clientMode : false, + }) }; const _bootstrap_services = { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a0daff27..bdae7329 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -295,6 +295,9 @@ importers: '@libp2p/identify': specifier: ^3.0.6 version: 3.0.9 + '@libp2p/kad-dht': + specifier: 14.0.0 + version: 14.0.0 '@libp2p/mdns': specifier: ^11.0.8 version: 11.0.9 @@ -1577,6 +1580,9 @@ packages: '@libp2p/interface@2.1.3': resolution: {integrity: sha512-t1i2LWcnTGJEr7fDMslA8wYwBzJP81QKBlrBHoGhXxqqpRQa9035roCh/Akuw5RUgjKE47/ezjuzo90aWsJB8g==} + '@libp2p/kad-dht@14.0.0': + resolution: {integrity: sha512-uPIC5TEvdjCgn4xvsjlOUyCVEGmJIzLM9MW34ReN71lXYF1LP7uRQPGBuF/Of42V5+YVlyPzIFKjo/VxFR/TkQ==} + '@libp2p/logger@5.1.2': resolution: {integrity: sha512-To14ikSC+fnNXO+GkZB/Vj+kOGbdGcdpHdAMxvAWjm69ILDreGUlcDVotnAKVtN2bPAHL3Z0XzqDyKeRI6j73A==} @@ -1604,6 +1610,9 @@ packages: '@libp2p/pubsub@10.0.9': resolution: {integrity: sha512-8f6anvHz2BT3jvMrbkb3P1jlYluk6/0CiBM+9dO9JgItdANmF3uJk7FxZjOTmJAipxxnd7Gglno47AA3xnEEng==} + '@libp2p/record@4.0.4': + resolution: {integrity: sha512-wEEeHXGNIcc8HtGbgGMuSHbboUWMxKG7OxALFwkE+KACgfRJZTESOp6XIdZnyC0r9lfEFsjF01pFKBTzoBmWEQ==} + '@libp2p/simple-metrics@1.2.5': resolution: {integrity: sha512-aOf0NqEQAyJQ55JMWpsYvl+olvSqFF6R0NkzSuK2TVvauGQ5PIqz48hBzZvmxp0JQpFgV8Ma7ECq6Vsg/Uvs8Q==} @@ -3542,6 +3551,9 @@ packages: resolution: {integrity: sha512-kx2UTJuy7/lsT3QUzf50NjfxU1Z4P4wlvYp6YnR5Nc61P8XKfy+QtiJi1VLojA+Kea7vMbB4002rIij1Ol9hcw==} engines: {node: '>=16.0.0', npm: '>=7.0.0'} + it-length@3.0.6: + resolution: {integrity: sha512-R7bxHAzpRzYz7vghc2DDH7x4KXvEkeLfN/h316++jzbkEHIRXbEPLbE20p5yrqqBdOeK6/FRUDuHlTJ0H1hysw==} + it-map@3.1.1: resolution: {integrity: sha512-9bCSwKD1yN1wCOgJ9UOl+46NQtdatosPWzxxUk2NdTLwRPXLh+L7iwCC9QKsbgM60RQxT/nH8bKMqm3H/o8IHQ==} @@ -6831,6 +6843,39 @@ snapshots: progress-events: 1.0.1 uint8arraylist: 2.4.8 + '@libp2p/kad-dht@14.0.0': + dependencies: + '@libp2p/crypto': 5.0.5 + '@libp2p/interface': 2.1.3 + '@libp2p/interface-internal': 2.0.9 + '@libp2p/peer-collections': 6.0.9 + '@libp2p/peer-id': 5.0.6 + '@libp2p/record': 4.0.4 + '@libp2p/utils': 6.1.2 + '@multiformats/multiaddr': 12.3.1 + any-signal: 4.1.1 + hashlru: 2.3.0 + interface-datastore: 8.3.1 + it-drain: 3.0.7 + it-length: 3.0.6 + it-length-prefixed: 9.1.0 + it-map: 3.1.1 + it-merge: 3.0.5 + it-parallel: 3.0.8 + it-pipe: 3.0.1 + it-protobuf-stream: 1.1.5 + it-take: 3.0.6 + multiformats: 13.3.0 + p-defer: 4.0.1 + p-event: 6.0.1 + p-queue: 8.0.1 + progress-events: 1.0.1 + protons-runtime: 5.5.0 + race-signal: 1.1.0 + uint8-varint: 2.0.4 + uint8arraylist: 2.4.8 + uint8arrays: 5.1.0 + '@libp2p/logger@5.1.2': dependencies: '@libp2p/interface': 2.1.3 @@ -6932,6 +6977,12 @@ snapshots: uint8arraylist: 2.4.8 uint8arrays: 5.1.0 + '@libp2p/record@4.0.4': + dependencies: + protons-runtime: 5.5.0 + uint8arraylist: 2.4.8 + uint8arrays: 5.1.0 + '@libp2p/simple-metrics@1.2.5': dependencies: '@libp2p/interface': 2.1.3 @@ -9172,6 +9223,8 @@ snapshots: uint8arraylist: 2.4.8 uint8arrays: 5.1.0 + it-length@3.0.6: {} + it-map@3.1.1: dependencies: it-peekable: 3.0.5 From 003082545d5ec25cf4a1558b172abbcdc49be7d4 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Tue, 29 Oct 2024 00:02:45 +0200 Subject: [PATCH 02/61] Adding topology_dht --- packages/network/src/node.ts | 12 +-- packages/network/src/utils/topology_dht.ts | 112 +++++++++++++++++++++ 2 files changed, 118 insertions(+), 6 deletions(-) create mode 100644 packages/network/src/utils/topology_dht.ts diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 1dc44107..74631fcb 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -85,8 +85,8 @@ export class TopologyNetworkNode { }), ] : [ - // _pubsubPeerDiscovery - ]; + // _pubsubPeerDiscovery + ]; const _node_services = { autonat: autoNAT(), @@ -94,10 +94,10 @@ export class TopologyNetworkNode { identify: identify(), pubsub: gossipsub(), kadDHT: kadDHT({ - protocol : "/topology/dht/1.0.0", - kBucketSize : 50, - clientMode : false, - }) + protocol: "/topology/dht/1.0.0", + kBucketSize: 50, + clientMode: false, + }), }; const _bootstrap_services = { diff --git a/packages/network/src/utils/topology_dht.ts b/packages/network/src/utils/topology_dht.ts new file mode 100644 index 00000000..e83153db --- /dev/null +++ b/packages/network/src/utils/topology_dht.ts @@ -0,0 +1,112 @@ +import { PeerId } from "@libp2p/interface"; +import { type KadDHT } from "@libp2p/kad-dht"; +import { toString as uint8ArrayToString } from "uint8arrays"; +import { fromString as uint8ArrayFromString } from "uint8arrays"; + +class TopologyDHT { + private _dht: KadDHT; + + constructor(dht: KadDHT) { + this._dht = dht; + } + + /* + * Announce the peer on the DHT + * @param topic The topic to announce the peer on + * @param peer_id The peer to announce + * @returns nothing + * */ + + async announcePeer(topic: string, peer_id: PeerId): Promise { + const peersSet = await this.getPeersOnTopic(topic); + peersSet.add(peer_id); + const newPeers = JSON.stringify(Array.from(peersSet)); + const newPeersUint8 = uint8ArrayFromString(newPeers); + const uint8Topic = uint8ArrayFromString(topic); + await this._putDataOnDHT(uint8Topic, newPeersUint8); + } + + /* + * Get the peers on a topic from the DHT + * @param topic The topic to get the peers from + * @returns A set of PeerId + * */ + async getPeersOnTopic(topic: string): Promise> { + const uint8Topic = uint8ArrayFromString(topic); + const peersOnTopic = this._dht?.get(uint8Topic); + let peersSet = new Set(); + if (peersOnTopic) { + for await (const evt of peersOnTopic) { + if (evt.name === "VALUE") { + const uint8Peers = evt.value; + const peersArray = JSON.parse(uint8ArrayToString(uint8Peers)); + peersSet = new Set(peersArray); + } + } + } + return peersSet; + } + + /* + * Remove the peer from the DHT + * @param topic The topic to remove the peer from + * @param peer_id The peer to remove + * @returns nothing + * */ + async removePeer(topic: string, peerId: PeerId): Promise { + const peersSet = await this.getPeersOnTopic(topic); + peersSet.delete(peerId); + const newPeers = JSON.stringify(Array.from(peersSet)); + const newPeersUint8 = uint8ArrayFromString(newPeers); + const uint8Topic = uint8ArrayFromString(topic); + await this._putDataOnDHT(uint8Topic, newPeersUint8); + } + + private async _putDataOnDHT( + key: Uint8Array, + value: Uint8Array, + ): Promise { + if (!this._dht) { + console.error( + "topology::network::topic::discovery: DHT not initialized. Please run .start()", + ); + return false; + } + + try { + await this._dht?.put(key, value); + return true; + } catch (e) { + throw new Error( + "topology::network::topic::discovery: Error storing data on DHT : " + e, + ); + return false; + } + } + + private async _getDataFromDHT( + key: Uint8Array, + ): Promise { + if (!this._dht) { + console.error( + "topology::network::topic::discovery: DHT not initialized. Please run .start()", + ); + return null; + } + + try { + const value = await this._dht?.get(key); + for await (const evt of value) { + if (evt.name === "VALUE") { + return evt.value; + } + } + } catch (e) { + throw new Error( + "topology::network::topic::discovery: Error fetching data from DHT : " + + e, + ); + return null; + } + } +} From 015a970b12951d5c0b131a7a718298889b6aadf9 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Tue, 29 Oct 2024 01:05:07 +0200 Subject: [PATCH 03/61] Testing connection to DHT --- packages/network/src/node.ts | 36 +++++++++++++++++----- packages/network/src/utils/topology_dht.ts | 4 +-- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 74631fcb..dd7f0450 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -31,7 +31,10 @@ import { type Libp2p, createLibp2p } from "libp2p"; import { fromString as uint8ArrayFromString } from "uint8arrays/from-string"; import { Message } from "./proto/messages_pb.js"; import { uint8ArrayToStream } from "./stream.js"; -import { kadDHT } from "@libp2p/kad-dht"; +import { KadDHT, kadDHT } from "@libp2p/kad-dht"; +import { TopologyDHT } from "./utils/topology_dht.js"; +import { peerIdFromString } from '@libp2p/peer-id' + export * from "./stream.js"; @@ -48,6 +51,7 @@ export class TopologyNetworkNode { private _config?: TopologyNetworkNodeConfig; private _node?: Libp2p; private _pubsub?: PubSub; + private _topologyDHT?: TopologyDHT; peerId = ""; @@ -93,7 +97,7 @@ export class TopologyNetworkNode { dcutr: dcutr(), identify: identify(), pubsub: gossipsub(), - kadDHT: kadDHT({ + dht: kadDHT({ protocol: "/topology/dht/1.0.0", kBucketSize: 50, clientMode: false, @@ -136,11 +140,24 @@ export class TopologyNetworkNode { if (!this._config?.bootstrap) { for (const addr of this._config?.bootstrap_peers || []) { - this._node.dial(multiaddr(addr)); + const stream = await this._node.dial(multiaddr(addr)); } } + if (!this._config?.bootstrap) { + // get bootstrap node peerStore + setInterval(() => { + console.log("CHeck peers"); + const peers = this._node?.peerStore; + console.log("PEERS", peers); + + }, 10000); + } + + const bootstrap_peer_id = peerIdFromString("12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ"); + this._pubsub = this._node.services.pubsub as PubSub; + this.peerId = this._node.peerId.toString(); console.log( @@ -148,9 +165,11 @@ export class TopologyNetworkNode { this.peerId, ); - this._node.addEventListener("peer:connect", (e) => + this._node.addEventListener("peer:connect", (e) => { console.log("::start::peer::connect", e.detail), - ); + this._topologyDHT = new TopologyDHT(this._node?.services.dht as KadDHT, bootstrap_peer_id); + console.log("CONNECTED TO DHT"); + }); 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) { @@ -158,9 +177,10 @@ export class TopologyNetworkNode { } console.log("::start::peer::discovery", e.detail); }); - this._node.addEventListener("peer:identify", (e) => - console.log("::start::peer::identify", e.detail), - ); + this._node.addEventListener("peer:identify", (e) => { + // TO BE UNCOMMENTED + // console.log("::start::peer::identify", e.detail), + }); } subscribe(topic: string) { diff --git a/packages/network/src/utils/topology_dht.ts b/packages/network/src/utils/topology_dht.ts index e83153db..4fca6989 100644 --- a/packages/network/src/utils/topology_dht.ts +++ b/packages/network/src/utils/topology_dht.ts @@ -3,10 +3,10 @@ import { type KadDHT } from "@libp2p/kad-dht"; import { toString as uint8ArrayToString } from "uint8arrays"; import { fromString as uint8ArrayFromString } from "uint8arrays"; -class TopologyDHT { +export class TopologyDHT { private _dht: KadDHT; - constructor(dht: KadDHT) { + constructor(dht: KadDHT, peerId: PeerId) { this._dht = dht; } From 9ed1eea3bb9e64ff120aeb212f09ee33fce1ade5 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:25:34 +0200 Subject: [PATCH 04/61] Announcing and getting peers --- packages/network/src/node.ts | 19 +++++++++++++++++-- packages/network/src/utils/topology_dht.ts | 2 ++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index dd7f0450..9eb087df 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -165,18 +165,33 @@ export class TopologyNetworkNode { this.peerId, ); - this._node.addEventListener("peer:connect", (e) => { + this._node.addEventListener("peer:connect", async (e) => { console.log("::start::peer::connect", e.detail), this._topologyDHT = new TopologyDHT(this._node?.services.dht as KadDHT, bootstrap_peer_id); console.log("CONNECTED TO DHT"); + const peers = await this._topologyDHT.getPeersOnTopic("topology::disco"); + console.log("PEERS FROM DHT", peers); + }); - this._node.addEventListener("peer:discovery", (e) => { + + + this._node.addEventListener("peer:discovery", async (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); } console.log("::start::peer::discovery", e.detail); + if(this._config?.bootstrap){ + await this._topologyDHT?.announcePeer("topology::disco", e.detail.id); + console.log("ANNOUNCED PEER TO DHT"); + setInterval(async () => { + const peers = await this._topologyDHT?.getPeersOnTopic("topology::disco"); + console.log("PEERS FROM DHT", peers); + }, 150000); + } }); + + this._node.addEventListener("peer:identify", (e) => { // TO BE UNCOMMENTED // console.log("::start::peer::identify", e.detail), diff --git a/packages/network/src/utils/topology_dht.ts b/packages/network/src/utils/topology_dht.ts index 4fca6989..c2f45647 100644 --- a/packages/network/src/utils/topology_dht.ts +++ b/packages/network/src/utils/topology_dht.ts @@ -32,11 +32,13 @@ export class TopologyDHT { * @returns A set of PeerId * */ async getPeersOnTopic(topic: string): Promise> { + console.log("Get peers on a topic"); const uint8Topic = uint8ArrayFromString(topic); const peersOnTopic = this._dht?.get(uint8Topic); let peersSet = new Set(); if (peersOnTopic) { for await (const evt of peersOnTopic) { + console.log(evt); if (evt.name === "VALUE") { const uint8Peers = evt.value; const peersArray = JSON.parse(uint8ArrayToString(uint8Peers)); From 80a327b3c7d0f7bb6078d29b25e00663082f3909 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Thu, 31 Oct 2024 01:04:42 +0200 Subject: [PATCH 05/61] Commenting pubsub discovery --- packages/network/src/node.ts | 47 +++++----------------- packages/network/src/utils/topology_dht.ts | 27 ++++++++----- 2 files changed, 28 insertions(+), 46 deletions(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 9eb087df..534187a9 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -31,10 +31,9 @@ import { type Libp2p, createLibp2p } from "libp2p"; import { fromString as uint8ArrayFromString } from "uint8arrays/from-string"; import { Message } from "./proto/messages_pb.js"; import { uint8ArrayToStream } from "./stream.js"; -import { KadDHT, kadDHT } from "@libp2p/kad-dht"; +import { type KadDHT, kadDHT } from "@libp2p/kad-dht"; import { TopologyDHT } from "./utils/topology_dht.js"; -import { peerIdFromString } from '@libp2p/peer-id' - +import { peerIdFromString } from "@libp2p/peer-id"; export * from "./stream.js"; @@ -104,7 +103,7 @@ export class TopologyNetworkNode { }), }; - const _bootstrap_services = { + const _bootstrap_node_services = { ..._node_services, relay: circuitRelayServer(), }; @@ -122,7 +121,9 @@ export class TopologyNetworkNode { }, metrics: this._config?.browser_metrics ? devToolsMetrics() : undefined, peerDiscovery: _peerDiscovery, - services: this._config?.bootstrap ? _bootstrap_services : _node_services, + services: this._config?.bootstrap + ? _bootstrap_node_services + : _node_services, streamMuxers: [yamux()], transports: [ circuitRelayTransport({ @@ -144,20 +145,9 @@ export class TopologyNetworkNode { } } - if (!this._config?.bootstrap) { - // get bootstrap node peerStore - setInterval(() => { - console.log("CHeck peers"); - const peers = this._node?.peerStore; - console.log("PEERS", peers); - - }, 10000); - } - - const bootstrap_peer_id = peerIdFromString("12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ"); - this._pubsub = this._node.services.pubsub as PubSub; - + this._topologyDHT = new TopologyDHT(this._node?.services.dht as KadDHT); + this.peerId = this._node.peerId.toString(); console.log( @@ -166,14 +156,9 @@ export class TopologyNetworkNode { ); this._node.addEventListener("peer:connect", async (e) => { - console.log("::start::peer::connect", e.detail), - this._topologyDHT = new TopologyDHT(this._node?.services.dht as KadDHT, bootstrap_peer_id); - console.log("CONNECTED TO DHT"); - const peers = await this._topologyDHT.getPeersOnTopic("topology::disco"); - console.log("PEERS FROM DHT", peers); - + console.log("::start::peer::connect", e.detail); + this._topologyDHT = new TopologyDHT(this._node?.services.dht as KadDHT,); }); - this._node.addEventListener("peer:discovery", async (e) => { // current bug in v11.0.0 requires manual dial (https://github.com/libp2p/js-libp2p-pubsub-peer-discovery/issues/149) @@ -181,20 +166,10 @@ export class TopologyNetworkNode { this._node?.dial(ma); } console.log("::start::peer::discovery", e.detail); - if(this._config?.bootstrap){ - await this._topologyDHT?.announcePeer("topology::disco", e.detail.id); - console.log("ANNOUNCED PEER TO DHT"); - setInterval(async () => { - const peers = await this._topologyDHT?.getPeersOnTopic("topology::disco"); - console.log("PEERS FROM DHT", peers); - }, 150000); - } }); - this._node.addEventListener("peer:identify", (e) => { - // TO BE UNCOMMENTED - // console.log("::start::peer::identify", e.detail), + console.log("::start::peer::identify", e.detail); }); } diff --git a/packages/network/src/utils/topology_dht.ts b/packages/network/src/utils/topology_dht.ts index c2f45647..82e4ef21 100644 --- a/packages/network/src/utils/topology_dht.ts +++ b/packages/network/src/utils/topology_dht.ts @@ -1,12 +1,12 @@ -import { PeerId } from "@libp2p/interface"; -import { type KadDHT } from "@libp2p/kad-dht"; +import type { PeerId } from "@libp2p/interface"; +import type { KadDHT } from "@libp2p/kad-dht"; import { toString as uint8ArrayToString } from "uint8arrays"; import { fromString as uint8ArrayFromString } from "uint8arrays"; export class TopologyDHT { private _dht: KadDHT; - constructor(dht: KadDHT, peerId: PeerId) { + constructor(dht: KadDHT) { this._dht = dht; } @@ -64,6 +64,18 @@ export class TopologyDHT { await this._putDataOnDHT(uint8Topic, newPeersUint8); } + async put_string_on_dht(key: string, value: string): Promise { + return this._putDataOnDHT(uint8ArrayFromString(key), uint8ArrayFromString(value)); + } + + async get_string_on_dht(key: string): Promise { + const value = await this._getDataFromDHT(uint8ArrayFromString(key)); + if (value) { + return uint8ArrayToString(value); + } + return null; + } + private async _putDataOnDHT( key: Uint8Array, value: Uint8Array, @@ -80,9 +92,8 @@ export class TopologyDHT { return true; } catch (e) { throw new Error( - "topology::network::topic::discovery: Error storing data on DHT : " + e, + `topology::network::topic::discovery: Error storing data on DHT : ${ e }` ); - return false; } } @@ -104,11 +115,7 @@ export class TopologyDHT { } } } catch (e) { - throw new Error( - "topology::network::topic::discovery: Error fetching data from DHT : " + - e, - ); - return null; + throw new Error( `topology::network::topic::discovery: Error fetching data from DHT : : ${ e }`); } } } From 596d3bbaf918216d87e20dc343c7405d52afb59d Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Thu, 31 Oct 2024 16:46:49 +0200 Subject: [PATCH 06/61] Testing online before cleaning --- packages/network/package.json | 1 + packages/network/src/node.ts | 80 ++++++++++++++++++++++++++++++++--- pnpm-lock.yaml | 22 ++++++++++ 3 files changed, 96 insertions(+), 7 deletions(-) diff --git a/packages/network/package.json b/packages/network/package.json index 79a0cf62..f6e3eb5f 100644 --- a/packages/network/package.json +++ b/packages/network/package.json @@ -45,6 +45,7 @@ "@libp2p/kad-dht": "14.0.0", "@libp2p/mdns": "^11.0.8", "@libp2p/peer-id": "^5.0.4", + "@libp2p/peer-store": "11.0.7", "@libp2p/pubsub-peer-discovery": "^11.0.0", "@libp2p/webrtc": "^5.0.9", "@libp2p/websockets": "^9.0.7", diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 534187a9..4f7d3cfe 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -31,7 +31,7 @@ import { type Libp2p, createLibp2p } from "libp2p"; import { fromString as uint8ArrayFromString } from "uint8arrays/from-string"; import { Message } from "./proto/messages_pb.js"; import { uint8ArrayToStream } from "./stream.js"; -import { type KadDHT, kadDHT } from "@libp2p/kad-dht"; +import { type KadDHT, kadDHT, removePrivateAddressesMapper, removePublicAddressesMapper } from "@libp2p/kad-dht"; import { TopologyDHT } from "./utils/topology_dht.js"; import { peerIdFromString } from "@libp2p/peer-id"; @@ -75,10 +75,10 @@ export class TopologyNetworkNode { "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", ]; - const _pubsubPeerDiscovery = pubsubPeerDiscovery({ - interval: 10_000, - topics: ["topology::discovery"], - }); + // const _pubsubPeerDiscovery = pubsubPeerDiscovery({ + // interval: 10_000, + // topics: ["topology::discovery"], + // }); const _peerDiscovery = _bootstrapNodesList.length ? [ @@ -98,8 +98,12 @@ export class TopologyNetworkNode { pubsub: gossipsub(), dht: kadDHT({ protocol: "/topology/dht/1.0.0", - kBucketSize: 50, + kBucketSize: 20, clientMode: false, + peerInfoMapper: removePublicAddressesMapper, + querySelfInterval: 10_000, + initialQuerySelfInterval: 20_000, + allowQueryWithZeroPeers: false }), }; @@ -108,6 +112,32 @@ export class TopologyNetworkNode { relay: circuitRelayServer(), }; + + // CONTENT ROUTING + // const components = { + // peerId: id, + // connectionManager: stubInterface(), + // peerStore: stubInterface(), + // logger: defaultLogger() + // } + // const table = new RoutingTable(components, { + // kBucketSize: 20, + // logPrefix: '', + // metricsPrefix: '', + // protocol: '/ipfs/kad/1.0.0', + // network: stubInterface() + // }) + // refresh = new RoutingTableRefresh({ + // logger: defaultLogger() + // }, { + // routingTable: table, + // // @ts-expect-error not a full implementation + // peerRouting: {}, + // logPrefix: '' + // }) + + // END CONTENT ROUTING + this._node = await createLibp2p({ privateKey, addresses: { @@ -119,6 +149,8 @@ export class TopologyNetworkNode { return false; }, }, + // contentRouters: [kadDHT()], + // peerRouters: [kadDHT()], metrics: this._config?.browser_metrics ? devToolsMetrics() : undefined, peerDiscovery: _peerDiscovery, services: this._config?.bootstrap @@ -155,9 +187,24 @@ export class TopologyNetworkNode { this.peerId, ); + // setInterval(() => { + setTimeout(() => { + const ma = this._node?.getMultiaddrs(); + console.log("multiaddrs", ma); + }, 9000); + + setInterval(() => { + console.log("MY PEERS ARE ", this._node?.getPeers()); + }, 30000); + + // // // get all my peers + // // const peers = this._node?.peerStore; + // // console.log("peers", peers); + // }, 10000); + this._node.addEventListener("peer:connect", async (e) => { console.log("::start::peer::connect", e.detail); - this._topologyDHT = new TopologyDHT(this._node?.services.dht as KadDHT,); + // this._topologyDHT = new TopologyDHT(this._node?.services.dht as KadDHT); }); this._node.addEventListener("peer:discovery", async (e) => { @@ -168,11 +215,30 @@ export class TopologyNetworkNode { console.log("::start::peer::discovery", e.detail); }); + // console log peer store + // this._pubsub?.subscribe("we_are_here"); + + // this._pubsub?.addEventListener("message", (message) => { + // // if (message. === groupName) { + // console.log("Received message in message:", message.detail); + // }); + + // setInterval(() => { + // // console.log("peer store", this._node?.getPeers()); + // // send a message to the group + // this._pubsub?.publish("we_are_here", uint8ArrayFromString("hello")); + // }, 10000); + this._node.addEventListener("peer:identify", (e) => { console.log("::start::peer::identify", e.detail); }); } + // receive topic from stream after dialing + // receiveTopic(stream: Stream) { + // stream. + // } + subscribe(topic: string) { if (!this._node) { console.error( diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bdae7329..99eca30e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -304,6 +304,9 @@ importers: '@libp2p/peer-id': specifier: ^5.0.4 version: 5.0.6 + '@libp2p/peer-store': + specifier: 11.0.7 + version: 11.0.7 '@libp2p/pubsub-peer-discovery': specifier: ^11.0.0 version: 11.0.0 @@ -1601,6 +1604,9 @@ packages: '@libp2p/peer-record@8.0.9': resolution: {integrity: sha512-Ixiha//G7oCzQXSXHyXhv4Xp4qzVGSZLKUWmgUuLpqnlHrVXcqPLmPx0vkOik3ndIGriYGj5Hi7zAfCG0BN4oQ==} + '@libp2p/peer-store@11.0.7': + resolution: {integrity: sha512-h8W/XVYfKTmJhhnh2Mdub23CzPv24l5g1RRwFsEKCkWAe95M/fvDMPTM2ahRUB64qfnFT5X4XNFFyJFMsVtjLA==} + '@libp2p/peer-store@11.0.9': resolution: {integrity: sha512-gBuSXihGtxD2r/KylgcaVm0fv0hy30j74mWcmMokpwqwLH2aLReGN9QelubmXtH2cnaRafD66QutuHNORIgRlg==} @@ -6934,6 +6940,22 @@ snapshots: uint8arraylist: 2.4.8 uint8arrays: 5.1.0 + '@libp2p/peer-store@11.0.7': + dependencies: + '@libp2p/crypto': 5.0.5 + '@libp2p/interface': 2.1.3 + '@libp2p/peer-collections': 6.0.9 + '@libp2p/peer-id': 5.0.6 + '@libp2p/peer-record': 8.0.9 + '@multiformats/multiaddr': 12.3.1 + interface-datastore: 8.3.1 + it-all: 3.0.6 + mortice: 3.0.6 + multiformats: 13.3.0 + protons-runtime: 5.5.0 + uint8arraylist: 2.4.8 + uint8arrays: 5.1.0 + '@libp2p/peer-store@11.0.9': dependencies: '@libp2p/crypto': 5.0.5 From e2022f452ac2907ec4336544398ebe57701fd3b6 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Thu, 31 Oct 2024 17:33:07 +0200 Subject: [PATCH 07/61] Changing bootstrap ndoe --- packages/network/src/node.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 4f7d3cfe..b3ff7dae 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -72,7 +72,8 @@ export class TopologyNetworkNode { ? this._config.bootstrap_peers : [ // "/dns4/relay.droak.sh/tcp/443/wss/p2p/Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP", - "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + // "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ" ]; // const _pubsubPeerDiscovery = pubsubPeerDiscovery({ From 2e43495d1aa24cb0568afc7b6384d043d1d80ec3 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Fri, 1 Nov 2024 13:15:42 +0200 Subject: [PATCH 08/61] Applying biome fix --- examples/.DS_Store | Bin 0 -> 6148 bytes examples/grid/vite.config.mts | 1 + packages/network/src/node.ts | 92 ++-------------- packages/network/src/utils/topology_dht.ts | 121 --------------------- 4 files changed, 12 insertions(+), 202 deletions(-) create mode 100644 examples/.DS_Store delete mode 100644 packages/network/src/utils/topology_dht.ts diff --git a/examples/.DS_Store b/examples/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8261d2354aeaa80f605b79de0102e343e597530d GIT binary patch literal 6148 zcmeHKO>5gg5S?{YM<$f`&_FH$L9S`)2Ko_tQJwUVYZTf;Q(P%BiKwbIk{ln5LAM0* zV|wae>ECJJ>~4x(H@8qqn1R_hJ9@Lyz7<+65vl$-eNNORA|KA!>Y(|H@pbkkYq?At zsLU8KRY$o#OLCnou_f_8D!^;krZbAEpi8v#>&Gv}TlnrzW9IQaa4*2C=hm5d-v*BdWeR80SI?jq=X$rD*2+HY)tVs2wug67NncB!+@H>8I(A}6$dpp6){n<`1 z-QPp_`qhistmAKNKYMdL_>zAu^p%-DDZJ>$9y`2+YXly-Nnb`~k?Z0dIp(iZPTGi^ z(^E)4Fyw?Ws r&u}*8H5PxDATV1oxV#l_!i^yxZ~zP)HWrbA$&Y}MK^jrupDOSRgQ|R` literal 0 HcmV?d00001 diff --git a/examples/grid/vite.config.mts b/examples/grid/vite.config.mts index e3518486..09a99b91 100644 --- a/examples/grid/vite.config.mts +++ b/examples/grid/vite.config.mts @@ -1,4 +1,5 @@ import path from "node:path"; +import { fs } from "memfs"; import { defineConfig } from "vite"; import { nodePolyfills } from "vite-plugin-node-polyfills"; diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index b3ff7dae..27217b29 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -21,6 +21,12 @@ import type { Stream, StreamHandler, } from "@libp2p/interface"; +import { + type KadDHT, + kadDHT, + removePrivateAddressesMapper, + removePublicAddressesMapper, +} from "@libp2p/kad-dht"; import { pubsubPeerDiscovery } from "@libp2p/pubsub-peer-discovery"; import { webRTC, webRTCDirect } from "@libp2p/webrtc"; import { webSockets } from "@libp2p/websockets"; @@ -31,9 +37,6 @@ import { type Libp2p, createLibp2p } from "libp2p"; import { fromString as uint8ArrayFromString } from "uint8arrays/from-string"; import { Message } from "./proto/messages_pb.js"; import { uint8ArrayToStream } from "./stream.js"; -import { type KadDHT, kadDHT, removePrivateAddressesMapper, removePublicAddressesMapper } from "@libp2p/kad-dht"; -import { TopologyDHT } from "./utils/topology_dht.js"; -import { peerIdFromString } from "@libp2p/peer-id"; export * from "./stream.js"; @@ -50,7 +53,6 @@ export class TopologyNetworkNode { private _config?: TopologyNetworkNodeConfig; private _node?: Libp2p; private _pubsub?: PubSub; - private _topologyDHT?: TopologyDHT; peerId = ""; @@ -73,24 +75,16 @@ export class TopologyNetworkNode { : [ // "/dns4/relay.droak.sh/tcp/443/wss/p2p/Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP", // "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", - "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ" + "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", ]; - // const _pubsubPeerDiscovery = pubsubPeerDiscovery({ - // interval: 10_000, - // topics: ["topology::discovery"], - // }); - const _peerDiscovery = _bootstrapNodesList.length ? [ - // _pubsubPeerDiscovery, bootstrap({ list: _bootstrapNodesList, }), ] - : [ - // _pubsubPeerDiscovery - ]; + : []; const _node_services = { autonat: autoNAT(), @@ -104,7 +98,7 @@ export class TopologyNetworkNode { peerInfoMapper: removePublicAddressesMapper, querySelfInterval: 10_000, initialQuerySelfInterval: 20_000, - allowQueryWithZeroPeers: false + allowQueryWithZeroPeers: false, }), }; @@ -113,32 +107,6 @@ export class TopologyNetworkNode { relay: circuitRelayServer(), }; - - // CONTENT ROUTING - // const components = { - // peerId: id, - // connectionManager: stubInterface(), - // peerStore: stubInterface(), - // logger: defaultLogger() - // } - // const table = new RoutingTable(components, { - // kBucketSize: 20, - // logPrefix: '', - // metricsPrefix: '', - // protocol: '/ipfs/kad/1.0.0', - // network: stubInterface() - // }) - // refresh = new RoutingTableRefresh({ - // logger: defaultLogger() - // }, { - // routingTable: table, - // // @ts-expect-error not a full implementation - // peerRouting: {}, - // logPrefix: '' - // }) - - // END CONTENT ROUTING - this._node = await createLibp2p({ privateKey, addresses: { @@ -150,8 +118,6 @@ export class TopologyNetworkNode { return false; }, }, - // contentRouters: [kadDHT()], - // peerRouters: [kadDHT()], metrics: this._config?.browser_metrics ? devToolsMetrics() : undefined, peerDiscovery: _peerDiscovery, services: this._config?.bootstrap @@ -179,7 +145,6 @@ export class TopologyNetworkNode { } this._pubsub = this._node.services.pubsub as PubSub; - this._topologyDHT = new TopologyDHT(this._node?.services.dht as KadDHT); this.peerId = this._node.peerId.toString(); @@ -188,24 +153,8 @@ export class TopologyNetworkNode { this.peerId, ); - // setInterval(() => { - setTimeout(() => { - const ma = this._node?.getMultiaddrs(); - console.log("multiaddrs", ma); - }, 9000); - - setInterval(() => { - console.log("MY PEERS ARE ", this._node?.getPeers()); - }, 30000); - - // // // get all my peers - // // const peers = this._node?.peerStore; - // // console.log("peers", peers); - // }, 10000); - this._node.addEventListener("peer:connect", async (e) => { console.log("::start::peer::connect", e.detail); - // this._topologyDHT = new TopologyDHT(this._node?.services.dht as KadDHT); }); this._node.addEventListener("peer:discovery", async (e) => { @@ -213,33 +162,14 @@ export class TopologyNetworkNode { for (const ma of e.detail.multiaddrs) { this._node?.dial(ma); } - console.log("::start::peer::discovery", e.detail); + console.log("::start::peer::discovery", e.detail.id); }); - // console log peer store - // this._pubsub?.subscribe("we_are_here"); - - // this._pubsub?.addEventListener("message", (message) => { - // // if (message. === groupName) { - // console.log("Received message in message:", message.detail); - // }); - - // setInterval(() => { - // // console.log("peer store", this._node?.getPeers()); - // // send a message to the group - // this._pubsub?.publish("we_are_here", uint8ArrayFromString("hello")); - // }, 10000); - this._node.addEventListener("peer:identify", (e) => { - console.log("::start::peer::identify", e.detail); + console.log("::start::peer::identify", e.detail.peerId); }); } - // receive topic from stream after dialing - // receiveTopic(stream: Stream) { - // stream. - // } - subscribe(topic: string) { if (!this._node) { console.error( diff --git a/packages/network/src/utils/topology_dht.ts b/packages/network/src/utils/topology_dht.ts deleted file mode 100644 index 82e4ef21..00000000 --- a/packages/network/src/utils/topology_dht.ts +++ /dev/null @@ -1,121 +0,0 @@ -import type { PeerId } from "@libp2p/interface"; -import type { KadDHT } from "@libp2p/kad-dht"; -import { toString as uint8ArrayToString } from "uint8arrays"; -import { fromString as uint8ArrayFromString } from "uint8arrays"; - -export class TopologyDHT { - private _dht: KadDHT; - - constructor(dht: KadDHT) { - this._dht = dht; - } - - /* - * Announce the peer on the DHT - * @param topic The topic to announce the peer on - * @param peer_id The peer to announce - * @returns nothing - * */ - - async announcePeer(topic: string, peer_id: PeerId): Promise { - const peersSet = await this.getPeersOnTopic(topic); - peersSet.add(peer_id); - const newPeers = JSON.stringify(Array.from(peersSet)); - const newPeersUint8 = uint8ArrayFromString(newPeers); - const uint8Topic = uint8ArrayFromString(topic); - await this._putDataOnDHT(uint8Topic, newPeersUint8); - } - - /* - * Get the peers on a topic from the DHT - * @param topic The topic to get the peers from - * @returns A set of PeerId - * */ - async getPeersOnTopic(topic: string): Promise> { - console.log("Get peers on a topic"); - const uint8Topic = uint8ArrayFromString(topic); - const peersOnTopic = this._dht?.get(uint8Topic); - let peersSet = new Set(); - if (peersOnTopic) { - for await (const evt of peersOnTopic) { - console.log(evt); - if (evt.name === "VALUE") { - const uint8Peers = evt.value; - const peersArray = JSON.parse(uint8ArrayToString(uint8Peers)); - peersSet = new Set(peersArray); - } - } - } - return peersSet; - } - - /* - * Remove the peer from the DHT - * @param topic The topic to remove the peer from - * @param peer_id The peer to remove - * @returns nothing - * */ - async removePeer(topic: string, peerId: PeerId): Promise { - const peersSet = await this.getPeersOnTopic(topic); - peersSet.delete(peerId); - const newPeers = JSON.stringify(Array.from(peersSet)); - const newPeersUint8 = uint8ArrayFromString(newPeers); - const uint8Topic = uint8ArrayFromString(topic); - await this._putDataOnDHT(uint8Topic, newPeersUint8); - } - - async put_string_on_dht(key: string, value: string): Promise { - return this._putDataOnDHT(uint8ArrayFromString(key), uint8ArrayFromString(value)); - } - - async get_string_on_dht(key: string): Promise { - const value = await this._getDataFromDHT(uint8ArrayFromString(key)); - if (value) { - return uint8ArrayToString(value); - } - return null; - } - - private async _putDataOnDHT( - key: Uint8Array, - value: Uint8Array, - ): Promise { - if (!this._dht) { - console.error( - "topology::network::topic::discovery: DHT not initialized. Please run .start()", - ); - return false; - } - - try { - await this._dht?.put(key, value); - return true; - } catch (e) { - throw new Error( - `topology::network::topic::discovery: Error storing data on DHT : ${ e }` - ); - } - } - - private async _getDataFromDHT( - key: Uint8Array, - ): Promise { - if (!this._dht) { - console.error( - "topology::network::topic::discovery: DHT not initialized. Please run .start()", - ); - return null; - } - - try { - const value = await this._dht?.get(key); - for await (const evt of value) { - if (evt.name === "VALUE") { - return evt.value; - } - } - } catch (e) { - throw new Error( `topology::network::topic::discovery: Error fetching data from DHT : : ${ e }`); - } - } -} From 790e8201bb4ece5911a762fcc27f59faccf695d5 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:32:31 +0200 Subject: [PATCH 09/61] Updating grid example --- examples/grid/index.html | 1 - examples/grid/src/index.ts | 24 +++++++++++++----------- packages/network/src/node.ts | 22 ++++++++++++++++++---- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/examples/grid/index.html b/examples/grid/index.html index c43df353..06790a66 100644 --- a/examples/grid/index.html +++ b/examples/grid/index.html @@ -10,7 +10,6 @@

A 2D grid made with CRO

Your Peer ID:

Peers on dRAM:

-

Discovery Peers:

| diff --git a/examples/grid/src/index.ts b/examples/grid/src/index.ts index d8c84e69..0e5f1c18 100644 --- a/examples/grid/src/index.ts +++ b/examples/grid/src/index.ts @@ -7,7 +7,6 @@ const node = new TopologyNode(); let topologyObject: TopologyObject; let gridCRO: Grid; let peers: string[] = []; -let discoveryPeers: string[] = []; let objectPeers: string[] = []; const formatNodeId = (id: string): string => { @@ -65,11 +64,6 @@ const render = () => { const element_peers = document.getElementById("peers"); element_peers.innerHTML = `[${peers.map((peer) => `${formatNodeId(peer)}`).join(", ")}]`; - const element_discoveryPeers = ( - document.getElementById("discoveryPeers") - ); - element_discoveryPeers.innerHTML = `[${discoveryPeers.map((peer) => `${formatNodeId(peer)}`).join(", ")}]`; - const element_objectPeers = ( document.getElementById("objectPeers") ); @@ -205,11 +199,19 @@ async function main() { await node.start(); render(); - node.addCustomGroupMessageHandler("", (e) => { - peers = node.networkNode.getAllPeers(); - discoveryPeers = node.networkNode.getGroupPeers("topology::discovery"); - render(); - }); + // THIS WORKS ONLY AFTER A PUBSUB MESSAGE IS RECEIVED + // node.addCustomGroupMessageHandler("", (e) => { + // peers = node.networkNode.getAllPeers(); + // render(); + // }); + + setInterval(() => { + if (node.networkNode.checkNodeReady()) { + console.log("Node is ready"); + peers = node.networkNode.getAllPeers(); + render(); + } + }, 1000); const button_create = ( document.getElementById("createGrid") diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 27217b29..28601dda 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -74,8 +74,8 @@ export class TopologyNetworkNode { ? this._config.bootstrap_peers : [ // "/dns4/relay.droak.sh/tcp/443/wss/p2p/Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP", - // "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", - "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + // "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", ]; const _peerDiscovery = _bootstrapNodesList.length @@ -96,8 +96,8 @@ export class TopologyNetworkNode { kBucketSize: 20, clientMode: false, peerInfoMapper: removePublicAddressesMapper, - querySelfInterval: 10_000, - initialQuerySelfInterval: 20_000, + querySelfInterval: 20000, + initialQuerySelfInterval: 10000, allowQueryWithZeroPeers: false, }), }; @@ -278,4 +278,18 @@ export class TopologyNetworkNode { addMessageHandler(protocol: string | string[], handler: StreamHandler) { this._node?.handle(protocol, handler); } + + /** + * This function allows to check if the node is ready to be used on the network + * We check if the node has any multiaddrs as for /webrtc it takes a while to get them assigned from the relay server node. + * @returns boolean + */ + checkNodeReady() : boolean { + if(this._node?.getMultiaddrs().length){ + return true; + } + return false; + } + + } From cebbc84420955d0873faeac92c437f206684a8b3 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Fri, 1 Nov 2024 17:19:38 +0200 Subject: [PATCH 10/61] Updating the grid example --- examples/grid/src/index.ts | 7 ------- packages/network/src/node.ts | 8 +++----- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/examples/grid/src/index.ts b/examples/grid/src/index.ts index 0e5f1c18..7f7c4e0f 100644 --- a/examples/grid/src/index.ts +++ b/examples/grid/src/index.ts @@ -199,15 +199,8 @@ async function main() { await node.start(); render(); - // THIS WORKS ONLY AFTER A PUBSUB MESSAGE IS RECEIVED - // node.addCustomGroupMessageHandler("", (e) => { - // peers = node.networkNode.getAllPeers(); - // render(); - // }); - setInterval(() => { if (node.networkNode.checkNodeReady()) { - console.log("Node is ready"); peers = node.networkNode.getAllPeers(); render(); } diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 28601dda..1db68c53 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -93,7 +93,7 @@ export class TopologyNetworkNode { pubsub: gossipsub(), dht: kadDHT({ protocol: "/topology/dht/1.0.0", - kBucketSize: 20, + kBucketSize: this._config?.bootstrap ? 40 : 20, clientMode: false, peerInfoMapper: removePublicAddressesMapper, querySelfInterval: 20000, @@ -284,12 +284,10 @@ export class TopologyNetworkNode { * We check if the node has any multiaddrs as for /webrtc it takes a while to get them assigned from the relay server node. * @returns boolean */ - checkNodeReady() : boolean { - if(this._node?.getMultiaddrs().length){ + checkNodeReady(): boolean { + if (this._node?.getMultiaddrs().length) { return true; } return false; } - - } From 6adaef034f261871898f2a7958de6033ceab61fa Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:40:22 +0200 Subject: [PATCH 11/61] Resolving review --- examples/.DS_Store | Bin 6148 -> 0 bytes examples/grid/vite.config.mts | 1 - packages/network/src/node.ts | 20 ++++++-------------- 3 files changed, 6 insertions(+), 15 deletions(-) delete mode 100644 examples/.DS_Store diff --git a/examples/.DS_Store b/examples/.DS_Store deleted file mode 100644 index 8261d2354aeaa80f605b79de0102e343e597530d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKO>5gg5S?{YM<$f`&_FH$L9S`)2Ko_tQJwUVYZTf;Q(P%BiKwbIk{ln5LAM0* zV|wae>ECJJ>~4x(H@8qqn1R_hJ9@Lyz7<+65vl$-eNNORA|KA!>Y(|H@pbkkYq?At zsLU8KRY$o#OLCnou_f_8D!^;krZbAEpi8v#>&Gv}TlnrzW9IQaa4*2C=hm5d-v*BdWeR80SI?jq=X$rD*2+HY)tVs2wug67NncB!+@H>8I(A}6$dpp6){n<`1 z-QPp_`qhistmAKNKYMdL_>zAu^p%-DDZJ>$9y`2+YXly-Nnb`~k?Z0dIp(iZPTGi^ z(^E)4Fyw?Ws r&u}*8H5PxDATV1oxV#l_!i^yxZ~zP)HWrbA$&Y}MK^jrupDOSRgQ|R` diff --git a/examples/grid/vite.config.mts b/examples/grid/vite.config.mts index 09a99b91..e3518486 100644 --- a/examples/grid/vite.config.mts +++ b/examples/grid/vite.config.mts @@ -1,5 +1,4 @@ import path from "node:path"; -import { fs } from "memfs"; import { defineConfig } from "vite"; import { nodePolyfills } from "vite-plugin-node-polyfills"; diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 9f9c74e8..b2676f90 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -21,13 +21,7 @@ import type { Stream, StreamHandler, } from "@libp2p/interface"; -import { - type KadDHT, - kadDHT, - removePrivateAddressesMapper, - removePublicAddressesMapper, -} from "@libp2p/kad-dht"; -import { pubsubPeerDiscovery } from "@libp2p/pubsub-peer-discovery"; +import { kadDHT, removePublicAddressesMapper } from "@libp2p/kad-dht"; import { webRTC, webRTCDirect } from "@libp2p/webrtc"; import { webSockets } from "@libp2p/websockets"; import * as filters from "@libp2p/websockets/filters"; @@ -78,9 +72,7 @@ export class TopologyNetworkNode { const _bootstrapNodesList = this._config?.bootstrap_peers ? this._config.bootstrap_peers : [ - // "/dns4/relay.droak.sh/tcp/443/wss/p2p/Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP", - "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", - // "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", ]; const _peerDiscovery = _bootstrapNodesList.length @@ -145,7 +137,7 @@ export class TopologyNetworkNode { if (!this._config?.bootstrap) { for (const addr of this._config?.bootstrap_peers || []) { - const stream = await this._node.dial(multiaddr(addr)); + this._node.dial(multiaddr(addr)); } } @@ -159,7 +151,7 @@ export class TopologyNetworkNode { ); this._node.addEventListener("peer:connect", async (e) => { - console.log("::start::peer::connect", e.detail); + }); this._node.addEventListener("peer:discovery", async (e) => { @@ -167,11 +159,11 @@ export class TopologyNetworkNode { for (const ma of e.detail.multiaddrs) { this._node?.dial(ma); } - console.log("::start::peer::discovery", e.detail.id); + }); this._node.addEventListener("peer:identify", (e) => { - console.log("::start::peer::identify", e.detail.peerId); + log.info("::start::peer::identify", e.detail.peerId); }); } From dad86e4f1ac5325009e238e9cebfd68c5add1ef9 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:40:57 +0200 Subject: [PATCH 12/61] Resolving review --- packages/network/src/node.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index b2676f90..49dd38df 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -150,16 +150,13 @@ export class TopologyNetworkNode { this.peerId, ); - this._node.addEventListener("peer:connect", async (e) => { - - }); + this._node.addEventListener("peer:connect", async (e) => {}); this._node.addEventListener("peer:discovery", async (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); } - }); this._node.addEventListener("peer:identify", (e) => { From 466e5469ae3e738152854e2afb94e0a5cf5f336a Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Mon, 4 Nov 2024 19:03:08 +0200 Subject: [PATCH 13/61] Remove nfinic bootstrap --- packages/network/src/node.ts | 2 +- pnpm-lock.yaml | 54 +++++++++++++++++------------------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 49dd38df..1db0dfe8 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -72,7 +72,7 @@ export class TopologyNetworkNode { const _bootstrapNodesList = this._config?.bootstrap_peers ? this._config.bootstrap_peers : [ - "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + "/dns4/relay.droak.sh/tcp/443/wss/p2p/Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP", ]; const _peerDiscovery = _bootstrapNodesList.length diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7c478fbc..b1cfa5eb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -303,7 +303,7 @@ importers: version: 1.1.8 '@libp2p/identify': specifier: ^3.0.6 - version: 3.0.9 + version: 3.0.10 '@libp2p/kad-dht': specifier: 14.0.0 version: 14.0.0 @@ -312,7 +312,7 @@ importers: version: 11.0.10 '@libp2p/peer-id': specifier: ^5.0.4 - version: 5.0.6 + version: 5.0.7 '@libp2p/peer-store': specifier: 11.0.7 version: 11.0.7 @@ -1607,8 +1607,8 @@ packages: '@libp2p/kad-dht@14.0.0': resolution: {integrity: sha512-uPIC5TEvdjCgn4xvsjlOUyCVEGmJIzLM9MW34ReN71lXYF1LP7uRQPGBuF/Of42V5+YVlyPzIFKjo/VxFR/TkQ==} - '@libp2p/logger@5.1.2': - resolution: {integrity: sha512-To14ikSC+fnNXO+GkZB/Vj+kOGbdGcdpHdAMxvAWjm69ILDreGUlcDVotnAKVtN2bPAHL3Z0XzqDyKeRI6j73A==} + '@libp2p/logger@5.1.3': + resolution: {integrity: sha512-NUVWEWGbXlBDgDE5ntdm51+ZICmaKYI8mor6KrlPeB1WXDyIFxRWIBw6uzt+HgprQJWzLTojeUEGv6OPsj95Dg==} '@libp2p/mdns@11.0.10': resolution: {integrity: sha512-9U/byQsGmTC6Vqc+DaIsFPpIWBlh7CHT24PSg4CvUHC8CrypHADlTEGUxQjP5KTW1i50ZR1hkGlQZUC592RQxw==} @@ -1625,25 +1625,23 @@ packages: '@libp2p/peer-record@8.0.10': resolution: {integrity: sha512-k5A5YFhx7xGgFjiFWp0j8Cbw5kUYLJoBY9I3YTIHrieusLUUkMtUkYeuWeagNL1JYcXr06gguoIaYBRNCMQAow==} + '@libp2p/peer-store@11.0.10': + resolution: {integrity: sha512-yUkIAKrk2XAJt01SVOvxpsaT/FZ9ju7j67TJhvh0NUon/dMYSQKVHwykK8SI/dxZi/7cDslSKIbIKv7eU5ZUTQ==} + '@libp2p/peer-store@11.0.7': resolution: {integrity: sha512-h8W/XVYfKTmJhhnh2Mdub23CzPv24l5g1RRwFsEKCkWAe95M/fvDMPTM2ahRUB64qfnFT5X4XNFFyJFMsVtjLA==} - '@libp2p/peer-store@11.0.9': - resolution: {integrity: sha512-gBuSXihGtxD2r/KylgcaVm0fv0hy30j74mWcmMokpwqwLH2aLReGN9QelubmXtH2cnaRafD66QutuHNORIgRlg==} - - '@libp2p/pubsub-peer-discovery@11.0.0': resolution: {integrity: sha512-QlknUb2SCbmWScWzv2TS1tJIErYzr2HJoA93ZKYAlz5Dsfr9P1I17HvvlOIt/Q2PFp1aMOJOOF5mNsFV5kU73w==} '@libp2p/pubsub@10.0.10': resolution: {integrity: sha512-LMEcMa2aVs3V8kUQUmWYEMf0WvkteJ6EJOnR+cxFj+icsE4LZCqAG7zoZNUJeiVW6UDLmv1qolWWQayHrslKTw==} - '@libp2p/record@4.0.4': resolution: {integrity: sha512-wEEeHXGNIcc8HtGbgGMuSHbboUWMxKG7OxALFwkE+KACgfRJZTESOp6XIdZnyC0r9lfEFsjF01pFKBTzoBmWEQ==} - '@libp2p/simple-metrics@1.2.5': - resolution: {integrity: sha512-aOf0NqEQAyJQ55JMWpsYvl+olvSqFF6R0NkzSuK2TVvauGQ5PIqz48hBzZvmxp0JQpFgV8Ma7ECq6Vsg/Uvs8Q==} + '@libp2p/simple-metrics@1.2.6': + resolution: {integrity: sha512-BCyL9DGRqP7FV+KlA2NfTFnz7DeZh8DV84g/d7EsdzLdDycXgHL0aZ5zS51eQ+B6ad1nrP1OESRdgC4a/pmYpg==} '@libp2p/utils@6.1.3': resolution: {integrity: sha512-n1D6phOXGkqE3tuvmZwm5gaHKcGanlKwCWEBlrZqx9SSCyd5U5C58BcyQ8YH5/nb4kYMI7HyjomfQAVs2S2R9Q==} @@ -6888,13 +6886,13 @@ snapshots: '@libp2p/kad-dht@14.0.0': dependencies: - '@libp2p/crypto': 5.0.5 - '@libp2p/interface': 2.1.3 - '@libp2p/interface-internal': 2.0.9 - '@libp2p/peer-collections': 6.0.9 - '@libp2p/peer-id': 5.0.6 + '@libp2p/crypto': 5.0.6 + '@libp2p/interface': 2.2.0 + '@libp2p/interface-internal': 2.0.10 + '@libp2p/peer-collections': 6.0.10 + '@libp2p/peer-id': 5.0.7 '@libp2p/record': 4.0.4 - '@libp2p/utils': 6.1.2 + '@libp2p/utils': 6.1.3 '@multiformats/multiaddr': 12.3.1 any-signal: 4.1.1 hashlru: 2.3.0 @@ -6908,7 +6906,7 @@ snapshots: it-pipe: 3.0.1 it-protobuf-stream: 1.1.5 it-take: 3.0.6 - multiformats: 13.3.0 + multiformats: 13.3.1 p-defer: 4.0.1 p-event: 6.0.1 p-queue: 8.0.1 @@ -6919,7 +6917,7 @@ snapshots: uint8arraylist: 2.4.8 uint8arrays: 5.1.0 - '@libp2p/logger@5.1.2': + '@libp2p/logger@5.1.3': dependencies: '@libp2p/interface': 2.2.0 '@multiformats/multiaddr': 12.3.1 @@ -6977,26 +6975,26 @@ snapshots: uint8arraylist: 2.4.8 uint8arrays: 5.1.0 - '@libp2p/peer-store@11.0.7': + '@libp2p/peer-store@11.0.10': dependencies: - '@libp2p/crypto': 5.0.5 - '@libp2p/interface': 2.1.3 - '@libp2p/peer-collections': 6.0.9 - '@libp2p/peer-id': 5.0.6 - '@libp2p/peer-record': 8.0.9 + '@libp2p/crypto': 5.0.6 + '@libp2p/interface': 2.2.0 + '@libp2p/peer-id': 5.0.7 + '@libp2p/peer-record': 8.0.10 '@multiformats/multiaddr': 12.3.1 interface-datastore: 8.3.1 it-all: 3.0.6 mortice: 3.0.6 - multiformats: 13.3.0 + multiformats: 13.3.1 protons-runtime: 5.5.0 uint8arraylist: 2.4.8 uint8arrays: 5.1.0 - '@libp2p/peer-store@11.0.9': + '@libp2p/peer-store@11.0.7': dependencies: '@libp2p/crypto': 5.0.6 '@libp2p/interface': 2.2.0 + '@libp2p/peer-collections': 6.0.10 '@libp2p/peer-id': 5.0.7 '@libp2p/peer-record': 8.0.10 '@multiformats/multiaddr': 12.3.1 @@ -7041,7 +7039,7 @@ snapshots: uint8arraylist: 2.4.8 uint8arrays: 5.1.0 - '@libp2p/simple-metrics@1.2.5': + '@libp2p/simple-metrics@1.2.6': dependencies: '@libp2p/interface': 2.2.0 '@libp2p/logger': 5.1.3 From 5a83b6253297bb552bd466c56cd7046c18f4c8d9 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:14:47 +0200 Subject: [PATCH 14/61] Optimizing DHT --- packages/network/src/node.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 1db0dfe8..fa8f718a 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -21,7 +21,7 @@ import type { Stream, StreamHandler, } from "@libp2p/interface"; -import { kadDHT, removePublicAddressesMapper } from "@libp2p/kad-dht"; +import { kadDHT, removePrivateAddressesMapper, removePublicAddressesMapper } from "@libp2p/kad-dht"; import { webRTC, webRTCDirect } from "@libp2p/webrtc"; import { webSockets } from "@libp2p/websockets"; import * as filters from "@libp2p/websockets/filters"; @@ -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/relay.droak.sh/tcp/443/wss/p2p/Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP", + "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ" ]; const _peerDiscovery = _bootstrapNodesList.length @@ -92,9 +93,19 @@ export class TopologyNetworkNode { protocol: "/topology/dht/1.0.0", kBucketSize: this._config?.bootstrap ? 40 : 20, clientMode: false, + peerInfoMapper: removePrivateAddressesMapper, + initialQuerySelfInterval: 10000, + querySelfInterval: 15000, + allowQueryWithZeroPeers: false, + + }), + lanDHT: kadDHT({ + protocol: "/topology/lan/dht/1.0.0", + kBucketSize: 20, + clientMode: false, peerInfoMapper: removePublicAddressesMapper, - querySelfInterval: 20000, initialQuerySelfInterval: 10000, + querySelfInterval: 15000, allowQueryWithZeroPeers: false, }), }; From 885b5bb98fc3f7f529c7726787aaedfe8319822c Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:33:28 +0200 Subject: [PATCH 15/61] Trying WAN DHT only --- packages/network/src/node.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index fa8f718a..7da3de5f 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -73,7 +73,8 @@ export class TopologyNetworkNode { ? this._config.bootstrap_peers : [ // "/dns4/relay.droak.sh/tcp/443/wss/p2p/Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP", - "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ" + // "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", ]; const _peerDiscovery = _bootstrapNodesList.length @@ -99,15 +100,15 @@ export class TopologyNetworkNode { allowQueryWithZeroPeers: false, }), - lanDHT: kadDHT({ - protocol: "/topology/lan/dht/1.0.0", - kBucketSize: 20, - clientMode: false, - peerInfoMapper: removePublicAddressesMapper, - initialQuerySelfInterval: 10000, - querySelfInterval: 15000, - allowQueryWithZeroPeers: false, - }), + // lanDHT: kadDHT({ + // protocol: "/topology/lan/dht/1.0.0", + // kBucketSize: 20, + // clientMode: false, + // peerInfoMapper: removePublicAddressesMapper, + // initialQuerySelfInterval: 10000, + // querySelfInterval: 15000, + // allowQueryWithZeroPeers: false, + // }), }; const _bootstrap_node_services = { From bd09c285ad00ac057e15f2b1aafb13e103a26859 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:06:44 +0200 Subject: [PATCH 16/61] Keeping all addresses types --- packages/network/src/node.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 7da3de5f..784bd802 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -94,8 +94,9 @@ export class TopologyNetworkNode { protocol: "/topology/dht/1.0.0", kBucketSize: this._config?.bootstrap ? 40 : 20, clientMode: false, - peerInfoMapper: removePrivateAddressesMapper, - initialQuerySelfInterval: 10000, + // peerInfoMapper: removePrivateAddressesMapper, + // peerInfoMapper: removePublicAddressesMapper, + initialQuerySelfInterval: 2000, querySelfInterval: 15000, allowQueryWithZeroPeers: false, @@ -162,6 +163,11 @@ export class TopologyNetworkNode { this.peerId, ); + setInterval(() => { + const ma = this._node?.getMultiaddrs(); + log.info("::start::multiaddrs", ma); + }, 5000); + this._node.addEventListener("peer:connect", async (e) => {}); this._node.addEventListener("peer:discovery", async (e) => { From bf2fa605750a40a01ac35b3d588ff0c447313ac9 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:17:06 +0200 Subject: [PATCH 17/61] Remove private addresses mapper --- packages/network/src/node.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 784bd802..9492ecde 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -73,8 +73,8 @@ export class TopologyNetworkNode { ? this._config.bootstrap_peers : [ // "/dns4/relay.droak.sh/tcp/443/wss/p2p/Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP", - // "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", - "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + // "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", ]; const _peerDiscovery = _bootstrapNodesList.length @@ -90,16 +90,25 @@ export class TopologyNetworkNode { dcutr: dcutr(), identify: identify(), pubsub: gossipsub(), + // dht: kadDHT({ + // protocol: "/topology/dht/1.0.0", + // kBucketSize: this._config?.bootstrap ? 40 : 20, + // clientMode: false, + // // peerInfoMapper: removePrivateAddressesMapper, + // // peerInfoMapper: removePublicAddressesMapper, + // querySelfInterval: 20000, + // initialQuerySelfInterval: 30000, + // allowQueryWithZeroPeers: false, + + // }), dht: kadDHT({ protocol: "/topology/dht/1.0.0", kBucketSize: this._config?.bootstrap ? 40 : 20, clientMode: false, - // peerInfoMapper: removePrivateAddressesMapper, - // peerInfoMapper: removePublicAddressesMapper, - initialQuerySelfInterval: 2000, - querySelfInterval: 15000, + peerInfoMapper: removePrivateAddressesMapper, + querySelfInterval: 20000, + initialQuerySelfInterval: 10000, allowQueryWithZeroPeers: false, - }), // lanDHT: kadDHT({ // protocol: "/topology/lan/dht/1.0.0", From 75f875c871e939a3bae260434cce7c49198b3562 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:33:37 +0200 Subject: [PATCH 18/61] Updating DHT config --- packages/network/src/node.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 9492ecde..de35f3ea 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -73,8 +73,8 @@ export class TopologyNetworkNode { ? this._config.bootstrap_peers : [ // "/dns4/relay.droak.sh/tcp/443/wss/p2p/Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP", - "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", - // "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + // "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", ]; const _peerDiscovery = _bootstrapNodesList.length @@ -108,7 +108,7 @@ export class TopologyNetworkNode { peerInfoMapper: removePrivateAddressesMapper, querySelfInterval: 20000, initialQuerySelfInterval: 10000, - allowQueryWithZeroPeers: false, + allowQueryWithZeroPeers: true, }), // lanDHT: kadDHT({ // protocol: "/topology/lan/dht/1.0.0", From 7695a5319308c1ee6a9283b897cb1a91d5503130 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Wed, 6 Nov 2024 01:19:00 +0200 Subject: [PATCH 19/61] Public mapper --- packages/network/src/node.ts | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index de35f3ea..4ae60718 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -73,8 +73,8 @@ export class TopologyNetworkNode { ? this._config.bootstrap_peers : [ // "/dns4/relay.droak.sh/tcp/443/wss/p2p/Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP", - // "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", - "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + // "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", ]; const _peerDiscovery = _bootstrapNodesList.length @@ -100,15 +100,24 @@ export class TopologyNetworkNode { // initialQuerySelfInterval: 30000, // allowQueryWithZeroPeers: false, + // }), + // dht: kadDHT({ + // protocol: "/topology/dht/1.0.0", + // kBucketSize: this._config?.bootstrap ? 40 : 20, + // clientMode: false, + // // peerInfoMapper: removePrivateAddressesMapper, + // // peerInfoMapper: removePublicAddressesMapper, + // querySelfInterval: 1000, + // initialQuerySelfInterval: 20000, + // allowQueryWithZeroPeers: true, + // }), dht: kadDHT({ - protocol: "/topology/dht/1.0.0", - kBucketSize: this._config?.bootstrap ? 40 : 20, clientMode: false, - peerInfoMapper: removePrivateAddressesMapper, - querySelfInterval: 20000, - initialQuerySelfInterval: 10000, - allowQueryWithZeroPeers: true, + peerInfoMapper: removePrivateAddressesMapper, //this._config?.bootstrap ? removePrivateAddressesMapper : removePublicAddressesMapper, + querySelfInterval: 1000, + initialQuerySelfInterval: 20000, + allowQueryWithZeroPeers: false, }), // lanDHT: kadDHT({ // protocol: "/topology/lan/dht/1.0.0", @@ -159,7 +168,13 @@ export class TopologyNetworkNode { if (!this._config?.bootstrap) { for (const addr of this._config?.bootstrap_peers || []) { + // check if not dialing self + // try { this._node.dial(multiaddr(addr)); + // }catch(err){ + // console.error("Error dialing bootstrap peer", err); + // process.exit(1); + // } } } From b4fe317638b9e2715e35ed2b3f1dfab255663060 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Wed, 6 Nov 2024 01:36:35 +0200 Subject: [PATCH 20/61] Remove public address mapper --- packages/network/src/node.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 4ae60718..05fd45cb 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -73,8 +73,8 @@ export class TopologyNetworkNode { ? this._config.bootstrap_peers : [ // "/dns4/relay.droak.sh/tcp/443/wss/p2p/Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP", - "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", - // "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + // "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", ]; const _peerDiscovery = _bootstrapNodesList.length @@ -114,7 +114,7 @@ export class TopologyNetworkNode { // }), dht: kadDHT({ clientMode: false, - peerInfoMapper: removePrivateAddressesMapper, //this._config?.bootstrap ? removePrivateAddressesMapper : removePublicAddressesMapper, + peerInfoMapper: removePublicAddressesMapper, //this._config?.bootstrap ? removePrivateAddressesMapper : removePublicAddressesMapper, querySelfInterval: 1000, initialQuerySelfInterval: 20000, allowQueryWithZeroPeers: false, From 1fa8fd89ee03eee45de2a12ef157e222601270bc Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Wed, 6 Nov 2024 01:48:57 +0200 Subject: [PATCH 21/61] Rolling back to old config --- packages/network/src/node.ts | 39 +++++------------------------------- 1 file changed, 5 insertions(+), 34 deletions(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 05fd45cb..361ad7aa 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -90,44 +90,15 @@ export class TopologyNetworkNode { dcutr: dcutr(), identify: identify(), pubsub: gossipsub(), - // dht: kadDHT({ - // protocol: "/topology/dht/1.0.0", - // kBucketSize: this._config?.bootstrap ? 40 : 20, - // clientMode: false, - // // peerInfoMapper: removePrivateAddressesMapper, - // // peerInfoMapper: removePublicAddressesMapper, - // querySelfInterval: 20000, - // initialQuerySelfInterval: 30000, - // allowQueryWithZeroPeers: false, - - // }), - // dht: kadDHT({ - // protocol: "/topology/dht/1.0.0", - // kBucketSize: this._config?.bootstrap ? 40 : 20, - // clientMode: false, - // // peerInfoMapper: removePrivateAddressesMapper, - // // peerInfoMapper: removePublicAddressesMapper, - // querySelfInterval: 1000, - // initialQuerySelfInterval: 20000, - // allowQueryWithZeroPeers: true, - - // }), dht: kadDHT({ + protocol: "/topology/dht/1.0.0", + kBucketSize: this._config?.bootstrap ? 40 : 20, clientMode: false, - peerInfoMapper: removePublicAddressesMapper, //this._config?.bootstrap ? removePrivateAddressesMapper : removePublicAddressesMapper, - querySelfInterval: 1000, - initialQuerySelfInterval: 20000, + peerInfoMapper: removePublicAddressesMapper, + querySelfInterval: 20000, + initialQuerySelfInterval: 10000, allowQueryWithZeroPeers: false, }), - // lanDHT: kadDHT({ - // protocol: "/topology/lan/dht/1.0.0", - // kBucketSize: 20, - // clientMode: false, - // peerInfoMapper: removePublicAddressesMapper, - // initialQuerySelfInterval: 10000, - // querySelfInterval: 15000, - // allowQueryWithZeroPeers: false, - // }), }; const _bootstrap_node_services = { From 606f098f2a729c20fee4692b56318f33b459c8fa Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Wed, 6 Nov 2024 02:14:26 +0200 Subject: [PATCH 22/61] Public & private --- packages/network/src/node.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 361ad7aa..2f0b67b3 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -94,6 +94,15 @@ export class TopologyNetworkNode { protocol: "/topology/dht/1.0.0", kBucketSize: this._config?.bootstrap ? 40 : 20, clientMode: false, + peerInfoMapper: removePrivateAddressesMapper, + querySelfInterval: 20000, + initialQuerySelfInterval: 10000, + allowQueryWithZeroPeers: false, + }), + lanDHT: kadDHT({ + protocol: "/topology/lan/dht/1.0.0", + kBucketSize: this._config?.bootstrap ? 40 : 20, + clientMode: false, peerInfoMapper: removePublicAddressesMapper, querySelfInterval: 20000, initialQuerySelfInterval: 10000, From cba5542a47d1c91e811470d3024a36c552412726 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Wed, 6 Nov 2024 02:42:53 +0200 Subject: [PATCH 23/61] internet protocol --- packages/network/src/node.ts | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 2f0b67b3..51549911 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -73,8 +73,8 @@ export class TopologyNetworkNode { ? this._config.bootstrap_peers : [ // "/dns4/relay.droak.sh/tcp/443/wss/p2p/Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP", - // "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", - "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + // "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", ]; const _peerDiscovery = _bootstrapNodesList.length @@ -99,15 +99,15 @@ export class TopologyNetworkNode { initialQuerySelfInterval: 10000, allowQueryWithZeroPeers: false, }), - lanDHT: kadDHT({ - protocol: "/topology/lan/dht/1.0.0", - kBucketSize: this._config?.bootstrap ? 40 : 20, - clientMode: false, - peerInfoMapper: removePublicAddressesMapper, - querySelfInterval: 20000, - initialQuerySelfInterval: 10000, - allowQueryWithZeroPeers: false, - }), + // lanDHT: kadDHT({ + // protocol: "/topology/lan/dht/1.0.0", + // kBucketSize: this._config?.bootstrap ? 40 : 20, + // clientMode: false, + // peerInfoMapper: removePublicAddressesMapper, + // querySelfInterval: 20000, + // initialQuerySelfInterval: 10000, + // allowQueryWithZeroPeers: false, + // }), }; const _bootstrap_node_services = { @@ -131,7 +131,12 @@ export class TopologyNetworkNode { services: this._config?.bootstrap ? _bootstrap_node_services : _node_services, - streamMuxers: [yamux()], + streamMuxers: [yamux({ + enableKeepAlive: true, + keepAliveInterval: 10000, + maxMessageSize: 4194304, + + })], transports: [ circuitRelayTransport({ discoverRelays: 2, From eb2750e253b6c1b272206ae58e506754f4364bad Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Wed, 6 Nov 2024 02:53:53 +0200 Subject: [PATCH 24/61] Removing mapper --- packages/network/src/node.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 51549911..1105c6fe 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -73,8 +73,8 @@ export class TopologyNetworkNode { ? this._config.bootstrap_peers : [ // "/dns4/relay.droak.sh/tcp/443/wss/p2p/Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP", - "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", - // "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + // "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", ]; const _peerDiscovery = _bootstrapNodesList.length @@ -94,7 +94,7 @@ export class TopologyNetworkNode { protocol: "/topology/dht/1.0.0", kBucketSize: this._config?.bootstrap ? 40 : 20, clientMode: false, - peerInfoMapper: removePrivateAddressesMapper, + // peerInfoMapper: removePrivateAddressesMapper, querySelfInterval: 20000, initialQuerySelfInterval: 10000, allowQueryWithZeroPeers: false, From 93dac3249628ddc2d4b18066ab8bac841a8611c3 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Wed, 6 Nov 2024 03:28:27 +0200 Subject: [PATCH 25/61] Rmv private addr mapper --- packages/network/src/node.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 1105c6fe..e9423d48 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -94,7 +94,7 @@ export class TopologyNetworkNode { protocol: "/topology/dht/1.0.0", kBucketSize: this._config?.bootstrap ? 40 : 20, clientMode: false, - // peerInfoMapper: removePrivateAddressesMapper, + peerInfoMapper: removePrivateAddressesMapper, querySelfInterval: 20000, initialQuerySelfInterval: 10000, allowQueryWithZeroPeers: false, From 9bb5f1ba982b7e6953ad1bf5d50ad72566322499 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Wed, 6 Nov 2024 03:28:51 +0200 Subject: [PATCH 26/61] Rmv private addr mapper --- packages/network/src/node.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index e9423d48..b2d63fbe 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -94,7 +94,7 @@ export class TopologyNetworkNode { protocol: "/topology/dht/1.0.0", kBucketSize: this._config?.bootstrap ? 40 : 20, clientMode: false, - peerInfoMapper: removePrivateAddressesMapper, + peerInfoMapper: removePublicAddressesMapper, querySelfInterval: 20000, initialQuerySelfInterval: 10000, allowQueryWithZeroPeers: false, From b9fe214db9597d44b06adc98dee9bd923f62fd68 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Wed, 6 Nov 2024 06:16:16 +0200 Subject: [PATCH 27/61] Adding callback on new peers --- examples/grid/src/index.ts | 24 ++++++++++++----- packages/network/src/node.ts | 51 ++++++++++++++++++++++++++---------- 2 files changed, 55 insertions(+), 20 deletions(-) diff --git a/examples/grid/src/index.ts b/examples/grid/src/index.ts index 7f7c4e0f..1468c57c 100644 --- a/examples/grid/src/index.ts +++ b/examples/grid/src/index.ts @@ -4,6 +4,7 @@ import { Grid } from "./objects/grid"; import { hslToRgb, rgbToHex, rgbToHsl } from "./util/color"; const node = new TopologyNode(); + let topologyObject: TopologyObject; let gridCRO: Grid; let peers: string[] = []; @@ -196,15 +197,26 @@ async function createConnectHandlers() { } async function main() { + // node.networkNode.setOnPeerConnect((peerId : any) => { + // console.log("NEW PEER CONNECTED", peerId); + // peers = node.networkNode.getAllPeers(); + // render(); + // }); + await node.start(); render(); - setInterval(() => { - if (node.networkNode.checkNodeReady()) { - peers = node.networkNode.getAllPeers(); - render(); - } - }, 1000); + node.networkNode.getNode().addEventListener("peer:connect", (peerId) => { + peers = node.networkNode.getAllPeers(); + render(); + }); + + node.networkNode.getNode().addEventListener("peer:disconnect", (peerId) => { + peers = node.networkNode.getAllPeers(); + render(); + }); + + const button_create = ( document.getElementById("createGrid") diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index b2d63fbe..e1abe581 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -17,6 +17,7 @@ import { devToolsMetrics } from "@libp2p/devtools-metrics"; import { identify } from "@libp2p/identify"; import type { EventCallback, + PeerId, PubSub, Stream, StreamHandler, @@ -36,6 +37,7 @@ import { uint8ArrayToStream } from "./stream.js"; export * from "./stream.js"; let log: Logger; +type PeerConnectionCallback = (peerId: CustomEvent) => void; // snake_casing to match the JSON config export interface TopologyNetworkNodeConfig { @@ -45,6 +47,8 @@ export interface TopologyNetworkNodeConfig { browser_metrics?: boolean; private_key_seed?: string; log_config?: LoggerOptions; + onPeerConnect?: PeerConnectionCallback; + onPeerDisconnect?: PeerConnectionCallback; } export class TopologyNetworkNode { @@ -73,8 +77,8 @@ export class TopologyNetworkNode { ? this._config.bootstrap_peers : [ // "/dns4/relay.droak.sh/tcp/443/wss/p2p/Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP", - // "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", - "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + // "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", ]; const _peerDiscovery = _bootstrapNodesList.length @@ -90,17 +94,8 @@ export class TopologyNetworkNode { dcutr: dcutr(), identify: identify(), pubsub: gossipsub(), - dht: kadDHT({ - protocol: "/topology/dht/1.0.0", - kBucketSize: this._config?.bootstrap ? 40 : 20, - clientMode: false, - peerInfoMapper: removePublicAddressesMapper, - querySelfInterval: 20000, - initialQuerySelfInterval: 10000, - allowQueryWithZeroPeers: false, - }), - // lanDHT: kadDHT({ - // protocol: "/topology/lan/dht/1.0.0", + // dht: kadDHT({ + // protocol: "/topology/dht/1.0.0", // kBucketSize: this._config?.bootstrap ? 40 : 20, // clientMode: false, // peerInfoMapper: removePublicAddressesMapper, @@ -108,6 +103,15 @@ export class TopologyNetworkNode { // initialQuerySelfInterval: 10000, // allowQueryWithZeroPeers: false, // }), + lanDHT: kadDHT({ + protocol: "/topology/lan/dht/1.0.0", + kBucketSize: this._config?.bootstrap ? 40 : 20, + clientMode: false, + peerInfoMapper: removePublicAddressesMapper, + querySelfInterval: 20000, + initialQuerySelfInterval: 10000, + allowQueryWithZeroPeers: false, + }), }; const _bootstrap_node_services = { @@ -177,7 +181,13 @@ export class TopologyNetworkNode { log.info("::start::multiaddrs", ma); }, 5000); - this._node.addEventListener("peer:connect", async (e) => {}); + this._node.addEventListener("peer:connect", async (e) => { + if(this._config?.onPeerConnect) this._config?.onPeerConnect(e); + }); + + this._node.addEventListener("peer:disconnect", async (e) => { + if(this._config?.onPeerDisconnect) this._config?.onPeerDisconnect(e); + }); this._node.addEventListener("peer:discovery", async (e) => { // current bug in v11.0.0 requires manual dial (https://github.com/libp2p/js-libp2p-pubsub-peer-discovery/issues/149) @@ -301,4 +311,17 @@ export class TopologyNetworkNode { } return false; } + + // Set connection callback + setOnPeerConnect(callback: PeerConnectionCallback) { + if(this._config) this._config.onPeerConnect = callback; + } + + setOnPeerDisconnect(callback: PeerConnectionCallback) { + if(this._config) this._config.onPeerDisconnect = callback; + } + + getNode(): Libp2p | undefined { + return this._node; + } } From 408a8065a79b80ef654289b8df0f5c53ae4ee1f3 Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Wed, 6 Nov 2024 06:20:49 +0200 Subject: [PATCH 28/61] Refactoring Chat Example --- examples/chat/index.html | 1 - examples/chat/src/index.ts | 17 +++++++---------- packages/network/src/node.ts | 17 ++--------------- 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/examples/chat/index.html b/examples/chat/index.html index 51d899f1..8b77cf1d 100644 --- a/examples/chat/index.html +++ b/examples/chat/index.html @@ -11,7 +11,6 @@

Topology Protocol - Chat

Current peer ID

Connected to

peers:

-

discovery_peers:

object_peers:

diff --git a/examples/chat/src/index.ts b/examples/chat/src/index.ts index 50e6db6c..7845400f 100644 --- a/examples/chat/src/index.ts +++ b/examples/chat/src/index.ts @@ -7,7 +7,6 @@ const node = new TopologyNode(); let topologyObject: TopologyObject; let chatCRO: Chat; let peers: string[] = []; -let discoveryPeers: string[] = []; let objectPeers: string[] = []; const render = () => { @@ -20,11 +19,6 @@ const render = () => { const element_peers = document.getElementById("peers"); element_peers.innerHTML = `[${peers.join(", ")}]`; - const element_discoveryPeers = ( - document.getElementById("discoveryPeers") - ); - element_discoveryPeers.innerHTML = `[${discoveryPeers.join(", ")}]`; - const element_objectPeers = ( document.getElementById("objectPeers") ); @@ -75,14 +69,17 @@ async function createConnectHandlers() { }); } -async function main() { +async function main() { await node.start(); render(); - // generic message handler - node.addCustomGroupMessageHandler("", (e) => { + node.networkNode.getNode().addEventListener("peer:connect", (peerId) => { + peers = node.networkNode.getAllPeers(); + render(); + }); + + node.networkNode.getNode().addEventListener("peer:disconnect", (peerId) => { peers = node.networkNode.getAllPeers(); - discoveryPeers = node.networkNode.getGroupPeers("topology::discovery"); render(); }); diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index e1abe581..dd59dc21 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -181,13 +181,9 @@ export class TopologyNetworkNode { log.info("::start::multiaddrs", ma); }, 5000); - this._node.addEventListener("peer:connect", async (e) => { - if(this._config?.onPeerConnect) this._config?.onPeerConnect(e); - }); + this._node.addEventListener("peer:connect", async (e) => { }); - this._node.addEventListener("peer:disconnect", async (e) => { - if(this._config?.onPeerDisconnect) this._config?.onPeerDisconnect(e); - }); + this._node.addEventListener("peer:disconnect", async (e) => { }); this._node.addEventListener("peer:discovery", async (e) => { // current bug in v11.0.0 requires manual dial (https://github.com/libp2p/js-libp2p-pubsub-peer-discovery/issues/149) @@ -312,15 +308,6 @@ export class TopologyNetworkNode { return false; } - // Set connection callback - setOnPeerConnect(callback: PeerConnectionCallback) { - if(this._config) this._config.onPeerConnect = callback; - } - - setOnPeerDisconnect(callback: PeerConnectionCallback) { - if(this._config) this._config.onPeerDisconnect = callback; - } - getNode(): Libp2p | undefined { return this._node; } From 75899aba38a332cc5cc0ed9d6d57db5dc7bc726e Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Wed, 6 Nov 2024 06:26:26 +0200 Subject: [PATCH 29/61] Fixing canvas example --- examples/canvas/index.html | 1 - examples/canvas/src/index.ts | 14 ++++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/examples/canvas/index.html b/examples/canvas/index.html index 3211f75a..4dd69765 100644 --- a/examples/canvas/index.html +++ b/examples/canvas/index.html @@ -11,7 +11,6 @@

Connected to

peers:

-

discovery_peers:

object_peers:

{ const peers_element = document.getElementById("peers"); peers_element.innerHTML = `[${peers.join(", ")}]`; - const discovery_element = ( - document.getElementById("discovery_peers") - ); - discovery_element.innerHTML = `[${discoveryPeers.join(", ")}]`; - const object_element = ( document.getElementById("object_peers") ); @@ -84,9 +78,13 @@ async function init() { } } - node.addCustomGroupMessageHandler("", (e) => { + node.networkNode.getNode().addEventListener("peer:connect", (peerId) => { + peers = node.networkNode.getAllPeers(); + render(); + }); + + node.networkNode.getNode().addEventListener("peer:disconnect", (peerId) => { peers = node.networkNode.getAllPeers(); - discoveryPeers = node.networkNode.getGroupPeers("topology::discovery"); render(); }); From eed1ef39919fe7e0ab8b351613d2101b78ec699c Mon Sep 17 00:00:00 2001 From: elielnfinic <46634774+elielnfinic@users.noreply.github.com> Date: Fri, 8 Nov 2024 04:50:24 +0200 Subject: [PATCH 30/61] Research on bad dependencies issue --- examples/grid/src/index.ts | 1 - packages/network/src/node.ts | 2 +- packages/node/src/index.ts | 1 + packages/object/src/hashgraph/index.ts | 3 +++ 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/grid/src/index.ts b/examples/grid/src/index.ts index 1468c57c..10ac5b9a 100644 --- a/examples/grid/src/index.ts +++ b/examples/grid/src/index.ts @@ -264,7 +264,6 @@ async function main() { navigator.clipboard .writeText(gridIdText) .then(() => { - // alert("Grid CRO ID copied to clipboard!"); console.log("Grid CRO ID copied to clipboard"); }) .catch((err) => { diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index dd59dc21..b26c386b 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -103,7 +103,7 @@ export class TopologyNetworkNode { // initialQuerySelfInterval: 10000, // allowQueryWithZeroPeers: false, // }), - lanDHT: kadDHT({ + dht: kadDHT({ protocol: "/topology/lan/dht/1.0.0", kBucketSize: this._config?.bootstrap ? 40 : 20, clientMode: false, diff --git a/packages/node/src/index.ts b/packages/node/src/index.ts index 20463d61..b6079d49 100644 --- a/packages/node/src/index.ts +++ b/packages/node/src/index.ts @@ -78,6 +78,7 @@ export class TopologyNode { operations.createObject(this, object); operations.subscribeObject(this, object.id); if (sync) { + console.log("SYNC OBJECT WHEN STARTING"); operations.syncObject(this, object.id, peerId); } return object; diff --git a/packages/object/src/hashgraph/index.ts b/packages/object/src/hashgraph/index.ts index ba269009..47e03cad 100644 --- a/packages/object/src/hashgraph/index.ts +++ b/packages/object/src/hashgraph/index.ts @@ -124,6 +124,9 @@ export class HashGraph { return hash; // Vertex already exists } + console.log("My deps: ", deps); + console.log("Forward edges: ", this.forwardEdges); + console.log("Vertices: ", this.vertices); // Temporary fix: don't add the vertex if the dependencies are not present in the local HG. if ( !deps.every((dep) => this.forwardEdges.has(dep) || this.vertices.has(dep)) From ae2a7dc618f0083c8a00aba5893047d295014baa Mon Sep 17 00:00:00 2001 From: droak Date: Sat, 2 Nov 2024 02:29:37 +0900 Subject: [PATCH 31/61] chore: release v0.2.1 --- examples/canvas/package.json | 10 +++++----- examples/chat/package.json | 10 +++++----- examples/grid/package.json | 8 ++++---- examples/local-bootstrap/package.json | 10 +++++----- package.json | 2 +- packages/blueprints/package.json | 4 ++-- packages/logger/package.json | 2 +- packages/network/package.json | 4 ++-- packages/node/package.json | 10 +++++----- packages/object/package.json | 4 ++-- 10 files changed, 32 insertions(+), 32 deletions(-) diff --git a/examples/canvas/package.json b/examples/canvas/package.json index b842d07b..8810aee4 100644 --- a/examples/canvas/package.json +++ b/examples/canvas/package.json @@ -1,6 +1,6 @@ { "name": "ts-topology-examples-canvas", - "version": "0.2.1-4", + "version": "0.2.1", "license": "MIT", "scripts": { "build": "vite build", @@ -9,10 +9,10 @@ "start": "ts-node ./src/index.ts" }, "dependencies": { - "@topology-foundation/blueprints": "0.2.1-4", - "@topology-foundation/network": "0.2.1-4", - "@topology-foundation/node": "0.2.1-4", - "@topology-foundation/object": "0.2.1-4", + "@topology-foundation/blueprints": "0.2.1", + "@topology-foundation/network": "0.2.1", + "@topology-foundation/node": "0.2.1", + "@topology-foundation/object": "0.2.1", "crypto-browserify": "^3.12.0", "process": "^0.11.10", "stream-browserify": "^3.0.0", diff --git a/examples/chat/package.json b/examples/chat/package.json index 5c4686e2..559314be 100644 --- a/examples/chat/package.json +++ b/examples/chat/package.json @@ -1,6 +1,6 @@ { "name": "topology-example-chat", - "version": "0.2.1-4", + "version": "0.2.1", "description": "Topology Protocol Chat Example", "main": "src/index.ts", "repository": "https://github.com/topology-foundation/ts-topology.git", @@ -13,10 +13,10 @@ "start": "ts-node ./src/index.ts" }, "dependencies": { - "@topology-foundation/blueprints": "0.2.1-4", - "@topology-foundation/network": "0.2.1-4", - "@topology-foundation/node": "0.2.1-4", - "@topology-foundation/object": "0.2.1-4", + "@topology-foundation/blueprints": "0.2.1", + "@topology-foundation/network": "0.2.1", + "@topology-foundation/node": "0.2.1", + "@topology-foundation/object": "0.2.1", "assemblyscript": "^0.27.29", "crypto-browserify": "^3.12.0", "process": "^0.11.10", diff --git a/examples/grid/package.json b/examples/grid/package.json index 9d82ef26..c9dbd51c 100644 --- a/examples/grid/package.json +++ b/examples/grid/package.json @@ -1,6 +1,6 @@ { "name": "topology-example-grid", - "version": "0.2.1-4", + "version": "0.2.1", "description": "Topology Protocol Grid Exmaple", "main": "src/index.ts", "repository": "https://github.com/topology-foundation/ts-topology.git", @@ -13,9 +13,9 @@ "start": "ts-node ./src/index.ts" }, "dependencies": { - "@topology-foundation/network": "0.2.1-4", - "@topology-foundation/node": "0.2.1-4", - "@topology-foundation/object": "0.2.1-4", + "@topology-foundation/network": "0.2.1", + "@topology-foundation/node": "0.2.1", + "@topology-foundation/object": "0.2.1", "assemblyscript": "^0.27.29", "crypto-browserify": "^3.12.0", "memfs": "^4.11.1", diff --git a/examples/local-bootstrap/package.json b/examples/local-bootstrap/package.json index a86c3e20..064cd75f 100644 --- a/examples/local-bootstrap/package.json +++ b/examples/local-bootstrap/package.json @@ -1,6 +1,6 @@ { "name": "topology-example-localdev", - "version": "0.2.1-4", + "version": "0.2.1", "description": "Topology Protocol Local Dev Example", "main": "src/index.ts", "repository": "https://github.com/topology-foundation/ts-topology.git", @@ -13,10 +13,10 @@ "start": "ts-node ./src/index.ts" }, "dependencies": { - "@topology-foundation/blueprints": "0.2.1-4", - "@topology-foundation/network": "0.2.1-4", - "@topology-foundation/node": "0.2.1-4", - "@topology-foundation/object": "0.2.1-4", + "@topology-foundation/blueprints": "0.2.1", + "@topology-foundation/network": "0.2.1", + "@topology-foundation/node": "0.2.1", + "@topology-foundation/object": "0.2.1", "assemblyscript": "^0.27.29", "crypto-browserify": "^3.12.0", "process": "^0.11.10", diff --git a/package.json b/package.json index fb3cac75..c66bf75d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ts-topology", "description": "The official TypeScript implementation of Topology Protocol", - "version": "0.2.1-4", + "version": "0.2.1", "license": "MIT", "homepage": "https://topology.gg/", "repository": { diff --git a/packages/blueprints/package.json b/packages/blueprints/package.json index 0956e297..7a823e07 100644 --- a/packages/blueprints/package.json +++ b/packages/blueprints/package.json @@ -1,6 +1,6 @@ { "name": "@topology-foundation/blueprints", - "version": "0.2.1-4", + "version": "0.2.1", "license": "MIT", "repository": { "type": "git", @@ -34,7 +34,7 @@ "test": "vitest" }, "devDependencies": { - "@topology-foundation/object": "0.2.1-4", + "@topology-foundation/object": "0.2.1", "assemblyscript": "^0.27.29" }, "dependencies": { diff --git a/packages/logger/package.json b/packages/logger/package.json index 350197a3..545b739d 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -1,6 +1,6 @@ { "name": "@topology-foundation/logger", - "version": "0.2.1-4", + "version": "0.2.1", "license": "MIT", "repository": { "type": "git", diff --git a/packages/network/package.json b/packages/network/package.json index 153d0b47..fb30cdad 100644 --- a/packages/network/package.json +++ b/packages/network/package.json @@ -1,6 +1,6 @@ { "name": "@topology-foundation/network", - "version": "0.2.1-4", + "version": "0.2.1", "license": "MIT", "repository": { "type": "git", @@ -51,7 +51,7 @@ "@libp2p/websockets": "^9.0.7", "@libp2p/webtransport": "^5.0.9", "@multiformats/multiaddr": "^12.3.1", - "@topology-foundation/logger": "^0.2.1-4", + "@topology-foundation/logger": "^0.2.1", "it-length-prefixed": "^9.1.0", "it-map": "^3.1.1", "it-pipe": "^3.0.1", diff --git a/packages/node/package.json b/packages/node/package.json index f7db895e..23a9458d 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -1,6 +1,6 @@ { "name": "@topology-foundation/node", - "version": "0.2.1-4", + "version": "0.2.1", "license": "MIT", "repository": { "type": "git", @@ -40,10 +40,10 @@ "@grpc/grpc-js": "^1.12.2", "@libp2p/interface": "^2.1.3", "dotenv": "^16.4.5", - "@topology-foundation/blueprints": "0.2.1-4", - "@topology-foundation/network": "0.2.1-4", - "@topology-foundation/object": "0.2.1-4", - "@topology-foundation/logger": "0.2.1-4", + "@topology-foundation/blueprints": "0.2.1", + "@topology-foundation/network": "0.2.1", + "@topology-foundation/object": "0.2.1", + "@topology-foundation/logger": "0.2.1", "commander": "^12.1.0", "google-protobuf": "^3.21.2" } diff --git a/packages/object/package.json b/packages/object/package.json index 1987d451..ede49451 100644 --- a/packages/object/package.json +++ b/packages/object/package.json @@ -1,6 +1,6 @@ { "name": "@topology-foundation/object", - "version": "0.2.1-4", + "version": "0.2.1", "license": "MIT", "repository": { "type": "git", @@ -33,7 +33,7 @@ }, "dependencies": { "@bufbuild/protobuf": "^2.0.0", - "@topology-foundation/logger": "^0.2.1-4", + "@topology-foundation/logger": "^0.2.1", "ts-proto": "^2.2.4" } } From e9c4433a4eaf601a2faae9a9eb2105a4409ac527 Mon Sep 17 00:00:00 2001 From: Oak Date: Wed, 6 Nov 2024 02:44:12 +0000 Subject: [PATCH 32/61] feat: initial benchmarking w/ page deployment (#234) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: trungnotchung Co-authored-by: Phạm Xuân Trung <66519569+trungnotchung@users.noreply.github.com> Co-authored-by: github-action-benchmark --- .github/workflows/benchmark.yml | 56 +++++++++++++++++ .github/workflows/docs.yml | 7 +++ CODEOWNERS | 2 +- biome.json | 1 + packages/node/src/version.ts | 2 +- packages/object/package.json | 7 ++- .../object/tests/causallyrelated.bench.ts | 2 +- packages/object/tests/hashgraph.bench.ts | 63 +++++++++++++++++++ pnpm-lock.yaml | 63 ++++++++++++------- 9 files changed, 176 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/benchmark.yml create mode 100644 packages/object/tests/hashgraph.bench.ts diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 00000000..ff432b62 --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -0,0 +1,56 @@ +name: Benchmark +on: + push: + branches: [main] + +permissions: + pages: write + id-token: write + contents: write + +jobs: + benchmark: + name: Run benchmark + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + with: + version: 9 + - shell: bash + run: | + pnpm install --no-frozen-lockfile + cd packages/object + pnpm run benchmark + # possible lockfile and version.ts changes + git stash + + - name: Set cache dir + uses: actions/cache@v4 + with: + path: ./cache + key: ${{ runner.os }}-benchmark + + - name: Store benchmark result + uses: benchmark-action/github-action-benchmark@v1 + with: + name: Benchmark.js Benchmark + tool: "benchmarkjs" + github-token: ${{ secrets.GITHUB_TOKEN }} + output-file-path: packages/object/benchmark-output.txt + alert-threshold: "10%" + fail-on-alert: true + comment-always: true + gh-pages-branch: main + skip-fetch-gh-pages: true + benchmark-data-dir-path: ./cache/benchmarks + + docs: + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + name: Release docs + permissions: + pages: write + id-token: write + needs: + - benchmark + uses: ./.github/workflows/docs.yml diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 2bd6c7e5..cba684db 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -2,6 +2,7 @@ name: Generate docs on: release: types: [published] + workflow_call: permissions: pages: write id-token: write @@ -13,9 +14,15 @@ jobs: - uses: pnpm/action-setup@v4 with: version: 9 + - name: Get benchmark cache + uses: actions/cache@v4 + with: + path: ./cache + key: ${{ runner.os }}-benchmark - run: | pnpm install --no-frozen-lockfile yarn docs + cp -r ./cache/* ./docs - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: diff --git a/CODEOWNERS b/CODEOWNERS index 6c0fb776..16d023a2 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1 +1 @@ -* @d-roak @JanLewDev @elielnfinic @trungnotchung @winprn @hoangquocvietuet +* @trungnotchung diff --git a/biome.json b/biome.json index 26df7c23..ae1e79f0 100644 --- a/biome.json +++ b/biome.json @@ -4,6 +4,7 @@ "ignore": [ "**/dist/*", "**/docs/*", + "**/doc/*", "**/*_pb.js", "**/*_pb.ts", "**/bundle/*", diff --git a/packages/node/src/version.ts b/packages/node/src/version.ts index bb1d4545..2e0f48d1 100644 --- a/packages/node/src/version.ts +++ b/packages/node/src/version.ts @@ -1 +1 @@ -export const VERSION = "0.2.1-4"; +export const VERSION = "0.2.1"; diff --git a/packages/object/package.json b/packages/object/package.json index ede49451..5c4ac459 100644 --- a/packages/object/package.json +++ b/packages/object/package.json @@ -26,10 +26,13 @@ "build": "tsc -b", "clean": "rm -rf dist/ node_modules/", "prepack": "tsc -b", - "test": "vitest" + "test": "vitest", + "benchmark": "npx tsx tests/hashgraph.bench.ts | tee benchmark-output.txt" }, "devDependencies": { - "assemblyscript": "^0.27.29" + "assemblyscript": "^0.27.29", + "benchmark": "^2.1.4", + "tsx": "4.19.1" }, "dependencies": { "@bufbuild/protobuf": "^2.0.0", diff --git a/packages/object/tests/causallyrelated.bench.ts b/packages/object/tests/causallyrelated.bench.ts index 8f9e1a73..1eaf0963 100644 --- a/packages/object/tests/causallyrelated.bench.ts +++ b/packages/object/tests/causallyrelated.bench.ts @@ -1,5 +1,5 @@ import { bench, describe } from "vitest"; -import { AddWinsSet } from "../../crdt/src/cros/AddWinsSet/index.js"; +import { AddWinsSet } from "../../blueprints/src/AddWinsSet/index.js"; import { type Hash, TopologyObject } from "../src/index.js"; describe("AreCausallyDependent benchmark", async () => { diff --git a/packages/object/tests/hashgraph.bench.ts b/packages/object/tests/hashgraph.bench.ts new file mode 100644 index 00000000..eaa77791 --- /dev/null +++ b/packages/object/tests/hashgraph.bench.ts @@ -0,0 +1,63 @@ +import Benchmark from "benchmark"; +import { AddWinsSet } from "../../blueprints/src/AddWinsSet/index.js"; +import { TopologyObject } from "../src/index.js"; + +function benchmarkForAddWinSet( + name: string, + numCROs: number, + verticesPerCRO: number, + mergeFn: boolean, +) { + return suite.add(name, () => { + const objects: TopologyObject[] = []; + for (let i = 0; i < numCROs; i++) { + const obj: TopologyObject = new TopologyObject( + `peer${i + 1}`, + new AddWinsSet(), + ); + const cro = obj.cro as AddWinsSet; + for (let j = 0; j < verticesPerCRO; j++) { + if (i % 3 === 2) { + cro.add(j); + cro.remove(j); + } else if (i % 3 === 1) { + cro.remove(j); + cro.add(j); + } else { + cro.add(j); + } + } + objects.push(obj); + } + + if (mergeFn) { + for (let i = 0; i < objects.length; i++) { + for (let j = 0; j < objects.length; j++) { + if (i !== j) { + objects[i].merge(objects[j].hashGraph.getAllVertices()); + } + } + } + } + }); +} + +const suite = new Benchmark.Suite(); + +benchmarkForAddWinSet("Create HashGraph with 1000 vertices", 1, 1000, false); + +benchmarkForAddWinSet( + "Create 2 CROs (1000 vertices each) and Merge", + 2, + 1000, + true, +); + +suite + .on("cycle", (event) => { + console.log(String(event.target)); + }) + .on("complete", function () { + console.log(`Fastest is ${this.filter("fastest").map("name")}`); + }) + .run({ async: true }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b1cfa5eb..93d12c76 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -45,16 +45,16 @@ importers: examples/canvas: dependencies: '@topology-foundation/blueprints': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../../packages/blueprints '@topology-foundation/network': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../../packages/network '@topology-foundation/node': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../../packages/node '@topology-foundation/object': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../../packages/object crypto-browserify: specifier: ^3.12.0 @@ -91,16 +91,16 @@ importers: examples/chat: dependencies: '@topology-foundation/blueprints': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../../packages/blueprints '@topology-foundation/network': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../../packages/network '@topology-foundation/node': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../../packages/node '@topology-foundation/object': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../../packages/object assemblyscript: specifier: ^0.27.29 @@ -143,13 +143,13 @@ importers: examples/grid: dependencies: '@topology-foundation/network': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../../packages/network '@topology-foundation/node': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../../packages/node '@topology-foundation/object': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../../packages/object assemblyscript: specifier: ^0.27.29 @@ -198,16 +198,16 @@ importers: examples/local-bootstrap: dependencies: '@topology-foundation/blueprints': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../../packages/blueprints '@topology-foundation/network': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../../packages/network '@topology-foundation/node': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../../packages/node '@topology-foundation/object': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../../packages/object assemblyscript: specifier: ^0.27.29 @@ -254,7 +254,7 @@ importers: version: 4.1.2 devDependencies: '@topology-foundation/object': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../object assemblyscript: specifier: ^0.27.29 @@ -332,7 +332,7 @@ importers: specifier: ^12.3.1 version: 12.3.1 '@topology-foundation/logger': - specifier: ^0.2.1-4 + specifier: ^0.2.1 version: link:../logger it-length-prefixed: specifier: ^9.1.0 @@ -372,16 +372,16 @@ importers: specifier: ^2.1.3 version: 2.2.0 '@topology-foundation/blueprints': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../blueprints '@topology-foundation/logger': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../logger '@topology-foundation/network': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../network '@topology-foundation/object': - specifier: 0.2.1-4 + specifier: 0.2.1 version: link:../object commander: specifier: ^12.1.0 @@ -415,7 +415,7 @@ importers: specifier: ^2.0.0 version: 2.2.1 '@topology-foundation/logger': - specifier: ^0.2.1-4 + specifier: ^0.2.1 version: link:../logger ts-proto: specifier: ^2.2.4 @@ -424,6 +424,12 @@ importers: assemblyscript: specifier: ^0.27.29 version: 0.27.30 + benchmark: + specifier: ^2.1.4 + version: 2.1.4 + tsx: + specifier: 4.19.1 + version: 4.19.1 packages: @@ -2466,6 +2472,9 @@ packages: before-after-hook@2.2.3: resolution: {integrity: sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==} + benchmark@2.1.4: + resolution: {integrity: sha512-l9MlfN4M1K/H2fbhfMy3B7vJd6AGKJVQn2h6Sg/Yx+KckoUA7ewS5Vv6TjSq18ooE1kS9hhAlQRH3AkXIh/aOQ==} + binaryen@116.0.0-nightly.20240114: resolution: {integrity: sha512-0GZrojJnuhoe+hiwji7QFaL3tBlJoA+KFUN7ouYSDGZLSo9CKM8swQX8n/UcbR0d1VuZKU+nhogNzv423JEu5A==} hasBin: true @@ -4386,6 +4395,9 @@ packages: resolution: {integrity: sha512-NPE8TDbzl/3YQYY7CSS228s3g2ollTFnc+Qi3tqmqJp9Vg2ovUpixcJEo2HJScN2Ez+kEaal6y70c0ehqJBJeA==} engines: {node: '>=10'} + platform@1.3.6: + resolution: {integrity: sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg==} + possible-typed-array-names@1.0.0: resolution: {integrity: sha512-d7Uw+eZoloe0EHDIYoe+bQ5WXnGMOpmiZFTuMWCwpjzzkL2nTjcKiAk4hh8TjnGye2TwWOk3UXucZ+3rbmBa8Q==} engines: {node: '>= 0.4'} @@ -8110,6 +8122,11 @@ snapshots: before-after-hook@2.2.3: {} + benchmark@2.1.4: + dependencies: + lodash: 4.17.21 + platform: 1.3.6 + binaryen@116.0.0-nightly.20240114: {} bintrees@1.0.2: {} @@ -10294,6 +10311,8 @@ snapshots: dependencies: find-up: 5.0.0 + platform@1.3.6: {} + possible-typed-array-names@1.0.0: {} postcss@8.4.47: From 722cbacbd9e6deb2103f3faf3295871b41401c0d Mon Sep 17 00:00:00 2001 From: droak Date: Wed, 6 Nov 2024 11:56:11 +0900 Subject: [PATCH 33/61] chore: remove compose in favor of infra repo --- docker-compose.yml | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index c12e0e13..00000000 --- a/docker-compose.yml +++ /dev/null @@ -1,25 +0,0 @@ -services: - proxy: - image: valian/docker-nginx-auto-ssl - restart: on-failure - ports: - - 80:80 - - 443:443 - volumes: - - ssl_data:/etc/resty-auto-ssl - environment: - FORCE_HTTPS: true - SITES: relay.domain.com=relay:50000 - depends_on: - - relay - - relay: - build: - context: packages/node - dockerfile: Dockerfile - ports: - - 50000:50000 - command: -m relay - -volumes: - ssl_data: From 90abfe1f3dea2b22c12041a88aa55f3a2060f7fe Mon Sep 17 00:00:00 2001 From: droak Date: Wed, 6 Nov 2024 11:58:15 +0900 Subject: [PATCH 34/61] chore: change the alert threshold for the benchmark --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index ff432b62..b6c6564e 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -38,7 +38,7 @@ jobs: tool: "benchmarkjs" github-token: ${{ secrets.GITHUB_TOKEN }} output-file-path: packages/object/benchmark-output.txt - alert-threshold: "10%" + alert-threshold: "200%" fail-on-alert: true comment-always: true gh-pages-branch: main From 329514de6e74037505b6504247b0a7b0ea18782a Mon Sep 17 00:00:00 2001 From: Oak Date: Wed, 6 Nov 2024 03:46:11 +0000 Subject: [PATCH 35/61] ci: add pull request on the benchmark flow (#235) --- .github/workflows/benchmark.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index b6c6564e..61130d50 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -2,15 +2,19 @@ name: Benchmark on: push: branches: [main] + pull_request: + branches: [main] permissions: pages: write id-token: write - contents: write + pull-requests: write jobs: benchmark: name: Run benchmark + permissions: + pull-requests: write runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -42,7 +46,7 @@ jobs: fail-on-alert: true comment-always: true gh-pages-branch: main - skip-fetch-gh-pages: true + skip-fetch-gh-pages: ${{ github.event_name == 'push' }} benchmark-data-dir-path: ./cache/benchmarks docs: From cd58082fa599faa5f7f02df9a30088de6c03769e Mon Sep 17 00:00:00 2001 From: Oak Date: Wed, 6 Nov 2024 04:24:34 +0000 Subject: [PATCH 36/61] ci: refactor perms and change output summaries (#237) --- .github/workflows/benchmark.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 61130d50..e6cf97b2 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -8,13 +8,11 @@ on: permissions: pages: write id-token: write - pull-requests: write + contents: write jobs: benchmark: name: Run benchmark - permissions: - pull-requests: write runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -26,8 +24,6 @@ jobs: pnpm install --no-frozen-lockfile cd packages/object pnpm run benchmark - # possible lockfile and version.ts changes - git stash - name: Set cache dir uses: actions/cache@v4 @@ -44,7 +40,8 @@ jobs: output-file-path: packages/object/benchmark-output.txt alert-threshold: "200%" fail-on-alert: true - comment-always: true + comment-on-alert: ${{ github.event_name == 'push' }} + summary-always: true gh-pages-branch: main skip-fetch-gh-pages: ${{ github.event_name == 'push' }} benchmark-data-dir-path: ./cache/benchmarks From 25782165a94f2532ea96f35896a609f2eb4e4dfa Mon Sep 17 00:00:00 2001 From: droak Date: Wed, 6 Nov 2024 13:30:40 +0900 Subject: [PATCH 37/61] ci: save benchmark cache --- .github/workflows/benchmark.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index e6cf97b2..bbb6a7e4 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -46,6 +46,12 @@ jobs: skip-fetch-gh-pages: ${{ github.event_name == 'push' }} benchmark-data-dir-path: ./cache/benchmarks + - name: Save cache + uses: actions/cache/save@v4 + with: + path: ./cache + key: ${{ runner.os }}-benchmark + docs: if: github.event_name == 'push' && github.ref == 'refs/heads/main' name: Release docs From a1dae4084731e6bfe594c99d58ae8b81926f6558 Mon Sep 17 00:00:00 2001 From: droak Date: Wed, 6 Nov 2024 13:41:18 +0900 Subject: [PATCH 38/61] ci: use cache restore in the benchmark --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index bbb6a7e4..eef3c382 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -26,7 +26,7 @@ jobs: pnpm run benchmark - name: Set cache dir - uses: actions/cache@v4 + uses: actions/cache/restore@v4 with: path: ./cache key: ${{ runner.os }}-benchmark From 2ef4864d4eb35310700abe2719b0977fae777e03 Mon Sep 17 00:00:00 2001 From: droak Date: Wed, 6 Nov 2024 13:46:26 +0900 Subject: [PATCH 39/61] ci: change how cache is saved/restored --- .github/workflows/benchmark.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index eef3c382..a6b50099 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -26,10 +26,12 @@ jobs: pnpm run benchmark - name: Set cache dir - uses: actions/cache/restore@v4 + uses: actions/cache@v4 with: path: ./cache - key: ${{ runner.os }}-benchmark + key: benchmark-${{ runner.os }}-${{ github.run_id }} + restore-keys: | + benchmark-${{ runner.os }} - name: Store benchmark result uses: benchmark-action/github-action-benchmark@v1 @@ -46,12 +48,6 @@ jobs: skip-fetch-gh-pages: ${{ github.event_name == 'push' }} benchmark-data-dir-path: ./cache/benchmarks - - name: Save cache - uses: actions/cache/save@v4 - with: - path: ./cache - key: ${{ runner.os }}-benchmark - docs: if: github.event_name == 'push' && github.ref == 'refs/heads/main' name: Release docs From f823199bc2d4a9f278f082d7d15fee725e53941d Mon Sep 17 00:00:00 2001 From: droak Date: Wed, 6 Nov 2024 13:49:21 +0900 Subject: [PATCH 40/61] ci: change cache retrieved on docs workflow --- .github/workflows/docs.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index cba684db..7ff10a79 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -18,7 +18,10 @@ jobs: uses: actions/cache@v4 with: path: ./cache - key: ${{ runner.os }}-benchmark + key: benchmark-${{ runner.os }}-${{ github.run_id }} + restore-keys: | + benchmark-${{ runner.os }} + path: ./cache - run: | pnpm install --no-frozen-lockfile yarn docs From 378e2d117c929bd0a482deb5108f3c64e7726b06 Mon Sep 17 00:00:00 2001 From: droak Date: Wed, 6 Nov 2024 13:54:29 +0900 Subject: [PATCH 41/61] ci: change benchmark alert threshold to 50% --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index a6b50099..ff24bc7c 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -40,7 +40,7 @@ jobs: tool: "benchmarkjs" github-token: ${{ secrets.GITHUB_TOKEN }} output-file-path: packages/object/benchmark-output.txt - alert-threshold: "200%" + alert-threshold: "50%" fail-on-alert: true comment-on-alert: ${{ github.event_name == 'push' }} summary-always: true From f7331c8ebfb80a61dd190cc3ab588cb583b344c1 Mon Sep 17 00:00:00 2001 From: droak Date: Wed, 6 Nov 2024 13:56:35 +0900 Subject: [PATCH 42/61] ci: change benchmark alert threshold to 110% --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index ff24bc7c..f86b3302 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -40,7 +40,7 @@ jobs: tool: "benchmarkjs" github-token: ${{ secrets.GITHUB_TOKEN }} output-file-path: packages/object/benchmark-output.txt - alert-threshold: "50%" + alert-threshold: "110%" fail-on-alert: true comment-on-alert: ${{ github.event_name == 'push' }} summary-always: true From 7fc36283aa5cbe1e4785b71300b01551e5dd28bc Mon Sep 17 00:00:00 2001 From: droak Date: Wed, 6 Nov 2024 14:00:08 +0900 Subject: [PATCH 43/61] ci: change benchmark alert threshold to 130% --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index f86b3302..4e4f6d9b 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -40,7 +40,7 @@ jobs: tool: "benchmarkjs" github-token: ${{ secrets.GITHUB_TOKEN }} output-file-path: packages/object/benchmark-output.txt - alert-threshold: "110%" + alert-threshold: "130%" fail-on-alert: true comment-on-alert: ${{ github.event_name == 'push' }} summary-always: true From aa109ceb8b85029c981b99a82053fdc6c5cb5d91 Mon Sep 17 00:00:00 2001 From: droak Date: Wed, 6 Nov 2024 14:58:40 +0900 Subject: [PATCH 44/61] chore: fix CODEOWNERS --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index 16d023a2..c1a433c7 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1 +1 @@ -* @trungnotchung +* @d-roak @JanLewDev @elielnfinic @trungnotchung @hoangquocvietue From 3c3d6c2777eabcd6381bb2930b239340c9530ab5 Mon Sep 17 00:00:00 2001 From: Oak Date: Wed, 6 Nov 2024 16:40:16 +0000 Subject: [PATCH 45/61] chore: fix oliver's id --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index c1a433c7..9a152947 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1 +1 @@ -* @d-roak @JanLewDev @elielnfinic @trungnotchung @hoangquocvietue +* @d-roak @JanLewDev @elielnfinic @trungnotchung @hoangquocvietuet From 15c9a0ce023493b6f59df095ed3c7b7ec514cef2 Mon Sep 17 00:00:00 2001 From: Oak Date: Wed, 6 Nov 2024 18:35:28 +0000 Subject: [PATCH 46/61] refactor: change relay to bootstrap mode (#239) --- packages/node/README.md | 4 ++-- packages/node/src/cli/index.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/node/README.md b/packages/node/README.md index 1c01ec96..bf467ecb 100644 --- a/packages/node/README.md +++ b/packages/node/README.md @@ -30,13 +30,13 @@ topology-node --help You can run a bootstrap node using the following command: ```bash -pnpm relay --config configs/bootstrap.json +pnpm cli bootstrap --config configs/bootstrap.json ``` If you want to run a local bootstrap node, you can use the following command: ```bash -pnpm relay --config configs/local-bootstrap.json +pnpm cli bootstrap --config configs/local-bootstrap.json ``` ### Integration diff --git a/packages/node/src/cli/index.ts b/packages/node/src/cli/index.ts index 822ac3d3..93edc214 100644 --- a/packages/node/src/cli/index.ts +++ b/packages/node/src/cli/index.ts @@ -8,5 +8,5 @@ program.addOption(new Option("-c, --config ", "config file")); program.addOption( new Option("-m, --mode ", "mode to run in") .default("node") - .choices(["node", "relay"]), + .choices(["node", "bootstrap"]), ); From 36f63b01e94cbfb22170919ccb67ac4afd789e73 Mon Sep 17 00:00:00 2001 From: droak Date: Thu, 7 Nov 2024 03:37:27 +0900 Subject: [PATCH 47/61] chore: release v0.3.0 --- examples/canvas/package.json | 10 +++++----- examples/chat/package.json | 10 +++++----- examples/grid/package.json | 8 ++++---- examples/local-bootstrap/package.json | 10 +++++----- package.json | 2 +- packages/blueprints/package.json | 4 ++-- packages/logger/package.json | 2 +- packages/network/package.json | 4 ++-- packages/node/package.json | 10 +++++----- packages/object/package.json | 4 ++-- 10 files changed, 32 insertions(+), 32 deletions(-) diff --git a/examples/canvas/package.json b/examples/canvas/package.json index 8810aee4..4830d3cf 100644 --- a/examples/canvas/package.json +++ b/examples/canvas/package.json @@ -1,6 +1,6 @@ { "name": "ts-topology-examples-canvas", - "version": "0.2.1", + "version": "0.3.0", "license": "MIT", "scripts": { "build": "vite build", @@ -9,10 +9,10 @@ "start": "ts-node ./src/index.ts" }, "dependencies": { - "@topology-foundation/blueprints": "0.2.1", - "@topology-foundation/network": "0.2.1", - "@topology-foundation/node": "0.2.1", - "@topology-foundation/object": "0.2.1", + "@topology-foundation/blueprints": "0.3.0", + "@topology-foundation/network": "0.3.0", + "@topology-foundation/node": "0.3.0", + "@topology-foundation/object": "0.3.0", "crypto-browserify": "^3.12.0", "process": "^0.11.10", "stream-browserify": "^3.0.0", diff --git a/examples/chat/package.json b/examples/chat/package.json index 559314be..81780eaf 100644 --- a/examples/chat/package.json +++ b/examples/chat/package.json @@ -1,6 +1,6 @@ { "name": "topology-example-chat", - "version": "0.2.1", + "version": "0.3.0", "description": "Topology Protocol Chat Example", "main": "src/index.ts", "repository": "https://github.com/topology-foundation/ts-topology.git", @@ -13,10 +13,10 @@ "start": "ts-node ./src/index.ts" }, "dependencies": { - "@topology-foundation/blueprints": "0.2.1", - "@topology-foundation/network": "0.2.1", - "@topology-foundation/node": "0.2.1", - "@topology-foundation/object": "0.2.1", + "@topology-foundation/blueprints": "0.3.0", + "@topology-foundation/network": "0.3.0", + "@topology-foundation/node": "0.3.0", + "@topology-foundation/object": "0.3.0", "assemblyscript": "^0.27.29", "crypto-browserify": "^3.12.0", "process": "^0.11.10", diff --git a/examples/grid/package.json b/examples/grid/package.json index c9dbd51c..436f2b29 100644 --- a/examples/grid/package.json +++ b/examples/grid/package.json @@ -1,6 +1,6 @@ { "name": "topology-example-grid", - "version": "0.2.1", + "version": "0.3.0", "description": "Topology Protocol Grid Exmaple", "main": "src/index.ts", "repository": "https://github.com/topology-foundation/ts-topology.git", @@ -13,9 +13,9 @@ "start": "ts-node ./src/index.ts" }, "dependencies": { - "@topology-foundation/network": "0.2.1", - "@topology-foundation/node": "0.2.1", - "@topology-foundation/object": "0.2.1", + "@topology-foundation/network": "0.3.0", + "@topology-foundation/node": "0.3.0", + "@topology-foundation/object": "0.3.0", "assemblyscript": "^0.27.29", "crypto-browserify": "^3.12.0", "memfs": "^4.11.1", diff --git a/examples/local-bootstrap/package.json b/examples/local-bootstrap/package.json index 064cd75f..891c5971 100644 --- a/examples/local-bootstrap/package.json +++ b/examples/local-bootstrap/package.json @@ -1,6 +1,6 @@ { "name": "topology-example-localdev", - "version": "0.2.1", + "version": "0.3.0", "description": "Topology Protocol Local Dev Example", "main": "src/index.ts", "repository": "https://github.com/topology-foundation/ts-topology.git", @@ -13,10 +13,10 @@ "start": "ts-node ./src/index.ts" }, "dependencies": { - "@topology-foundation/blueprints": "0.2.1", - "@topology-foundation/network": "0.2.1", - "@topology-foundation/node": "0.2.1", - "@topology-foundation/object": "0.2.1", + "@topology-foundation/blueprints": "0.3.0", + "@topology-foundation/network": "0.3.0", + "@topology-foundation/node": "0.3.0", + "@topology-foundation/object": "0.3.0", "assemblyscript": "^0.27.29", "crypto-browserify": "^3.12.0", "process": "^0.11.10", diff --git a/package.json b/package.json index c66bf75d..4c8184fb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ts-topology", "description": "The official TypeScript implementation of Topology Protocol", - "version": "0.2.1", + "version": "0.3.0", "license": "MIT", "homepage": "https://topology.gg/", "repository": { diff --git a/packages/blueprints/package.json b/packages/blueprints/package.json index 7a823e07..1f448eaa 100644 --- a/packages/blueprints/package.json +++ b/packages/blueprints/package.json @@ -1,6 +1,6 @@ { "name": "@topology-foundation/blueprints", - "version": "0.2.1", + "version": "0.3.0", "license": "MIT", "repository": { "type": "git", @@ -34,7 +34,7 @@ "test": "vitest" }, "devDependencies": { - "@topology-foundation/object": "0.2.1", + "@topology-foundation/object": "0.3.0", "assemblyscript": "^0.27.29" }, "dependencies": { diff --git a/packages/logger/package.json b/packages/logger/package.json index 545b739d..82c27807 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -1,6 +1,6 @@ { "name": "@topology-foundation/logger", - "version": "0.2.1", + "version": "0.3.0", "license": "MIT", "repository": { "type": "git", diff --git a/packages/network/package.json b/packages/network/package.json index fb30cdad..bc742d93 100644 --- a/packages/network/package.json +++ b/packages/network/package.json @@ -1,6 +1,6 @@ { "name": "@topology-foundation/network", - "version": "0.2.1", + "version": "0.3.0", "license": "MIT", "repository": { "type": "git", @@ -51,7 +51,7 @@ "@libp2p/websockets": "^9.0.7", "@libp2p/webtransport": "^5.0.9", "@multiformats/multiaddr": "^12.3.1", - "@topology-foundation/logger": "^0.2.1", + "@topology-foundation/logger": "^0.3.0", "it-length-prefixed": "^9.1.0", "it-map": "^3.1.1", "it-pipe": "^3.0.1", diff --git a/packages/node/package.json b/packages/node/package.json index 23a9458d..04a8d9f3 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -1,6 +1,6 @@ { "name": "@topology-foundation/node", - "version": "0.2.1", + "version": "0.3.0", "license": "MIT", "repository": { "type": "git", @@ -40,10 +40,10 @@ "@grpc/grpc-js": "^1.12.2", "@libp2p/interface": "^2.1.3", "dotenv": "^16.4.5", - "@topology-foundation/blueprints": "0.2.1", - "@topology-foundation/network": "0.2.1", - "@topology-foundation/object": "0.2.1", - "@topology-foundation/logger": "0.2.1", + "@topology-foundation/blueprints": "0.3.0", + "@topology-foundation/network": "0.3.0", + "@topology-foundation/object": "0.3.0", + "@topology-foundation/logger": "0.3.0", "commander": "^12.1.0", "google-protobuf": "^3.21.2" } diff --git a/packages/object/package.json b/packages/object/package.json index 5c4ac459..70b75ae3 100644 --- a/packages/object/package.json +++ b/packages/object/package.json @@ -1,6 +1,6 @@ { "name": "@topology-foundation/object", - "version": "0.2.1", + "version": "0.3.0", "license": "MIT", "repository": { "type": "git", @@ -36,7 +36,7 @@ }, "dependencies": { "@bufbuild/protobuf": "^2.0.0", - "@topology-foundation/logger": "^0.2.1", + "@topology-foundation/logger": "^0.3.0", "ts-proto": "^2.2.4" } } From 5f090f79e09e5a1f3506a751d6113a4d8a4200e7 Mon Sep 17 00:00:00 2001 From: Chen Wen Kang <23054115+cwkang1998@users.noreply.github.com> Date: Fri, 8 Nov 2024 00:51:54 +0700 Subject: [PATCH 48/61] fix: lost of CRO context in `resolveConflicts` (#243) --- packages/object/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/object/src/index.ts b/packages/object/src/index.ts index baf19fd8..3389003a 100644 --- a/packages/object/src/index.ts +++ b/packages/object/src/index.ts @@ -56,7 +56,7 @@ export class TopologyObject implements ITopologyObject { this.cro = new Proxy(cro, this.proxyCROHandler()); this.hashGraph = new HashGraph( nodeId, - cro.resolveConflicts, + cro.resolveConflicts.bind(cro), cro.semanticsType, ); this.subscriptions = []; From 2c3b6223eafb4e1515306247a7bbed0a05b120f2 Mon Sep 17 00:00:00 2001 From: Oak Date: Sun, 10 Nov 2024 10:54:09 +0000 Subject: [PATCH 49/61] chore: rm oliver from codeowners --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index 9a152947..b35b4700 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1 +1 @@ -* @d-roak @JanLewDev @elielnfinic @trungnotchung @hoangquocvietuet +* @d-roak @JanLewDev @elielnfinic @trungnotchung From 46bb51177bd8476db2a37dadb140e566450dbe15 Mon Sep 17 00:00:00 2001 From: droak Date: Wed, 13 Nov 2024 15:52:28 +0900 Subject: [PATCH 50/61] rebase el pr --- packages/network/src/node.ts | 29 ++++++++++++++++++++---- packages/node/src/version.ts | 2 +- pnpm-lock.yaml | 44 ++++++++++++++++++------------------ 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index b26c386b..c9b6525e 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -76,9 +76,8 @@ export class TopologyNetworkNode { const _bootstrapNodesList = this._config?.bootstrap_peers ? this._config.bootstrap_peers : [ - // "/dns4/relay.droak.sh/tcp/443/wss/p2p/Qma3GsJmB47xYuyahPZPSadh1avvxfyYQwk8R3UnFrQ6aP", - "/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", - // "/dns4/topology-1.nfinic.com/tcp/4430/wss/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ", + "/dns4/bootstrap1.topology.gg/tcp/443/wss/p2p/12D3KooWBu1pZ3v2u6tXSmkN35kiMLENpv3bEXcyT1GJTVhipAkG", + "/dns4/bootstrap2.topology.gg/tcp/443/wss/p2p/12D3KooWLGuTtCHLpd1SBHeyvzT3kHVe2dw8P7UdoXsfQHu8qvkf", ]; const _peerDiscovery = _bootstrapNodesList.length @@ -187,9 +186,29 @@ export class TopologyNetworkNode { this._node.addEventListener("peer:discovery", async (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); } +<<<<<<< HEAD +======= + + log.info("::start::peer::discovery", e.detail); +>>>>>>> 02a2e65 (feat: add new bootstrap nodes; sort order for dialing discovered ma's (#246)) }); this._node.addEventListener("peer:identify", (e) => { diff --git a/packages/node/src/version.ts b/packages/node/src/version.ts index 2e0f48d1..387b59eb 100644 --- a/packages/node/src/version.ts +++ b/packages/node/src/version.ts @@ -1 +1 @@ -export const VERSION = "0.2.1"; +export const VERSION = "0.3.0"; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 93d12c76..1e11ed91 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -45,16 +45,16 @@ importers: examples/canvas: dependencies: '@topology-foundation/blueprints': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../../packages/blueprints '@topology-foundation/network': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../../packages/network '@topology-foundation/node': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../../packages/node '@topology-foundation/object': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../../packages/object crypto-browserify: specifier: ^3.12.0 @@ -91,16 +91,16 @@ importers: examples/chat: dependencies: '@topology-foundation/blueprints': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../../packages/blueprints '@topology-foundation/network': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../../packages/network '@topology-foundation/node': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../../packages/node '@topology-foundation/object': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../../packages/object assemblyscript: specifier: ^0.27.29 @@ -143,13 +143,13 @@ importers: examples/grid: dependencies: '@topology-foundation/network': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../../packages/network '@topology-foundation/node': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../../packages/node '@topology-foundation/object': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../../packages/object assemblyscript: specifier: ^0.27.29 @@ -198,16 +198,16 @@ importers: examples/local-bootstrap: dependencies: '@topology-foundation/blueprints': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../../packages/blueprints '@topology-foundation/network': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../../packages/network '@topology-foundation/node': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../../packages/node '@topology-foundation/object': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../../packages/object assemblyscript: specifier: ^0.27.29 @@ -254,7 +254,7 @@ importers: version: 4.1.2 devDependencies: '@topology-foundation/object': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../object assemblyscript: specifier: ^0.27.29 @@ -332,7 +332,7 @@ importers: specifier: ^12.3.1 version: 12.3.1 '@topology-foundation/logger': - specifier: ^0.2.1 + specifier: ^0.3.0 version: link:../logger it-length-prefixed: specifier: ^9.1.0 @@ -372,16 +372,16 @@ importers: specifier: ^2.1.3 version: 2.2.0 '@topology-foundation/blueprints': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../blueprints '@topology-foundation/logger': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../logger '@topology-foundation/network': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../network '@topology-foundation/object': - specifier: 0.2.1 + specifier: 0.3.0 version: link:../object commander: specifier: ^12.1.0 @@ -415,7 +415,7 @@ importers: specifier: ^2.0.0 version: 2.2.1 '@topology-foundation/logger': - specifier: ^0.2.1 + specifier: ^0.3.0 version: link:../logger ts-proto: specifier: ^2.2.4 From fcc195107b6391fe292087530367238ca29d0bde Mon Sep 17 00:00:00 2001 From: droak Date: Tue, 12 Nov 2024 14:55:10 +0900 Subject: [PATCH 51/61] chore: release v0.3.1 --- examples/canvas/package.json | 10 +++++----- examples/chat/package.json | 10 +++++----- examples/grid/package.json | 8 ++++---- examples/local-bootstrap/package.json | 10 +++++----- package.json | 2 +- packages/blueprints/package.json | 4 ++-- packages/logger/package.json | 2 +- packages/network/package.json | 4 ++-- packages/node/package.json | 10 +++++----- packages/object/package.json | 4 ++-- 10 files changed, 32 insertions(+), 32 deletions(-) diff --git a/examples/canvas/package.json b/examples/canvas/package.json index 4830d3cf..1fe20fb8 100644 --- a/examples/canvas/package.json +++ b/examples/canvas/package.json @@ -1,6 +1,6 @@ { "name": "ts-topology-examples-canvas", - "version": "0.3.0", + "version": "0.3.1", "license": "MIT", "scripts": { "build": "vite build", @@ -9,10 +9,10 @@ "start": "ts-node ./src/index.ts" }, "dependencies": { - "@topology-foundation/blueprints": "0.3.0", - "@topology-foundation/network": "0.3.0", - "@topology-foundation/node": "0.3.0", - "@topology-foundation/object": "0.3.0", + "@topology-foundation/blueprints": "0.3.1", + "@topology-foundation/network": "0.3.1", + "@topology-foundation/node": "0.3.1", + "@topology-foundation/object": "0.3.1", "crypto-browserify": "^3.12.0", "process": "^0.11.10", "stream-browserify": "^3.0.0", diff --git a/examples/chat/package.json b/examples/chat/package.json index 81780eaf..e1013ada 100644 --- a/examples/chat/package.json +++ b/examples/chat/package.json @@ -1,6 +1,6 @@ { "name": "topology-example-chat", - "version": "0.3.0", + "version": "0.3.1", "description": "Topology Protocol Chat Example", "main": "src/index.ts", "repository": "https://github.com/topology-foundation/ts-topology.git", @@ -13,10 +13,10 @@ "start": "ts-node ./src/index.ts" }, "dependencies": { - "@topology-foundation/blueprints": "0.3.0", - "@topology-foundation/network": "0.3.0", - "@topology-foundation/node": "0.3.0", - "@topology-foundation/object": "0.3.0", + "@topology-foundation/blueprints": "0.3.1", + "@topology-foundation/network": "0.3.1", + "@topology-foundation/node": "0.3.1", + "@topology-foundation/object": "0.3.1", "assemblyscript": "^0.27.29", "crypto-browserify": "^3.12.0", "process": "^0.11.10", diff --git a/examples/grid/package.json b/examples/grid/package.json index 436f2b29..13250d3f 100644 --- a/examples/grid/package.json +++ b/examples/grid/package.json @@ -1,6 +1,6 @@ { "name": "topology-example-grid", - "version": "0.3.0", + "version": "0.3.1", "description": "Topology Protocol Grid Exmaple", "main": "src/index.ts", "repository": "https://github.com/topology-foundation/ts-topology.git", @@ -13,9 +13,9 @@ "start": "ts-node ./src/index.ts" }, "dependencies": { - "@topology-foundation/network": "0.3.0", - "@topology-foundation/node": "0.3.0", - "@topology-foundation/object": "0.3.0", + "@topology-foundation/network": "0.3.1", + "@topology-foundation/node": "0.3.1", + "@topology-foundation/object": "0.3.1", "assemblyscript": "^0.27.29", "crypto-browserify": "^3.12.0", "memfs": "^4.11.1", diff --git a/examples/local-bootstrap/package.json b/examples/local-bootstrap/package.json index 891c5971..6e37ba8e 100644 --- a/examples/local-bootstrap/package.json +++ b/examples/local-bootstrap/package.json @@ -1,6 +1,6 @@ { "name": "topology-example-localdev", - "version": "0.3.0", + "version": "0.3.1", "description": "Topology Protocol Local Dev Example", "main": "src/index.ts", "repository": "https://github.com/topology-foundation/ts-topology.git", @@ -13,10 +13,10 @@ "start": "ts-node ./src/index.ts" }, "dependencies": { - "@topology-foundation/blueprints": "0.3.0", - "@topology-foundation/network": "0.3.0", - "@topology-foundation/node": "0.3.0", - "@topology-foundation/object": "0.3.0", + "@topology-foundation/blueprints": "0.3.1", + "@topology-foundation/network": "0.3.1", + "@topology-foundation/node": "0.3.1", + "@topology-foundation/object": "0.3.1", "assemblyscript": "^0.27.29", "crypto-browserify": "^3.12.0", "process": "^0.11.10", diff --git a/package.json b/package.json index 4c8184fb..99a1f256 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ts-topology", "description": "The official TypeScript implementation of Topology Protocol", - "version": "0.3.0", + "version": "0.3.1", "license": "MIT", "homepage": "https://topology.gg/", "repository": { diff --git a/packages/blueprints/package.json b/packages/blueprints/package.json index 1f448eaa..625f64c6 100644 --- a/packages/blueprints/package.json +++ b/packages/blueprints/package.json @@ -1,6 +1,6 @@ { "name": "@topology-foundation/blueprints", - "version": "0.3.0", + "version": "0.3.1", "license": "MIT", "repository": { "type": "git", @@ -34,7 +34,7 @@ "test": "vitest" }, "devDependencies": { - "@topology-foundation/object": "0.3.0", + "@topology-foundation/object": "0.3.1", "assemblyscript": "^0.27.29" }, "dependencies": { diff --git a/packages/logger/package.json b/packages/logger/package.json index 82c27807..92e36863 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -1,6 +1,6 @@ { "name": "@topology-foundation/logger", - "version": "0.3.0", + "version": "0.3.1", "license": "MIT", "repository": { "type": "git", diff --git a/packages/network/package.json b/packages/network/package.json index bc742d93..0154a885 100644 --- a/packages/network/package.json +++ b/packages/network/package.json @@ -1,6 +1,6 @@ { "name": "@topology-foundation/network", - "version": "0.3.0", + "version": "0.3.1", "license": "MIT", "repository": { "type": "git", @@ -51,7 +51,7 @@ "@libp2p/websockets": "^9.0.7", "@libp2p/webtransport": "^5.0.9", "@multiformats/multiaddr": "^12.3.1", - "@topology-foundation/logger": "^0.3.0", + "@topology-foundation/logger": "^0.3.1", "it-length-prefixed": "^9.1.0", "it-map": "^3.1.1", "it-pipe": "^3.0.1", diff --git a/packages/node/package.json b/packages/node/package.json index 04a8d9f3..20b5bd21 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -1,6 +1,6 @@ { "name": "@topology-foundation/node", - "version": "0.3.0", + "version": "0.3.1", "license": "MIT", "repository": { "type": "git", @@ -40,10 +40,10 @@ "@grpc/grpc-js": "^1.12.2", "@libp2p/interface": "^2.1.3", "dotenv": "^16.4.5", - "@topology-foundation/blueprints": "0.3.0", - "@topology-foundation/network": "0.3.0", - "@topology-foundation/object": "0.3.0", - "@topology-foundation/logger": "0.3.0", + "@topology-foundation/blueprints": "0.3.1", + "@topology-foundation/network": "0.3.1", + "@topology-foundation/object": "0.3.1", + "@topology-foundation/logger": "0.3.1", "commander": "^12.1.0", "google-protobuf": "^3.21.2" } diff --git a/packages/object/package.json b/packages/object/package.json index 70b75ae3..66a872b1 100644 --- a/packages/object/package.json +++ b/packages/object/package.json @@ -1,6 +1,6 @@ { "name": "@topology-foundation/object", - "version": "0.3.0", + "version": "0.3.1", "license": "MIT", "repository": { "type": "git", @@ -36,7 +36,7 @@ }, "dependencies": { "@bufbuild/protobuf": "^2.0.0", - "@topology-foundation/logger": "^0.3.0", + "@topology-foundation/logger": "^0.3.1", "ts-proto": "^2.2.4" } } From 215e905d6edc6faa0003e3dbb7b3dc02b4944f04 Mon Sep 17 00:00:00 2001 From: Oak Date: Tue, 12 Nov 2024 08:00:40 +0000 Subject: [PATCH 52/61] chore: split folders for code reviewers --- CODEOWNERS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CODEOWNERS b/CODEOWNERS index b35b4700..86f9c702 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1 +1,5 @@ * @d-roak @JanLewDev @elielnfinic @trungnotchung +packages/object @JanLewDev @trungnotchung +packages/blueprints @JanLewDev @trungnotchung +packages/network @elielnfinic +packages/node @elielnfinic From ab2d699cb970970ce998ffd94e40f1528e286c70 Mon Sep 17 00:00:00 2001 From: Oak Date: Tue, 12 Nov 2024 08:01:32 +0000 Subject: [PATCH 53/61] chore: rm everyone from generic codeowner --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index 86f9c702..cc65c057 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,4 +1,4 @@ -* @d-roak @JanLewDev @elielnfinic @trungnotchung +* @d-roak packages/object @JanLewDev @trungnotchung packages/blueprints @JanLewDev @trungnotchung packages/network @elielnfinic From 7cb7b575f3e911dc14be5ec7ecd6e1477cc0aa14 Mon Sep 17 00:00:00 2001 From: Oak Date: Tue, 12 Nov 2024 18:22:57 +0000 Subject: [PATCH 54/61] fix: paths on codeowners --- CODEOWNERS | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index cc65c057..d0a58112 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,5 +1,5 @@ -* @d-roak -packages/object @JanLewDev @trungnotchung -packages/blueprints @JanLewDev @trungnotchung -packages/network @elielnfinic -packages/node @elielnfinic +* @d-roak +/packages/object @JanLewDev @trungnotchung +/packages/blueprints @JanLewDev @trungnotchung +/packages/network @elielnfinic +/packages/node @elielnfinic From 50a13553353498e314acce1ec40f1809fe365d7b Mon Sep 17 00:00:00 2001 From: Oak Date: Tue, 12 Nov 2024 18:24:37 +0000 Subject: [PATCH 55/61] fix: paths on codeowners --- CODEOWNERS | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index d0a58112..3661f7b0 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,5 +1,5 @@ -* @d-roak -/packages/object @JanLewDev @trungnotchung -/packages/blueprints @JanLewDev @trungnotchung -/packages/network @elielnfinic -/packages/node @elielnfinic +* @d-roak +/packages/object/ @JanLewDev @trungnotchung +/packages/blueprints/ @JanLewDev @trungnotchung +/packages/network/ @elielnfinic +/packages/node/ @elielnfinic From c759fcc82c7fc7ff2598b4c7e7c577910659a63c Mon Sep 17 00:00:00 2001 From: Oak Date: Wed, 13 Nov 2024 04:37:22 +0000 Subject: [PATCH 56/61] chore: rm el from node package reviewing --- CODEOWNERS | 1 - 1 file changed, 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index 3661f7b0..4e4921e3 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -2,4 +2,3 @@ /packages/object/ @JanLewDev @trungnotchung /packages/blueprints/ @JanLewDev @trungnotchung /packages/network/ @elielnfinic -/packages/node/ @elielnfinic From 54884e9d7517f8bc2008857a7f92b06942dda213 Mon Sep 17 00:00:00 2001 From: droak Date: Wed, 13 Nov 2024 14:12:23 +0900 Subject: [PATCH 57/61] chore: update lock and version --- packages/node/src/version.ts | 2 +- pnpm-lock.yaml | 44 ++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/node/src/version.ts b/packages/node/src/version.ts index 387b59eb..767a57d4 100644 --- a/packages/node/src/version.ts +++ b/packages/node/src/version.ts @@ -1 +1 @@ -export const VERSION = "0.3.0"; +export const VERSION = "0.3.1"; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1e11ed91..64f74894 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -45,16 +45,16 @@ importers: examples/canvas: dependencies: '@topology-foundation/blueprints': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../../packages/blueprints '@topology-foundation/network': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../../packages/network '@topology-foundation/node': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../../packages/node '@topology-foundation/object': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../../packages/object crypto-browserify: specifier: ^3.12.0 @@ -91,16 +91,16 @@ importers: examples/chat: dependencies: '@topology-foundation/blueprints': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../../packages/blueprints '@topology-foundation/network': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../../packages/network '@topology-foundation/node': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../../packages/node '@topology-foundation/object': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../../packages/object assemblyscript: specifier: ^0.27.29 @@ -143,13 +143,13 @@ importers: examples/grid: dependencies: '@topology-foundation/network': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../../packages/network '@topology-foundation/node': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../../packages/node '@topology-foundation/object': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../../packages/object assemblyscript: specifier: ^0.27.29 @@ -198,16 +198,16 @@ importers: examples/local-bootstrap: dependencies: '@topology-foundation/blueprints': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../../packages/blueprints '@topology-foundation/network': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../../packages/network '@topology-foundation/node': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../../packages/node '@topology-foundation/object': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../../packages/object assemblyscript: specifier: ^0.27.29 @@ -254,7 +254,7 @@ importers: version: 4.1.2 devDependencies: '@topology-foundation/object': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../object assemblyscript: specifier: ^0.27.29 @@ -332,7 +332,7 @@ importers: specifier: ^12.3.1 version: 12.3.1 '@topology-foundation/logger': - specifier: ^0.3.0 + specifier: ^0.3.1 version: link:../logger it-length-prefixed: specifier: ^9.1.0 @@ -372,16 +372,16 @@ importers: specifier: ^2.1.3 version: 2.2.0 '@topology-foundation/blueprints': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../blueprints '@topology-foundation/logger': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../logger '@topology-foundation/network': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../network '@topology-foundation/object': - specifier: 0.3.0 + specifier: 0.3.1 version: link:../object commander: specifier: ^12.1.0 @@ -415,7 +415,7 @@ importers: specifier: ^2.0.0 version: 2.2.1 '@topology-foundation/logger': - specifier: ^0.3.0 + specifier: ^0.3.1 version: link:../logger ts-proto: specifier: ^2.2.4 From 66eb1ea3a7b9496c8bbb1064d9e84666a173a29a Mon Sep 17 00:00:00 2001 From: droak Date: Wed, 13 Nov 2024 16:31:06 +0900 Subject: [PATCH 58/61] rm unused dep and console logs --- packages/network/package.json | 1 - packages/node/src/index.ts | 1 - packages/object/src/hashgraph/index.ts | 3 --- pnpm-lock.yaml | 22 ---------------------- 4 files changed, 27 deletions(-) diff --git a/packages/network/package.json b/packages/network/package.json index 0154a885..3fdb6db5 100644 --- a/packages/network/package.json +++ b/packages/network/package.json @@ -45,7 +45,6 @@ "@libp2p/kad-dht": "14.0.0", "@libp2p/mdns": "^11.0.8", "@libp2p/peer-id": "^5.0.4", - "@libp2p/peer-store": "11.0.7", "@libp2p/pubsub-peer-discovery": "^11.0.0", "@libp2p/webrtc": "^5.0.9", "@libp2p/websockets": "^9.0.7", diff --git a/packages/node/src/index.ts b/packages/node/src/index.ts index b6079d49..20463d61 100644 --- a/packages/node/src/index.ts +++ b/packages/node/src/index.ts @@ -78,7 +78,6 @@ export class TopologyNode { operations.createObject(this, object); operations.subscribeObject(this, object.id); if (sync) { - console.log("SYNC OBJECT WHEN STARTING"); operations.syncObject(this, object.id, peerId); } return object; diff --git a/packages/object/src/hashgraph/index.ts b/packages/object/src/hashgraph/index.ts index 47e03cad..ba269009 100644 --- a/packages/object/src/hashgraph/index.ts +++ b/packages/object/src/hashgraph/index.ts @@ -124,9 +124,6 @@ export class HashGraph { return hash; // Vertex already exists } - console.log("My deps: ", deps); - console.log("Forward edges: ", this.forwardEdges); - console.log("Vertices: ", this.vertices); // Temporary fix: don't add the vertex if the dependencies are not present in the local HG. if ( !deps.every((dep) => this.forwardEdges.has(dep) || this.vertices.has(dep)) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 64f74894..4e61f796 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -313,9 +313,6 @@ importers: '@libp2p/peer-id': specifier: ^5.0.4 version: 5.0.7 - '@libp2p/peer-store': - specifier: 11.0.7 - version: 11.0.7 '@libp2p/pubsub-peer-discovery': specifier: ^11.0.0 version: 11.0.0 @@ -1634,9 +1631,6 @@ packages: '@libp2p/peer-store@11.0.10': resolution: {integrity: sha512-yUkIAKrk2XAJt01SVOvxpsaT/FZ9ju7j67TJhvh0NUon/dMYSQKVHwykK8SI/dxZi/7cDslSKIbIKv7eU5ZUTQ==} - '@libp2p/peer-store@11.0.7': - resolution: {integrity: sha512-h8W/XVYfKTmJhhnh2Mdub23CzPv24l5g1RRwFsEKCkWAe95M/fvDMPTM2ahRUB64qfnFT5X4XNFFyJFMsVtjLA==} - '@libp2p/pubsub-peer-discovery@11.0.0': resolution: {integrity: sha512-QlknUb2SCbmWScWzv2TS1tJIErYzr2HJoA93ZKYAlz5Dsfr9P1I17HvvlOIt/Q2PFp1aMOJOOF5mNsFV5kU73w==} @@ -7002,22 +6996,6 @@ snapshots: uint8arraylist: 2.4.8 uint8arrays: 5.1.0 - '@libp2p/peer-store@11.0.7': - dependencies: - '@libp2p/crypto': 5.0.6 - '@libp2p/interface': 2.2.0 - '@libp2p/peer-collections': 6.0.10 - '@libp2p/peer-id': 5.0.7 - '@libp2p/peer-record': 8.0.10 - '@multiformats/multiaddr': 12.3.1 - interface-datastore: 8.3.1 - it-all: 3.0.6 - mortice: 3.0.6 - multiformats: 13.3.1 - protons-runtime: 5.5.0 - uint8arraylist: 2.4.8 - uint8arrays: 5.1.0 - '@libp2p/pubsub-peer-discovery@11.0.0': dependencies: '@libp2p/crypto': 5.0.6 From b867fb67c5c47b486c0c28a0cf7cf14ea86303b4 Mon Sep 17 00:00:00 2001 From: droak Date: Wed, 13 Nov 2024 16:35:20 +0900 Subject: [PATCH 59/61] run biome --- examples/chat/src/index.ts | 2 +- examples/grid/src/index.ts | 4 +--- packages/network/src/node.ts | 25 +++++++++++++++---------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/examples/chat/src/index.ts b/examples/chat/src/index.ts index 7845400f..b0f40513 100644 --- a/examples/chat/src/index.ts +++ b/examples/chat/src/index.ts @@ -69,7 +69,7 @@ async function createConnectHandlers() { }); } -async function main() { +async function main() { await node.start(); render(); diff --git a/examples/grid/src/index.ts b/examples/grid/src/index.ts index 10ac5b9a..fc0a6c0b 100644 --- a/examples/grid/src/index.ts +++ b/examples/grid/src/index.ts @@ -198,7 +198,7 @@ async function createConnectHandlers() { async function main() { // node.networkNode.setOnPeerConnect((peerId : any) => { - // console.log("NEW PEER CONNECTED", peerId); + // console.log("NEW PEER CONNECTED", peerId); // peers = node.networkNode.getAllPeers(); // render(); // }); @@ -216,8 +216,6 @@ async function main() { render(); }); - - const button_create = ( document.getElementById("createGrid") ); diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index e7a99bf1..b474db10 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -22,7 +22,11 @@ import type { Stream, StreamHandler, } from "@libp2p/interface"; -import { kadDHT, removePrivateAddressesMapper, removePublicAddressesMapper } from "@libp2p/kad-dht"; +import { + kadDHT, + removePrivateAddressesMapper, + removePublicAddressesMapper, +} from "@libp2p/kad-dht"; import { webRTC, webRTCDirect } from "@libp2p/webrtc"; import { webSockets } from "@libp2p/websockets"; import * as filters from "@libp2p/websockets/filters"; @@ -48,7 +52,7 @@ export interface TopologyNetworkNodeConfig { private_key_seed?: string; log_config?: LoggerOptions; onPeerConnect?: PeerConnectionCallback; - onPeerDisconnect?: PeerConnectionCallback; + onPeerDisconnect?: PeerConnectionCallback; } export class TopologyNetworkNode { @@ -134,12 +138,13 @@ export class TopologyNetworkNode { services: this._config?.bootstrap ? _bootstrap_node_services : _node_services, - streamMuxers: [yamux({ - enableKeepAlive: true, - keepAliveInterval: 10000, - maxMessageSize: 4194304, - - })], + streamMuxers: [ + yamux({ + enableKeepAlive: true, + keepAliveInterval: 10000, + maxMessageSize: 4194304, + }), + ], transports: [ circuitRelayTransport({ discoverRelays: 2, @@ -180,9 +185,9 @@ export class TopologyNetworkNode { log.info("::start::multiaddrs", ma); }, 5000); - this._node.addEventListener("peer:connect", async (e) => { }); + this._node.addEventListener("peer:connect", async (e) => {}); - this._node.addEventListener("peer:disconnect", async (e) => { }); + this._node.addEventListener("peer:disconnect", async (e) => {}); this._node.addEventListener("peer:discovery", async (e) => { // current bug in v11.0.0 requires manual dial (https://github.com/libp2p/js-libp2p-pubsub-peer-discovery/issues/149) From 42244404755442acae7bafff07c337b797b79bae Mon Sep 17 00:00:00 2001 From: droak Date: Wed, 13 Nov 2024 16:44:31 +0900 Subject: [PATCH 60/61] remove commented stuff, unused code, and irrelevant stuff to the pr --- packages/network/src/node.ts | 60 ++++++------------------------------ 1 file changed, 10 insertions(+), 50 deletions(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index b474db10..27aeeea3 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -97,17 +97,8 @@ export class TopologyNetworkNode { dcutr: dcutr(), identify: identify(), pubsub: gossipsub(), - // dht: kadDHT({ - // protocol: "/topology/dht/1.0.0", - // kBucketSize: this._config?.bootstrap ? 40 : 20, - // clientMode: false, - // peerInfoMapper: removePublicAddressesMapper, - // querySelfInterval: 20000, - // initialQuerySelfInterval: 10000, - // allowQueryWithZeroPeers: false, - // }), dht: kadDHT({ - protocol: "/topology/lan/dht/1.0.0", + protocol: "/topology/dht/1.0.0", kBucketSize: this._config?.bootstrap ? 40 : 20, clientMode: false, peerInfoMapper: removePublicAddressesMapper, @@ -138,13 +129,7 @@ export class TopologyNetworkNode { services: this._config?.bootstrap ? _bootstrap_node_services : _node_services, - streamMuxers: [ - yamux({ - enableKeepAlive: true, - keepAliveInterval: 10000, - maxMessageSize: 4194304, - }), - ], + streamMuxers: [yamux()], transports: [ circuitRelayTransport({ discoverRelays: 2, @@ -161,18 +146,11 @@ export class TopologyNetworkNode { if (!this._config?.bootstrap) { for (const addr of this._config?.bootstrap_peers || []) { - // check if not dialing self - // try { this._node.dial(multiaddr(addr)); - // }catch(err){ - // console.error("Error dialing bootstrap peer", err); - // process.exit(1); - // } } } this._pubsub = this._node.services.pubsub as PubSub; - this.peerId = this._node.peerId.toString(); log.info( @@ -180,16 +158,16 @@ export class TopologyNetworkNode { this.peerId, ); - setInterval(() => { - const ma = this._node?.getMultiaddrs(); - log.info("::start::multiaddrs", ma); - }, 5000); - - this._node.addEventListener("peer:connect", async (e) => {}); + this._node.addEventListener("peer:connect", async (e) => { + log.info("::peer:connect", e.detail); + }); - this._node.addEventListener("peer:disconnect", async (e) => {}); + this._node.addEventListener("peer:disconnect", async (e) => { + log.info("::peer:disconnect", e.detail); + }); this._node.addEventListener("peer:discovery", async (e) => { + log.info("::start::peer::discovery", e.detail); // current bug in v11.0.0 requires manual dial (https://github.com/libp2p/js-libp2p-pubsub-peer-discovery/issues/149) const sortedAddrs = e.detail.multiaddrs.sort((a, b) => { const localRegex = @@ -209,12 +187,10 @@ export class TopologyNetworkNode { for (const address of sortedAddrs) { this._node?.dial(address); } - - log.info("::start::peer::discovery", e.detail); }); this._node.addEventListener("peer:identify", (e) => { - log.info("::start::peer::identify", e.detail.peerId); + log.info("::start::peer::identify", e.detail); }); } @@ -316,20 +292,4 @@ export class TopologyNetworkNode { addMessageHandler(protocol: string | string[], handler: StreamHandler) { this._node?.handle(protocol, handler); } - - /** - * This function allows to check if the node is ready to be used on the network - * We check if the node has any multiaddrs as for /webrtc it takes a while to get them assigned from the relay server node. - * @returns boolean - */ - checkNodeReady(): boolean { - if (this._node?.getMultiaddrs().length) { - return true; - } - return false; - } - - getNode(): Libp2p | undefined { - return this._node; - } } From fdc11b3f98b361cc4820cb91ec4208978e50919b Mon Sep 17 00:00:00 2001 From: droak Date: Thu, 14 Nov 2024 13:03:16 +0900 Subject: [PATCH 61/61] rm unused callbacks; await on the dial --- packages/network/src/node.ts | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/packages/network/src/node.ts b/packages/network/src/node.ts index 27aeeea3..e3c7b1fb 100644 --- a/packages/network/src/node.ts +++ b/packages/network/src/node.ts @@ -22,11 +22,7 @@ import type { Stream, StreamHandler, } from "@libp2p/interface"; -import { - kadDHT, - removePrivateAddressesMapper, - removePublicAddressesMapper, -} from "@libp2p/kad-dht"; +import { kadDHT, removePrivateAddressesMapper } from "@libp2p/kad-dht"; import { webRTC, webRTCDirect } from "@libp2p/webrtc"; import { webSockets } from "@libp2p/websockets"; import * as filters from "@libp2p/websockets/filters"; @@ -41,7 +37,6 @@ import { uint8ArrayToStream } from "./stream.js"; export * from "./stream.js"; let log: Logger; -type PeerConnectionCallback = (peerId: CustomEvent) => void; // snake_casing to match the JSON config export interface TopologyNetworkNodeConfig { @@ -51,8 +46,6 @@ export interface TopologyNetworkNodeConfig { browser_metrics?: boolean; private_key_seed?: string; log_config?: LoggerOptions; - onPeerConnect?: PeerConnectionCallback; - onPeerDisconnect?: PeerConnectionCallback; } export class TopologyNetworkNode { @@ -99,12 +92,9 @@ export class TopologyNetworkNode { pubsub: gossipsub(), dht: kadDHT({ protocol: "/topology/dht/1.0.0", - kBucketSize: this._config?.bootstrap ? 40 : 20, - clientMode: false, - peerInfoMapper: removePublicAddressesMapper, - querySelfInterval: 20000, - initialQuerySelfInterval: 10000, - allowQueryWithZeroPeers: false, + // both undefined and false should run client mode + clientMode: !this._config?.bootstrap, + peerInfoMapper: removePrivateAddressesMapper, }), }; @@ -158,11 +148,11 @@ export class TopologyNetworkNode { this.peerId, ); - this._node.addEventListener("peer:connect", async (e) => { + this._node.addEventListener("peer:connect", (e) => { log.info("::peer:connect", e.detail); }); - this._node.addEventListener("peer:disconnect", async (e) => { + this._node.addEventListener("peer:disconnect", (e) => { log.info("::peer:disconnect", e.detail); }); @@ -185,7 +175,7 @@ export class TopologyNetworkNode { // Dial non-local multiaddrs, then WebRTC multiaddrs for (const address of sortedAddrs) { - this._node?.dial(address); + await this._node?.dial(address); } });