enr

Struct 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 client_info(&self) -> Option<(String, String, Option<String>)>

Returns EIP-7636 entry 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 remove_udp4(&mut self, key: &K) -> Result<(), Error>

Unsets the udp field on the ENR.

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 remove_udp6(&mut self, key: &K) -> Result<(), Error>

Unsets the udp6 field on the ENR.

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 remove_tcp(&mut self, key: &K) -> Result<(), Error>

Unsets the tcp field on the ENR.

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 remove_tcp6(&mut self, key: &K) -> Result<(), Error>

Unsets the tcp6 field on the ENR.

Source

pub fn set_client_info( &mut self, name: String, version: String, build: Option<String>, key: &K, ) -> Result<(), Error>

Sets the EIP-7636 client field 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 remove_udp_socket(&mut self, key: &K) -> Result<(), Error>

Unsets the ip and udp fields on the ENR.

Source

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

Unsets the ip6 and udp6 fields on the ENR.

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_tcp_socket(&mut self, key: &K) -> Result<(), Error>

Unsets the ip and tcp fields on the ENR.

Source

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

Unsets the ip6 and tcp6 fields on the ENR.

Source

pub fn remove_key( &mut self, content_key: impl AsRef<[u8]>, enr_key: &K, ) -> Result<(), Error>

Removes a key from the ENR.

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.

Source§

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>

Source§

type Item = (Vec<u8>, Bytes)

The type of the elements being iterated over.
Source§

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

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<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> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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

Source§

type Output = T

Should always be Self
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> 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>,

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