mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-23 14:51:34 +00:00
refactor(relay): introduce Handler::new
functions (#3334)
This commit is contained in:
@ -350,19 +350,7 @@ impl IntoConnectionHandler for Prototype {
|
|||||||
// Deny all substreams on relayed connection.
|
// Deny all substreams on relayed connection.
|
||||||
Either::Right(dummy::ConnectionHandler)
|
Either::Right(dummy::ConnectionHandler)
|
||||||
} else {
|
} else {
|
||||||
Either::Left(Handler {
|
Either::Left(Handler::new(self.config, endpoint.clone()))
|
||||||
endpoint: endpoint.clone(),
|
|
||||||
config: self.config,
|
|
||||||
queued_events: Default::default(),
|
|
||||||
pending_error: Default::default(),
|
|
||||||
reservation_request_future: Default::default(),
|
|
||||||
circuit_accept_futures: Default::default(),
|
|
||||||
circuit_deny_futures: Default::default(),
|
|
||||||
alive_lend_out_substreams: Default::default(),
|
|
||||||
circuits: Default::default(),
|
|
||||||
active_reservation: Default::default(),
|
|
||||||
keep_alive: KeepAlive::Yes,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -431,6 +419,22 @@ pub struct Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Handler {
|
impl Handler {
|
||||||
|
fn new(config: Config, endpoint: ConnectedPoint) -> Handler {
|
||||||
|
Handler {
|
||||||
|
endpoint,
|
||||||
|
config,
|
||||||
|
queued_events: Default::default(),
|
||||||
|
pending_error: Default::default(),
|
||||||
|
reservation_request_future: Default::default(),
|
||||||
|
circuit_accept_futures: Default::default(),
|
||||||
|
circuit_deny_futures: Default::default(),
|
||||||
|
alive_lend_out_substreams: Default::default(),
|
||||||
|
circuits: Default::default(),
|
||||||
|
active_reservation: Default::default(),
|
||||||
|
keep_alive: KeepAlive::Yes,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn on_fully_negotiated_inbound(
|
fn on_fully_negotiated_inbound(
|
||||||
&mut self,
|
&mut self,
|
||||||
FullyNegotiatedInbound {
|
FullyNegotiatedInbound {
|
||||||
|
@ -140,18 +140,11 @@ impl IntoConnectionHandler for Prototype {
|
|||||||
// Deny all substreams on relayed connection.
|
// Deny all substreams on relayed connection.
|
||||||
Either::Right(dummy::ConnectionHandler)
|
Either::Right(dummy::ConnectionHandler)
|
||||||
} else {
|
} else {
|
||||||
let mut handler = Handler {
|
let mut handler = Handler::new(
|
||||||
remote_peer_id: *remote_peer_id,
|
self.local_peer_id,
|
||||||
remote_addr: endpoint.get_remote_address().clone(),
|
*remote_peer_id,
|
||||||
local_peer_id: self.local_peer_id,
|
endpoint.get_remote_address().clone(),
|
||||||
queued_events: Default::default(),
|
);
|
||||||
pending_error: Default::default(),
|
|
||||||
reservation: Reservation::None,
|
|
||||||
alive_lend_out_substreams: Default::default(),
|
|
||||||
circuit_deny_futs: Default::default(),
|
|
||||||
send_error_futs: Default::default(),
|
|
||||||
keep_alive: KeepAlive::Yes,
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(event) = self.initial_in {
|
if let Some(event) = self.initial_in {
|
||||||
handler.on_behaviour_event(event)
|
handler.on_behaviour_event(event)
|
||||||
@ -212,6 +205,21 @@ pub struct Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Handler {
|
impl Handler {
|
||||||
|
fn new(local_peer_id: PeerId, remote_peer_id: PeerId, remote_addr: Multiaddr) -> Self {
|
||||||
|
Self {
|
||||||
|
local_peer_id,
|
||||||
|
remote_peer_id,
|
||||||
|
remote_addr,
|
||||||
|
queued_events: Default::default(),
|
||||||
|
pending_error: Default::default(),
|
||||||
|
reservation: Reservation::None,
|
||||||
|
alive_lend_out_substreams: Default::default(),
|
||||||
|
circuit_deny_futs: Default::default(),
|
||||||
|
send_error_futs: Default::default(),
|
||||||
|
keep_alive: KeepAlive::Yes,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn on_fully_negotiated_inbound(
|
fn on_fully_negotiated_inbound(
|
||||||
&mut self,
|
&mut self,
|
||||||
FullyNegotiatedInbound {
|
FullyNegotiatedInbound {
|
||||||
|
Reference in New Issue
Block a user