Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
91 changes: 84 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ description = "A feature rich BitTorrent tracker."
edition = "2018"

[profile.release]
debug = 1
lto = "fat"

[features]
dhat-heap = [] # if you are doing heap profiling

[dependencies]
serde = {version = "1.0", features = ["derive"]}
serde = { version = "1.0", features = ["derive"] }
serde_bencode = "^0.2.3"
serde_bytes = "0.11"
serde_json = "1.0.72"
hex = "0.4.3"
percent-encoding = "2.1.0"
warp = {version = "0.3", features = ["tls"]}
tokio = {version = "1.7", features = ["full"]}
warp = { version = "0.3", features = ["tls"] }
tokio = { version = "1.7", features = ["full"] }
binascii = "0.1"
toml = "0.5"
log = {version = "0.4", features = ["release_max_level_info"]}
log = { version = "0.4", features = ["release_max_level_info"] }
fern = "0.6"
chrono = "0.4"
byteorder = "1"
Expand All @@ -34,3 +38,4 @@ thiserror = "1.0"
aquatic_udp_protocol = { git = "https://github.com/greatest-ape/aquatic" }
futures = "0.3.21"
async-trait = "0.1.52"
dhat = "0.3.0"
7 changes: 4 additions & 3 deletions src/common.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use aquatic_udp_protocol::{AnnounceEvent, NumberOfBytes};
use serde::{Deserialize, Serialize};

pub const MAX_SCRAPE_TORRENTS: u8 = 74;
pub const AUTH_KEY_LENGTH: usize = 32;
Expand All @@ -19,7 +19,7 @@ pub enum AnnounceEventDef {
Started,
Stopped,
Completed,
None
None,
}

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -135,7 +135,7 @@ impl PeerId {
String::from(std::str::from_utf8(bytes_out).unwrap())
} else {
"".to_string()
}
};
}
}

Expand Down Expand Up @@ -218,6 +218,7 @@ impl PeerId {
}
}
}

impl Serialize for PeerId {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down
32 changes: 17 additions & 15 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
pub use crate::tracker::TrackerMode;
use serde::{Serialize, Deserialize, Serializer};
use std;
use std::collections::HashMap;
use std::fs;
use toml;
use std::net::{IpAddr};
use std::net::IpAddr;
use std::path::Path;
use std::str::FromStr;
use config::{ConfigError, Config, File};

use config::{Config, ConfigError, File};
use serde::{Deserialize, Serialize, Serializer};
use toml;

use crate::database::DatabaseDrivers;
pub use crate::tracker::TrackerMode;

#[derive(Serialize, Deserialize, PartialEq)]
pub enum TrackerServer {
UDP,
HTTP
HTTP,
}

#[derive(Serialize, Deserialize, Debug)]
Expand All @@ -30,7 +32,7 @@ pub struct HttpTrackerConfig {
#[serde(serialize_with = "none_as_empty_string")]
pub ssl_cert_path: Option<String>,
#[serde(serialize_with = "none_as_empty_string")]
pub ssl_key_path: Option<String>
pub ssl_key_path: Option<String>,
}

impl HttpTrackerConfig {
Expand Down Expand Up @@ -114,7 +116,7 @@ impl Configuration {
match Self::load(data.as_slice()) {
Ok(cfg) => {
Ok(cfg)
},
}
Err(e) => Err(ConfigurationError::ParseError(e)),
}
}
Expand Down Expand Up @@ -158,21 +160,21 @@ impl Configuration {
enabled: true,
bind_address: String::from("127.0.0.1:1212"),
access_tokens: [(String::from("admin"), String::from("MyAccessToken"))].iter().cloned().collect(),
}
},
};
configuration.udp_trackers.push(
UdpTrackerConfig{
UdpTrackerConfig {
enabled: false,
bind_address: String::from("0.0.0.0:6969")
bind_address: String::from("0.0.0.0:6969"),
}
);
configuration.http_trackers.push(
HttpTrackerConfig{
HttpTrackerConfig {
enabled: false,
bind_address: String::from("0.0.0.0:6969"),
ssl_enabled: false,
ssl_cert_path: None,
ssl_key_path: None
ssl_key_path: None,
}
);
configuration
Expand All @@ -190,15 +192,15 @@ impl Configuration {
eprintln!("Creating config file..");
let config = Configuration::default();
let _ = config.save_to_file();
return Err(ConfigError::Message(format!("Please edit the config.TOML in the root folder and restart the tracker.")))
return Err(ConfigError::Message(format!("Please edit the config.TOML in the root folder and restart the tracker.")));
}

let torrust_config: Configuration = config.try_into().map_err(|e| ConfigError::Message(format!("Errors while processing config: {}.", e)))?;

Ok(torrust_config)
}

pub fn save_to_file(&self) -> Result<(), ()>{
pub fn save_to_file(&self) -> Result<(), ()> {
let toml_string = toml::to_string(self).expect("Could not encode TOML value");
fs::write("config.toml", toml_string).expect("Could not write to file!");
Ok(())
Expand Down
12 changes: 7 additions & 5 deletions src/database.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
use std::collections::BTreeMap;
use crate::{InfoHash};
use crate::key_manager::AuthKey;
use crate::sqlite_database::SqliteDatabase;

use async_trait::async_trait;
use derive_more::{Display, Error};
use log::debug;
use serde::{Deserialize, Serialize};

use crate::InfoHash;
use crate::key_manager::AuthKey;
use crate::mysql_database::MysqlDatabase;
use serde::{Serialize, Deserialize};
use crate::sqlite_database::SqliteDatabase;
use crate::torrent::TorrentEntry;

#[derive(Serialize, Deserialize, Debug)]
pub enum DatabaseDrivers {
Sqlite3,
MySQL
MySQL,
}

pub fn connect_database(db_driver: &DatabaseDrivers, db_path: &str) -> Result<Box<dyn Database>, r2d2::Error> {
Expand Down
Loading