From 11c075615735abcaf754b130b0debcfd0a3f482e Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Tue, 9 Jan 2024 10:56:01 +0200 Subject: [PATCH] general refactor --- lib/plugin-hub-client.cjs | 4 ++-- lib/plugin-hub.cjs | 18 ++++++++---------- package-lock.json | 14 +++++++------- package.json | 2 +- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/plugin-hub-client.cjs b/lib/plugin-hub-client.cjs index b46b84d..4008fbd 100644 --- a/lib/plugin-hub-client.cjs +++ b/lib/plugin-hub-client.cjs @@ -10,10 +10,10 @@ module.exports = { }, /** - * @param {any} local + * @param {any} peer * @param {any} config */ - init(local, config) { + init(peer, config) { return { /** * @param {string} origin diff --git a/lib/plugin-hub.cjs b/lib/plugin-hub.cjs index f00f751..83212a0 100644 --- a/lib/plugin-hub.cjs +++ b/lib/plugin-hub.cjs @@ -20,6 +20,7 @@ function ErrorDuplex(message) { module.exports = { name: 'hub', version: '1.0.0', + // needs: ['conn'], // FIXME: uncomment once we re-write conn manifest: { createTunnel: 'duplex', ping: 'sync', @@ -32,17 +33,14 @@ module.exports = { allow: ['createTunnel', 'ping', 'metadata', 'attendants', 'createToken'], }, }, - init(local, config) { - if (!local.conn || !local.conn.connect) { - throw new Error('tunnel plugin is missing the required ssb-conn plugin') - } - debug('running multiserver at %s', local.getAddress('public')) + init(peer, config) { + debug('running multiserver at %s', peer.getAddress('public')) Tokens.load(config.global.path) Members.load(config.global.path) // Ensure that client connections are only from members or to-be members - local.auth.hook(function (fn, args) { + peer.auth.hook(function (fn, args) { const [clientMetadata, cb] = args const { pubkey, extra } = clientMetadata if (Members.has(pubkey)) { @@ -67,7 +65,7 @@ module.exports = { const notifyAttendants = Notify() pull( - local.conn.hub().listen(), + peer.conn.hub().listen(), pull.filter( ({ type }) => type === 'connecting-failed' || type === 'disconnected' ), @@ -86,8 +84,8 @@ module.exports = { return { attendants() { const clientPubkey = this.shse.pubkey - const clientRPC = local.peers[this.id][0] - if (clientPubkey && clientPubkey !== local.pubkey) { + const clientRPC = peer.peers[this.id][0] + if (clientPubkey && clientPubkey !== peer.pubkey) { debug('welcome %s', clientPubkey) if (!attendants.has(clientPubkey)) { attendants.set(clientPubkey, clientRPC) @@ -128,7 +126,7 @@ module.exports = { getBootstrap() { const port = config.global.connections.incoming.net[0].port - const pubkey = local.shse.pubkey + const pubkey = peer.shse.pubkey const token = 'none' return { port, pubkey, token } }, diff --git a/package-lock.json b/package-lock.json index 06facf9..459f49b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,7 @@ "remark-parse": "10.0.2", "remark-rehype": "10.1.0", "secret-handshake-ext": "0.0.11", - "secret-stack": "8.0.0", + "secret-stack": "8.1.0", "ssb-conn": "6.0.4", "unified": "10.1.2" }, @@ -2986,9 +2986,9 @@ } }, "node_modules/secret-stack": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/secret-stack/-/secret-stack-8.0.0.tgz", - "integrity": "sha512-lKtn6EkdfhoBQ3u50QZ1jwJM0ht76/z3xKlO9uLGOrcm01UCzkXjW1uzEOYM+Igd3Kdni1Zku8LNB9+ggyVdug==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/secret-stack/-/secret-stack-8.1.0.tgz", + "integrity": "sha512-5hRiMjAu+fpgzqU6JSPJrAqmsuS0IbY4XrTmnGXDfiVemjAmD4MiEGFUc5vlCLITucQQgDZX+7Vljhfmn1eopQ==", "dependencies": { "debug": "^4.3.0", "hoox": "0.0.1", @@ -6110,9 +6110,9 @@ } }, "secret-stack": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/secret-stack/-/secret-stack-8.0.0.tgz", - "integrity": "sha512-lKtn6EkdfhoBQ3u50QZ1jwJM0ht76/z3xKlO9uLGOrcm01UCzkXjW1uzEOYM+Igd3Kdni1Zku8LNB9+ggyVdug==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/secret-stack/-/secret-stack-8.1.0.tgz", + "integrity": "sha512-5hRiMjAu+fpgzqU6JSPJrAqmsuS0IbY4XrTmnGXDfiVemjAmD4MiEGFUc5vlCLITucQQgDZX+7Vljhfmn1eopQ==", "requires": { "debug": "^4.3.0", "hoox": "0.0.1", diff --git a/package.json b/package.json index 9426ead..c79dbaa 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "pull-cat": "1.1.11", "pull-notify": "0.1.2", "pull-stream": "3.7.0", - "secret-stack": "8.0.0", + "secret-stack": "8.1.0", "secret-handshake-ext": "0.0.11", "ssb-conn": "6.0.4", "unified": "10.1.2",