diff --git a/beacon_node/libp2p/src/rpc/handler.rs b/beacon_node/libp2p/src/rpc/handler.rs deleted file mode 100644 index e69de29bb..000000000 diff --git a/beacon_node/libp2p/src/rpc/methods.rs b/beacon_node/libp2p/src/rpc/methods.rs index d299e9bb7..b6563ba64 100644 --- a/beacon_node/libp2p/src/rpc/methods.rs +++ b/beacon_node/libp2p/src/rpc/methods.rs @@ -19,17 +19,17 @@ impl From for RPCMethod { #[derive(Debug, Clone)] pub enum RPCRequest { - HelloRequest, + Hello(HelloBody), } #[derive(Debug, Clone)] pub enum RPCResponse { - HelloResponse(HelloResponse), + Hello(HelloBody), } // request/response structs for RPC methods #[derive(Encode, Decode, Clone, Debug)] -pub struct HelloResponse { +pub struct HelloBody { pub network_id: u8, pub latest_finalized_root: Hash256, pub latest_finalized_epoch: Epoch, diff --git a/beacon_node/libp2p/src/rpc/mod.rs b/beacon_node/libp2p/src/rpc/mod.rs index f66f531eb..4cebb1e39 100644 --- a/beacon_node/libp2p/src/rpc/mod.rs +++ b/beacon_node/libp2p/src/rpc/mod.rs @@ -2,7 +2,6 @@ /// /// This is purpose built for Ethereum 2.0 serenity and the protocol listens on /// `/eth/serenity/rpc/1.0.0` -mod handler; mod methods; mod protocol; diff --git a/beacon_node/libp2p/src/rpc/protocol.rs b/beacon_node/libp2p/src/rpc/protocol.rs index 2c6b3caa0..4b462bb77 100644 --- a/beacon_node/libp2p/src/rpc/protocol.rs +++ b/beacon_node/libp2p/src/rpc/protocol.rs @@ -1,11 +1,5 @@ -use super::methods::HelloResponse; -use super::methods::{RPCMethod, RPCRequest, RPCResponse}; -//use crate::rpc_proto; -//use byteorder::{BigEndian, ByteOrder}; -//use bytes::BytesMut; -use futures::{future, stream, Future, Stream}; -use libp2p::core::{upgrade, InboundUpgrade, OutboundUpgrade, PeerId, UpgradeInfo}; -//use std::{io, iter}; +use super::methods::{HelloBody, RPCMethod, RPCRequest, RPCResponse}; +use libp2p::core::{upgrade, InboundUpgrade, OutboundUpgrade, UpgradeInfo}; use ssz::{ssz_encode, Decodable, Encodable, SszStream}; use std::io; use std::iter; @@ -83,7 +77,10 @@ fn decode(packet: Vec) -> Result { if request { let body = match RPCMethod::from(method_id) { - RPCMethod::Hello => RPCRequest::HelloRequest, + RPCMethod::Hello => { + let (hello_body, _index) = HelloBody::ssz_decode(&packet, index)?; + RPCRequest::Hello(hello_body) + } RPCMethod::Unknown => return Err(DecodeError::UnknownRPCMethod), }; @@ -97,8 +94,8 @@ fn decode(packet: Vec) -> Result { else { let result = match RPCMethod::from(method_id) { RPCMethod::Hello => { - let (hello_response, _index) = HelloResponse::ssz_decode(&packet, index)?; - RPCResponse::HelloResponse(hello_response) + let (body, _index) = HelloBody::ssz_decode(&packet, index)?; + RPCResponse::Hello(body) } RPCMethod::Unknown => return Err(DecodeError::UnknownRPCMethod), }; @@ -137,8 +134,8 @@ impl Encodable for RpcEvent { s.append(id); s.append(method_id); match body { - RPCRequest::HelloRequest => {} - } + RPCRequest::Hello(body) => s.append(body), + }; } RpcEvent::Response { id, @@ -149,7 +146,7 @@ impl Encodable for RpcEvent { s.append(id); s.append(method_id); match result { - RPCResponse::HelloResponse(response) => { + RPCResponse::Hello(response) => { s.append(response); } }