Trait torrust_tracker::tracker::databases::Database
source · pub trait Database: Sync + Send {
Show 14 methods
// Required methods
fn new(db_path: &str) -> Result<Self, Error>
where Self: Sized;
fn create_database_tables(&self) -> Result<(), Error>;
fn drop_database_tables(&self) -> Result<(), Error>;
fn load_persistent_torrents<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<Vec<(InfoHash, u32)>, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn save_persistent_torrent<'life0, 'life1, 'async_trait>(
&'life0 self,
info_hash: &'life1 InfoHash,
completed: u32
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn load_whitelist<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<Vec<InfoHash>, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn get_info_hash_from_whitelist<'life0, 'life1, 'async_trait>(
&'life0 self,
info_hash: &'life1 InfoHash
) -> Pin<Box<dyn Future<Output = Result<Option<InfoHash>, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn add_info_hash_to_whitelist<'life0, 'async_trait>(
&'life0 self,
info_hash: InfoHash
) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn remove_info_hash_from_whitelist<'life0, 'async_trait>(
&'life0 self,
info_hash: InfoHash
) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn load_keys<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<Vec<ExpiringKey>, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn get_key_from_keys<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 Key
) -> Pin<Box<dyn Future<Output = Result<Option<ExpiringKey>, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn add_key_to_keys<'life0, 'life1, 'async_trait>(
&'life0 self,
auth_key: &'life1 ExpiringKey
) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn remove_key_from_keys<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 Key
) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided method
fn is_info_hash_whitelisted<'life0, 'life1, 'async_trait>(
&'life0 self,
info_hash: &'life1 InfoHash
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
The persistence trait. It contains all the methods to interact with the database.
Required Methods§
sourcefn new(db_path: &str) -> Result<Self, Error>where
Self: Sized,
fn new(db_path: &str) -> Result<Self, Error>where Self: Sized,
It instantiates a new database driver.
Errors
Will return r2d2::Error if db_path is not able to create a database.
sourcefn create_database_tables(&self) -> Result<(), Error>
fn create_database_tables(&self) -> Result<(), Error>
It generates the database tables. SQL queries are hardcoded in the trait implementation.
Context: Schema
Errors
Will return Error if unable to create own tables.
sourcefn drop_database_tables(&self) -> Result<(), Error>
fn drop_database_tables(&self) -> Result<(), Error>
sourcefn load_persistent_torrents<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<Vec<(InfoHash, u32)>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn load_persistent_torrents<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<Vec<(InfoHash, u32)>, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
It loads the torrent metrics data from the database.
It returns an array of tuples with the torrent
InfoHash and the
completed counter
which is the number of times the torrent has been downloaded.
See Entry::completed.
Context: Torrent Metrics
Errors
Will return Err if unable to load.
sourcefn save_persistent_torrent<'life0, 'life1, 'async_trait>(
&'life0 self,
info_hash: &'life1 InfoHash,
completed: u32
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn save_persistent_torrent<'life0, 'life1, 'async_trait>( &'life0 self, info_hash: &'life1 InfoHash, completed: u32 ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
It saves the torrent metrics data into the database.
Context: Torrent Metrics
Errors
Will return Err if unable to save.
sourcefn load_whitelist<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<Vec<InfoHash>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn load_whitelist<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<Vec<InfoHash>, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
It loads the whitelisted torrents from the database.
Context: Whitelist
Errors
Will return Err if unable to load.
sourcefn get_info_hash_from_whitelist<'life0, 'life1, 'async_trait>(
&'life0 self,
info_hash: &'life1 InfoHash
) -> Pin<Box<dyn Future<Output = Result<Option<InfoHash>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_info_hash_from_whitelist<'life0, 'life1, 'async_trait>( &'life0 self, info_hash: &'life1 InfoHash ) -> Pin<Box<dyn Future<Output = Result<Option<InfoHash>, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
It checks if the torrent is whitelisted.
It returns Some(InfoHash) if the torrent is whitelisted, None otherwise.
Context: Whitelist
Errors
Will return Err if unable to load.
sourcefn add_info_hash_to_whitelist<'life0, 'async_trait>(
&'life0 self,
info_hash: InfoHash
) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn add_info_hash_to_whitelist<'life0, 'async_trait>( &'life0 self, info_hash: InfoHash ) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
sourcefn remove_info_hash_from_whitelist<'life0, 'async_trait>(
&'life0 self,
info_hash: InfoHash
) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn remove_info_hash_from_whitelist<'life0, 'async_trait>( &'life0 self, info_hash: InfoHash ) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
It removes the torrent from the whitelist.
Context: Whitelist
Errors
Will return Err if unable to save.
sourcefn load_keys<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<Vec<ExpiringKey>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn load_keys<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<Vec<ExpiringKey>, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
It loads the expiring authentication keys from the database.
Context: Authentication Keys
Errors
Will return Err if unable to load.
sourcefn get_key_from_keys<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 Key
) -> Pin<Box<dyn Future<Output = Result<Option<ExpiringKey>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_key_from_keys<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 Key ) -> Pin<Box<dyn Future<Output = Result<Option<ExpiringKey>, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
It gets an expiring authentication key from the database.
It returns Some(ExpiringKey) if a ExpiringKey
with the input Key exists, None otherwise.
Context: Authentication Keys
Errors
Will return Err if unable to load.
sourcefn add_key_to_keys<'life0, 'life1, 'async_trait>(
&'life0 self,
auth_key: &'life1 ExpiringKey
) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn add_key_to_keys<'life0, 'life1, 'async_trait>( &'life0 self, auth_key: &'life1 ExpiringKey ) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
It adds an expiring authentication key to the database.
Context: Authentication Keys
Errors
Will return Err if unable to save.
sourcefn remove_key_from_keys<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 Key
) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn remove_key_from_keys<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 Key ) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
It removes an expiring authentication key from the database.
Context: Authentication Keys
Errors
Will return Err if unable to load.
Provided Methods§
sourcefn is_info_hash_whitelisted<'life0, 'life1, 'async_trait>(
&'life0 self,
info_hash: &'life1 InfoHash
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn is_info_hash_whitelisted<'life0, 'life1, 'async_trait>( &'life0 self, info_hash: &'life1 InfoHash ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
It checks if the torrent is whitelisted.
Context: Whitelist
Errors
Will return Err if unable to load.