From 25fef49217f97a63aab5738f3937c5c4a0f4ca91 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Tue, 7 May 2024 15:47:22 +0200 Subject: [PATCH] Rename to pzp --- README.md | 10 +++++++++- lib/hub-observer.js | 6 +++--- lib/ms-tunnel.js | 6 +++--- lib/plugin-hub-client.js | 34 ++++++++++++++++++---------------- package.json | 12 ++++++------ 5 files changed, 39 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index ba9d17d..035123b 100644 --- a/README.md +++ b/README.md @@ -1 +1,9 @@ -**Work in progress** \ No newline at end of file +# pzp-hub-client + +secret-stack plugin to connect to a pzp-hub + +## Installation + +``` +npm install pzp-hub-client +``` diff --git a/lib/hub-observer.js b/lib/hub-observer.js index 611d31f..bda53eb 100644 --- a/lib/hub-observer.js +++ b/lib/hub-observer.js @@ -1,11 +1,11 @@ -const debug = require('debug')('ppppp:hub-client') +const debug = require('debug')('pzp:hub-client') const pull = require('pull-stream') // @ts-ignore const getSeverity = require('ssb-network-errors') /** - * @typedef {ReturnType} PPPPPNet - * @typedef {{net: PPPPPNet, shse: {pubkey: string}}} Peer + * @typedef {ReturnType} PZPNet + * @typedef {{net: PZPNet, shse: {pubkey: string}}} Peer * @typedef {(pull.Sink & {abort: () => void})} Drain * @typedef {{type: 'state', pubkeys: Array}} AttendantsEventState * @typedef {{type: 'joined', pubkey: string}} AttendantsEventJoined diff --git a/lib/ms-tunnel.js b/lib/ms-tunnel.js index 64585c4..3f018ba 100644 --- a/lib/ms-tunnel.js +++ b/lib/ms-tunnel.js @@ -1,17 +1,17 @@ -const debug = require('debug')('ppppp:hub-client') +const debug = require('debug')('pzp:hub-client') const pull = require('pull-stream') const run = require('promisify-tuple') const HubObserver = require('./hub-observer') const { muxrpcMissing } = require('./utils') /** - * @typedef {ReturnType} PPPPPNet + * @typedef {ReturnType} PZPNet * @typedef {Map} Hubs */ /** * @param {Hubs} hubs - * @param {{net: PPPPPNet, shse: {pubkey: string}}} peer + * @param {{net: PZPNet, shse: {pubkey: string}}} peer */ const makeTunnelPlugin = (hubs, peer) => (/** @type {any}} */ msConfig) => { const self = { diff --git a/lib/plugin-hub-client.js b/lib/plugin-hub-client.js index 439044e..0acb9af 100644 --- a/lib/plugin-hub-client.js +++ b/lib/plugin-hub-client.js @@ -1,7 +1,7 @@ // @ts-ignore const DuplexPair = require('pull-pair/duplex') // @ts-ignore const Notify = require('pull-notify') -const debug = require('debug')('ppppp:hub-client') +const debug = require('debug')('pzp:hub-client') const makeTunnelPlugin = require('./ms-tunnel') const { ErrorDuplex } = require('./utils') @@ -9,12 +9,12 @@ const HUBS_SUBDOMAIN = 'hubs' /** * @typedef {`/${string}/${string}/${string}/${string}/${string}/${string}`} HubMultiaddr - * @typedef {ReturnType} PPPPPNet - * @typedef {ReturnType} PPPPPSet - * @typedef {import('ppppp-net').Info} Info + * @typedef {ReturnType} PZPNet + * @typedef {ReturnType} PZPSet + * @typedef {import('pzp-net').Info} Info * @typedef {{ - * net: PPPPPNet, - * set: PPPPPSet, + * net: PZPNet, + * set: PZPSet, * multiserver: { * transport(transport: any): void * }, @@ -90,16 +90,18 @@ function initHubClient(peer, config) { if (err === true || !peers) return cb(null, []) if (err) return cb(new Error('Failed to get hubs', { cause: err })) const infoMap = new Map(peers) - const multiaddrs = peer.set.values(HUBS_SUBDOMAIN) - const hubs = [] - for (const multiaddr of multiaddrs) { - const stats = infoMap.get(multiaddr)?.stats ?? { failure: 1 } - hubs.push({ multiaddr, stats }) - } - hubs.sort((a, b) => (a.stats.failure ?? 1) - (b.stats.failure ?? 1)) - hubs.splice(amount) - const returnable = hubs.map((h) => h.multiaddr) - cb(null, returnable) + peer.set.values(HUBS_SUBDOMAIN, null, (err, multiaddrs) => { + if (err) return cb(err) + const hubs = [] + for (const multiaddr of multiaddrs) { + const stats = infoMap.get(multiaddr)?.stats ?? { failure: 1 } + hubs.push({ multiaddr, stats }) + } + hubs.sort((a, b) => (a.stats.failure ?? 1) - (b.stats.failure ?? 1)) + hubs.splice(amount) + const returnable = hubs.map((h) => h.multiaddr) + cb(null, returnable) + }) }) } diff --git a/package.json b/package.json index 99b3b94..c8fc4a3 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { - "name": "ppppp-hub-client", + "name": "pzp-hub-client", "version": "0.0.1", - "description": "secret-stack plugin to connect to a ppppp-hub", + "description": "secret-stack plugin to connect to a pzp-hub", "author": "Andre Staltz ", "license": "MIT", - "homepage": "https://github.com/staltz/ppppp-hub-client", + "homepage": "https://codeberg.org/pzp/pzp-hub-client", "repository": { "type": "git", - "url": "git@github.com:staltz/ppppp-hub-client.git" + "url": "git@codeberg.org:pzp/pzp-hub-client.git" }, "main": "lib/index.js", "files": [ @@ -45,8 +45,8 @@ "@types/pull-stream": "^3.6.2", "c8": "7", "husky": "^4.3.0", - "ppppp-net": "github:staltz/ppppp-net", - "ppppp-set": "github:staltz/ppppp-set", + "pzp-net": "^1.0.0", + "pzp-set": "^1.0.0", "prettier": "^2.6.2", "pretty-quick": "^3.1.3", "typescript": "^5.1.3"