bclocal

package
v0.0.0-...-f6f957e Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2025 License: GPL-3.0 Imports: 36 Imported by: 0

Documentation

Overview

Package bclocal implements a local Blobcache service.

Index

Constants

View Source
const (
	// DefaultVolumeTTL is the default time to live for a volume handle.
	DefaultVolumeTTL = 5 * time.Minute
	// DefaultTxTTL is the default time to live for a transaction handle.
	DefaultTxTTL = 1 * time.Minute

	// MaxMaxBlobSize is the maximum value that a Volume's max size can be set to.
	MaxMaxBlobSize = 1 << 24
)

Variables

This section is empty.

Functions

func AddDefaultSchema

func AddDefaultSchema(name blobcache.SchemaName, constructor schema.Constructor)

func DefaultPebbleOptions

func DefaultPebbleOptions() *pebble.Options

DefaultPebbleOptions

func DefaultRoot

func DefaultRoot() blobcache.VolumeSpec

DefaultRoot returns the default root volume spec. It uses the basicns schema and a 2MB byte max size.

func DefaultSchemas

func DefaultSchemas() map[blobcache.SchemaName]schema.Constructor

Types

type AllOrNothingPolicy

type AllOrNothingPolicy struct {
	Allow []blobcache.PeerID
}

AllOrNothingPolicy is a policy that allows or disallows all actions for all peers.

func (*AllOrNothingPolicy) CanConnect

func (p *AllOrNothingPolicy) CanConnect(peer blobcache.PeerID) bool

func (*AllOrNothingPolicy) CanCreate

func (p *AllOrNothingPolicy) CanCreate(peer blobcache.PeerID) bool

func (*AllOrNothingPolicy) Open

type Config

type Config struct {
	// When set to true, the service will not sync the database and blob directory.
	NoSync bool
}

Config contains configuration for the service. Config{} works fine. You don't need to worry about anything in here.

type Env

type Env struct {
	Background context.Context
	// StateDir is the directory where all the state is stored.
	StateDir string
	// PrivateKey determines the node's identity.
	// It must be provided if PacketConn is set.
	PrivateKey ed25519.PrivateKey
	// Schemas is the supported schemas.
	Schemas map[blobcache.SchemaName]schema.Constructor
	// Root is the spec to use for the root volume.
	Root blobcache.VolumeSpec
	// Policy control network access to the service.
	Policy Policy
}

func NewTestEnv

func NewTestEnv(t testing.TB) Env

NewTestEnv creates a test environment. It uses: - t.TempDir() to create a temporary directory - creates a UDP socket on a random port. All the resources are cleaned up when the test is done.

type ErrNotAllowed

type ErrNotAllowed struct {
	Peer   blobcache.PeerID
	Action string
	Target blobcache.OID
}

func (ErrNotAllowed) Error

func (e ErrNotAllowed) Error() string

type LocalVolumeID

type LocalVolumeID uint64

func (LocalVolumeID) Marshal

func (lvid LocalVolumeID) Marshal(out []byte) []byte

type Policy

type Policy interface {
	Open(peer blobcache.PeerID, target blobcache.OID) blobcache.ActionSet
	// CanCreate returns true if the peer can create a new volume.
	CanCreate(peer blobcache.PeerID) bool
	CanConnect(peer blobcache.PeerID) bool
}

type RefCount

type RefCount uint32

type Service

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

Service implements a blobcache.Service.

func New

func New(env Env, cfg Config) (*Service, error)

func NewTestService

func NewTestService(t testing.TB) *Service

NewTestService creates a service scoped to the life of the test. It calls NewTestEnv and NewTestServiceFromEnv

func NewTestServiceFromEnv

func NewTestServiceFromEnv(t testing.TB, env Env) *Service

NewTestServiceFromEnv creates a service from an environment. It runs the service in the background and forcibly aborts all transactions when the test is done.

func (*Service) Abort

func (s *Service) Abort(ctx context.Context, txh blobcache.Handle) error

func (*Service) AbortAll

func (s *Service) AbortAll(ctx context.Context) error

AbortAll aborts all transactions.

