Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement incoming side of FAST_EXT #19

Merged
merged 67 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
3795c82
wip
Nov 1, 2024
cdcfda5
hello world
Nov 1, 2024
ce29888
working writes
Nov 2, 2024
32a2519
something working
Nov 2, 2024
4fd93f6
its's workgin!
Nov 2, 2024
611f9c2
Multi recv
Nov 2, 2024
41352a7
Experiment with timeouts
Nov 3, 2024
b2fa45a
Working timeout
Nov 3, 2024
3160e4c
Working mmap files
Nov 3, 2024
38e2124
Parsing and encoding peer messages
Nov 3, 2024
9122cbf
rename decoder module
Nov 3, 2024
de6008a
some refactors
Nov 3, 2024
333faf3
wip
Nov 5, 2024
89faa1a
First comms with container
Nov 10, 2024
e6960c9
Break out loop to different module
Nov 10, 2024
f21304a
wip
Nov 10, 2024
d7b2ac8
ensure buffers are always returned
Nov 11, 2024
00dfb31
Fix incorrect user data
Nov 12, 2024
3d3a834
Refactor eventloop code
Nov 12, 2024
2f2e51c
add piece selector
Nov 12, 2024
075d126
Add piece structs
Nov 16, 2024
d0b6767
Prevent encoding from taking ownership of buffer
Nov 16, 2024
5d5707d
Update buffer pool api and add torrent state
Nov 16, 2024
af437ab
Continue filling in peer connection
Nov 16, 2024
273cac3
Update piece selector and torret state
Nov 16, 2024
dbd3fd3
Update eventloop
Nov 16, 2024
4040e9c
More peer id to protocol
Nov 16, 2024
eaada2e
update examples
Nov 16, 2024
aca60b3
allow specifying order
Nov 17, 2024
f4c8d99
Sync more often
Nov 17, 2024
fae1aa0
fix buffer length bugs
Nov 20, 2024
0b3bdf4
Add filestore
Nov 25, 2024
cfe3fd6
Move over on piece completeted from old impl
Nov 25, 2024
2e3d81e
Add moving average
Nov 25, 2024
7c7d400
Fix filestore bug and remove default impl
Dec 1, 2024
a63ad3a
Refactor peer connection a bit
Dec 1, 2024
a106f50
Handle ENOBUFS for connected writes
Dec 2, 2024
97fa08a
Add timeout support
Dec 2, 2024
f1bbf59
Change order and only mark compelete once
Dec 2, 2024
7f431ad
Track stats for peer connection
Dec 2, 2024
a2604b4
Implement tick
Dec 2, 2024
3bc16df
Always use coop taskrun
Dec 3, 2024
da2a902
Add event backlog to deal with full submission queues
Dec 4, 2024
e449712
fmt and tweak slab size
Dec 4, 2024
3aded24
Make tick take torrentstate
Dec 5, 2024
aed721a
Return from eventloop when torrent is complete
Dec 5, 2024
df37928
time download in example
Dec 5, 2024
c348334
wip timeout
Dec 6, 2024
8a2d66b
wip working
Dec 8, 2024
fb9da78
Fix example
Dec 8, 2024
9bf9717
Remember to unregister read ring
Dec 8, 2024
5cc3827
misc
Dec 8, 2024
3fb454d
Fix logs and clamp desired queue size
Dec 8, 2024
8d8a8fe
Fix bug in deciding not to end slow start
Dec 8, 2024
44d5d5d
Fix desired queue size calculation
Dec 8, 2024
51df710
move connect to
Dec 8, 2024
ad02fad
Don't return torrent complete in event handler
Dec 12, 2024
dbd23f4
replace old impl
Dec 12, 2024
2d2ba72
Enable fast extension
Dec 12, 2024
7e5676f
HaveNone/HaveAll
Dec 12, 2024
5ce719e
Suggest piece
Dec 14, 2024
b0d07e6
Reject piece
Dec 14, 2024
85c21c9
profile tweaks
Dec 14, 2024
07121ab
Allowed Fast
Dec 14, 2024
3f45107
fix
Dec 28, 2024
f87aee2
Clarify comments and re-add crate metadata
Dec 28, 2024
b290c7e
remove print
Dec 28, 2024
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
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ env_logger = "0.10"
[profile.release]
overflow-checks = true
debug-assertions = true
lto = true

[profile.release.package."*"]
opt-level = 3
1 change: 0 additions & 1 deletion bittorrent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ homepage = "https://github.com/Nehliin/vortex"
repository = "https://github.com/Nehliin/vortex"
license = "BSD-3-Clause"


[dependencies]
io-uring = "0.7"
libc = "0.2"
Expand Down
44 changes: 35 additions & 9 deletions bittorrent/src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use slab::Slab;
use crate::{
buf_pool::BufferPool,
buf_ring::{Bgid, Bid, BufferRing},
peer_connection::{Error, PeerConnection},
peer_protocol::{parse_handshake, write_handshake, HANDSHAKE_SIZE},
peer_connection::{Error, OutgoingMsg, PeerConnection},
peer_protocol::{self, parse_handshake, write_handshake, HANDSHAKE_SIZE},
piece_selector::SUBPIECE_SIZE,
TorrentState,
};
Expand Down Expand Up @@ -410,12 +410,41 @@ impl EventLoop {
// We always have a buffer associated
let buffer = read_bid.map(|bid| self.read_ring.get(bid)).unwrap();
// Expect this to be the handshake response
let peer_id = parse_handshake(torrent_state.info_hash, &buffer[..len]).unwrap();
let peer_connection = PeerConnection::new(fd, peer_id);
let parsed_handshake =
parse_handshake(torrent_state.info_hash, &buffer[..len]).unwrap();
let peer_connection =
PeerConnection::new(fd, parsed_handshake.peer_id, parsed_handshake.fast_ext);
log::info!("Finished handshake!: {peer_connection:?}");
let connection_idx = self.connections.insert(peer_connection);
// We are now connected!
*event = Event::ConnectedRecv { connection_idx };

let completed = torrent_state.piece_selector.completed_clone();
let message = if completed.all() {
peer_protocol::PeerMessage::HaveAll
} else if completed.not_any() {
peer_protocol::PeerMessage::HaveNone
} else {
peer_protocol::PeerMessage::Bitfield(completed.into())
};
// sent as first message after handshake
let bitfield_msg = OutgoingMsg {
message,
ordered: true,
};
let buffer = self.write_pool.get_buffer();
bitfield_msg.message.encode(buffer.inner);
let size = bitfield_msg.message.encoded_size();
push_connected_write(
connection_idx,
fd,
&mut self.events,
sq,
buffer.index,
&buffer.inner[..size],
bitfield_msg.ordered,
backlog,
);
}
Event::ConnectedRecv { connection_idx } => {
let connection = &mut self.connections[connection_idx];
Expand Down Expand Up @@ -481,11 +510,8 @@ impl EventLoop {
)
}
}
Err(Error::Disconnect) => {
log::warn!(
"[Peer {}] is being disconnected",
connection.peer_id
);
Err(err @ Error::Disconnect(_)) => {
log::warn!("[Peer {}] {err}", connection.peer_id);
// TODO proper shutdown
}
Err(err) => {
Expand Down
Loading
Loading