From 756fd240f53f5b55bcb22dafb5427c2ad7afa162 Mon Sep 17 00:00:00 2001 From: Ladd Date: Wed, 1 Jan 2025 22:45:17 -0600 Subject: [PATCH] removed libp2p/gossipsub --- __tests__/run/002-two-nodes.ts | 2 - package-lock.json | 315 --------------------------------- package.json | 7 - src/deltas.ts | 2 +- src/node.ts | 23 +-- src/peers.ts | 15 +- src/pub-sub.ts | 99 +---------- util/app.ts | 4 +- 8 files changed, 8 insertions(+), 459 deletions(-) diff --git a/__tests__/run/002-two-nodes.ts b/__tests__/run/002-two-nodes.ts index f52203d..23a5254 100644 --- a/__tests__/run/002-two-nodes.ts +++ b/__tests__/run/002-two-nodes.ts @@ -13,8 +13,6 @@ describe('Run', () => { apps[1] = new App({ httpEnable: true, peerId: 'app-002-B', - // Make the apps use the same pubsub topic so they can talk to each other - pubSubTopic: apps[0].config.pubSubTopic, }); apps[0].config.seedPeers.push(apps[1].myRequestAddr); apps[1].config.seedPeers.push(apps[0].myRequestAddr); diff --git a/package-lock.json b/package-lock.json index 420e01b..3f8906b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,13 +9,6 @@ "version": "0.1.0", "license": "Unlicense", "dependencies": { - "@chainsafe/libp2p-gossipsub": "^14.1.0", - "@chainsafe/libp2p-noise": "^16.0.0", - "@chainsafe/libp2p-yamux": "^7.0.1", - "@libp2p/identify": "^3.0.14", - "@libp2p/mdns": "^11.0.16", - "@libp2p/ping": "^2.0.14", - "@libp2p/tcp": "^10.0.14", "debug": "^4.4.0", "express": "^4.21.2", "json-logic-js": "^2.0.5", @@ -607,89 +600,12 @@ "dev": true, "license": "MIT" }, - "node_modules/@chainsafe/as-chacha20poly1305": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/@chainsafe/as-chacha20poly1305/-/as-chacha20poly1305-0.1.0.tgz", - "integrity": "sha512-BpNcL8/lji/GM3+vZ/bgRWqJ1q5kwvTFmGPk7pxm/QQZDbaMI98waOHjEymTjq2JmdD/INdNBFOVSyJofXg7ew==", - "license": "Apache-2.0" - }, - "node_modules/@chainsafe/as-sha256": { - "version": "0.4.2", - "resolved": "https://registry.npmjs.org/@chainsafe/as-sha256/-/as-sha256-0.4.2.tgz", - "integrity": "sha512-HJ8GZBRjLeWtRsAXf3EbNsNzmTGpzTFjfpSf4yHkLYC+E52DhT6hwz+7qpj6I/EmFzSUm5tYYvT9K8GZokLQCQ==", - "license": "Apache-2.0" - }, "node_modules/@chainsafe/is-ip": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/@chainsafe/is-ip/-/is-ip-2.0.2.tgz", "integrity": "sha512-ndGqEMG1W5WkGagaqOZHpPU172AGdxr+LD15sv3WIUvT5oCFUrG1Y0CW/v2Egwj4JXEvSibaIIIqImsm98y1nA==", "license": "MIT" }, - "node_modules/@chainsafe/libp2p-gossipsub": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/@chainsafe/libp2p-gossipsub/-/libp2p-gossipsub-14.1.0.tgz", - "integrity": "sha512-nzFBbHOoRFa/bXUSzmJaXOgHI+EttTldhLJ33yWcM0DxnWhLKychHkCDLoJO3THa1+dnzrDJoxj3N3/V0WoPVw==", - "license": "Apache-2.0", - "dependencies": { - "@libp2p/crypto": "^5.0.0", - "@libp2p/interface": "^2.0.0", - "@libp2p/interface-internal": "^2.0.0", - "@libp2p/peer-id": "^5.0.0", - "@libp2p/pubsub": "^10.0.0", - "@multiformats/multiaddr": "^12.1.14", - "denque": "^2.1.0", - "it-length-prefixed": "^9.0.4", - "it-pipe": "^3.0.1", - "it-pushable": "^3.2.3", - "multiformats": "^13.0.1", - "protons-runtime": "^5.5.0", - "uint8arraylist": "^2.4.8", - "uint8arrays": "^5.0.1" - }, - "engines": { - "npm": ">=8.7.0" - } - }, - "node_modules/@chainsafe/libp2p-noise": { - "version": "16.0.0", - "resolved": "https://registry.npmjs.org/@chainsafe/libp2p-noise/-/libp2p-noise-16.0.0.tgz", - "integrity": "sha512-8rqr8V1RD2/lVbfL0Bb//N8iPOFof11cUe8v8z8xJT7fUhCAbtCCSM4jbwI4HCnw0MvHLmcpmAfDCFRwcWzoeA==", - "license": "Apache-2.0 OR MIT", - "dependencies": { - "@chainsafe/as-chacha20poly1305": "^0.1.0", - "@chainsafe/as-sha256": "^0.4.1", - "@libp2p/crypto": "^5.0.0", - "@libp2p/interface": "^2.0.0", - "@libp2p/peer-id": "^5.0.0", - "@noble/ciphers": "^0.6.0", - "@noble/curves": "^1.1.0", - "@noble/hashes": "^1.3.1", - "it-length-prefixed": "^9.0.1", - "it-length-prefixed-stream": "^1.0.0", - "it-pair": "^2.0.6", - "it-pipe": "^3.0.1", - "it-stream-types": "^2.0.1", - "protons-runtime": "^5.5.0", - "uint8arraylist": "^2.4.3", - "uint8arrays": "^5.0.0", - "wherearewe": "^2.0.1" - } - }, - "node_modules/@chainsafe/libp2p-yamux": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/@chainsafe/libp2p-yamux/-/libp2p-yamux-7.0.1.tgz", - "integrity": "sha512-949MI0Ll0AsYq1gUETZmL/MijwX0jilOQ1i4s8wDEXGiMhuPWWiMsPgEnX6n+VzFmTrfNYyGaaJj5/MqxV9y/g==", - "license": "Apache-2.0 OR MIT", - "dependencies": { - "@libp2p/interface": "^2.0.0", - "@libp2p/utils": "^6.0.0", - "get-iterator": "^2.0.1", - "it-foreach": "^2.0.6", - "it-pushable": "^3.2.3", - "it-stream-types": "^2.0.1", - "uint8arraylist": "^2.4.8" - } - }, "node_modules/@chainsafe/netmask": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@chainsafe/netmask/-/netmask-2.0.0.tgz", @@ -1445,29 +1361,6 @@ "uint8arrays": "^5.1.0" } }, - "node_modules/@libp2p/identify": { - "version": "3.0.14", - "resolved": "https://registry.npmjs.org/@libp2p/identify/-/identify-3.0.14.tgz", - "integrity": "sha512-H80tdH8csD3W+wHoaltJEnjTAmZBJ22bYqFOPk5YKCF0k19Ox2MwRTkyCXuVDIdQfrYs94JE3HvLvUoN9X/JBQ==", - "license": "Apache-2.0 OR MIT", - "dependencies": { - "@libp2p/crypto": "^5.0.8", - "@libp2p/interface": "^2.3.0", - "@libp2p/interface-internal": "^2.2.1", - "@libp2p/peer-id": "^5.0.9", - "@libp2p/peer-record": "^8.0.13", - "@libp2p/utils": "^6.3.0", - "@multiformats/multiaddr": "^12.3.3", - "@multiformats/multiaddr-matcher": "^1.6.0", - "it-drain": "^3.0.7", - "it-parallel": "^3.0.8", - "it-protobuf-stream": "^1.1.5", - "protons-runtime": "^5.5.0", - "uint8arraylist": "^2.4.8", - "uint8arrays": "^5.1.0", - "wherearewe": "^2.0.1" - } - }, "node_modules/@libp2p/interface": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@libp2p/interface/-/interface-2.3.0.tgz", @@ -1508,22 +1401,6 @@ "weald": "^1.0.4" } }, - "node_modules/@libp2p/mdns": { - "version": "11.0.16", - "resolved": "https://registry.npmjs.org/@libp2p/mdns/-/mdns-11.0.16.tgz", - "integrity": "sha512-FJLJywEFCm5r61b7IZ+KGvxUPEGuGx5VGXyTSE10y7lSxizn50ZUAmnN76OsBdLz/Uj3/iyzTOOmY17mzBjN3g==", - "license": "Apache-2.0 OR MIT", - "dependencies": { - "@libp2p/interface": "^2.3.0", - "@libp2p/interface-internal": "^2.2.1", - "@libp2p/peer-id": "^5.0.9", - "@libp2p/utils": "^6.3.0", - "@multiformats/multiaddr": "^12.3.3", - "@types/multicast-dns": "^7.2.4", - "dns-packet": "^5.6.1", - "multicast-dns": "^7.2.5" - } - }, "node_modules/@libp2p/multistream-select": { "version": "6.0.10", "resolved": "https://registry.npmjs.org/@libp2p/multistream-select/-/multistream-select-6.0.10.tgz", @@ -1603,59 +1480,6 @@ "uint8arrays": "^5.1.0" } }, - "node_modules/@libp2p/ping": { - "version": "2.0.14", - "resolved": "https://registry.npmjs.org/@libp2p/ping/-/ping-2.0.14.tgz", - "integrity": "sha512-+idRl+4T2bhP+FNDgwBFWHyHkFoOcjwzQmezLR00mG8hg2iH3BvDmzMd7cagZM21SaeDd4eiN8XyhQqyi1RcZA==", - "license": "Apache-2.0 OR MIT", - "dependencies": { - "@libp2p/crypto": "^5.0.8", - "@libp2p/interface": "^2.3.0", - "@libp2p/interface-internal": "^2.2.1", - "@multiformats/multiaddr": "^12.3.3", - "it-byte-stream": "^1.1.0", - "uint8arrays": "^5.1.0" - } - }, - "node_modules/@libp2p/pubsub": { - "version": "10.0.14", - "resolved": "https://registry.npmjs.org/@libp2p/pubsub/-/pubsub-10.0.14.tgz", - "integrity": "sha512-fzHHpI6Smrvvlje1ySRfohjlxeifpoowNRcnJy6/ZFoziHvtufuPQdJ65jL/oobd6sTnbbShAlkkx/KVXBr5lw==", - "license": "Apache-2.0 OR MIT", - "dependencies": { - "@libp2p/crypto": "^5.0.8", - "@libp2p/interface": "^2.3.0", - "@libp2p/interface-internal": "^2.2.1", - "@libp2p/peer-collections": "^6.0.13", - "@libp2p/peer-id": "^5.0.9", - "@libp2p/utils": "^6.3.0", - "it-length-prefixed": "^9.1.0", - "it-pipe": "^3.0.1", - "it-pushable": "^3.2.3", - "multiformats": "^13.3.1", - "p-queue": "^8.0.1", - "uint8arraylist": "^2.4.8", - "uint8arrays": "^5.1.0" - } - }, - "node_modules/@libp2p/tcp": { - "version": "10.0.14", - "resolved": "https://registry.npmjs.org/@libp2p/tcp/-/tcp-10.0.14.tgz", - "integrity": "sha512-HwYCvNnSqjVzoy3DQh6chy4EwWgmnII+ccT/LEpitKbV8QzHTv2HUeSaGtuGc42Z95rFMXqmJeqBkhbXcpeCRA==", - "license": "Apache-2.0 OR MIT", - "dependencies": { - "@libp2p/interface": "^2.3.0", - "@libp2p/utils": "^6.3.0", - "@multiformats/mafmt": "^12.1.6", - "@multiformats/multiaddr": "^12.3.3", - "@types/sinon": "^17.0.3", - "p-defer": "^4.0.1", - "p-event": "^6.0.1", - "progress-events": "^1.0.1", - "race-event": "^1.3.0", - "stream-to-it": "^1.0.1" - } - }, "node_modules/@libp2p/utils": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/@libp2p/utils/-/utils-6.3.0.tgz", @@ -1702,15 +1526,6 @@ "uint8arrays": "^5.0.2" } }, - "node_modules/@multiformats/mafmt": { - "version": "12.1.6", - "resolved": "https://registry.npmjs.org/@multiformats/mafmt/-/mafmt-12.1.6.tgz", - "integrity": "sha512-tlJRfL21X+AKn9b5i5VnaTD6bNttpSpcqwKVmDmSHLwxoz97fAHaepqFOk/l1fIu94nImIXneNbhsJx/RQNIww==", - "license": "Apache-2.0 OR MIT", - "dependencies": { - "@multiformats/multiaddr": "^12.0.0" - } - }, "node_modules/@multiformats/multiaddr": { "version": "12.3.4", "resolved": "https://registry.npmjs.org/@multiformats/multiaddr/-/multiaddr-12.3.4.tgz", @@ -1736,15 +1551,6 @@ "multiformats": "^13.0.0" } }, - "node_modules/@noble/ciphers": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/@noble/ciphers/-/ciphers-0.6.0.tgz", - "integrity": "sha512-mIbq/R9QXk5/cTfESb1OKtyFnk7oc1Om/8onA1158K9/OZUQFDEVy55jVTato+xmp3XX6F6Qh0zz0Nc1AxAlRQ==", - "license": "MIT", - "funding": { - "url": "https://paulmillr.com/funding/" - } - }, "node_modules/@noble/curves": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.7.0.tgz", @@ -2089,16 +1895,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/multicast-dns": { - "version": "7.2.4", - "resolved": "https://registry.npmjs.org/@types/multicast-dns/-/multicast-dns-7.2.4.tgz", - "integrity": "sha512-ib5K4cIDR4Ro5SR3Sx/LROkMDa0BHz0OPaCBL/OSPDsAXEGZ3/KQeS6poBKYVN7BfjXDL9lWNwzyHVgt/wkyCw==", - "license": "MIT", - "dependencies": { - "@types/dns-packet": "*", - "@types/node": "*" - } - }, "node_modules/@types/murmurhash3js-revisited": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@types/murmurhash3js-revisited/-/murmurhash3js-revisited-3.0.3.tgz", @@ -2170,21 +1966,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/sinon": { - "version": "17.0.3", - "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-17.0.3.tgz", - "integrity": "sha512-j3uovdn8ewky9kRBG19bOwaZbexJu/XjtkHyjvUgt4xfPFz18dcORIMqnYh66Fx3Powhcr85NT5+er3+oViapw==", - "license": "MIT", - "dependencies": { - "@types/sinonjs__fake-timers": "*" - } - }, - "node_modules/@types/sinonjs__fake-timers": { - "version": "8.1.5", - "resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.5.tgz", - "integrity": "sha512-mQkU2jY8jJEF7YHjHvsQO8+3ughTL1mcnn96igfhONmR+fUPSKIkefQYpSe8bsly2Ep7oQbn/6VG5/9/0qcArQ==", - "license": "MIT" - }, "node_modules/@types/stack-utils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.3.tgz", @@ -4098,15 +3879,6 @@ "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==", "license": "MIT" }, - "node_modules/denque": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", - "integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==", - "license": "Apache-2.0", - "engines": { - "node": ">=0.10" - } - }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -6184,12 +5956,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/is-electron": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/is-electron/-/is-electron-2.2.2.tgz", - "integrity": "sha512-FO/Rhvz5tuw4MCWkpMzHFKWD2LsfHzIb7i6MdPYZ/KW7AlxawyLkqdy+jPZP1WubqEADE3O4FUENlJHDfQASRg==", - "license": "MIT" - }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -6722,20 +6488,6 @@ "it-pushable": "^3.2.3" } }, - "node_modules/it-pair": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/it-pair/-/it-pair-2.0.6.tgz", - "integrity": "sha512-5M0t5RAcYEQYNG5BV7d7cqbdwbCAp5yLdzvkxsZmkuZsLbTdZzah6MQySYfaAQjNDCq6PUnDt0hqBZ4NwMfW6g==", - "license": "Apache-2.0 OR MIT", - "dependencies": { - "it-stream-types": "^2.0.1", - "p-defer": "^4.0.0" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, "node_modules/it-parallel": { "version": "3.0.8", "resolved": "https://registry.npmjs.org/it-parallel/-/it-parallel-3.0.8.tgz", @@ -6766,17 +6518,6 @@ "npm": ">=7.0.0" } }, - "node_modules/it-protobuf-stream": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/it-protobuf-stream/-/it-protobuf-stream-1.1.5.tgz", - "integrity": "sha512-H70idW45As3cEbU4uSoZ9IYHUIV3YM69/2mmXYR7gOlPabWjuyNi3/abK11geiiq3la27Sos/mXr68JljjKtEQ==", - "license": "Apache-2.0 OR MIT", - "dependencies": { - "it-length-prefixed-stream": "^1.0.0", - "it-stream-types": "^2.0.1", - "uint8arraylist": "^2.4.8" - } - }, "node_modules/it-pushable": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/it-pushable/-/it-pushable-3.2.3.tgz", @@ -8046,19 +7787,6 @@ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "license": "MIT" }, - "node_modules/multicast-dns": { - "version": "7.2.5", - "resolved": "https://registry.npmjs.org/multicast-dns/-/multicast-dns-7.2.5.tgz", - "integrity": "sha512-2eznPJP8z2BFLX50tf0LuODrpINqP1RVIm/CObbTcBRITQgmC/TjcREF1NeTBzIcR5XO/ukWo+YHOjBbFwIupg==", - "license": "MIT", - "dependencies": { - "dns-packet": "^5.2.2", - "thunky": "^1.0.2" - }, - "bin": { - "multicast-dns": "cli.js" - } - }, "node_modules/multiformats": { "version": "13.3.1", "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-13.3.1.tgz", @@ -8386,21 +8114,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/p-event": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/p-event/-/p-event-6.0.1.tgz", - "integrity": "sha512-Q6Bekk5wpzW5qIyUP4gdMEujObYstZl6DMMOSenwBvV0BlE5LkDwkjs5yHbZmdCEq2o4RJx4tE1vwxFVf2FG1w==", - "license": "MIT", - "dependencies": { - "p-timeout": "^6.1.2" - }, - "engines": { - "node": ">=16.17" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -9529,15 +9242,6 @@ "node": ">= 0.8" } }, - "node_modules/stream-to-it": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/stream-to-it/-/stream-to-it-1.0.1.tgz", - "integrity": "sha512-AqHYAYPHcmvMrcLNgncE/q0Aj/ajP6A4qGhxP6EVn7K3YTNs0bJpJyk57wc2Heb7MUL64jurvmnmui8D9kjZgA==", - "license": "Apache-2.0 OR MIT", - "dependencies": { - "it-stream-types": "^2.0.1" - } - }, "node_modules/string_decoder": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", @@ -9757,12 +9461,6 @@ "license": "MIT", "peer": true }, - "node_modules/thunky": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/thunky/-/thunky-1.1.0.tgz", - "integrity": "sha512-eHY7nBftgThBqOyHGVN+l8gF0BucP09fMo0oO/Lb0w1OF80dJv+lDVpXG60WMQvkcxAkNybKsrEIE3ZtKGmPrA==", - "license": "MIT" - }, "node_modules/tldts": { "version": "6.1.69", "resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.69.tgz", @@ -10393,19 +10091,6 @@ "url": "https://github.com/chalk/supports-color?sponsor=1" } }, - "node_modules/wherearewe": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/wherearewe/-/wherearewe-2.0.1.tgz", - "integrity": "sha512-XUguZbDxCA2wBn2LoFtcEhXL6AXo+hVjGonwhSTTTU9SzbWG8Xu3onNIpzf9j/mYUcJQ0f+m37SzG77G851uFw==", - "license": "Apache-2.0 OR MIT", - "dependencies": { - "is-electron": "^2.2.0" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index 35dc333..c5df3aa 100644 --- a/package.json +++ b/package.json @@ -38,13 +38,6 @@ "author": "Taliesin (Ladd) ", "license": "Unlicense", "dependencies": { - "@chainsafe/libp2p-gossipsub": "^14.1.0", - "@chainsafe/libp2p-noise": "^16.0.0", - "@chainsafe/libp2p-yamux": "^7.0.1", - "@libp2p/identify": "^3.0.14", - "@libp2p/mdns": "^11.0.16", - "@libp2p/ping": "^2.0.14", - "@libp2p/tcp": "^10.0.14", "debug": "^4.4.0", "express": "^4.21.2", "json-logic-js": "^2.0.5", diff --git a/src/deltas.ts b/src/deltas.ts index c92357e..6cd62e4 100644 --- a/src/deltas.ts +++ b/src/deltas.ts @@ -88,7 +88,7 @@ export class DeltaStream { async publishDelta(delta: Delta) { debug(`[${this.rhizomeNode.config.peerId}]`, `Publishing delta: ${JSON.stringify(delta)}`); await this.rhizomeNode.pubSub.publish( - this.rhizomeNode.config.pubSubTopic, + "deltas", this.serializeDelta(delta) ); } diff --git a/src/node.ts b/src/node.ts index 546b9cb..1df34ce 100644 --- a/src/node.ts +++ b/src/node.ts @@ -1,5 +1,5 @@ import Debug from 'debug'; -import {CREATOR, HTTP_API_ADDR, HTTP_API_ENABLE, HTTP_API_PORT, PEER_ID, PUB_SUB_TOPIC, PUBLISH_BIND_ADDR, PUBLISH_BIND_HOST, PUBLISH_BIND_PORT, REQUEST_BIND_ADDR, REQUEST_BIND_HOST, REQUEST_BIND_PORT, SEED_PEERS} from './config.js'; +import {CREATOR, HTTP_API_ADDR, HTTP_API_ENABLE, HTTP_API_PORT, PEER_ID, PUBLISH_BIND_ADDR, PUBLISH_BIND_HOST, PUBLISH_BIND_PORT, REQUEST_BIND_ADDR, REQUEST_BIND_HOST, REQUEST_BIND_PORT, SEED_PEERS} from './config.js'; import {DeltaStream} from './deltas.js'; import {HttpServer} from './http/index.js'; import {Lossless} from './lossless.js'; @@ -21,7 +21,6 @@ export type RhizomeNodeConfig = { seedPeers: PeerAddress[]; peerId: string; creator: string; // TODO each host should be able to support multiple users - pubSubTopic: string; }; // So that we can run more than one instance in the same process (for testing) @@ -50,7 +49,6 @@ export class RhizomeNode { seedPeers: parseAddressList(SEED_PEERS), peerId: PEER_ID, creator: CREATOR, - pubSubTopic: PUB_SUB_TOPIC, ...config }; debug(`[${this.config.peerId}]`, 'Config', this.config); @@ -76,10 +74,7 @@ export class RhizomeNode { // Bind ZeroMQ publish socket // TODO: Config option to enable zmq pubsub - // await this.pubSub.startZmq(); - - // Initialize Libp2p - await this.pubSub.startLibp2p(); + await this.pubSub.startZmq(); // Bind ZeroMQ request socket // TODO: request/reply via libp2p? @@ -91,22 +86,12 @@ export class RhizomeNode { this.httpServer.start(); } - { - // Start libp2p subscription - // TODO: Config option to enable gossipsub - // TODO: Config options for gossipsub and other libp2p configs - this.peers.start(); - - // Wait a short time for peers to connect - await new Promise((resolve) => setTimeout(resolve, 200)); - } - { // Wait a short time for sockets to initialize - // await new Promise((resolve) => setTimeout(resolve, 500)); + await new Promise((resolve) => setTimeout(resolve, 500)); // Subscribe to seed peers - // this.peers.subscribeToSeeds(); + this.peers.subscribeToSeeds(); // Wait a short time for sockets to initialize // await new Promise((resolve) => setTimeout(resolve, 500)); diff --git a/src/peers.ts b/src/peers.ts index db5f32e..77a2d9c 100644 --- a/src/peers.ts +++ b/src/peers.ts @@ -80,7 +80,7 @@ class Peer { // ZeroMQ subscription this.subscription = this.rhizomeNode.pubSub.subscribe( this.publishAddr, - this.rhizomeNode.config.pubSubTopic, + "deltas", (sender, msg) => { const delta = this.rhizomeNode.deltaStream.deserializeDelta(msg); delta.receivedFrom = sender; @@ -135,19 +135,6 @@ export class Peers { }); } - start() { - // TODO: Move this somewhere that makes more sense - this.rhizomeNode.pubSub.subscribeTopic( - this.rhizomeNode.config.pubSubTopic, - (sender, msg) => { - const delta = this.rhizomeNode.deltaStream.deserializeDelta(msg); - delta.receivedFrom = sender; - debug(`[${this.rhizomeNode.config.peerId}]`, `Received delta: ${JSON.stringify(delta)}`); - this.rhizomeNode.deltaStream.ingestDelta(delta); - } - ); - } - stop() { debug(`[${this.rhizomeNode.config.peerId}]`, 'Closing all peer request sockets'); for (const peer of this.peers) { diff --git a/src/pub-sub.ts b/src/pub-sub.ts index 3fe2cac..c40bee6 100644 --- a/src/pub-sub.ts +++ b/src/pub-sub.ts @@ -1,12 +1,4 @@ -import {GossipSub, gossipsub} from '@chainsafe/libp2p-gossipsub'; -import {noise} from '@chainsafe/libp2p-noise'; -import {yamux} from '@chainsafe/libp2p-yamux'; -import {identify} from '@libp2p/identify'; -import {mdns} from '@libp2p/mdns'; -import {ping} from '@libp2p/ping'; -import {tcp} from '@libp2p/tcp'; import Debug from 'debug'; -import {Libp2p, createLibp2p} from 'libp2p'; import {Publisher, Subscriber} from 'zeromq'; import {RhizomeNode} from './node.js'; import {PeerAddress} from './peers.js'; @@ -21,20 +13,17 @@ export class Subscription { publishAddr: PeerAddress; publishAddrStr: string; cb: SubscribedMessageHandler; - libp2p?: Libp2p; constructor( readonly pubSub: PubSub, publishAddr: PeerAddress, topic: string, cb: SubscribedMessageHandler, - libp2p?: Libp2p ) { this.cb = cb; this.topic = topic; this.publishAddr = publishAddr; this.publishAddrStr = `tcp://${this.publishAddr.toAddrString()}`; - this.libp2p = libp2p; } async start() { @@ -60,7 +49,6 @@ export class PubSub { publishSock?: Publisher; publishAddrStr: string; subscriptions: Subscription[] = []; - libp2p?: Libp2p; constructor(rhizomeNode: RhizomeNode) { this.rhizomeNode = rhizomeNode; @@ -76,33 +64,6 @@ export class PubSub { debug(`[${this.rhizomeNode.config.peerId}]`, `ZeroMQ publishing socket bound to ${this.publishAddrStr}`); } - async startLibp2p() { - this.libp2p = await createLibp2p({ - addresses: { - // TODO: Config - listen: ['/ip4/127.0.0.1/tcp/0'] - }, - transports: [tcp()], - connectionEncrypters: [noise()], - streamMuxers: [yamux()], - peerDiscovery: [mdns()], - services: { - pubsub: gossipsub(), - identify: identify(), - ping: ping(), - } - }); - - this.libp2p.addEventListener("peer:discovery", (event) => { - debug(`[${this.rhizomeNode.config.peerId}]`, `Found peer: ${JSON.stringify(event.detail)}`); - this.libp2p?.dial(event.detail.multiaddrs); - }); - - this.libp2p.addEventListener("peer:connect", (event) => { - debug(`[${this.rhizomeNode.config.peerId}]`, `Connected to peer: ${JSON.stringify(event.detail)}`); - }); - } - async publish(topic: string, msg: string) { if (this.publishSock) { await this.publishSock.send([ @@ -112,44 +73,6 @@ export class PubSub { ]); debug(`[${this.rhizomeNode.config.peerId}]`, `Published to ZeroMQ, msg: ${msg}`); } - - if (this.libp2p) { - const pubsub = this.libp2p.services.pubsub as GossipSub; - let published = false; - try { - await pubsub.publish(topic, Buffer.from(msg)); - published = true; - } catch (e: unknown) { - if (!((e as Error).message as string).match("PublishError.NoPeersSubscribedToTopic")) { - debug(`[${this.rhizomeNode.config.peerId}]`, 'Libp2p publish:', (e as Error).message); - } - } - if (published) { - debug(`[${this.rhizomeNode.config.peerId}]`, `Published to Libp2p, msg: ${msg}`); - } - } - } - - subscribedTopics = new Set(); - - subscribeTopic(topic: string, cb: SubscribedMessageHandler) { - if (!this.libp2p) throw new Error('libp2p not initialized'); - const pubsub = this.libp2p.services.pubsub as GossipSub; - - // TODO: If we subscribe to multiple topics this callback will be duplicated - pubsub.addEventListener("message", (event) => { - const msg = Buffer.from(event.detail.data).toString(); - debug(`[${this.rhizomeNode.config.peerId}]`, `Libp2p subscribtion received msg: ${msg}`); - cb(new PeerAddress('libp2p', 0), msg); - }); - - // Add to our list of subscribed topics so we can unsubscribe later. - // Also has the effect of not calling subscribe more than once per topic. - if (!this.subscribedTopics.has(topic)) { - pubsub.subscribe(topic); - this.subscribedTopics.add(topic); - debug(`[${this.rhizomeNode.config.peerId}]`, 'Subscribed topics:', Array.from(this.subscribedTopics.keys())); - } } subscribe( @@ -157,7 +80,7 @@ export class PubSub { topic: string, cb: SubscribedMessageHandler ): Subscription { - const subscription = new Subscription(this, publishAddr, topic, cb, this.libp2p); + const subscription = new Subscription(this, publishAddr, topic, cb); this.subscriptions.push(subscription); return subscription; } @@ -173,25 +96,5 @@ export class PubSub { for (const subscription of this.subscriptions) { subscription.sock.close(); } - - if (this.libp2p) { - const pubsub = this.libp2p.services.pubsub as GossipSub; - - pubsub.removeEventListener("message"); - - for (const topic of this.subscribedTopics) { - debug(`[${this.rhizomeNode.config.peerId}]`, `Unsubscribing Libp2p topic ${topic}`); - pubsub.unsubscribe(topic) - } - - debug(`[${this.rhizomeNode.config.peerId}]`, 'Stopping gossipsub'); - - await pubsub.stop(); - - await this.libp2p.stop(); - - debug(`[${this.rhizomeNode.config.peerId}]`, 'Stopped libp2p'); - - } } } diff --git a/util/app.ts b/util/app.ts index c7f8c37..76b15ac 100644 --- a/util/app.ts +++ b/util/app.ts @@ -1,6 +1,5 @@ -import {RhizomeNode, RhizomeNodeConfig} from "../src/node.js"; import {Collection} from "../src/collection.js"; -import {randomUUID} from "crypto"; +import {RhizomeNode, RhizomeNodeConfig} from "../src/node.js"; const start = 5000; const range = 5000; @@ -15,7 +14,6 @@ export class App extends RhizomeNode { publishBindPort: getRandomPort(), requestBindPort: getRandomPort(), httpPort: getRandomPort(), - pubSubTopic: config?.pubSubTopic || `deltas-${randomUUID()}`, ...config, });