Skip to content
This repository was archived by the owner on Apr 24, 2023. It is now read-only.

Suppress libp2p:ip-port-to-multiaddr:err invalid ip:port for creating a multiaddr #147

Merged
merged 2 commits into from
Mar 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/socket-to-conn.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ module.exports = (socket, options = {}) => {

conn: socket,

localAddr: socket.localAddress && socket.localPort
? toMultiaddr(socket.localAddress, socket.localPort)
: undefined,
localAddr: toLocalAddr(socket),

// If the remote address was passed, use it - it may have the peer ID encapsulated
remoteAddr: options.remoteAddr,
Expand Down Expand Up @@ -98,3 +96,19 @@ module.exports = (socket, options = {}) => {

return maConn
}

/**
* Get local multiaddr from socket.
*
* @param {SimplePeer} socket
* @returns {Multiaddr|undefined}
*/
function toLocalAddr (socket) {
if (socket.localAddress && socket.localPort) {
try {
return toMultiaddr(socket.localAddress, socket.localPort)
} catch {
// Might fail if the socket.localAddress is fqdn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wemeetagain what about this catch case? Should it be handled somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to ensure we get a multiaddr from a fqdn then we would need to change upstream in simple-peer and find a way to get the ip version of the connection https://github.com/ipfs-shipyard/simple-peer/blob/1039b90f91fc8e91492ff1af52f9fc9bfff97c35/index.js#L773 with a fqdn domain.

I am not convinced that is worth it as it works fine in Chrome with undefined.

}
}
}