A multiplexed p2p network framework that supports custom protocols

Overview

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

Usage

From cargo

[dependencies]
tentacle = { version = "0.4.0-beta.1" }

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 ws -- server
  1. On another terminal:
$ RUST_LOG=simple=info,tentacle=debug cargo run --example simple
  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 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.

Comments
  • Reinstate original copyright

    Reinstate original copyright

    This code is a fork of rust-libp2p but this is not mentioned anywhere (which is required by the license). Can you please put back the original copyright notice?

    opened by dvdplm 6
  • wrong module name in yamux example?

    wrong module name in yamux example?

    i encounter a error when running yamux example

    https://github.com/driftluo/p2p/blob/a3fa13b15ab0350e624ee900639b758de4175f64/yamux/examples/simple.rs#L11

    then i change yamux to tokio_yamux to run this example successfully

    use tokio_yamux::{config::Config, session::Session, stream::StreamHandle};
    
    opened by b1tg 2
  • build error

    build error

    `error: Please choose a serialization format via feature. Possible choices: flatc, molc --> secio/src/handshake/mod.rs:13:1 | 13 | compile_error!("Please choose a serialization format via feature. Possible choices: flatc, molc"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    error[E0599]: no method named encode found for struct handshake::handshake_struct::Exchange in the current scope --> secio/src/handshake/procedure.rs:120:37 | 120 | let local_exchanges = exchanges.encode(); | ^^^^^^ method not found in handshake::handshake_struct::Exchange | ::: secio/src/handshake/handshake_struct.rs:139:1 | 139 | pub struct Exchange { | ------------------- method encode not found for this | = help: items from traits can only be used if the trait is implemented and in scope = note: the following traits define an item encode, perhaps you need to implement one of them: candidate #1: tokio_util::codec::encoder::Encoder candidate #2: ring::rsa::padding::RsaEncoding

    error[E0599]: no function or associated item named decode found for struct handshake::handshake_struct::Exchange in the current scope --> secio/src/handshake/procedure.rs:137:44 | 137 | let remote_exchanges = match Exchange::decode(&raw_exchanges) { | ^^^^^^ function or associated item not found in handshake::handshake_struct::Exchange | ::: secio/src/handshake/handshake_struct.rs:139:1 | 139 | pub struct Exchange { | ------------------- function or associated item decode not found for this | = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item decode, perhaps you need to implement it: candidate #1: tokio_util::codec::decoder::Decoder

    error: aborting due to 3 previous errors

    For more information about this error, try rustc --explain E0599. error: could not compile tentacle-secio.

    To learn more, run the command again with --verbose. warning: build failed, waiting for other jobs to finish... error: build failed `

    opened by yingnierxiao 1
  • Run example  error

    Run example error

    After clone the repo, Run the example:

    RUST_LOG=simple=info,p2p=debug cargo run --example simple -- server
    

    and get the following compile error:

    error: failed to parse manifest at `/Volumes/x/gettingStart/rust/p2p/Cargo.toml`
    
    Caused by:
      editions are unstable
    
    Caused by:
      feature `edition` is required
    
    consider adding `cargo-features = ["edition"]` to the manifest
    

    Is better to have a rust-toolchain file?

    opened by leeyr338 1
  • fix: resolve cpu load issue of prepare_uninitialized_buffer

    fix: resolve cpu load issue of prepare_uninitialized_buffer

    After doing some basic profiling, I found that a lot of CPU was spent on memset, and traced the code to find that it was caused by not implementing the prepare_uninitialized_buffer method

    below is the bench result comparison

    After counting 10 cycles, estimated total time spent on task "10mb_benchmark_with_secio" is 3.0800651s
    task name: 10mb_benchmark_with_secio
    cycles: 100
    total cost: 3.019923503s
    average: 30.199235ms
    median: 30.015518ms
    max: 42.400898ms
    min: 28.272243ms
    

    v.s

    After counting 10 cycles, estimated total time spent on task "10mb_benchmark_with_secio" is 1.707217s
    task name: 10mb_benchmark_with_secio
    cycles: 100
    total cost: 1.75304821s
    average: 17.530482ms
    median: 17.24187ms
    max: 35.465816ms
    min: 16.76556ms
    
    opened by quake 0
  • sec-io refactored

    sec-io refactored

    1. SecureStream supports AsyncRead/AsyncWrite directly
    2. As a result, StreamHandle no longer needed, and channle and messages all removed
    3. sec-io is now message oriented, Read/Write will operate on the entire frame
    4. Read takes a bit more work when the frame is too big for the input buffer. Have to make an internal recv_buffer for holding the remained frame body
    opened by kingwel-xie 0
  • Run example  error

    Run example error

    After clone the repo, Run the example:

    RUST_LOG=simple=info,p2p=debug cargo run --example simple -- server
    

    and get the following compile error:

    error: failed to parse manifest at `/Volumes/x/gettingStart/rust/p2p/Cargo.toml`
    
    Caused by:
      editions are unstable
    
    Caused by:
      feature `edition` is required
    
    consider adding `cargo-features = ["edition"]` to the manifest
    

    Is better to have a rust-toolchain file?

    opened by leeyr338 0
