pub struct Peer<S: Store> {
pub remote_id: PeerId,
/* private fields */
}Expand description
WebRTC peer connection wrapper
Each Peer is an independent agent that tracks:
pending_requests: requests WE sent TO this peer (awaiting response)their_requests: requests THEY sent TO US that we couldn’t fulfill
This matches the hashtree-ts Peer architecture. Wire protocol is binary MessagePack compatible with hashtree-ts.
Fields§
§remote_id: PeerIdRemote peer identifier
Implementations§
Source§impl<S: Store + 'static> Peer<S>
impl<S: Store + 'static> Peer<S>
Sourcepub async fn new(
remote_id: PeerId,
local_peer_id: String,
signaling_tx: Sender<SignalingMessage>,
local_store: Arc<S>,
debug: bool,
) -> Result<Self, PeerError>
pub async fn new( remote_id: PeerId, local_peer_id: String, signaling_tx: Sender<SignalingMessage>, local_store: Arc<S>, debug: bool, ) -> Result<Self, PeerError>
Create a new peer connection
Sourcepub async fn with_forward_channel(
remote_id: PeerId,
local_peer_id: String,
signaling_tx: Sender<SignalingMessage>,
local_store: Arc<S>,
debug: bool,
forward_tx: Option<ForwardTx>,
) -> Result<Self, PeerError>
pub async fn with_forward_channel( remote_id: PeerId, local_peer_id: String, signaling_tx: Sender<SignalingMessage>, local_store: Arc<S>, debug: bool, forward_tx: Option<ForwardTx>, ) -> Result<Self, PeerError>
Create a new peer connection with a forwarding channel
Sourcepub async fn handle_signaling(
&self,
msg: SignalingMessage,
) -> Result<(), PeerError>
pub async fn handle_signaling( &self, msg: SignalingMessage, ) -> Result<(), PeerError>
Handle incoming signaling message
Sourcepub async fn request(&self, hash: &Hash) -> Result<Option<Vec<u8>>, PeerError>
pub async fn request(&self, hash: &Hash) -> Result<Option<Vec<u8>>, PeerError>
Request data by hash with default HTL
Sourcepub async fn request_with_htl(
&self,
hash: &Hash,
htl: u8,
) -> Result<Option<Vec<u8>>, PeerError>
pub async fn request_with_htl( &self, hash: &Hash, htl: u8, ) -> Result<Option<Vec<u8>>, PeerError>
Request data by hash with specified HTL Uses binary MessagePack protocol compatible with hashtree-ts
Sourcepub async fn send_response_for_hash(
&self,
hash: &Hash,
data: Option<&[u8]>,
) -> Result<(), PeerError>
pub async fn send_response_for_hash( &self, hash: &Hash, data: Option<&[u8]>, ) -> Result<(), PeerError>
Send data response using binary MessagePack protocol Note: For found data, use the internal fragmentation-aware send_response This method is kept for API compatibility but now uses binary protocol
Sourcepub fn set_on_forward_request<F>(&mut self, callback: F)
pub fn set_on_forward_request<F>(&mut self, callback: F)
Set the forward request callback Called when this peer requests data we don’t have locally Parameters: (hash, exclude_peer_id, htl)
Sourcepub fn htl_config(&self) -> PeerHTLConfig
pub fn htl_config(&self) -> PeerHTLConfig
Get the peer’s HTL config (for testing)
Sourcepub async fn send_data(
&self,
hash_hex: &str,
data: &[u8],
) -> Result<bool, PeerError>
pub async fn send_data( &self, hash_hex: &str, data: &[u8], ) -> Result<bool, PeerError>
Send data to this peer for a hash they previously requested Returns true if this peer had requested this hash
Sourcepub async fn has_requested(&self, hash_hex: &str) -> bool
pub async fn has_requested(&self, hash_hex: &str) -> bool
Check if this peer has requested a hash
Sourcepub async fn their_request_count(&self) -> usize
pub async fn their_request_count(&self) -> usize
Get count of pending requests from this peer
Sourcepub async fn our_request_count(&self) -> usize
pub async fn our_request_count(&self) -> usize
Get count of pending requests we sent to this peer
Auto Trait Implementations§
impl<S> Freeze for Peer<S>
impl<S> !RefUnwindSafe for Peer<S>
impl<S> Send for Peer<S>
impl<S> Sync for Peer<S>
impl<S> Unpin for Peer<S>
impl<S> UnsafeUnpin for Peer<S>
impl<S> !UnwindSafe for Peer<S>
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