bcnet

package
v0.0.0-...-575026b Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

bcnet implements the Blobcache Protocol (BCP).

Index

Constants

View Source
const (
	MT_OK = 128 + iota

	MT_ERROR_TIMEOUT
	MT_ERROR_INVALID_HANDLE
	MT_ERROR_NOT_FOUND
	MT_ERROR_NO_PERMISSION
	MT_ERROR_NO_LINK

	MT_ERROR_UNKNOWN = 255
)

Response messages

View Source
const HeaderLen = 1 + 4

Variables

This section is empty.

Functions

func AddFrom

func AddFrom(ctx context.Context, tp Transport, ep blobcache.Endpoint, tx blobcache.Handle, cids []blobcache.CID, srcTxns []blobcache.Handle, success []bool) error
func AllowLink(ctx context.Context, tp Transport, ep blobcache.Endpoint, tx blobcache.Handle, subvol blobcache.Handle) error

func CloneVolume

func CloneVolume(ctx context.Context, tp Transport, ep blobcache.Endpoint, caller *blobcache.PeerID, volh blobcache.Handle) (*blobcache.Handle, error)

func Commit

func Commit(ctx context.Context, tp Transport, ep blobcache.Endpoint, tx blobcache.Handle, root *[]byte) error

func Delete

func Delete(ctx context.Context, tp Transport, ep blobcache.Endpoint, tx blobcache.Handle, cids []blobcache.CID) error

func Exists

func Exists(ctx context.Context, tp Transport, ep blobcache.Endpoint, tx blobcache.Handle, cids []blobcache.CID, dst []bool) error

func Get

func IsVisited

func IsVisited(ctx context.Context, tp Transport, ep blobcache.Endpoint, tx blobcache.Handle, cids []blobcache.CID, dst []bool) error

func KeepAlive

func KeepAlive(ctx context.Context, tp Transport, ep blobcache.Endpoint, hs []blobcache.Handle) error

func Load

func Load(ctx context.Context, tp Transport, ep blobcache.Endpoint, tx blobcache.Handle, dst *[]byte) error

func ParseWireError

func ParseWireError(code MessageType, x []byte) error

func Post

func Post(ctx context.Context, tp Transport, ep blobcache.Endpoint, txh blobcache.Handle, salt *blobcache.CID, data []byte) (blobcache.CID, error)

func Save

func Save(ctx context.Context, tp Transport, ep blobcache.Endpoint, tx blobcache.Handle, src []byte) error

func Visit

Types

type AbortReq

type AbortReq struct {
	Tx blobcache.Handle
}

func (AbortReq) Marshal

func (ar AbortReq) Marshal(out []byte) []byte

func (*AbortReq) Unmarshal

func (ar *AbortReq) Unmarshal(data []byte) error

type AbortResp

type AbortResp struct{}

func (AbortResp) Marshal

func (ar AbortResp) Marshal(out []byte) []byte

func (*AbortResp) Unmarshal

func (ar *AbortResp) Unmarshal(data []byte) error

type AccessFunc

type AccessFunc func(blobcache.PeerID) blobcache.Service

AccessFun is called to get a service to access

type AddFromReq

type AddFromReq struct {
	Tx   blobcache.Handle
	CIDs []blobcache.CID
	Srcs []blobcache.Handle
}

func (AddFromReq) Marshal

func (ar AddFromReq) Marshal(out []byte) []byte

func (*AddFromReq) Unmarshal

func (ar *AddFromReq) Unmarshal(data []byte) error

type AddFromResp

type AddFromResp struct {
	Added []bool
}

func (AddFromResp) Marshal

func (ar AddFromResp) Marshal(out []byte) []byte

func (*AddFromResp) Unmarshal

func (ar *AddFromResp) Unmarshal(data []byte) error

type AllowLinkReq

type AllowLinkReq struct {
	Tx     blobcache.Handle
	Subvol blobcache.Handle
}

func (AllowLinkReq) Marshal

