mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-15 18:21:22 +00:00
refactor: dht async/await (#480)
* refactor: core async (#478) * refactor: cleanup core test: auto dial on startup * fix: make hangup work properly * chore: fix lint * chore: apply suggestions from code review Co-Authored-By: Vasco Santos <vasco.santos@moxy.studio> * fix: provide libp2p dialer to the dht * chore: use dht release
This commit is contained in:
@ -17,6 +17,7 @@ const pipe = require('it-pipe')
|
||||
|
||||
const Libp2p = require('../../src')
|
||||
const Dialer = require('../../src/dialer')
|
||||
const PeerStore = require('../../src/peer-store')
|
||||
const TransportManager = require('../../src/transport-manager')
|
||||
const { codes: ErrorCodes } = require('../../src/errors')
|
||||
const Protector = require('../../src/pnet')
|
||||
@ -86,7 +87,7 @@ describe('Dialing (direct, TCP)', () => {
|
||||
expect.fail('Dial should have failed')
|
||||
})
|
||||
|
||||
it('should be able to connect to a given peer', async () => {
|
||||
it('should be able to connect to a given peer info', async () => {
|
||||
const dialer = new Dialer({ transportManager: localTM })
|
||||
const peerId = await PeerId.createFromJSON(Peers[0])
|
||||
const peerInfo = new PeerInfo(peerId)
|
||||
@ -97,6 +98,23 @@ describe('Dialing (direct, TCP)', () => {
|
||||
await connection.close()
|
||||
})
|
||||
|
||||
it('should be able to connect to a given peer id', async () => {
|
||||
const peerStore = new PeerStore()
|
||||
const dialer = new Dialer({
|
||||
transportManager: localTM,
|
||||
peerStore
|
||||
})
|
||||
|
||||
const peerId = await PeerId.createFromJSON(Peers[0])
|
||||
const peerInfo = new PeerInfo(peerId)
|
||||
peerInfo.multiaddrs.add(remoteAddr)
|
||||
peerStore.put(peerInfo)
|
||||
|
||||
const connection = await dialer.connectToPeer(peerId)
|
||||
expect(connection).to.exist()
|
||||
await connection.close()
|
||||
})
|
||||
|
||||
it('should fail to connect to a given peer with unsupported addresses', async () => {
|
||||
const dialer = new Dialer({ transportManager: localTM })
|
||||
const peerId = await PeerId.createFromJSON(Peers[0])
|
||||
|
Reference in New Issue
Block a user