Skip to content

Commit

Permalink
WIP: Move over to raw-uring (#18)
Browse files Browse the repository at this point in the history
* wip

* hello world

* working writes

* something working

* its's workgin!

* Multi recv

* Experiment with timeouts

* Working timeout

* Working mmap files

* Parsing and encoding peer messages

* rename decoder module

* some refactors

* wip

* First comms with container

First communication with container

* Break out loop to different module

* wip

* ensure buffers are always returned

* Fix incorrect user data

* Refactor eventloop code

* add piece selector

* Add piece structs

* Prevent encoding from taking ownership of buffer

* Update buffer pool api and add torrent state

* Continue filling in peer connection

* Update piece selector and torret state

* Update eventloop

* More peer id to protocol

* update examples

* allow specifying order

* Sync more often

* fix buffer length bugs

* Add filestore

* Move over on piece completeted from old impl

* Add moving average

* Fix filestore bug and remove default impl

* Refactor peer connection a bit

* Handle ENOBUFS for connected writes

* Add timeout support

* Change order and only mark compelete once

* Track stats for peer connection

* Implement tick

* Always use coop taskrun

* Add event backlog to deal with full submission queues

* fmt and tweak slab size

* Make tick take torrentstate

* Return from eventloop when torrent is complete

* time download in example

* wip timeout

* wip working

* Fix example

* Remember to unregister read ring

* misc

* Fix logs and clamp desired queue size

* Fix bug in deciding not to end slow start

* Fix desired queue size calculation

* move connect to

* Don't return torrent complete in event handler

* replace old impl

* comment out not working impl

* fix examples

* re add licence

---------

Co-authored-by: Nehliin <>
  • Loading branch information
Nehliin authored Dec 28, 2024
1 parent eaa3abc commit 5a93206
Show file tree
Hide file tree
Showing 25 changed files with 2,208 additions and 29,679 deletions.
305 changes: 246 additions & 59 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 11 additions & 13 deletions bittorrent/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
[package]
name = "vortex-bittorrent"
version = "0.1.0"
authors = ["Oskar Nehlin"]
edition = "2021"
description = "An implementation of the bittorrent protocol built on top of io-uring"
homepage = "https://github.com/Nehliin/vortex"
repository = "https://github.com/Nehliin/vortex"
license = "BSD-3-Clause"


[dependencies]
bytes = { workspace = true }
tokio-uring = { workspace = true }
tokio-util = "0.7.4"
anyhow = { workspace = true }
log = { workspace = true }
lava_torrent = "0.10"
slotmap = "1"
parking_lot = { workspace = true }
io-uring = "0.7"
libc = "0.2"
slab = "0.4"
bytes = "1.8"
bitvec = { version = "1.0", default-features = false, features = ["alloc"]}
sha1 = "0.10.5"
tokio = { workspace = true, features = ["time", "sync", "macros"] }
rand = { workspace = true }
arbitrary = { version = "1.1.3", features = ["derive"]}
log = "0.4"
socket2 = "0.5"
rand = "0.8"
lava_torrent = "0.11"
thiserror = "2"
sha1 = "0.10.5"

[dev-dependencies]
env_logger = { workspace = true }
rand = { workspace = true }
24 changes: 24 additions & 0 deletions bittorrent/examples/basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::{io::Write, net::TcpStream};

use vortex_bittorrent::setup_listener;

fn main() {
env_logger::builder()
.filter_level(log::LevelFilter::Debug)
// .target(env_logger::Target::Pipe(Box::new(log_file)))
.init();
let handle = std::thread::spawn(|| {
//setup_listener();
});
std::thread::sleep_ms(500);
let mut stream = TcpStream::connect("127.0.0.1:3456").unwrap();
stream.write_all(b"Hello from stream!!").unwrap();
std::thread::sleep_ms(500);
stream.write_all(b"HERE AGAIN!!").unwrap();
stream.write_all(b"WOOOO").unwrap();
// 36 + 10 * 300
for _ in 0..300 {
stream.write_all(b"SOMETHING\n").unwrap();
}
handle.join().unwrap();
}
33 changes: 33 additions & 0 deletions bittorrent/examples/connect.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use std::{
io::Write,
net::{TcpListener, TcpStream},
time::Instant,
};

use vortex_bittorrent::{connect_to, TorrentState};

fn main() {
env_logger::builder()
.filter_level(log::LevelFilter::Info)
// .target(env_logger::Target::Pipe(Box::new(log_file)))
.init();
let torrent = lava_torrent::torrent::v1::Torrent::read_from_file(
"bittorrent/assets/test-file-1.torrent",
)
.unwrap();
let torrent = TorrentState::new(torrent);
//let handle = std::thread::spawn(|| {
// let listener = TcpListener::bind("127.0.0.1:3456").unwrap();
// let (stream, _) = listener.accept().unwrap();
//});
//std::net::TcpStream::connect("172.17.0.2:51413").unwrap();

let download_time = Instant::now();
connect_to("172.17.0.2:51413".parse().unwrap(), torrent);
let elapsed = download_time.elapsed();
log::info!("Download complete in: {}s", elapsed.as_secs());
let expected = std::fs::read("bittorrent/assets/test-file-1").unwrap();
let actual = std::fs::read("bittorrent/downloaded/test-file-1").unwrap();
assert_eq!(actual, expected);
//handle.join().unwrap();
}
41 changes: 0 additions & 41 deletions bittorrent/examples/download.rs

This file was deleted.

Loading

0 comments on commit 5a93206

Please sign in to comment.