Skip to content

Commit aea3a4c

Browse files
committed
Put a random nonce in the lease
1 parent af3c279 commit aea3a4c

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ clicolors-control = "1.0"
4242
crc32c = { version = "0.6.6", optional = true }
4343
derive_more = "0.99"
4444
fail = { version = "0.5.1" }
45+
fastrand = "2.3.0"
4546
filetime = "0.2"
4647
futures = { version = "0.3", optional = true }
4748
globset = "0.4.5"
@@ -107,7 +108,6 @@ predicates = "3"
107108
pretty_assertions = "1.0"
108109
proptest = "1.5"
109110
proptest-derive = "0.5"
110-
rand = "0.8"
111111
rstest = { version = "0.19", default-features = false }
112112
tracing-test = { version = "0.2", features = ["no-env-filter"] }
113113

src/lease.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ impl Lease {
9999
client_version: Some(crate::VERSION.to_string()),
100100
acquired: lease_taken,
101101
expiry: lease_expiry,
102+
nonce: fastrand::u32(..),
102103
};
103104
let url = transport.url().join(LEASE_FILENAME).unwrap();
104105
let mut s: String = serde_json::to_string(&content).expect("serialize lease");
@@ -221,6 +222,8 @@ pub struct LeaseContent {
221222
pub pid: Option<u32>,
222223
/// Conserve version string.
223224
pub client_version: Option<String>,
225+
/// Random nonce to distinguish different leases from the same client.
226+
pub nonce: u32,
224227

225228
/// Time when the lease was taken.
226229
#[serde(with = "time::serde::iso8601")]
@@ -330,7 +333,8 @@ mod test {
330333
"pid": 1234,
331334
"client_version": "0.1.2",
332335
"acquired": "2021-01-01T12:34:56Z",
333-
"expiry": "2021-01-01T12:35:56Z"
336+
"expiry": "2021-01-01T12:35:56Z",
337+
"nonce": 12345
334338
}"#,
335339
)
336340
.unwrap();

0 commit comments

Comments
 (0)