pub struct Server {
config: Arc<Config>,
tx: Sender<Event>,
thread_pool: ThreadPool,
coordinator_id: Option<Id>,
dhcp_service: Service,
peers: HashMap<Id, Peer>,
election_state: ElectionState,
majority: bool,
}
Expand description
The distributed DHCP server
Fields§
§config: Arc<Config>
§tx: Sender<Event>
§thread_pool: ThreadPool
§coordinator_id: Option<Id>
§dhcp_service: Service
§peers: HashMap<Id, Peer>
§election_state: ElectionState
§majority: bool
Implementations§
source§impl Server
impl Server
sourcepub fn start(
config: Config,
peer_listener: TcpListener,
client_listener: TcpListener,
)
pub fn start( config: Config, peer_listener: TcpListener, client_listener: TcpListener, )
Start listening to incoming connections from server peers and DHCP clients.
fn run_event_loop(&mut self, server_rx: &Receiver<Event>)
fn attempt_connect(&mut self)
fn become_coordinator(&mut self)
fn answer_handshake(&mut self, stream: TcpStream)
fn add_peer(&mut self, peer_id: Id, peer: Peer) -> Result<(), ()>
fn remove_peer(&mut self, peer_id: Id)
sourcefn start_election(&mut self)
fn start_election(&mut self)
Send Message::Election
to all server peers with higher ids than this server.
This function starts a timer thread which sleeps until the bully algorithm timeout expires.
The timer triggers a Event::ElectionTimeout
to the the server thread.
sourcefn finish_election(&mut self)
fn finish_election(&mut self)
Inspect current server role. Become leader and send Message::Coordinator
to all peers
if no event has reset the server role back to ElectionState::Follower
.
fn handle_lease_request( &mut self, mac_address: MacAddr, tx: &Sender<LeaseOffer>, )
fn handle_confirm_request( &mut self, mac_address: MacAddr, ip: Ipv4Addr, tx: &Sender<bool>, )
fn handle_peer_message(&mut self, sender_id: Id, message: Message)
fn handle_election(&mut self, sender_id: Id)
fn handle_okay(&mut self, sender_id: Id)
fn handle_coordinator(&mut self, sender_id: Id, majority: bool)
fn handle_add_lease(&mut self, lease: Lease)
fn handle_set_pool(&mut self, pool: Ipv4Range)
fn handle_majority(&mut self, majority: bool)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Server
impl !RefUnwindSafe for Server
impl Send for Server
impl Sync for Server
impl Unpin for Server
impl !UnwindSafe for Server
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more