Skip to content

Commit

Permalink
Fix a race condition in the relay usage switches
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedilger committed Feb 1, 2024
1 parent 2bf5f3a commit 258cdcc
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions gossip-bin/src/ui/widgets/relay_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,14 +713,16 @@ impl RelayEntry {
off_fill,
);
if response.changed() {
modify_relay(&self.relay.url, |relay| {
relay.adjust_usage_bit(Relay::READ, self.usage.read)
});
if !self.usage.read {
// if read was turned off, inbox must also be turned off
self.usage.inbox = false;
modify_relay(&self.relay.url, |relay| {
relay.adjust_usage_bit(Relay::INBOX, self.usage.inbox)
relay.adjust_usage_bit(Relay::READ, self.usage.read);
relay.adjust_usage_bit(Relay::INBOX, self.usage.inbox);
});
} else {
modify_relay(&self.relay.url, |relay| {
relay.adjust_usage_bit(Relay::READ, self.usage.read);
});
}
}
Expand Down Expand Up @@ -799,14 +801,16 @@ impl RelayEntry {
off_fill,
);
if response.changed() {
modify_relay(&self.relay.url, |relay| {
relay.adjust_usage_bit(Relay::WRITE, self.usage.write)
});
if !self.usage.write {
// if write was turned off, outbox must also be turned off
self.usage.outbox = false;
modify_relay(&self.relay.url, |relay| {
relay.adjust_usage_bit(Relay::OUTBOX, self.usage.outbox)
relay.adjust_usage_bit(Relay::WRITE, self.usage.write);
relay.adjust_usage_bit(Relay::OUTBOX, self.usage.outbox);
});
} else {
modify_relay(&self.relay.url, |relay| {
relay.adjust_usage_bit(Relay::WRITE, self.usage.write);
});
}
}
Expand Down

0 comments on commit 258cdcc

Please sign in to comment.