no event.parsedAddress
This commit is contained in:
parent
c499e0f945
commit
c62e7fc3bf
|
@ -10,13 +10,16 @@ const { muxrpcMissing } = require('./utils')
|
|||
*/
|
||||
|
||||
/**
|
||||
* @param {Array<[any, any]>} parsedAddress
|
||||
* @param {string} addresses
|
||||
* @returns {string | undefined}
|
||||
*/
|
||||
function extractSHSEPubkey(parsedAddress) {
|
||||
for (const [transport, transform] of parsedAddress) {
|
||||
if (transform.name === 'shse') {
|
||||
return bs58.encode(transform.pubkey)
|
||||
function extractSHSEPubkey(addresses) {
|
||||
for (const address of addresses.split(';')) {
|
||||
for (const [transport, transform] of address.split('~')) {
|
||||
const [name, pubkey, extra] = transform.split(':')
|
||||
if (name === 'shse') {
|
||||
return pubkey
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,8 +45,8 @@ const makeTunnelPlugin = (hubs, peer) => (/** @type {any}} */ msConfig) => {
|
|||
pull(
|
||||
peer.net.listen(),
|
||||
pull.filter(({ type }) => type === 'connected'),
|
||||
pull.drain(async ({ address, parsedAddress, details }) => {
|
||||
const pubkey = extractSHSEPubkey(parsedAddress)
|
||||
pull.drain(async ({ address, details }) => {
|
||||
const pubkey = extractSHSEPubkey(address)
|
||||
if (!pubkey) return
|
||||
if (hubs.has(pubkey)) return
|
||||
if (!details?.rpc) return
|
||||
|
@ -69,8 +72,8 @@ const makeTunnelPlugin = (hubs, peer) => (/** @type {any}} */ msConfig) => {
|
|||
pull(
|
||||
peer.net.listen(),
|
||||
pull.filter(({ type }) => type === 'disconnected'),
|
||||
pull.drain(({ parsedAddress }) => {
|
||||
const pubkey = extractSHSEPubkey(parsedAddress)
|
||||
pull.drain(({ address }) => {
|
||||
const pubkey = extractSHSEPubkey(address)
|
||||
if (!pubkey) return
|
||||
if (!hubs.has(pubkey)) return
|
||||
hubs.get(pubkey)?.close()
|
||||
|
@ -107,7 +110,7 @@ const makeTunnelPlugin = (hubs, peer) => (/** @type {any}} */ msConfig) => {
|
|||
|
||||
// If no hub found, wait a second and try again
|
||||
if (!hubRPC) {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000))
|
||||
hubRPC = hubs.get(hub)?.rpc
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue