Struct enr::Enr

source ·
pub struct Enr<K: EnrKey> { /* private fields */ }
Expand description

The ENR, allowing for arbitrary signing algorithms.

This struct will always have a valid signature, known public key type, sequence number and NodeId. All other parameters are variable/optional.

Implementations§

source§

impl<K: EnrKey> Enr<K>

source

pub fn builder() -> Builder<K>

Get a builder::Builder with the default identity scheme.

source

pub fn empty(signing_key: &K) -> Result<Self, Error>

Get an empty Enr for the v4 identity scheme.

source

pub const fn node_id(&self) -> NodeId

The NodeId for the record.

source

pub const fn seq(&self) -> u64

The current sequence number of the ENR record.

source

pub fn get(&self, key: impl AsRef<[u8]>) -> Option<Bytes>

👎Deprecated since 0.11.2: use get_decodable

Reads a custom key from the record if it exists, decoded as data. Caution! Only use for data that is not an aggregate type. Default to using get_decodable.

source

pub fn get_decodable<T: Decodable>( &self, key: impl AsRef<[u8]> ) -> Option<Result<T, DecoderError>>

Reads a custom key from the record if it exists, decoded as T.

source

pub fn get_raw_rlp(&self, key: impl AsRef<[u8]>) -> Option<&[u8]>

Reads a custom key from the record if it exists as raw RLP bytes.

source

pub fn iter(&self) -> impl Iterator<Item = (&Vec<u8>, &[u8])>

Returns an iterator over all key/value pairs in the ENR.

source

pub fn ip4(&self) -> Option<Ipv4Addr>

Returns the IPv4 address of the ENR record if it is defined.

source

pub fn ip6(&self) -> Option<Ipv6Addr>

Returns the IPv6 address of the ENR record if it is defined.

source

pub fn id(&self) -> Option<String>

The id of ENR record if it is defined.

source

pub fn tcp4(&self) -> Option<u16>

The TCP port of ENR record if it is defined.

source

pub fn tcp6(&self) -> Option<u16>

The IPv6-specific TCP port of ENR record if it is defined.

source

pub fn udp4(&self) -> Option<u16>

The UDP port of ENR record if it is defined.

source

pub fn udp6(&self) -> Option<u16>

The IPv6-specific UDP port of ENR record if it is defined.

source

pub fn udp4_socket(&self) -> Option<SocketAddrV4>

Provides a socket (based on the UDP port), if the IPv4 and UDP fields are specified.

source

pub fn udp6_socket(&self) -> Option<SocketAddrV6>

Provides a socket (based on the UDP port), if the IPv6 and UDP fields are specified.

source

pub fn tcp4_socket(&self) -> Option<SocketAddrV4>

Provides a socket (based on the TCP port), if the IP and TCP fields are specified.

source

pub fn tcp6_socket(&self) -> Option<SocketAddrV6>

Provides a socket (based on the TCP port), if the IPv6 and TCP6 fields are specified.

source

pub fn signature(&self) -> &[u8]

The signature of the ENR record.

source

pub fn public_key(&self) -> K::PublicKey

Returns the public key of the ENR record.

§Panics

Will panic if the public key is not supported.

source

pub fn verify(&self) -> bool

Verify the signature of the ENR record.

source

pub fn compare_content(&self, other: &Self) -> bool

Compare if the content of 2 Enr’s match.

source

pub fn to_base64(&self) -> String

Provides the URL-safe base64 encoded “text” version of the ENR prefixed by “enr:”.

source

pub fn size(&self) -> usize

Returns the current size of the ENR.

source

pub fn set_seq(&mut self, seq: u64, key: &K) -> Result<(), Error>

Allows setting the sequence number to an arbitrary value.

source

pub fn insert<T: Encodable>( &mut self, key: impl AsRef<[u8]>, value: &T, enr_key: &K ) -> Result<Option<Bytes>, Error>

Adds or modifies a key/value to the ENR record. A EnrKey is required to re-sign the record once modified.

Returns the previous value as rlp encoded bytes in the record if it exists.

source

pub fn insert_raw_rlp( &mut self, key: impl AsRef<[u8]>, value: Bytes, enr_key: &K ) -> Result<Option<Bytes>, Error>

Adds or modifies a key/value to the ENR record. A EnrKey is required to re-sign the record once modified. The value here is interpreted as raw RLP data.

Returns the previous value as rlp encoded bytes in the record if it exists.

source

pub fn set_ip(&mut self, ip: IpAddr, key: &K) -> Result<Option<IpAddr>, Error>

Sets the ip field of the ENR. Returns any pre-existing IP address in the record.

source

pub fn set_udp4(&mut self, udp: u16, key: &K) -> Result<Option<u16>, Error>

Sets the udp field of the ENR. Returns any pre-existing UDP port in the record.

source

pub fn set_udp6(&mut self, udp: u16, key: &K) -> Result<Option<u16>, Error>

Sets the udp6 field of the ENR. Returns any pre-existing UDP port in the record.

source

pub fn set_tcp4(&mut self, tcp: u16, key: &K) -> Result<Option<u16>, Error>

Sets the tcp field of the ENR. Returns any pre-existing tcp port in the record.

source

pub fn set_tcp6(&mut self, tcp: u16, key: &K) -> Result<Option<u16>, Error>

Sets the tcp6 field of the ENR. Returns any pre-existing tcp6 port in the record.

source

pub fn set_udp_socket( &mut self, socket: SocketAddr, key: &K ) -> Result<(), Error>

Sets the IP and UDP port in a single update with a single increment in sequence number.

source

pub fn set_tcp_socket( &mut self, socket: SocketAddr, key: &K ) -> Result<(), Error>

Sets the IP and TCP port in a single update with a single increment in sequence number.

source

pub fn remove_insert<'a>( &mut self, remove_keys: impl Iterator<Item = impl AsRef<[u8]>>, insert_key_values: impl Iterator<Item = (impl AsRef<[u8]>, &'a [u8])>, enr_key: &K ) -> Result<(Vec<Option<Bytes>>, Vec<Option<Bytes>>), Error>

Removes key/value mappings and adds or overwrites key/value mappings to the ENR record as one sequence number update. An EnrKey is required to re-sign the record once modified. Reverts whole ENR record on error.

Returns the previous values as rlp encoded bytes if they exist for the removed and added/ overwritten keys.

source

pub fn set_public_key( &mut self, public_key: &K::PublicKey, key: &K ) -> Result<(), Error>

Sets a new public key for the record.

source

pub fn is_udp_reachable(&self) -> bool

Returns whether the node can be reached over UDP or not.

source

pub fn is_tcp_reachable(&self) -> bool

Returns whether the node can be reached over TCP or not.

Trait Implementations§

source§

impl<K: EnrKey> Clone for Enr<K>

source§

fn clone(&self) -> Self

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<K: EnrKey> Debug for Enr<K>

source§

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

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

impl<K: EnrKey> Decodable for Enr<K>

source§

fn decode(buf: &mut &[u8]) -> Result<Self, DecoderError>

Decodes the blob into the appropriate type. buf must be advanced past the decoded object.
source§

impl<'de, K: EnrKey> Deserialize<'de> for Enr<K>

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<K: EnrKey> Display for Enr<K>

source§

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

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

impl<K: EnrKey> Encodable for Enr<K>

source§

fn encode(&self, out: &mut dyn BufMut)

Encodes the type into the out buffer.
source§

fn length(&self) -> usize

Returns the length of the encoding of this type in bytes. Read more
source§

impl<T: EnrKey> From<&Enr<T>> for NodeId

source§

fn from(enr: &Enr<T>) -> Self

Converts to this type from the input type.
source§

impl<T: EnrKey> From<Enr<T>> for NodeId

source§

fn from(enr: Enr<T>) -> Self

Converts to this type from the input type.
source§

impl<K: EnrKey> FromStr for Enr<K>

Convert a URL-SAFE base64 encoded ENR into an ENR.

§

type Err = String

The associated error which can be returned from parsing.
source§

fn from_str(base64_string: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl<K: EnrKey> Hash for Enr<K>

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<K: EnrKey> IntoIterator for Enr<K>

§

type Item = (Vec<u8>, Bytes)

The type of the elements being iterated over.
§

type IntoIter = EnrIntoIter

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<K: EnrKey> PartialEq for Enr<K>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<K: EnrKey> Serialize for Enr<K>

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<K: EnrKey> Eq for Enr<K>

Auto Trait Implementations§

§

impl<K> Freeze for Enr<K>

§

impl<K> RefUnwindSafe for Enr<K>
where K: RefUnwindSafe,

§

impl<K> Send for Enr<K>

§

impl<K> Sync for Enr<K>

§

impl<K> Unpin for Enr<K>

§

impl<K> UnwindSafe for Enr<K>
where K: UnwindSafe,

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> 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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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

§

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