File: README.md

package info (click to toggle)
rust-libp2p-identity 0.2.10%2B20250205%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 804 kB
  • sloc: makefile: 8; sh: 1
file content (35 lines) | stat: -rw-r--r-- 1,069 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
## Description

This example shows the usage of the `stream::Behaviour`.
As a counter-part to the `request_response::Behaviour`, the `stream::Behaviour` allows users to write stream-oriented protocols whilst having minimal interaction with the `Swarm`.

In this showcase, we implement an echo protocol: All incoming data is echoed back to the dialer, until the stream is closed.

## Usage

To run the example, follow these steps:

1. Start an instance of the example in one terminal:

   ```sh
   cargo run --bin stream-example
   ```

   Observe printed listen address.

2. Start another instance in a new terminal, providing the listen address of the first one.

   ```sh
   cargo run --bin stream-example -- <address>
   ```

3. Both terminals should now continuously print messages. 

## Conclusion

The `stream::Behaviour` is an "escape-hatch" from the way typical rust-libp2p protocols are written.
It is suitable for several scenarios including:

- prototyping of new protocols
- experimentation with rust-libp2p
- integration in `async/await`-heavy applications