Skip to main content

blueprint_gossip_primitives/
lib.rs

1//! # Blueprint Gossip Primitives
2//!
3//! Reusable abstractions for building gossip-based protocols in the Blueprint SDK.
4//!
5//! This crate provides:
6//! - [`ProtocolNetwork`] trait for abstracting network operations
7//! - [`GossipManager`] for message deduplication and reliable delivery
8//! - [`MessageStore`] for efficient message storage with indexing
9//! - Mock implementations for testing without real network dependencies
10//!
11//! ## Design Principles
12//!
13//! 1. **Protocol Agnostic**: These primitives work with any message type
14//! 2. **Testable**: Mock implementations allow unit testing without mDNS/libp2p
15//! 3. **Event-Driven**: Async streams instead of polling for efficient message handling
16//! 4. **Memory Bounded**: LRU caches prevent unbounded memory growth
17//!
18//! ## Example
19//!
20//! ```rust,ignore
21//! use blueprint_gossip_primitives::{ProtocolNetwork, GossipManager, GossipConfig};
22//!
23//! // Create a gossip manager with deduplication
24//! let config = GossipConfig::default();
25//! let mut gossip = GossipManager::new(config);
26//!
27//! // Check if message should be processed (not a duplicate)
28//! if gossip.should_process(&message_hash) {
29//!     // Process and re-gossip
30//!     gossip.mark_seen(message_hash);
31//! }
32//! ```
33
34#![cfg_attr(not(feature = "std"), no_std)]
35
36extern crate alloc;
37
38pub mod dedup;
39pub mod error;
40pub mod network;
41pub mod store;
42
43#[cfg(any(test, feature = "testing"))]
44pub mod mock;
45
46// Re-exports
47pub use dedup::{DeduplicationCache, GossipConfig, GossipManager};
48pub use error::GossipError;
49pub use network::{MessageStream, NetworkEvent, ProtocolNetwork};
50pub use store::{MessageEntry, MessageStore};
51
52#[cfg(any(test, feature = "testing"))]
53pub use mock::{MockNetwork, MockNetworkConfig};