Skip to content
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

refactor(perf): don't use OutboundOpenInfo #3763

Merged
merged 4 commits into from
Apr 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions protocols/perf/src/client/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pub struct Handler {
>,
>,

requested_streams: VecDeque<Command>,

outbound: FuturesUnordered<BoxFuture<'static, Result<Event, std::io::Error>>>,

keep_alive: KeepAlive,
Expand All @@ -70,6 +72,7 @@ impl Handler {
pub fn new() -> Self {
Self {
queued_events: Default::default(),
requested_streams: Default::default(),
outbound: Default::default(),
keep_alive: KeepAlive::Yes,
}
Expand All @@ -88,17 +91,18 @@ impl ConnectionHandler for Handler {
type Error = Void;
type InboundProtocol = DeniedUpgrade;
type OutboundProtocol = ReadyUpgrade<&'static [u8]>;
type OutboundOpenInfo = Command;
type OutboundOpenInfo = ();
type InboundOpenInfo = ();

fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol, Self::InboundOpenInfo> {
SubstreamProtocol::new(DeniedUpgrade, ())
}

fn on_behaviour_event(&mut self, command: Self::InEvent) {
self.requested_streams.push_back(command);
self.queued_events
.push_back(ConnectionHandlerEvent::OutboundSubstreamRequest {
protocol: SubstreamProtocol::new(ReadyUpgrade::new(crate::PROTOCOL_NAME), command),
protocol: SubstreamProtocol::new(ReadyUpgrade::new(crate::PROTOCOL_NAME), ()),
})
}

Expand All @@ -117,26 +121,34 @@ impl ConnectionHandler for Handler {
}) => void::unreachable(protocol),
ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound {
protocol,
info: Command { params, id },
}) => self.outbound.push(
crate::protocol::send_receive(params, protocol)
.map_ok(move |timers| Event {
id,
result: Ok(RunStats { params, timers }),
})
.boxed(),
),
info: (),
}) => {
let Command { id, params } = self
.requested_streams
.pop_front()
.expect("opened a stream without a pending command");
self.outbound.push(
crate::protocol::send_receive(params, protocol)
.map_ok(move |timers| Event {
id,
result: Ok(RunStats { params, timers }),
})
.boxed(),
);
}

ConnectionEvent::AddressChange(_) => {}
ConnectionEvent::DialUpgradeError(DialUpgradeError {
info: Command { id, .. },
error,
}) => self
.queued_events
.push_back(ConnectionHandlerEvent::Custom(Event {
id,
result: Err(error),
})),
ConnectionEvent::DialUpgradeError(DialUpgradeError { info: (), error }) => {
let Command { id, .. } = self
.requested_streams
.pop_front()
.expect("requested stream without pending command");
self.queued_events
.push_back(ConnectionHandlerEvent::Custom(Event {
id,
result: Err(error),
}));
}
ConnectionEvent::ListenUpgradeError(ListenUpgradeError { info: (), error }) => {
match error {
ConnectionHandlerUpgrErr::Timeout => {}
Expand Down