Skip to content

Commit e6e6e54

Browse files
committed
feat: getMultiaddr and missing deps
1 parent fd0f156 commit e6e6e54

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@
3737
"dependencies": {
3838
"debug": "^3.1.0",
3939
"interface-connection": "~0.3.2",
40+
"ip-address": "^5.8.9",
4041
"lodash.includes": "^4.3.0",
4142
"lodash.isfunction": "^3.0.9",
4243
"mafmt": "^3.0.2",
4344
"multiaddr": "^3.0.2",
4445
"once": "^1.4.0",
46+
"stream-to-pull-stream": "^1.7.2",
4547
"utp-native": "^1.6.2"
4648
},
4749
"contributors": [

src/get-multiaddr.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict'
2+
3+
const multiaddr = require('multiaddr')
4+
const Address6 = require('ip-address').Address6
5+
6+
module.exports = (socket) => {
7+
let ma
8+
9+
if (socket.remoteFamily === 'IPv6') {
10+
const addr = new Address6(socket.remoteAddress)
11+
12+
if (addr.v4) {
13+
const ip4 = addr.to4().correctForm()
14+
ma = multiaddr('/ip4/' + ip4 +
15+
'/tcp/' + socket.remotePort
16+
)
17+
} else {
18+
ma = multiaddr('/ip6/' + socket.remoteAddress +
19+
'/tcp/' + socket.remotePort
20+
)
21+
}
22+
} else {
23+
ma = multiaddr('/ip4/' + socket.remoteAddress +
24+
'/tcp/' + socket.remotePort)
25+
}
26+
27+
return ma
28+
}

0 commit comments

Comments
 (0)