func (ar AllowLinkReq) Marshal(out []byte) []byte

func (*AllowLinkReq) Unmarshal

func (ar *AllowLinkReq) Unmarshal(data []byte) error

type AllowLinkResp

type AllowLinkResp struct{}

func (AllowLinkResp) Marshal

func (ar AllowLinkResp) Marshal(out []byte) []byte

func (*AllowLinkResp) Unmarshal

func (ar *AllowLinkResp) Unmarshal(data []byte) error

type AwaitReq

type AwaitReq struct {
	Cond blobcache.Conditions
}

func (AwaitReq) Marshal

func (ar AwaitReq) Marshal(out []byte) []byte

func (*AwaitReq) Unmarshal

func (ar *AwaitReq) Unmarshal(data []byte) error

type AwaitResp

type AwaitResp struct{}

func (AwaitResp) Marshal

func (ar AwaitResp) Marshal(out []byte) []byte

func (*AwaitResp) Unmarshal

func (ar *AwaitResp) Unmarshal(data []byte) error

type BeginTxReq

type BeginTxReq struct {
	Volume blobcache.Handle
	Params blobcache.TxParams
}

func (BeginTxReq) Marshal

func (btx BeginTxReq) Marshal(out []byte) []byte

func (*BeginTxReq) Unmarshal

func (btx *BeginTxReq) Unmarshal(data []byte) error

type BeginTxResp

type BeginTxResp struct {
	// Tx is the handle for the transaction.
	Tx blobcache.Handle
	// VolumeInfo is the volume info for the transaction.
	VolumeInfo blobcache.VolumeInfo
}

func (BeginTxResp) Marshal

func (btx BeginTxResp) Marshal(out []byte) []byte

func (*BeginTxResp) Unmarshal

func (btx *BeginTxResp) Unmarshal(data []byte) error

type CloneVolumeReq

type CloneVolumeReq struct {
	Volume blobcache.Handle
}

func (CloneVolumeReq) Marshal

func (cr CloneVolumeReq) Marshal(out []byte) []byte

func (*CloneVolumeReq) Unmarshal

func (cr *CloneVolumeReq) Unmarshal(data []byte) error

type CloneVolumeResp

type CloneVolumeResp struct {
	Handle blobcache.Handle
}

func (CloneVolumeResp) Marshal

func (cr CloneVolumeResp) Marshal(out []byte) []byte

func (*CloneVolumeResp) Unmarshal

func (cr *CloneVolumeResp) Unmarshal(data []byte) error

type CommitReq

type CommitReq struct {
	Tx blobcache.Handle
	// Root can be optionally set to call Save before Commit.
	Root *[]byte
}

func (CommitReq) Marshal

func (cr CommitReq) Marshal(out []byte) []byte

func (*CommitReq) Unmarshal

func (cr *CommitReq) Unmarshal(data []byte) error

type CommitResp

type CommitResp struct{}

func (CommitResp) Marshal

func (cr CommitResp) Marshal(out []byte) []byte

func (*CommitResp) Unmarshal

func (cr *CommitResp) Unmarshal(data []byte) error

type CreateVolumeReq

type CreateVolumeReq struct {
	Spec blobcache.VolumeSpec
}

func (CreateVolumeReq) Marshal

func (cr CreateVolumeReq) Marshal(out []byte) []byte

func (*CreateVolumeReq) Unmarshal

func (cr *CreateVolumeReq) Unmarshal(data []byte) error

type CreateVolumeResp

type CreateVolumeResp struct {
	Handle blobcache.Handle
	Info   blobcache.VolumeInfo
}

func (CreateVolumeResp) Marshal

func (cr CreateVolumeResp) Marshal(out []byte) []byte

func (*CreateVolumeResp) Unmarshal

func (cr *CreateVolumeResp) Unmarshal(data []byte) error

type DeleteReq

type DeleteReq struct {
	Tx   blobcache.Handle
	CIDs []blobcache.CID
}

func (DeleteReq) Marshal

