mirror of
https://github.com/fluencelabs/js-libp2p-websockets
synced 2025-04-25 17:12:26 +00:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
157aba2835 | ||
|
f1a5d21600 | ||
|
c5ddb0b58e | ||
|
ff4b764eaf | ||
|
d07d1b779e | ||
|
993416145d | ||
|
dff8549c7c | ||
|
511d4b4c99 | ||
|
d6cdb17dc9 | ||
|
577d3505f5 | ||
|
757a48f660 | ||
|
a9f8cfa4ef | ||
|
96244f0489 |
14
.aegir.js
14
.aegir.js
@ -10,23 +10,21 @@ const mockUpgrader = {
|
||||
}
|
||||
let listener
|
||||
|
||||
async function boot () {
|
||||
async function before () {
|
||||
const ws = new WS({ upgrader: mockUpgrader })
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9095/ws')
|
||||
const ma = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9095/ws')
|
||||
listener = ws.createListener(conn => pipe(conn, conn))
|
||||
await listener.listen(ma)
|
||||
listener.on('error', console.error)
|
||||
}
|
||||
|
||||
function shutdown () {
|
||||
function after () {
|
||||
return listener.close()
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
hooks: {
|
||||
browser: {
|
||||
pre: boot,
|
||||
post: shutdown
|
||||
}
|
||||
test: {
|
||||
before,
|
||||
after
|
||||
}
|
||||
}
|
||||
|
26
CHANGELOG.md
26
CHANGELOG.md
@ -1,3 +1,29 @@
|
||||
## [0.15.4](https://github.com/libp2p/js-libp2p-websockets/compare/v0.15.3...v0.15.4) (2021-03-31)
|
||||
|
||||
|
||||
|
||||
## [0.15.3](https://github.com/libp2p/js-libp2p-websockets/compare/v0.15.2...v0.15.3) (2021-02-22)
|
||||
|
||||
|
||||
|
||||
## [0.15.2](https://github.com/libp2p/js-libp2p-websockets/compare/v0.15.1...v0.15.2) (2021-02-09)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* add error event handler ([#118](https://github.com/libp2p/js-libp2p-websockets/issues/118)) ([577d350](https://github.com/libp2p/js-libp2p-websockets/commit/577d3505f559b153ec9e0bbca7d31d2f164712bc))
|
||||
|
||||
|
||||
|
||||
## [0.15.1](https://github.com/libp2p/js-libp2p-websockets/compare/v0.15.0...v0.15.1) (2021-02-05)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* incompatibility with @evanw/esbuild[#740](https://github.com/libp2p/js-libp2p-websockets/issues/740) ([#120](https://github.com/libp2p/js-libp2p-websockets/issues/120)) ([96244f0](https://github.com/libp2p/js-libp2p-websockets/commit/96244f048929c5225905327ae27a88961fe535f8))
|
||||
|
||||
|
||||
|
||||
# [0.15.0](https://github.com/libp2p/js-libp2p-websockets/compare/v0.13.1...v0.15.0) (2020-11-24)
|
||||
|
||||
|
||||
|
29
package.json
29
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "libp2p-websockets",
|
||||
"version": "0.15.0",
|
||||
"version": "0.15.4",
|
||||
"description": "JavaScript implementation of the WebSockets module that libp2p uses and that implements the interface-transport spec",
|
||||
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
||||
"main": "src/index.js",
|
||||
@ -16,7 +16,7 @@
|
||||
"coverage": "nyc --reporter=lcov --reporter=text npm run test:node"
|
||||
},
|
||||
"browser": {
|
||||
"src/listener": "./src/listener.browser.js"
|
||||
"./src/listener.js": "./src/listener.browser.js"
|
||||
},
|
||||
"files": [
|
||||
"src",
|
||||
@ -41,39 +41,42 @@
|
||||
"abortable-iterator": "^3.0.0",
|
||||
"class-is": "^1.1.0",
|
||||
"debug": "^4.2.0",
|
||||
"err-code": "^2.0.3",
|
||||
"ipfs-utils": "^4.0.1",
|
||||
"it-ws": "^3.0.2",
|
||||
"err-code": "^3.0.1",
|
||||
"ipfs-utils": "^6.0.1",
|
||||
"it-ws": "^4.0.0",
|
||||
"libp2p-utils": "^0.2.1",
|
||||
"mafmt": "^8.0.1",
|
||||
"multiaddr": "^8.1.1",
|
||||
"multiaddr-to-uri": "^6.0.0",
|
||||
"p-timeout": "^3.2.0"
|
||||
"multiaddr": "^9.0.1",
|
||||
"multiaddr-to-uri": "fluencelabs/js-multiaddr-to-uri",
|
||||
"p-defer": "^3.0.0",
|
||||
"p-timeout": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"abort-controller": "^3.0.0",
|
||||
"aegir": "^28.1.0",
|
||||
"aegir": "^32.2.0",
|
||||
"bl": "^4.0.0",
|
||||
"is-loopback-addr": "^1.0.1",
|
||||
"it-goodbye": "^2.0.1",
|
||||
"it-pipe": "^1.0.1",
|
||||
"libp2p-interfaces": "^0.7.1",
|
||||
"libp2p-interfaces": "^0.8.3",
|
||||
"streaming-iterables": "^5.0.2",
|
||||
"uint8arrays": "^1.1.0"
|
||||
"uint8arrays": "^2.1.2",
|
||||
"util": "^0.12.3"
|
||||
},
|
||||
"contributors": [
|
||||
"David Dias <daviddias.p@gmail.com>",
|
||||
"Jacob Heun <jacobheun@gmail.com>",
|
||||
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
||||
"Vasco Santos <vasco.santos@moxy.studio>",
|
||||
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
||||
"Francisco Baio Dias <xicombd@gmail.com>",
|
||||
"Dmitriy Ryajov <dryajov@gmail.com>",
|
||||
"Hugo Dias <hugomrdias@gmail.com>",
|
||||
"Alex Potsides <alex@achingbrain.net>",
|
||||
"Hugo Dias <hugomrdias@gmail.com>",
|
||||
"Maciej Krüger <mkg20001@gmail.com>",
|
||||
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
|
||||
"Chris Campbell <christopher.d.campbell@gmail.com>",
|
||||
"Diogo Silva <fsdiogo@gmail.com>",
|
||||
"Irakli Gozalishvili <contact@gozala.io>",
|
||||
"Jack Kleeman <jackkleeman@gmail.com>",
|
||||
"Marcin Rataj <lidel@lidel.org>",
|
||||
"Michael FIG <michael+github@fig.org>",
|
||||
|
28
src/index.js
28
src/index.js
@ -4,8 +4,11 @@ const connect = require('it-ws/client')
|
||||
const withIs = require('class-is')
|
||||
const toUri = require('multiaddr-to-uri')
|
||||
const { AbortError } = require('abortable-iterator')
|
||||
const pDefer = require('p-defer')
|
||||
|
||||
const log = require('debug')('libp2p:websockets')
|
||||
const debug = require('debug')
|
||||
const log = debug('libp2p:websockets')
|
||||
log.error = debug('libp2p:websockets:error')
|
||||
const env = require('ipfs-utils/src/env')
|
||||
|
||||
const createListener = require('./listener')
|
||||
@ -63,10 +66,24 @@ class WebSockets {
|
||||
const cOpts = ma.toOptions()
|
||||
log('dialing %s:%s', cOpts.host, cOpts.port)
|
||||
|
||||
const errorPromise = pDefer()
|
||||
const errfn = (err) => {
|
||||
const msg = `connection error: ${err.message}`
|
||||
log.error(msg)
|
||||
|
||||
errorPromise.reject(err)
|
||||
}
|
||||
|
||||
const rawSocket = connect(toUri(ma), Object.assign({ binary: true }, options))
|
||||
|
||||
if (rawSocket.socket.on) {
|
||||
rawSocket.socket.on('error', errfn)
|
||||
} else {
|
||||
rawSocket.socket.onerror = errfn
|
||||
}
|
||||
|
||||
if (!options.signal) {
|
||||
await rawSocket.connected()
|
||||
await Promise.race([rawSocket.connected(), errorPromise.promise])
|
||||
|
||||
log('connected %s', ma)
|
||||
return rawSocket
|
||||
@ -77,7 +94,10 @@ class WebSockets {
|
||||
const abort = new Promise((resolve, reject) => {
|
||||
onAbort = () => {
|
||||
reject(new AbortError())
|
||||
rawSocket.close()
|
||||
// FIXME: https://github.com/libp2p/js-libp2p-websockets/issues/121
|
||||
setTimeout(() => {
|
||||
rawSocket.close()
|
||||
})
|
||||
}
|
||||
|
||||
// Already aborted?
|
||||
@ -86,7 +106,7 @@ class WebSockets {
|
||||
})
|
||||
|
||||
try {
|
||||
await Promise.race([abort, rawSocket.connected()])
|
||||
await Promise.race([abort, errorPromise.promise, rawSocket.connected()])
|
||||
} finally {
|
||||
options.signal.removeEventListener('abort', onAbort)
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ module.exports = ({ handler, upgrader }, options = {}) => {
|
||||
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)))
|
||||
multiaddrs.push(new multiaddr.Multiaddr(m.toString().replace('0.0.0.0', ni.address)))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -38,7 +38,8 @@ module.exports = (stream, options = {}) => {
|
||||
conn: stream,
|
||||
|
||||
localAddr: options.localAddr || (stream.localAddress && stream.localPort
|
||||
? toMultiaddr(stream.localAddress, stream.localPort) : undefined),
|
||||
? toMultiaddr(stream.localAddress, stream.localPort)
|
||||
: undefined),
|
||||
|
||||
// If the remote address was passed, use it - it may have the peer ID encapsulated
|
||||
remoteAddr: options.remoteAddr || toMultiaddr(stream.remoteAddress, stream.remotePort),
|
||||
|
@ -17,7 +17,7 @@ const mockUpgrader = {
|
||||
}
|
||||
|
||||
describe('libp2p-websockets', () => {
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9095/ws')
|
||||
const ma = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9095/ws')
|
||||
let ws
|
||||
let conn
|
||||
|
||||
|
@ -12,10 +12,10 @@ describe('interface-transport compliance', () => {
|
||||
async setup ({ upgrader }) { // eslint-disable-line require-await
|
||||
const ws = new WS({ upgrader, filter: filters.all })
|
||||
const addrs = [
|
||||
multiaddr('/ip4/127.0.0.1/tcp/9091/ws'),
|
||||
multiaddr('/ip4/127.0.0.1/tcp/9092/ws'),
|
||||
multiaddr('/dns4/ipfs.io/tcp/9092/ws'),
|
||||
multiaddr('/dns4/ipfs.io/tcp/9092/wss')
|
||||
new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9091/ws'),
|
||||
new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9092/ws'),
|
||||
new multiaddr.Multiaddr('/dns4/ipfs.io/tcp/9092/ws'),
|
||||
new multiaddr.Multiaddr('/dns4/ipfs.io/tcp/9092/wss')
|
||||
]
|
||||
|
||||
let delayMs = 0
|
||||
|
133
test/node.js
133
test/node.js
@ -5,6 +5,7 @@
|
||||
const https = require('https')
|
||||
const fs = require('fs')
|
||||
|
||||
const AbortController = require('abort-controller').default
|
||||
const { expect } = require('aegir/utils/chai')
|
||||
const multiaddr = require('multiaddr')
|
||||
const goodbye = require('it-goodbye')
|
||||
@ -34,7 +35,7 @@ describe('instantiate the transport', () => {
|
||||
describe('listen', () => {
|
||||
describe('ip4', () => {
|
||||
let ws
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9090/ws')
|
||||
const ma = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9090/ws')
|
||||
|
||||
beforeEach(() => {
|
||||
ws = new WS({ upgrader: mockUpgrader })
|
||||
@ -69,7 +70,7 @@ describe('listen', () => {
|
||||
})
|
||||
|
||||
it('listen on addr with /ipfs/QmHASH', async () => {
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9090/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9090/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const listener = ws.createListener((conn) => { })
|
||||
|
||||
await listener.listen(ma)
|
||||
@ -77,7 +78,7 @@ describe('listen', () => {
|
||||
})
|
||||
|
||||
it('listen on port 0', async () => {
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/0/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/0/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const listener = ws.createListener((conn) => { })
|
||||
|
||||
await listener.listen(ma)
|
||||
@ -87,7 +88,7 @@ describe('listen', () => {
|
||||
})
|
||||
|
||||
it('listen on any Interface', async () => {
|
||||
const ma = multiaddr('/ip4/0.0.0.0/tcp/0/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma = new multiaddr.Multiaddr('/ip4/0.0.0.0/tcp/0/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const listener = ws.createListener((conn) => { })
|
||||
|
||||
await listener.listen(ma)
|
||||
@ -106,7 +107,7 @@ describe('listen', () => {
|
||||
})
|
||||
|
||||
it('getAddrs on port 0 listen', async () => {
|
||||
const addr = multiaddr('/ip4/127.0.0.1/tcp/0/ws')
|
||||
const addr = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/0/ws')
|
||||
const listener = ws.createListener((conn) => { })
|
||||
await listener.listen(addr)
|
||||
const addrs = await listener.getAddrs()
|
||||
@ -116,7 +117,7 @@ describe('listen', () => {
|
||||
})
|
||||
|
||||
it('getAddrs from listening on 0.0.0.0', async () => {
|
||||
const addr = multiaddr('/ip4/0.0.0.0/tcp/9003/ws')
|
||||
const addr = new multiaddr.Multiaddr('/ip4/0.0.0.0/tcp/9003/ws')
|
||||
const listener = ws.createListener((conn) => { })
|
||||
await listener.listen(addr)
|
||||
const addrs = await listener.getAddrs()
|
||||
@ -125,7 +126,7 @@ describe('listen', () => {
|
||||
})
|
||||
|
||||
it('getAddrs from listening on 0.0.0.0 and port 0', async () => {
|
||||
const addr = multiaddr('/ip4/0.0.0.0/tcp/0/ws')
|
||||
const addr = new multiaddr.Multiaddr('/ip4/0.0.0.0/tcp/0/ws')
|
||||
const listener = ws.createListener((conn) => { })
|
||||
await listener.listen(addr)
|
||||
const addrs = await listener.getAddrs()
|
||||
@ -135,7 +136,7 @@ describe('listen', () => {
|
||||
})
|
||||
|
||||
it('getAddrs preserves p2p Id', async () => {
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9090/ws/p2p/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9090/ws/p2p/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const listener = ws.createListener((conn) => { })
|
||||
|
||||
await listener.listen(ma)
|
||||
@ -148,7 +149,7 @@ describe('listen', () => {
|
||||
|
||||
describe('ip6', () => {
|
||||
let ws
|
||||
const ma = multiaddr('/ip6/::1/tcp/9091/ws')
|
||||
const ma = new multiaddr.Multiaddr('/ip6/::1/tcp/9091/ws')
|
||||
|
||||
beforeEach(() => {
|
||||
ws = new WS({ upgrader: mockUpgrader })
|
||||
@ -183,7 +184,7 @@ describe('listen', () => {
|
||||
})
|
||||
|
||||
it('listen on addr with /ipfs/QmHASH', async () => {
|
||||
const ma = multiaddr('/ip6/::1/tcp/9091/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma = new multiaddr.Multiaddr('/ip6/::1/tcp/9091/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const listener = ws.createListener((conn) => { })
|
||||
await listener.listen(ma)
|
||||
await listener.close()
|
||||
@ -195,7 +196,7 @@ describe('dial', () => {
|
||||
describe('ip4', () => {
|
||||
let ws
|
||||
let listener
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9091/ws')
|
||||
const ma = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9091/ws')
|
||||
|
||||
beforeEach(() => {
|
||||
ws = new WS({ upgrader: mockUpgrader })
|
||||
@ -215,7 +216,7 @@ describe('dial', () => {
|
||||
})
|
||||
|
||||
it('dial with p2p Id', async () => {
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9091/ws/p2p/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9091/ws/p2p/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const conn = await ws.dial(ma)
|
||||
const s = goodbye({ source: ['hey'], sink: collect })
|
||||
|
||||
@ -224,8 +225,18 @@ describe('dial', () => {
|
||||
expect(result).to.be.eql([uint8ArrayFromString('hey')])
|
||||
})
|
||||
|
||||
it('dial should throw on immediate abort', async () => {
|
||||
const ma = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/0/ws')
|
||||
const controller = new AbortController()
|
||||
|
||||
const conn = ws.dial(ma, { signal: controller.signal })
|
||||
controller.abort()
|
||||
|
||||
await expect(conn).to.eventually.be.rejected()
|
||||
})
|
||||
|
||||
it('should resolve port 0', async () => {
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/0/ws')
|
||||
const ma = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/0/ws')
|
||||
const ws = new WS({ upgrader: mockUpgrader })
|
||||
|
||||
// Create a Promise that resolves when a connection is handled
|
||||
@ -255,7 +266,7 @@ describe('dial', () => {
|
||||
describe('ip4 no loopback', () => {
|
||||
let ws
|
||||
let listener
|
||||
const ma = multiaddr('/ip4/0.0.0.0/tcp/0/ws')
|
||||
const ma = new multiaddr.Multiaddr('/ip4/0.0.0.0/tcp/0/ws')
|
||||
|
||||
beforeEach(() => {
|
||||
ws = new WS({ upgrader: mockUpgrader })
|
||||
@ -285,7 +296,7 @@ describe('dial', () => {
|
||||
describe('ip4 with wss', () => {
|
||||
let ws
|
||||
let listener
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9091/wss')
|
||||
const ma = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9091/wss')
|
||||
|
||||
const server = https.createServer({
|
||||
cert: fs.readFileSync('./test/fixtures/certificate.pem'),
|
||||
@ -313,7 +324,7 @@ describe('dial', () => {
|
||||
describe('ip6', () => {
|
||||
let ws
|
||||
let listener
|
||||
const ma = multiaddr('/ip6/::1/tcp/9091')
|
||||
const ma = new multiaddr.Multiaddr('/ip6/::1/tcp/9091')
|
||||
|
||||
beforeEach(() => {
|
||||
ws = new WS({ upgrader: mockUpgrader })
|
||||
@ -342,7 +353,7 @@ describe('dial', () => {
|
||||
})
|
||||
|
||||
it('dial with p2p Id', async () => {
|
||||
const ma = multiaddr('/ip6/::1/tcp/9091/ws/p2p/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma = new multiaddr.Multiaddr('/ip6/::1/tcp/9091/ws/p2p/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const conn = await ws.dial(ma)
|
||||
|
||||
const s = goodbye({
|
||||
@ -365,19 +376,19 @@ describe('filter addrs', () => {
|
||||
})
|
||||
|
||||
it('should filter out invalid WS addresses', function () {
|
||||
const ma1 = multiaddr('/ip4/127.0.0.1/tcp/9090')
|
||||
const ma2 = multiaddr('/ip4/127.0.0.1/udp/9090')
|
||||
const ma3 = multiaddr('/ip6/::1/tcp/80')
|
||||
const ma4 = multiaddr('/dnsaddr/ipfs.io/tcp/80')
|
||||
const ma1 = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9090')
|
||||
const ma2 = new multiaddr.Multiaddr('/ip4/127.0.0.1/udp/9090')
|
||||
const ma3 = new multiaddr.Multiaddr('/ip6/::1/tcp/80')
|
||||
const ma4 = new multiaddr.Multiaddr('/dnsaddr/ipfs.io/tcp/80')
|
||||
|
||||
const valid = ws.filter([ma1, ma2, ma3, ma4])
|
||||
expect(valid.length).to.equal(0)
|
||||
})
|
||||
|
||||
it('should filter correct dns address', function () {
|
||||
const ma1 = multiaddr('/dnsaddr/ipfs.io/ws')
|
||||
const ma2 = multiaddr('/dnsaddr/ipfs.io/tcp/80/ws')
|
||||
const ma3 = multiaddr('/dnsaddr/ipfs.io/tcp/80/wss')
|
||||
const ma1 = new multiaddr.Multiaddr('/dnsaddr/ipfs.io/ws')
|
||||
const ma2 = new multiaddr.Multiaddr('/dnsaddr/ipfs.io/tcp/80/ws')
|
||||
const ma3 = new multiaddr.Multiaddr('/dnsaddr/ipfs.io/tcp/80/wss')
|
||||
|
||||
const valid = ws.filter([ma1, ma2, ma3])
|
||||
expect(valid.length).to.equal(3)
|
||||
@ -387,8 +398,8 @@ describe('filter addrs', () => {
|
||||
})
|
||||
|
||||
it('should filter correct dns address with ipfs id', function () {
|
||||
const ma1 = multiaddr('/dnsaddr/ipfs.io/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma2 = multiaddr('/dnsaddr/ipfs.io/tcp/443/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma1 = new multiaddr.Multiaddr('/dnsaddr/ipfs.io/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma2 = new multiaddr.Multiaddr('/dnsaddr/ipfs.io/tcp/443/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
@ -397,8 +408,8 @@ describe('filter addrs', () => {
|
||||
})
|
||||
|
||||
it('should filter correct dns4 address', function () {
|
||||
const ma1 = multiaddr('/dns4/ipfs.io/tcp/80/ws')
|
||||
const ma2 = multiaddr('/dns4/ipfs.io/tcp/443/wss')
|
||||
const ma1 = new multiaddr.Multiaddr('/dns4/ipfs.io/tcp/80/ws')
|
||||
const ma2 = new multiaddr.Multiaddr('/dns4/ipfs.io/tcp/443/wss')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
@ -407,8 +418,8 @@ describe('filter addrs', () => {
|
||||
})
|
||||
|
||||
it('should filter correct dns6 address', function () {
|
||||
const ma1 = multiaddr('/dns6/ipfs.io/tcp/80/ws')
|
||||
const ma2 = multiaddr('/dns6/ipfs.io/tcp/443/wss')
|
||||
const ma1 = new multiaddr.Multiaddr('/dns6/ipfs.io/tcp/80/ws')
|
||||
const ma2 = new multiaddr.Multiaddr('/dns6/ipfs.io/tcp/443/wss')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
@ -417,8 +428,8 @@ describe('filter addrs', () => {
|
||||
})
|
||||
|
||||
it('should filter correct dns6 address with ipfs id', function () {
|
||||
const ma1 = multiaddr('/dns6/ipfs.io/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma2 = multiaddr('/dns6/ipfs.io/tcp/443/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma1 = new multiaddr.Multiaddr('/dns6/ipfs.io/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma2 = new multiaddr.Multiaddr('/dns6/ipfs.io/tcp/443/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
@ -433,18 +444,18 @@ describe('filter addrs', () => {
|
||||
})
|
||||
|
||||
it('should fail invalid WS addresses', function () {
|
||||
const ma1 = multiaddr('/ip4/127.0.0.1/tcp/9090')
|
||||
const ma2 = multiaddr('/ip4/127.0.0.1/udp/9090')
|
||||
const ma3 = multiaddr('/ip6/::1/tcp/80')
|
||||
const ma4 = multiaddr('/dnsaddr/ipfs.io/tcp/80')
|
||||
const ma1 = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9090')
|
||||
const ma2 = new multiaddr.Multiaddr('/ip4/127.0.0.1/udp/9090')
|
||||
const ma3 = new multiaddr.Multiaddr('/ip6/::1/tcp/80')
|
||||
const ma4 = new multiaddr.Multiaddr('/dnsaddr/ipfs.io/tcp/80')
|
||||
|
||||
const valid = ws.filter([ma1, ma2, ma3, ma4])
|
||||
expect(valid.length).to.equal(0)
|
||||
})
|
||||
|
||||
it('should filter correct ipv4 addresses', function () {
|
||||
const ma1 = multiaddr('/ip4/127.0.0.1/tcp/80/ws')
|
||||
const ma2 = multiaddr('/ip4/127.0.0.1/tcp/443/wss')
|
||||
const ma1 = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/80/ws')
|
||||
const ma2 = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/443/wss')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
@ -453,8 +464,8 @@ describe('filter addrs', () => {
|
||||
})
|
||||
|
||||
it('should filter correct ipv4 addresses with ipfs id', function () {
|
||||
const ma1 = multiaddr('/ip4/127.0.0.1/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma2 = multiaddr('/ip4/127.0.0.1/tcp/80/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma1 = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma2 = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/80/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
@ -463,8 +474,8 @@ describe('filter addrs', () => {
|
||||
})
|
||||
|
||||
it('should filter correct ipv6 address', function () {
|
||||
const ma1 = multiaddr('/ip6/::1/tcp/80/ws')
|
||||
const ma2 = multiaddr('/ip6/::1/tcp/443/wss')
|
||||
const ma1 = new multiaddr.Multiaddr('/ip6/::1/tcp/80/ws')
|
||||
const ma2 = new multiaddr.Multiaddr('/ip6/::1/tcp/443/wss')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
@ -473,8 +484,8 @@ describe('filter addrs', () => {
|
||||
})
|
||||
|
||||
it('should filter correct ipv6 addresses with ipfs id', function () {
|
||||
const ma1 = multiaddr('/ip6/::1/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma2 = multiaddr('/ip6/::1/tcp/443/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma1 = new multiaddr.Multiaddr('/ip6/::1/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma2 = new multiaddr.Multiaddr('/ip6/::1/tcp/443/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
@ -483,9 +494,9 @@ describe('filter addrs', () => {
|
||||
})
|
||||
|
||||
it('should filter correct dns address', function () {
|
||||
const ma1 = multiaddr('/dnsaddr/ipfs.io/ws')
|
||||
const ma2 = multiaddr('/dnsaddr/ipfs.io/tcp/80/ws')
|
||||
const ma3 = multiaddr('/dnsaddr/ipfs.io/tcp/80/wss')
|
||||
const ma1 = new multiaddr.Multiaddr('/dnsaddr/ipfs.io/ws')
|
||||
const ma2 = new multiaddr.Multiaddr('/dnsaddr/ipfs.io/tcp/80/ws')
|
||||
const ma3 = new multiaddr.Multiaddr('/dnsaddr/ipfs.io/tcp/80/wss')
|
||||
|
||||
const valid = ws.filter([ma1, ma2, ma3])
|
||||
expect(valid.length).to.equal(3)
|
||||
@ -495,8 +506,8 @@ describe('filter addrs', () => {
|
||||
})
|
||||
|
||||
it('should filter correct dns address with ipfs id', function () {
|
||||
const ma1 = multiaddr('/dnsaddr/ipfs.io/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma2 = multiaddr('/dnsaddr/ipfs.io/tcp/443/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma1 = new multiaddr.Multiaddr('/dnsaddr/ipfs.io/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma2 = new multiaddr.Multiaddr('/dnsaddr/ipfs.io/tcp/443/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
@ -505,8 +516,8 @@ describe('filter addrs', () => {
|
||||
})
|
||||
|
||||
it('should filter correct dns4 address', function () {
|
||||
const ma1 = multiaddr('/dns4/ipfs.io/tcp/80/ws')
|
||||
const ma2 = multiaddr('/dns4/ipfs.io/tcp/443/wss')
|
||||
const ma1 = new multiaddr.Multiaddr('/dns4/ipfs.io/tcp/80/ws')
|
||||
const ma2 = new multiaddr.Multiaddr('/dns4/ipfs.io/tcp/443/wss')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
@ -515,8 +526,8 @@ describe('filter addrs', () => {
|
||||
})
|
||||
|
||||
it('should filter correct dns6 address', function () {
|
||||
const ma1 = multiaddr('/dns6/ipfs.io/tcp/80/ws')
|
||||
const ma2 = multiaddr('/dns6/ipfs.io/tcp/443/wss')
|
||||
const ma1 = new multiaddr.Multiaddr('/dns6/ipfs.io/tcp/80/ws')
|
||||
const ma2 = new multiaddr.Multiaddr('/dns6/ipfs.io/tcp/443/wss')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
@ -525,8 +536,8 @@ describe('filter addrs', () => {
|
||||
})
|
||||
|
||||
it('should filter correct dns6 address with ipfs id', function () {
|
||||
const ma1 = multiaddr('/dns6/ipfs.io/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma2 = multiaddr('/dns6/ipfs.io/tcp/443/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma1 = new multiaddr.Multiaddr('/dns6/ipfs.io/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma2 = new multiaddr.Multiaddr('/dns6/ipfs.io/tcp/443/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
@ -535,11 +546,11 @@ describe('filter addrs', () => {
|
||||
})
|
||||
|
||||
it('should filter mixed addresses', function () {
|
||||
const ma1 = multiaddr('/dns6/ipfs.io/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma2 = multiaddr('/ip4/127.0.0.1/tcp/9090')
|
||||
const ma3 = multiaddr('/ip4/127.0.0.1/udp/9090')
|
||||
const ma4 = multiaddr('/dns6/ipfs.io/ws')
|
||||
const mh5 = multiaddr('/ip4/127.0.0.1/tcp/9090/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw' +
|
||||
const ma1 = new multiaddr.Multiaddr('/dns6/ipfs.io/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma2 = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9090')
|
||||
const ma3 = new multiaddr.Multiaddr('/ip4/127.0.0.1/udp/9090')
|
||||
const ma4 = new multiaddr.Multiaddr('/dns6/ipfs.io/ws')
|
||||
const mh5 = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9090/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw' +
|
||||
'/p2p-circuit/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
|
||||
const valid = ws.filter([ma1, ma2, ma3, ma4, mh5])
|
||||
@ -549,7 +560,7 @@ describe('filter addrs', () => {
|
||||
})
|
||||
|
||||
it('filter a single addr for this transport', () => {
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9090/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma = new multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/9090/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
|
||||
const valid = ws.filter(ma)
|
||||
expect(valid.length).to.equal(1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user