Remove HostTrait altogether (#8681)

This commit is contained in:
Pierre Krieger 2018-06-02 11:05:11 +02:00 committed by Marek Kotewicz
parent 2060ea5de3
commit 3d76417353
9 changed files with 13 additions and 26 deletions

View File

@ -21,7 +21,7 @@
use transaction::UnverifiedTransaction;
use io::TimerToken;
use network::{HostInfo, NetworkProtocolHandler, NetworkContext, PeerId};
use network::{NetworkProtocolHandler, NetworkContext, PeerId};
use rlp::{RlpStream, Rlp};
use ethereum_types::{H256, U256};
use kvdb::DBValue;
@ -1082,7 +1082,7 @@ fn punish(peer: PeerId, io: &IoContext, e: Error) {
}
impl NetworkProtocolHandler for LightProtocol {
fn initialize(&self, io: &NetworkContext, _host_info: &HostInfo) {
fn initialize(&self, io: &NetworkContext) {
io.register_timer(TIMEOUT, TIMEOUT_INTERVAL)
.expect("Error registering sync timer.");
io.register_timer(TICK_TIMEOUT, TICK_TIMEOUT_INTERVAL)

View File

@ -21,7 +21,7 @@ use std::ops::Range;
use std::time::Duration;
use bytes::Bytes;
use devp2p::NetworkService;
use network::{NetworkProtocolHandler, NetworkContext, HostInfo, PeerId, ProtocolId,
use network::{NetworkProtocolHandler, NetworkContext, PeerId, ProtocolId,
NetworkConfiguration as BasicNetworkConfiguration, NonReservedPeerMode, Error, ErrorKind,
ConnectionFilter};
use ethereum_types::{H256, H512, U256};
@ -371,7 +371,7 @@ struct SyncProtocolHandler {
}
impl NetworkProtocolHandler for SyncProtocolHandler {
fn initialize(&self, io: &NetworkContext, _host_info: &HostInfo) {
fn initialize(&self, io: &NetworkContext) {
if io.subprotocol_name() != WARP_SYNC_PROTOCOL_ID {
io.register_timer(0, Duration::from_secs(1)).expect("Error registering sync timer");
}

View File

@ -26,7 +26,7 @@ use node_table::NodeId;
use io::{IoContext, StreamToken};
use ethkey::{KeyPair, Public, Secret, recover, sign, Generator, Random};
use ethkey::crypto::{ecdh, ecies};
use network::{Error, ErrorKind, HostInfo as HostInfoTrait};
use network::{Error, ErrorKind};
use host::HostInfo;
#[derive(PartialEq, Eq, Debug)]

View File

@ -39,7 +39,6 @@ use PROTOCOL_VERSION;
use node_table::*;
use network::{NetworkConfiguration, NetworkIoMessage, ProtocolId, PeerId, PacketId};
use network::{NonReservedPeerMode, NetworkContext as NetworkContextTrait};
use network::HostInfo as HostInfoTrait;
use network::{SessionInfo, Error, ErrorKind, DisconnectReason, NetworkProtocolHandler};
use discovery::{Discovery, TableUpdates, NodeEntry};
use ip_utils::{map_external_address, select_public_address};
@ -223,10 +222,8 @@ impl HostInfo {
pub(crate) fn secret(&self) -> &Secret {
self.keys.secret()
}
}
impl HostInfoTrait for HostInfo {
fn id(&self) -> &NodeId {
pub(crate) fn id(&self) -> &NodeId {
self.keys.public()
}
}
@ -997,7 +994,6 @@ impl IoHandler<NetworkIoMessage> for Host {
let reserved = self.reserved_nodes.read();
h.initialize(
&NetworkContext::new(io, *protocol, None, self.sessions.clone(), &reserved),
&*self.info.read(),
);
self.handlers.write().insert(*protocol, h);
let mut info = self.info.write();

View File

@ -29,7 +29,7 @@
//! struct MyHandler;
//!
//! impl NetworkProtocolHandler for MyHandler {
//! fn initialize(&self, io: &NetworkContext, _host_info: &HostInfo) {
//! fn initialize(&self, io: &NetworkContext) {
//! io.register_timer(0, Duration::from_secs(1));
//! }
//!

View File

@ -28,7 +28,7 @@ use connection::{EncryptedConnection, Packet, Connection, MAX_PAYLOAD_SIZE};
use handshake::Handshake;
use io::{IoContext, StreamToken};
use network::{Error, ErrorKind, DisconnectReason, SessionInfo, ProtocolId, PeerCapabilityInfo};
use network::{SessionCapabilityInfo, HostInfo as HostInfoTrait};
use network::SessionCapabilityInfo;
use host::*;
use node_table::NodeId;
use snappy;

View File

@ -70,7 +70,7 @@ impl TestProtocol {
}
impl NetworkProtocolHandler for TestProtocol {
fn initialize(&self, io: &NetworkContext, _host_info: &HostInfo) {
fn initialize(&self, io: &NetworkContext) {
io.register_timer(0, Duration::from_millis(10)).unwrap();
}

View File

@ -333,17 +333,12 @@ impl<'a, T> NetworkContext for &'a T where T: ?Sized + NetworkContext {
}
}
pub trait HostInfo {
/// Returns public key
fn id(&self) -> &NodeId;
}
/// Network IO protocol handler. This needs to be implemented for each new subprotocol.
/// All the handler function are called from within IO event loop.
/// `Message` is the type for message data.
pub trait NetworkProtocolHandler: Sync + Send {
/// Initialize the handler
fn initialize(&self, _io: &NetworkContext, _host_info: &HostInfo) {}
fn initialize(&self, _io: &NetworkContext) {}
/// Called when new network packet received.
fn read(&self, io: &NetworkContext, peer: &PeerId, packet_id: u8, data: &[u8]);
/// Called when new peer is connected. Only called when peer supports the same protocol.

View File

@ -23,7 +23,7 @@ use std::time::{Duration, SystemTime};
use std::sync::Arc;
use ethereum_types::{H256, H512};
use network::{self, HostInfo, NetworkContext, NodeId, PeerId, ProtocolId, TimerToken};
use network::{self, NetworkContext, NodeId, PeerId, ProtocolId, TimerToken};
use ordered_float::OrderedFloat;
use parking_lot::{Mutex, RwLock};
use rlp::{DecoderError, RlpStream, Rlp};
@ -423,7 +423,6 @@ pub struct Network<T> {
messages: Arc<RwLock<Messages>>,
handler: T,
peers: RwLock<HashMap<PeerId, Mutex<Peer>>>,
node_key: RwLock<NodeId>,
}
// public API.
@ -434,7 +433,6 @@ impl<T> Network<T> {
messages: Arc::new(RwLock::new(Messages::new(messages_size_bytes))),
handler: handler,
peers: RwLock::new(HashMap::new()),
node_key: RwLock::new(Default::default()),
}
}
@ -685,12 +683,10 @@ impl<T: MessageHandler> Network<T> {
}
impl<T: MessageHandler> ::network::NetworkProtocolHandler for Network<T> {
fn initialize(&self, io: &NetworkContext, host_info: &HostInfo) {
fn initialize(&self, io: &NetworkContext) {
// set up broadcast timer (< 1s)
io.register_timer(RALLY_TOKEN, RALLY_TIMEOUT)
.expect("Failed to initialize message rally timer");
*self.node_key.write() = host_info.id().clone();
}
fn read(&self, io: &NetworkContext, peer: &PeerId, packet_id: u8, data: &[u8]) {
@ -720,7 +716,7 @@ impl<T: MessageHandler> ::network::NetworkProtocolHandler for Network<T> {
pub struct ParityExtensions;
impl ::network::NetworkProtocolHandler for ParityExtensions {
fn initialize(&self, _io: &NetworkContext, _host_info: &HostInfo) { }
fn initialize(&self, _io: &NetworkContext) { }
fn read(&self, _io: &NetworkContext, _peer: &PeerId, _id: u8, _msg: &[u8]) { }