swarm/handler: replace inject_* methods (#3085)

Previously, we had one callback for each kind of message that a `ConnectionHandler` would receive from either its `NetworkBehaviour` or the connection itself.

With this patch, we combine these functions, resulting in two callbacks:

- `on_behaviour_event`
- `on_connection_event`

Resolves #3080.
This commit is contained in:
João Oliveira
2022-11-17 17:19:36 +00:00
committed by GitHub
parent 6d49bf4a53
commit 7803524a76
30 changed files with 1718 additions and 1094 deletions

View File

@ -149,7 +149,8 @@ where
}
/// Notifies the connection handler of an event.
pub fn inject_event(&mut self, event: THandler::InEvent) {
pub fn on_behaviour_event(&mut self, event: THandler::InEvent) {
#[allow(deprecated)]
self.handler.inject_event(event);
}
@ -180,6 +181,7 @@ where
match requested_substreams.poll_next_unpin(cx) {
Poll::Ready(Some(Ok(()))) => continue,
Poll::Ready(Some(Err(user_data))) => {
#[allow(deprecated)]
handler.inject_dial_upgrade_error(user_data, ConnectionHandlerUpgrErr::Timeout);
continue;
}
@ -208,10 +210,12 @@ where
match negotiating_out.poll_next_unpin(cx) {
Poll::Pending | Poll::Ready(None) => {}
Poll::Ready(Some((user_data, Ok(upgrade)))) => {
#[allow(deprecated)]
handler.inject_fully_negotiated_outbound(upgrade, user_data);
continue;
}
Poll::Ready(Some((user_data, Err(err)))) => {
#[allow(deprecated)]
handler.inject_dial_upgrade_error(user_data, err);
continue;
}
@ -222,10 +226,12 @@ where
match negotiating_in.poll_next_unpin(cx) {
Poll::Pending | Poll::Ready(None) => {}
Poll::Ready(Some((user_data, Ok(upgrade)))) => {
#[allow(deprecated)]
handler.inject_fully_negotiated_inbound(upgrade, user_data);
continue;
}
Poll::Ready(Some((user_data, Err(err)))) => {
#[allow(deprecated)]
handler.inject_listen_upgrade_error(user_data, err);
continue;
}
@ -273,6 +279,7 @@ where
match muxing.poll_unpin(cx)? {
Poll::Pending => {}
Poll::Ready(StreamMuxerEvent::AddressChange(address)) => {
#[allow(deprecated)]
handler.inject_address_change(&address);
return Poll::Ready(Ok(Event::AddressChange(address)));
}