@@ -111,15 +111,15 @@ pub async fn clear_connections(
111111 self . connections
112112 . lock ( )
113113 . await
114- . retain ( |( conn_user_id, conn_device_id, conn_conn_id) , _| {
114+ . retain ( |( conn_user_id, conn_device_id, conn_conn_id, conn_xff ) , _| {
115115 let retain = user_id. is_none_or ( is_equal_to ! ( conn_user_id) )
116116 && device_id. is_none_or ( is_equal_to ! ( conn_device_id) )
117117 && ( conn_id. is_none ( ) || conn_id == conn_conn_id. as_ref ( ) ) ;
118118
119119 if !retain {
120120 self . db
121121 . userdeviceconnid_conn
122- . del ( ( conn_user_id, conn_device_id, conn_conn_id) ) ;
122+ . del ( ( conn_user_id, conn_device_id, conn_conn_id, conn_xff ) ) ;
123123 }
124124
125125 retain
@@ -129,10 +129,10 @@ pub async fn clear_connections(
129129#[ implement( Service ) ]
130130#[ tracing:: instrument( level = "debug" , skip( self ) ) ]
131131pub async fn drop_connection ( & self , key : & ConnectionKey ) {
132- let mut cache = self . connections . lock ( ) . await ;
133-
134- self . db . userdeviceconnid_conn . del ( key ) ;
135- cache . remove ( key) ;
132+ self . connections
133+ . lock ( )
134+ . await
135+ . remove ( key) ;
136136}
137137
138138#[ implement( Service ) ]
@@ -220,15 +220,7 @@ pub async fn is_connection_stored(&self, key: &ConnectionKey) -> bool {
220220 self . db . userdeviceconnid_conn . contains ( key) . await
221221}
222222
223- #[ inline]
224- pub fn into_connection_key < U , D , C > ( user_id : U , device_id : D , conn_id : Option < C > ) -> ConnectionKey
225- where
226- U : Into < OwnedUserId > ,
227- D : Into < OwnedDeviceId > ,
228- C : Into < ConnectionId > ,
229- {
230- ( user_id. into ( ) , device_id. into ( ) , conn_id. map ( Into :: into) )
231- }
223+
232224
233225#[ implement( Connection ) ]
234226#[ tracing:: instrument( level = "debug" , skip( self , service) ) ]
@@ -373,66 +365,48 @@ fn some_or_sticky<T: Clone>(target: Option<&T>, cached: &mut Option<T>) {
373365 }
374366}
375367
376- #[ implement( Service ) ]
377- pub fn clear_connections (
378- & self ,
379- user_id : Option < & UserId > ,
380- device_id : Option < & DeviceId > ,
381- conn_id : Option < & ConnectionId > ,
382- ) {
383- self . connections . lock ( ) . expect ( "locked" ) . retain (
384- |( conn_user_id, conn_device_id, conn_conn_id, _conn_xff) , _| {
385- !( user_id. is_none_or ( is_equal_to ! ( conn_user_id) )
386- && device_id. is_none_or ( is_equal_to ! ( conn_device_id) )
387- && ( conn_id. is_none ( ) || conn_id == conn_conn_id. as_ref ( ) ) )
388- } ,
389- ) ;
390- }
391368
392- #[ implement( Service ) ]
393- pub fn drop_connection ( & self , key : & ConnectionKey ) {
394- self . connections
395- . lock ( )
396- . expect ( "locked" )
397- . remove ( key) ;
398- }
399369
400370#[ implement( Service ) ]
401- pub fn list_connections ( & self ) -> Vec < ConnectionKey > {
371+ #[ tracing:: instrument( level = "trace" , skip( self ) ) ]
372+ pub async fn list_connections ( & self ) -> Vec < ConnectionKey > {
402373 self . connections
403374 . lock ( )
404- . expect ( "locked" )
375+ . await
405376 . keys ( )
406377 . cloned ( )
407378 . collect ( )
408379}
409380
410381#[ implement( Service ) ]
411- pub fn init_connection ( & self , key : & ConnectionKey ) -> ConnectionVal {
382+ #[ tracing:: instrument( level = "debug" , skip( self ) ) ]
383+ pub async fn init_connection ( & self , key : & ConnectionKey ) -> ConnectionVal {
412384 self . connections
413385 . lock ( )
414- . expect ( "locked" )
386+ . await
415387 . entry ( key. clone ( ) )
416388 . and_modify ( |existing| * existing = ConnectionVal :: default ( ) )
417389 . or_default ( )
418390 . clone ( )
419391}
420392
421393#[ implement( Service ) ]
422- pub fn find_connection ( & self , key : & ConnectionKey ) -> Result < ConnectionVal > {
394+ #[ tracing:: instrument( level = "debug" , skip( self ) ) ]
395+ pub async fn find_connection ( & self , key : & ConnectionKey ) -> Result < ConnectionVal > {
423396 self . connections
424397 . lock ( )
425- . expect ( "locked" )
398+ . await
426399 . get ( key)
427400 . cloned ( )
428401 . ok_or_else ( || err ! ( Request ( NotFound ( "Connection not found." ) ) ) )
429402}
430403
431404#[ implement( Service ) ]
432- pub fn contains_connection ( & self , key : & ConnectionKey ) -> bool {
405+ #[ tracing:: instrument( level = "trace" , skip( self ) ) ]
406+ pub async fn contains_connection ( & self , key : & ConnectionKey ) -> bool {
433407 self . connections
434408 . lock ( )
435- . expect ( "locked" )
409+ . await
436410 . contains_key ( key)
437411}
438412
0 commit comments