Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nanne007/naive_p2p
https://github.com/nanne007/naive_p2p
p2p rust
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/nanne007/naive_p2p
- Owner: nanne007
- Created: 2019-08-30T00:49:32.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-02T01:59:14.000Z (over 4 years ago)
- Last Synced: 2023-07-13T19:50:50.372Z (over 1 year ago)
- Topics: p2p, rust
- Language: Rust
- Size: 36.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### native p2p
#### solve
1. 客户端通过HTTP协议随机给节点发包
2. 节点对消息按ID进行排序,并计算Hash,节点hash结果应跟客户端一致,多个节点的Hash应该一致
3. 节点支持随时重启功能,可以kill任一节点并重启,hash结果应该保持和测试端一致
4. 节点支持基本的P2P功能,包括节点发现,消息路由
5. 可以使用rust blocking io/mio/tokio 包括不稳定特性如async/await等实现
6. 客户端代码在 https://github.com/fanngyuan/performance-client ,客户端发的每条消息都做了Base64,URL encoding,使用sha256.Sum256计算hash### Give a try
开多个 shell,依次执行:
```shell script
./target/debug/naive_p2p --config configs/tom.toml
``````shell script
./target/debug/naive_p2p --config configs/alice.toml
``````shell script
./target/debug/naive_p2p --config configs/bob.toml
```用 `https://github.com/fanngyuan/performance-client` 写入数据:
```shell script
./client -times 1000 -url http://localhost:8080,http://localhost:8081,http://localhost:8082
```client 给出 hash:`ee3d211f26b3b3d3468d269b9cc57209ff3276952622bca5bd5aa2aaa5fdc27a`
查看 p2p node 的hash:
- tom: `http :8080/state`
- alice: `http :8081/state`
- bob: `http :8082/state`### How it work
#### peer discovery
1. new peer 广播
2. node 定时的 去 random outbound peer 拿它的 random inbound peer。#### block sync
1. new block broadcast
2. 节点之间通过 hearbeat 同步 lastest block index,如果发现自己落后,就主动去同步数据。#### block storage
内存实现。节点重启,数据丢失,重新从 bootnodes 去 sync。
### 存在的问题
- [ ] 限制 节点的 inbound/outbound 连接数。
- [ ] 更高效的 block sync 协议。
- [ ] 更高效的 peer discovery 方法。
- [ ] block 落盘到 rocksdb。