@@ -3125,14 +3125,17 @@ where
31253125 // The protocol negotiation occurs once a message is sent/received. Once this happens we
31263126 // update the type of peer that this is in order to determine which kind of routing should
31273127 // occur.
3128- let connected_peer = self . connected_peers . entry ( peer_id) . or_insert ( PeerDetails {
3129- kind : PeerKind :: Floodsub ,
3130- connections : vec ! [ ] ,
3131- outbound : false ,
3132- sender : Sender :: new ( self . config . connection_handler_queue_len ( ) ) ,
3133- topics : Default :: default ( ) ,
3134- dont_send : LinkedHashMap :: new ( ) ,
3135- } ) ;
3128+ let connected_peer = self
3129+ . connected_peers
3130+ . entry ( peer_id)
3131+ . or_insert_with ( || PeerDetails {
3132+ kind : PeerKind :: Floodsub ,
3133+ connections : vec ! [ ] ,
3134+ outbound : false ,
3135+ sender : Sender :: new ( self . config . connection_handler_queue_len ( ) ) ,
3136+ topics : Default :: default ( ) ,
3137+ dont_send : LinkedHashMap :: new ( ) ,
3138+ } ) ;
31363139 // Add the new connection
31373140 connected_peer. connections . push ( connection_id) ;
31383141
@@ -3150,16 +3153,19 @@ where
31503153 _: Endpoint ,
31513154 _: PortUse ,
31523155 ) -> Result < THandler < Self > , ConnectionDenied > {
3153- let connected_peer = self . connected_peers . entry ( peer_id) . or_insert ( PeerDetails {
3154- kind : PeerKind :: Floodsub ,
3155- connections : vec ! [ ] ,
3156- // Diverging from the go implementation we only want to consider a peer as outbound peer
3157- // if its first connection is outbound.
3158- outbound : !self . px_peers . contains ( & peer_id) ,
3159- sender : Sender :: new ( self . config . connection_handler_queue_len ( ) ) ,
3160- topics : Default :: default ( ) ,
3161- dont_send : LinkedHashMap :: new ( ) ,
3162- } ) ;
3156+ let connected_peer = self
3157+ . connected_peers
3158+ . entry ( peer_id)
3159+ . or_insert_with ( || PeerDetails {
3160+ kind : PeerKind :: Floodsub ,
3161+ connections : vec ! [ ] ,
3162+ // Diverging from the go implementation we only want to consider a peer as outbound
3163+ // peer if its first connection is outbound.
3164+ outbound : !self . px_peers . contains ( & peer_id) ,
3165+ sender : Sender :: new ( self . config . connection_handler_queue_len ( ) ) ,
3166+ topics : Default :: default ( ) ,
3167+ dont_send : LinkedHashMap :: new ( ) ,
3168+ } ) ;
31633169 // Add the new connection
31643170 connected_peer. connections . push ( connection_id) ;
31653171
0 commit comments