bsrvadapter

package module
v0.0.0-...-198d7db Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 5 Imported by: 0

README

bsrvadapter

The bsrvadapter package/module is a small piece of glue code to connect the github.com/ipfs/go-blockservice package, and packages implementing its interfaces, forward into the go-ipld-prime/storage interfaces.

This can be used to rig systems like Bitswap up behind go-ipld-prime storage APIs.

(Whether or not this is a good idea is debatable. It should be noted that both the ipfs/go-blockservice API, as well as Bitswap in particular as an implementation, are inherently prone to the infamous "N+1 Query Problem". Treating a remote network fetch as equivalent to a local low-latency operation just isn't a good idea for performance or predictability, no matter how you slice it. Nonetheless: it's possible, using this code, if you really want to do it.)

Why structured like this?

See ../README_adapters.md for details about why adapter code is needed, why this is in a module, why it's here, etc.

Which of dsadapter vs bsadapter vs bsrvadapter should I use?

In short: you should prefer direct implementations of the storage APIs over any of these adapters, if one is available with the features you need.

Otherwise, if that's not an option (yet) for some reason, use whichever adapter gets you most directly connected to the code you need.

See ../README_adapters.md for more details and discussion.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	Wrapped blockservice.BlockService
}

Adapter implements go-ipld-prime/storage.ReadableStorage and go-ipld-prime/storage.WritableStorage backed by a go-blockservice.BlockService.

The go-blockservice.BlockService may internally have other configuration, and contain whole other systems like Bitswap for transport. We don't interfere with that here; such configuration should be handled when creating the go-blockservice value.

Note that this system will only work for certain structures of keys -- this is because the blockservice API works on the level of CIDs. As long as your key string is the binary form of a CID, it will work correctly. Other keys are not possible to support with this adapter.

Contexts given to this system are passed through where possible, but it is not possible in all cases. For operations where the underlying interface doesn't accept a context parameter, this adapter will check the context for errors before beginning an operation, but the context will otherwise have no effect. For operations where BlockService does accept a context, we pass it on.

func (*Adapter) Get

func (a *Adapter) Get(ctx context.Context, key string) ([]byte, error)

Get implements go-ipld-prime/storage.ReadableStorage.Get.

func (*Adapter) Has

func (a *Adapter) Has(ctx context.Context, key string) (bool, error)

Has implements go-ipld-prime/storage.Storage.Has.

Note that for a BlockService, the Has operation has rather unusual semantics. Has may return false, and an immediately subsequent Get for the same key might return data! This is because the Has operation is defined as whether the Blockstore that the BlockService wraps has the requested key, immediately, locally; while the Get operation might use the BlockService to go _find_ the requested key and its content, even remotely!

func (*Adapter) Put

func (a *Adapter) Put(ctx context.Context, key string, content []byte) error

Put implements go-ipld-prime/storage.WritableStorage.Put.

Jump to

Keyboard shortcuts

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