README.md 1.23 KB
Newer Older
1
2
3
4
5
6
7
8
# Protocol Multiplexing using rpc-style multicodecs, protobufs with libp2p

This examples shows how to use multicodecs (i.e. protobufs) to encode and transmit information between LibP2P hosts using LibP2P Streams.
Multicodecs present a common interface, making it very easy to swap the codec implementation if needed.
This example expects that you area already familiar with the [echo example](https://github.com/libp2p/go-libp2p/tree/master/examples/echo).

## Build

Aviv Eyal's avatar
Aviv Eyal committed
9
Compile the .proto files using the protobufs go compiler:
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

```
protoc --go_out=. ./p2p.proto
```


From `multipro` base source folder:

```
> go build
```


## Usage

```
> ./multipro

```

## Details

Aviv Eyal's avatar
Aviv Eyal committed
32
The example creates two LibP2P Hosts supporting 2 protocols: ping and echo.
33

Aviv Eyal's avatar
Aviv Eyal committed
34
Each protocol consists RPC-style requests and respones and each request and response is a typed protobufs message (and a go data object).
35

Aviv Eyal's avatar
Aviv Eyal committed
36
This is a different pattern then defining a whole p2p protocol as 1 protobuf message with lots of optional fields (as can be observed in various p2p-lib protocols using protobufs such as dht).
37

Aviv Eyal's avatar
Aviv Eyal committed
38
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.
39

40
41
42
## Author

@avive
43