ipfs

package
v0.0.0-...-eb31e87 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2018 License: Apache-2.0 Imports: 25 Imported by: 0

README

This directory contains an experimental chunkstore backed by IPFS.

As IPFS does not currently provide any kind of durability or consistency guarantees, neither does a database backed by this ChunkStore implementation.

Documentation

Index

Constants

View Source
const (
	DefaultAPIPort     = 5001
	DefaultGatewayPort = 8080
	DefaultSwarmPort   = 4001
)

Default ports for IPFS

View Source
const (
	// NetworkProtoName is the default protocol name for networked IPFS ChunkStores. SetLocal for more information
	NetworkProtoName = "ipfs"

	// LocalProtoName is the default protocol name for local IPFS ChunkStores. See SetLocal for more information.
	// information.
	LocalProtoName = "ipfs-local"
)

Variables

This section is empty.

Functions

func CidToNomsHash

func CidToNomsHash(id *cid.Cid) (h hash.Hash)

func NewChunkStore

func NewChunkStore(dbPath string, opts ...Option) (chunks.ChunkStore, error)

NewChunkStore creates a new ChunkStore backed by IPFS.

Noms chunks written to this ChunkStore are converted to IPFS blocks and stored in an IPFS BlockStore.

IPFS database specs have the form:

ipfs://<path-to-ipfs-dir> for networked ChunkStores
ipfs-local://<path-to-ipfs-dir> for local ChunkStores

where 'ipfs' or 'ipfs-local' indicates the noms protocol and the path indicates the path to the directory where the ipfs repo resides. The chunkstore creates two files in the ipfs directory called 'noms' and 'noms-local' which stores the root of the noms database. This should ideally be done with IPNS, but that is currently too slow to be practical.

This function creates an IPFS repo at the appropriate path if one doesn't already exist.

See Option documentation for more information on options.

func NomsHashToCID

func NomsHashToCID(nh hash.Hash) *cid.Cid

func OpenIPFSRepo

func OpenIPFSRepo(path string, portIdx int) (*core.IpfsNode, error)

OpenIPFSRepo opens an IPFS repo for use as a noms store, and returns an IPFS node for that repo. Creates a new repo at this indicated path if one doesn't already exist. See SetPortIdx for information on portIdx.

func RegisterProtocols

func RegisterProtocols(opts ...Option) error

RegisterProtocols registers the "ipfs" and "ipfs-local" protocols as external protocols for Specs, with the given options applied to both local and networked protocols. The protocols default to port index 0 and a maximum concurrent request count of 1. SetLocal and SetNetworked are ignored.

The external protocol is implemented by the Protocol type.

func UnregisterProtocols

func UnregisterProtocols()

UnregisterProtocols unregisters the "ipfs" and "ipfs-local" protocols as external protocols for Specs.

Types

type HasIPFSNode

type HasIPFSNode interface {
	IPFSNode() *core.IpfsNode
}

Implementing HasIPFSNode indicates that a type has an underlying IPFS node. It is implemented by the ChunkStore and Database returned by Protocol (i.e. all ChunkStores and Databases created via a Spec) and NewChunkStore/ChunkStoreFromIPFSNode

type IPFSStats

type IPFSStats struct {
	Local   bool
	PortIdx int
}

type Option

type Option interface {
	// contains filtered or unexported methods
}

An Option configures the IPFS ChunkStore

func SetLocal

func SetLocal() Option

SetLocal makes the ChunkStore only use the local IPFS blockstore for both reads and writes.

func SetMaxConcurrent

func SetMaxConcurrent(max int) Option

SetMaxConcurrent sets the maximum number of concurrent requests used when creating IPFS ChunkStores from a Spec. The default is 1. Negative values of n will return an error.

func SetNetworked

func SetNetworked() Option

SetNetworked makes reads fall through to the network and expose stored blocks to the entire IPFS network.

func SetPortIdx

func SetPortIdx(portIdx int) Option

SetPortIdx sets the port index to use when creating IPFS ChunkStores from a Spec. If portIdx is a number between 1 and 8 inclusive, the config file will be modified to add 'portIdx' to each external port's number. The defaults are API: 5001, gateway: 8080, swarm: 4001, so a portIdx of 1 would give you 5002, 8081, and 4002.

The default is 0, which stands for IPFS default ports. idx must be between 0 and 8 inclusive; other values will result in an error.

type Protocol

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

Protocol implements spec.ProtocolImpl for the IPFS ChunkStore

func NewProtocol

func NewProtocol(opts ...Option) (*Protocol, error)

NewProtocol returns a new Protocol with the given options. The protocol defaults to port index 0, and a maximum concurrent request count of 1. See documentation under Option for more information on options

func (Protocol) NewChunkStore

func (p Protocol) NewChunkStore(sp spec.Spec) (chunks.ChunkStore, error)

NewChunkStore returns a new ChunkStore backed by IPFS using the options passed in via NewProtocol The returned ChunkStore implements HasIPFSNode.

See the package-level NewChunkStore and Options for more information.

func (Protocol) NewDatabase

func (p Protocol) NewDatabase(sp spec.Spec) (datas.Database, error)

NewDatabase returns a new Database backed by an IPFS ChunkStore. The returned database implements HasIPFSNode.

See the package-level NewChunkStore and Options for more information.

Jump to

Keyboard shortcuts

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