Skip to content

Commit 8ff668f

Browse files
committed
Merge torrust#959: dev: remove async trait dep
64850af dev: remove async trait dep (Cameron Garnham) Pull request description: Remove Unneeded Async Trait Dependency ACKs for top commit: da2ce7: ACK 64850af Tree-SHA512: 54a83db83d11b0829c80e3daf4dd5776bd6b4e4709553645ffe742dcdba458c24dfa195e2c1b8abac1a59152144aa5419698d9edbf25af657f1e6c85943fda78
2 parents f2629ce + 64850af commit 8ff668f

21 files changed

+208
-183
lines changed

Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ version = "3.0.0-alpha.12-develop"
3232
[dependencies]
3333
anyhow = "1"
3434
aquatic_udp_protocol = "0"
35-
async-trait = "0"
3635
axum = { version = "0", features = ["macros"] }
3736
axum-client-ip = "0"
3837
axum-extra = { version = "0", features = ["query"] }

src/core/databases/mod.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ pub mod sqlite;
5050

5151
use std::marker::PhantomData;
5252

53-
use async_trait::async_trait;
5453
use torrust_tracker_primitives::info_hash::InfoHash;
5554
use torrust_tracker_primitives::PersistentTorrents;
5655

@@ -79,7 +78,6 @@ where
7978
}
8079

