File tree 2 files changed +30
-0
lines changed
2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 37
37
"dependencies" : {
38
38
"debug" : " ^3.1.0" ,
39
39
"interface-connection" : " ~0.3.2" ,
40
+ "ip-address" : " ^5.8.9" ,
40
41
"lodash.includes" : " ^4.3.0" ,
41
42
"lodash.isfunction" : " ^3.0.9" ,
42
43
"mafmt" : " ^3.0.2" ,
43
44
"multiaddr" : " ^3.0.2" ,
44
45
"once" : " ^1.4.0" ,
46
+ "stream-to-pull-stream" : " ^1.7.2" ,
45
47
"utp-native" : " ^1.6.2"
46
48
},
47
49
"contributors" : [
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments