Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ethcore/light/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions ethcore/sync/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::io;
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};
Expand Down Expand Up @@ -370,7 +370,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");
}
Expand Down
2 changes: 1 addition & 1 deletion util/network-devp2p/src/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 1 addition & 5 deletions util/network-devp2p/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -994,7 +991,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();
Expand Down
2 changes: 1 addition & 1 deletion util/network-devp2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
//! }
//!
Expand Down
2 changes: 1 addition & 1 deletion util/network-devp2p/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion util/network-devp2p/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
7 changes: 1 addition & 6 deletions util/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,17 +329,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.
Expand Down
10 changes: 3 additions & 7 deletions whisper/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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.
Expand All @@ -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()),
}
}

Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -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]) { }

Expand Down