Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
476 changes: 260 additions & 216 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
[package]
name = "vortex-protocol"
version = "0.1.5"
version = "0.2.0"
description = "A P2P file transfer protocol"
authors = ["The Dragonfly Developers"]
homepage = "https://d7y.io/"
repository = "https://github.com/dragonflyoss/vortex.git"
repository = "https://github.com/dragonflyoss/vortex-protocol.git"
keywords = ["dragonfly", "p2p"]
license = "Apache-2.0"
readme = "README.md"
edition = "2021"
rust-version = "1.80"

[dependencies]
thiserror = "2.0"
rand = "0.8"
bytes = "1"
zerocopy = { version = "0.8", features = ["derive"] }
chrono = { version = "0.4.44", features = ["serde", "clock"] }

[dev-dependencies]
Expand Down
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,41 @@ efficient and flexible data transmission, making it ideal for large-scale file d
- **High Performance**: Designed for high-throughput file transfer scenarios.
- **Extensible Design**: Reserved tags for future protocol extensions like compression and encryption.

## Usage

Every TLV value implements `Message`, which encodes into any `BufMut` and decodes from a byte
slice. `encode_packet` prepends the packet header; `Vortex::decode` parses a whole packet.

```rust
use bytes::BytesMut;
use vortex_protocol::tlv::download_piece::DownloadPiece;
use vortex_protocol::{Message, Vortex, HEADER_SIZE};

let request = DownloadPiece::new("a".repeat(64), 1);
let mut buffer = BytesMut::with_capacity(HEADER_SIZE + request.encoded_len());
request.encode_packet(&mut buffer);

match Vortex::decode(&buffer)? {
Vortex::DownloadPiece(header, request) => println!("{} {:?}", header.length(), request),
packet => println!("unexpected packet {packet:?}"),
}
```

The wire format is stable across releases: peers running different versions of the crate
interoperate, and `tests/wire_format.rs` pins the bytes produced by earlier releases.

## Documentation

For details, please see [the specification](docs/README.md).

## Benchmarking

Vortex protocol includes comprehensive benchmarks for packet creation, serialization, and deserialization:
Vortex protocol includes benchmarks for encoding and decoding every message and whole packets:

```bash
# Run all benchmarks
cargo bench

# Run specific benchmark group
cargo bench "Vortex Packet Creation"
# Run the benchmarks of one message
cargo bench PieceContent
```
Loading
Loading