func (dr DeleteReq) Marshal(out []byte) []byte

func (*DeleteReq) Unmarshal

func (dr *DeleteReq) Unmarshal(data []byte) error

type DeleteResp

type DeleteResp struct{}

func (DeleteResp) Marshal

func (dr DeleteResp) Marshal(out []byte) []byte

func (*DeleteResp) Unmarshal

func (dr *DeleteResp) Unmarshal(data []byte) error

type DropReq

type DropReq struct {
	Handle blobcache.Handle
}

func (DropReq) Marshal

func (dr DropReq) Marshal(out []byte) []byte

func (*DropReq) Unmarshal

func (dr *DropReq) Unmarshal(data []byte) error

type DropResp

type DropResp struct{}

func (DropResp) Marshal

func (dr DropResp) Marshal(out []byte) []byte

func (*DropResp) Unmarshal

func (dr *DropResp) Unmarshal(data []byte) error

type ExistsReq

type ExistsReq struct {
	Tx   blobcache.Handle
	CIDs []blobcache.CID
}

func (ExistsReq) Marshal

func (er ExistsReq) Marshal(out []byte) []byte

func (*ExistsReq) Unmarshal

func (er *ExistsReq) Unmarshal(data []byte) error

type ExistsResp

type ExistsResp struct {
	Exists []bool
}

func (ExistsResp) Marshal

func (er ExistsResp) Marshal(out []byte) []byte

func (*ExistsResp) Unmarshal

func (er *ExistsResp) Unmarshal(data []byte) error

type GetReq

type GetReq struct {
	Tx   blobcache.Handle
	CID  blobcache.CID
	Salt *blobcache.CID
}

func (GetReq) Marshal

func (gr GetReq) Marshal(out []byte) []byte

func (*GetReq) Unmarshal

func (gr *GetReq) Unmarshal(data []byte) error

type GetResp

type GetResp struct {
	Data []byte
}

func (GetResp) Marshal

func (gr GetResp) Marshal(out []byte) []byte

func (*GetResp) Unmarshal

func (gr *GetResp) Unmarshal(data []byte) error

type InspectHandleReq

type InspectHandleReq struct {
	Handle blobcache.Handle
}

func (InspectHandleReq) Marshal

func (ir InspectHandleReq) Marshal(out []byte) []byte

func (*InspectHandleReq) Unmarshal

func (ir *InspectHandleReq) Unmarshal(data []byte) error

type InspectHandleResp

type InspectHandleResp struct {
	Info blobcache.HandleInfo
}

func (InspectHandleResp) Marshal

func (ir InspectHandleResp) Marshal(out []byte) []byte

func (*InspectHandleResp) Unmarshal

func (ir *InspectHandleResp) Unmarshal(data []byte) error

type InspectTxReq

type InspectTxReq struct {
	Tx blobcache.Handle
}

func (InspectTxReq) Marshal

func (r InspectTxReq) Marshal(out []byte) []byte

func (*InspectTxReq) Unmarshal

func (r *InspectTxReq) Unmarshal(data []byte) error

type InspectTxResp

type InspectTxResp struct {
	Info blobcache.TxInfo
}

func (InspectTxResp) Marshal

func (r InspectTxResp) Marshal(out []byte) []byte

func (*InspectTxResp) Unmarshal

func (r *InspectTxResp) Unmarshal(data []byte) error

type InspectVolumeReq

type InspectVolumeReq struct {
	Volume blobcache.Handle
}

func (InspectVolumeReq) Marshal

func (iv InspectVolumeReq) Marshal(out []byte) []byte

func (*InspectVolumeReq) Unmarshal

func (iv *InspectVolumeReq) Unmarshal(data []byte) error

type InspectVolumeResp

type InspectVolumeResp struct {
	Info blobcache.VolumeInfo
}

func (InspectVolumeResp) Marshal

func (iv InspectVolumeResp) Marshal(out []byte) []byte

func (*InspectVolumeResp) Unmarshal

