2022-08-07 19:42:22 +02:00
mod data ;
pub use data ::Data ;
2022-10-09 17:25:06 +02:00
use ruma ::{
2023-07-29 14:30:48 +00:00
serde ::Base64 , OwnedDeviceId , OwnedEventId , OwnedRoomId , OwnedServerName ,
OwnedServerSigningKeyId , OwnedUserId ,
2022-10-09 17:25:06 +02:00
} ;
2022-08-07 19:42:22 +02:00
2022-10-05 09:34:25 +02:00
use crate ::api ::server_server ::FedDest ;
2022-08-07 19:42:22 +02:00
2023-03-18 08:58:20 +01:00
use crate ::{ services , Config , Error , Result } ;
2023-08-02 01:00:06 +02:00
use futures_util ::FutureExt ;
2024-04-27 11:10:13 +03:00
use hickory_resolver ::TokioAsyncResolver ;
2023-08-02 01:00:06 +02:00
use hyper ::{
client ::connect ::dns ::{ GaiResolver , Name } ,
service ::Service as HyperService ,
} ;
use reqwest ::dns ::{ Addrs , Resolve , Resolving } ;
2021-01-14 21:32:22 -05:00
use ruma ::{
2021-06-30 09:52:01 +02:00
api ::{
2022-02-18 15:33:14 +01:00
client ::sync ::sync_events ,
2021-06-30 09:52:01 +02:00
federation ::discovery ::{ ServerSigningKeys , VerifyKey } ,
} ,
2022-10-09 17:26:53 +02:00
DeviceId , RoomVersionId , ServerName , UserId ,
2021-01-14 21:32:22 -05:00
} ;
2021-06-06 16:58:32 +04:30
use std ::{
collections ::{ BTreeMap , HashMap } ,
2023-08-02 01:00:06 +02:00
error ::Error as StdError ,
2021-06-08 17:50:06 +04:30
fs ,
2023-08-02 01:00:06 +02:00
future ::{ self , Future } ,
iter ,
2022-01-27 10:19:28 -06:00
net ::{ IpAddr , SocketAddr } ,
2021-06-06 16:58:32 +04:30
path ::PathBuf ,
2023-07-29 14:30:48 +00:00
sync ::{
atomic ::{ self , AtomicBool } ,
2024-03-05 20:15:11 +00:00
Arc , RwLock as StdRwLock ,
2023-07-29 14:30:48 +00:00
} ,
2021-06-06 16:58:32 +04:30
time ::{ Duration , Instant } ,
} ;
2024-03-05 14:22:54 +00:00
use tokio ::sync ::{ broadcast , watch ::Receiver , Mutex , RwLock , Semaphore } ;
2023-03-18 08:58:20 +01:00
use tracing ::{ error , info } ;
2020-07-23 23:03:24 -04:00
2023-08-01 14:48:50 -10:00
use base64 ::{ engine ::general_purpose , Engine as _ } ;
2022-10-09 17:25:06 +02:00
type WellKnownMap = HashMap < OwnedServerName , ( FedDest , String ) > ;
2021-08-26 23:11:13 +02:00
type TlsNameMap = HashMap < String , ( Vec < IpAddr > , u16 ) > ;
2021-05-20 23:46:52 +02:00
type RateLimitState = ( Instant , u32 ) ; // Time if last failed try, number of failed tries
2021-07-14 12:31:38 +02:00
type SyncHandle = (
2022-02-18 15:33:14 +01:00
Option < String > , // since
Receiver < Option < Result < sync_events ::v3 ::Response > > > , // rx
2021-07-14 12:31:38 +02:00
) ;
2022-10-05 12:45:54 +02:00
pub struct Service {
2022-10-08 13:02:52 +02:00
pub db : & 'static dyn Data ,
2022-08-07 19:42:22 +02:00
2021-03-04 12:35:12 +00:00
pub actual_destination_cache : Arc < RwLock < WellKnownMap > > , // actual_destination, host
2024-03-05 20:15:11 +00:00
pub tls_name_override : Arc < StdRwLock < TlsNameMap > > ,
2022-02-06 20:23:22 +01:00
pub config : Config ,
2023-06-04 00:12:35 +02:00
allow_registration : RwLock < bool > ,
2020-09-15 16:13:54 +02:00
keypair : Arc < ruma ::signatures ::Ed25519KeyPair > ,
2020-12-06 11:05:51 +01:00
dns_resolver : TokioAsyncResolver ,
2022-10-09 15:34:36 +02:00
jwt_decoding_key : Option < jsonwebtoken ::DecodingKey > ,
2022-01-28 12:42:47 -06:00
federation_client : reqwest ::Client ,
default_client : reqwest ::Client ,
2021-11-01 01:58:26 +00:00
pub stable_room_versions : Vec < RoomVersionId > ,
pub unstable_room_versions : Vec < RoomVersionId > ,
2022-10-09 17:25:06 +02:00
pub bad_event_ratelimiter : Arc < RwLock < HashMap < OwnedEventId , RateLimitState > > > ,
2021-07-18 20:43:39 +02:00
pub bad_signature_ratelimiter : Arc < RwLock < HashMap < Vec < String > , RateLimitState > > > ,
2023-09-13 20:54:53 +02:00
pub bad_query_ratelimiter : Arc < RwLock < HashMap < OwnedServerName , RateLimitState > > > ,
2022-10-09 17:25:06 +02:00
pub servername_ratelimiter : Arc < RwLock < HashMap < OwnedServerName , Arc < Semaphore > > > > ,
pub sync_receivers : RwLock < HashMap < ( OwnedUserId , OwnedDeviceId ) , SyncHandle > > ,
pub roomid_mutex_insert : RwLock < HashMap < OwnedRoomId , Arc < Mutex < ( ) > > > > ,
2024-03-05 14:22:54 +00:00
pub roomid_mutex_state : RwLock < HashMap < OwnedRoomId , Arc < Mutex < ( ) > > > > ,
pub roomid_mutex_federation : RwLock < HashMap < OwnedRoomId , Arc < Mutex < ( ) > > > > , // this lock will be held longer
2022-10-09 17:25:06 +02:00
pub roomid_federationhandletime : RwLock < HashMap < OwnedRoomId , ( OwnedEventId , Instant ) > > ,
2024-05-31 21:46:38 +01:00
server_user : OwnedUserId ,
2022-05-30 12:58:43 +02:00
pub stateres_mutex : Arc < Mutex < ( ) > > ,
2021-07-14 07:07:08 +00:00
pub rotate : RotationHandler ,
2023-03-18 08:58:20 +01:00
pub shutdown : AtomicBool ,
2020-05-03 17:25:31 +02:00
}
2021-07-14 07:07:08 +00:00
/// Handles "rotation" of long-polling requests. "Rotation" in this context is similar to "rotation" of log files and the like.
///
/// This is utilized to have sync workers return early and release read locks on the database.
2024-05-05 13:11:44 +01:00
pub struct RotationHandler ( broadcast ::Sender < ( ) > ) ;
2021-07-14 07:07:08 +00:00
impl RotationHandler {
pub fn new ( ) -> Self {
2024-05-05 13:11:44 +01:00
let s = broadcast ::channel ( 1 ) . 0 ;
Self ( s )
2021-07-14 07:07:08 +00:00
}
pub fn watch ( & self ) -> impl Future < Output = ( ) > {
let mut r = self . 0. subscribe ( ) ;
async move {
let _ = r . recv ( ) . await ;
}
}
pub fn fire ( & self ) {
let _ = self . 0. send ( ( ) ) ;
}
}
2021-07-14 12:31:38 +02:00
impl Default for RotationHandler {
fn default ( ) -> Self {
Self ::new ( )
}
}
2023-08-02 01:00:06 +02:00
pub struct Resolver {
inner : GaiResolver ,
2024-03-05 20:15:11 +00:00
overrides : Arc < StdRwLock < TlsNameMap > > ,
2023-08-02 01:00:06 +02:00
}
impl Resolver {
2024-03-05 20:15:11 +00:00
pub fn new ( overrides : Arc < StdRwLock < TlsNameMap > > ) -> Self {
2023-08-02 01:00:06 +02:00
Resolver {
inner : GaiResolver ::new ( ) ,
overrides ,
}
}
}
impl Resolve for Resolver {
fn resolve ( & self , name : Name ) -> Resolving {
2024-01-24 15:11:17 -08:00
self . overrides
. read ( )
2024-03-05 14:22:54 +00:00
. unwrap ( )
2024-01-24 15:11:17 -08:00
. get ( name . as_str ( ) )
. and_then ( | ( override_name , port ) | {
2024-01-25 20:33:15 -08:00
override_name . first ( ) . map ( | first_name | {
2024-01-24 15:11:17 -08:00
let x : Box < dyn Iterator < Item = SocketAddr > + Send > =
Box ::new ( iter ::once ( SocketAddr ::new ( * first_name , * port ) ) ) ;
let x : Resolving = Box ::pin ( future ::ready ( Ok ( x ) ) ) ;
x
} )
} )
. unwrap_or_else ( | | {
let this = & mut self . inner . clone ( ) ;
Box ::pin ( HyperService ::< Name > ::call ( this , name ) . map ( | result | {
result
. map ( | addrs | -> Addrs { Box ::new ( addrs ) } )
. map_err ( | err | -> Box < dyn StdError + Send + Sync > { Box ::new ( err ) } )
} ) )
} )
2023-08-02 01:00:06 +02:00
}
}
2022-10-05 12:45:54 +02:00
impl Service {
2022-10-08 13:02:52 +02:00
pub fn load ( db : & 'static dyn Data , config : Config ) -> Result < Self > {
2022-09-07 13:25:51 +02:00
let keypair = db . load_keypair ( ) ;
2020-09-15 21:46:10 +02:00
let keypair = match keypair {
Ok ( k ) = > k ,
Err ( e ) = > {
error! ( " Keypair invalid. Deleting... " ) ;
2022-10-08 13:02:52 +02:00
db . remove_keypair ( ) ? ;
2020-09-15 21:46:10 +02:00
return Err ( e ) ;
}
} ;
2020-05-03 17:25:31 +02:00
2024-03-05 20:15:11 +00:00
let tls_name_override = Arc ::new ( StdRwLock ::new ( TlsNameMap ::new ( ) ) ) ;
2020-12-19 16:00:11 +01:00
2021-02-07 17:38:45 +01:00
let jwt_decoding_key = config
. jwt_secret
. as_ref ( )
2022-10-09 15:34:36 +02:00
. map ( | secret | jsonwebtoken ::DecodingKey ::from_secret ( secret . as_bytes ( ) ) ) ;
2021-02-07 17:38:45 +01:00
2022-01-28 12:42:47 -06:00
let default_client = reqwest_client_builder ( & config ) ? . build ( ) ? ;
let federation_client = reqwest_client_builder ( & config ) ?
2024-01-24 15:11:17 -08:00
. dns_resolver ( Arc ::new ( Resolver ::new ( tls_name_override . clone ( ) ) ) )
2022-01-27 10:19:28 -06:00
. build ( ) ? ;
2022-01-24 18:42:15 -06:00
2021-11-01 01:58:26 +00:00
// Supported and stable room versions
2022-02-18 13:41:37 +01:00
let stable_room_versions = vec! [
RoomVersionId ::V6 ,
RoomVersionId ::V7 ,
RoomVersionId ::V8 ,
RoomVersionId ::V9 ,
2022-10-10 15:00:44 +02:00
RoomVersionId ::V10 ,
2024-04-12 05:14:39 +00:00
RoomVersionId ::V11 ,
2022-10-10 15:00:44 +02:00
] ;
2022-10-15 12:16:32 +02:00
// Experimental, partially supported room versions
2024-04-16 22:45:04 +01:00
let unstable_room_versions = vec! [ RoomVersionId ::V3 , RoomVersionId ::V4 , RoomVersionId ::V5 ] ;
2021-11-01 01:58:26 +00:00
2021-11-05 20:47:11 +00:00
let mut s = Self {
2023-06-04 00:12:35 +02:00
allow_registration : RwLock ::new ( config . allow_registration ) ,
2024-05-31 21:46:38 +01:00
server_user : UserId ::parse ( format! ( " @conduit: {} " , & config . server_name ) )
. expect ( " @conduit:server_name is valid " ) ,
2022-09-07 13:25:51 +02:00
db ,
2020-12-06 11:05:51 +01:00
config ,
2020-09-15 21:46:10 +02:00
keypair : Arc ::new ( keypair ) ,
2022-02-07 12:55:21 +01:00
dns_resolver : TokioAsyncResolver ::tokio_from_system_conf ( ) . map_err ( | e | {
error! (
" Failed to set up trust dns resolver with system config: {} " ,
e
) ;
2021-01-29 11:20:33 -05:00
Error ::bad_config ( " Failed to set up trust dns resolver with system config. " )
} ) ? ,
2021-04-15 22:07:27 -03:00
actual_destination_cache : Arc ::new ( RwLock ::new ( WellKnownMap ::new ( ) ) ) ,
tls_name_override ,
2022-01-28 12:42:47 -06:00
federation_client ,
default_client ,
2021-03-15 09:48:19 +01:00
jwt_decoding_key ,
2021-11-01 01:58:26 +00:00
stable_room_versions ,
unstable_room_versions ,
2021-07-18 20:43:39 +02:00
bad_event_ratelimiter : Arc ::new ( RwLock ::new ( HashMap ::new ( ) ) ) ,
bad_signature_ratelimiter : Arc ::new ( RwLock ::new ( HashMap ::new ( ) ) ) ,
2023-09-13 20:54:53 +02:00
bad_query_ratelimiter : Arc ::new ( RwLock ::new ( HashMap ::new ( ) ) ) ,
2021-07-18 20:43:39 +02:00
servername_ratelimiter : Arc ::new ( RwLock ::new ( HashMap ::new ( ) ) ) ,
2021-08-03 11:10:58 +02:00
roomid_mutex_state : RwLock ::new ( HashMap ::new ( ) ) ,
roomid_mutex_insert : RwLock ::new ( HashMap ::new ( ) ) ,
2021-07-18 20:43:39 +02:00
roomid_mutex_federation : RwLock ::new ( HashMap ::new ( ) ) ,
2022-05-30 12:58:43 +02:00
roomid_federationhandletime : RwLock ::new ( HashMap ::new ( ) ) ,
stateres_mutex : Arc ::new ( Mutex ::new ( ( ) ) ) ,
2021-07-18 20:43:39 +02:00
sync_receivers : RwLock ::new ( HashMap ::new ( ) ) ,
2021-07-14 07:07:08 +00:00
rotate : RotationHandler ::new ( ) ,
2023-03-18 08:58:20 +01:00
shutdown : AtomicBool ::new ( false ) ,
2021-06-08 17:50:06 +04:30
} ;
fs ::create_dir_all ( s . get_media_folder ( ) ) ? ;
2021-11-05 20:47:11 +00:00
if ! s
. supported_room_versions ( )
. contains ( & s . config . default_room_version )
{
2022-12-18 09:44:46 +01:00
error! ( config = ? s . config . default_room_version , fallback = ? crate ::config ::default_default_room_version ( ) , " Room version in config isn't supported, falling back to default version " ) ;
2022-10-15 10:42:14 +02:00
s . config . default_room_version = crate ::config ::default_default_room_version ( ) ;
2021-11-05 20:47:11 +00:00
} ;
2021-06-08 17:50:06 +04:30
Ok ( s )
2020-05-03 17:25:31 +02:00
}
/// Returns this server's keypair.
2020-06-05 18:19:26 +02:00
pub fn keypair ( & self ) -> & ruma ::signatures ::Ed25519KeyPair {
2020-05-03 17:25:31 +02:00
& self . keypair
}
2022-01-24 18:42:15 -06:00
/// Returns a reqwest client which can be used to send requests
2022-01-28 12:42:47 -06:00
pub fn default_client ( & self ) -> reqwest ::Client {
// Client is cheap to clone (Arc wrapper) and avoids lifetime issues
self . default_client . clone ( )
2022-01-24 18:42:15 -06:00
}
2021-08-26 23:11:13 +02:00
2022-01-27 10:19:28 -06:00
/// Returns a client used for resolving .well-knowns
2022-01-28 12:42:47 -06:00
pub fn federation_client ( & self ) -> reqwest ::Client {
// Client is cheap to clone (Arc wrapper) and avoids lifetime issues
self . federation_client . clone ( )
2020-05-03 17:25:31 +02:00
}
2021-07-29 08:36:01 +02:00
#[ tracing::instrument(skip(self)) ]
2020-05-03 17:25:31 +02:00
pub fn next_count ( & self ) -> Result < u64 > {
2022-10-05 15:33:57 +02:00
self . db . next_count ( )
2020-05-03 17:25:31 +02:00
}
2021-07-29 08:36:01 +02:00
#[ tracing::instrument(skip(self)) ]
2020-05-03 17:25:31 +02:00
pub fn current_count ( & self ) -> Result < u64 > {
2022-10-05 15:33:57 +02:00
self . db . current_count ( )
}
2023-07-29 20:01:38 +02:00
#[ tracing::instrument(skip(self)) ]
pub fn last_check_for_updates_id ( & self ) -> Result < u64 > {
self . db . last_check_for_updates_id ( )
}
#[ tracing::instrument(skip(self)) ]
pub fn update_check_for_updates_id ( & self , id : u64 ) -> Result < ( ) > {
self . db . update_check_for_updates_id ( id )
}
2022-10-05 15:33:57 +02:00
pub async fn watch ( & self , user_id : & UserId , device_id : & DeviceId ) -> Result < ( ) > {
self . db . watch ( user_id , device_id ) . await
}
pub fn cleanup ( & self ) -> Result < ( ) > {
self . db . cleanup ( )
}
2020-07-17 16:00:39 -04:00
pub fn server_name ( & self ) -> & ServerName {
2020-12-05 21:03:43 +01:00
self . config . server_name . as_ref ( )
2020-06-06 19:02:31 +02:00
}
2024-05-31 21:46:38 +01:00
pub fn server_user ( & self ) -> & UserId {
self . server_user . as_ref ( )
}
2020-07-23 23:03:24 -04:00
pub fn max_request_size ( & self ) -> u32 {
2020-12-05 21:03:43 +01:00
self . config . max_request_size
2020-07-23 23:03:24 -04:00
}
2022-09-09 19:17:29 +02:00
pub fn max_fetch_prev_events ( & self ) -> u16 {
self . config . max_fetch_prev_events
}
2023-06-04 00:12:35 +02:00
/// Allows for the temporary (non-persistant) toggling of registration
pub async fn set_registration ( & self , status : bool ) {
let mut lock = self . allow_registration . write ( ) . await ;
* lock = status ;
}
/// Checks whether user registration is allowed
pub async fn allow_registration ( & self ) -> bool {
* self . allow_registration . read ( ) . await
2020-06-06 19:02:31 +02:00
}
2020-07-26 20:41:10 +02:00
2021-01-01 13:47:53 +01:00
pub fn allow_encryption ( & self ) -> bool {
self . config . allow_encryption
2020-07-26 20:41:10 +02:00
}
2020-10-06 21:04:51 +02:00
2021-01-01 13:47:53 +01:00
pub fn allow_federation ( & self ) -> bool {
self . config . allow_federation
2020-10-06 21:04:51 +02:00
}
2020-12-06 11:05:51 +01:00
2021-09-24 07:16:34 +00:00
pub fn allow_room_creation ( & self ) -> bool {
self . config . allow_room_creation
}
2021-11-01 01:58:26 +00:00
pub fn allow_unstable_room_versions ( & self ) -> bool {
self . config . allow_unstable_room_versions
}
pub fn default_room_version ( & self ) -> RoomVersionId {
2021-11-05 20:47:11 +00:00
self . config . default_room_version . clone ( )
2021-11-01 01:58:26 +00:00
}
2022-06-23 06:58:34 +00:00
pub fn enable_lightning_bolt ( & self ) -> bool {
self . config . enable_lightning_bolt
}
2023-07-29 20:01:38 +02:00
pub fn allow_check_for_updates ( & self ) -> bool {
self . config . allow_check_for_updates
}
2022-10-09 17:25:06 +02:00
pub fn trusted_servers ( & self ) -> & [ OwnedServerName ] {
2021-03-01 09:17:53 -05:00
& self . config . trusted_servers
}
2020-12-06 11:05:51 +01:00
pub fn dns_resolver ( & self ) -> & TokioAsyncResolver {
& self . dns_resolver
}
2021-01-14 21:32:22 -05:00
2022-10-09 15:34:36 +02:00
pub fn jwt_decoding_key ( & self ) -> Option < & jsonwebtoken ::DecodingKey > {
2021-02-07 17:38:45 +01:00
self . jwt_decoding_key . as_ref ( )
}
2021-01-14 21:32:22 -05:00
2021-10-01 15:53:16 +02:00
pub fn turn_password ( & self ) -> & String {
& self . config . turn_password
}
pub fn turn_ttl ( & self ) -> u64 {
self . config . turn_ttl
}
pub fn turn_uris ( & self ) -> & [ String ] {
& self . config . turn_uris
}
pub fn turn_username ( & self ) -> & String {
& self . config . turn_username
}
2021-10-02 00:37:39 +02:00
pub fn turn_secret ( & self ) -> & String {
& self . config . turn_secret
}
2022-04-07 12:11:55 +00:00
pub fn emergency_password ( & self ) -> & Option < String > {
& self . config . emergency_password
}
2021-11-01 01:58:26 +00:00
pub fn supported_room_versions ( & self ) -> Vec < RoomVersionId > {
let mut room_versions : Vec < RoomVersionId > = vec! [ ] ;
2021-11-05 20:47:11 +00:00
room_versions . extend ( self . stable_room_versions . clone ( ) ) ;
2021-11-01 01:58:26 +00:00
if self . allow_unstable_room_versions ( ) {
2021-11-05 20:47:11 +00:00
room_versions . extend ( self . unstable_room_versions . clone ( ) ) ;
2021-11-01 01:58:26 +00:00
} ;
room_versions
}
2021-01-14 21:32:22 -05:00
/// TODO: the key valid until timestamp is only honored in room version > 4
/// Remove the outdated keys and insert the new ones.
///
/// This doesn't actually check that the keys provided are newer than the old set.
2021-08-29 13:25:20 +02:00
pub fn add_signing_key (
& self ,
origin : & ServerName ,
new_keys : ServerSigningKeys ,
2022-10-09 17:25:06 +02:00
) -> Result < BTreeMap < OwnedServerSigningKeyId , VerifyKey > > {
2022-10-05 15:33:57 +02:00
self . db . add_signing_key ( origin , new_keys )
2021-01-14 21:32:22 -05:00
}
/// This returns an empty `Ok(BTreeMap<..>)` when there are no keys found for the server.
pub fn signing_keys_for (
& self ,
origin : & ServerName ,
2022-10-09 17:25:06 +02:00
) -> Result < BTreeMap < OwnedServerSigningKeyId , VerifyKey > > {
2023-07-15 23:43:25 +02:00
let mut keys = self . db . signing_keys_for ( origin ) ? ;
if origin = = self . server_name ( ) {
keys . insert (
format! ( " ed25519: {} " , services ( ) . globals . keypair ( ) . version ( ) )
. try_into ( )
. expect ( " found invalid server signing keys in DB " ) ,
VerifyKey {
key : Base64 ::new ( self . keypair . public_key ( ) . to_vec ( ) ) ,
} ,
) ;
}
Ok ( keys )
2021-01-14 21:32:22 -05:00
}
2021-05-17 10:25:27 +02:00
pub fn database_version ( & self ) -> Result < u64 > {
2022-10-05 15:33:57 +02:00
self . db . database_version ( )
2021-05-17 10:25:27 +02:00
}
pub fn bump_database_version ( & self , new_version : u64 ) -> Result < ( ) > {
2022-10-05 15:33:57 +02:00
self . db . bump_database_version ( new_version )
2021-05-17 10:25:27 +02:00
}
2021-06-04 08:06:12 +04:30
pub fn get_media_folder ( & self ) -> PathBuf {
let mut r = PathBuf ::new ( ) ;
r . push ( self . config . database_path . clone ( ) ) ;
r . push ( " media " ) ;
r
}
2021-06-06 16:58:32 +04:30
pub fn get_media_file ( & self , key : & [ u8 ] ) -> PathBuf {
2021-06-04 08:06:12 +04:30
let mut r = PathBuf ::new ( ) ;
r . push ( self . config . database_path . clone ( ) ) ;
r . push ( " media " ) ;
2023-08-01 14:48:50 -10:00
r . push ( general_purpose ::URL_SAFE_NO_PAD . encode ( key ) ) ;
2021-06-04 08:06:12 +04:30
r
}
2023-03-18 08:58:20 +01:00
2024-05-02 09:26:43 +01:00
pub fn well_known_server ( & self ) -> OwnedServerName {
self . config . well_known_server ( )
}
pub fn well_known_client ( & self ) -> String {
self . config . well_known_client ( )
2023-07-06 10:32:25 +02:00
}
2023-03-18 08:58:20 +01:00
pub fn shutdown ( & self ) {
self . shutdown . store ( true , atomic ::Ordering ::Relaxed ) ;
// On shutdown
info! ( target : " shutdown-sync " , " Received shutdown notification, notifying sync helpers... " ) ;
services ( ) . globals . rotate . fire ( ) ;
}
2020-05-03 17:25:31 +02:00
}
2022-01-24 18:42:15 -06:00
2022-01-27 10:19:28 -06:00
fn reqwest_client_builder ( config : & Config ) -> Result < reqwest ::ClientBuilder > {
2022-01-24 18:42:15 -06:00
let mut reqwest_client_builder = reqwest ::Client ::builder ( )
2023-01-14 21:20:16 +01:00
. pool_max_idle_per_host ( 0 )
2022-01-24 18:42:15 -06:00
. connect_timeout ( Duration ::from_secs ( 30 ) )
. timeout ( Duration ::from_secs ( 60 * 3 ) ) ;
if let Some ( proxy ) = config . proxy . to_proxy ( ) ? {
reqwest_client_builder = reqwest_client_builder . proxy ( proxy ) ;
}
Ok ( reqwest_client_builder )
}