Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
protocol: provide more information for invalid timestamps
✗ CI failure Fintan Halpenny committed 5 months ago
commit 91002ad560f38ce5c32e57366cabc0098e2ae986
parent 37d4ae4a9f2527a6f4922bf10a68b49ba67b0204
1 passed 1 failed (2 total) View logs
3 files changed +16 -4
modified crates/radicle-node/src/tests.rs
@@ -447,8 +447,8 @@ fn test_inventory_relay_bad_timestamp() {
    );
    assert_matches!(
        alice.outbox().next(),
-
        Some(Io::Disconnect(addr, DisconnectReason::Session(session::Error::InvalidTimestamp(t))))
-
        if addr == bob.id() && t == timestamp
+
        Some(Io::Disconnect(addr, DisconnectReason::Session(session::Error::InvalidTimestamp(session::InvalidTimestamp::Future { theirs, .. }))))
+
        if addr == bob.id() && theirs == timestamp
    );
}

modified crates/radicle-protocol/src/service.rs
@@ -1524,7 +1524,7 @@ where

        // Don't allow messages from too far in the future.
        if timestamp.saturating_sub(now.as_millis()) > MAX_TIME_DELTA.as_millis() as u64 {
-
            return Err(session::Error::InvalidTimestamp(timestamp));
+
            return Err(session::Error::future_timestamp(timestamp, now.into()));
        }

        // We don't process announcements from nodes we don't know, since the node announcement is
modified crates/radicle-protocol/src/service/session.rs
@@ -22,7 +22,7 @@ pub enum Error {
    /// The remote peer sent an invalid announcement timestamp,
    /// for eg. a timestamp far in the future.
    #[error("invalid announcement timestamp: {0}")]
-
    InvalidTimestamp(Timestamp),
+
    InvalidTimestamp(InvalidTimestamp),
    /// The remote peer sent git protocol messages while we were expecting
    /// gossip messages. Or vice-versa.
    #[error("protocol mismatch")]
@@ -36,6 +36,18 @@ pub enum Error {
}

impl Error {
+
    pub(crate) fn future_timestamp(theirs: Timestamp, ours: Timestamp) -> Self {
+
        Self::InvalidTimestamp(InvalidTimestamp::Future { theirs, ours })
+
    }
+
}
+

+
#[derive(thiserror::Error, Debug, Clone, Copy)]
+
pub enum InvalidTimestamp {
+
    #[error("{theirs} appears too far in the future compared to {ours}")]
+
    Future { theirs: Timestamp, ours: Timestamp },
+
}
+

+
impl Error {
    /// Return the severity for this error.
    pub fn severity(&self) -> Severity {
        match self {