Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
fix: handle address being undefined (#209)
Browse files Browse the repository at this point in the history
I observed a crash while running IPFS, need to do more investigation
as to the cause but this is the fix.
  • Loading branch information
achingbrain authored Sep 12, 2022
1 parent c79ceb8 commit 64ed009
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,16 @@ export function createListener (context: Context) {
throw new Error('Incorrect server address type')
}

// Because TCP will only return the IPv6 version
// we need to capture from the passed multiaddr
if (listeningAddr.toString().startsWith('/ip4')) {
addrs = addrs.concat(getMultiaddrs('ip4', address.address, address.port))
} else if (address.family === 'IPv6') {
addrs = addrs.concat(getMultiaddrs('ip6', address.address, address.port))
try {
// Because TCP will only return the IPv6 version
// we need to capture from the passed multiaddr
if (listeningAddr.toString().startsWith('/ip4')) {
addrs = addrs.concat(getMultiaddrs('ip4', address.address, address.port))
} else if (address.family === 'IPv6') {
addrs = addrs.concat(getMultiaddrs('ip6', address.address, address.port))
}
} catch (err) {
log.error('could not turn %s:%s into multiaddr', address.address, address.port, err)
}

return addrs.map(ma => peerId != null ? ma.encapsulate(`/p2p/${peerId}`) : ma)
Expand Down

0 comments on commit 64ed009

Please sign in to comment.