func (iv *InspectVolumeResp) Unmarshal(data []byte) error

type IsVisitedReq

type IsVisitedReq struct {
	Tx   blobcache.Handle
	CIDs []blobcache.CID
}

func (IsVisitedReq) Marshal

func (ir IsVisitedReq) Marshal(out []byte) []byte

func (*IsVisitedReq) Unmarshal

func (ir *IsVisitedReq) Unmarshal(data []byte) error

type IsVisitedResp

type IsVisitedResp struct {
	Visited []bool
}

func (IsVisitedResp) Marshal

func (ir IsVisitedResp) Marshal(out []byte) []byte

func (*IsVisitedResp) Unmarshal

func (ir *IsVisitedResp) Unmarshal(data []byte) error

type KeepAliveReq

type KeepAliveReq struct {
	Handles []blobcache.Handle
}

func (KeepAliveReq) Marshal

func (kr KeepAliveReq) Marshal(out []byte) []byte

func (*KeepAliveReq) Unmarshal

func (kr *KeepAliveReq) Unmarshal(data []byte) error

type KeepAliveResp

type KeepAliveResp struct{}

func (KeepAliveResp) Marshal

func (kr KeepAliveResp) Marshal(out []byte) []byte

func (*KeepAliveResp) Unmarshal

func (kr *KeepAliveResp) Unmarshal(data []byte) error

type LoadReq

type LoadReq struct {
	Tx blobcache.Handle
}

func (LoadReq) Marshal

func (lr LoadReq) Marshal(out []byte) []byte

func (*LoadReq) Unmarshal

func (lr *LoadReq) Unmarshal(data []byte) error

type LoadResp

type LoadResp struct {
	Root []byte
}

func (LoadResp) Marshal

func (lr LoadResp) Marshal(out []byte) []byte

func (*LoadResp) Unmarshal

func (lr *LoadResp) Unmarshal(data []byte) error

type Marshaller

type Marshaller interface {
	Marshal(out []byte) []byte
}

type Message

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

func (*Message) Body

func (m *Message) Body() []byte

func (*Message) Header

func (m *Message) Header() MessageHeader

func (*Message) ReadFrom

func (m *Message) ReadFrom(r io.Reader) (int64, error)

func (*Message) SetBody

func (m *Message) SetBody(body []byte)

func (*Message) SetCode

func (m *Message) SetCode(code MessageType)

func (*Message) SetError

func (m *Message) SetError(err error)

func (*Message) WriteTo

func (m *Message) WriteTo(w io.Writer) (int64, error)

type MessageHeader

type MessageHeader [HeaderLen]byte

func (MessageHeader) BodyLen

func (h MessageHeader) BodyLen() int

func (MessageHeader) Code

func (h MessageHeader) Code() MessageType

func (*MessageHeader) SetBodyLen

func (h *MessageHeader) SetBodyLen(bodyLen int)

func (*MessageHeader) SetCode

func (h *MessageHeader) SetCode(code MessageType)

type MessageType

type MessageType uint8
const (
	MT_UNKNOWN MessageType = iota
	// MT_PING is a request to ping the remote peer.
	MT_PING
)
const (
	MT_HANDLE_INSPECT MessageType = 16 + iota
	MT_HANDLE_DROP
	MT_HANDLE_KEEP_ALIVE
	MT_HANDLE_SHARE
)

Handle messages

const (
	MT_OPEN_AS MessageType = 32 + iota
	MT_OPEN_FROM
	MT_CREATE_VOLUME
	MT_VOLUME_INSPECT
	MT_VOLUME_AWAIT
	MT_VOLUME_BEGIN_TX
	MT_VOLUME_CLONE
)

Volume messages

const (
	MT_TX_INSPECT MessageType = 48 + iota

	MT_TX_COMMIT
	MT_TX_ABORT

	MT_TX_LOAD
	MT_TX_SAVE

	MT_TX_POST
	MT_TX_POST_SALT
	MT_TX_GET
	MT_TX_EXISTS
	MT_TX_DELETE
	MT_TX_ADD_FROM
	MT_TX_ALLOW_LINK
	MT_TX_VISIT
	MT_TX_IS_VISITED
)

