mirror of
https://github.com/fluencelabs/js-libp2p-tcp
synced 2025-07-02 05:21:51 +00:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
3d17d40c2b | |||
8fac0f9dd6 | |||
500ca9b699 |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "libp2p-tcp",
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.1",
|
||||
"description": "Node.js implementation of the TCP module that libp2p uses, which implements the interface-connection and interface-transport interfaces",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
|
20
src/index.js
20
src/index.js
@ -1,6 +1,7 @@
|
||||
const debug = require('debug')
|
||||
const log = debug('libp2p:tcp')
|
||||
// const debug = require('debug')
|
||||
// const log = debug('libp2p:tcp')
|
||||
const tcp = require('net')
|
||||
const multiaddr = require('multiaddr')
|
||||
|
||||
exports = module.exports = TCP
|
||||
|
||||
@ -31,13 +32,24 @@ function TCP () {
|
||||
}
|
||||
|
||||
var count = 0
|
||||
const freshMultiaddrs = []
|
||||
|
||||
multiaddrs.forEach((m) => {
|
||||
const listener = tcp.createServer(handler)
|
||||
listener.listen(m.toOptions(), () => {
|
||||
log('listening on: ', m.toString())
|
||||
// Node.js likes to convert addr to IPv6 (when 0.0.0.0 for e.g)
|
||||
const address = listener.address()
|
||||
if (m.toString().indexOf('ip4')) {
|
||||
m = m.decapsulate('tcp')
|
||||
m = m.encapsulate('/tcp/' + address.port)
|
||||
freshMultiaddrs.push(m)
|
||||
}
|
||||
if (address.family === 'IPv6') {
|
||||
freshMultiaddrs.push(multiaddr('/ip6/' + address.address + '/tcp/' + address.port))
|
||||
}
|
||||
|
||||
if (++count === multiaddrs.length) {
|
||||
callback()
|
||||
callback(null, freshMultiaddrs)
|
||||
}
|
||||
})
|
||||
listeners.push(listener)
|
||||
|
Reference in New Issue
Block a user