-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the ability for the behaviour to disconnect a peer #2110
Changes from 1 commit
5bbebb6
9db53b7
abb23d9
7c43788
1ac40e6
cc61123
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -293,6 +293,15 @@ pub enum NetworkBehaviourAction<TInEvent, TOutEvent> { | |||||||||||||
/// relative to other observed addresses. | ||||||||||||||
score: AddressScore, | ||||||||||||||
}, | ||||||||||||||
|
||||||||||||||
/// Instructs the `Swarm` to initiate a graceful close of the connection | ||||||||||||||
/// with a peer. | ||||||||||||||
DisconnectPeer { | ||||||||||||||
/// The peer to disconnect. | ||||||||||||||
peer_id: PeerId, | ||||||||||||||
/// The ID of the connection whose `ProtocolsHandler` to disconnect. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These docs seems to be slightly off given that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, thank you! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
handler: DisconnectPeerHandler, | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
impl<TInEvent, TOutEvent> NetworkBehaviourAction<TInEvent, TOutEvent> { | ||||||||||||||
|
@@ -312,7 +321,10 @@ impl<TInEvent, TOutEvent> NetworkBehaviourAction<TInEvent, TOutEvent> { | |||||||||||||
event: f(event) | ||||||||||||||
}, | ||||||||||||||
NetworkBehaviourAction::ReportObservedAddr { address, score } => | ||||||||||||||
NetworkBehaviourAction::ReportObservedAddr { address, score } | ||||||||||||||
NetworkBehaviourAction::ReportObservedAddr { address, score }, | ||||||||||||||
NetworkBehaviourAction::DisconnectPeer { peer_id, handler } => { | ||||||||||||||
NetworkBehaviourAction::DisconnectPeer { peer_id, handler } | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
@@ -328,7 +340,9 @@ impl<TInEvent, TOutEvent> NetworkBehaviourAction<TInEvent, TOutEvent> { | |||||||||||||
NetworkBehaviourAction::NotifyHandler { peer_id, handler, event } => | ||||||||||||||
NetworkBehaviourAction::NotifyHandler { peer_id, handler, event }, | ||||||||||||||
NetworkBehaviourAction::ReportObservedAddr { address, score } => | ||||||||||||||
NetworkBehaviourAction::ReportObservedAddr { address, score } | ||||||||||||||
NetworkBehaviourAction::ReportObservedAddr { address, score }, | ||||||||||||||
NetworkBehaviourAction::DisconnectPeer { peer_id, handler } => | ||||||||||||||
NetworkBehaviourAction::DisconnectPeer { peer_id, handler } | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
@@ -373,3 +387,18 @@ impl Default for DialPeerCondition { | |||||||||||||
DialPeerCondition::Disconnected | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/// The options which connection handlers to disconnect. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
#[derive(Debug, Clone)] | ||||||||||||||
pub enum DisconnectPeerHandler { | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docs mention the term I'd also agree to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose someone would like to disconnect a specified connection by its
I tried to follow the style of naming structures and enumerations that you follow :)
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I did see that and thought you would have been inspired by What about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would be in favor of calling both the |
||||||||||||||
/// Disconnect a particular connection handler. | ||||||||||||||
One(ConnectionId), | ||||||||||||||
/// Disconnect all connection handlers. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Your changes closes the connection. The handler is not actively being closed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, thanks! |
||||||||||||||
All, | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
impl Default for DisconnectPeerHandler { | ||||||||||||||
fn default() -> Self { | ||||||||||||||
DisconnectPeerHandler::All | ||||||||||||||
} | ||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This naming would be more intuitive to me. What do you think @sergeyboyko0791?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with you and @thomaseizinger