pub struct Peer {
pub peer_id: PeerId,
pub direction: PeerDirection,
pub created_at: Instant,
pub connected_at: Option<Instant>,
pub data_channel: Arc<Mutex<Option<Arc<RTCDataChannel>>>>,
pub pending_requests: Arc<Mutex<HashMap<String, PendingRequest>>>,
/* private fields */
}Expand description
WebRTC peer connection with data channel protocol
Fields§
§peer_id: PeerId§direction: PeerDirection§created_at: Instant§connected_at: Option<Instant>§data_channel: Arc<Mutex<Option<Arc<RTCDataChannel>>>>§pending_requests: Arc<Mutex<HashMap<String, PendingRequest>>>Implementations§
Source§impl Peer
impl Peer
pub async fn new( peer_id: PeerId, direction: PeerDirection, my_peer_id: PeerId, signaling_tx: Sender<SignalingMessage>, stun_servers: Vec<String>, ) -> Result<Peer, Error>
pub async fn new_with_store( peer_id: PeerId, direction: PeerDirection, my_peer_id: PeerId, signaling_tx: Sender<SignalingMessage>, stun_servers: Vec<String>, store: Option<Arc<dyn ContentStore>>, ) -> Result<Peer, Error>
pub async fn new_with_store_and_events( peer_id: PeerId, direction: PeerDirection, my_peer_id: PeerId, signaling_tx: Sender<SignalingMessage>, stun_servers: Vec<String>, store: Option<Arc<dyn ContentStore>>, state_event_tx: Option<Sender<PeerStateEvent>>, nostr_relay: Option<Arc<dyn MeshRelayClient>>, mesh_frame_tx: Option<Sender<(PeerId, MeshNostrFrame)>>, cashu_quotes: Option<Arc<CashuQuoteState>>, ) -> Result<Peer, Error>
pub fn set_store(&mut self, store: Arc<dyn ContentStore>)
pub fn state(&self) -> RTCPeerConnectionState
pub fn signaling_state(&self) -> RTCSignalingState
pub fn is_connected(&self) -> bool
pub fn htl_config(&self) -> &PeerHTLConfig
pub async fn setup_handlers(&self) -> Result<(), Error>
pub async fn connect(&self) -> Result<Value, Error>
pub async fn handle_offer(&self, offer: Value) -> Result<Value, Error>
pub async fn handle_answer(&self, answer: Value) -> Result<(), Error>
pub async fn handle_candidate(&self, candidate: Value) -> Result<(), Error>
pub fn has_data_channel(&self) -> bool
pub async fn request(&self, hash_hex: &str) -> Result<Option<Vec<u8>>, Error>
pub async fn request_with_timeout( &self, hash_hex: &str, timeout: Duration, ) -> Result<Option<Vec<u8>>, Error>
pub async fn query_nostr_events( &self, filters: Vec<Filter>, timeout: Duration, ) -> Result<Vec<Event>, Error>
pub async fn send_mesh_frame_text( &self, frame: &MeshNostrFrame, ) -> Result<(), Error>
pub async fn send_message(&self, msg: &DataMessage) -> Result<(), Error>
pub async fn close(&self) -> Result<(), Error>
Trait Implementations§
Source§impl PeerLink for Peer
impl PeerLink for Peer
Source§fn send<'life0, 'async_trait>(
&'life0 self,
data: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Peer: 'async_trait,
fn send<'life0, 'async_trait>(
&'life0 self,
data: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Peer: 'async_trait,
Send data to the peer.
Source§fn recv<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Option<Vec<u8>>> + Send + 'async_trait>>where
'life0: 'async_trait,
Peer: 'async_trait,
fn recv<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Option<Vec<u8>>> + Send + 'async_trait>>where
'life0: 'async_trait,
Peer: 'async_trait,
Receive data from the peer.
Auto Trait Implementations§
impl Freeze for Peer
impl !RefUnwindSafe for Peer
impl Send for Peer
impl Sync for Peer
impl Unpin for Peer
impl UnsafeUnpin for Peer
impl !UnwindSafe for Peer
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more