store

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: Apache-2.0, MIT Imports: 26 Imported by: 23

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPreconditionFailed = errors.New("precondition failed")

ErrPreconditionFailed is returned when a conditional write fails.

View Source
var MaxEntryChunkSize = 16384

MaxEntryChunkSize is the maximum number of multihashes each advertisement entry chunk may contain.

Functions

func ChunkLink(ctx context.Context, ds ProviderContextTable, p peer.ID, contextID []byte) (datamodel.Link, error)

func Encode

func Encode(ctx context.Context, ds SimpleStore, lnk ipld.Link, w io.Writer) error

func EncodeHead

func EncodeHead(ctx context.Context, ds SimpleStore, w io.Writer) error
func Head(ctx context.Context, ds SimpleStore) (*head.SignedHead, error)

func IsNotFound

func IsNotFound(err error) bool

func Metadata

func Metadata(ctx context.Context, mctx metadata.MetadataContext, ds ProviderContextTable, p peer.ID, contextID []byte) (metadata.Metadata, error)

func PutAdvert

func PutAdvert(ctx context.Context, ds SimpleStore, adv schema.Advertisement) (ipld.Link, error)
func PutChunkLink(ctx context.Context, ds ProviderContextTable, p peer.ID, contextID []byte, lnk datamodel.Link) error

func PutEntries

func PutEntries(ctx context.Context, ds SimpleStore, entries iter.Seq[multihash.Multihash], chunkSize int) (next ipld.Link, err error)

func PutMetadata

func PutMetadata(ctx context.Context, ds ProviderContextTable, p peer.ID, contextID []byte, md metadata.Metadata) error

func ReplaceHead added in v0.3.0

func ReplaceHead(ctx context.Context, ds Store, oldHead *head.SignedHead, newHead *head.SignedHead) (datamodel.Link, error)

Types

type AdStore

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

func NewPublisherStore

func NewPublisherStore(store Store, chunkLinks, metadataTable ProviderContextTable, opts ...Option) *AdStore

func (*AdStore) Advert

func (s *AdStore) Advert(ctx context.Context, id ipld.Link) (schema.Advertisement, error)

func (*AdStore) ChunkLinkForProviderAndContextID

func (s *AdStore) ChunkLinkForProviderAndContextID(ctx context.Context, p peer.ID, contextID []byte) (datamodel.Link, error)

func (*AdStore) DeleteChunkLinkForProviderAndContextID

func (s *AdStore) DeleteChunkLinkForProviderAndContextID(ctx context.Context, p peer.ID, contextID []byte) error

func (*AdStore) DeleteMetadataForProviderAndContextID

func (s *AdStore) DeleteMetadataForProviderAndContextID(ctx context.Context, p peer.ID, contextID []byte) error

func (*AdStore) Encode

func (s *AdStore) Encode(ctx context.Context, id datamodel.Link, w io.Writer) error

func (*AdStore) EncodeHead

func (s *AdStore) EncodeHead(ctx context.Context, w io.Writer) error

func (*AdStore) Entries

func (s *AdStore) Entries(ctx context.Context, root ipld.Link) iter.Seq2[multihash.Multihash, error]

func (*AdStore) Head

func (s *AdStore) Head(ctx context.Context) (*head.SignedHead, error)

func (*AdStore) MetadataForProviderAndContextID

func (s *AdStore) MetadataForProviderAndContextID(ctx context.Context, p peer.ID, contextID []byte) (metadata.Metadata, error)

func (*AdStore) PutAdvert

func (s *AdStore) PutAdvert(ctx context.Context, ad schema.Advertisement) (ipld.Link, error)

func (*AdStore) PutChunkLinkForProviderAndContextID

func (s *AdStore) PutChunkLinkForProviderAndContextID(ctx context.Context, p peer.ID, contextID []byte, chunkLink datamodel.Link) error

func (*AdStore) PutEntries

func (s *AdStore) PutEntries(ctx context.Context, mhs iter.Seq[multihash.Multihash]) (ipld.Link, error)

func (*AdStore) PutMetadataForProviderAndContextID

func (s *AdStore) PutMetadataForProviderAndContextID(ctx context.Context, p peer.ID, contextID []byte, md metadata.Metadata) error

func (*AdStore) ReplaceHead added in v0.3.0

func (s *AdStore) ReplaceHead(ctx context.Context, oldHead *head.SignedHead, newHead *head.SignedHead) (datamodel.Link, error)

type AdvertReadable

type AdvertReadable interface {
	// Advert retrieves an existing advert from the store.
	Advert(ctx context.Context, id ipld.Link) (schema.Advertisement, error)
}

