Struct NetAddr

Source
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

Source

pub fn is_relayable(&self) -> bool

| Whether this address should be relayed | to other peers even if we can’t reach | it ourselves. |

Source

pub fn serialize<Stream>(&self, s: &mut Stream)

| Serialize to a stream. |

Source

pub fn unserialize<Stream>(&mut self, s: &mut Stream)

| Unserialize from a stream. |

Source

pub fn serialize_v1array(&self, arr: &mut [u8; 16])

| Serialize in pre-ADDRv2/BIP155 format | to an array. |

Source

pub fn serialize_v1stream<Stream>(&self, s: &mut Stream)

| Serialize in pre-ADDRv2/BIP155 format | to a stream. |

Source

pub fn serialize_v2stream<Stream>(&self, s: &mut Stream)

| Serialize as ADDRv2 / BIP155. |

Source

pub fn unserialize_v1array(&mut self, arr: &mut [u8; 16])

| Unserialize from a pre-ADDRv2/BIP155 | format from an array. |

Source

pub fn unserialize_v1stream<Stream>(&mut self, s: &mut Stream)

| Unserialize from a pre-ADDRv2/BIP155 | format from a stream. |

Source

pub fn unserialize_v2stream<Stream>(&mut self, s: &mut Stream)

| Unserialize from a ADDRv2 / BIP155 format. |

Source

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. |

Source

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. |

Source

pub fn setip(&mut self, ip_in: &NetAddr)

Source

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. |

Source

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

Source

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() |

Source

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() |

Source

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() |

Source

pub fn new(ipv_6addr: &In6Addr, scope: Option<u32>) -> Self

Source

pub fn is_bind_any(&self) -> bool

| INADDR_ANY equivalent |

Source

pub fn is_ipv4(&self) -> bool

| IPv4 mapped address (::FFFF:0:0/96, | 0.0.0.0/0) |

Source

pub fn is_ipv6(&self) -> bool

| IPv6 address (not mapped IPv4, not Tor) |

Source

pub fn isrfc1918(&self) -> bool

| IPv4 private networks (10.0.0.0/8, | 192.168.0.0/16, 172.16.0.0/12) |

Source

pub fn isrfc2544(&self) -> bool

| IPv4 inter-network communications | (198.18.0.0/15) |

Source

pub fn isrfc3927(&self) -> bool

| IPv4 autoconfig (169.254.0.0/16) |

Source

pub fn isrfc6598(&self) -> bool

| IPv4 ISP-level NAT (100.64.0.0/10) |

Source

pub fn isrfc5737(&self) -> bool

| IPv4 documentation addresses (192.0.2.0/24, | 198.51.100.0/24, 203.0.113.0/24) |

Source

pub fn isrfc3849(&self) -> bool

| IPv6 documentation address (2001:0DB8::/32) |

Source

pub fn isrfc3964(&self) -> bool

| IPv6 6to4 tunnelling (2002::/16) |

Source

pub fn isrfc6052(&self) -> bool

| IPv6 well-known prefix for IPv4-embedded | address (64:FF9B::/96) |

Source

pub fn isrfc4380(&self) -> bool

| IPv6 Teredo tunnelling (2001::/32) |

Source

pub fn isrfc4862(&self) -> bool

| IPv6 autoconfig (FE80::/64) |

Source

pub fn isrfc4193(&self) -> bool

| IPv6 unique local (FC00::/7) |

Source

pub fn isrfc6145(&self) -> bool

| IPv6 IPv4-translated address (::FFFF:0:0:0/96) | (actually defined in RFC2765) |

Source

pub fn isrfc4843(&self) -> bool

| IPv6 ORCHID (deprecated) (2001:10::/28) |

Source

pub fn isrfc7343(&self) -> bool

| IPv6 ORCHIDv2 (2001:20::/28) |

Source

pub fn is_he_net(&self) -> bool

| IPv6 Hurricane Electric - https://he.net | (2001:0470::/36) |

Source

pub fn is_tor(&self) -> bool

| Check whether this object represents | a TOR address. @see CNetAddr::SetSpecial(const | std::string &) |

Source

pub fn isi2p(&self) -> bool

| Check whether this object represents | an I2P address. |

Source

pub fn iscjdns(&self) -> bool

| Check whether this object represents | a CJDNS address. |

Source

pub fn is_local(&self) -> bool

Source

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. |

Source

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. |

Source

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 &) |

Source

pub fn is_addr_v1compatible(&self) -> bool

| Check if the current object can be serialized | in pre-ADDRv2/BIP155 format. |

Source

pub fn get_network(&self) -> Network

Source

pub fn to_stringip(&self) -> String

Source

pub fn to_string(&self) -> String

Source

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() |

Source

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() |

Source

pub fn has_linked_ipv4(&self) -> bool

| Whether this address has a linked IPv4 | address (see GetLinkedIPv4()). |

Source

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. |

Source

pub fn get_net_class(&self) -> Network

Source

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.

Source

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. |

Source

pub fn get_addr_bytes(&self) -> Vec<u8>

Source

pub fn get_hash(&self) -> u64

Source

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

Source§

fn is_reachable(&self) -> bool

| @return | | true if the address is in a reachable | network, false otherwise |

Source§

impl Clone for NetAddr

Source§

fn clone(&self) -> NetAddr

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NetAddr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NetAddr

Source§

fn default() -> Self

| Construct an unspecified IPv6 network | address (::/128). | | ———– | @note | | This address is considered invalid | by | | CNetAddr::IsValid() |

Source§

impl<'de> Deserialize<'de> for NetAddr

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&in_addr> for NetAddr

Source§

fn from(ipv_4addr: &InAddr) -> Self

Converts to this type from the input type.
Source§

impl Hash for NetAddr

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for NetAddr

Source§

fn cmp(&self, other: &NetAddr) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for NetAddr

Source§

fn eq(&self, other: &NetAddr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for NetAddr

Source§

fn partial_cmp(&self, other: &NetAddr) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for NetAddr

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for NetAddr

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CallHasher for T
where T: Hash + ?Sized,

Source§

default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64
where H: Hash + ?Sized, B: BuildHasher,

Source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

Source§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> StaticUpcast<T> for T

Source§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,