Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
protocol: debounce inventory announcements
Quaylyn Rimer committed 3 months ago
commit 9f57ab940ef166b826d562906894bf3344cbd794
parent 8efa29a00f26c7e6297a1248c1b069aea9aaf33b
1 file changed +18 -0
modified crates/radicle-protocol/src/service.rs
@@ -471,6 +471,10 @@ pub struct Service<D, S, G> {
    refs_populate_pending: bool,
    /// Whether inventory scan is pending.
    inventory_scan_pending: bool,
+
    /// Whether inventory announce is pending (debounced).
+
    inventory_announce_pending: bool,
+
    /// Last time inventory announcement was sent.
+
    last_inventory_sent_at: LocalTime,
    /// Gossip backoff multiplier.
    gossip_backoff: u64,
    /// Sync backoff multiplier.
@@ -597,6 +601,8 @@ where
            metrics: Metrics::default(),
            refs_populate_pending: false,
            inventory_scan_pending: false,
+
            inventory_announce_pending: false,
+
            last_inventory_sent_at: LocalTime::default(),
            gossip_backoff: 1,
            sync_backoff: 1,
        }
@@ -813,6 +819,11 @@ where
                    }
                }
            }
+
            if self.inventory_announce_pending
+
                && now - self.last_inventory_sent_at >= self.idle_interval()
+
            {
+
                self.announce_inventory();
+
            }

            self.keep_alive(&now);
            self.disconnect_unresponsive_peers(&now);
@@ -2522,6 +2533,11 @@ where

    /// Announce our inventory to all connected peers, unless it was already announced.
    fn announce_inventory(&mut self) {
+
        if self.clock - self.last_inventory_sent_at < self.idle_interval() {
+
            debug!(target: "service", "Debouncing inventory announcement");
+
            self.inventory_announce_pending = true;
+
            return;
+
        }
        let timestamp = self.inventory.timestamp.to_local_time();

        if self.last_inventory == timestamp {
@@ -2536,6 +2552,8 @@ where
            self.db.gossip_mut(),
        );
        self.last_inventory = timestamp;
+
        self.last_inventory_sent_at = self.clock;
+
        self.inventory_announce_pending = false;
    }

    fn prune_routing_entries(&mut self, now: &LocalTime) -> Result<(), routing::Error> {