README.md 1.79 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
10
11
Install gx:
```sh
> go get -u github.com/whyrusleeping/gx
12
13

```
Aviv Eyal's avatar
Aviv Eyal committed
14
15
16
17

Run GX from the root libp2p source dir: 
```sh
>gx install
18
19
```

Aviv Eyal's avatar
Aviv Eyal committed
20
21
22
23
24
Build libp2p:
```sh
> make deps
> make
```
25

Aviv Eyal's avatar
Aviv Eyal committed
26
Run from `multipro` directory
27

Aviv Eyal's avatar
Aviv Eyal committed
28
```sh
29
30
31
32
33
34
> go build
```


## Usage

Aviv Eyal's avatar
Aviv Eyal committed
35
```sh
36
37
38
39
40
41
> ./multipro

```

## Details

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

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

Aviv Eyal's avatar
Aviv Eyal committed
46
This is a different pattern then 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).
47

Aviv Eyal's avatar
Aviv Eyal committed
48
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.
49

Aviv Eyal's avatar
Aviv Eyal committed
50
51
52
53
54
55
56
57
58
The idea is to use lib-p2p protocol multiplexing on a per-message basis.

### Features
1. 2 fully implemented protocols using an RPC-like request-response pattern - Ping and Echo
2. Scaffolding for quickly implementing new app-level versioned RPC-like protocols
3. Full authentication of incoming message data by author (who might not be the message's sender peer)
4. Base p2p format in protobufs with fields shared by all protocol messages
5. Full access to request data when processing a response.

59
60
## Author
@avive
61

Aviv Eyal's avatar
Aviv Eyal committed
62