Skip to content

Commit

Permalink
Support ping/pong cycle for bifrost protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jun 9, 2022
1 parent 37ab11b commit c6a9bd0
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/peerd/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub fn run(

debug!("Staring main service runtime");
let runtime = Runtime {
config: params.config.ext.clone(),
identity,
local_id: params.local_id,
remote_id: params.remote_id,
Expand All @@ -101,8 +102,7 @@ pub fn run(
messages_received: 0,
awaited_pong: None,
};
let ext = params.config.ext.clone();
let config = Config::with(params.config, ext);
let config = Config::with(params.config, runtime.config.clone());
let mut service = Service::service(config, runtime)?;
service.add_loopback(rx)?;
service.run_loop()?;
Expand Down Expand Up @@ -183,6 +183,7 @@ where
}

pub struct Runtime {
config: super::Config,
identity: ServiceId,
local_id: PublicKey,
remote_id: Option<PublicKey>,
Expand Down Expand Up @@ -513,8 +514,20 @@ impl Runtime {
rng.fill_bytes(&mut noise);
let pong_size = rng.gen_range(4, 32);
self.messages_sent += 1;
self.sender
.send_message(bolt::Messages::Ping(bolt::Ping { ignored: noise.into(), pong_size }))?;
match self.config.protocol {
P2pProtocol::Bolt => {
self.sender.send_message(bolt::Messages::Ping(bolt::Ping {
ignored: noise.into(),
pong_size,
}))?;
}
P2pProtocol::Bifrost => {
self.sender.send_message(bifrost::Messages::Ping(bifrost::Ping {
ignored: noise.into(),
pong_size,
}))?;
}
}
self.awaited_pong = Some(pong_size);
Ok(())
}
Expand All @@ -527,7 +540,14 @@ impl Runtime {
*byte = rng.gen();
}
self.messages_sent += 1;
self.sender.send_message(bolt::Messages::Pong(noise.into()))?;
match self.config.protocol {
P2pProtocol::Bolt => {
self.sender.send_message(bolt::Messages::Pong(noise.into()))?;
}
P2pProtocol::Bifrost => {
self.sender.send_message(bifrost::Messages::Pong(noise.into()))?;
}
}
Ok(())
}
}

0 comments on commit c6a9bd0

Please sign in to comment.