mirror of https://codeberg.org/pzp/pzp-hub.git
general refactor
This commit is contained in:
parent
d4698d2dbe
commit
11c0756157
|
@ -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
|
||||
|
|
|
@ -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 }
|
||||
},
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue