diff --git a/lib/peer.cjs b/lib/peer.cjs index a194725..c88151f 100644 --- a/lib/peer.cjs +++ b/lib/peer.cjs @@ -11,7 +11,7 @@ module.exports = function startPeer() { return SecretStack() .use(require('secret-stack/plugins/net')) .use(require('secret-handshake-ext/secret-stack')) - .use(require('ssb-conn')) + .use(require('ppppp-net')) .use(require('./plugin-hub.cjs')) .use(require('./plugin-hub-client.cjs')) .call(null, { @@ -38,7 +38,7 @@ module.exports = function startPeer() { }, }, }, - conn: { + net: { autostart: false, }, }) diff --git a/lib/plugin-hub.cjs b/lib/plugin-hub.cjs index 0ad146f..08a374a 100644 --- a/lib/plugin-hub.cjs +++ b/lib/plugin-hub.cjs @@ -1,3 +1,4 @@ +const bs58 = require('bs58') const cat = require('pull-cat') const Notify = require('pull-notify') const pull = require('pull-stream') @@ -17,10 +18,22 @@ function ErrorDuplex(message) { } } +/** + * @param {Array<[any, any]>} parsedAddress + * @returns {string | undefined} + */ +function extractSHSEPubkey(parsedAddress) { + for (const [transport, transform] of parsedAddress) { + if (transform.name === 'shse') { + return bs58.encode(transform.pubkey) + } + } +} + module.exports = { name: 'hub', version: '1.0.0', - // needs: ['conn'], // FIXME: uncomment once we re-write conn + needs: ['net'], manifest: { createTunnel: 'duplex', ping: 'sync', @@ -65,14 +78,15 @@ module.exports = { const notifyAttendants = Notify() pull( - peer.conn.hub().listen(), + peer.net.listen(), pull.filter( ({ type }) => type === 'connecting-failed' || type === 'disconnected' ), - pull.filter(({ key }) => !!key && attendants.has(key)), - pull.drain(({ key }) => { - debug('farewell %s', key) - attendants.delete(key) + pull.map(({ parsedAddress }) => extractSHSEPubkey(parsedAddress)), + pull.filter((pubkey) => !!pubkey && attendants.has(pubkey)), + pull.drain((pubkey) => { + debug('farewell %s', pubkey) + attendants.delete(pubkey) notifyAttendants([...attendants.keys()]) }) )