diff options
Diffstat (limited to 'src/remake/local.rs')
| -rw-r--r-- | src/remake/local.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/remake/local.rs b/src/remake/local.rs index 0d6c6c7..04ac0b0 100644 --- a/src/remake/local.rs +++ b/src/remake/local.rs @@ -53,6 +53,8 @@ struct Inner { contents: HashMap<[u8; 32], (Arc<Vec<u8>>, Instant)>, /// Content being downloaded. content_fetches: HashSet<[u8; 32]>, + /// Remakes this node coordinates now (`coordinator`). + coordinating: HashSet<String>, } /// Content no remake refers to any more is kept this long after it was stored, for @@ -145,6 +147,19 @@ impl RemakeState { self.started_at } + /// Whether this node starts coordinating `id` now (false if it already does). + pub(crate) fn start_coordinating(&self, id: &str) -> bool { + self.lock().coordinating.insert(id.to_owned()) + } + + pub(crate) fn end_coordinating(&self, id: &str) { + self.lock().coordinating.remove(id); + } + + pub(crate) fn is_coordinating(&self, id: &str) -> bool { + self.lock().coordinating.contains(id) + } + fn lock(&self) -> MutexGuard<'_, Inner> { self.inner .lock() |
