Skip to main content

Crate dig_peer_protocol

Crate dig_peer_protocol 

Source
Expand description

§dig-peer-protocol

The DIG Network peer wire — a native protocol, plus the narrow chia surface a DIG node needs to also speak to chia full nodes.

§The native DIG wire

DigMessage is the envelope for every DIG message: a raw u8 opcode, an optional correlation id, and a Bytes payload, encoded by this crate and nothing else. It carries the 200..=222 DIG opcode band, which chia_protocol::Message structurally cannot express — its ProtocolMessageTypes is a closed #[repr(u8)] enum with no Unknown(u8), so a DIG opcode is neither constructible nor decodable through it, and one inbound DIG frame drops a whole chia-sdk-client connection rather than that one frame.

DIG answered that with vendored forks of chia-protocol and chia-sdk-client. This crate replaces the forks: DigLink is a websocket peer link written directly against the wire format, and the DIG types it carries — Bytes, NodeType, DigMessage, DigMessageType, RegisterPeer, RegisterAck — are DIG’s own.

§What is deliberately still chia, and why

Decoupling from chia-protocol is not the same as decoupling from every crate whose name starts with chia. Two are kept ON PURPOSE. Do not “finish the decoupling” by removing them — they were assessed and retained:

  • chia-traits (Streamable) and chia_streamable_macro (streamable) — a serialization trait and a derive macro. Neither has the property this crate is escaping: there is no closed enum and no private-field wire authority in either. They serialize the bodies of DIG messages, and they do it with an encoding that is already live on the network. Replacing them would mean owning a serializer — new surface, and a fresh byte-identity risk — to buy nothing that matters.
  • chia-protocol’s ChiaProtocolMessage and TimestampedPeerInfo, and chia-sdk-client — these serve genuine chia traffic. A DIG node talks to chia full nodes too: DigLink’s typed send/request derive a chia opcode from ChiaProtocolMessage, RespondPeersIntroducer is chia opcode 64, and OpcodeRateLimits re-keys chia’s own published rate-limit table so a chia opcode is limited exactly as a stock peer would limit it. Chia types for chia traffic is the design, not a leftover.

There is no blanket pub use chia_protocol::*. A glob re-export is how chia types reach consumers that never asked for them, and it made a chia version bump a breaking change to every downstream crate. What a chia-full-node path needs is named explicitly below.

§Feature flags

FlagForwards toEffect
native-tlschia-sdk-client/native-tlsOS-native TLS; enables Client, ClientState, Connector, create_native_tls_connector, DigLink::connect
rustlschia-sdk-client/rustlsPure-Rust TLS; enables Client, ClientState, Connector, create_rustls_connector, DigLink::connect

Neither is enabled by default. Without one, the TLS-dependent items above are unavailable; DigLink::from_websocket and DigLink::from_server_websocket stay available, since adopting an already-established socket needs no TLS backend of its own.

Structs§

Bytes
A length-prefixed byte payload.
ChiaCertificate
DigLink
A live websocket link to one peer, framing every message as a DigMessage.
DigMessage
The DIG peer envelope: a raw u8 opcode, an optional correlation id, and a payload.
LinkOptions
Tunables for a single link.
Network
OpcodeRateLimiter
A sliding-window outbound limiter over OpcodeRateLimits.
OpcodeRateLimits
Chia’s V2_RATE_LIMITS, re-keyed from ProtocolMessageTypes to the wire byte.
Peer
PeerOptions
RateLimit
RateLimiter
RateLimits
RegisterAck
Introducer acknowledgement. success == false is a valid wire outcome (policy rejection).
RegisterPeer
Registration request: advertise this node’s P2P reachability to the introducer.
RequestPeersIntroducer
Empty introducer “get peers” request (protocol opcode 63).
RespondPeersIntroducer
Introducer peer list response (protocol opcode 64).
TimestampedPeerInfo
UnknownDigMessageType
Error returned by TryFrom<u8> when the wire value is not a known DIG discriminant.
UnknownNodeType
A wire byte that names no NodeType.

Enums§

Admission
The verdict on one outbound message.
ClientError
DigMessageType
DIG L2 wire discriminants (200..=219) extending Chia’s protocol namespace.
LinkError
Everything that can go wrong on a DIG peer link.
NodeType
The service role a peer declares. One byte on the wire.
ProtocolMessageTypes

Constants§

ALL_DIG_OPCODES
Every opcode DIG has assigned, ascending — the 20 consensus opcodes plus the 3 free-band ones.
DIG_BAND_START
First opcode of the DIG band. Everything below this belongs to Chia.
DIG_MESSAGE
Wire opcode for a directed dig-message envelope (WU6, epic #796).
FREE_BAND_START
First opcode of the free half of the DIG band — application protocols, not L2 consensus.
HOLDINGS_ANNOUNCE
Wire opcode for a holdings-announce broadcast (#1428, spec #1394).
STORE_MELTED
Wire opcode for a store-melted broadcast (epic #1316).

Statics§

V2_RATE_LIMITS

Traits§

ChiaProtocolMessage
Streamable

Functions§

is_dig_opcode
Whether opcode belongs to the DIG band rather than Chia’s namespace.
load_ssl_cert
Loads an SSL certificate, or creates it if it doesn’t exist already.

Attribute Macros§

streamable