pub struct Peer<L: BucketLogProvider> { /* private fields */ }Expand description
Overview of a peer’s state, generic over a bucket log provider. Provides everything that a peer needs in order to load data, interact with peers, and manage buckets.
Implementations§
Source§impl<L: BucketLogProvider> Peer<L>
impl<L: BucketLogProvider> Peer<L>
pub fn logs(&self) -> &L
pub fn blobs(&self) -> &BlobsStore
pub fn endpoint(&self) -> &Endpoint
pub fn log_provider(&self) -> &L
pub fn secret(&self) -> &SecretKey
pub fn socket(&self) -> &SocketAddr
pub fn id(&self) -> NodeId
Sourcepub async fn dispatch(&self, job: SyncJob) -> Result<()>
pub async fn dispatch(&self, job: SyncJob) -> Result<()>
Dispatch a sync job to the sync provider
The provider decides when/where this executes (immediately, queued, etc.)
Sourcepub async fn ping(&self, bucket_id: Uuid) -> Result<()>
pub async fn ping(&self, bucket_id: Uuid) -> Result<()>
Ping all peers in a bucket’s shares
Dispatches ping jobs to all peers listed in the bucket’s current manifest shares (except ourselves).
Sourcepub async fn ping_and_collect(
&self,
bucket_id: Uuid,
timeout: Option<Duration>,
) -> Result<HashMap<String, PingReplyStatus>>
pub async fn ping_and_collect( &self, bucket_id: Uuid, timeout: Option<Duration>, ) -> Result<HashMap<String, PingReplyStatus>>
Ping all peers for a bucket and collect their responses
Returns a map of peer public key hex to their ping reply status. This waits for all pings to complete before returning.
§Arguments
bucket_id- The bucket to ping peers fortimeout- Optional timeout duration for the entire operation
Sourcepub async fn mount_for_read(&self, bucket_id: Uuid) -> Result<Mount, MountError>
pub async fn mount_for_read(&self, bucket_id: Uuid) -> Result<Mount, MountError>
Load mount for reading based on the peer’s role in the bucket.
This method determines the appropriate version to load based on the peer’s role:
- Owners see HEAD (latest state, including unpublished changes)
- Mirrors (or unknown roles) see the latest_published version
This ensures that mirrors only see content that has been explicitly published to them, while owners always see the most recent state.
§Arguments
bucket_id- The UUID of the bucket to load
§Returns
The Mount at the appropriate version for this peer’s role
§Errors
Returns error if:
- Bucket not found in log
- No published version available (for mirrors)
- Failed to load mount from blobs
Sourcepub async fn save_mount(
&self,
mount: &Mount,
publish: bool,
) -> Result<Link, MountError>
pub async fn save_mount( &self, mount: &Mount, publish: bool, ) -> Result<Link, MountError>
Save a mount and append it to the bucket’s log
This method:
- Saves the mount to blobs, getting a new link
- Appends the new link to the bucket’s log
- Dispatches sync jobs to notify peers
§Arguments
mount- The mount to savepublish- If true, publish the bucket (expose the secret so mirrors can decrypt)
§Returns
The new link where the mount was saved
§Errors
Returns error if:
- Failed to save mount to blobs
- Failed to append to log
Trait Implementations§
Source§impl<L> ProtocolHandler for Peer<L>
impl<L> ProtocolHandler for Peer<L>
Source§fn accept(
&self,
conn: Connection,
) -> BoxFuture<'static, Result<(), AcceptError>>
fn accept( &self, conn: Connection, ) -> BoxFuture<'static, Result<(), AcceptError>>
Source§fn on_connecting(
&self,
connecting: Connecting,
) -> impl Future<Output = Result<Connection, AcceptError>> + Send
fn on_connecting( &self, connecting: Connecting, ) -> impl Future<Output = Result<Connection, AcceptError>> + Send
Connecting state. Read moreAuto Trait Implementations§
impl<L> Freeze for Peer<L>where
L: Freeze,
impl<L> !RefUnwindSafe for Peer<L>
impl<L> Send for Peer<L>
impl<L> Sync for Peer<L>
impl<L> Unpin for Peer<L>where
L: Unpin,
impl<L> !UnwindSafe for Peer<L>
Blanket Implementations§
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<P> DynProtocolHandler for Pwhere
P: ProtocolHandler,
impl<P> DynProtocolHandler for Pwhere
P: ProtocolHandler,
Source§fn accept(
&self,
connection: Connection,
) -> Pin<Box<dyn Future<Output = Result<(), AcceptError>> + Send + '_>>
fn accept( &self, connection: Connection, ) -> Pin<Box<dyn Future<Output = Result<(), AcceptError>> + Send + '_>>
Source§fn on_connecting(
&self,
connecting: Connecting,
) -> Pin<Box<dyn Future<Output = Result<Connection, AcceptError>> + Send + '_>>
fn on_connecting( &self, connecting: Connecting, ) -> Pin<Box<dyn Future<Output = Result<Connection, AcceptError>> + Send + '_>>
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