Skip to main content

decdn_protocol/
lib.rs

1//! Wire protocol types, ALPN identifiers, and message definitions for deCDN.
2//!
3//! This is the leaf crate in the dependency graph โ€” it has minimal dependencies
4//! and defines the shared vocabulary used by all other deCDN crates.
5
6pub mod client;
7pub mod coverage;
8pub mod dht;
9pub mod framing;
10pub mod identity;
11pub mod message;
12pub mod region;
13
14pub use client::{
15    BINDING_SIG_LEN, CHUNK_BYTES, ChunkData, ChunkPreimage, ClientBinding, ClientMessage,
16    MAX_CHAIN_LENGTH, MB_BYTES, StreamError, StreamRequest, StreamRequestExt, StreamResponse,
17    StreamResponseBody, StreamResponseExt, VOUCHER_SIG_LEN, Voucher, VoucherRejectReason,
18    encode_chunk_frame, encode_stream_request, encode_stream_response, parse_stream_request_ext,
19    parse_stream_response_ext,
20};
21pub use coverage::{Coverage, DISCOVERY_BLOCK_BYTES, discovery_block_bytes, num_blocks};
22#[cfg(feature = "test-support")]
23pub use coverage::{TestBlockSizeGuard, override_discovery_block_bytes_for_test};
24pub use dht::{
25    BatchStoreAck, BatchStoreRequest, CloserNodes, CloserNodesError, DhtMessage, FindNodeRequest,
26    FindNodeResponse, FindValueRequest, FindValueResponse, FindValueResponseExt,
27    MAX_BATCH_STORE_HASHES, MAX_CLOSER_NODES, MAX_PROVIDERS_PER_HASH, StoreAck, StoreRequest,
28    StoreRequestExt, encode_find_value_response, encode_store_request,
29    parse_find_value_response_ext, parse_store_request_ext,
30};
31pub use framing::{
32    FrameError, MAX_MESSAGE_SIZE, TopLevelEnum, decode_message, encode_message, is_unknown_variant,
33    read_frame, write_frame,
34};
35pub use identity::{ContentHash, ID_LEN, NodeId};
36pub use message::{
37    MAX_RATE_PER_MB, MessageValidationError, ProbeMessage, ProbeRequest, ProbeResponse,
38    ProbeResponseBody, ProbeResponseExt, SLASH_SIG_LEN, encode_probe_response,
39    parse_probe_response_ext,
40};
41pub use region::{InvalidRegion, Region, is_valid_region};
42
43/// ALPN protocol identifier for latency and availability probing.
44pub const ALPN_PROBE: &[u8] = b"cdn/probe/v1";
45
46/// ALPN protocol identifier for paid blob delivery (client-to-node and node-to-node).
47pub const ALPN_CLIENT: &[u8] = b"cdn/client/v1";
48
49/// ALPN protocol identifier for Kademlia-based content discovery (ADR 022).
50pub const ALPN_DHT: &[u8] = b"cdn/dht/v1";
51
52/// Connection rejected by the per-source or global rate limiter (ADR 013 ยง0x10).
53///
54/// Unlike `0x01`โ€“`0x03`, this code is delivered via `CONNECTION_CLOSE` rather
55/// than `RESET_STREAM` because the rejection happens before any application
56/// stream is opened. The close-frame reason bytes carry a short layer label
57/// (e.g. `global-full`, `per-source`) so the peer can pick an appropriate
58/// backoff. Peers that receive this code SHOULD back off before
59/// reconnecting; they MUST NOT treat it as a protocol error (the server is
60/// functioning normally โ€” the client is overloading it). The requester side
61/// (`decdn-client`) types this code as `UpstreamRateLimited` so the pull
62/// orchestrator suppresses the peer briefly instead of scoring it unreachable.
63pub const APP_ERR_RATE_LIMITED: u32 = 0x10;