Skip to content

Commit

Permalink
server: Integrate Message::SetMajority to Message::Coordinator (v0.11.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
gustafla committed Dec 16, 2024
1 parent 24d12c5 commit fcd95d6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server-node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "server-node"
version = "0.10.0"
version = "0.11.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
12 changes: 7 additions & 5 deletions server-node/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ impl Server {
self.handle_majority(majority);

for peer in self.peers.values() {
peer.send_message(Message::Coordinator);
peer.send_message(Message::SetMajority(self.majority));
peer.send_message(Message::Coordinator { majority });
}

#[allow(
Expand Down Expand Up @@ -330,6 +329,9 @@ impl Server {
self.become_coordinator();
}

// If coordinator was lost, we need to hold an election again.
// It's possible, that during this election, the majority-bit is incorrect.
// This is acceptable, because DHCP clients should never use conflicting addresses.
if Some(peer_id) == self.coordinator_id {
self.start_election();
}
Expand Down Expand Up @@ -440,10 +442,9 @@ impl Server {
Message::Heartbeat => console::debug!("Received heartbeat from {sender_id}"),
Message::Election => self.handle_election(sender_id),
Message::Okay => self.handle_okay(sender_id),
Message::Coordinator => self.handle_coordinator(sender_id),
Message::Coordinator { majority } => self.handle_coordinator(sender_id, majority),
Message::Lease(lease) => self.handle_add_lease(lease),
Message::SetPool(update) => self.handle_set_pool(update),
Message::SetMajority(majority) => self.handle_majority(majority),
Message::Join(..) | Message::JoinAck { .. } => {
console::warning!("Server received unexpected {message:?} from peer {sender_id}");
}
Expand Down Expand Up @@ -473,10 +474,11 @@ impl Server {
}
}

fn handle_coordinator(&mut self, sender_id: peer::Id) {
fn handle_coordinator(&mut self, sender_id: peer::Id, majority: bool) {
console::log!("Recognizing {sender_id} as Coordinator");
self.coordinator_id = Some(sender_id);
self.election_state = ElectionState::Follower;
self.handle_majority(majority);
if sender_id < self.config.id {
self.start_election();
}
Expand Down
5 changes: 3 additions & 2 deletions server-node/src/server/peer/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ pub enum Message {
Heartbeat,
Election,
Okay,
Coordinator,
Coordinator {
majority: bool,
},
Lease(Lease),
SetPool(Ipv4Range),
SetMajority(bool),
}

impl RecvCbor<Message> for TcpStream {}
Expand Down

0 comments on commit fcd95d6

Please sign in to comment.