pub struct Mesh {
pub dup: Arc<RwLock<Dup>>,
pub near: Arc<RwLock<usize>>,
pub pid: String,
/* private fields */
}Expand description
DAM Mesh - handles message routing and peer communication
The mesh is the central coordinator for all peer-to-peer communication in Gun. It manages:
- Peer connections and routing
- Message signing and verification (BLS signatures)
- Message deduplication
- Message broadcasting and targeted delivery
- Peer public key management
Based on Gun.js mesh.js. The mesh is thread-safe and can be shared across
threads using Arc<Mesh>.
§Example
use gun::dam::Mesh;
use gun::core::GunCore;
use chia_bls::{SecretKey, PublicKey};
use std::sync::Arc;
let core = Arc::new(GunCore::new());
let secret_key = SecretKey::from_seed(&[0u8; 32]);
let public_key = secret_key.public_key();
let mesh = Arc::new(Mesh::new(core, secret_key, public_key, None));Fields§
§dup: Arc<RwLock<Dup>>§near: Arc<RwLock<usize>>§pid: StringImplementations§
Source§impl Mesh
impl Mesh
pub fn new( core: Arc<GunCore>, secret_key: SecretKey, public_key: PublicKey, message_predicate: Option<MessagePredicate>, ) -> Self
Sourcepub async fn hear(&self, raw: &str, peer: Option<&Peer>) -> GunResult<()>
pub async fn hear(&self, raw: &str, peer: Option<&Peer>) -> GunResult<()>
Handle incoming message (matches mesh.hear)
Sourcepub async fn say(&self, msg: &Value, peer: Option<&Peer>) -> GunResult<()>
pub async fn say(&self, msg: &Value, peer: Option<&Peer>) -> GunResult<()>
Send message to peer(s) (matches mesh.say)
Sourcepub async fn set_peer_sender(
&self,
peer_id: &str,
tx: UnboundedSender<String>,
) -> GunResult<()>
pub async fn set_peer_sender( &self, peer_id: &str, tx: UnboundedSender<String>, ) -> GunResult<()>
Update peer with WebSocket sender (called when connection is established)
Sourcepub async fn connected_peer_count(&self) -> usize
pub async fn connected_peer_count(&self) -> usize
Get the number of connected peers (peers with active WebSocket connections) Acquires read lock with timeout to avoid indefinite blocking
Sourcepub async fn has_connected_peers(&self) -> bool
pub async fn has_connected_peers(&self) -> bool
Check if any peers are connected
Sourcepub async fn wait_for_connection(&self, timeout_ms: u64) -> bool
pub async fn wait_for_connection(&self, timeout_ms: u64) -> bool
Wait for at least one peer to be connected, with timeout
Auto Trait Implementations§
impl Freeze for Mesh
impl !RefUnwindSafe for Mesh
impl Send for Mesh
impl Sync for Mesh
impl Unpin for Mesh
impl !UnwindSafe for Mesh
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> 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<'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
Mutably borrows from an owned value. Read more