@@ -595,7 +595,7 @@ impl SessionContainer {
595595 return None ;
596596 } )
597597 }
598-
598+
599599 fn register_finalized_handshake ( & self , token : usize , id : Option < & ethereum_types:: H512 > ) {
600600 let node_id = match id {
601601 Some ( id) => id. clone ( ) ,
@@ -608,7 +608,7 @@ impl SessionContainer {
608608
609609 // register this session.
610610 if let Some ( old) = self . node_id_to_session . lock ( ) . insert ( node_id, token) {
611- // in scenarios where we did have registered the session to this node,
611+ // in scenarios where we did have registered the session to this node,
612612 // the token id wont change.
613613 // but still we need a lock to node_id_to_session anyway.
614614 if old != token {
@@ -839,7 +839,6 @@ impl Host {
839839
840840 let mut peers = Vec :: with_capacity ( sessions. len ( ) ) ;
841841
842-
843842 for peer_id in sessions. keys ( ) {
844843 peers. push ( peer_id. clone ( ) ) ;
845844 }
@@ -989,7 +988,6 @@ impl Host {
989988 }
990989
991990 fn connect_peers ( & self , io : & IoContext < NetworkIoMessage > ) {
992-
993991 let ( min_peers, pin, max_handshakes, allow_ips, self_id) = {
994992 let info = self . info . read ( ) ;
995993 if info. capabilities . is_empty ( ) {
@@ -1005,15 +1003,20 @@ impl Host {
10051003 * info. id ( ) ,
10061004 )
10071005 } ;
1008-
1006+
10091007 let ( mut handshake_count, egress_count, ingress_count) = self . session_count ( ) ;
10101008 // we clone the reserved nodes, to avoid deadlocks and reduce locking time.
1011- let reserved_nodes = Arc :: new ( self . reserved_nodes . read ( ) . clone ( ) ) ;
1012- let unconnected_reserved_nodes: Vec < NodeId > = reserved_nodes. as_ref ( ) . into_iter ( ) . filter ( |f| !self . have_session ( f) ) . cloned ( ) . collect ( ) ;
1009+ let reserved_nodes = Arc :: new ( self . reserved_nodes . read ( ) . clone ( ) ) ;
1010+ let unconnected_reserved_nodes: Vec < NodeId > = reserved_nodes
1011+ . as_ref ( )
1012+ . into_iter ( )
1013+ . filter ( |f| !self . have_session ( f) )
1014+ . cloned ( )
1015+ . collect ( ) ;
10131016
10141017 // reserved peers are already findable in the SessionContainer, even they are handshaking.
10151018 // so we wont trigger a second handshake here.
1016-
1019+
10171020 let mut started: usize = 0 ;
10181021
10191022 for reserved in & unconnected_reserved_nodes {
@@ -1034,21 +1037,23 @@ impl Host {
10341037
10351038 // ip filter:
10361039 //.nodes(&allow_ips))
1037- let number_of_connects_to_make = ( min_peers as usize ) . min ( max_handshakes_per_round. min ( max_handshakes - handshake_count) ) ;
1038-
1039- let nodes_to_connect = self . nodes . read ( ) . nodes_filtered ( number_of_connects_to_make,
1040- & allow_ips,
1041- |n : & Node | {
1042- n. id != self_id
1043- && !& reserved_nodes. contains ( & n. id )
1044- && self . filter . as_ref ( ) . map_or ( true , |f| {
1045- f. connection_allowed ( & self_id, & n. id , ConnectionDirection :: Outbound ) } )
1046- && !self . have_session ( & n. id ) // alternative strategy: we might also get an list of active connections, instead of locking here to figure out if we have a session or not.
1047- } ) ;
1040+ let number_of_connects_to_make = ( min_peers as usize )
1041+ . min ( max_handshakes_per_round. min ( max_handshakes - handshake_count) ) ;
1042+
1043+ let nodes_to_connect =
1044+ self . nodes
1045+ . read ( )
1046+ . nodes_filtered ( number_of_connects_to_make, & allow_ips, |n : & Node | {
1047+ n. id != self_id
1048+ && !& reserved_nodes. contains ( & n. id )
1049+ && self . filter . as_ref ( ) . map_or ( true , |f| {
1050+ f. connection_allowed ( & self_id, & n. id , ConnectionDirection :: Outbound )
1051+ } )
1052+ && !self . have_session ( & n. id ) // alternative strategy: we might also get an list of active connections, instead of locking here to figure out if we have a session or not.
1053+ } ) ;
10481054
10491055 // now connect to nodes from the node table.
1050- for id in nodes_to_connect
1051- {
1056+ for id in nodes_to_connect {
10521057 self . connect_peer ( & id, io) ;
10531058 started += 1 ;
10541059 }
@@ -1172,7 +1177,7 @@ impl Host {
11721177 }
11731178 Ok ( SessionData :: Ready ) => {
11741179 let ( _, egress_count, ingress_count) = self . session_count ( ) ;
1175-
1180+
11761181 let mut s = session. lock ( ) ;
11771182 self . sessions . register_finalized_handshake ( token, s. id ( ) ) ;
11781183 let ( min_peers, mut max_peers, reserved_only, self_id) = {
@@ -1419,7 +1424,7 @@ impl Host {
14191424 let mut expired_session = None ;
14201425 if token >= FIRST_SESSION {
14211426 // we can shorten the session read lock here, if this causes a deadlock.
1422- // on the other hand it is good, so not that many sessions manipulations can take place
1427+ // on the other hand it is good, so not that many sessions manipulations can take place
14231428 // at the same time.
14241429 let sessions = self . sessions . sessions . read ( ) ;
14251430 if let Some ( session) = sessions. get ( & token) . cloned ( ) {
0 commit comments