8180
/// The persistence trait. It contains all the methods to interact with the database.
82-
#[async_trait]
8381
pub trait Database: Sync + Send {
8482
/// It instantiates a new database driver.
8583
///
@@ -126,7 +124,7 @@ pub trait Database: Sync + Send {
126124
/// # Errors
127125
///
128126
/// Will return `Err` if unable to load.
129-
async fn load_persistent_torrents(&self) -> Result<PersistentTorrents, Error>;
127+
fn load_persistent_torrents(&self) -> Result<PersistentTorrents, Error>;
130128

131129
/// It saves the torrent metrics data into the database.
132130
///
@@ -135,7 +133,7 @@ pub trait Database: Sync + Send {
135133
/// # Errors
136134
///
137135
/// Will return `Err` if unable to save.
138-
async fn save_persistent_torrent(&self, info_hash: &InfoHash, downloaded: u32) -> Result<(), Error>;
136+
fn save_persistent_torrent(&self, info_hash: &InfoHash, downloaded: u32) -> Result<(), Error>;
139137

140138
// Whitelist
141139

@@ -146,7 +144,7 @@ pub trait Database: Sync + Send {
146144
/// # Errors
147145
///
148146
/// Will return `Err` if unable to load.
149-
async fn load_whitelist(&self) -> Result<Vec<InfoHash>, Error>;
147+
fn load_whitelist(&self) -> Result<Vec<InfoHash>, Error>;
150148

151149
/// It checks if the torrent is whitelisted.
152150
///
@@ -157,7 +155,7 @@ pub trait Database: Sync + Send {
157155
/// # Errors
158156
///
159157
/// Will return `Err` if unable to load.
160-
async fn get_info_hash_from_whitelist(&self, info_hash: &InfoHash) -> Result<Option<InfoHash>, Error>;
158+
fn get_info_hash_from_whitelist(&self, info_hash: InfoHash) -> Result<Option<InfoHash>, Error>;
161159

162160
/// It adds the torrent to the whitelist.
163161
///
@@ -166,7 +164,7 @@ pub trait Database: Sync + Send {
166164
/// # Errors
167165
///
168166
/// Will return `Err` if unable to save.
169-
async fn add_info_hash_to_whitelist(&self, info_hash: InfoHash) -> Result<usize, Error>;
167+
fn add_info_hash_to_whitelist(&self, info_hash: InfoHash) -> Result<usize, Error>;
170168

171169
/// It checks if the torrent is whitelisted.
172170
///
@@ -175,8 +173,8 @@ pub trait Database: Sync + Send {
175173
/// # Errors
176174
///
177175
/// Will return `Err` if unable to load.
178-
async fn is_info_hash_whitelisted(&self, info_hash: &InfoHash) -> Result<bool, Error> {
179-
Ok(self.get_info_hash_from_whitelist(info_hash).await?.is_some())
176+
fn is_info_hash_whitelisted(&self, info_hash: InfoHash) -> Result<bool, Error> {
177+
Ok(self.get_info_hash_from_whitelist(info_hash)?.is_some())
180178
}
181179

182180
/// It removes the torrent from the whitelist.
@@ -186,7 +184,7 @@ pub trait Database: Sync + Send {
186184
/// # Errors
187185
///
188186
/// Will return `Err` if unable to save.
189-
async fn remove_info_hash_from_whitelist(&self, info_hash: InfoHash) -> Result<usize, Error>;
187+
fn remove_info_hash_from_whitelist(&self, info_hash: InfoHash) -> Result<usize, Error>;
190188

191189
// Authentication keys
192190

@@ -197,19 +195,19 @@ pub trait Database: Sync + Send {
197195
/// # Errors
198196
///
199197
/// Will return `Err` if unable to load.
200-
async fn load_keys(&self) -> Result<Vec<auth::ExpiringKey>, Error>;
198+
fn load_keys(&self) -> Result<Vec<auth::ExpiringKey>, Error>;
201199

202200
/// It gets an expiring authentication key from the database.
203201
///
204202
/// It returns `Some(ExpiringKey)` if a [`ExpiringKey`](crate::core::auth::ExpiringKey)
205-
/// with the input [`Key`](crate::core::auth::Key) exists, `None` otherwise.
203+
/// with the input [`Key`] exists, `None` otherwise.
206204
///
207205
/// # Context: Authentication Keys
208206
///
209207
/// # Errors
210208
///
211209
/// Will return `Err` if unable to load.
212-
async fn get_key_from_keys(&self, key: &Key) -> Result<Option<auth::ExpiringKey>, Error>;
210+
fn get_key_from_keys(&self, key: &Key) -> Result<Option<auth::ExpiringKey>, Error>;
213211

214212
/// It adds an expiring authentication key to the database.
215213
///
@@ -218,7 +216,7 @@ pub trait Database: Sync + Send {
218216
/// # Errors
219217
///
220218
/// Will return `Err` if unable to save.
221-
async fn add_key_to_keys(&self, auth_key: &auth::ExpiringKey) -> Result<usize, Error>;
219+
fn add_key_to_keys(&self, auth_key: &auth::ExpiringKey) -> Result<usize, Error>;
222220

223221
/// It removes an expiring authentication key from the database.
224222
///
@@ -227,5 +225,5 @@ pub trait Database: Sync + Send {
227225
/// # Errors
228226
///
229227
/// Will return `Err` if unable to load.
230-
async fn remove_key_from_keys(&self, key: &Key) -> Result<usize, Error>;
228+
fn remove_key_from_keys(&self, key: &Key) -> Result<usize, Error>;
231229
}

src/core/databases/mysql.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
use std::str::FromStr;
33
use std::time::Duration;
44

5-
use async_trait::async_trait;
65
use r2d2::Pool;
76
use r2d2_mysql::mysql::prelude::Queryable;
87
use r2d2_mysql::mysql::{params, Opts, OptsBuilder};
@@ -22,7 +21,6 @@ pub struct Mysql {
2221
pool: Pool<MySqlConnectionManager>,
2322
}
2423

25-
#[async_trait]
2624
impl Database for Mysql {
2725
/// It instantiates a new `MySQL` database driver.
2826
///
@@ -106,7 +104,7 @@ impl Database for Mysql {
106104
}
107105

108106
/// Refer to [`databases::Database::load_persistent_torrents`](crate::core::databases::Database::load_persistent_torrents).
109-
async fn load_persistent_torrents(&self) -> Result<PersistentTorrents, Error> {
107+
fn load_persistent_torrents(&self) -> Result<PersistentTorrents, Error> {
110108
let mut conn = self.pool.get().map_err(|e| (e, DRIVER))?;
111109

112110
let torrents = conn.query_map(
@@ -121,7 +119,7 @@ impl Database for Mysql {
121119
}
122120

123121
/// Refer to [`databases::Database::load_keys`](crate::core::databases::Database::load_keys).
124-
async fn load_keys(&self) -> Result<Vec<auth::ExpiringKey>, Error> {
122+
fn load_keys(&self) -> Result<Vec<auth::ExpiringKey>, Error> {
125123
let mut conn = self.pool.get().map_err(|e| (e, DRIVER))?;
126124

127125
let keys = conn.query_map(
@@ -136,7 +134,7 @@ impl Database for Mysql {
136134
}
137135

138136
/// Refer to [`databases::Database::load_whitelist`](crate::core::databases::Database::load_whitelist).
139-
async fn load_whitelist(&self) -> Result<Vec<InfoHash>, Error> {
137+
fn load_whitelist(&self) -> Result<Vec<InfoHash>, Error> {
140138
let mut conn = self.pool.get().map_err(|e| (e, DRIVER))?;
141139

142140
let info_hashes = conn.query_map("SELECT info_hash FROM whitelist", |info_hash: String| {
@@ -147,7 +145,7 @@ impl Database for Mysql {
147145
}
148146

149147
/// Refer to [`databases::Database::save_persistent_torrent`](crate::core::databases::Database::save_persistent_torrent).
150-
async fn save_persistent_torrent(&self, info_hash: &InfoHash, completed: u32) -> Result<(), Error> {
148+
fn save_persistent_torrent(&self, info_hash: &InfoHash, completed: u32) -> Result<(), Error> {
151149
const COMMAND : &str = "INSERT INTO torrents (info_hash, completed) VALUES (:info_hash_str, :completed) ON DUPLICATE KEY UPDATE completed = VALUES(completed)";
152150

153151
let mut conn = self.pool.get().map_err(|e| (e, DRIVER))?;
@@ -160,7 +158,7 @@ impl Database for Mysql {
160158
}
161159

162160
/// Refer to [`databases::Database::get_info_hash_from_whitelist`](crate::core::databases::Database::get_info_hash_from_whitelist).
163-
async fn get_info_hash_from_whitelist(&self, info_hash: &InfoHash) -> Result<Option<InfoHash>, Error> {
161+
fn get_info_hash_from_whitelist(&self, info_hash: InfoHash) -> Result<Option<InfoHash>, Error> {
164162
let mut conn = self.pool.get().map_err(|e| (e, DRIVER))?;
165163

166164
let select = conn.exec_first::<String, _, _>(
@@ -174,7 +172,7 @@ impl Database for Mysql {
174172
}
175173

176174
/// Refer to [`databases::Database::add_info_hash_to_whitelist`](crate::core::databases::Database::add_info_hash_to_whitelist).
177-
async fn add_info_hash_to_whitelist(&self, info_hash: InfoHash) -> Result<usize, Error> {
175+
fn add_info_hash_to_whitelist(&self, info_hash: InfoHash) -> Result<usize, Error> {
178176
let mut conn = self.pool.get().map_err(|e| (e, DRIVER))?;
179177

180178
let info_hash_str = info_hash.to_string();
@@ -188,7 +186,7 @@ impl Database for Mysql {
188186
}
189187

190188
/// Refer to [`databases::Database::remove_info_hash_from_whitelist`](crate::core::databases::Database::remove_info_hash_from_whitelist).
191-
async fn remove_info_hash_from_whitelist(&self, info_hash: InfoHash) -> Result<usize, Error> {
189+
fn remove_info_hash_from_whitelist(&self, info_hash: InfoHash) -> Result<usize, Error> {
192190
let mut conn = self.pool.get().map_err(|e| (e, DRIVER))?;
193191

194192
let info_hash = info_hash.to_string();
@@ -199,7 +197,7 @@ impl Database for Mysql {
199197
}
200198

201199
/// Refer to [`databases::Database::get_key_from_keys`](crate::core::databases::Database::get_key_from_keys).
202-
async fn get_key_from_keys(&self, key: &Key) -> Result<Option<auth::ExpiringKey>, Error> {
200+
fn get_key_from_keys(&self, key: &Key) -> Result<Option<auth::ExpiringKey>, Error> {
203201
let mut conn = self.pool.get().map_err(|e| (e, DRIVER))?;
204202

205203
let query = conn.exec_first::<(String, i64), _, _>(
@@ -216,7 +214,7 @@ impl Database for Mysql {
216214
}
217215

218216
/// Refer to [`databases::Database::add_key_to_keys`](crate::core::databases::Database::add_key_to_keys).
219-
async fn add_key_to_keys(&self, auth_key: &auth::ExpiringKey) -> Result<usize, Error> {
217+
fn add_key_to_keys(&self, auth_key: &auth::ExpiringKey) -> Result<usize, Error> {
220218
let mut conn = self.pool.get().map_err(|e| (e, DRIVER))?;
221219

222220
let key = auth_key.key.to_string();
@@ -231,7 +229,7 @@ impl Database for Mysql {
231229
}
232230

233231
/// Refer to [`databases::Database::remove_key_from_keys`](crate::core::databases::Database::remove_key_from_keys).
234-
async fn remove_key_from_keys(&self, key: &Key) -> Result<usize, Error> {
232+
fn remove_key_from_keys(&self, key: &Key) -> Result<usize, Error> {
235233
let mut conn = self.pool.get().map_err(|e| (e, DRIVER))?;
236234

237235
conn.exec_drop("DELETE FROM `keys` WHERE key = :key", params! { "key" => key.to_string() })?;

src/core/databases/sqlite.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
use std::panic::Location;
33
use std::str::FromStr;
44

5-
use async_trait::async_trait;
65
use r2d2::Pool;
76
use r2d2_sqlite::SqliteConnectionManager;
87
use torrust_tracker_primitives::info_hash::InfoHash;
@@ -18,7 +17,6 @@ pub struct Sqlite {
1817
pool: Pool<SqliteConnectionManager>,
1918
}
2019

21-
#[async_trait]
2220
impl Database for Sqlite {
2321
/// It instantiates a new `SQLite3` database driver.
2422
///
@@ -90,7 +88,7 @@ impl Database for Sqlite {
9088
}
9189

9290
/// Refer to [`databases::Database::load_persistent_torrents`](crate::core::databases::Database::load_persistent_torrents).
93-
async fn load_persistent_torrents(&self) -> Result<PersistentTorrents, Error> {
91+
fn load_persistent_torrents(&self) -> Result<PersistentTorrents, Error> {
9492
let conn = self.pool.get().map_err(|e| (e, DRIVER))?;
9593

9694
let mut stmt = conn.prepare("SELECT info_hash, completed FROM torrents")?;
@@ -106,7 +104,7 @@ impl Database for Sqlite {
106104
}
107105

108106
/// Refer to [`databases::Database::load_keys`](crate::core::databases::Database::load_keys).
109-
async fn load_keys(&self) -> Result<Vec<auth::ExpiringKey>, Error> {
107+
fn load_keys(&self) -> Result<Vec<auth::ExpiringKey>, Error> {
110108
let conn = self.pool.get().map_err(|e| (e, DRIVER))?;
111109

112110
let mut stmt = conn.prepare("SELECT key, valid_until FROM keys")?;
@@ -127,7 +125,7 @@ impl Database for Sqlite {
127125
}
128126

129127
/// Refer to [`databases::Database::load_whitelist`](crate::core::databases::Database::load_whitelist).
130-
async fn load_whitelist(&self) -> Result<Vec<InfoHash>, Error> {
128+
fn load_whitelist(&self) -> Result<Vec<InfoHash>, Error> {
131129
let conn = self.pool.get().map_err(|e| (e, DRIVER))?;
132130

133131
let mut stmt = conn.prepare("SELECT info_hash FROM whitelist")?;
@@ -144,7 +142,7 @@ impl Database for Sqlite {
144142
}
145143

146144
/// Refer to [`databases::Database::save_persistent_torrent`](crate::core::databases::Database::save_persistent_torrent).
147-
async fn save_persistent_torrent(&self, info_hash: &InfoHash, completed: u32) -> Result<(), Error> {
145+
fn save_persistent_torrent(&self, info_hash: &InfoHash, completed: u32) -> Result<(), Error> {
148146
let conn = self.pool.get().map_err(|e| (e, DRIVER))?;
149147

150148
let insert = conn.execute(
@@ -163,7 +161,7 @@ impl Database for Sqlite {
163161
}
164162

165163
/// Refer to [`databases::Database::get_info_hash_from_whitelist`](crate::core::databases::Database::get_info_hash_from_whitelist).
166-
async fn get_info_hash_from_whitelist(&self, info_hash: &InfoHash) -> Result<Option<InfoHash>, Error> {
164+
fn get_info_hash_from_whitelist(&self, info_hash: InfoHash) -> Result<Option<InfoHash>, Error> {
167165
let conn = self.pool.get().map_err(|e| (e, DRIVER))?;
168166

169167
let mut stmt = conn.prepare("SELECT info_hash FROM whitelist WHERE info_hash = ?")?;
@@ -176,7 +174,7 @@ impl Database for Sqlite {
176174
}
177175

178176
/// Refer to [`databases::Database::add_info_hash_to_whitelist`](crate::core::databases::Database::add_info_hash_to_whitelist).
179-
async fn add_info_hash_to_whitelist(&self, info_hash: InfoHash) -> Result<usize, Error> {
177+
fn add_info_hash_to_whitelist(&self, info_hash: InfoHash) -> Result<usize, Error> {
180178
let conn = self.pool.get().map_err(|e| (e, DRIVER))?;
181179

182180
let insert = conn.execute("INSERT INTO whitelist (info_hash) VALUES (?)", [info_hash.to_string()])?;
@@ -192,7 +190,7 @@ impl Database for Sqlite {
192190
}
193191

194192
/// Refer to [`databases::Database::remove_info_hash_from_whitelist`](crate::core::databases::Database::remove_info_hash_from_whitelist).
195-
async fn remove_info_hash_from_whitelist(&self, info_hash: InfoHash) -> Result<usize, Error> {
193+
fn remove_info_hash_from_whitelist(&self, info_hash: InfoHash) -> Result<usize, Error> {
196194
let conn = self.pool.get().map_err(|e| (e, DRIVER))?;
197195

198196
let deleted = conn.execute("DELETE FROM whitelist WHERE info_hash = ?", [info_hash.to_string()])?;
@@ -210,7 +208,7 @@ impl Database for Sqlite {
210208
}
211209

212210
/// Refer to [`databases::Database::get_key_from_keys`](crate::core::databases::Database::get_key_from_keys).
213-
async fn get_key_from_keys(&self, key: &Key) -> Result<Option<auth::ExpiringKey>, Error> {
211+
fn get_key_from_keys(&self, key: &Key) -> Result<Option<auth::ExpiringKey>, Error> {
214212
let conn = self.pool.get().map_err(|e| (e, DRIVER))?;
215213

216214
let mut stmt = conn.prepare("SELECT key, valid_until FROM keys WHERE key = ?")?;
@@ -230,7 +228,7 @@ impl Database for Sqlite {
230228
}
231229

232230
/// Refer to [`databases::Database::add_key_to_keys`](crate::core::databases::Database::add_key_to_keys).
233-
async fn add_key_to_keys(&self, auth_key: &auth::ExpiringKey) -> Result<usize, Error> {
231+
fn add_key_to_keys(&self, auth_key: &auth::ExpiringKey) -> Result<usize, Error> {
234232
let conn = self.pool.get().map_err(|e| (e, DRIVER))?;
235233

236234
let insert = conn.execute(
@@ -249,7 +247,7 @@ impl Database for Sqlite {
249247
}
250248

251249
/// Refer to [`databases::Database::remove_key_from_keys`](crate::core::databases::Database::remove_key_from_keys).
252-
async fn remove_key_from_keys(&self, key: &Key) -> Result<usize, Error> {
250+
fn remove_key_from_keys(&self, key: &Key) -> Result<usize, Error> {
253251
let conn = self.pool.get().map_err(|e| (e, DRIVER))?;
254252

255253
let deleted = conn.execute("DELETE FROM keys WHERE key = ?", [key.to_string()])?;

0 commit comments

Comments
 (0)