mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-03-30 22:31:03 +00:00
There are a few places in the codebase where we send/receive data from the network without timeouts/abort controllers which means the user has to wait for the underlying socket to timeout which can take a long time depending on the platform, if at all. This change ensures we can time out while running identify (both flavours), ping and fetch and adds tests to ensure there are no regressions.
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
/* eslint-env mocha */
|
|
|
|
import { expect } from 'aegir/chai'
|
|
import mergeOptions from 'merge-options'
|
|
import { validateConfig } from '../../src/config.js'
|
|
import { createLibp2pNode, Libp2pNode } from '../../src/libp2p.js'
|
|
import { baseOptions } from './utils.js'
|
|
|
|
describe('Protocol prefix is configurable', () => {
|
|
let libp2p: Libp2pNode
|
|
|
|
afterEach(async () => {
|
|
if (libp2p != null) {
|
|
await libp2p.stop()
|
|
}
|
|
})
|
|
|
|
it('protocolPrefix is provided', async () => {
|
|
const testProtocol = 'test-protocol'
|
|
libp2p = await createLibp2pNode(mergeOptions(baseOptions, {
|
|
identify: {
|
|
protocolPrefix: testProtocol
|
|
},
|
|
ping: {
|
|
protocolPrefix: testProtocol
|
|
},
|
|
fetch: {
|
|
protocolPrefix: testProtocol
|
|
}
|
|
}))
|
|
await libp2p.start()
|
|
|
|
const protocols = await libp2p.peerStore.protoBook.get(libp2p.peerId)
|
|
expect(protocols).to.include.members([
|
|
`/${testProtocol}/fetch/0.0.1`,
|
|
'/libp2p/circuit/relay/0.1.0',
|
|
`/${testProtocol}/id/1.0.0`,
|
|
`/${testProtocol}/id/push/1.0.0`,
|
|
`/${testProtocol}/ping/1.0.0`
|
|
])
|
|
})
|
|
|
|
it('protocolPrefix is not provided', async () => {
|
|
libp2p = await createLibp2pNode(validateConfig(baseOptions))
|
|
await libp2p.start()
|
|
|
|
const protocols = await libp2p.peerStore.protoBook.get(libp2p.peerId)
|
|
expect(protocols).to.include.members([
|
|
'/libp2p/circuit/relay/0.1.0',
|
|
'/ipfs/id/1.0.0',
|
|
'/ipfs/id/push/1.0.0',
|
|
'/ipfs/ping/1.0.0',
|
|
'/libp2p/fetch/0.0.1'
|
|
])
|
|
})
|
|
})
|