Sahib Yar
fa153c58dd
Co-authored-by: Sahib Yar <sahib.yar@securiti.ai> Co-authored-by: Marco Munizaga <marco@marcopolo.io> |
1 year ago | |
---|---|---|
.. | ||
pb | sync: update CI config files (#2073) | 2 years ago |
.gitignore | Add .gitignore for each example | 4 years ago |
AUTHORS | chore: bring examples back into repository | 4 years ago |
LICENSE | chore: bring examples back into repository | 4 years ago |
README.md | docs: Add a Github workflow for checking dead links (#2406) | 1 year ago |
echo.go | examples: update go-libp2p to v0.23.x (#1803) | 2 years ago |
main.go | sync: update CI config files (#2073) | 2 years ago |
main_test.go | chore: add tests for examples | 4 years ago |
node.go | docs: fix some comments (#2391) | 1 year ago |
ping.go | examples: fix flaky multipro TestMain (#2289) | 2 years ago |
README.md
Protocol Multiplexing using rpc-style protobufs with libp2p
This example shows how to use protobufs to encode and transmit information between libp2p hosts using libp2p Streams. This example expects that you are already familiar with the echo example.
Build
From the go-libp2p/examples
directory run the following:
> cd multipro/
> go build
Usage
> ./multipro
Details
The example creates two libp2p Hosts supporting 2 protocols: ping and echo.
Each protocol consists of RPC-style requests and responses and each request and response is a typed protobufs message (and a go data object).
This is a different pattern than defining a whole p2p protocol as one protobuf message with lots of optional fields (as can be observed in various p2p-lib protocols using protobufs such as dht).
The example shows how to match async received responses with their requests. This is useful when processing a response requires access to the request data.
The idea is to use libp2p protocol multiplexing on a per-message basis.
Features
- 2 fully implemented protocols using an RPC-like request-response pattern - Ping and Echo
- Scaffolding for quickly implementing new app-level versioned RPC-like protocols
- Full authentication of incoming message data by author (who might not be the message's sender peer)
- Base p2p format in protobufs with fields shared by all protocol messages
- Full access to request data when processing a response.