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:
Vasco Santos
2019-11-26 16:40:04 +01:00
committed by Jacob Heun
parent f28b09fc0d
commit c563e06a60
10 changed files with 380 additions and 43 deletions

View File

@ -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])