hopr_transport_session/
lib.rs

1//! [`Session`] object providing the session functionality over the HOPR transport
2//!
3//! The session proxies the user interactions with the transport in order to hide the
4//! advanced interactions and functionality.
5
6pub mod errors;
7pub mod initiation;
8mod manager;
9pub mod traits;
10pub mod types;
11
12pub use manager::{DispatchResult, SessionManager, SessionManagerConfig};
13
14use crate::types::SessionTarget;
15use hopr_network_types::prelude::state::SessionFeature;
16pub use hopr_network_types::types::*;
17use libp2p_identity::PeerId;
18pub use types::{IncomingSession, Session, SessionId, SESSION_USABLE_MTU_SIZE};
19#[cfg(feature = "serde")]
20use {
21    serde::{Deserialize, Serialize},
22    serde_with::{As, DisplayFromStr},
23};
24
25/// Capabilities of a session.
26#[repr(u8)]
27#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, strum::EnumIter, strum::Display, strum::EnumString)]
28#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
29pub enum Capability {
30    /// Frame segmentation
31    Segmentation,
32    /// Frame retransmission (ACK and NACK-based)
33    Retransmission,
34    /// Frame retransmission (only ACK-based)
35    RetransmissionAckOnly,
36    /// Disable packet buffering
37    NoDelay,
38}
39
40impl IntoIterator for Capability {
41    type Item = SessionFeature;
42    type IntoIter = std::vec::IntoIter<Self::Item>;
43
44    fn into_iter(self) -> Self::IntoIter {
45        match self {
46            Capability::Segmentation => vec![],
47            Capability::Retransmission => vec![
48                SessionFeature::AcknowledgeFrames,
49                SessionFeature::RequestIncompleteFrames,
50                SessionFeature::RetransmitFrames,
51            ],
52            Capability::RetransmissionAckOnly => {
53                vec![SessionFeature::AcknowledgeFrames, SessionFeature::RetransmitFrames]
54            }
55            Capability::NoDelay => vec![SessionFeature::NoDelay],
56        }
57        .into_iter()
58    }
59}
60
61/// Configuration for the session.
62///
63/// Relevant primarily for the client, since the server is only
64/// a reactive component in regard to the session concept.
65#[derive(Debug, PartialEq, Clone)]
66#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
67pub struct SessionClientConfig {
68    /// The peer to which the session should be established.
69    #[cfg_attr(feature = "serde", serde(with = "As::<DisplayFromStr>"))]
70    pub peer: PeerId,
71
72    /// The fixed path options for the session.
73    pub path_options: RoutingOptions,
74
75    /// Contains target protocol and optionally encrypted target of the session.
76    pub target: SessionTarget,
77
78    /// Capabilities offered by the session.
79    pub capabilities: Vec<Capability>,
80}