reth_network_peers

Struct Enr

pub struct Enr<K>
where 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§

§

impl<K> Enr<K>
where K: EnrKey,

pub fn builder() -> Builder<K>

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

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

Get an empty Enr for the v4 identity scheme.

pub const fn node_id(&self) -> NodeId

The NodeId for the record.

pub const fn seq(&self) -> u64

The current sequence number of the ENR record.

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.

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

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

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.

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

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

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

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

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

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

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

The id of ENR record if it is defined.

pub fn client_info(&self) -> Option<(String, String, Option<String>)>

Returns EIP-7636 entry if it is defined.

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

The TCP port of ENR record if it is defined.

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

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

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

The UDP port of ENR record if it is defined.

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

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

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

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

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

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

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

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

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

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

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

The signature of the ENR record.

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

Returns the public key of the ENR record.

§Panics

Will panic if the public key is not supported.

pub fn verify(&self) -> bool

Verify the signature of the ENR record.

pub fn compare_content(&self, other: &Enr<K>) -> bool

Compare if the content of 2 Enr’s match.

pub fn to_base64(&self) -> String

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

pub fn size(&self) -> usize

Returns the current size of the ENR.

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

Allows setting the sequence number to an arbitrary value.

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

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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

Sets a new public key for the record.

pub fn is_udp_reachable(&self) -> bool

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

pub fn is_tcp_reachable(&self) -> bool

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

Trait Implementations§

§

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

§

fn clone(&self) -> Enr<K>

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
§

impl<K> Debug for Enr<K>
where K: EnrKey,

§

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

Formats the value using the given formatter. Read more
§

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

§

fn decode(buf: &mut &[u8]) -> Result<Enr<K>, Error>

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

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

Available on crate feature serde only.
§

fn deserialize<D>( deserializer: D, ) -> Result<Enr<K>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

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

impl<K> Display for Enr<K>
where K: EnrKey,

§

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

Formats the value using the given formatter. Read more
§

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

§

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

Encodes the type into the out buffer.
§

fn length(&self) -> usize

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

impl From<Enr<SecretKey>> for AnyNode

Available on crate feature secp256k1 only.
Source§

fn from(value: Enr<SecretKey>) -> Self

Converts to this type from the input type.
§

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

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

§

type Err = String

The associated error which can be returned from parsing.
§

fn from_str(base64_string: &str) -> Result<Enr<K>, <Enr<K> as FromStr>::Err>

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

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

§

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

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
§

impl<K> IntoIterator for Enr<K>
where K: EnrKey,

§

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?
§

fn into_iter(self) -> <Enr<K> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
§

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

§

fn eq(&self, other: &Enr<K>) -> 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.
§

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

Available on crate feature serde only.
§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

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

impl TryFrom<&Enr<SecretKey>> for NodeRecord

Available on crate feature secp256k1 only.
Source§

type Error = NodeRecordParseError

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

fn try_from(enr: &Enr<SecretKey>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Enr<SecretKey>> for NodeRecord

Available on crate feature secp256k1 only.
Source§

type Error = NodeRecordParseError

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

fn try_from(enr: Enr<SecretKey>) -> Result<Self, Self::Error>

Performs the conversion.
§

impl<K> Eq for Enr<K>
where K: EnrKey,

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

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

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

§

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

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

§

fn vzip(self) -> V

Source§

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

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 88 bytes