func (s *Service) AllowLink(ctx context.Context, txh blobcache.Handle, subvolh blobcache.Handle) error

func (*Service) Await

func (s *Service) Await(ctx context.Context, cond blobcache.Conditions) error

func (*Service) BeginTx

func (s *Service) BeginTx(ctx context.Context, volh blobcache.Handle, txspec blobcache.TxParams) (*blobcache.Handle, error)

func (*Service) Cleanup

func (s *Service) Cleanup(ctx context.Context) error

Cleanup runs the full cleanup process. This method is called periodically by Run, but it can also be called manually.

func (*Service) CloneVolume

func (s *Service) CloneVolume(ctx context.Context, caller *blobcache.PeerID, volh blobcache.Handle) (*blobcache.Handle, error)

func (*Service) Close

func (s *Service) Close() error

func (*Service) Commit

func (s *Service) Commit(ctx context.Context, txh blobcache.Handle) error

func (*Service) Copy

func (s *Service) Copy(ctx context.Context, txh blobcache.Handle, cids []blobcache.CID, srcTxns []blobcache.Handle, out []bool) error

func (*Service) CreateVolume

func (s *Service) CreateVolume(ctx context.Context, host *blobcache.Endpoint, vspec blobcache.VolumeSpec) (*blobcache.Handle, error)

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, txh blobcache.Handle, cids []blobcache.CID) error

func (*Service) Drop

func (s *Service) Drop(ctx context.Context, h blobcache.Handle) error

func (*Service) Endpoint

func (s *Service) Endpoint(ctx context.Context) (blobcache.Endpoint, error)

Endpoint blocks waiting for a node to be created (happens when Serve is running). And then returns the Endpoint for that Node.

func (*Service) Exists

func (s *Service) Exists(ctx context.Context, txh blobcache.Handle, cids []blobcache.CID, dst []bool) error

func (*Service) Get

func (s *Service) Get(ctx context.Context, txh blobcache.Handle, cid blobcache.CID, buf []byte, opts blobcache.GetOpts) (int, error)

func (*Service) InspectHandle

func (s *Service) InspectHandle(ctx context.Context, h blobcache.Handle) (*blobcache.HandleInfo, error)

func (*Service) InspectTx

func (s *Service) InspectTx(ctx context.Context, txh blobcache.Handle) (*blobcache.TxInfo, error)

func (*Service) InspectVolume

func (s *Service) InspectVolume(ctx context.Context, h blobcache.Handle) (*blobcache.VolumeInfo, error)

func (*Service) IsVisited

func (s *Service) IsVisited(ctx context.Context, txh blobcache.Handle, cids []blobcache.CID, dst []bool) error

func (*Service) KeepAlive

func (s *Service) KeepAlive(ctx context.Context, hs []blobcache.Handle) error

func (*Service) Load

func (s *Service) Load(ctx context.Context, txh blobcache.Handle, dst *[]byte) error

func (*Service) LocalID

func (s *Service) LocalID() blobcache.PeerID

func (*Service) OpenFiat

func (s *Service) OpenFiat(ctx context.Context, x blobcache.OID, mask blobcache.ActionSet) (*blobcache.Handle, error)

func (*Service) OpenFrom

func (*Service) Post

func (s *Service) Post(ctx context.Context, txh blobcache.Handle, data []byte, opts blobcache.PostOpts) (blobcache.CID, error)

func (*Service) Save

func (s *Service) Save(ctx context.Context, txh blobcache.Handle, root []byte) error

func (*Service) Serve

func (s *Service) Serve(ctx context.Context, pc net.PacketConn) error

Serve handles requests from the network. Serve blocks untilt the context is cancelled, or Close is called. Cancelling the context will cause Run to return without an error. If Serve is *not* running, then remote volumes will not work, hosted on this Node or other Nodes.

func (*Service) Share

func (*Service) Visit

func (s *Service) Visit(ctx context.Context, txh blobcache.Handle, cids []blobcache.CID) error

Directories

Path Synopsis
internal
pdb
package pdb has utilities for working with the Pebble database.
package pdb has utilities for working with the Pebble database.

Jump to

Keyboard shortcuts

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