Tx messages

const (
	// MT_LAYER2_TELL is used for volume implementations to communicate with other volumes.
	MT_LAYER2_TELL MessageType = 96 + iota
	// MT_LAYER2_ASK is used for volume implementations to communicate with other volumes.
	MT_LAYER2_ASK
)

func (MessageType) IsError

func (mt MessageType) IsError() bool

func (MessageType) IsOK

func (mt MessageType) IsOK() bool

type Node

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

func New

func New(privateKey ed25519.PrivateKey, pc net.PacketConn) *Node

func (*Node) Ask

func (n *Node) Ask(ctx context.Context, remote blobcache.Endpoint, req Message, resp *Message) error

Ask opens a bidirectional stream to the given peer and sends the given request, then waits for a response.

func (*Node) LocalAddr

func (n *Node) LocalAddr() netip.AddrPort

func (*Node) LocalEndpoint

func (n *Node) LocalEndpoint() blobcache.Endpoint

func (*Node) LocalID

func (n *Node) LocalID() blobcache.PeerID

func (*Node) Serve

func (n *Node) Serve(ctx context.Context, srv Server) error

Serve blocks handling all incoming connections, until ctx is cancelled.

func (*Node) Tell

func (n *Node) Tell(ctx context.Context, remote blobcache.Endpoint, req *Message) error

Tell opens a uni-stream to the given peer and sends the given request.

type OpenFiatReq

type OpenFiatReq struct {
	Target blobcache.OID
	Mask   blobcache.ActionSet
}

func (OpenFiatReq) Marshal

func (oa OpenFiatReq) Marshal(out []byte) []byte

func (*OpenFiatReq) Unmarshal

func (oa *OpenFiatReq) Unmarshal(data []byte) error

type OpenFiatResp

type OpenFiatResp struct {
	Handle blobcache.Handle
	Info   blobcache.VolumeInfo
}

func (OpenFiatResp) Marshal

func (oa OpenFiatResp) Marshal(out []byte) []byte

func (*OpenFiatResp) Unmarshal

func (oa *OpenFiatResp) Unmarshal(data []byte) error

type OpenFromReq

type OpenFromReq struct {
	Base   blobcache.Handle
	Target blobcache.OID
	Mask   blobcache.ActionSet
}

func (OpenFromReq) Marshal

func (of OpenFromReq) Marshal(out []byte) []byte

func (*OpenFromReq) Unmarshal

func (of *OpenFromReq) Unmarshal(data []byte) error

type OpenFromResp

type OpenFromResp struct {
	Handle blobcache.Handle
	Info   blobcache.VolumeInfo
}

func (OpenFromResp) Marshal

func (of OpenFromResp) Marshal(out []byte) []byte

func (*OpenFromResp) Unmarshal

func (of *OpenFromResp) Unmarshal(data []byte) error

type SaveReq

type SaveReq struct {
	Tx   blobcache.Handle
	Root []byte
}

func (SaveReq) Marshal

func (r SaveReq) Marshal(out []byte) []byte

func (*SaveReq) Unmarshal

func (r *SaveReq) Unmarshal(data []byte) error

type SaveResp

type SaveResp struct{}

func (SaveResp) Marshal

func (r SaveResp) Marshal(out []byte) []byte

func (*SaveResp) Unmarshal

func (r *SaveResp) Unmarshal(data []byte) error

type Server

type Server struct {
	Access AccessFunc
}

type ShareReq

type ShareReq struct {
	Handle blobcache.Handle
	Peer   blobcache.PeerID
	Mask   blobcache.ActionSet
}

func (ShareReq) Marshal

func (sr ShareReq) Marshal(out []byte) []byte

func (*ShareReq) Unmarshal

func (sr *ShareReq) Unmarshal(data []byte) error

