openethereum/src/network/mod.rs

90 lines
2.0 KiB
Rust
Raw Normal View History

2015-11-29 11:50:28 +01:00
extern crate mio;
2015-12-02 12:07:46 +01:00
mod host;
mod connection;
mod handshake;
mod session;
mod discovery;
2015-12-17 11:42:30 +01:00
mod service;
2015-12-02 20:11:13 +01:00
#[derive(Debug, Copy, Clone)]
pub enum DisconnectReason
{
DisconnectRequested,
TCPError,
BadProtocol,
UselessPeer,
TooManyPeers,
DuplicatePeer,
IncompatibleProtocol,
NullIdentity,
ClientQuit,
UnexpectedIdentity,
LocalIdentity,
PingTimeout,
}
#[derive(Debug)]
pub enum Error {
Crypto(::crypto::CryptoError),
Io(::std::io::Error),
2015-12-02 12:07:46 +01:00
Auth,
BadProtocol,
AddressParse(::std::net::AddrParseError),
AddressResolve(Option<::std::io::Error>),
NodeIdParse(::error::EthcoreError),
2015-12-17 11:42:30 +01:00
PeerNotFound,
2015-12-02 20:11:13 +01:00
Disconnect(DisconnectReason)
}
impl From<::std::io::Error> for Error {
fn from(err: ::std::io::Error) -> Error {
Error::Io(err)
}
}
impl From<::crypto::CryptoError> for Error {
fn from(err: ::crypto::CryptoError) -> Error {
Error::Crypto(err)
}
}
2015-12-22 22:23:43 +01:00
2015-12-02 12:07:46 +01:00
impl From<::std::net::AddrParseError> for Error {
fn from(err: ::std::net::AddrParseError) -> Error {
Error::AddressParse(err)
}
}
impl From<::error::EthcoreError> for Error {
fn from(err: ::error::EthcoreError) -> Error {
Error::NodeIdParse(err)
}
}
impl From<::rlp::DecoderError> for Error {
fn from(_err: ::rlp::DecoderError) -> Error {
Error::Auth
}
}
2015-12-17 11:42:30 +01:00
impl From<::mio::NotifyError<host::HostMessage>> for Error {
fn from(_err: ::mio::NotifyError<host::HostMessage>) -> Error {
Error::Io(::std::io::Error::new(::std::io::ErrorKind::ConnectionAborted, "Network IO notification error"))
}
}
pub type PeerId = host::PeerId;
2015-12-22 22:23:43 +01:00
pub type PacketId = host::PacketId;
pub type TimerToken = host::TimerToken;
2015-12-17 11:42:30 +01:00
pub type HandlerIo<'s> = host::HostIo<'s>;
pub trait ProtocolHandler: Send {
fn initialize(&mut self, io: &mut HandlerIo);
2015-12-22 22:23:43 +01:00
fn read(&mut self, io: &mut HandlerIo, peer: &PeerId, packet_id: u8, data: &[u8]);
2015-12-17 11:42:30 +01:00
fn connected(&mut self, io: &mut HandlerIo, peer: &PeerId);
fn disconnected(&mut self, io: &mut HandlerIo, peer: &PeerId);
2015-12-22 22:23:43 +01:00
fn timeout(&mut self, io: &mut HandlerIo, timer: TimerToken);
2015-12-02 12:07:46 +01:00
}
2015-12-17 11:42:30 +01:00
pub struct NetworkClient;
2015-12-22 22:23:43 +01:00
pub type NetworkService = service::NetworkService;
2015-12-17 11:42:30 +01:00