bcnet

package
v0.0.0-...-1ef88f4 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const HeaderLen = 1 + 4

Variables

This section is empty.

Functions

func MarshalWireError

func MarshalWireError(err error) []byte

func OpenVolume

func OpenVolume(ctx context.Context, n *Node, ep blobcache.Endpoint, id blobcache.OID) (volumes.Volume, error)

func ParseWireError

func ParseWireError(x []byte) error

Types

type AbortReq

type AbortReq struct {
	Tx blobcache.Handle `json:"tx"`
}

type AbortResp

type AbortResp struct{}

type AccessFunc

type AccessFunc func(blobcache.PeerID) blobcache.Service

AccessFun is called to get a service to access

type AwaitReq

type AwaitReq struct {
	Cond blobcache.Conditions `json:"cond"`
}

type AwaitResp

type AwaitResp struct{}

type BeginTxReq

type BeginTxReq struct {
	Volume blobcache.Handle   `json:"volume"`
	Params blobcache.TxParams `json:"params"`
}

type BeginTxResp

type BeginTxResp struct {
	// Tx is the handle for the transaction.
	Tx blobcache.Handle `json:"tx"`
	// VolumeInfo is the volume info for the transaction.
	VolumeInfo blobcache.VolumeInfo `json:"volume_info"`
}

type CommitReq

type CommitReq struct {
	Tx   blobcache.Handle `json:"tx"`
	Root []byte           `json:"root"`
}

type CommitResp

type CommitResp struct{}

type DeleteEntryReq

type DeleteEntryReq struct {
	Namespace blobcache.Handle `json:"namespace"`
	Name      string           `json:"name"`
}

type DeleteEntryResp

type DeleteEntryResp struct{}

type DeleteReq

type DeleteReq struct {
	Tx  blobcache.Handle `json:"tx"`
	CID blobcache.CID    `json:"cid"`
}

type DeleteResp

type DeleteResp struct{}

type DropReq

type DropReq struct {
	Handle blobcache.Handle `json:"handle"`
}

type DropResp

type DropResp struct{}

type ExistsReq

type ExistsReq struct {
	Tx   blobcache.Handle `json:"tx"`
	CIDs []blobcache.CID  `json:"cids"`
}

type ExistsResp

type ExistsResp struct {
	Exists []bool `json:"exists"`
}

type GetEntryReq

type GetEntryReq struct {
	Namespace blobcache.Handle `json:"namespace"`
	Name      string           `json:"name"`
}

type GetEntryResp

type GetEntryResp struct {
	Entry blobcache.Entry `json:"entry"`
}

type GetReq

type GetReq struct {
	Tx   blobcache.Handle `json:"tx"`
	CID  blobcache.CID    `json:"cid"`
	Salt *blobcache.CID   `json:"salt,omitempty"`
}

type GetResp

type GetResp struct {
	Data []byte `json:"data"`
}

type HandleMapping

type HandleMapping struct {
	Upwards   func(blobcache.Handle) blobcache.Handle
	Downwards func(blobcache.Handle) blobcache.Handle
}

func (HandleMapping) IsZero

func (hm HandleMapping) IsZero() bool

type InspectHandleReq

type InspectHandleReq struct {
	Handle blobcache.Handle `json:"handle"`
}

type InspectHandleResp

type InspectHandleResp struct {
	Info blobcache.HandleInfo `json:"info"`
}

type InspectVolumeReq

type InspectVolumeReq struct {
	Volume blobcache.Handle `json:"volume"`
}

type InspectVolumeResp

type InspectVolumeResp struct {
	Info *blobcache.VolumeInfo `json:"info"`
}

type KeepAliveReq

type KeepAliveReq struct {
	Handles []blobcache.Handle `json:"handles"`
}

type KeepAliveResp

type KeepAliveResp struct{}

type ListNamesReq

type ListNamesReq struct {
	Target blobcache.Handle `json:"target"`
}

type ListNamesResp

type ListNamesResp struct {
	Names []string `json:"names"`
}

type LoadReq

type LoadReq struct {
	Tx blobcache.Handle `json:"tx"`
}

type LoadResp

type LoadResp struct {
	Root []byte `json:"root"`
}

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_OK is the success response to a request.
	MT_OK

	// MT_PING is a request to ping the remote peer.
	MT_PING

	MT_HANDLE_INSPECT
	MT_HANDLE_DROP
	MT_HANDLE_KEEP_ALIVE
	MT_OPEN

	MT_NAMESPACE_OPEN_AT
	MT_NAMESPACE_GET_ENTRY
	MT_NAMESPACE_PUT_ENTRY
	MT_NAMESPACE_DELETE_ENTRY
	MT_NAMESPACE_LIST_NAMES

	MT_VOLUME_INSPECT
	MT_VOLUME_AWAIT
	MT_VOLUME_BEGIN_TX

	MT_TX_COMMIT
	MT_TX_ABORT
	MT_TX_LOAD
	MT_TX_POST
	MT_TX_POST_SALT
	MT_TX_GET
	MT_TX_EXISTS
	MT_TX_DELETE

	// MT_LAYER2_TELL is used for volume implementations to communicate with other volumes.
	MT_LAYER2_TELL
	// MT_LAYER2_ASK is used for volume implementations to communicate with other volumes.
	MT_LAYER2_ASK

	MT_ERROR = 255
)

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 OpenAtReq

type OpenAtReq struct {
	Namespace blobcache.Handle `json:"namespace"`
	Name      string           `json:"name"`
}

type OpenAtResp

type OpenAtResp struct {
	Handle blobcache.Handle `json:"handle"`
}

type OpenReq

type OpenReq struct {
	OID blobcache.OID `json:"target"`
}

type OpenResp

type OpenResp struct {
	Handle blobcache.Handle `json:"handle"`
}

type PutEntryReq

type PutEntryReq struct {
	Namespace blobcache.Handle `json:"namespace"`
	Name      string           `json:"name"`
	Target    blobcache.Handle
}

type PutEntryResp

type PutEntryResp struct{}

type Server

type Server struct {
	Access AccessFunc
}

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) Commit

func (tx *Tx) Commit(ctx context.Context, root []byte) error

func (*Tx) Delete

func (tx *Tx) Delete(ctx context.Context, cid blobcache.CID) error

func (*Tx) Exists

func (tx *Tx) Exists(ctx context.Context, cid blobcache.CID) (bool, error)

func (*Tx) Get

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

func (*Tx) Hash

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

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, salt *blobcache.CID, data []byte) (blobcache.CID, error)

type Volume

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

Volume is a remote volume.

func NewVolume

func NewVolume(n *Node, ep blobcache.Endpoint, h blobcache.Handle, handleMapper HandleMapping) *Volume

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)

type WireError

type WireError struct {
	InvalidHandle *blobcache.ErrInvalidHandle `json:"invalid_handle,omitempty"`
	NotFound      *blobcache.ErrNotFound      `json:"not_found,omitempty"`
	Unknown       *string                     `json:"unknown,omitempty"`
}

Jump to

Keyboard shortcuts

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