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>
impl<K: EnrKey> Enr<K>
Sourcepub fn builder() -> Builder<K>
pub fn builder() -> Builder<K>
Get a builder::Builder
with the default identity scheme.
Sourcepub fn empty(signing_key: &K) -> Result<Self, Error>
pub fn empty(signing_key: &K) -> Result<Self, Error>
Get an empty Enr for the v4 identity scheme.
Sourcepub fn get(&self, key: impl AsRef<[u8]>) -> Option<Bytes>
👎Deprecated since 0.11.2: use get_decodable
pub fn get(&self, key: impl AsRef<[u8]>) -> Option<Bytes>
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
.
Sourcepub fn get_decodable<T: Decodable>(
&self,
key: impl AsRef<[u8]>,
) -> Option<Result<T, DecoderError>>
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
.
Sourcepub fn get_raw_rlp(&self, key: impl AsRef<[u8]>) -> Option<&[u8]>
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.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&Vec<u8>, &[u8])>
pub fn iter(&self) -> impl Iterator<Item = (&Vec<u8>, &[u8])>
Returns an iterator over all key/value pairs in the ENR.
Sourcepub fn ip4(&self) -> Option<Ipv4Addr>
pub fn ip4(&self) -> Option<Ipv4Addr>
Returns the IPv4 address of the ENR record if it is defined.
Sourcepub fn ip6(&self) -> Option<Ipv6Addr>
pub fn ip6(&self) -> Option<Ipv6Addr>
Returns the IPv6 address of the ENR record if it is defined.
Sourcepub fn client_info(&self) -> Option<(String, String, Option<String>)>
pub fn client_info(&self) -> Option<(String, String, Option<String>)>
Returns EIP-7636 entry if it is defined.
Sourcepub fn udp4_socket(&self) -> Option<SocketAddrV4>
pub fn udp4_socket(&self) -> Option<SocketAddrV4>
Provides a socket (based on the UDP port), if the IPv4 and UDP fields are specified.
Sourcepub fn udp6_socket(&self) -> Option<SocketAddrV6>
pub fn udp6_socket(&self) -> Option<SocketAddrV6>
Provides a socket (based on the UDP port), if the IPv6 and UDP fields are specified.
Sourcepub fn tcp4_socket(&self) -> Option<SocketAddrV4>
pub fn tcp4_socket(&self) -> Option<SocketAddrV4>
Provides a socket (based on the TCP port), if the IP and TCP fields are specified.
Sourcepub fn tcp6_socket(&self) -> Option<SocketAddrV6>
pub fn tcp6_socket(&self) -> Option<SocketAddrV6>
Provides a socket (based on the TCP port), if the IPv6 and TCP6 fields are specified.
Sourcepub fn public_key(&self) -> K::PublicKey
pub fn public_key(&self) -> K::PublicKey
Sourcepub fn compare_content(&self, other: &Self) -> bool
pub fn compare_content(&self, other: &Self) -> bool
Compare if the content of 2 Enr’s match.
Sourcepub fn to_base64(&self) -> String
pub fn to_base64(&self) -> String
Provides the URL-safe base64 encoded “text” version of the ENR prefixed by “enr:”.
Sourcepub fn set_seq(&mut self, seq: u64, key: &K) -> Result<(), Error>
pub fn set_seq(&mut self, seq: u64, key: &K) -> Result<(), Error>
Allows setting the sequence number to an arbitrary value.
Sourcepub fn insert<T: Encodable>(
&mut self,
key: impl AsRef<[u8]>,
value: &T,
enr_key: &K,
) -> Result<Option<Bytes>, Error>
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.
Sourcepub fn insert_raw_rlp(
&mut self,
key: impl AsRef<[u8]>,
value: Bytes,
enr_key: &K,
) -> Result<Option<Bytes>, Error>
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.
Sourcepub fn set_ip(&mut self, ip: IpAddr, key: &K) -> Result<Option<IpAddr>, Error>
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.
Sourcepub fn set_udp4(&mut self, udp: u16, key: &K) -> Result<Option<u16>, Error>
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.
Sourcepub fn set_udp6(&mut self, udp: u16, key: &K) -> Result<Option<u16>, Error>
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.
Sourcepub fn set_tcp4(&mut self, tcp: u16, key: &K) -> Result<Option<u16>, Error>
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.
Sourcepub fn set_tcp6(&mut self, tcp: u16, key: &K) -> Result<Option<u16>, Error>
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.
Sourcepub fn set_client_info(
&mut self,
name: String,
version: String,
build: Option<String>,
key: &K,
) -> Result<(), Error>
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.
Sourcepub fn set_udp_socket(
&mut self,
socket: SocketAddr,
key: &K,
) -> Result<(), Error>
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.
Sourcepub fn remove_udp_socket(&mut self, key: &K) -> Result<(), Error>
pub fn remove_udp_socket(&mut self, key: &K) -> Result<(), Error>
Unsets the ip
and udp
fields on the ENR.
Sourcepub fn remove_udp6_socket(&mut self, key: &K) -> Result<(), Error>
pub fn remove_udp6_socket(&mut self, key: &K) -> Result<(), Error>
Unsets the ip6
and udp6
fields on the ENR.
Sourcepub fn set_tcp_socket(
&mut self,
socket: SocketAddr,
key: &K,
) -> Result<(), Error>
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.
Sourcepub fn remove_tcp_socket(&mut self, key: &K) -> Result<(), Error>
pub fn remove_tcp_socket(&mut self, key: &K) -> Result<(), Error>
Unsets the ip
and tcp
fields on the ENR.
Sourcepub fn remove_tcp6_socket(&mut self, key: &K) -> Result<(), Error>
pub fn remove_tcp6_socket(&mut self, key: &K) -> Result<(), Error>
Unsets the ip6
and tcp6
fields on the ENR.
Sourcepub fn remove_key(
&mut self,
content_key: impl AsRef<[u8]>,
enr_key: &K,
) -> Result<(), Error>
pub fn remove_key( &mut self, content_key: impl AsRef<[u8]>, enr_key: &K, ) -> Result<(), Error>
Removes a key from the ENR.
Sourcepub 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>
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.
Sourcepub fn set_public_key(
&mut self,
public_key: &K::PublicKey,
key: &K,
) -> Result<(), Error>
pub fn set_public_key( &mut self, public_key: &K::PublicKey, key: &K, ) -> Result<(), Error>
Sets a new public key for the record.
Sourcepub fn is_udp_reachable(&self) -> bool
pub fn is_udp_reachable(&self) -> bool
Returns whether the node can be reached over UDP or not.
Sourcepub fn is_tcp_reachable(&self) -> bool
pub fn is_tcp_reachable(&self) -> bool
Returns whether the node can be reached over TCP or not.
Trait Implementations§
Source§impl<'de, K: EnrKey> Deserialize<'de> for Enr<K>
impl<'de, K: EnrKey> Deserialize<'de> for Enr<K>
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<K: EnrKey> IntoIterator for Enr<K>
impl<K: EnrKey> IntoIterator for Enr<K>
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> 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)