Skip to content

Commit 91c18e1

Browse files
committed
Put a random nonce in the lease
1 parent b237742 commit 91c18e1

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ lazy_static = "1.4.0"
5252
libssh2-sys = { version = "0.3.0", optional = true }
5353
lru = "0.12"
5454
mutants = "0.0.3"
55+
rand = "0.8"
5556
rayon = "1.3.0"
5657
readahead-iterator = "0.1.1"
5758
regex = "1.3.9"
@@ -109,7 +110,6 @@ predicates = "3"
109110
pretty_assertions = "1.0"
110111
proptest = "1.5"
111112
proptest-derive = "0.5"
112-
rand = "0.8"
113113
rstest = { version = "0.19", default-features = false }
114114
tracing-test = { version = "0.2", features = ["no-env-filter"] }
115115

src/lease.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ impl Lease {
9797
client_version: Some(crate::VERSION.to_string()),
9898
acquired: lease_taken,
9999
expiry: lease_expiry,
100+
nonce: rand::random(),
100101
};
101102
let url = transport.relative_file_url(LEASE_FILENAME);
102103
let mut s: String = serde_json::to_string(&content).expect("serialize lease");
@@ -214,6 +215,8 @@ pub struct LeaseContent {
214215
pub pid: Option<u32>,
215216
/// Conserve version string.
216217
pub client_version: Option<String>,
218+
/// Random nonce to distinguish different leases from the same client.
219+
pub nonce: u32,
217220

218221
/// Time when the lease was taken.
219222
#[serde(with = "time::serde::iso8601")]
@@ -323,7 +326,8 @@ mod test {
323326
"pid": 1234,
324327
"client_version": "0.1.2",
325328
"acquired": "2021-01-01T12:34:56Z",
326-
"expiry": "2021-01-01T12:35:56Z"
329+
"expiry": "2021-01-01T12:35:56Z",
330+
"nonce": 12345
327331
}"#,
328332
)
329333
.unwrap();

0 commit comments

Comments
 (0)