Rename to pzp
This commit is contained in:
parent
6dec9c2529
commit
25fef49217
10
README.md
10
README.md
|
@ -1 +1,9 @@
|
||||||
**Work in progress**
|
# pzp-hub-client
|
||||||
|
|
||||||
|
secret-stack plugin to connect to a pzp-hub
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```
|
||||||
|
npm install pzp-hub-client
|
||||||
|
```
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
const debug = require('debug')('ppppp:hub-client')
|
const debug = require('debug')('pzp:hub-client')
|
||||||
const pull = require('pull-stream')
|
const pull = require('pull-stream')
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const getSeverity = require('ssb-network-errors')
|
const getSeverity = require('ssb-network-errors')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {ReturnType<import('ppppp-net').init>} PPPPPNet
|
* @typedef {ReturnType<import('pzp-net').init>} PZPNet
|
||||||
* @typedef {{net: PPPPPNet, shse: {pubkey: string}}} Peer
|
* @typedef {{net: PZPNet, shse: {pubkey: string}}} Peer
|
||||||
* @typedef {(pull.Sink<AttendantsEvent> & {abort: () => void})} Drain
|
* @typedef {(pull.Sink<AttendantsEvent> & {abort: () => void})} Drain
|
||||||
* @typedef {{type: 'state', pubkeys: Array<string>}} AttendantsEventState
|
* @typedef {{type: 'state', pubkeys: Array<string>}} AttendantsEventState
|
||||||
* @typedef {{type: 'joined', pubkey: string}} AttendantsEventJoined
|
* @typedef {{type: 'joined', pubkey: string}} AttendantsEventJoined
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
const debug = require('debug')('ppppp:hub-client')
|
const debug = require('debug')('pzp:hub-client')
|
||||||
const pull = require('pull-stream')
|
const pull = require('pull-stream')
|
||||||
const run = require('promisify-tuple')
|
const run = require('promisify-tuple')
|
||||||
const HubObserver = require('./hub-observer')
|
const HubObserver = require('./hub-observer')
|
||||||
const { muxrpcMissing } = require('./utils')
|
const { muxrpcMissing } = require('./utils')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {ReturnType<import('ppppp-net').init>} PPPPPNet
|
* @typedef {ReturnType<import('pzp-net').init>} PZPNet
|
||||||
* @typedef {Map<string, HubObserver>} Hubs
|
* @typedef {Map<string, HubObserver>} Hubs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Hubs} 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 makeTunnelPlugin = (hubs, peer) => (/** @type {any}} */ msConfig) => {
|
||||||
const self = {
|
const self = {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const DuplexPair = require('pull-pair/duplex') // @ts-ignore
|
const DuplexPair = require('pull-pair/duplex') // @ts-ignore
|
||||||
const Notify = require('pull-notify')
|
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 makeTunnelPlugin = require('./ms-tunnel')
|
||||||
const { ErrorDuplex } = require('./utils')
|
const { ErrorDuplex } = require('./utils')
|
||||||
|
|
||||||
|
@ -9,12 +9,12 @@ const HUBS_SUBDOMAIN = 'hubs'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {`/${string}/${string}/${string}/${string}/${string}/${string}`} HubMultiaddr
|
* @typedef {`/${string}/${string}/${string}/${string}/${string}/${string}`} HubMultiaddr
|
||||||
* @typedef {ReturnType<import('ppppp-net').init>} PPPPPNet
|
* @typedef {ReturnType<import('pzp-net').init>} PZPNet
|
||||||
* @typedef {ReturnType<import('ppppp-set').init>} PPPPPSet
|
* @typedef {ReturnType<import('pzp-set').init>} PZPSet
|
||||||
* @typedef {import('ppppp-net').Info} Info
|
* @typedef {import('pzp-net').Info} Info
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* net: PPPPPNet,
|
* net: PZPNet,
|
||||||
* set: PPPPPSet,
|
* set: PZPSet,
|
||||||
* multiserver: {
|
* multiserver: {
|
||||||
* transport(transport: any): void
|
* transport(transport: any): void
|
||||||
* },
|
* },
|
||||||
|
@ -90,16 +90,18 @@ function initHubClient(peer, config) {
|
||||||
if (err === true || !peers) return cb(null, [])
|
if (err === true || !peers) return cb(null, [])
|
||||||
if (err) return cb(new Error('Failed to get hubs', { cause: err }))
|
if (err) return cb(new Error('Failed to get hubs', { cause: err }))
|
||||||
const infoMap = new Map(peers)
|
const infoMap = new Map(peers)
|
||||||
const multiaddrs = peer.set.values(HUBS_SUBDOMAIN)
|
peer.set.values(HUBS_SUBDOMAIN, null, (err, multiaddrs) => {
|
||||||
const hubs = []
|
if (err) return cb(err)
|
||||||
for (const multiaddr of multiaddrs) {
|
const hubs = []
|
||||||
const stats = infoMap.get(multiaddr)?.stats ?? { failure: 1 }
|
for (const multiaddr of multiaddrs) {
|
||||||
hubs.push({ multiaddr, stats })
|
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)
|
hubs.sort((a, b) => (a.stats.failure ?? 1) - (b.stats.failure ?? 1))
|
||||||
const returnable = hubs.map((h) => h.multiaddr)
|
hubs.splice(amount)
|
||||||
cb(null, returnable)
|
const returnable = hubs.map((h) => h.multiaddr)
|
||||||
|
cb(null, returnable)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
package.json
12
package.json
|
@ -1,13 +1,13 @@
|
||||||
{
|
{
|
||||||
"name": "ppppp-hub-client",
|
"name": "pzp-hub-client",
|
||||||
"version": "0.0.1",
|
"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>",
|
"author": "Andre Staltz <contact@staltz.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"homepage": "https://github.com/staltz/ppppp-hub-client",
|
"homepage": "https://codeberg.org/pzp/pzp-hub-client",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git@github.com:staltz/ppppp-hub-client.git"
|
"url": "git@codeberg.org:pzp/pzp-hub-client.git"
|
||||||
},
|
},
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"files": [
|
"files": [
|
||||||
|
@ -45,8 +45,8 @@
|
||||||
"@types/pull-stream": "^3.6.2",
|
"@types/pull-stream": "^3.6.2",
|
||||||
"c8": "7",
|
"c8": "7",
|
||||||
"husky": "^4.3.0",
|
"husky": "^4.3.0",
|
||||||
"ppppp-net": "github:staltz/ppppp-net",
|
"pzp-net": "^1.0.0",
|
||||||
"ppppp-set": "github:staltz/ppppp-set",
|
"pzp-set": "^1.0.0",
|
||||||
"prettier": "^2.6.2",
|
"prettier": "^2.6.2",
|
||||||
"pretty-quick": "^3.1.3",
|
"pretty-quick": "^3.1.3",
|
||||||
"typescript": "^5.1.3"
|
"typescript": "^5.1.3"
|
||||||
|
|
Loading…
Reference in New Issue