@@ -50,12 +50,9 @@ use network::{
5050 client_version:: ClientVersion ,
5151} ;
5252use parity_path:: restrict_permissions_owner;
53- use parking_lot:: {
54- Mutex , RwLock ,
55- } ;
53+ use parking_lot:: { Mutex , RwLock } ;
5654use stats:: { PrometheusMetrics , PrometheusRegistry } ;
5755
58-
5956const MAX_SESSIONS : usize = 2048 + MAX_HANDSHAKES ;
6057const MAX_HANDSHAKES : usize = 1024 ;
6158
@@ -375,7 +372,7 @@ impl SessionContainer {
375372 sessions : Arc :: new ( RwLock :: new ( std:: collections:: BTreeMap :: new ( ) ) ) ,
376373 expired_sessions : Arc :: new ( RwLock :: new ( Vec :: new ( ) ) ) ,
377374 node_id_to_session : Mutex :: new ( BTreeMap :: new ( ) ) ,
378- sessions_token_max : Mutex :: new ( 0 )
375+ sessions_token_max : Mutex :: new ( 0 ) ,
379376 }
380377 }
381378
@@ -447,20 +444,20 @@ impl SessionContainer {
447444 let new_session_arc = Arc :: new ( Mutex :: new ( session) ) ;
448445 let old_session_o =
449446 sessions. insert ( * existing_peer_id, new_session_arc) ;
450-
447+
451448 match old_session_o {
452449 Some ( old) => {
453450 // we remember the expired session, so it can get closed and cleaned up in a nice way later.
454451 expired_session. push ( old) ;
455- } ,
452+ }
456453 None => {
457454 // we have a cache missmatch.
458455 // but the only thing is missing is a clean ending of the old session.
459456 // nothing mission critical.
460457 error ! ( target: "network" , "host cache inconsistency: Session for node id {} was not found in sessions map, but it should be there." , node_id) ;
461- } ,
458+ }
462459 }
463-
460+
464461 // in this context, the stream might already be unregistered ?!
465462 // we can just register the stream again.
466463 if let Err ( err) = io. register_stream ( * existing_peer_id) {
@@ -488,7 +485,10 @@ impl SessionContainer {
488485 // we reuse that peer_id, so other in flight actions are pointing to the same node again.
489486 match Session :: new ( io, socket, existing_peer_id. clone ( ) , id, nonce, host) {
490487 Ok ( new_session) => {
491- sessions. insert ( existing_peer_id. clone ( ) , Arc :: new ( Mutex :: new ( new_session) ) ) ;
488+ sessions. insert (
489+ existing_peer_id. clone ( ) ,
490+ Arc :: new ( Mutex :: new ( new_session) ) ,
491+ ) ;
492492 return Ok ( existing_peer_id. clone ( ) ) ;
493493 }
494494 Err ( err) => {
@@ -536,14 +536,15 @@ impl SessionContainer {
536536 // if we dont know a NodeID
537537 // debug!(target: "network", "Session create error: {:?}", e);
538538 }
539-
539+
540540 fn get_session_for ( & self , id : & NodeId ) -> Option < SharedSession > {
541-
542- self . node_id_to_session . lock ( ) . get ( id) . map_or ( None , |peer_id| {
543- let sessions = self . sessions . read ( ) ;
544- sessions. get ( peer_id) . cloned ( )
545- } )
546-
541+ self . node_id_to_session
542+ . lock ( )
543+ . get ( id)
544+ . map_or ( None , |peer_id| {
545+ let sessions = self . sessions . read ( ) ;
546+ sessions. get ( peer_id) . cloned ( )
547+ } )
547548 }
548549}
549550
@@ -843,7 +844,6 @@ impl Host {
843844 }
844845
845846 fn have_session ( & self , id : & NodeId ) -> bool {
846-
847847 self . sessions . get_session_for ( id) . is_some ( )
848848 }
849849
@@ -1745,7 +1745,7 @@ impl IoHandler<NetworkIoMessage> for Host {
17451745 . update_socket ( reg, event_loop)
17461746 . expect ( "Error updating socket" ) ;
17471747 }
1748- } ,
1748+ }
17491749 }
17501750 }
17511751}
0 commit comments