Pallas Network 2
A new take on the Ouroboros networking stack that prioritises P2P
operation over the client / server shape used by pallas-network. The
public API is split between an Interface (where IO happens) and a
Behavior (the business logic), reconciled by a Manager — a layout
inspired by libp2p's swarm.
Once this crate is thoroughly tested and adopted by downstream clients,
network2 is intended to replace the original pallas-network.
Usage
A typical setup pairs a transport (an Interface impl, e.g. the
TCP-backed TcpInterface) with a protocol (a Behavior impl, e.g. the
node-to-node InitiatorBehavior) and drives both through a Manager.
The Manager polls the interface for IO events, hands them to the
behavior, and pushes any commands the behavior emits back at the
interface — leaving you to consume the behavior's external events. The
example below is illustrative (error handling and the await runtime
are elided):
use ;
let interface = new;
let behavior = default;
let mut manager = new;
manager.execute;
while let Some = manager.poll_next.await
Overview
Manager— drives a pairedInterface+Behavior.poll_nextadvances IO and the behavior;executeforwards an external command to the behavior.Interfacetrait — the IO side. ReceivesInterfaceCommand(Connect / Send / Disconnect) and yieldsInterfaceEvent(Connected / Disconnected / Sent / Recv / Error / Idle).Behaviortrait — the protocol logic. Defines its ownEvent,Command,PeerState, andMessage, and emitsBehaviorOutputs.Messagetrait — describes a mini-protocol message (channel id + payload encoding).OutboundQueue— convenience queue of pendingBehaviorOutputs ready to be polled by the manager.PeerId,Channel,Payload,MAX_SEGMENT_PAYLOAD_LENGTH— the primitive vocabulary.
Modules
bearer— low-level transport for reading and writing multiplexed segments.interface—Interfaceimplementations for TCP connections.behavior— opinionatedBehaviorimplementations for Cardano stacks.protocol— the Ouroboros mini-protocol definitions (handshake, chainsync, blockfetch, …).
Feature flags
emulation— enables theemulationmodule, an in-memory test harness for exercising behaviors without real network IO.