pub struct MessagingService { /* private fields */ }Expand description
High-level messaging service that coordinates all messaging components
Implementations§
Source§impl MessagingService
impl MessagingService
Sourcepub async fn new(
identity: FourWordAddress,
dht_client: DhtClient,
) -> Result<Self>
pub async fn new( identity: FourWordAddress, dht_client: DhtClient, ) -> Result<Self>
Create a new messaging service with default configuration
Uses OS-assigned port (port 0) by default to avoid port conflicts. This is the recommended way to create a MessagingService for most use cases.
§Example
let dht = DhtClient::new()?;
let address = FourWordAddress("test-user-one-alpha".to_string());
let service = MessagingService::new(address, dht).await?;
// Get actual bound port
let addrs = service.listen_addrs().await;
println!("Listening on: {:?}", addrs);Sourcepub async fn new_with_config(
identity: FourWordAddress,
dht_client: DhtClient,
config: NetworkConfig,
) -> Result<Self>
pub async fn new_with_config( identity: FourWordAddress, dht_client: DhtClient, config: NetworkConfig, ) -> Result<Self>
Create a new messaging service with custom network configuration
This allows fine-grained control over port binding, IP mode, and retry behavior.
§Arguments
identity- Four-word address for this nodedht_client- DHT client for distributed operationsconfig- Network configuration (port, IP mode, retry behavior)
§Example with OS-Assigned Port
let dht = DhtClient::new()?;
let address = FourWordAddress("test-user-one-alpha".to_string());
// Use default config (OS-assigned port)
let config = NetworkConfig::default();
let service = MessagingService::new_with_config(address, dht, config).await?;§Example with Explicit Port
let dht = DhtClient::new()?;
let address = FourWordAddress("test-user-two-alpha".to_string());
// Use explicit port
let config = NetworkConfig {
port: PortConfig::Explicit(12345),
ip_mode: IpMode::IPv4Only,
retry_behavior: RetryBehavior::FailFast,
};
let service = MessagingService::new_with_config(address, dht, config).await?;§Note
Currently, only PortConfig::OsAssigned and PortConfig::Explicit are fully supported.
Full configuration support (port ranges, dual-stack separate ports) requires ant-quic 0.10.0.
Sourcepub async fn enable_restart_management(
&self,
restart_manager: Arc<RestartManager>,
)
pub async fn enable_restart_management( &self, restart_manager: Arc<RestartManager>, )
Enable restart management for this service
This integrates the RestartManager to handle network rejections and identity regeneration.
Sourcepub async fn send_message(
&self,
recipients: Vec<FourWordAddress>,
content: MessageContent,
channel_id: ChannelId,
options: SendOptions,
) -> Result<(MessageId, DeliveryReceipt)>
pub async fn send_message( &self, recipients: Vec<FourWordAddress>, content: MessageContent, channel_id: ChannelId, options: SendOptions, ) -> Result<(MessageId, DeliveryReceipt)>
Send a message to recipients
Sourcepub async fn send_message_to_channel(
&self,
channel_id: ChannelId,
content: MessageContent,
options: SendOptions,
) -> Result<(MessageId, DeliveryReceipt)>
pub async fn send_message_to_channel( &self, channel_id: ChannelId, content: MessageContent, options: SendOptions, ) -> Result<(MessageId, DeliveryReceipt)>
Send a message to a channel
Sourcepub async fn subscribe_messages(
&self,
channel_filter: Option<ChannelId>,
) -> Receiver<ReceivedMessage>
pub async fn subscribe_messages( &self, channel_filter: Option<ChannelId>, ) -> Receiver<ReceivedMessage>
Subscribe to incoming messages
Sourcepub async fn get_message_status(
&self,
message_id: MessageId,
) -> Result<DeliveryStatus>
pub async fn get_message_status( &self, message_id: MessageId, ) -> Result<DeliveryStatus>
Get message delivery status
Sourcepub async fn get_message(&self, message_id: MessageId) -> Result<RichMessage>
pub async fn get_message(&self, message_id: MessageId) -> Result<RichMessage>
Retrieve a message by ID
Sourcepub async fn get_channel_messages(
&self,
channel_id: ChannelId,
limit: usize,
before: Option<DateTime<Utc>>,
) -> Result<Vec<RichMessage>>
pub async fn get_channel_messages( &self, channel_id: ChannelId, limit: usize, before: Option<DateTime<Utc>>, ) -> Result<Vec<RichMessage>>
Sourcepub async fn get_thread_messages(
&self,
thread_id: ThreadId,
) -> Result<Vec<RichMessage>>
pub async fn get_thread_messages( &self, thread_id: ThreadId, ) -> Result<Vec<RichMessage>>
Sourcepub async fn mark_user_online(&self, user: FourWordAddress) -> Result<()>
pub async fn mark_user_online(&self, user: FourWordAddress) -> Result<()>
Mark a user as online
Sourcepub async fn mark_delivered(
&self,
message_id: MessageId,
recipient: FourWordAddress,
) -> Result<()>
pub async fn mark_delivered( &self, message_id: MessageId, recipient: FourWordAddress, ) -> Result<()>
Mark message as delivered
Sourcepub async fn process_message_queue(&self) -> Result<()>
pub async fn process_message_queue(&self) -> Result<()>
Process queued messages
Sourcepub async fn encrypt_message(
&self,
recipient: FourWordAddress,
channel_id: ChannelId,
content: MessageContent,
) -> Result<EncryptedMessage>
pub async fn encrypt_message( &self, recipient: FourWordAddress, channel_id: ChannelId, content: MessageContent, ) -> Result<EncryptedMessage>
Encrypt a message for a recipient
Sourcepub async fn decrypt_message(
&self,
encrypted: EncryptedMessage,
) -> Result<RichMessage>
pub async fn decrypt_message( &self, encrypted: EncryptedMessage, ) -> Result<RichMessage>
Decrypt a message
Sourcepub async fn listen_addrs(&self) -> Vec<SocketAddr>
pub async fn listen_addrs(&self) -> Vec<SocketAddr>
Get the local network address(es) this node is listening on
Sourcepub async fn connected_peers(&self) -> Vec<String>
pub async fn connected_peers(&self) -> Vec<String>
Get the list of currently connected peer IDs
Sourcepub async fn peer_count(&self) -> usize
pub async fn peer_count(&self) -> usize
Get the count of currently connected peers
Sourcepub async fn is_running(&self) -> bool
pub async fn is_running(&self) -> bool
Check if the P2P node is running
Sourcepub async fn connect_peer(&self, address: &str) -> Result<String>
pub async fn connect_peer(&self, address: &str) -> Result<String>
Auto Trait Implementations§
impl Freeze for MessagingService
impl !RefUnwindSafe for MessagingService
impl Send for MessagingService
impl Sync for MessagingService
impl Unpin for MessagingService
impl !UnwindSafe for MessagingService
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> 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> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.