use std::net::SocketAddrV4;
use crate::Id;
use super::Actor;
#[derive(Debug, Clone)]
pub struct Info {
id: Id,
local_addr: SocketAddrV4,
public_address: Option<SocketAddrV4>,
firewalled: bool,
dht_size_estimate: (usize, f64),
server_mode: bool,
routing_table_size: usize,
singing_peers_routing_table_size: usize,
}
impl Info {
pub fn id(&self) -> &Id {
&self.id
}
pub fn local_addr(&self) -> SocketAddrV4 {
self.local_addr
}
pub fn public_address(&self) -> Option<SocketAddrV4> {
self.public_address
}
pub fn firewalled(&self) -> bool {
self.firewalled
}
pub fn server_mode(&self) -> bool {
self.server_mode
}
pub fn dht_size_estimate(&self) -> (usize, f64) {
self.dht_size_estimate
}
pub fn routing_table_size(&self) -> usize {
self.routing_table_size
}
pub fn singing_peers_routing_table_size(&self) -> usize {
self.singing_peers_routing_table_size
}
}
impl From<&Actor> for Info {
fn from(actor: &Actor) -> Self {
Self {
id: *actor.id(),
public_address: actor.core.public_address,
firewalled: actor.core.firewalled,
server_mode: actor.core.server_mode,
local_addr: actor.socket.local_addr(),
dht_size_estimate: actor.core.routing_table.dht_size_estimate(),
routing_table_size: actor.core.routing_table.size(),
singing_peers_routing_table_size: actor.core.signed_peers_routing_table.size(),
}
}
}