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

Commit 2593f87

Browse files
committed
Extract logic to function
1 parent ab4cc82 commit 2593f87

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/socket-to-conn.js

Lines changed: 13 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,15 @@ 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+
return socket.localAddress && socket.localPort
108+
? toMultiaddr(socket.localAddress, socket.localPort)
109+
: undefined
110+
}

0 commit comments

Comments
 (0)