@@ -0,1 +1,10 @@ | ||
## [0.30.2](https://github.com/libp2p/js-libp2p/compare/v0.30.1...v0.30.2) (2021-01-21) | ||
### Bug Fixes | ||
* store multiaddrs during content and peer routing queries ([#865](https://github.com/libp2p/js-libp2p/issues/865)) ([45c3367](https://github.com/libp2p/js-libp2p/commit/45c33675a7412c66d0fd4e113ef8506077b6f492)) | ||
## [0.30.1](https://github.com/libp2p/js-libp2p/compare/v0.30.0...v0.30.1) (2021-01-18) | ||
@@ -2,0 +11,0 @@ |
export = PeerRouting; | ||
/** | ||
* @typedef {import('peer-id')} PeerId | ||
* @typedef {import('multiaddr')} Multiaddr | ||
@@ -30,3 +29,3 @@ */ | ||
/** | ||
* Iterates over all peer routers in series to find the given peer. | ||
* Iterates over all peer routers in parallel to find the given peer. | ||
* | ||
@@ -38,6 +37,6 @@ * @param {PeerId} id - The id of the peer to find | ||
*/ | ||
findPeer(id: PeerId, options?: { | ||
findPeer(id: import("peer-id"), options?: { | ||
timeout?: number | undefined; | ||
} | undefined): Promise<{ | ||
id: PeerId; | ||
id: import("peer-id"); | ||
multiaddrs: Multiaddr[]; | ||
@@ -56,3 +55,3 @@ }>; | ||
} | undefined): AsyncIterable<{ | ||
id: PeerId; | ||
id: import("peer-id"); | ||
multiaddrs: Multiaddr[]; | ||
@@ -62,6 +61,5 @@ }>; | ||
declare namespace PeerRouting { | ||
export { PeerId, Multiaddr }; | ||
export { Multiaddr }; | ||
} | ||
type PeerId = import("peer-id"); | ||
type Multiaddr = import("multiaddr"); | ||
//# sourceMappingURL=peer-routing.d.ts.map |
{ | ||
"name": "libp2p", | ||
"version": "0.30.1", | ||
"version": "0.30.2", | ||
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack", | ||
@@ -68,6 +68,12 @@ "leadMaintainer": "Jacob Heun <jacobheun@gmail.com>", | ||
"it-buffer": "^0.1.2", | ||
"it-drain": "^1.0.3", | ||
"it-filter": "^1.0.1", | ||
"it-first": "^1.0.4", | ||
"it-handshake": "^1.0.1", | ||
"it-length-prefixed": "^3.0.1", | ||
"it-map": "^1.0.4", | ||
"it-merge": "1.0.0", | ||
"it-pipe": "^1.1.0", | ||
"it-protocol-buffers": "^0.2.0", | ||
"it-take": "1.0.0", | ||
"libp2p-crypto": "^0.18.0", | ||
@@ -154,7 +160,7 @@ "libp2p-interfaces": "^0.8.1", | ||
"Ryan Bell <ryan@piing.net>", | ||
"Samlior <samlior@foxmail.com>", | ||
"Thomas Eizinger <thomas@eizinger.io>", | ||
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>", | ||
"Didrik Nordström <didrik@betamos.se>", | ||
"Fei Liu <liu.feiwood@gmail.com>", | ||
"Ethan Lam <elmemphis2000@gmail.com>", | ||
"Irakli Gozalishvili <rfobic@gmail.com>", | ||
"Joel Gustafson <joelg@mit.edu>", | ||
@@ -167,3 +173,3 @@ "Julien Bouquillon <contact@revolunet.com>", | ||
"Diogo Silva <fsdiogo@gmail.com>", | ||
"Samlior <samlior@foxmail.com>", | ||
"isan_rivkin <isanrivkin@gmail.com>", | ||
"Smite Chow <xiaopengyou@live.com>", | ||
@@ -179,11 +185,11 @@ "Soeren <nikorpoulsen@gmail.com>", | ||
"Chris Bratlien <chrisbratlien@gmail.com>", | ||
"ebinks <elizabethjbinks@gmail.com>", | ||
"Florian-Merle <florian.david.merle@gmail.com>", | ||
"Francis Gulotta <wizard@roborooter.com>", | ||
"Felipe Martins <felipebrasil93@gmail.com>", | ||
"ebinks <elizabethjbinks@gmail.com>", | ||
"Henrique Dias <hacdias@gmail.com>", | ||
"Bernd Strehl <bernd.strehl@gmail.com>", | ||
"Henrique Dias <hacdias@gmail.com>", | ||
"isan_rivkin <isanrivkin@gmail.com>", | ||
"Irakli Gozalishvili <rfobic@gmail.com>" | ||
"Fei Liu <liu.feiwood@gmail.com>", | ||
"Ethan Lam <elmemphis2000@gmail.com>" | ||
] | ||
} |
@@ -163,3 +163,3 @@ 'use strict' | ||
await tasks | ||
await Promise.all(tasks) | ||
this.connections.clear() | ||
@@ -166,0 +166,0 @@ } |
@@ -8,5 +8,13 @@ 'use strict' | ||
const errCode = require('err-code') | ||
const { | ||
storeAddresses, | ||
uniquePeers, | ||
requirePeers | ||
} = require('./content-routing/utils') | ||
const all = require('it-all') | ||
const pAny = require('p-any') | ||
const merge = require('it-merge') | ||
const { pipe } = require('it-pipe') | ||
const first = require('it-first') | ||
const drain = require('it-drain') | ||
const filter = require('it-filter') | ||
const { | ||
@@ -16,5 +24,5 @@ setDelayedInterval, | ||
} = require('set-delayed-interval') | ||
const PeerId = require('peer-id') | ||
/** | ||
* @typedef {import('peer-id')} PeerId | ||
* @typedef {import('multiaddr')} Multiaddr | ||
@@ -32,5 +40,5 @@ */ | ||
// If we have the dht, make it first | ||
// If we have the dht, add it to the available peer routers | ||
if (libp2p._dht) { | ||
this._routers.unshift(libp2p._dht) | ||
this._routers.push(libp2p._dht) | ||
} | ||
@@ -61,5 +69,4 @@ | ||
try { | ||
for await (const { id, multiaddrs } of this.getClosestPeers(this._peerId.id)) { | ||
this._peerStore.addressBook.add(id, multiaddrs) | ||
} | ||
// nb getClosestPeers adds the addresses to the address book | ||
await drain(this.getClosestPeers(this._peerId.id)) | ||
} catch (err) { | ||
@@ -78,3 +85,3 @@ log.error(err) | ||
/** | ||
* Iterates over all peer routers in series to find the given peer. | ||
* Iterates over all peer routers in parallel to find the given peer. | ||
* | ||
@@ -91,12 +98,16 @@ * @param {PeerId} id - The id of the peer to find | ||
return pAny(this._routers.map(async (router) => { | ||
const result = await router.findPeer(id, options) | ||
const output = await pipe( | ||
merge( | ||
...this._routers.map(router => [router.findPeer(id, options)]) | ||
), | ||
(source) => filter(source, Boolean), | ||
(source) => storeAddresses(source, this._peerStore), | ||
(source) => first(source) | ||
) | ||
// If we don't have a result, we need to provide an error to keep trying | ||
if (!result || Object.keys(result).length === 0) { | ||
throw errCode(new Error('not found'), 'NOT_FOUND') | ||
} | ||
if (output) { | ||
return output | ||
} | ||
return result | ||
})) | ||
throw errCode(new Error('not found'), 'NOT_FOUND') | ||
} | ||
@@ -117,16 +128,10 @@ | ||
const result = await pAny( | ||
this._routers.map(async (router) => { | ||
const peers = await all(router.getClosestPeers(key, options)) | ||
if (!peers || !peers.length) { | ||
throw errCode(new Error('not found'), 'NOT_FOUND') | ||
} | ||
return peers | ||
}) | ||
yield * pipe( | ||
merge( | ||
...this._routers.map(router => router.getClosestPeers(key, options)) | ||
), | ||
(source) => storeAddresses(source, this._peerStore), | ||
(source) => uniquePeers(source), | ||
(source) => requirePeers(source) | ||
) | ||
for (const peer of result) { | ||
yield peer | ||
} | ||
} | ||
@@ -133,0 +138,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1234131
0.52%212
1.44%10913
1.28%48
14.29%