-
Notifications
You must be signed in to change notification settings - Fork 281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
review Wire protocol section from the relay spec #18
Conversation
|
||
Events: | ||
- phase I: Open a request for a relayed stream (A to R) | ||
- A dials a new stream `sAR` to R using protocol `/libp2p/relay/hop` |
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.
It's /libp2p/relay/circuit/1.0.0/hop
- A writes Bs multiaddr `/p2p/QmB` on `sAR` | ||
- R receives stream `sAR` and reads `/p2p/QmB` from it. | ||
- phase II: Open a stream to be relayed (R to B) | ||
- R opens a new stream `sRB` to B using protocol `/libp2p/relay/stop` |
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.
Same here /libp2p/relay/circuit/1.0.0/stop
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.
And a couple more of the same throughout the rest of the doc
#### Function definitions | ||
##### Process for reading a multiaddr | ||
We define `readLpMaddr` to be the following: | ||
Read a Uvarint `V` from the stream. If the value is higher than `maxAddrLen`, writes an error code back, closes the stream and halts the relay attempt. If not, then reads `V` bytes from the stream and checks if its a valid multiaddr. Check for multiaddr validity and error back if not a valid formated multiaddr. |
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 line should be indented as a sub-item of the previous list item
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 the definition of that function. I can change how that is communicated.
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.
Just trying to save space :)
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.
Thanks! Just a few
Peer R checks to make sure that `<src>` matches the remote peer of the stream its reading | ||
from. If it does not match, it (writes an error back?) closes the stream and halts the relay attempt. | ||
|
||
Peer R checks to make sure that `<src>` matches the remote peer of the stream its reading from. If it does not match, it writes an Error message, closes the stream and halts the relay attempt. |
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.
typo its/it's
``` | ||
<uvarint len(maddrA)><madddrA><uvarint len(maddrB)><madddrB> | ||
``` | ||
|
||
After this, R simply pipes the stream from A and the stream it opened to B together. R's job is complete. | ||
After this, R pipes the stream from A and the stream it opened to B together. R also writes OK back to A. R's job is complete. |
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.
Maybe worth noting that R's job actually continues: it now needs to keep the connections alive
|
||
### 'stop' protocol handler | ||
Peer B receives a new stream on the '/libp2p/relay/stop' protocol. It then calls `readLpMaddr` twice on this stream. |
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.
Writing both the <src>
and <dst>
seems a bit redundant here. What is the use case for sending the <dst>
as well?
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.
Other than that LGTM! 👍
Thanks for the review @lgierth @dryajov <3 There is just one thing that is itching me, the fact that we are mixing a protocol codec with an RPC method name on having If we want to say that we have the I also don't understand the resistance to use a serializable data format like protobuf or cbor this time, we use it everywhere already (see Identify, Bitswap, DHT, and others) and it gives a nice feature that we can add more information later without having to do complicated retro compatibility tests to make sure all the bytes are read in the same order and what not. Using a protobuf this time would give us the ability to just specify the type of message (hop, stop) on the message itself. |
For the sake of playing the devils advocate, what is the danger of using multistream select as an RPC mechanism (note, I'm neither proposing nor condemning that use case). Also, how placing the semver at the end would prevent that - the current syntax maps nicely to a sub protocol in my mind, which is accurate in this case.
I would love to hear the reasoning behind this also, the only thing that comes to mind is that the amount of structured data exchanged between peers is minimal, and going with a text based protocol saves the additional dependencies, complexity and overhead that cbor/protobuf introduce? |
multistream-select has a cost:
protobuf RPC exist to reduce complexity and we already know that things change over time really well, that is why we have a whole project just for self-describable data formats :) |
I'd be down for us reworking this part -- I kinda agree that the changes to multistream-select would be non-trivial and likely risky, while the neccessity for them isn't very strong. I'd also be down to at the very least put a multicodec-packed header in front of the header. (Good call.) // edit: multicodec-packed header |
What do you mean by this:
|
Similar to how there's a multicodec-packed header in a CID to describe the following hash, we'd put one in front of the relay header to describe what follows. For now this would just be the multicodec code for multiaddr (0x32), but being able to switch this over to e.g. the cbor code, would make the header more future-proof. |
@lgierth ah, makes sense. Thanks! |
Re: RPC I think we need to make a decision here to move circuit forward. Lets time box this, how about we decide by next @lgierth what are your thoughts on this, I gather that you tend to agree with what @diasdavid is proposing. I'm on board with reworking the RPC calls with a proper, binary packed format instead. Next question is, what format should we use - Lets put this to a vote. Vote 👍 or 👎 on this issue to reimplement or leave it as is. Use the links bellow to 👍 or 👎 CBOR vs Protobufs. |
Vote:
|
Vote:
|
i prefer protobufs here, pretty much just because they will be much smaller |
I'm also in favor to use protobufs. It has suited well our needs and as @whyrusleeping points out, they are smaller. |
Looks like we're rewriting the protocol with protobufs - If there are no objections I'll start working on this ASAP. |
@lgierth @diasdavid @whyrusleeping I though I put something together for the actual protobuf message to get the ball rolling. This is merely to start the discussion, i haven't implemented anything around this yet.
|
Reviewed the wire protocol section. There were some incoherences in the high-level order of events and some question marks everywhere, I fixed them based on commons and our conversations.