Rename to pzp

This commit is contained in:
Jacob Karlsson 2024-05-07 15:47:22 +02:00
parent 6dec9c2529
commit 25fef49217
5 changed files with 39 additions and 29 deletions

View File

@ -1 +1,9 @@
**Work in progress**
# pzp-hub-client
secret-stack plugin to connect to a pzp-hub
## Installation
```
npm install pzp-hub-client
```

View File

@ -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<import('ppppp-net').init>} PPPPPNet
* @typedef {{net: PPPPPNet, shse: {pubkey: string}}} Peer
* @typedef {ReturnType<import('pzp-net').init>} PZPNet
* @typedef {{net: PZPNet, shse: {pubkey: string}}} Peer
* @typedef {(pull.Sink<AttendantsEvent> & {abort: () => void})} Drain
* @typedef {{type: 'state', pubkeys: Array<string>}} AttendantsEventState
* @typedef {{type: 'joined', pubkey: string}} AttendantsEventJoined

View File

@ -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<import('ppppp-net').init>} PPPPPNet
* @typedef {ReturnType<import('pzp-net').init>} PZPNet
* @typedef {Map<string, HubObserver>} 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 = {

View File

@ -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<import('ppppp-net').init>} PPPPPNet
* @typedef {ReturnType<import('ppppp-set').init>} PPPPPSet
* @typedef {import('ppppp-net').Info} Info
* @typedef {ReturnType<import('pzp-net').init>} PZPNet
* @typedef {ReturnType<import('pzp-set').init>} 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)
})
})
}

View File

@ -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 <contact@staltz.com>",
"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"