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

UDP Trackers #102

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft

UDP Trackers #102

wants to merge 7 commits into from

Conversation

billyb2
Copy link

@billyb2 billyb2 commented May 17, 2021

(Currently not ready, still working out some stuff).

This pull request should add the ability to connect to UDP trackers, which is a major stepping point for the crate.

billyb2 added 4 commits March 8, 2021 14:50
The first part of the work is now complete! I'm following
https://www.bittorrent.org/beps/bep_0015.html to follow the
specification perfectly.
Haven't been able to fully test this, though I expect it should work
fine. There are some minor quirks. For instance, I was unsure of how
large the arrays for the announce message should be, so I made it 30
bytes (the bep was kind of unclear on this).
Kind of realized that I didn't very the transaction ID, so I did that and added a Result
UdpTracker struct and Tracker struct have been combined into one, with
no breaking changes! (External to the library). Internally, there's now
a udp bool, that's just equal to true or false, indicating whether a
tracker uses UDP or not. I still can't download from UDP only trackers
for some damn reason, and there's still issues with finding working UDP
trackers and connecting to them, but now, the program can technically
work.
@billyb2 billyb2 mentioned this pull request May 17, 2021
cratetorrent/src/metainfo.rs Outdated Show resolved Hide resolved
This is a bit easier to understand than the tuple used previously.
cratetorrent/src/metainfo.rs Outdated Show resolved Hide resolved
cratetorrent/src/metainfo.rs Outdated Show resolved Hide resolved
billyb2 added 2 commits May 19, 2021 09:01
So when I first started working on this months ago, I didn't realize that the torrent protocol wanted signed ints, so basically, I just changed all the unsigned ints into signed (where it was wanted by the protocol), and edited some of my old code to be nicer.
@billyb2
Copy link
Author

billyb2 commented Aug 3, 2021

Hi, could someone please help me to understand if my code is correct or not? I feel as though I've fixed all of the issues, and have a properly working tracker udp protocol, but am having difficulties downloading some UDP only torrents.

Copy link
Owner

@vimpunk vimpunk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this, @billyb2!

I haven't tested the actual code yet, I'll do that as a next step.

I think it would make more sense if the different tracker types were distinct types. HttpTracker and UdpTracker. That makes the distinction a bit clearer. I'd then make a Tracker (object safe) trait and use Box<dyn Tracker> instances throughout the code. Since trackers are generally not on the hot path and are called infrequently, the small price of the dynamic dispatch is of no concern here, but the code becomes clearer as a result.

What do you think?

Then, I think the parsing of the binary protocol could be achieved with tokio frames. That would make it easier to see at a glance what the announce logic does.

#[derive(Clone)]
pub struct TrackerUrl {
pub url: Url,
pub protocol: NetProtocol,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary. The Url type already contains the scheme.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Url struct is reqwest only, so it only works for HTTP, not for UDP

@@ -0,0 +1,2 @@
[build]
jobs = 1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mean to include that, I usually build with 1 thread since I'm doing homework or playing games while I program.

addrs.shuffle(&mut thread_rng());

//TODO: Make an error for not finding an actual IPV4 address
let addr = *addrs.iter().find(|a| a.is_ipv4()).unwrap();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this is a draft, so I would just like to put a note here as a reminder to take out the unwrap once the PR nears completion.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yea, of course. I definitely won't resolve this until I actually fix it.


//Supporting around a few hundred peers, just for the test

let mut response_buf: [u8; MAX_NUM_PEERS] = [0; MAX_NUM_PEERS];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should support an arbitrary number of peers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could probably just turn it into a vector if you'd like

.await
.unwrap();

//The magic protocol id number
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please leave a white space between the last forward slash and the first character of the comment? Same goes for the other places.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants