pub struct BandwidthController<St> { /* private fields */ }Expand description
Owns all ecash credential state and is the single writer to the credential Storage.
It serves ticket spending, credential acquisition, and global signing-data retrieval while keeping storage consistent by being the only component that writes to it. The acquisition and retrieval work is delegated to two pluggable, storage-free fetchers: they only do the network/cryptographic work and hand the results back for the controller to persist.
CredentialPublicDataFetcher(public_data_fetcher): lazily retrieves the global ecash signing materials - master verification key, coin-index and expiration-date signatures - when they’re missing locally.CredentialFetcher(credential_fetcher): provisions usable ticketbooks (making deposits and aggregating wallet signatures). It is a superset of the public-data fetcher, so installing one viaSelf::with_credential_fetcheralso registers it as the public-data fetcher.
It can be driven two ways:
Self::run— the event loop: handles requests fromBandwidthControllerRequestSenderand, on native targets, proactively restocks low ticket types in the background, keeps the global data topped up, and resolveswait_for_ticketbooksreadiness waiters as fetches complete.- directly on a non-running instance — e.g.
Self::fetch_ticketbookorSelf::prepare_ecash_ticket— for one-shot use without spawning the loop.
Implementations§
Source§impl<St: Storage> BandwidthController<St>
impl<St: Storage> BandwidthController<St>
pub fn new(storage: St) -> Self
pub fn with_config(self, config: BandwidthControllerConfig) -> Self
pub fn with_credential_fetcher( self, fetcher: impl CredentialFetcher + 'static, ) -> Self
pub fn with_credential_public_data_fetcher( self, fetcher: impl CredentialPublicDataFetcher + 'static, ) -> Self
Sourcepub fn get_request_sender(&self) -> BandwidthControllerRequestSender
pub fn get_request_sender(&self) -> BandwidthControllerRequestSender
Get the request channel used to send request to the controller.
Request are handled only if the BandwidthController is running using run
Sourcepub async fn run(self, shutdown_token: ShutdownToken)
pub async fn run(self, shutdown_token: ShutdownToken)
Runs the controller event loop, handling incoming requests until the request channel is closed or cancellation is requested. Additionally drives the proactive restock timer and drains completed background fetches.
pub async fn prepare_ecash_ticket( &self, ticketbook_type: TicketType, provider_pk: [u8; 32], tickets_to_spend: u32, spend_time: OffsetDateTime, ) -> Result<Option<PreparedCredential>, BandwidthControllerError>
Sourcepub async fn get_next_usable_ticketbook(
&self,
ticketbook_type: TicketType,
tickets: u32,
) -> Result<Option<RetrievedTicketbook>, BandwidthControllerError>
pub async fn get_next_usable_ticketbook( &self, ticketbook_type: TicketType, tickets: u32, ) -> Result<Option<RetrievedTicketbook>, BandwidthControllerError>
Tries to retrieve one of the stored, unused credentials for the given type that hasn’t yet expired.
Sourcepub async fn fetch_ticketbook(
&self,
ticketbook_type: TicketType,
) -> Result<(), BandwidthControllerError>
pub async fn fetch_ticketbook( &self, ticketbook_type: TicketType, ) -> Result<(), BandwidthControllerError>
Fetches a ticketbook of ticketbook_type via the configured credential fetcher and persists
it (together with the global signing materials it needs). The fetch runs inline, so this
works on a controller that isn’t running its event loop - suitable for one-shot issuance.
Trait Implementations§
Source§impl<St: Storage> BandwidthTicketProvider for BandwidthController<St>
impl<St: Storage> BandwidthTicketProvider for BandwidthController<St>
fn get_ecash_ticket<'life0, 'async_trait>(
&'life0 self,
ticket_type: TicketType,
gateway_id: PublicKey,
tickets_to_spend: u32,
spend_time: OffsetDateTime,
) -> Pin<Box<dyn Future<Output = Result<Option<PreparedCredential>, BandwidthControllerError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_upgrade_mode_token<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, BandwidthControllerError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn attempt_revert_spending<'life0, 'async_trait>(
&'life0 self,
metadata: PreparedCredentialMetadata,
) -> Pin<Box<dyn Future<Output = Result<bool, BandwidthControllerError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn close<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Auto Trait Implementations§
impl<St> !RefUnwindSafe for BandwidthController<St>
impl<St> !UnwindSafe for BandwidthController<St>
impl<St> Freeze for BandwidthController<St>where
St: Freeze,
impl<St> Send for BandwidthController<St>where
St: Send,
impl<St> Sync for BandwidthController<St>where
St: Sync,
impl<St> Unpin for BandwidthController<St>where
St: Unpin,
impl<St> UnsafeUnpin for BandwidthController<St>where
St: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Declassify for T
impl<T> Declassify for T
type Declassified = T
fn declassify(self) -> T
Source§impl<T> Deprecatable for T
impl<T> Deprecatable for T
fn deprecate(self) -> Deprecated<Self>where
Self: Sized,
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 moreSource§impl<T> OptionalSet for T
impl<T> OptionalSet for T
Source§fn with_optional<F, T>(self, f: F, val: Option<T>) -> Self
fn with_optional<F, T>(self, f: F, val: Option<T>) -> Self
Some), the provided closure is applied.
Otherwise self is returned with no modifications.Source§fn with_validated_optional<F, T, V, E>(
self,
f: F,
value: Option<T>,
validate: V,
) -> Result<Self, E>
fn with_validated_optional<F, T, V, E>( self, f: F, value: Option<T>, validate: V, ) -> Result<Self, E>
Some) it is validated and then the provided closure is applied.
Otherwise self is returned with no modifications.Source§fn with_optional_env<F, T>(self, f: F, val: Option<T>, env_var: &str) -> Self
fn with_optional_env<F, T>(self, f: F, val: Option<T>, env_var: &str) -> Self
Some), the provided closure is applied.
Otherwise, if the environment was configured and the corresponding variable was set,
the value is parsed using the FromStr implementation and the closure is applied on that instead.
Finally, if none of those were available, self is returned with no modifications.Source§fn with_optional_custom_env<F, T, G>(
self,
f: F,
val: Option<T>,
env_var: &str,
parser: G,
) -> Self
fn with_optional_custom_env<F, T, G>( self, f: F, val: Option<T>, env_var: &str, parser: G, ) -> Self
Some), the provided closure is applied.
Otherwise, if the environment was configured and the corresponding variable was set,
the value is parsed using the provided parser and the closure is applied on that instead.
Finally, if none of those were available, self is returned with no modifications.