type AdvertStore

type AdvertStore interface {
	AdvertReadable
	AdvertWritable
}

type AdvertWritable

type AdvertWritable interface {
	PutAdvert(ctx context.Context, ad schema.Advertisement) (ipld.Link, error)
}

type ChunkLinkStore

type ChunkLinkStore interface {
	ChunkLinkForProviderAndContextID(ctx context.Context, p peer.ID, contextID []byte) (ipld.Link, error)
	PutChunkLinkForProviderAndContextID(ctx context.Context, p peer.ID, contextID []byte, adCid ipld.Link) error
	DeleteChunkLinkForProviderAndContextID(ctx context.Context, p peer.ID, contextID []byte) error
}

type EncodeableStore

type EncodeableStore interface {
	Encode(ctx context.Context, id ipld.Link, w io.Writer) error
	EncodeHead(ctx context.Context, w io.Writer) error
}

type EntriesReadable

type EntriesReadable interface {
	// Entries returns an iterable of multihashes from the store for the
	// given root of an existing advertisement entries chain.
	Entries(ctx context.Context, root ipld.Link) iter.Seq2[multihash.Multihash, error]
}

type EntriesStore

type EntriesStore interface {
	EntriesReadable
	EntriesWritable
}

type EntriesWritable

type EntriesWritable interface {
	// PutEntries writes a given set of multihash entries to do the store and returns the root cid
	PutEntries(ctx context.Context, entries iter.Seq[multihash.Multihash]) (ipld.Link, error)
}

type ErrNotFound

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

func NewErrNotFound

func NewErrNotFound(underlying error) ErrNotFound

func (ErrNotFound) Error

func (e ErrNotFound) Error() string

func (ErrNotFound) Unwrap

func (e ErrNotFound) Unwrap() error

type FullStore

type FullStore interface {
	EncodeableStore
	PublisherStore
}

func FromDatastore

func FromDatastore(ds datastore.Datastore, opts ...Option) FullStore

func FromLocalStore

func FromLocalStore(storagePath string, ds datastore.Datastore, opts ...Option) FullStore

type HeadStore

type HeadStore interface {
	Head(ctx context.Context) (*head.SignedHead, error)
	// ReplaceHead swaps the previous head for the provided new head. Note the
	// previous head may be nil when no head exists yet.
	//
	// It allows an implementation to perform conditional writes to mitigate
	// against losing an advert when 2 or more are published concurrently.
	//
	// [ErrPreconditionFailed] is returned when the write fails due to the current
	// head not matching the passed old head.
	ReplaceHead(ctx context.Context, oldHead *head.SignedHead, newHead *head.SignedHead) (ipld.Link, error)
}

type MetadataStore

type MetadataStore interface {
	MetadataForProviderAndContextID(ctx context.Context, p peer.ID, contextID []byte) (metadata.Metadata, error)
	PutMetadataForProviderAndContextID(ctx context.Context, p peer.ID, contextID []byte, md metadata.Metadata) error
	DeleteMetadataForProviderAndContextID(ctx context.Context, p peer.ID, contextID []byte) error
}

type Option

type Option func(cfg *options)

Option is an option configuring a store.

func WithMetadataContext

func WithMetadataContext(context metadata.MetadataContext) Option

WithMetadataContext configues the IPNI metadata context, allowing custom metadata types to be stored. If not configured, the default context is used.

type ProviderContextTable

type ProviderContextTable interface {
	Get(ctx context.Context, p peer.ID, contextID []byte) ([]byte, error)
	Put(ctx context.Context, p peer.ID, contextID []byte, data []byte) error
	Delete(ctx context.Context, p peer.ID, contextID []byte) error
}

func NewDatastoreProviderContextTable added in v0.3.0

func NewDatastoreProviderContextTable(ds datastore.Datastore) ProviderContextTable

type SimpleStore added in v0.3.0

type SimpleStore interface {
	Get(ctx context.Context, key string) (io.ReadCloser, error)
	Put(ctx context.Context, key string, len uint64, data io.Reader) error
}

func SimpleStoreFromDatastore

func SimpleStoreFromDatastore(ds datastore.Datastore) SimpleStore

type Store

type Store interface {
	SimpleStore
	// Replace allows conditional writes to the store. It returns
	// [ErrPreconditionFailed] when a write fails due to the old data not matching
	// the passed value. Note: old may be nil, when no old data exists.
	Replace(ctx context.Context, key string, old io.Reader, len uint64, new io.Reader) error
}

Jump to

Keyboard shortcuts

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