Trait 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(&self) -> Result<PersistentTorrents, Error>; fn save_persistent_torrent( &self, info_hash: &InfoHash, downloaded: u32, ) -> Result<(), Error>; fn load_whitelist(&self) -> Result<Vec<InfoHash>, Error>; fn get_info_hash_from_whitelist( &self, info_hash: InfoHash, ) -> Result<Option<InfoHash>, Error>; fn add_info_hash_to_whitelist( &self, info_hash: InfoHash, ) -> Result<usize, Error>; fn remove_info_hash_from_whitelist( &self, info_hash: InfoHash, ) -> Result<usize, Error>; fn load_keys(&self) -> Result<Vec<PeerKey>, Error>; fn get_key_from_keys(&self, key: &Key) -> Result<Option<PeerKey>, Error>; fn add_key_to_keys(&self, auth_key: &PeerKey) -> Result<usize, Error>; fn remove_key_from_keys(&self, key: &Key) -> Result<usize, Error>; // Provided method fn is_info_hash_whitelisted( &self, info_hash: InfoHash, ) -> Result<bool, Error> { ... }
}
Expand description

The persistence trait. It contains all the methods to interact with the database.

Required Methods§

Source

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.

Source

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.

Source

fn drop_database_tables(&self) -> Result<(), Error>

It drops the database tables.

§Context: Schema
§Errors

Will return Err if unable to drop tables.

Source

fn load_persistent_torrents(&self) -> Result<PersistentTorrents, Error>

It loads the torrent metrics data from the database.

It returns an array of tuples with the torrent InfoHash and the downloaded counter which is the number of times the torrent has been downloaded. See Entry::downloaded.

§Context: Torrent Metrics
§Errors

Will return Err if unable to load.

Source

fn save_persistent_torrent( &self, info_hash: &InfoHash, downloaded: u32, ) -> Result<(), Error>

It saves the torrent metrics data into the database.

§Context: Torrent Metrics
§Errors

Will return Err if unable to save.

Source

fn load_whitelist(&self) -> Result<Vec<InfoHash>, Error>

It loads the whitelisted torrents from the database.

§Context: Whitelist
§Errors

Will return Err if unable to load.

Source

fn get_info_hash_from_whitelist( &self, info_hash: InfoHash, ) -> Result<Option<InfoHash>, Error>

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.

Source

fn add_info_hash_to_whitelist( &self, info_hash: InfoHash, ) -> Result<usize, Error>

It adds the torrent to the whitelist.

§Context: Whitelist
§Errors

Will return Err if unable to save.

Source

fn remove_info_hash_from_whitelist( &self, info_hash: InfoHash, ) -> Result<usize, Error>

It removes the torrent from the whitelist.

§Context: Whitelist
§Errors

Will return Err if unable to save.

Source

fn load_keys(&self) -> Result<Vec<PeerKey>, Error>

It loads the expiring authentication keys from the database.

§Context: Authentication Keys
§Errors

Will return Err if unable to load.

Source

fn get_key_from_keys(&self, key: &Key) -> Result<Option<PeerKey>, Error>

It gets an expiring authentication key from the database.

It returns Some(PeerKey) if a PeerKey with the input Key exists, None otherwise.

§Context: Authentication Keys
§Errors

Will return Err if unable to load.

Source

fn add_key_to_keys(&self, auth_key: &PeerKey) -> Result<usize, Error>

It adds an expiring authentication key to the database.

§Context: Authentication Keys
§Errors

Will return Err if unable to save.

Source

fn remove_key_from_keys(&self, key: &Key) -> Result<usize, Error>

It removes an expiring authentication key from the database.

§Context: Authentication Keys
§Errors

Will return Err if unable to load.

Provided Methods§

Source

fn is_info_hash_whitelisted(&self, info_hash: InfoHash) -> Result<bool, Error>

It checks if the torrent is whitelisted.

§Context: Whitelist
§Errors

Will return Err if unable to load.

Implementors§