Tidy message handler

This commit is contained in:
Age Manning 2019-03-19 21:44:52 +11:00
parent c0bc45f1f3
commit 6e10ce93d4
No known key found for this signature in database
GPG Key ID: 05EED64B79E06A93

View File

@ -91,6 +91,7 @@ impl MessageHandler {
Ok(handler_send) Ok(handler_send)
} }
/// Handle all messages incoming from the network service.
fn handle_message(&mut self, message: HandlerMessage) { fn handle_message(&mut self, message: HandlerMessage) {
match message { match message {
// we have initiated a connection to a peer // we have initiated a connection to a peer
@ -107,6 +108,9 @@ impl MessageHandler {
} }
} }
/* RPC - Related functionality */
/// Handle RPC messages
fn handle_rpc_message(&mut self, peer_id: PeerId, rpc_message: RPCEvent) { fn handle_rpc_message(&mut self, peer_id: PeerId, rpc_message: RPCEvent) {
match rpc_message { match rpc_message {
RPCEvent::Request { RPCEvent::Request {
@ -140,6 +144,7 @@ impl MessageHandler {
} }
} }
/// Handle a HELLO RPC request message.
fn handle_hello_request(&mut self, peer_id: PeerId, id: u64, hello_message: HelloMessage) { fn handle_hello_request(&mut self, peer_id: PeerId, id: u64, hello_message: HelloMessage) {
// send back a HELLO message // send back a HELLO message
self.send_hello(peer_id.clone(), id, false); self.send_hello(peer_id.clone(), id, false);
@ -153,12 +158,15 @@ impl MessageHandler {
} }
} }
/// Handle a HELLO RPC response message.
fn handle_hello_response(&mut self, peer_id: PeerId, id: u64, response: HelloMessage) { fn handle_hello_response(&mut self, peer_id: PeerId, id: u64, response: HelloMessage) {
debug!(self.log, "Hello response received from peer: {:?}", peer_id); debug!(self.log, "Hello response received from peer: {:?}", peer_id);
// validate peer - decide whether to drop/ban or add to sync // validate peer - decide whether to drop/ban or add to sync
// TODO: Peer validation // TODO: Peer validation
} }
/* General RPC helper functions */
/// Generates a new request id for a peer. /// Generates a new request id for a peer.
fn generate_request_id(&mut self, peer_id: &PeerId) -> u64 { fn generate_request_id(&mut self, peer_id: &PeerId) -> u64 {
// generate a unique id for the peer // generate a unique id for the peer