added clap support
This commit is contained in:
parent
393234b41b
commit
dac68c8ff7
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rusty_torrent"
|
name = "rusty_torrent"
|
||||||
version = "0.9.2"
|
version = "0.9.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
description = "A BitTorrent client implemented in Rust that allows you to interact with the BitTorrent protocol and download torrents."
|
description = "A BitTorrent client implemented in Rust that allows you to interact with the BitTorrent protocol and download torrents."
|
||||||
@ -16,6 +16,7 @@ repository = "https://github.com/arlofilley/rusty_torrent"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
clap = { version = "4.4.0", features = ["derive"] }
|
||||||
dns-lookup = "2.0.2"
|
dns-lookup = "2.0.2"
|
||||||
log = "0.4.20"
|
log = "0.4.20"
|
||||||
regex = "1.9.4"
|
regex = "1.9.4"
|
||||||
@ -25,4 +26,4 @@ serde_bencode = "0.2.3"
|
|||||||
serde_bytes = "0.11.12"
|
serde_bytes = "0.11.12"
|
||||||
sha1 = "0.10.5"
|
sha1 = "0.10.5"
|
||||||
simple-logging = "2.0.2"
|
simple-logging = "2.0.2"
|
||||||
tokio = { version = "1.30.0", features = ["full"] }
|
tokio = { version = "1.30.0", features = ["full"] }
|
||||||
|
47
src/main.rs
47
src/main.rs
@ -31,41 +31,40 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
// External Ipmorts
|
// External Ipmorts
|
||||||
use log::{ debug, info, LevelFilter, error };
|
use clap::Parser;
|
||||||
|
use log::{ debug, info, LevelFilter };
|
||||||
|
|
||||||
|
/// Struct Respresenting needed arguments
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
#[command(author, version, about, long_about = None)]
|
||||||
|
struct Args {
|
||||||
|
#[arg(short, long)]
|
||||||
|
log_file_path: Option<String>,
|
||||||
|
|
||||||
|
#[arg(short, long)]
|
||||||
|
torrent_file_path: String,
|
||||||
|
|
||||||
|
#[arg(short, long)]
|
||||||
|
download_path: String,
|
||||||
|
}
|
||||||
|
|
||||||
/// The root function
|
/// The root function
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
let args = Args::parse();
|
||||||
|
|
||||||
// Creates a log file to handle large amounts of data
|
// Creates a log file to handle large amounts of data
|
||||||
let log_path = "/Users/arlo/code/RustyTorrent/log/rustytorrent.log";
|
let log_path = args.log_file_path.unwrap_or(String::from("./log/rustytorrent.log"));
|
||||||
simple_logging::log_to_file(log_path, LevelFilter::Info).unwrap();
|
simple_logging::log_to_file(&log_path, LevelFilter::Info).unwrap();
|
||||||
|
|
||||||
let torrent_file_path = match std::env::args().nth(1) {
|
|
||||||
None => {
|
|
||||||
error!("Please Provide A Torrent File");
|
|
||||||
eprintln!("Critical error, please read log for more info: {}", log_path);
|
|
||||||
return
|
|
||||||
}
|
|
||||||
Some(path) => { path }
|
|
||||||
};
|
|
||||||
|
|
||||||
let download_path = match std::env::args().nth(2) {
|
|
||||||
None => {
|
|
||||||
error!("Please Provide A Download Path");
|
|
||||||
eprintln!("Critical error, please read log for more info: {}", log_path);
|
|
||||||
return
|
|
||||||
}
|
|
||||||
Some(path) => { path }
|
|
||||||
};
|
|
||||||
|
|
||||||
// Read the Torrent File
|
// Read the Torrent File
|
||||||
let torrent = Torrent::from_torrent_file(&torrent_file_path).await;
|
let torrent = Torrent::from_torrent_file(&args.torrent_file_path).await;
|
||||||
info!("Sucessfully read torrent file");
|
info!("Sucessfully read torrent file");
|
||||||
torrent.log_useful_information();
|
torrent.log_useful_information();
|
||||||
|
|
||||||
// Create the files that will be written to
|
// Create the files that will be written to
|
||||||
let mut files = Files::new();
|
let mut files = Files::new();
|
||||||
files.create_files(&torrent, &download_path).await;
|
files.create_files(&torrent, &args.download_path).await;
|
||||||
|
|
||||||
// Gets peers from the given tracker
|
// Gets peers from the given tracker
|
||||||
let (_remote_hostname, _remote_port) = torrent.get_tracker();
|
let (_remote_hostname, _remote_port) = torrent.get_tracker();
|
||||||
@ -93,7 +92,7 @@ async fn main() {
|
|||||||
info!("Found Peers");
|
info!("Found Peers");
|
||||||
|
|
||||||
// Creates an assumed peer connection to the `SocketAddr` given
|
// Creates an assumed peer connection to the `SocketAddr` given
|
||||||
let mut peer = match Peer::create_connection(&format!("{}:{}", announce_message_response.ips[4], announce_message_response.ports[4])).await {
|
let mut peer = match Peer::create_connection(&format!("{}:{}", announce_message_response.ips[0], announce_message_response.ports[0])).await {
|
||||||
None => { return },
|
None => { return },
|
||||||
Some(peer) => peer
|
Some(peer) => peer
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user