@@ -3125,14 +3125,17 @@ where
3125
3125
// The protocol negotiation occurs once a message is sent/received. Once this happens we
3126
3126
// update the type of peer that this is in order to determine which kind of routing should
3127
3127
// 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
+ } ) ;
3136
3139
// Add the new connection
3137
3140
connected_peer. connections . push ( connection_id) ;
3138
3141
@@ -3150,16 +3153,19 @@ where
3150
3153
_: Endpoint ,
3151
3154
_: PortUse ,
3152
3155
) -> 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
+ } ) ;
3163
3169
// Add the new connection
3164
3170
connected_peer. connections . push ( connection_id) ;
3165
3171
0 commit comments