Skip to content

Commit

Permalink
feat: getMultiaddr and missing deps
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Mar 19, 2018
1 parent fd0f156 commit e6e6e54
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -37,11 +37,13 @@
"dependencies": {
"debug": "^3.1.0",
"interface-connection": "~0.3.2",
"ip-address": "^5.8.9",
"lodash.includes": "^4.3.0",
"lodash.isfunction": "^3.0.9",
"mafmt": "^3.0.2",
"multiaddr": "^3.0.2",
"once": "^1.4.0",
"stream-to-pull-stream": "^1.7.2",
"utp-native": "^1.6.2"
},
"contributors": [
Expand Down
28 changes: 28 additions & 0 deletions src/get-multiaddr.js
@@ -0,0 +1,28 @@
'use strict'

const multiaddr = require('multiaddr')
const Address6 = require('ip-address').Address6

module.exports = (socket) => {
let ma

if (socket.remoteFamily === 'IPv6') {
const addr = new Address6(socket.remoteAddress)

if (addr.v4) {
const ip4 = addr.to4().correctForm()
ma = multiaddr('/ip4/' + ip4 +
'/tcp/' + socket.remotePort
)
} else {
ma = multiaddr('/ip6/' + socket.remoteAddress +
'/tcp/' + socket.remotePort
)
}
} else {
ma = multiaddr('/ip4/' + socket.remoteAddress +
'/tcp/' + socket.remotePort)
}

return ma
}

0 comments on commit e6e6e54

Please sign in to comment.