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
|
* @param {any} config
|
||||||
*/
|
*/
|
||||||
init(local, config) {
|
init(peer, config) {
|
||||||
return {
|
return {
|
||||||
/**
|
/**
|
||||||
* @param {string} origin
|
* @param {string} origin
|
||||||
|
|
|
@ -20,6 +20,7 @@ function ErrorDuplex(message) {
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'hub',
|
name: 'hub',
|
||||||
version: '1.0.0',
|
version: '1.0.0',
|
||||||
|
// needs: ['conn'], // FIXME: uncomment once we re-write conn
|
||||||
manifest: {
|
manifest: {
|
||||||
createTunnel: 'duplex',
|
createTunnel: 'duplex',
|
||||||
ping: 'sync',
|
ping: 'sync',
|
||||||
|
@ -32,17 +33,14 @@ module.exports = {
|
||||||
allow: ['createTunnel', 'ping', 'metadata', 'attendants', 'createToken'],
|
allow: ['createTunnel', 'ping', 'metadata', 'attendants', 'createToken'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
init(local, config) {
|
init(peer, config) {
|
||||||
if (!local.conn || !local.conn.connect) {
|
debug('running multiserver at %s', peer.getAddress('public'))
|
||||||
throw new Error('tunnel plugin is missing the required ssb-conn plugin')
|
|
||||||
}
|
|
||||||
debug('running multiserver at %s', local.getAddress('public'))
|
|
||||||
|
|
||||||
Tokens.load(config.global.path)
|
Tokens.load(config.global.path)
|
||||||
Members.load(config.global.path)
|
Members.load(config.global.path)
|
||||||
|
|
||||||
// Ensure that client connections are only from members or to-be members
|
// 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 [clientMetadata, cb] = args
|
||||||
const { pubkey, extra } = clientMetadata
|
const { pubkey, extra } = clientMetadata
|
||||||
if (Members.has(pubkey)) {
|
if (Members.has(pubkey)) {
|
||||||
|
@ -67,7 +65,7 @@ module.exports = {
|
||||||
const notifyAttendants = Notify()
|
const notifyAttendants = Notify()
|
||||||
|
|
||||||
pull(
|
pull(
|
||||||
local.conn.hub().listen(),
|
peer.conn.hub().listen(),
|
||||||
pull.filter(
|
pull.filter(
|
||||||
({ type }) => type === 'connecting-failed' || type === 'disconnected'
|
({ type }) => type === 'connecting-failed' || type === 'disconnected'
|
||||||
),
|
),
|
||||||
|
@ -86,8 +84,8 @@ module.exports = {
|
||||||
return {
|
return {
|
||||||
attendants() {
|
attendants() {
|
||||||
const clientPubkey = this.shse.pubkey
|
const clientPubkey = this.shse.pubkey
|
||||||
const clientRPC = local.peers[this.id][0]
|
const clientRPC = peer.peers[this.id][0]
|
||||||
if (clientPubkey && clientPubkey !== local.pubkey) {
|
if (clientPubkey && clientPubkey !== peer.pubkey) {
|
||||||
debug('welcome %s', clientPubkey)
|
debug('welcome %s', clientPubkey)
|
||||||
if (!attendants.has(clientPubkey)) {
|
if (!attendants.has(clientPubkey)) {
|
||||||
attendants.set(clientPubkey, clientRPC)
|
attendants.set(clientPubkey, clientRPC)
|
||||||
|
@ -128,7 +126,7 @@ module.exports = {
|
||||||
|
|
||||||
getBootstrap() {
|
getBootstrap() {
|
||||||
const port = config.global.connections.incoming.net[0].port
|
const port = config.global.connections.incoming.net[0].port
|
||||||
const pubkey = local.shse.pubkey
|
const pubkey = peer.shse.pubkey
|
||||||
const token = 'none'
|
const token = 'none'
|
||||||
return { port, pubkey, token }
|
return { port, pubkey, token }
|
||||||
},
|
},
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
"remark-parse": "10.0.2",
|
"remark-parse": "10.0.2",
|
||||||
"remark-rehype": "10.1.0",
|
"remark-rehype": "10.1.0",
|
||||||
"secret-handshake-ext": "0.0.11",
|
"secret-handshake-ext": "0.0.11",
|
||||||
"secret-stack": "8.0.0",
|
"secret-stack": "8.1.0",
|
||||||
"ssb-conn": "6.0.4",
|
"ssb-conn": "6.0.4",
|
||||||
"unified": "10.1.2"
|
"unified": "10.1.2"
|
||||||
},
|
},
|
||||||
|
@ -2986,9 +2986,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/secret-stack": {
|
"node_modules/secret-stack": {
|
||||||
"version": "8.0.0",
|
"version": "8.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/secret-stack/-/secret-stack-8.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/secret-stack/-/secret-stack-8.1.0.tgz",
|
||||||
"integrity": "sha512-lKtn6EkdfhoBQ3u50QZ1jwJM0ht76/z3xKlO9uLGOrcm01UCzkXjW1uzEOYM+Igd3Kdni1Zku8LNB9+ggyVdug==",
|
"integrity": "sha512-5hRiMjAu+fpgzqU6JSPJrAqmsuS0IbY4XrTmnGXDfiVemjAmD4MiEGFUc5vlCLITucQQgDZX+7Vljhfmn1eopQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"debug": "^4.3.0",
|
"debug": "^4.3.0",
|
||||||
"hoox": "0.0.1",
|
"hoox": "0.0.1",
|
||||||
|
@ -6110,9 +6110,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"secret-stack": {
|
"secret-stack": {
|
||||||
"version": "8.0.0",
|
"version": "8.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/secret-stack/-/secret-stack-8.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/secret-stack/-/secret-stack-8.1.0.tgz",
|
||||||
"integrity": "sha512-lKtn6EkdfhoBQ3u50QZ1jwJM0ht76/z3xKlO9uLGOrcm01UCzkXjW1uzEOYM+Igd3Kdni1Zku8LNB9+ggyVdug==",
|
"integrity": "sha512-5hRiMjAu+fpgzqU6JSPJrAqmsuS0IbY4XrTmnGXDfiVemjAmD4MiEGFUc5vlCLITucQQgDZX+7Vljhfmn1eopQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"debug": "^4.3.0",
|
"debug": "^4.3.0",
|
||||||
"hoox": "0.0.1",
|
"hoox": "0.0.1",
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
"pull-cat": "1.1.11",
|
"pull-cat": "1.1.11",
|
||||||
"pull-notify": "0.1.2",
|
"pull-notify": "0.1.2",
|
||||||
"pull-stream": "3.7.0",
|
"pull-stream": "3.7.0",
|
||||||
"secret-stack": "8.0.0",
|
"secret-stack": "8.1.0",
|
||||||
"secret-handshake-ext": "0.0.11",
|
"secret-handshake-ext": "0.0.11",
|
||||||
"ssb-conn": "6.0.4",
|
"ssb-conn": "6.0.4",
|
||||||
"unified": "10.1.2",
|
"unified": "10.1.2",
|
||||||
|
|
Loading…
Reference in New Issue