From 67c09021f01cf9bba0b5e990c7a21405425e5a28 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Tue, 19 Mar 2019 13:03:12 +1100 Subject: [PATCH] Initial handling RPC responses --- beacon_node/network/src/message_handler.rs | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/beacon_node/network/src/message_handler.rs b/beacon_node/network/src/message_handler.rs index 11ce3d4c0..14be9acdc 100644 --- a/beacon_node/network/src/message_handler.rs +++ b/beacon_node/network/src/message_handler.rs @@ -8,7 +8,7 @@ use futures::future; use futures::prelude::*; use libp2p::{ rpc::{RPCMethod, RPCRequest, RPCResponse}, - PeerId, RPCEvent, + HelloMessage, PeerId, RPCEvent, }; use slog::warn; use slog::{debug, trace}; @@ -115,7 +115,7 @@ impl MessageHandler { match rpc_message { RPCEvent::Request { id, - method_id: _, + method_id: _, // TODO: Clean up RPC Message types, have a cleaner type by this point. body, } => self.handle_rpc_request(peer_id, id, body), RPCEvent::Response { @@ -126,11 +126,31 @@ impl MessageHandler { } } - fn handle_rpc_request(&mut self, peer_id: PeerId, id: u64, request: RPCRequest) {} + /// A new RPC request has been received from the network. + fn handle_rpc_request(&mut self, peer_id: PeerId, id: u64, request: RPCRequest) { + match request { + RPCRequest::Hello(hello_message) => { + self.handle_hello_response(peer_id, id, hello_message) + } + } + } + /// An RPC response has been received from the network. // we match on id and ignore responses past the timeout. fn handle_rpc_response(&mut self, peer_id: PeerId, id: u64, response: RPCResponse) {} + fn handle_hello_response(&mut self, peer_id: PeerId, id: u64, response: HelloMessage) { + /* + // if response id is not in our list, ignore (likely RPC timeout) + match self.requests.get(peer_id) { + None => return; + Some(rpc_info) => { + if rpc_info.con + + */ + + } + /// Sends a HELLO RPC request to a newly connected peer. fn send_hello_request(&mut self, peer_id: PeerId) { // generate a unique id for the peer