#network #peer-to-peer

tentacle

Minimal implementation for a multiplexed p2p network framework

20 releases

0.3.8 Feb 23, 2021
0.3.3 Nov 4, 2020
0.3.0-alpha.5 Jun 18, 2020
0.3.0-alpha.2 Mar 30, 2020
0.2.0-alpha.1 Mar 14, 2019

#72 in Network programming

Download history 486/week @ 2020-11-14 381/week @ 2020-11-21 457/week @ 2020-11-28 406/week @ 2020-12-05 520/week @ 2020-12-12 462/week @ 2020-12-19 307/week @ 2020-12-26 536/week @ 2021-01-02 426/week @ 2021-01-09 173/week @ 2021-01-16 550/week @ 2021-01-23 248/week @ 2021-01-30 353/week @ 2021-02-06 247/week @ 2021-02-13 786/week @ 2021-02-20 453/week @ 2021-02-27

1,679 downloads per month
Used in 11 crates (5 directly)

MIT license

745KB
18K SLoC

Tentacle

Build Status image

Overview

This is a minimal implementation for a multiplexed p2p network based on yamux that supports mounting custom protocols.

Architecture

  1. Data stream transmission
+----+      +----------------+      +-----------+      +-------------+      +----------+      +------+
|user| <--> | custom streams | <--> |Yamux frame| <--> |Secure stream| <--> |TCP stream| <--> |remote|
+----+      +----------------+      +-----------+      +-------------+      +----------+      +------+
  1. Code implementation

All data is passed through the futures channel, yamux splits the actual tcp/websocket stream into multiple substreams, and the service layer wraps the yamux substream into a protocol stream.

Detailed introduction: 中文/English

Note: It is not compatible with libp2p.

Status

The API of this project is basically usable. However we still need more tests. PR is welcome.

The codes in the protocols/ directory are no longer maintained and only used as reference

Feature flatc is not recommended and will be removed in the next version.

Usage

From cargo

[dependencies]
tentacle = { version = "0.3", features = ["molc"] }

Example

  1. Clone
$ git clone https://github.com/nervosnetwork/tentacle.git
  1. On one terminal:

Listen on 127.0.0.1:1337

$ RUST_LOG=simple=info,tentacle=debug cargo run --example simple --features molc,ws -- server
  1. On another terminal:
$ RUST_LOG=simple=info,tentacle=debug cargo run --example simple --features molc
  1. Now you can see some data interaction information on the terminal.

You can see more detailed example in these three repos:

Run on browser and test

  1. setup a ws server:
$ cd tentacle && RUST_LOG=info cargo run --example simple --features molc,ws -- server
  1. setup a browser client
$ cd simple_wasm/www && wasm-pack build
$ npm install && npm run start

all wasm code generate from book

  1. Use a browser to visit http://localhost:8080/

  2. Now you can see the connection on the server workbench or on browser's console

Other Languages

Implementations in other languages

Why?

Because when I use rust-libp2p, I have encountered some difficult problems, and it is difficult to locate whether it is my problem or the library itself, it is better to implement one myself.

Dependencies

~4–8.5MB
~173K SLoC