-
Notifications
You must be signed in to change notification settings - Fork 60
Conversation
efece9f
to
0fc408a
Compare
0fc408a
to
89f85bf
Compare
"libp2p-mplex": "~0.8.5", | ||
"libp2p-switch": "~0.42.7", | ||
"libp2p-tcp": "~0.13.0", | ||
"it-pair": "^1.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will create an issue to track the removal of peer-book
for tests, as well as handle the peer-store
operations currently done here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async
can be removed from the dependencies now. And chai-checkmark
needs to be a dev dep.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we still use async/queue
for the query WorkerQueue
. I will create an issue to track that
@@ -100,10 +96,10 @@ describe('multiple nodes', () => { | |||
await dhts[4].put(key, Buffer.from('world4')) | |||
|
|||
const res = await Promise.all([ | |||
dhts[3].get(key, { maxTimeout: 2000 }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont't know as this was passing before.
It was getting stored locally world3
(after put), which was the first result obtained from getMany
. Then, we use the selector: () => 0
and the first record was obtained
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just left a couple of nits and suggestions
), | ||
lp.decode(), | ||
async source => { | ||
for await (const chunk of source) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it's worth adding a dependency just for this, but the streaming iterables library has some useful functions, eg this could be replaced with a map and a collect
src/rpc/index.js
Outdated
* @param {PeerInfo} peer | ||
* @param {Message} msg | ||
* @returns {Promise<Message>} | ||
* | ||
* @private | ||
*/ | ||
async function handleMessage (peer, msg) { | ||
async function handleMessage (peer, msg) { // eslint-disable-line | ||
// get handler & exectue it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// get handler & exectue it | |
// get handler & execute it |
@@ -11,6 +11,16 @@ const { Record } = require('libp2p-record') | |||
const PeerId = require('peer-id') | |||
const errcode = require('err-code') | |||
|
|||
exports.itFilter = function (predicate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using https://github.com/bustle/streaming-iterables#filter
"libp2p-mplex": "~0.8.5", | ||
"libp2p-switch": "~0.42.7", | ||
"libp2p-tcp": "~0.13.0", | ||
"it-pair": "^1.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async
can be removed from the dependencies now. And chai-checkmark
needs to be a dev dep.
src/network.js
Outdated
await this.dht._add(peer) | ||
this._log('added to the routing table: %s', peer.id.toB58String()) | ||
// Open a stream with the connected peer | ||
await conn.newStream(c.PROTOCOL_DHT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary now, correct? We previously dialed the protocol to check support, but we already have that information now. We're not performing an explicit action, so we shouldn't create a stream.
src/network.js
Outdated
@@ -151,10 +154,10 @@ class Network { | |||
* | |||
* @param {Connection} conn - the connection to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few places in the jsdocs that inaccurately reference Connection
. We should make sure these are duplex iterables.
test/query/index.spec.js
Outdated
_peerInfo: ourPeerInfo, | ||
_peerBook: new PeerBook() | ||
} | ||
_peerBook: peerStore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dialer._peerBook
and dialer._peerInfo
should be deleted, they're not properties of the dialer.
@@ -87,6 +87,7 @@ describe('rpc - handlers - GetValue', () => { | |||
|
|||
const msg = new Message(T, key, 0) | |||
|
|||
dht.peerStore.put(other) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did this need to get added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in the code we try to find the peer in the peer-store
. After this test we have another one for unkwown peers
data.push(chunk.slice()) | ||
} | ||
} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use collect
from streaming-iterables
I think this code can be simplified a bit (as well as some of the other places we are doing collects here. Also, there are multiple slices of the BufferList happening in this stream, it's not needed. You could also use the it-buffer
module and simplify all of this to be:
const data = await pipe(
[msg.serialize()],
lp.encode(),
collect
)
const duplexStream = {
source: data,
sink: async (source) => {
const res = await pipe(
source,
lp.decode(),
toBuffer, // Ensure we have buffers here for validateMessage to consume
collect
)
validateMessage(res)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yap, cool tip!
a10506e
to
5ad4af7
Compare
Co-Authored-By: dirkmc <dirkmdev@gmail.com> Co-Authored-By: Jacob Heun <jacobheun@gmail.com>
5ad4af7
to
44054b2
Compare
9ca9a2b
to
a0a8500
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good! 🚢 🚀
This PR aims to use
async iterators
instead ofpull-streams
in the context of the asyn migration, as a follow up for #148