[−][src]Struct discv5::session::Session
Manages active handshakes and connections between nodes in discv5. There are three main states
a session can be in, initializing (WhoAreYouSent
or RandomSent
), Untrusted
(when the
socket address of the ENR doesn't match the last_seen_socket
) and Established
(the session
has been successfully established).
Fields
state: SessionState
The current state of the Session
trusted: TrustedState
Whether the last seen socket address of the peer matches its known ENR. If it does not, the session is considered untrusted, and outgoing messages are not sent.
remote_enr: Option<Enr<CombinedKey>>
The ENR of the remote node. This may be unknown during WhoAreYouSent
states.
last_seen_socket: SocketAddr
Last seen IP address and port. This is used to determine if the session is trusted or not.
Implementations
impl Session
[src]
pub(crate) fn new_random(
tag: Tag,
remote_enr: Enr<CombinedKey>
) -> (Self, Packet)
[src]
tag: Tag,
remote_enr: Enr<CombinedKey>
) -> (Self, Packet)
Creates a new Session
instance and generates a RANDOM packet to be sent along with this
session being established. This session is set to RandomSent
state.
pub(crate) fn new_whoareyou(
node_id: &NodeId,
enr_seq: u64,
remote_enr: Option<Enr<CombinedKey>>,
auth_tag: AuthTag
) -> (Self, Packet)
[src]
node_id: &NodeId,
enr_seq: u64,
remote_enr: Option<Enr<CombinedKey>>,
auth_tag: AuthTag
) -> (Self, Packet)
Creates a new Session
and generates an associated WHOAREYOU packet. The returned session is in the
WhoAreYouSent
state.
pub(crate) fn establish_from_header(
&mut self,
local_key: &CombinedKey,
local_id: &NodeId,
remote_id: &NodeId,
id_nonce: Nonce,
auth_header: &AuthHeader
) -> Result<bool, Discv5Error>
[src]
&mut self,
local_key: &CombinedKey,
local_id: &NodeId,
remote_id: &NodeId,
id_nonce: Nonce,
auth_header: &AuthHeader
) -> Result<bool, Discv5Error>
Generates session keys from an authentication header. If the IP of the ENR does not match the source IP address, we consider this session untrusted. The output returns a boolean which specifies if the Session is trusted or not.
pub(crate) fn encrypt_with_header(
&mut self,
tag: Tag,
local_key: &CombinedKey,
updated_enr: Option<Enr<CombinedKey>>,
local_node_id: &NodeId,
id_nonce: &Nonce,
message: &[u8]
) -> Result<Packet, Discv5Error>
[src]
&mut self,
tag: Tag,
local_key: &CombinedKey,
updated_enr: Option<Enr<CombinedKey>>,
local_node_id: &NodeId,
id_nonce: &Nonce,
message: &[u8]
) -> Result<Packet, Discv5Error>
Encrypts a message and produces an AuthMessage.
pub(crate) fn encrypt_message(
&self,
tag: Tag,
message: &[u8]
) -> Result<Packet, Discv5Error>
[src]
&self,
tag: Tag,
message: &[u8]
) -> Result<Packet, Discv5Error>
Uses the current Session
to encrypt a message. Encrypt packets with the current session
key if we are awaiting a response from AuthMessage.
pub(crate) fn decrypt_message(
&mut self,
nonce: AuthTag,
message: &[u8],
aad: &[u8]
) -> Result<Vec<u8>, Discv5Error>
[src]
&mut self,
nonce: AuthTag,
message: &[u8],
aad: &[u8]
) -> Result<Vec<u8>, Discv5Error>
Decrypts an encrypted message. If a Session is already established, the original decryption keys are tried first, upon failure, the new keys are attempted. If the new keys succeed, the session keys are updated along with the Session state.
pub(crate) fn update_enr(&mut self, enr: Enr<CombinedKey>) -> bool
[src]
pub(crate) fn update_trusted(&mut self) -> bool
[src]
Updates the trusted status of a Session. It can be promoted to an established
state, or
demoted to an untrusted
state. This value returns true if the Session has been
promoted.
pub(crate) fn set_last_seen_socket(&mut self, socket: SocketAddr)
[src]
The socket address of the last packer received from this node.
pub(crate) fn is_whoareyou_sent(&self) -> bool
[src]
pub(crate) fn is_random_sent(&self) -> bool
[src]
pub(crate) fn is_awaiting_response(&self) -> bool
[src]
pub(crate) fn remote_enr(&self) -> &Option<Enr<CombinedKey>>
[src]
pub(crate) fn is_trusted(&self) -> bool
[src]
pub(crate) fn trusted_established(&self) -> bool
[src]
Returns true if the Session is trusted and has established session keys. This state means the session is capable of sending requests.
Auto Trait Implementations
impl RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnwindSafe for Session
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,