Skip to main content

weida/
lib.rs

1//! weida: a QUIC-native messaging framework.
2//!
3//! This crate hosts the runtime, the native QUIC transport, the raw stream core
4//! and the brokerless messaging patterns: Req/Rep, Push/Pull, Pub/Sub, PAIR,
5//! SURVEY and BUS — the whole nanomsg set, none of which adds wire
6//! vocabulary. A completion is a **cursor**: a level plus an absolute byte
7//! offset, reported on a unidirectional stream of its own
8//! ([`Cursors`], [`Reporter`]).
9//! `docs/ARCHITECTURE.md` describes the layer model,
10//! `docs/PROTOCOL.md` is the normative wire specification, and
11//! `docs/FAILURE_MODEL.md` defines what each outcome means.
12//!
13//! ```no_run
14//! use weida::{Runtime, RuntimeConfig, TransferMeta, Trust};
15//!
16//! # async fn example() -> weida::Result<()> {
17//! let runtime = Runtime::new(RuntimeConfig::default())?;
18//!
19//! // Trust belongs to the dialling endpoint, not to the runtime. Here the
20//! // address itself names the peer's public key, so nothing else is needed.
21//! let requester = runtime.requester(Trust::by_address());
22//! requester
23//!     .connect("weida://sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08@127.0.0.1:7443/transform")
24//!     .await?;
25//!
26//! // One bidirectional stream: the request half and the reply half. The
27//! // stream is the correlation, so nothing on the wire names the exchange.
28//! let (mut transfer, reply) = requester.open(TransferMeta::default()).await?;
29//! transfer.write_all(b"hello weida").await?;
30//! transfer.finish()?;
31//!
32//! let body = reply.recv().await?.collect(64 * 1024).await?;
33//! println!("{}", String::from_utf8_lossy(&body));
34//! # Ok(())
35//! # }
36//! ```
37//!
38//! The example above runs on the caller's ambient Tokio reactor. A caller
39//! that has none — or whose executor is not Tokio at all — uses
40//! [`Runtime::owned`] instead: the runtime then owns the reactor `quinn`
41//! needs, and every task, timer and name lookup weida performs runs there,
42//! while the futures it hands back may be driven by any executor. Transfer
43//! payloads implement both the `tokio::io` and the `futures-io` traits for
44//! the same reason.
45
46// The chunk framing both socket transports share: a named pipe has no
47// half-close and a unix socket has no abort, so the end of a payload is a
48// frame rather than a socket state.
49#[cfg(any(unix, windows))]
50mod chunked;
51mod config;
52mod conn;
53mod cursor;
54mod dedup;
55mod drain;
56mod endpoint;
57mod flow;
58#[cfg(any(unix, windows))]
59mod grouped;
60mod handoff;
61mod identity;
62mod inproc;
63mod listener;
64mod network;
65mod ordering;
66#[cfg(windows)]
67mod pipe;
68mod pool;
69mod pubsub;
70mod radio;
71mod reconnect;
72mod relay;
73mod report;
74mod runtime;
75mod segment;
76// A simulated UDP network under real QUIC, for tests (decisions/0042).
77#[cfg(feature = "test-util")]
78mod sim;
79mod stats;
80mod stream;
81mod tls;
82mod transfer;
83mod transport;
84#[cfg(unix)]
85mod unix;
86// SWARM: many sources, one verified blob (decisions/0040).
87#[cfg(feature = "swarm")]
88mod swarm;
89
90pub use config::{
91    Alpn, ClientTls, ClientTrust, Discovery, Identity, Pem, RuntimeConfig, ServerTls, Trust,
92};
93pub use cursor::{CursorSet, Cursors, Reporter};
94pub use drain::Drained;
95pub use endpoint::{
96    Bus, BusMember, Cast, Dish, Endpoint, Pair, Paired, Pattern, Pub, Publisher, Pull, Puller,
97    Push, Pusher, Radio, Rep, Replier, Req, Requester, Respond, Respondent, Sub, Subscriber,
98    Survey, SurveyRun, Surveyor, Tune,
99};
100#[cfg(feature = "swarm")]
101pub use endpoint::{Gather, Seed, Seeder, Swarm};
102pub use flow::{Flow, FlowInfo, FlowMeta, FlowStats, IncomingFlow};
103pub use handoff::Handoff;
104pub use identity::{
105    FilesOptions, IdentityEvent, IdentityEvents, IdentitySource, PeerChain, TrustSource,
106    WeakIdentitySource, WeakTrustSource,
107};
108#[cfg(windows)]
109pub use listener::PipeBinding;
110#[cfg(unix)]
111pub use listener::UnixBinding;
112pub use listener::{Binding, Listener, LocalBinding};
113pub use network::Network;
114pub use ordering::Gap;
115pub use pubsub::{DishDrops, FanOut, TopicDrops};
116pub use radio::{Join, JoinTerms, Received};
117pub use reconnect::{GiveUp, OutboxFull, PeerEvent, PeerEvents, ReconnectPolicy};
118pub use relay::{Relay, RelayBudget, RelayRequest};
119pub use runtime::Runtime;
120pub use segment::{MAX_SEGMENT_LAYERS, Segment, SegmentTerms};
121#[cfg(feature = "test-util")]
122pub use sim::{SimNet, SimStats};
123pub use stats::{ConnectionStats, PathStats, RemoteStats, TransportStats, UdpCounts};
124pub use stream::{Acceptor, Consumer, ConsumerId, CreditGrant, Incoming, Peer};
125#[cfg(feature = "swarm")]
126pub use swarm::{
127    Ask, Bits, Blob, BlobId, Fetch, FetchOptions, MAX_PENDING_SESSIONS, MAX_PIECES, MIN_RATE,
128    ParseBlobIdError, Piece, PieceList, PieceSize, SEED_STALL, SeedSession, TreeHasher,
129};
130pub use transfer::{
131    ConnectionId, Delivery, IncomingMeta, IncomingRequest, IncomingTransfer, OutgoingTransfer,
132    ReplyStream, TransferMeta, new_trace,
133};
134pub use weida_core::{
135    Address, Congestion, DEFAULT_DATAGRAM_RECEIVE_BYTES, DEFAULT_PORT, EndpointAddr, Error,
136    ErrorCode, Fingerprint, InprocAddr, Limits, LocalPrincipal, LossCause, PeerIdentity, PipeAddr,
137    RELAY_PATH, RelayAddr, Result, SCHEME_RELAY, StopReason, TraceContext, UnixAddr,
138    WindowsPrincipal,
139};
140pub use weida_protocol::{ALPN, RAFT_ALPN, VERSION, codes, filter};
141pub use weida_runtime::{Resolved, Resolver, SharedResolver, SystemResolver};
142// `Delivery` keeps its transfer-receipt meaning at this level, so the
143// dimension of the same name is re-exported under the name the guarantee
144// documents use for it.
145pub use weida_protocol::header::{
146    Acknowledgement, Backpressure, CursorLevel, Deduplication, Delivery as DeliveryLevel,
147    Durability, GuaranteeSet, OrderingMode, ProducerNaming, ReportMode,
148};