Releases(0.2.0-alpha.2)
  • 0.2.0-alpha.2(Apr 15, 2019)

    1. Change a lot of APIs
    2. Abstract transport layer #76
    3. Fix session close, substream close bug(Fix CPU abnormal occupation when the task is heavy) #88 #92 #93
    4. Add flatbuffer decode verification #84 #89
    5. Support service shutdown #105
    6. Support users to customize the version select procedure #97
    7. Replace task channel to unbound #94
    Source code(tar.gz)
    Source code(zip)
  • 0.2.0-alpha.1(Mar 14, 2019)

    • The 0.1 version has an error not reported to the user #54
    • There is a type of error using #54
    • Lack of defense against fd attacks, need a timeout error #54 #57
    • Some users want to be able to support event stream output instead of callback,0.2 should support both programming modes at the same time #58
    • Let user control turn protocol on and off, breaking change #62
    • May need to support each protocol has their own codec, and does not require the same structure(trait object) #63
    • Add poll API to all protocol handle, to allow users to customize some stream tasks in the handle #65
    Source code(tar.gz)
    Source code(zip)
Custom p2p swaps powered by Solana blockchain

Peer to peer, decentralized protocol which allow direct swaps between 2 network participants for custom tokens without liquidity pools on Solana blockchain.

Ilia 3 Mar 18, 2022
The Zenotta Network Protocol (ZNP), the network that supports the Zenotta blockchain

Zenotta Network Protocol A repo for the development of the Zenotta Network Protocol (ZNP). We will regularly be updating links and easter eggs inside

Zenotta AG 10 Apr 2, 2023
Retina is a network analysis framework that supports 100+ Gbps traffic analysis on a single server with no specialized hardware.

Retina Retina is a network analysis framework that enables operators and researchers to ask complex questions about high-speed (>100gbE) network links

Stanford Security Research 73 Jun 21, 2023
P2P Network to verify authorship & ownership, store & deliver proofs.

Anagolay Network Node Anagolay is a next-generation framework for ownerships, copyrights and digital licenses. ?? Local Development The installation a

Anagolay Network 5 May 30, 2022
Low-level Bitcoin P2P Network Client

Peerlink What is Peerlink? Peerlink is a low-level network client for the Bitcoin P2P network written in Rust. It uses a nonblocking reactor to accept

Alfred Hodler 6 Dec 23, 2022
A monorepo containing all the custom components of the Astria network

A monorepo containing all the custom components of the Astria network, a decentralized system that replaces traditional sequencers, offering a shared, permissionless sequencer network.

Astria 6 Jun 7, 2023
Password-Authenticated Key Agreement protocols

RustCrypto: PAKEs Password-Authenticated Key Agreement protocols implementation. Warnings Crates in this repository have not yet received any formal c

Rust Crypto 81 Dec 5, 2022
Rust implementation of the i2p client/server/router protocols

ri2p Rust implementation of the i2p client/server/router protocols Status Common Commands cargo build: Builds the ri2p binary cargo run: Runs the ri2p

Christopher Bilger 8 Nov 25, 2022
An implementation of the paper "Honey Badger of BFT Protocols" in Rust. This is a modular library of consensus.

Honey Badger Byzantine Fault Tolerant (BFT) consensus algorithm Welcome to a Rust library of the Honey Badger Byzantine Fault Tolerant (BFT) consensus

null 335 Dec 25, 2022
Two-party and multi-party ECDSA protocols based on class group with Rust

CG-MPC-ECDSA This project aims to implement two-party and multi-party ECDSA protocols based on class group with Rust. It currently includes schemes de

LatticeX Foundation 16 Mar 17, 2022
Lockstitch is an incremental, stateful cryptographic primitive for symmetric-key cryptographic operations in complex protocols.

Lockstitch is an incremental, stateful cryptographic primitive for symmetric-key cryptographic operations (e.g. hashing, encryption, message authentication codes, and authenticated encryption) in complex protocols.

Coda Hale 3 Dec 27, 2022
Proteus: Programmable Protocols for Censorship Circumvention

Proteus Debug build (also used for tests): cargo build Release build (optimized): cargo build --release Run unit tests: cargo test Run integration

null 5 Jul 11, 2023
A Rust implementation of the ISO11783 (ISOBUS) & J1939 protocols

AgIsoStack-rs About This Library AgIsoStack-rs is an MIT licensed hardware agnostic ISOBUS (ISO11783) and SAE J1939 CAN stack written in Rust. This pr

null 7 Aug 7, 2023
Open Protocol Indexer, OPI, is the best-in-slot open-source indexing client for meta-protocols on Bitcoin.

OPI - Open Protocol Indexer Open Protocol Indexer, OPI, is the best-in-slot open-source indexing client for meta-protocols on Bitcoin. OPI uses a fork

Best in Slot 33 Dec 16, 2023
A fully p2p cli chat utility written in rust.

P2P Chat Client This is a simple demonstration of a peer to peer chat client, written entirely in rust utilising the libp2p library. Demo On two seper

Josiah Bull 7 Dec 17, 2022
NAT Traversal techniques for p2p communication

P2P NAT-Traversal Crate Documentation Linux/OSX/Windows The goal of this crate is to provide a robust and crypto-secure NAT traversal for peer to peer

Spandan Sharma 123 Dec 24, 2022
Open source p2p share for devs to share anything with teammates across machines securely.

Secure share Share anything with teammates across machines via CLI. Share is a tool for secure peer-to-peer connections, enabling direct communication

Onboardbase 10 Aug 4, 2023
Ethereum (and Ethereum like) indexer using P2P message to fetch blocks and transactions

Ethereum P2P indexer This project is an indexer for Ethereum and Ethereum forks. It takes advantage of the ETH (Ethereum Wire Protocol) to fetch block

null 5 Nov 10, 2023
Cross-chain bridge message delivery network. We are hiring, [email protected]

Introduction Implementation of a https://darwinia.network node in Rust based on the Substrate framework. This repository contains runtimes for the Dar

Darwinia Network 225 Nov 8, 2022