Host info

This commit is contained in:
arkpar 2016-01-14 19:04:13 +01:00
parent db25f7e590
commit df2e9854c7
2 changed files with 14 additions and 3 deletions

View File

@ -223,7 +223,7 @@ enum ConnectionEntry {
/// Root IO handler. Manages protocol handlers, IO timers and network connections.
pub struct Host<Message> where Message: Send {
info: HostInfo,
pub info: HostInfo,
udp_socket: UdpSocket,
listener: TcpListener,
connections: Slab<ConnectionEntry>,

View File

@ -8,15 +8,19 @@ use io::*;
/// `Message` defines a notification data type.
pub struct NetworkService<Message> where Message: Send + 'static {
io_service: IoService<NetworkIoMessage<Message>>,
host_info: String,
}
impl<Message> NetworkService<Message> where Message: Send + 'static {
/// Starts IO event loop
pub fn start() -> Result<NetworkService<Message>, UtilError> {
let mut io_service = try!(IoService::<NetworkIoMessage<Message>>::start());
try!(io_service.register_handler(Box::new(Host::new())));
let host = Box::new(Host::new());
let host_info = host.info.client_version.clone();
try!(io_service.register_handler(host));
Ok(NetworkService {
io_service: io_service
io_service: io_service,
host_info: host_info,
})
}
@ -41,9 +45,16 @@ impl<Message> NetworkService<Message> where Message: Send + 'static {
Ok(())
}
/// Returns host identifier string as advertised to other peers
pub fn host_info(&self) -> String {
self.host_info.clone()
}
/// Returns underlying io service.
pub fn io(&mut self) -> &mut IoService<NetworkIoMessage<Message>> {
&mut self.io_service
}
}