@@ -11,20 +11,23 @@ use crate::protocol::clock::DurationSinceUnixEpoch;
1111use crate :: protocol:: common:: InfoHash ;
1212use crate :: tracker:: key:: AuthKey ;
1313
14- pub struct SqliteDatabase {
14+ pub struct Sqlite {
1515 pool : Pool < SqliteConnectionManager > ,
1616}
1717
18- impl SqliteDatabase {
19- pub fn new ( db_path : & str ) -> Result < SqliteDatabase , r2d2:: Error > {
18+ impl Sqlite {
19+ /// # Errors
20+ ///
21+ /// Will return `r2d2::Error` if `db_path` is not able to create `SqLite` database.
22+ pub fn new ( db_path : & str ) -> Result < Sqlite , r2d2:: Error > {
2023 let cm = SqliteConnectionManager :: file ( db_path) ;
2124 let pool = Pool :: new ( cm) . expect ( "Failed to create r2d2 SQLite connection pool." ) ;
22- Ok ( SqliteDatabase { pool } )
25+ Ok ( Sqlite { pool } )
2326 }
2427}
2528
2629#[ async_trait]
27- impl Database for SqliteDatabase {
30+ impl Database for Sqlite {
2831 fn create_database_tables ( & self ) -> Result < ( ) , database:: Error > {
2932 let create_whitelist_table = "
3033 CREATE TABLE IF NOT EXISTS whitelist (
@@ -86,7 +89,7 @@ impl Database for SqliteDatabase {
8689
8790 Ok ( AuthKey {
8891 key,
89- valid_until : Some ( DurationSinceUnixEpoch :: from_secs ( valid_until as u64 ) ) ,
92+ valid_until : Some ( DurationSinceUnixEpoch :: from_secs ( valid_until. unsigned_abs ( ) ) ) ,
9093 } )
9194 } ) ?;
9295
@@ -191,11 +194,11 @@ impl Database for SqliteDatabase {
191194
192195 if let Some ( row) = rows. next ( ) ? {
193196 let key: String = row. get ( 0 ) . unwrap ( ) ;
194- let valid_until_i64 : i64 = row. get ( 1 ) . unwrap ( ) ;
197+ let valid_until : i64 = row. get ( 1 ) . unwrap ( ) ;
195198
196199 Ok ( AuthKey {
197200 key,
198- valid_until : Some ( DurationSinceUnixEpoch :: from_secs ( valid_until_i64 as u64 ) ) ,
201+ valid_until : Some ( DurationSinceUnixEpoch :: from_secs ( valid_until . unsigned_abs ( ) ) ) ,
199202 } )
200203 } else {
201204 Err ( database:: Error :: QueryReturnedNoRows )
0 commit comments