Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
Use session RNG for ping
Alexis Sellier committed 3 years ago
commit fbd4fd9feaf1af27ef3a0ff2943d94fbce99a6b5
parent 86ed10fca9a01a0f8f468c81bcea49827df79a22
2 files changed +14 -13
modified radicle-node/src/service.rs
@@ -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();
        }
    }

modified radicle-node/src/service/peer.rs
@@ -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);