Add NetworkBehaviour::inject_replaced (#914)

* Add NetworkBehaviour::inject_replaced

* Address style

* Forgot to call set_disconnected

* Also add incoming addresses to kbuckets
This commit is contained in:
Pierre Krieger
2019-02-04 15:21:50 +01:00
committed by GitHub
parent 7f66c4f4b0
commit c9b7e237b6
4 changed files with 96 additions and 3 deletions

View File

@ -262,8 +262,7 @@ where TBehaviour: NetworkBehaviour,
self.behaviour.inject_disconnected(&peer_id, endpoint);
},
Async::Ready(RawSwarmEvent::Replaced { peer_id, closed_endpoint, endpoint }) => {
self.behaviour.inject_disconnected(&peer_id, closed_endpoint);
self.behaviour.inject_connected(peer_id, endpoint);
self.behaviour.inject_replaced(peer_id, closed_endpoint, endpoint);
},
Async::Ready(RawSwarmEvent::IncomingConnection(incoming)) => {
let handler = self.behaviour.new_handler();
@ -343,6 +342,12 @@ pub trait NetworkBehaviour {
/// endpoint is the one we used to be connected to.
fn inject_disconnected(&mut self, peer_id: &PeerId, endpoint: ConnectedPoint);
/// Indicates the behaviour that we replace the connection from the node with another.
fn inject_replaced(&mut self, peer_id: PeerId, closed_endpoint: ConnectedPoint, new_endpoint: ConnectedPoint) {
self.inject_disconnected(&peer_id, closed_endpoint);
self.inject_connected(peer_id, new_endpoint);
}
/// Indicates the behaviour that the node with the given peer id has generated an event for
/// us.
///