11 releases (7 breaking)

new 0.8.0 Nov 4, 2024
0.7.0 Sep 5, 2024
0.6.2 Jun 26, 2024
0.5.0 May 24, 2024
0.1.0 Apr 4, 2023

#91 in Network programming

Download history 31232/week @ 2024-07-18 28862/week @ 2024-07-25 23229/week @ 2024-08-01 38391/week @ 2024-08-08 31946/week @ 2024-08-15 32292/week @ 2024-08-22 37665/week @ 2024-08-29 39506/week @ 2024-09-05 35868/week @ 2024-09-12 35937/week @ 2024-09-19 33475/week @ 2024-09-26 42292/week @ 2024-10-03 40965/week @ 2024-10-10 41712/week @ 2024-10-17 43889/week @ 2024-10-24 45817/week @ 2024-10-31

180,908 downloads per month
Used in 110 crates (3 directly)

MIT license

2MB
36K SLoC

litep2p

License Crates.io docs.rs

litep2p is a libp2p-compatible peer-to-peer (P2P) networking library

Features

  • Supported protocols:
    • /ipfs/ping/1.0.0
    • /ipfs/identify/1.0.0
    • /ipfs/kad/1.0.0
    • /ipfs/bitswap/1.2.0
    • Multicast DNS
    • Notification protocol
    • Request-response protocol
    • API for creating custom protocols
  • Supported transports:
    • TCP
    • QUIC
    • WebRTC
    • WebSocket (WS + WSS)

Usage

litep2p has taken a different approach with API design and as such is not a drop-in replacement for rust-libp2p. Below is a sample usage of the library:

use futures::StreamExt;
use litep2p::{
    config::ConfigBuilder,
    protocol::{libp2p::ping, request_response::ConfigBuilder as RequestResponseConfigBuilder},
    transport::{quic::config::Config as QuicConfig, tcp::config::Config as TcpConfig},
    Litep2p, ProtocolName,
};

// simple example which enables `/ipfs/ping/1.0.0` and `/request/1` protocols
// and TCP and QUIC transports and starts polling events
#[tokio::main]
async fn main() {
    // enable IPFS PING protocol
    let (ping_config, mut ping_event_stream) = ping::Config::default();

    // enable `/request/1` request-response protocol
    let (req_resp_config, mut req_resp_handle) =
        RequestResponseConfigBuilder::new(ProtocolName::Static("/request/1"))
            .with_max_size(1024)
            .build();

    // build `Litep2pConfig` object
    let config = ConfigBuilder::new()
        .with_tcp(TcpConfig {
            listen_addresses: vec![
                "/ip6/::1/tcp/0".parse().expect("valid address"),
                "/ip4/127.0.0.1/tcp/0".parse().expect("valid address"),
            ],
            ..Default::default()
        })
        .with_quic(QuicConfig {
            listen_addresses: vec!["/ip4/127.0.0.1/udp/0/quic-v1"
                .parse()
                .expect("valid address")],
            ..Default::default()
        })
        .with_libp2p_ping(ping_config)
        .with_request_response_protocol(req_resp_config)
        .build();

    // build `Litep2p` object
    let mut litep2p = Litep2p::new(config).unwrap();

    loop {
        tokio::select! {
            _event = litep2p.next_event() => {},
            _event = req_resp_handle.next() => {},
            _event = ping_event_stream.next() => {},
        }
    }
}

Seeexamples for more details on how to use the library

Copying

MIT license

Dependencies

~25–41MB
~751K SLoC