Skip to main content

SnipSyncService

Struct SnipSyncService 

Source
pub struct SnipSyncService {
    pub db: Arc<Database>,
    pub rate_limiter: Arc<RateLimiter>,
    pub config: Config,
    pub metrics: Metrics,
    pub premade_manager: PremadeManager,
}

Fields§

§db: Arc<Database>§rate_limiter: Arc<RateLimiter>§config: Config§metrics: Metrics§premade_manager: PremadeManager

Implementations§

Source§

impl SnipSyncService

Source

pub fn record_request(&self, method: &str)

Source

pub fn record_request_finished(&self, method: &str, success: bool)

Source

pub fn update_request_ids( &self, method: &str, user_id: Option<String>, device_id: Option<String>, library_id: Option<String>, )

Update the last started request’s authenticated IDs.

Called after authentication resolves the user and device IDs. Only active with test-helpers feature.

Source

pub fn record_request_duration(&self, method: &str, start: Instant)

Source

pub fn record_rate_limit(&self)

Source

pub fn record_auth_failure(&self)

Source

pub fn record_db_error(&self)

Record a database failure (for example an upsert that failed inside a write transaction). Database failures are infrastructure errors, not content-level skips, so they are counted separately from the skipped_count a client sees.

Source

pub fn record_sync(&self, direction: &str)

Source

pub fn record_library_op(&self, operation: &str)

Source

pub async fn authenticate_and_rate_limit( &self, api_key: &str, rate_limit_key: &str, ) -> Result<String, Status>

Source

pub async fn authenticate_and_rate_limit_with_duration( &self, api_key: &str, rate_limit_key: &str, start: Option<Instant>, ) -> Result<String, Status>

Like authenticate_and_rate_limit, but records request duration on failure so the histogram captures latency for error responses.

rate_limit_key must come from Self::peer_rate_limit_key.

Source

pub fn validate_snippet(&self, snippet: &ProtoSnippet) -> Result<(), Status>

Trait Implementations§

Source§

impl SnippetSync for SnipSyncService

Source§

fn health<'life0, 'async_trait>( &'life0 self, _request: Request<HealthRequest>, ) -> Pin<Box<dyn Future<Output = Result<Response<HealthResponse>, Status>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Health check
Source§

fn register<'life0, 'async_trait>( &'life0 self, request: Request<RegisterRequest>, ) -> Pin<Box<dyn Future<Output = Result<Response<RegisterResponse>, Status>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Register a new device/user
Source§

fn get_snippets<'life0, 'async_trait>( &'life0 self, request: Request<GetSnippetsRequest>, ) -> Pin<Box<dyn Future<Output = Result<Response<SnippetList>, Status>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get non-deleted snippets from the selected library. Results are filtered to the records the server delivers at or after the cursor since (>=). The cursor is server-assigned and monotone: the server tracks it per row, so a record pushed with an older updated_at (a device whose clock is behind) is still delivered. The server uses >= deliberately: the cursor has second granularity, so a strict > would skip rows written in the same second as the previous cursor. Re-delivering boundary rows is safe — merges are idempotent by snippet identity.
Source§

fn push_snippets<'life0, 'async_trait>( &'life0 self, request: Request<PushSnippetsRequest>, ) -> Pin<Box<dyn Future<Output = Result<Response<PushSnippetsResponse>, Status>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Push local snippets to the selected library. Invalid snippets are rejected individually and reported in the response.
Source§

fn sync<'life0, 'async_trait>( &'life0 self, request: Request<SyncRequest>, ) -> Pin<Box<dyn Future<Output = Result<Response<SyncResponse>, Status>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Merge local snippets into the selected library and return changed server records, including deletion tombstones.
Source§

fn create_library<'life0, 'async_trait>( &'life0 self, request: Request<CreateLibraryRequest>, ) -> Pin<Box<dyn Future<Output = Result<Response<CreateLibraryResponse>, Status>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Library management. Library IDs are scoped to the authenticated account.
Source§

fn list_libraries<'life0, 'async_trait>( &'life0 self, request: Request<ListLibrariesRequest>, ) -> Pin<Box<dyn Future<Output = Result<Response<ListLibrariesResponse>, Status>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn delete_library<'life0, 'async_trait>( &'life0 self, request: Request<DeleteLibraryRequest>, ) -> Pin<Box<dyn Future<Output = Result<Response<DeleteLibraryResponse>, Status>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn list_premade_libraries<'life0, 'async_trait>( &'life0 self, request: Request<ListPremadeLibrariesRequest>, ) -> Pin<Box<dyn Future<Output = Result<Response<ListPremadeLibrariesResponse>, Status>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Premade libraries (server-to-client only).
Source§

fn get_premade_library<'life0, 'async_trait>( &'life0 self, request: Request<GetPremadeLibraryRequest>, ) -> Pin<Box<dyn Future<Output = Result<Response<GetPremadeLibraryResponse>, Status>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn search_premade_libraries<'life0, 'async_trait>( &'life0 self, request: Request<SearchPremadeLibrariesRequest>, ) -> Pin<Box<dyn Future<Output = Result<Response<SearchPremadeLibrariesResponse>, Status>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more