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

Commit 4525596

Browse files
authored
Merge pull request #147 from D4nte/invalid-ip-port
Suppress `libp2p:ip-port-to-multiaddr:err invalid ip:port for creating a multiaddr`
2 parents a73735b + c8cae5b commit 4525596

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/socket-to-conn.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ module.exports = (socket, options = {}) => {
4444

4545
conn: socket,
4646

47-
localAddr: socket.localAddress && socket.localPort
48-
? toMultiaddr(socket.localAddress, socket.localPort)
49-
: undefined,
47+
localAddr: toLocalAddr(socket),
5048

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

9997
return maConn
10098
}
99+
100+
/**
101+
* Get local multiaddr from socket.
102+
*
103+
* @param {SimplePeer} socket
104+
* @returns {Multiaddr|undefined}
105+
*/
106+
function toLocalAddr (socket) {
107+
if (socket.localAddress && socket.localPort) {
108+
try {
109+
return toMultiaddr(socket.localAddress, socket.localPort)
110+
} catch {
111+
// Might fail if the socket.localAddress is fqdn
112+
}
113+
}
114+
}

0 commit comments

Comments
 (0)