type ShareResp

type ShareResp struct {
	Handle blobcache.Handle
}

func (ShareResp) Marshal

func (sr ShareResp) Marshal(out []byte) []byte

func (*ShareResp) Unmarshal

func (sr *ShareResp) Unmarshal(data []byte) error

type Transport

type Transport interface {
	Tell(ctx context.Context, ep blobcache.Endpoint, req *Message) error
	Ask(ctx context.Context, ep blobcache.Endpoint, req Message, resp *Message) error
}

type Tx

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

Tx is a transaction on a remote volume.

func (*Tx) Abort

func (tx *Tx) Abort(ctx context.Context) error
func (tx *Tx) AllowLink(ctx context.Context, subvol blobcache.Handle) error

func (*Tx) Commit

func (tx *Tx) Commit(ctx context.Context) error

func (*Tx) Delete

func (tx *Tx) Delete(ctx context.Context, cids []blobcache.CID) error

func (*Tx) Exists

func (tx *Tx) Exists(ctx context.Context, cids []blobcache.CID, dst []bool) error

func (*Tx) Get

func (tx *Tx) Get(ctx context.Context, cid blobcache.CID, buf []byte, opts blobcache.GetOpts) (int, error)

func (*Tx) Hash

func (tx *Tx) Hash(salt *blobcache.CID, data []byte) blobcache.CID

func (*Tx) IsVisited

func (tx *Tx) IsVisited(ctx context.Context, cids []blobcache.CID, dst []bool) error

func (*Tx) Load

func (tx *Tx) Load(ctx context.Context, dst *[]byte) error

func (*Tx) MaxSize

func (tx *Tx) MaxSize() int

func (*Tx) Post

func (tx *Tx) Post(ctx context.Context, data []byte, opts blobcache.PostOpts) (blobcache.CID, error)

func (*Tx) Save

func (tx *Tx) Save(ctx context.Context, src []byte) error

func (*Tx) Visit

func (tx *Tx) Visit(ctx context.Context, cids []blobcache.CID) error

func (*Tx) Volume

func (tx *Tx) Volume() volumes.Volume

type Unmarshaller

type Unmarshaller interface {
	Unmarshal(data []byte) error
}

type VisitReq

type VisitReq struct {
	Tx   blobcache.Handle
	CIDs []blobcache.CID
}

func (VisitReq) Marshal

func (vr VisitReq) Marshal(out []byte) []byte

func (*VisitReq) Unmarshal

func (vr *VisitReq) Unmarshal(data []byte) error

type VisitResp

type VisitResp struct{}

func (VisitResp) Marshal

func (vr VisitResp) Marshal(out []byte) []byte

func (*VisitResp) Unmarshal

func (vr *VisitResp) Unmarshal(data []byte) error

type Volume

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

Volume is a remote volume.

func NewVolume

func NewVolume(node Transport, ep blobcache.Endpoint, h blobcache.Handle, info *blobcache.VolumeInfo) *Volume

func OpenVolumeAs

func OpenVolumeAs(ctx context.Context, tp Transport, ep blobcache.Endpoint, target blobcache.OID, mask blobcache.ActionSet) (*Volume, error)

func OpenVolumeFrom

func OpenVolumeFrom(ctx context.Context, tp Transport, ep blobcache.Endpoint, base blobcache.Handle, target blobcache.OID, mask blobcache.ActionSet) (*Volume, error)

func (*Volume) Await

func (v *Volume) Await(ctx context.Context, prev []byte, next *[]byte) error

func (*Volume) BeginTx

func (v *Volume) BeginTx(ctx context.Context, spec blobcache.TxParams) (volumes.Tx, error)

func (*Volume) Endpoint

func (v *Volume) Endpoint() blobcache.Endpoint

func (*Volume) Handle

func (v *Volume) Handle() blobcache.Handle

func (*Volume) Info

func (v *Volume) Info() *blobcache.VolumeInfo

Jump to

Keyboard shortcuts

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