crate::ix!();
pub const NUM_SOURCES: usize = 64;
pub const NUM_ADDRESSES_PER_SOURCE: usize = 256;
lazy_static!{
pub static ref SOURCES: Arc<Mutex<Vec<Address>>> = Arc::new(Mutex::new(vec![]));
pub static ref ADDRESSES: Arc<Mutex<Vec<Vec<Address>>>> = Arc::new(Mutex::new(vec![]));
}
pub fn create_addresses() {
if ADDRESSES.lock().len() > 0 {
return;
}
todo!();
}
#[derive(Debug,Serialize,Deserialize,Clone)]
pub struct Address {
pub service: Service,
pub n_time: u32,
pub n_services: ServiceFlags,
}
pub trait GetAddrRef {
fn addr(&self) -> &Address;
}
pub trait GetAddrMut {
fn addr_mut(&mut self) -> &mut Address;
}
impl Address {
delegate!{
to self.service {
pub fn set_sock_addr(&mut self, paddr: *const SocketAddr) -> bool;
pub fn to_string(&self) -> String;
pub fn get_port(&self) -> u16;
pub fn get_sock_addr(&self,
paddr: *mut SocketAddr,
addrlen: *mut libc::socklen_t) -> bool;
pub fn get_key(&self) -> Vec<u8>;
}
to self.service.base {
pub fn is_reachable(&self) -> bool;
pub fn is_relayable(&self) -> bool;
pub fn serialize<Stream>(&self, s: &mut Stream);
pub fn unserialize<Stream>(&mut self, s: &mut Stream);
pub fn serialize_v1array(&self, arr: &mut [u8; net_addr::V1_SERIALIZATION_SIZE]);
pub fn serialize_v1stream<Stream>(&self, s: &mut Stream);
pub fn serialize_v2stream<Stream>(&self, s: &mut Stream);
pub fn unserialize_v1array(&mut self, arr: &mut [u8; net_addr::V1_SERIALIZATION_SIZE]);
pub fn unserialize_v1stream<Stream>(&mut self, s: &mut Stream);
pub fn unserialize_v2stream<Stream>(&mut self, s: &mut Stream);
pub fn get_bip155network(&self) -> net_addr::BIP155Network;
pub fn set_net_from_bip155network(&mut self,
possible_bip155_net: u8,
address_size: usize) -> bool;
pub fn setip(&mut self, ip_in: &NetAddr);
pub fn set_legacy_ipv6(&mut self, ipv6: &[u8]);
pub fn set_internal(&mut self, name: &str) -> bool;
pub fn set_special(&mut self, addr: &String) -> bool;
pub fn set_tor(&mut self, addr: &String) -> bool;
pub fn seti2p(&mut self, addr: &String) -> bool;
pub fn is_bind_any(&self) -> bool;
pub fn is_ipv4(&self) -> bool;
pub fn is_ipv6(&self) -> bool;
pub fn isrfc1918(&self) -> bool;
pub fn isrfc2544(&self) -> bool;
pub fn isrfc3927(&self) -> bool;
pub fn isrfc6598(&self) -> bool;
pub fn isrfc5737(&self) -> bool;
pub fn isrfc3849(&self) -> bool;
pub fn isrfc3964(&self) -> bool;
pub fn isrfc6052(&self) -> bool;
pub fn isrfc4380(&self) -> bool;
pub fn isrfc4862(&self) -> bool;
pub fn isrfc4193(&self) -> bool;
pub fn isrfc6145(&self) -> bool;
pub fn isrfc4843(&self) -> bool;
pub fn isrfc7343(&self) -> bool;
pub fn is_he_net(&self) -> bool;
pub fn is_tor(&self) -> bool;
pub fn isi2p(&self) -> bool;
pub fn iscjdns(&self) -> bool;
pub fn is_local(&self) -> bool;
pub fn is_valid(&self) -> bool;
pub fn is_routable(&self) -> bool;
pub fn is_internal(&self) -> bool;
pub fn is_addr_v1compatible(&self) -> bool;
pub fn get_network(&self) -> Network;
pub fn get_in_addr(&self, pipv_4addr: *mut InAddr) -> bool;
pub fn get_in_6addr(&self, pipv_6addr: *mut In6Addr) -> bool;
pub fn has_linked_ipv4(&self) -> bool;
pub fn get_linked_ipv4(&self) -> u32;
pub fn get_net_class(&self) -> Network;
pub fn get_mappedas(&self, asmap: &Vec<bool>) -> u32;
pub fn get_group(&self, asmap: &Vec<bool>) -> Vec<u8>;
pub fn get_addr_bytes(&self) -> Vec<u8>;
pub fn get_hash(&self) -> u64;
pub fn get_reachability_from(&self, paddr_partner: *const NetAddr) -> i32;
}
}
}
impl Default for Address {
fn default() -> Self {
Self {
service: Service::default(),
n_time: address::TIME_INIT,
n_services: ServiceFlags::NODE_NONE,
}
}
}
pub mod address {
use super::*;
pub const TIME_INIT: u32 = 100000000;
pub const DISK_VERSION_INIT: u32 = 220000;
pub const DISK_VERSION_IGNORE_MASK: u32 = 0b00000000_00000111_11111111_11111111;
pub const DISK_VERSION_ADDRV2: u32 = 1 << 29;
const_assert!{
(DISK_VERSION_INIT & !DISK_VERSION_IGNORE_MASK) == 0
}
const_assert!{
(DISK_VERSION_ADDRV2 & DISK_VERSION_IGNORE_MASK) == 0
}
}
lazy_static!{
}
impl PartialEq<Address> for Address {
#[inline] fn eq(&self, other: &Address) -> bool {
self.n_time == other.n_time
&& self.n_services == other.n_services
&& self.service == other.service
}
}
impl Eq for Address {}
impl Address {
pub fn new(
ip_in: Service,
n_services_in: ServiceFlags) -> Self {
todo!();
}
pub fn new_with_time_in(
ip_in: Service,
n_services_in: ServiceFlags,
n_time_in: u32) -> Self {
todo!();
}
}