1个不稳定版本
0.1.13 | 2022年2月17日 |
---|---|
0.1.12 |
|
0.1.2 |
|
#45 在 #对等网络
32 每月下载量
87KB
2K SLoC
Libp2p-episub: 基于libp2p的近邻感知爆发式PubSub
这个Rust库实现了基于以下学术论文思想的libp2p行为,以实现高效的大规模pub/sub协议:
- HyParView:用于主题-节点成员管理和节点发现
- 爆发式广播树:用于构建高效的广播树和高效的内容分发
- GoCast:用于快速和可靠的组通信的Gossip增强覆盖多播
最初由@vyzo在Gossipsub之后作为继任者制定规范。
运行包含201个节点的拓扑
$ docker-compose up --scale node_n=200 --remove-orphans
测试和可视化p2p网络
首先启动审计节点,并在80端口上在浏览器中打开它,你应该看到一个空的P2P协议实验室页面。
$ docker-compose up -d node_audit
然后启动引导节点
$ docker-compose up -d node_0
你应该立即在实验室页面上看到它,然后启动50个节点,并观察网络自我发现。
$ docker-compose up --scale node_n=50
使用示例
let local_key = identity::Keypair::generate_ed25519();
let local_peer_id = PeerId::from(local_key.public());
let transport = libp2p::development_transport(local_key.clone()).await?;
// Create a Swarm to manage peers and events
let mut swarm = libp2p::Swarm::new(transport, Episub::new(), local_peer_id);
// Listen on all interfaces and whatever port the OS assigns
swarm
.listen_on("/ip4/0.0.0.0/tcp/4001".parse().unwrap())
.unwrap();
// subscribe to the topic specified on the command line
swarm.behaviour_mut().subscribe(opts.topic);
swarm.dial(bootstrap).unwrap()
while let Some(event) = swarm.next().await {
match event {
SwarmEvent::Behaviour(EpisubEvent::Message(m, t)) => {
println!("got a message: {:?} on topic {}", m, t);
}
SwarmEvent::Behaviour(EpisubEvent::Subscribed(t)) => {}
SwarmEvent::Behaviour(EpisubEvent::Unsubscribed(t)) => {}
SwarmEvent::Behaviour(EpisubEvent::ActivePeerAdded(p)) => {}
SwarmEvent::Behaviour(EpisubEvent::ActivePeerRemoved(p)) => {}
}
}
依赖关系
~10–15MB
~314K SLoC