pub struct NetAddr {
pub addr: PreVector<u8, ADDR_IPV6_SIZE>,
pub net: Network,
pub scope_id: u32,
}
Expand description
| Network address. |
Fields§
§addr: PreVector<u8, ADDR_IPV6_SIZE>
| Raw representation of the network address. | | In network byte order (big endian) for | IPv4 and IPv6. |
net: Network
| Network to which this address belongs. |
scope_id: u32
| Scope id if scoped/link-local IPV6 | address. | | See https://tools.ietf.org/html/rfc4007 |
Implementations§
Source§impl NetAddr
impl NetAddr
Sourcepub fn is_relayable(&self) -> bool
pub fn is_relayable(&self) -> bool
| Whether this address should be relayed | to other peers even if we can’t reach | it ourselves. |
Sourcepub fn serialize<Stream>(&self, s: &mut Stream)
pub fn serialize<Stream>(&self, s: &mut Stream)
| Serialize to a stream. |
Sourcepub fn unserialize<Stream>(&mut self, s: &mut Stream)
pub fn unserialize<Stream>(&mut self, s: &mut Stream)
| Unserialize from a stream. |
Sourcepub fn serialize_v1array(&self, arr: &mut [u8; 16])
pub fn serialize_v1array(&self, arr: &mut [u8; 16])
| Serialize in pre-ADDRv2/BIP155 format | to an array. |
Sourcepub fn serialize_v1stream<Stream>(&self, s: &mut Stream)
pub fn serialize_v1stream<Stream>(&self, s: &mut Stream)
| Serialize in pre-ADDRv2/BIP155 format | to a stream. |
Sourcepub fn serialize_v2stream<Stream>(&self, s: &mut Stream)
pub fn serialize_v2stream<Stream>(&self, s: &mut Stream)
| Serialize as ADDRv2 / BIP155. |
Sourcepub fn unserialize_v1array(&mut self, arr: &mut [u8; 16])
pub fn unserialize_v1array(&mut self, arr: &mut [u8; 16])
| Unserialize from a pre-ADDRv2/BIP155 | format from an array. |
Sourcepub fn unserialize_v1stream<Stream>(&mut self, s: &mut Stream)
pub fn unserialize_v1stream<Stream>(&mut self, s: &mut Stream)
| Unserialize from a pre-ADDRv2/BIP155 | format from a stream. |
Sourcepub fn unserialize_v2stream<Stream>(&mut self, s: &mut Stream)
pub fn unserialize_v2stream<Stream>(&mut self, s: &mut Stream)
| Unserialize from a ADDRv2 / BIP155 format. |
Sourcepub fn get_bip155network(&self) -> BIP155Network
pub fn get_bip155network(&self) -> BIP155Network
| Get the BIP155 network id of this address. | | Must not be called for IsInternal() | objects. | | | ———– | @return | | BIP155 network id, except TORV2 which | is no longer supported. |
Sourcepub fn set_net_from_bip155network(
&mut self,
possible_bip155_net: u8,
address_size: usize,
) -> bool
pub fn set_net_from_bip155network( &mut self, possible_bip155_net: u8, address_size: usize, ) -> bool
| Set m_net
from the provided BIP155
| network id and size after validation.
|
| ———–
| @return
|
| true the network was recognized, is
valid and m_net was set |
---|
@return |
| | false not recognised (from future?) | and should be silently ignored @throws | std::ios_base::failure if the network | is one of the BIP155 founding networks | (id 1..6) with wrong address size. |
pub fn setip(&mut self, ip_in: &NetAddr)
Sourcepub fn set_legacy_ipv6(&mut self, ipv6: &[u8])
pub fn set_legacy_ipv6(&mut self, ipv6: &[u8])
| Set from a legacy IPv6 address.
|
| Legacy IPv6 address may be a normal IPv6
| address, or another address (e.g. IPv4)
| disguised as IPv6.
|
| This encoding is used in the legacy addr
| encoding.
|
Sourcepub fn set_internal(&mut self, name: &str) -> bool
pub fn set_internal(&mut self, name: &str) -> bool
| Create an “internal” address that represents | a name or FQDN. AddrMan uses these fake | addresses to keep track of which DNS | seeds were used. | | | ———– | @return | | Whether or not the operation was successful. | @see NET_INTERNAL, INTERNAL_IN_IPV6_PREFIX, | CNetAddr::IsInternal(), CNetAddr::IsRFC4193() |
Source§impl NetAddr
impl NetAddr
Sourcepub fn set_special(&mut self, addr: &String) -> bool
pub fn set_special(&mut self, addr: &String) -> bool
| Parse a Tor or I2P address and set this | object to it. | | ———– | @param[in] addr | | Address to parse, for example pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion | or ukeu3k5oycgaauneqgtnvselmt4yemvoilkln7jpvamvfx7dnkdq.b32.i2p. | | ———– | @return | | Whether the operation was successful. | @see CNetAddr::IsTor(), CNetAddr::IsI2P() |
Sourcepub fn set_tor(&mut self, addr: &String) -> bool
pub fn set_tor(&mut self, addr: &String) -> bool
| Parse a Tor address and set this object | to it. | | ———– | @param[in] addr | | Address to parse, must be a valid C string, | for example pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion. | | ———– | @return | | Whether the operation was successful. | @see CNetAddr::IsTor() |
Sourcepub fn seti2p(&mut self, addr: &String) -> bool
pub fn seti2p(&mut self, addr: &String) -> bool
| Parse an I2P address and set this object | to it. | | ———– | @param[in] addr | | Address to parse, must be a valid C string, | for example ukeu3k5oycgaauneqgtnvselmt4yemvoilkln7jpvamvfx7dnkdq.b32.i2p. | | ———– | @return | | Whether the operation was successful. | @see CNetAddr::IsI2P() |
pub fn new(ipv_6addr: &In6Addr, scope: Option<u32>) -> Self
Sourcepub fn is_bind_any(&self) -> bool
pub fn is_bind_any(&self) -> bool
| INADDR_ANY equivalent |
Sourcepub fn isrfc1918(&self) -> bool
pub fn isrfc1918(&self) -> bool
| IPv4 private networks (10.0.0.0/8, | 192.168.0.0/16, 172.16.0.0/12) |
Sourcepub fn isrfc5737(&self) -> bool
pub fn isrfc5737(&self) -> bool
| IPv4 documentation addresses (192.0.2.0/24, | 198.51.100.0/24, 203.0.113.0/24) |
Sourcepub fn isrfc6052(&self) -> bool
pub fn isrfc6052(&self) -> bool
| IPv6 well-known prefix for IPv4-embedded | address (64:FF9B::/96) |
Sourcepub fn isrfc6145(&self) -> bool
pub fn isrfc6145(&self) -> bool
| IPv6 IPv4-translated address (::FFFF:0:0:0/96) | (actually defined in RFC2765) |
Sourcepub fn is_he_net(&self) -> bool
pub fn is_he_net(&self) -> bool
| IPv6 Hurricane Electric - https://he.net | (2001:0470::/36) |
Sourcepub fn is_tor(&self) -> bool
pub fn is_tor(&self) -> bool
| Check whether this object represents | a TOR address. @see CNetAddr::SetSpecial(const | std::string &) |
pub fn is_local(&self) -> bool
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
| @note | | A valid address may or may not be publicly | routable on the global internet. As | in, the set of valid addresses is a superset | of the set of publicly routable addresses. | @see CNetAddr::IsRoutable() | | ———– | @return | | Whether or not this network address | is a valid address that @a could be used | to refer to an actual host. |
Sourcepub fn is_routable(&self) -> bool
pub fn is_routable(&self) -> bool
| @note | | A routable address is always valid. | As in, the set of routable addresses | is a subset of the set of valid addresses. | @see CNetAddr::IsValid() | | ———– | @return | | Whether or not this network address | is publicly routable on the global internet. |
Sourcepub fn is_internal(&self) -> bool
pub fn is_internal(&self) -> bool
| @return | | Whether or not this is a dummy address | that represents a name. @see CNetAddr::SetInternal(const | std::string &) |
Sourcepub fn is_addr_v1compatible(&self) -> bool
pub fn is_addr_v1compatible(&self) -> bool
| Check if the current object can be serialized | in pre-ADDRv2/BIP155 format. |
pub fn get_network(&self) -> Network
pub fn to_stringip(&self) -> String
pub fn to_string(&self) -> String
Sourcepub fn get_in_addr(&self, pipv_4addr: *mut InAddr) -> bool
pub fn get_in_addr(&self, pipv_4addr: *mut InAddr) -> bool
| Try to get our IPv4 address. | | ———– | @param[out] pipv4Addr | | The in_addr struct to which to copy. | | ———– | @return | | Whether or not the operation was successful, | in particular, whether or not our address | was an IPv4 address. @see CNetAddr::IsIPv4() |
Sourcepub fn get_in_6addr(&self, pipv_6addr: *mut In6Addr) -> bool
pub fn get_in_6addr(&self, pipv_6addr: *mut In6Addr) -> bool
| Try to get our IPv6 address. | | ———– | @param[out] pipv6Addr | | The in6_addr struct to which to copy. | | ———– | @return | | Whether or not the operation was successful, | in particular, whether or not our address | was an IPv6 address. @see CNetAddr::IsIPv6() |
Sourcepub fn has_linked_ipv4(&self) -> bool
pub fn has_linked_ipv4(&self) -> bool
| Whether this address has a linked IPv4 | address (see GetLinkedIPv4()). |
Sourcepub fn get_linked_ipv4(&self) -> u32
pub fn get_linked_ipv4(&self) -> u32
| For IPv4, mapped IPv4, SIIT translated | | IPv4, Teredo, 6to4 tunneled addresses, | return the relevant IPv4 address as | a uint32. |
pub fn get_net_class(&self) -> Network
Sourcepub fn get_mappedas(&self, asmap: &Vec<bool>) -> u32
pub fn get_mappedas(&self, asmap: &Vec<bool>) -> u32
| The AS on the BGP path to the node we use | to diversify peers in AddrMan bucketing | based on the AS infrastructure. | | The ip->AS mapping depends on how asmap is | constructed.
Sourcepub fn get_group(&self, asmap: &Vec<bool>) -> Vec<u8> ⓘ
pub fn get_group(&self, asmap: &Vec<bool>) -> Vec<u8> ⓘ
| Get the canonical identifier of our | network group | | The groups are assigned in a way where | it should be costly for an attacker to | obtain addresses with many different | group identifiers, even if it is cheap | to obtain addresses with the same identifier. | | ———– | @note | | No two connections will be attempted | to addresses with the same network group. |
pub fn get_addr_bytes(&self) -> Vec<u8> ⓘ
pub fn get_hash(&self) -> u64
Sourcepub fn get_reachability_from(&self, paddr_partner: *const NetAddr) -> i32
pub fn get_reachability_from(&self, paddr_partner: *const NetAddr) -> i32
| Calculates a metric for how reachable | (*this) is from a given partner |
Trait Implementations§
Source§impl CheckIsReachable for NetAddr
impl CheckIsReachable for NetAddr
Source§fn is_reachable(&self) -> bool
fn is_reachable(&self) -> bool
| @return | | true if the address is in a reachable | network, false otherwise |
Source§impl<'de> Deserialize<'de> for NetAddr
impl<'de> Deserialize<'de> for NetAddr
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Ord for NetAddr
impl Ord for NetAddr
Source§impl PartialOrd for NetAddr
impl PartialOrd for NetAddr
impl Eq for NetAddr
Auto Trait Implementations§
impl Freeze for NetAddr
impl RefUnwindSafe for NetAddr
impl Send for NetAddr
impl Sync for NetAddr
impl Unpin for NetAddr
impl UnwindSafe for NetAddr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CallHasher for T
impl<T> CallHasher for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.