9 个版本 (5 个重大更改)

0.6.2 2024年6月26日
0.6.1 2024年6月20日
0.5.0 2024年5月24日
0.4.0 2024年5月23日
0.1.0 2023年4月4日

#95网络编程 中排名

Download history 178/week @ 2024-05-02 148/week @ 2024-05-09 259/week @ 2024-05-16 21601/week @ 2024-05-23 25272/week @ 2024-05-30 17795/week @ 2024-06-06 22046/week @ 2024-06-13 23693/week @ 2024-06-20 21494/week @ 2024-06-27 20607/week @ 2024-07-04 25594/week @ 2024-07-11 31232/week @ 2024-07-18 28862/week @ 2024-07-25 23229/week @ 2024-08-01 38391/week @ 2024-08-08 26716/week @ 2024-08-15

每月下载量123,685
用于 104 个Crate (3 个直接使用)

MIT 许可证

1.5MB
32K SLoC

litep2p

License Crates.io docs.rs

litep2p 是一个与 libp2p 兼容的 对等(P2P) 网络库

功能

  • 支持的协议
    • /ipfs/ping/1.0.0
    • /ipfs/identify/1.0.0
    • /ipfs/kad/1.0.0
    • /ipfs/bitswap/1.2.0
    • 多播DNS
    • 通知协议
    • 请求-响应协议
    • 创建自定义协议的API
  • 支持的传输
    • TCP
    • QUIC
    • WebRTC
    • WebSocket (WS + WSS)

使用方法

litep2p 在API设计上采用了不同的方法,因此不是 rust-libp2p 的直接替代品。以下是一个使用该库的示例

use futures::StreamExt;
use litep2p::{
    config::ConfigBuilder,
    protocol::{libp2p::ping, request_response::ConfigBuilder},
    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) =
        ConfigBuilder::new(ProtocolName::from("/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")],
        })
        .with_libp2p_ping(ping_config)
        .with_request_response_protocol(req_resp_config)
        .build();

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

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

有关如何使用库的更多详细信息,请参阅examples

复制

MIT许可证

依赖项

~29–46MB
~890K SLoC