diff --git a/README.md b/README.md index 7dfb2ea..db99368 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ # meteoro -A UDP BitTorrent tracker written in Rust +A BitTorrent tracker, written in Rust, implementing a BEP 15-compliant UDP tracker server. + +## Building + +`$ cargo build` + +## Usage + +After building the binary as described above, one can run the executable with the `--help` flag to see a listing of options the server software provides. + +The server software currently binds to the `localhost`, both IPv4 and IPv6, when run with no arguments. One can supply the `-a IPV4_ADDRESS:PORT` option or `-A IPV6_ADDRESS:PORT` option to specify interfaces for the server to bind to. Example: `$ meteoro -a 192.168.1.23:6969` to bind on 192.168.1.23, port 6969. diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..8d4e913 --- /dev/null +++ b/TODO.md @@ -0,0 +1,3 @@ +# The Big To-Do List + +- **Metrics/management API**, for returning statistics and modifying configurations at runtime using HTTP & JSON diff --git a/src/meteoro.rs b/src/meteoro.rs index 8aec265..21e2511 100644 --- a/src/meteoro.rs +++ b/src/meteoro.rs @@ -1,12 +1,11 @@ use std::net::{SocketAddr, UdpSocket}; use std::thread; -use std::time::Duration; use anyhow::Result; use flume::Sender; use threadpool::ThreadPool; -use crate::tracker::{self, RequestMessage, ResponseMessage, Tracker}; +use crate::tracker::{RequestMessage, ResponseMessage, Tracker}; use crate::udp_server; /// Instance of the meteoro BitTorrent tracker diff --git a/src/tracker.rs b/src/tracker.rs index c207899..3f3bbc9 100644 --- a/src/tracker.rs +++ b/src/tracker.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use std::net::{SocketAddr, SocketAddrV4, SocketAddrV6}; +use std::net::SocketAddr; use std::sync::atomic::{AtomicBool, Ordering}; use std::time::{Duration, Instant}; @@ -74,9 +74,13 @@ impl Tracker { let mut next_gc = Instant::now() + GARBAGE_COLLECTION_INTERVAL; let should_exit = AtomicBool::new(false); + // Wait for messages from the networking threads / main application + while !should_exit.load(Ordering::Relaxed) { let _ = Selector::new() .recv(&reqs, |request| { + // Tracker request + let request = request.unwrap(); log::trace!("Request from {} | {:?}", request.src_addr, request.request); @@ -89,6 +93,8 @@ impl Tracker { }; }) .recv(&ctrl, |msg| { + // Control message + let msg = msg.unwrap(); match msg { @@ -99,8 +105,9 @@ impl Tracker { }) .wait(); + // Garbage collection + if Instant::now() > next_gc { - // Garbage collect self.garbage_collect(); next_gc = Instant::now()