torrust / torrust-tracker

A modern and feature-rich (private) BitTorrent tracker.
https://torrust.com
GNU Affero General Public License v3.0
357 stars 41 forks source link

Overhaul tracker keys: allow permanent keys #979

Closed josecelano closed 2 months ago

josecelano commented 2 months ago

Parent issue: https://github.com/torrust/torrust-tracker/issues/773

We can allow single keys to be permanent.

/// An authentication key which has an expiration time.
/// After that time is will automatically become invalid.
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct ExpiringKey {
    /// Random 32-char string. For example: `YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ`
    pub key: Key,
    /// Timestamp, the key will be no longer valid after this timestamp
    pub valid_until: DurationSinceUnixEpoch,
}

There are some possible implementations:

Proposal 1: Set valid_until to 0

ExpiringKeys with the UnixEpoch value in the valid_until field don't expire.

Proposal 2: Make valid_until optional

pub struct ExpiringKey {
    pub key: Key,
    pub valid_until: Option<DurationSinceUnixEpoch>,
}

NOTICE: I would rename the struct to TrackerKey because it can be permanent. Alternatively, we could rename Key to Token and ExpiringKey to Key.

cc @da2ce7