Documentation
¶
Overview ¶
Package dagsync implements the iroh-dag-sync example protocol.
The wire protocol uses ALPN DAG_SYNC/1. A client writes one postcard Request to a bidirectional stream. The response is a sequence of 33-byte postcard SyncResponseHeader values, each optionally followed by a full-range BAO blob.
Index ¶
- Constants
- func ExtractLinks(c cid.Cid, data []byte) ([]cid.Cid, error)
- func ReadSyncResponse(ctx context.Context, r io.Reader, tables *Tables, out *blobs.BytesMap, ...) error
- func Sync(ctx context.Context, ep *iroh.Endpoint, addr netaddr.EndpointAddr, ...) error
- func WriteSyncResponse(ctx context.Context, w io.Writer, req SyncRequest, tables *Tables, m blobs.Map) error
- type Cid
- type FullTraversalOpts
- type Handler
- type InlineOpts
- type Request
- type SequenceTraversalOpts
- type SyncRequest
- type SyncResponseHeader
- type Tables
- func (t *Tables) BlobHash(c cid.Cid) (blobs.Hash, bool)
- func (t *Tables) CIDsForHash(hash blobs.Hash) []cid.Cid
- func (t *Tables) ImportBytes(ctx context.Context, m *blobs.BytesMap, c cid.Cid, data []byte) (blobs.Hash, error)
- func (t *Tables) Links(c cid.Cid) ([]cid.Cid, bool)
- func (t *Tables) Put(c cid.Cid, hash blobs.Hash, links []cid.Cid)
- type TraversalFilter
- type TraversalOpts
- type TraversalOrder
Constants ¶
const ALPN = "DAG_SYNC/1"
ALPN is the iroh-dag-sync protocol name.
Variables ¶
This section is empty.
Functions ¶
func ExtractLinks ¶
ExtractLinks returns IPLD links from data for c's codec.
func ReadSyncResponse ¶
func ReadSyncResponse(ctx context.Context, r io.Reader, tables *Tables, out *blobs.BytesMap, traversal TraversalOpts) error
ReadSyncResponse reads a sync response and records inline data.
Types ¶
type Cid ¶
Cid is a postcard byte-sequence wrapper around cid.Cid.
func (*Cid) DecodePostcard ¶
DecodePostcard decodes c from cid bytes.
func (Cid) EncodePostcard ¶
EncodePostcard encodes c as cid.to_bytes(), matching Rust.
func (Cid) MarshalPostcard ¶
MarshalPostcard implements postcard.Marshaler.
type FullTraversalOpts ¶
type FullTraversalOpts struct {
Root Cid
Visited []Cid
Order *TraversalOrder
Filter *TraversalFilter
}
FullTraversalOpts holds full DAG traversal options.
type Handler ¶
Handler serves dagsync requests.
func (*Handler) HandleStream ¶
HandleStream serves one bidirectional stream.
type InlineOpts ¶
InlineOpts selects which response items carry data.
func (*InlineOpts) DecodePostcard ¶
func (i *InlineOpts) DecodePostcard(d *postcard.Decoder) error
DecodePostcard decodes i from a Rust-compatible enum.
func (InlineOpts) EncodePostcard ¶
func (i InlineOpts) EncodePostcard(e *postcard.Encoder) error
EncodePostcard encodes i as a Rust-compatible enum.
type Request ¶
type Request struct {
Sync *SyncRequest
}
Request is a dagsync request.
func NewSyncRequest ¶
func NewSyncRequest(tr TraversalOpts, inline InlineOpts) Request
NewSyncRequest returns a sync request.
func (*Request) DecodePostcard ¶
DecodePostcard decodes r from a Rust-compatible enum.
func (Request) EncodePostcard ¶
EncodePostcard encodes r as a Rust-compatible enum.
func (Request) MarshalPostcard ¶
MarshalPostcard implements postcard.Marshaler.
type SequenceTraversalOpts ¶
type SequenceTraversalOpts struct {
Cids []Cid
}
SequenceTraversalOpts holds explicit CIDs.
type SyncRequest ¶
type SyncRequest struct {
Traversal TraversalOpts
Inline InlineOpts
}
SyncRequest asks for a traversal, optionally inlining block data.
type SyncResponseHeader ¶
SyncResponseHeader is one response item header.
func DataHeader ¶
func DataHeader(h blobs.Hash) SyncResponseHeader
DataHeader returns a data-carrying response header.
func HashHeader ¶
func HashHeader(h blobs.Hash) SyncResponseHeader
HashHeader returns a hash-only response header.
func (SyncResponseHeader) Bytes ¶
func (h SyncResponseHeader) Bytes() ([33]byte, error)
Bytes returns h encoded as the fixed 33-byte response header.
func (*SyncResponseHeader) DecodePostcard ¶
func (h *SyncResponseHeader) DecodePostcard(d *postcard.Decoder) error
DecodePostcard decodes h from a 33-byte Rust-compatible enum.
func (SyncResponseHeader) EncodePostcard ¶
func (h SyncResponseHeader) EncodePostcard(e *postcard.Encoder) error
EncodePostcard encodes h as a 33-byte Rust-compatible enum.
func (SyncResponseHeader) MarshalPostcard ¶
func (h SyncResponseHeader) MarshalPostcard() ([]byte, error)
MarshalPostcard implements postcard.Marshaler.
type Tables ¶
type Tables struct {
// contains filtered or unexported fields
}
Tables stores the CID-to-blob and CID-to-link metadata used by dagsync.
func (*Tables) CIDsForHash ¶
CIDsForHash returns CIDs recorded for hash.
func (*Tables) ImportBytes ¶
func (t *Tables) ImportBytes(ctx context.Context, m *blobs.BytesMap, c cid.Cid, data []byte) (blobs.Hash, error)
ImportBytes stores data in m and records metadata in t.
type TraversalFilter ¶
TraversalFilter filters CIDs during traversal.
func (*TraversalFilter) DecodePostcard ¶
func (f *TraversalFilter) DecodePostcard(d *postcard.Decoder) error
DecodePostcard decodes f from a Rust-compatible enum.
func (TraversalFilter) EncodePostcard ¶
func (f TraversalFilter) EncodePostcard(e *postcard.Encoder) error
EncodePostcard encodes f as a Rust-compatible enum.
type TraversalOpts ¶
type TraversalOpts struct {
Sequence *SequenceTraversalOpts
Full *FullTraversalOpts
}
TraversalOpts selects the traversal strategy.
func FullTraversal ¶
func FullTraversal(root cid.Cid) TraversalOpts
FullTraversal returns a depth-first traversal rooted at root.
func SequenceTraversal ¶
func SequenceTraversal(cids ...cid.Cid) TraversalOpts
SequenceTraversal returns a traversal over explicit CIDs.
func (*TraversalOpts) DecodePostcard ¶
func (t *TraversalOpts) DecodePostcard(d *postcard.Decoder) error
DecodePostcard decodes t from a Rust-compatible enum.
func (TraversalOpts) EncodePostcard ¶
func (t TraversalOpts) EncodePostcard(e *postcard.Encoder) error
EncodePostcard encodes t as a Rust-compatible enum.
type TraversalOrder ¶
type TraversalOrder struct {
DepthFirstPreOrderLeftToRight bool
}
TraversalOrder selects the traversal order.
func (*TraversalOrder) DecodePostcard ¶
func (o *TraversalOrder) DecodePostcard(d *postcard.Decoder) error
DecodePostcard decodes o from a Rust-compatible enum.
func (TraversalOrder) EncodePostcard ¶
func (o TraversalOrder) EncodePostcard(e *postcard.Encoder) error
EncodePostcard encodes o as a Rust-compatible enum.