@@ -65,6 +65,7 @@ pub enum UpgradeError {
65
65
Handler ( ConnectionHandlerUpgrErr < void:: Void > ) ,
66
66
}
67
67
68
+ #[ derive( Default ) ]
68
69
pub struct Behaviour {
69
70
/// Queue of actions to return when polled.
70
71
queued_actions : VecDeque < ActionBuilder > ,
@@ -145,40 +146,35 @@ impl NetworkBehaviour for Behaviour {
145
146
handler : Self :: ConnectionHandler ,
146
147
_error : & DialError ,
147
148
) {
148
- match handler {
149
- handler:: Prototype :: DirectConnection {
150
- relayed_connection_id,
151
- role : handler:: Role :: Initiator { attempt } ,
152
- } => {
153
- let peer_id =
154
- peer_id. expect ( "Peer of `Prototype::DirectConnection` is always known." ) ;
155
- if attempt < MAX_NUMBER_OF_UPGRADE_ATTEMPTS {
156
- self . queued_actions . push_back ( ActionBuilder :: Connect {
149
+ if let handler:: Prototype :: DirectConnection {
150
+ relayed_connection_id,
151
+ role : handler:: Role :: Initiator { attempt } ,
152
+ } = handler
153
+ {
154
+ let peer_id = peer_id. expect ( "Peer of `Prototype::DirectConnection` is always known." ) ;
155
+ if attempt < MAX_NUMBER_OF_UPGRADE_ATTEMPTS {
156
+ self . queued_actions . push_back ( ActionBuilder :: Connect {
157
+ peer_id,
158
+ handler : NotifyHandler :: One ( relayed_connection_id) ,
159
+ attempt : attempt + 1 ,
160
+ } ) ;
161
+ } else {
162
+ self . queued_actions . extend ( [
163
+ NetworkBehaviourAction :: NotifyHandler {
157
164
peer_id,
158
165
handler : NotifyHandler :: One ( relayed_connection_id) ,
159
- attempt : attempt + 1 ,
160
- } ) ;
161
- } else {
162
- self . queued_actions . extend ( [
163
- NetworkBehaviourAction :: NotifyHandler {
164
- peer_id,
165
- handler : NotifyHandler :: One ( relayed_connection_id) ,
166
- event : Either :: Left (
167
- handler:: relayed:: Command :: UpgradeFinishedDontKeepAlive ,
168
- ) ,
169
- }
170
- . into ( ) ,
171
- NetworkBehaviourAction :: GenerateEvent (
172
- Event :: DirectConnectionUpgradeFailed {
173
- remote_peer_id : peer_id,
174
- error : UpgradeError :: Dial ,
175
- } ,
176
- )
177
- . into ( ) ,
178
- ] ) ;
179
- }
166
+ event : Either :: Left (
167
+ handler:: relayed:: Command :: UpgradeFinishedDontKeepAlive ,
168
+ ) ,
169
+ }
170
+ . into ( ) ,
171
+ NetworkBehaviourAction :: GenerateEvent ( Event :: DirectConnectionUpgradeFailed {
172
+ remote_peer_id : peer_id,
173
+ error : UpgradeError :: Dial ,
174
+ } )
175
+ . into ( ) ,
176
+ ] ) ;
180
177
}
181
- _ => { }
182
178
}
183
179
}
184
180
@@ -324,7 +320,6 @@ impl NetworkBehaviour for Behaviour {
324
320
325
321
/// A [`NetworkBehaviourAction`], either complete, or still requiring data from [`PollParameters`]
326
322
/// before being returned in [`Behaviour::poll`].
327
- #[ allow( clippy:: large_enum_variant) ]
328
323
enum ActionBuilder {
329
324
Done ( NetworkBehaviourAction < Event , handler:: Prototype > ) ,
330
325
Connect {
@@ -333,7 +328,7 @@ enum ActionBuilder {
333
328
peer_id : PeerId ,
334
329
} ,
335
330
AcceptInboundConnect {
336
- inbound_connect : protocol:: inbound:: PendingConnect ,
331
+ inbound_connect : Box < protocol:: inbound:: PendingConnect > ,
337
332
handler : NotifyHandler ,
338
333
peer_id : PeerId ,
339
334
} ,
0 commit comments