pub struct MeshServices { /* private fields */ }Expand description
Mesh service registry and message handler.
Manages local service registration, discovery query generation and handling, and service request/response routing. All methods return actions (messages to send, events to emit) rather than performing I/O directly.
§Multi-hop discovery
Discovery queries are forwarded across multiple hops via gossip.
Discovery responses are sent to the direct sender of the query, never
to the originator the payload names, so that a spoofed originator cannot
make a provider leak its service list to an arbitrary peer. A node that
receives a response it did not originate forwards it as a unicast toward
the originator (see try_handle_discover_response) and emits no event of
its own; only the originator emits ServiceDiscovered.
Implementations§
Source§impl MeshServices
impl MeshServices
Sourcepub fn new() -> MeshServices
pub fn new() -> MeshServices
Creates a new empty service registry.
Sourcepub fn register_service(
&mut self,
descriptor: ServiceDescriptor,
) -> Result<(), ServiceError>
pub fn register_service( &mut self, descriptor: ServiceDescriptor, ) -> Result<(), ServiceError>
Registers a local service.
Sourcepub fn unregister_service(
&mut self,
service_id: &str,
) -> Result<bool, ServiceError>
pub fn unregister_service( &mut self, service_id: &str, ) -> Result<bool, ServiceError>
Unregisters a local service. Returns true if it was found and removed.
Sourcepub fn has_service(&self, service_id: &str) -> bool
pub fn has_service(&self, service_id: &str) -> bool
Returns true if a service with the given ID is registered locally.
Sourcepub fn discover_services(
&mut self,
user_id: &str,
known_peers: &[String],
service_id: Option<&str>,
) -> Result<DiscoverResult, ServiceError>
pub fn discover_services( &mut self, user_id: &str, known_peers: &[String], service_id: Option<&str>, ) -> Result<DiscoverResult, ServiceError>
Generates a discovery broadcast to known peers, capped at
DISCOVERY_INITIAL_BROADCAST_MAX recipients.
See the multi-hop discovery note on
MeshServices for where the responses go.
Sourcepub fn send_service_request(
&self,
provider: &str,
service_id: &str,
method: &str,
body: &str,
) -> Result<SendRequestResult, ServiceError>
pub fn send_service_request( &self, provider: &str, service_id: &str, method: &str, body: &str, ) -> Result<SendRequestResult, ServiceError>
Generates a service request message to a specific provider peer.
Sourcepub fn respond_to_service_request(
&self,
request_id: &str,
requester: &str,
service_id: &str,
status: &str,
body: &str,
) -> Result<SendResponseResult, ServiceError>
pub fn respond_to_service_request( &self, request_id: &str, requester: &str, service_id: &str, status: &str, body: &str, ) -> Result<SendResponseResult, ServiceError>
Generates a service response message.
Sourcepub fn handle_incoming_message(
&mut self,
content: &str,
sender: &str,
hop_count: u8,
user_id: &str,
known_peers: &[String],
) -> ServiceAction
pub fn handle_incoming_message( &mut self, content: &str, sender: &str, hop_count: u8, user_id: &str, known_peers: &[String], ) -> ServiceAction
Handles an incoming message, returning a ServiceAction.
hop_count is the hop count from the incoming message (used in discovery responses).
known_peers should exclude the sender.
Sourcepub fn cleanup_expired(&mut self)
pub fn cleanup_expired(&mut self)
Removes expired discovery query dedup entries.
Sourcepub fn seen_discovery_queries(&self) -> &HashMap<String, Instant>
pub fn seen_discovery_queries(&self) -> &HashMap<String, Instant>
Provides read access to seen_discovery_queries for testing / inspection.
Trait Implementations§
Source§impl Default for MeshServices
impl Default for MeshServices
Source§fn default() -> MeshServices
fn default() -> MeshServices
Auto Trait Implementations§
impl Freeze for MeshServices
impl RefUnwindSafe for MeshServices
impl Send for MeshServices
impl Sync for MeshServices
impl Unpin for MeshServices
impl UnsafeUnpin for MeshServices
impl UnwindSafe for MeshServices
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> Declassify for T
impl<T> Declassify for T
type Declassified = T
fn declassify(self) -> 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 moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);