pub struct Peer<const CONFIG: u64, LocalMessages: ReactiveMessagingSerializer<LocalMessages> + Send + Sync + PartialEq + Debug + 'static, SenderChannel: FullDuplexUniChannel<ItemType = LocalMessages, DerivedItemType = LocalMessages> + Send + Sync, StateType: Send + Sync + Clone + Debug + 'static = ()> {
pub peer_id: ConnectionId,
pub peer_address: SocketAddr,
pub state: Mutex<Option<StateType>>,
/* private fields */
}
Expand description
Represents a reactive channel connected to a remote peer, through which we’re able to send out “local messages” of type RetryableSenderImpl::LocalMessages
.
the Self::send() method honors whatever retrying config is specified in [RetryableSenderImpl::CONST_CONFIG].
IMPLEMENTATION NOTE: GAT traits (to reduce the number of generic parameters) couldn’t be used here – even after applying this compiler bug workaround https://github.com/rust-lang/rust/issues/102211#issuecomment-1513931928
– the “error: implementation of std::marker::Send
is not general enough” bug kept on popping up in user provided closures that called other async functions.
Fields§
§peer_id: ConnectionId
§peer_address: SocketAddr
§state: Mutex<Option<StateType>>
Implementations§
Source§impl<const CONFIG: u64, LocalMessages: ReactiveMessagingSerializer<LocalMessages> + Send + Sync + PartialEq + Debug, SenderChannel: FullDuplexUniChannel<ItemType = LocalMessages, DerivedItemType = LocalMessages> + Send + Sync, StateType: Send + Sync + Clone + Debug> Peer<CONFIG, LocalMessages, SenderChannel, StateType>
impl<const CONFIG: u64, LocalMessages: ReactiveMessagingSerializer<LocalMessages> + Send + Sync + PartialEq + Debug, SenderChannel: FullDuplexUniChannel<ItemType = LocalMessages, DerivedItemType = LocalMessages> + Send + Sync, StateType: Send + Sync + Clone + Debug> Peer<CONFIG, LocalMessages, SenderChannel, StateType>
pub fn new( retryable_sender: ReactiveMessagingSender<CONFIG, LocalMessages, SenderChannel>, peer_address: SocketAddr, connection: &SocketConnection<StateType>, ) -> Self
pub fn config(&self) -> ConstConfig
Sourcepub fn create_stream(
&self,
) -> (MutinyStream<'static, LocalMessages, SenderChannel, LocalMessages>, u32)
pub fn create_stream( &self, ) -> (MutinyStream<'static, LocalMessages, SenderChannel, LocalMessages>, u32)
Asks the underlying channel to revert to Stream-mode (rather than Execution-mode), returning the Stream
pub fn send(&self, message: LocalMessages) -> Result<(), (bool, String)>
pub async fn send_async( &self, message: LocalMessages, ) -> Result<(), (bool, String)>
Sourcepub async fn set_state(&self, state: StateType)
pub async fn set_state(&self, state: StateType)
Sets this object to a user-provided state, to facilitate communications between protocol processors
(a requirement to allow the “Composite Protocol Stacking” pattern).
See also Self::take_state()
Sourcepub fn try_set_state(&self, state: StateType) -> bool
pub fn try_set_state(&self, state: StateType) -> bool
Use [set_state()] (async) if possible
Sourcepub async fn take_state(&self) -> Option<StateType>
pub async fn take_state(&self) -> Option<StateType>
“Takes” this object’s user-provided state, previously set by Self::set_state() – used to facilitate communications between protocol processors (a requirement to allow the “Composite Protocol Stacking” pattern)
Sourcepub fn try_take_state(&self) -> Option<Option<StateType>>
pub fn try_take_state(&self) -> Option<Option<StateType>>
Use Self::take_state() (async) if possible