Skip to content

Commit

Permalink
deps: update tcp (#1366)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain authored Sep 5, 2022
1 parent 0e7096d commit fc2224a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/peer-and-content-routing/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const createNode = async () => {
])

// Wait for onConnect handlers in the DHT
await delay(100)
await delay(1000)

const cid = CID.parse('QmTp9VkYvnHyrqKQuFPiuZkiX9gPcqj6x5LJ1rmWuSySnL')
await node1.contentRouting.provide(cid)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
"@libp2p/mdns": "^3.0.0",
"@libp2p/mplex": "^5.0.0",
"@libp2p/pubsub": "^3.0.1",
"@libp2p/tcp": "^3.0.0",
"@libp2p/tcp": "^3.0.5",
"@libp2p/topology": "^3.0.0",
"@libp2p/webrtc-star": "^3.0.0",
"@libp2p/websockets": "^3.0.0",
Expand Down
6 changes: 6 additions & 0 deletions src/circuit/auto-relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ export class AutoRelay {
}

const peerId = provider.id

if (peerId.equals(this.components.getPeerId())) {
// Skip the provider if it's us as dialing will fail
continue
}

await this.components.getPeerStore().addressBook.add(peerId, provider.multiaddrs)

await this._tryToListenOnRelay(peerId)
Expand Down
5 changes: 4 additions & 1 deletion src/connection-manager/dialer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ export class Dialer implements Startable, Initializable {
throw errCode(new Error('already aborted'), codes.ERR_ALREADY_ABORTED)
}

return await this.components.getTransportManager().dial(addr, options)
return await this.components.getTransportManager().dial(addr, options).catch(err => {
log.error('dial to %s failed', addr, err)
throw err
})
}

const dialRequest = new DialRequest({
Expand Down
13 changes: 10 additions & 3 deletions test/relay/auto-relay.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,10 @@ describe('auto-relay', () => {
})).to.eventually.be.rejected()

// Disconnect from peer used for relay
const disconnectPromise = pEvent(relayLibp2p1.connectionManager, 'peer:disconnect', { timeout: 500 })
await relayLibp2p2.stop()
await pEvent(relayLibp2p1.connectionManager, 'peer:disconnect', { timeout: 500 })
const event = await disconnectPromise
expect(event.detail.remotePeer.toString()).to.equal(relayLibp2p2.peerId.toString())

// Should not be using the relay any more
await expect(usingAsRelay(relayLibp2p1, relayLibp2p2, {
Expand Down Expand Up @@ -399,6 +401,7 @@ describe('auto-relay', () => {
nock('http://0.0.0.0:60197')
.post('/api/v0/dht/findprovs')
.query(true)
.twice()
.reply(200, `{"Extra":"","ID":"${provider}","Responses":[{"Addrs":${JSON.stringify(multiaddrs)},"ID":"${provider}"}],"Type":4}\n`, [
'Content-Type', 'application/json',
'X-Chunked-Output', '1'
Expand Down Expand Up @@ -432,10 +435,14 @@ describe('auto-relay', () => {
await local.hangUp(relayAddr)

// Should try to find relay service providers
await pWaitFor(() => contentRoutingFindProvidersSpy.callCount === 1)
await pWaitFor(() => contentRoutingFindProvidersSpy.callCount === 1, {
timeout: 1000
})

// Wait for peer added as listen relay
await pWaitFor(() => local.getMultiaddrs().length === originalMultiaddrsLength + 1)
await pWaitFor(() => local.getMultiaddrs().length === originalMultiaddrsLength + 1, {
timeout: 1000
})

const relayedAddr = local.getMultiaddrs()[local.getMultiaddrs().length - 1]
await remote.peerStore.addressBook.set(local.peerId, [relayedAddr])
Expand Down

0 comments on commit fc2224a

Please sign in to comment.