libp2p / rust-libp2p

The Rust Implementation of the libp2p networking stack.
https://libp2p.io
MIT License
4.29k stars 889 forks source link

Improve request/response documentation #5276

Open nazar-pc opened 3 months ago

nazar-pc commented 3 months ago

Request/response is a powerful primitive, but could use a better description regarding codec requirements.

I looked at example json and cbor implementations and looks like codec is single-use (I guess a new stream is used for each request/response).

Then I looked into why codec is required to be clonable assuming it can be reused for different streams, but turns out it is cloned every time, limiting reuse of previously allocated buffers (that both json and cbor allocated in read methods every time from scratch.

Would be great if someone with good knowledge of this protocol improved documentation about codec requirements and maybe improved reviewed code looking at efficiency improvements.

For now I'll just follow mentioned codecs as examples.

P.S. Would be great to see https://github.com/paritytech/parity-scale-codec support as well, I'm happy to send a PR if it is welcome.

jxs commented 3 months ago

Hi Nazar, thanks for opening this. Do you want to submit a PR improving the doc with the information you learned? Regarding https://github.com/paritytech/parity-scale-codec support, Codec is pub and therefore can be implemented by a third party lib right?

nazar-pc commented 3 months ago

Do you want to submit a PR improving the doc with the information you learned?

Those are my assumptions, I'm not sure they are 100% accurate.

therefore can be implemented by a third party lib right?

Absolutely, but there are two implementations already, so maybe more are welcome?

jxs commented 3 months ago

I'd prefer leaving third party implementations on separate repos where it's maintainers could update them without me having to review them, but I'd be more than happy to update the README.md to link for them, wdyt Nazar?

nazar-pc commented 3 months ago

Makes sense to me