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>>>>Data channel - can be set from callback when receiving channel from peer
pending_requests: Arc<Mutex<HashMap<String, PendingRequest>>>Implementations§
Source§impl Peer
impl Peer
Sourcepub async fn new(
peer_id: PeerId,
direction: PeerDirection,
my_peer_id: PeerId,
signaling_tx: Sender<SignalingMessage>,
stun_servers: Vec<String>,
) -> Result<Self>
pub async fn new( peer_id: PeerId, direction: PeerDirection, my_peer_id: PeerId, signaling_tx: Sender<SignalingMessage>, stun_servers: Vec<String>, ) -> Result<Self>
Create a new peer connection
Sourcepub 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<Self>
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<Self>
Create a new peer connection with content store
Sourcepub fn set_store(&mut self, store: Arc<dyn ContentStore>)
pub fn set_store(&mut self, store: Arc<dyn ContentStore>)
Set content store
Sourcepub fn state(&self) -> RTCPeerConnectionState
pub fn state(&self) -> RTCPeerConnectionState
Get connection state
Sourcepub fn signaling_state(&self) -> RTCSignalingState
pub fn signaling_state(&self) -> RTCSignalingState
Get signaling state
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if connected
pub fn htl_config(&self) -> &PeerHTLConfig
Sourcepub async fn setup_handlers(&self) -> Result<()>
pub async fn setup_handlers(&self) -> Result<()>
Setup event handlers for the peer connection
Sourcepub async fn connect(&self) -> Result<Value>
pub async fn connect(&self) -> Result<Value>
Initiate connection (create offer) - for outbound connections
Sourcepub async fn handle_offer(&self, offer: Value) -> Result<Value>
pub async fn handle_offer(&self, offer: Value) -> Result<Value>
Handle incoming offer and create answer
Sourcepub async fn handle_answer(&self, answer: Value) -> Result<()>
pub async fn handle_answer(&self, answer: Value) -> Result<()>
Handle incoming answer
Sourcepub async fn handle_candidate(&self, candidate: Value) -> Result<()>
pub async fn handle_candidate(&self, candidate: Value) -> Result<()>
Handle incoming ICE candidate
Sourcepub fn has_data_channel(&self) -> bool
pub fn has_data_channel(&self) -> bool
Check if data channel is ready
Sourcepub async fn request(&self, hash_hex: &str) -> Result<Option<Vec<u8>>>
pub async fn request(&self, hash_hex: &str) -> Result<Option<Vec<u8>>>
Request content by hash from this peer
Sourcepub async fn request_with_timeout(
&self,
hash_hex: &str,
timeout: Duration,
) -> Result<Option<Vec<u8>>>
pub async fn request_with_timeout( &self, hash_hex: &str, timeout: Duration, ) -> Result<Option<Vec<u8>>>
Request content by hash from this peer with an explicit timeout.
Sourcepub async fn query_nostr_events(
&self,
filters: Vec<NostrFilter>,
timeout: Duration,
) -> Result<Vec<Event>>
pub async fn query_nostr_events( &self, filters: Vec<NostrFilter>, timeout: Duration, ) -> Result<Vec<Event>>
Query a peer’s embedded Nostr relay over the WebRTC data channel. Returns all events received before EOSE/timeout.
Sourcepub async fn send_mesh_frame_text(&self, frame: &MeshNostrFrame) -> Result<()>
pub async fn send_mesh_frame_text(&self, frame: &MeshNostrFrame) -> Result<()>
Send a mesh signaling frame as text over the data channel.
Sourcepub async fn send_message(&self, msg: &DataMessage) -> Result<()>
pub async fn send_message(&self, msg: &DataMessage) -> Result<()>
Send a message over the data channel
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<(), RoutedTransportError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn send<'life0, 'async_trait>(
&'life0 self,
data: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<(), RoutedTransportError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn recv<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Option<Vec<u8>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn recv<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Option<Vec<u8>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
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
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>
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>
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