mirror of
https://github.com/fluencelabs/js-libp2p-websockets
synced 2025-06-29 06:21:54 +00:00
feat: filter IPFS addrs correctly (#62)
* feat: dns support for WS * fix: address parsing * feat: filter IPFS addrs correctly * fix: remove lodash includes dependency * feat: mafmt addrs now support /ipfs no need for ad-hoc filtering * feat: skip p2p-circuit addresses * chore: updating ci files * chore: upgrading to new aegir * test: pass the no-parallel flag to tests * wip * test: removing global timeout and setting it on a specific test * feat: resolve 0 addresses (#64) * feat: resolve 0 addresses * chore: upgrading pull-ws * chore: update circle CI * chore: update gitignore * chore: update deps * chore: update CI again * test: fix node.js tests * test: fix browser tests * chore
This commit is contained in:
committed by
David Dias
parent
3d3cdf1c1e
commit
9ddff85601
@ -51,10 +51,16 @@ class WebSockets {
|
||||
}
|
||||
|
||||
return multiaddrs.filter((ma) => {
|
||||
if (includes(ma.protoNames(), 'p2p-circuit')) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (includes(ma.protoNames(), 'ipfs')) {
|
||||
ma = ma.decapsulate('ipfs')
|
||||
}
|
||||
return mafmt.WebSockets.matches(ma) || mafmt.WebSocketsSecure.matches(ma)
|
||||
|
||||
return mafmt.WebSockets.matches(ma) ||
|
||||
mafmt.WebSocketsSecure.matches(ma)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,11 @@
|
||||
|
||||
const Connection = require('interface-connection').Connection
|
||||
const includes = require('lodash.includes')
|
||||
const multiaddr = require('multiaddr')
|
||||
const os = require('os')
|
||||
|
||||
function noop () {}
|
||||
|
||||
const createServer = require('pull-ws/server') || noop
|
||||
|
||||
module.exports = (options, handler) => {
|
||||
@ -30,7 +34,39 @@ module.exports = (options, handler) => {
|
||||
}
|
||||
|
||||
listener.getAddrs = (callback) => {
|
||||
callback(null, [listeningMultiaddr])
|
||||
const multiaddrs = []
|
||||
const address = listener.address()
|
||||
|
||||
if (!address) {
|
||||
return callback(new Error('Listener is not ready yet'))
|
||||
}
|
||||
|
||||
let ipfsId = listeningMultiaddr.getPeerId()
|
||||
|
||||
// Because TCP will only return the IPv6 version
|
||||
// we need to capture from the passed multiaddr
|
||||
if (listeningMultiaddr.toString().indexOf('ip4') !== -1) {
|
||||
let m = listeningMultiaddr.decapsulate('tcp')
|
||||
m = m.encapsulate('/tcp/' + address.port + '/ws')
|
||||
if (listeningMultiaddr.getPeerId()) {
|
||||
m = m.encapsulate('/ipfs/' + ipfsId)
|
||||
}
|
||||
|
||||
if (m.toString().indexOf('0.0.0.0') !== -1) {
|
||||
const netInterfaces = os.networkInterfaces()
|
||||
Object.keys(netInterfaces).forEach((niKey) => {
|
||||
netInterfaces[niKey].forEach((ni) => {
|
||||
if (ni.family === 'IPv4') {
|
||||
multiaddrs.push(multiaddr(m.toString().replace('0.0.0.0', ni.address)))
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
multiaddrs.push(m)
|
||||
}
|
||||
}
|
||||
|
||||
callback(null, multiaddrs)
|
||||
}
|
||||
|
||||
return listener
|
||||
|
Reference in New Issue
Block a user