network

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

README

Network Primitives

Utilities for coordinating multi-party protocols: session identifiers, message routing, and simple exchange patterns. The package is transport-agnostic; callers provide a Delivery implementation.

Overview

  • Session IDs: SID hashes arbitrary inputs to a 32-byte identifier for protocol scoping.
  • Routing: Router wraps a Delivery to add correlation IDs, buffering, and quorum awareness.
  • Round helpers: aliases for RoundMessages, OutgoingUnicasts, and Quorum simplify MPC code.
  • Message exchange: ExchangeUnicastSimple sends per-recipient payloads and waits for responses with matching correlation IDs.
  • Subpackages: exchange combines broadcast + unicast flows; echo implements a three-round echo broadcast; testutils provides in-memory transports and helpers.

Key Types

  • Delivery: user-supplied transport with Send/Receive, PartyId, and Quorum.
  • Router: correlation-aware shim over a Delivery; buffers unrelated messages for later retrieval.
  • Runner: interface for protocol executors (Run(rt *Router)).
  • SID: 32-byte session identifier derived via SHA3-256 over user-provided blobs.

Typical Flow

  1. Implement Delivery (or use testutils.MockCoordinator) for your environment.
  2. Create a Router with NewRouter(delivery).
  3. Exchange messages with SendTo/ReceiveFrom or use helpers like ExchangeUnicastSimple.
  4. Compose more complex protocols via runners that accept a *Router.

Notes

  • Messages are CBOR-encoded inside the helpers; callers pass strongly typed payloads.
  • Correlation IDs distinguish concurrent exchanges on the same transport.
  • Deprecated identity/PKI helpers remain for backward compatibility and will be removed.

Documentation

Overview

Package network provides utilities for coordinating multi-party protocols: session identifiers, message routing, and simple exchange patterns. The package is transport-agnostic; callers provide a Delivery implementation.

See README.md for details.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidArgument = errs.New("invalid argument")
	ErrFailed          = errs.New("failed")
)

Functions

This section is empty.

Types

type Delivery

type Delivery interface {
	PartyID() sharing.ID
	Quorum() []sharing.ID
	Send(to sharing.ID, message []byte) error
	Receive() (from sharing.ID, message []byte, err error)
}

Delivery abstracts a transport layer used by the router.

type Message

type Message any

Message represents any network payload.

type OutgoingUnicasts

type OutgoingUnicasts[M Message] = ds.Map[sharing.ID, M]

OutgoingUnicasts maps recipients to outbound unicast payloads.

type Quorum

type Quorum = ds.Set[sharing.ID]

Quorum is the set of parties participating in a session.

type Round

type Round = uint64

Round is the sequential identifier of a protocol step.

type RoundMessages

type RoundMessages[M Message] = ds.Map[sharing.ID, M]

RoundMessages maps sender IDs to their round messages.

func ExchangeUnicastSimple

func ExchangeUnicastSimple[U any](rt *Router, correlationID string, messages RoundMessages[U]) (RoundMessages[U], error)

ExchangeUnicastSimple sends messages to all participants and receives the same messages back from them.

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router orchestrates correlation-aware sending and receiving over a Delivery.

func NewRouter

func NewRouter(delivery Delivery) *Router

NewRouter wraps a Delivery with buffering and correlation-aware routing.

func (*Router) PartyID

func (r *Router) PartyID() sharing.ID

PartyID returns the router's local party identifier.

func (*Router) Quorum

func (r *Router) Quorum() []sharing.ID

Quorum returns the identifiers of all parties in the session.

func (*Router) ReceiveFrom

func (r *Router) ReceiveFrom(correlationID string, froms ...sharing.ID) (map[sharing.ID][]byte, error)

ReceiveFrom collects messages matching the correlation identifier from the specified senders, buffering unrelated messages for later retrieval.

func (*Router) SendTo

func (r *Router) SendTo(correlationID string, messages map[sharing.ID][]byte) error

SendTo serialises and sends messages to the given recipients under a correlation identifier.

type Runner

type Runner[O any] interface {
	Run(rt *Router) (O, error)
}

Runner executes a networked protocol using a Router and returns its output.

type SID

type SID [32]byte

SID is a 32-byte session identifier derived from hashed inputs.

func NewSID

func NewSID(xs ...[]byte) (SID, error)

NewSID hashes the provided byte slices to produce a 32-byte session identifier.

Directories

Path Synopsis
Package echo provides three-round echo broadcast primitive that ensures all honest parties deliver the same payload.
Package echo provides three-round echo broadcast primitive that ensures all honest parties deliver the same payload.
Package exchange provides convenience functions that orchestrate broadcast and unicast communication patterns over a network.Router using correlation IDs and CBOR encoding.
Package exchange provides convenience functions that orchestrate broadcast and unicast communication patterns over a network.Router using correlation IDs and CBOR encoding.
Package ntu provides helpers for exercising network protocols in-memory without real transports.
Package ntu provides helpers for exercising network protocols in-memory without real transports.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL