Host info
This commit is contained in:
parent
db25f7e590
commit
df2e9854c7
@ -223,7 +223,7 @@ enum ConnectionEntry {
|
|||||||
|
|
||||||
/// Root IO handler. Manages protocol handlers, IO timers and network connections.
|
/// Root IO handler. Manages protocol handlers, IO timers and network connections.
|
||||||
pub struct Host<Message> where Message: Send {
|
pub struct Host<Message> where Message: Send {
|
||||||
info: HostInfo,
|
pub info: HostInfo,
|
||||||
udp_socket: UdpSocket,
|
udp_socket: UdpSocket,
|
||||||
listener: TcpListener,
|
listener: TcpListener,
|
||||||
connections: Slab<ConnectionEntry>,
|
connections: Slab<ConnectionEntry>,
|
||||||
|
@ -8,15 +8,19 @@ use io::*;
|
|||||||
/// `Message` defines a notification data type.
|
/// `Message` defines a notification data type.
|
||||||
pub struct NetworkService<Message> where Message: Send + 'static {
|
pub struct NetworkService<Message> where Message: Send + 'static {
|
||||||
io_service: IoService<NetworkIoMessage<Message>>,
|
io_service: IoService<NetworkIoMessage<Message>>,
|
||||||
|
host_info: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Message> NetworkService<Message> where Message: Send + 'static {
|
impl<Message> NetworkService<Message> where Message: Send + 'static {
|
||||||
/// Starts IO event loop
|
/// Starts IO event loop
|
||||||
pub fn start() -> Result<NetworkService<Message>, UtilError> {
|
pub fn start() -> Result<NetworkService<Message>, UtilError> {
|
||||||
let mut io_service = try!(IoService::<NetworkIoMessage<Message>>::start());
|
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 {
|
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(())
|
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>> {
|
pub fn io(&mut self) -> &mut IoService<NetworkIoMessage<Message>> {
|
||||||
&mut self.io_service
|
&mut self.io_service
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user