Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(do not merge) test CI #146

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,5 @@ For more information: [`examples/isolated-dht.mjs`](examples/isolated-dht.mjs)
## License

MIT

irrelevant change
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"standard": "^17.1.0"
},
"scripts": {
"test": "standard && node test/all.js",
"test": "standard && node test/relaying.js",
"test:generate": "brittle -r test/all.js test/*.js",
"lint": "standard"
},
Expand Down
96 changes: 49 additions & 47 deletions test/relaying.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,65 +351,67 @@ test('relay connections through node, server side, server aborts hole punch', as
await c.destroy()
})

test('relay connections through node, client and server side', async function (t) {
const { bootstrap } = await swarm(t)
for (let i = 0; i < 100; i++) {
test('relay connections through node, client and server side', async function (t) {
const { bootstrap } = await swarm(t)

const a = new DHT({ bootstrap, quickFirewall: false, ephemeral: true })
const b = new DHT({ bootstrap, quickFirewall: false, ephemeral: true })
const c = new DHT({ bootstrap, quickFirewall: false, ephemeral: true })
const a = new DHT({ bootstrap, quickFirewall: false, ephemeral: true })
const b = new DHT({ bootstrap, quickFirewall: false, ephemeral: true })
const c = new DHT({ bootstrap, quickFirewall: false, ephemeral: true })

const lc = t.test('socket lifecycle')
lc.plan(5)
const lc = t.test('socket lifecycle')
lc.plan(5)

const relay = new RelayServer({
createStream (opts) {
return a.createRawStream({ ...opts, framed: true })
}
})
const relay = new RelayServer({
createStream (opts) {
return a.createRawStream({ ...opts, framed: true })
}
})

t.teardown(() => relay.close())
t.teardown(() => relay.close())

const aServer = a.createServer(function (socket) {
const session = relay.accept(socket, { id: socket.remotePublicKey })
session
.on('error', (err) => t.comment(err.message))
})
const aServer = a.createServer(function (socket) {
const session = relay.accept(socket, { id: socket.remotePublicKey })
session
.on('error', (err) => t.comment(err.message))
})

await aServer.listen()
await aServer.listen()

const bServer = b.createServer({
relayThrough: aServer.publicKey
}, function (socket) {
lc.pass('server socket opened')
socket
.on('data', (data) => {
lc.alike(data, Buffer.from('hello world'))
})
.on('close', () => {
lc.pass('server socket closed')
})
.end()
})
const bServer = b.createServer({
relayThrough: aServer.publicKey
}, function (socket) {
lc.pass('server socket opened')
socket
.on('data', (data) => {
lc.alike(data, Buffer.from('hello world'))
})
.on('close', () => {
lc.pass('server socket closed')
})
.end()
})

await bServer.listen()
await bServer.listen()

const bSocket = c.connect(bServer.publicKey, { relayThrough: aServer.publicKey })
const bSocket = c.connect(bServer.publicKey, { relayThrough: aServer.publicKey })

bSocket
.on('open', () => {
lc.pass('client socket opened')
})
.on('close', () => {
lc.pass('client socket closed')
})
.end('hello world')
bSocket
.on('open', () => {
lc.pass('client socket opened')
})
.on('close', () => {
lc.pass('client socket closed')
})
.end('hello world')

await lc
await lc

await a.destroy()
await b.destroy()
await c.destroy()
})
await a.destroy()
await b.destroy()
await c.destroy()
})
}

test.skip('relay several connections through node with pool', async function (t) {
const { bootstrap } = await swarm(t)
Expand Down
Loading