mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-10 21:50:37 +08:00
Use session RNG for ping
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
@@ -492,7 +492,7 @@ where
|
||||
let peer = self
|
||||
.sessions
|
||||
.entry(ip)
|
||||
.or_insert_with(|| Session::new(*addr, Link::Outbound, persistent, &self.rng));
|
||||
.or_insert_with(|| Session::new(*addr, Link::Outbound, persistent, self.rng.clone()));
|
||||
|
||||
peer.attempted();
|
||||
}
|
||||
@@ -533,7 +533,7 @@ where
|
||||
addr,
|
||||
Link::Inbound,
|
||||
self.config.is_persistent(&address),
|
||||
&self.rng,
|
||||
self.rng.clone(),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -929,7 +929,7 @@ where
|
||||
.filter(|(_, session)| session.last_active < *now - KEEP_ALIVE_DELTA)
|
||||
.map(|(_, session)| session);
|
||||
for session in inactive_sessions {
|
||||
session.ping(&mut self.reactor, &self.rng).ok();
|
||||
session.ping(&mut self.reactor).ok();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ pub struct Session {
|
||||
}
|
||||
|
||||
impl Session {
|
||||
pub fn new(addr: net::SocketAddr, link: Link, persistent: bool, rng: &Rng) -> Self {
|
||||
pub fn new(addr: net::SocketAddr, link: Link, persistent: bool, rng: Rng) -> Self {
|
||||
Self {
|
||||
addr,
|
||||
state: SessionState::default(),
|
||||
@@ -92,7 +92,7 @@ impl Session {
|
||||
persistent,
|
||||
last_active: LocalTime::default(),
|
||||
attempts: 0,
|
||||
rng: rng.clone(),
|
||||
rng,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,15 +116,16 @@ impl Session {
|
||||
self.attempts = 0;
|
||||
}
|
||||
|
||||
pub fn ping(&mut self, reactor: &mut Reactor, rng: &Rng) -> Result<(), SessionError> {
|
||||
pub fn ping(&mut self, reactor: &mut Reactor) -> Result<(), SessionError> {
|
||||
if let SessionState::Negotiated { ping, .. } = &mut self.state {
|
||||
let ponglen = rng.u16(0..wire::message::MAX_PAYLOAD_SIZE_BYTES);
|
||||
let msg = Message::Ping {
|
||||
ponglen,
|
||||
zeroes: message::ZeroBytes::new(
|
||||
rng.u16(0..(wire::message::MAX_PAYLOAD_SIZE_BYTES - (size_of::<u16>() as u16))),
|
||||
),
|
||||
};
|
||||
let ponglen = self.rng.u16(0..wire::message::MAX_PAYLOAD_SIZE_BYTES);
|
||||
let msg =
|
||||
Message::Ping {
|
||||
ponglen,
|
||||
zeroes: message::ZeroBytes::new(self.rng.u16(
|
||||
0..(wire::message::MAX_PAYLOAD_SIZE_BYTES - (size_of::<u16>() as u16)),
|
||||
)),
|
||||
};
|
||||
reactor.write(self.addr, msg);
|
||||
|
||||
*ping = PingState::AwaitingResponse(ponglen);
|
||||
|
||||
Reference in New Issue
Block a user