iface

package
v0.4.18 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package iface defines IPFS Core API which is a set of interfaces used to interact with IPFS nodes.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIsDir   = errors.New("this dag node is a directory")
	ErrOffline = errors.New("this action must be run in online mode, try running 'ipfs daemon' first")
)
View Source
var (
	ErrNotConnected = errors.New("not connected")
	ErrConnNotFound = errors.New("conn not found")
)
View Source
var ErrResolveFailed = errors.New("could not resolve name")

Functions

This section is empty.

Types

type AddEvent added in v0.4.18

type AddEvent struct {
	Name  string
	Hash  string `json:",omitempty"`
	Bytes int64  `json:",omitempty"`
	Size  string `json:",omitempty"`
}

TODO: ideas on making this more coreapi-ish without breaking the http API?

type BadPinNode added in v0.4.14

type BadPinNode interface {
	// Path is the path of the node
	Path() ResolvedPath

	// Err is the reason why the node has been marked as bad
	Err() error
}

BadPinNode is a node that has been marked as bad by Pin.Verify

type BlockAPI added in v0.4.14

type BlockAPI interface {
	// Put imports raw block data, hashing it using specified settings.
	Put(context.Context, io.Reader, ...options.BlockPutOption) (BlockStat, error)

	// Get attempts to resolve the path and return a reader for data in the block
	Get(context.Context, Path) (io.Reader, error)

	// Rm removes the block specified by the path from local blockstore.
	// By default an error will be returned if the block can't be found locally.
	//
	// NOTE: If the specified block is pinned it won't be removed and no error
	// will be returned
	Rm(context.Context, Path, ...options.BlockRmOption) error

	// Stat returns information on
	Stat(context.Context, Path) (BlockStat, error)
}

BlockAPI specifies the interface to the block layer

type BlockStat added in v0.4.14

type BlockStat interface {
	// Size is the size of a block
	Size() int

	// Path returns path to the block
	Path() ResolvedPath
}

BlockStat contains information about a block

type ChangeType added in v0.4.18

type ChangeType int

ChangeType denotes type of change in ObjectChange

const (
	// DiffAdd is set when a link was added to the graph
	DiffAdd ChangeType = iota

	// DiffRemove is set when a link was removed from the graph
	DiffRemove

	// DiffMod is set when a link was changed in the graph
	DiffMod
)

type ConnectionInfo added in v0.4.18

type ConnectionInfo interface {
	// ID returns PeerID
	ID() peer.ID

	// Address returns the multiaddress via which we are connected with the peer
	Address() ma.Multiaddr

	// Direction returns which way the connection was established
	Direction() net.Direction

	// Latency returns last known round trip time to the peer
	Latency() (time.Duration, error)

	// Streams returns list of streams established with the peer
	Streams() ([]protocol.ID, error)
}

ConnectionInfo contains information about a peer

type CoreAPI added in v0.4.8

type CoreAPI interface {
	// Unixfs returns an implementation of Unixfs API
	Unixfs() UnixfsAPI

	// Block returns an implementation of Block API
	Block() BlockAPI

	// Dag returns an implementation of Dag API
	Dag() DagAPI

	// Name returns an implementation of Name API
	Name() NameAPI

	// Key returns an implementation of Key API
	Key() KeyAPI

	// Pin returns an implementation of Pin API
	Pin() PinAPI

	// ObjectAPI returns an implementation of Object API
	Object() ObjectAPI

	// Dht returns an implementation of Dht API
	Dht() DhtAPI

	// Swarm returns an implementation of Swarm API
	Swarm() SwarmAPI

	// PubSub returns an implementation of PubSub API
	PubSub() PubSubAPI

	// ResolvePath resolves the path using Unixfs resolver
	ResolvePath(context.Context, Path) (ResolvedPath, error)

	// ResolveNode resolves the path (if not resolved already) using Unixfs
	// resolver, gets and returns the resolved Node
	ResolveNode(context.Context, Path) (ipld.Node, error)
}

CoreAPI defines an unified interface to IPFS for Go programs

type DagAPI added in v0.4.14

type DagAPI interface {
	DagOps

	// Get attempts to resolve and get the node specified by the path
	Get(ctx context.Context, path Path) (ipld.Node, error)

	// Tree returns list of paths within a node specified by the path.
	Tree(ctx context.Context, path Path, opts ...options.DagTreeOption) ([]Path, error)

	// Batch creates new DagBatch
	Batch(ctx context.Context) DagBatch
}

DagAPI specifies the interface to IPLD

type DagBatch added in v0.4.18

type DagBatch interface {
	DagOps

	// Commit commits nodes to the datastore and announces them to the network
	Commit(ctx context.Context) error
}

DagBatch is the batching version of DagAPI. All implementations of DagBatch should be threadsafe

type DagOps added in v0.4.18

type DagOps interface {
	// Put inserts data using specified format and input encoding.
	// Unless used with WithCodec or WithHash, the defaults "dag-cbor" and
	// "sha256" are used.
	Put(ctx context.Context, src io.Reader, opts ...options.DagPutOption) (ResolvedPath, error)
}

DagOps groups operations that can be batched together

type DhtAPI added in v0.4.18

type DhtAPI interface {
	// FindPeer queries the DHT for all of the multiaddresses associated with a
	// Peer ID
	FindPeer(context.Context, peer.ID) (pstore.PeerInfo, error)

	// FindProviders finds peers in the DHT who can provide a specific value
	// given a key.
	FindProviders(context.Context, Path, ...options.DhtFindProvidersOption) (<-chan pstore.PeerInfo, error)

	// Provide announces to the network that you are providing given values
	Provide(context.Context, Path, ...options.DhtProvideOption) error
}

DhtAPI specifies the interface to the DHT Note: This API will likely get deprecated in near future, see https://github.com/ipfs/interface-ipfs-core/issues/249 for more context.

type IpnsEntry added in v0.4.14

type IpnsEntry interface {
	// Name returns IpnsEntry name
	Name() string
	// Value returns IpnsEntry value
	Value() Path
}

IpnsEntry specifies the interface to IpnsEntries

type IpnsResult added in v0.4.18

type IpnsResult struct {
	Path
	Err error
}

type Key added in v0.4.14

type Key interface {
	// Key returns key name
	Name() string

	// Path returns key path
	Path() Path

	// ID returns key PeerID
	ID() peer.ID
}

Key specifies the interface to Keys in KeyAPI Keystore

type KeyAPI added in v0.4.14

type KeyAPI interface {
	// Generate generates new key, stores it in the keystore under the specified
	// name and returns a base58 encoded multihash of it's public key
	Generate(ctx context.Context, name string, opts ...options.KeyGenerateOption) (Key, error)

	// Rename renames oldName key to newName. Returns the key and whether another
	// key was overwritten, or an error
	Rename(ctx context.Context, oldName string, newName string, opts ...options.KeyRenameOption) (Key, bool, error)

	// List lists keys stored in keystore
	List(ctx context.Context) ([]Key, error)

	// Self returns the 'main' node key
	Self(ctx context.Context) (Key, error)

	// Remove removes keys from keystore. Returns ipns path of the removed key
	Remove(ctx context.Context, name string) (Key, error)
}

KeyAPI specifies the interface to Keystore

type NameAPI added in v0.4.14

type NameAPI interface {
	// Publish announces new IPNS name
	Publish(ctx context.Context, path Path, opts ...options.NamePublishOption) (IpnsEntry, error)

	// Resolve attempts to resolve the newest version of the specified name
	Resolve(ctx context.Context, name string, opts ...options.NameResolveOption) (Path, error)

	// Search is a version of Resolve which outputs paths as they are discovered,
	// reducing the time to first entry
	//
	// Note: by default, all paths read from the channel are considered unsafe,
	// except the latest (last path in channel read buffer).
	Search(ctx context.Context, name string, opts ...options.NameResolveOption) (<-chan IpnsResult, error)
}

NameAPI specifies the interface to IPNS.

IPNS is a PKI namespace, where names are the hashes of public keys, and the private key enables publishing new (signed) values. In both publish and resolve, the default name used is the node's own PeerID, which is the hash of its public key.

You can use .Key API to list and generate more names and their respective keys.

type ObjectAPI added in v0.4.14

type ObjectAPI interface {
	// New creates new, empty (by default) dag-node.
	New(context.Context, ...options.ObjectNewOption) (ipld.Node, error)

	// Put imports the data into merkledag
	Put(context.Context, io.Reader, ...options.ObjectPutOption) (ResolvedPath, error)

	// Get returns the node for the path
	Get(context.Context, Path) (ipld.Node, error)

	// Data returns reader for data of the node
	Data(context.Context, Path) (io.Reader, error)

	// Links returns lint or links the node contains
	Links(context.Context, Path) ([]*ipld.Link, error)

	// Stat returns information about the node
	Stat(context.Context, Path) (*ObjectStat, error)

	// AddLink adds a link under the specified path. child path can point to a
	// subdirectory within the patent which must be present (can be overridden
	// with WithCreate option).
	AddLink(ctx context.Context, base Path, name string, child Path, opts ...options.ObjectAddLinkOption) (ResolvedPath, error)

	// RmLink removes a link from the node
	RmLink(ctx context.Context, base Path, link string) (ResolvedPath, error)

	// AppendData appends data to the node
	AppendData(context.Context, Path, io.Reader) (ResolvedPath, error)

	// SetData sets the data contained in the node
	SetData(context.Context, Path, io.Reader) (ResolvedPath, error)

	// Diff returns a set of changes needed to transform the first object into the
	// second.
	Diff(context.Context, Path, Path) ([]ObjectChange, error)
}

ObjectAPI specifies the interface to MerkleDAG and contains useful utilities for manipulating MerkleDAG data structures.

type ObjectChange added in v0.4.18

type ObjectChange struct {
	// Type of the change, either:
	// * DiffAdd - Added a link
	// * DiffRemove - Removed a link
	// * DiffMod - Modified a link
	Type ChangeType

	// Path to the changed link
	Path string

	// Before holds the link path before the change. Note that when a link is
	// added, this will be nil.
	Before ResolvedPath

	// After holds the link path after the change. Note that when a link is
	// removed, this will be nil.
	After ResolvedPath
}

ObjectChange represents a change ia a graph

type ObjectStat added in v0.4.14

type ObjectStat struct {
	// Cid is the CID of the node
	Cid cid.Cid

	// NumLinks is number of links the node contains
	NumLinks int

	// BlockSize is size of the raw serialized node
	BlockSize int

	// LinksSize is size of the links block section
	LinksSize int

	// DataSize is the size of data block section
	DataSize int

	// CumulativeSize is size of the tree (BlockSize + link sizes)
	CumulativeSize int
}

ObjectStat provides information about dag nodes

type Path added in v0.4.8

type Path interface {
	// String returns the path as a string.
	String() string

	// Namespace returns the first component of the path.
	//
	// For example path "/ipfs/QmHash", calling Namespace() will return "ipfs"
	Namespace() string

	// Mutable returns false if the data pointed to by this path in guaranteed
	// to not change.
	//
	// Note that resolved mutable path can be immutable.
	Mutable() bool
}

Path is a generic wrapper for paths used in the API. A path can be resolved to a CID using one of Resolve functions in the API.

Paths must be prefixed with a valid prefix:

* /ipfs - Immutable unixfs path (files) * /ipld - Immutable ipld path (data) * /ipns - Mutable names. Usually resolves to one of the immutable paths TODO: /local (MFS)

func ParsePath added in v0.4.17

func ParsePath(p string) (Path, error)

ParsePath parses string path to a Path

type Pin added in v0.4.14

type Pin interface {
	// Path to the pinned object
	Path() ResolvedPath

	// Type of the pin
	Type() string
}

Pin holds information about pinned resource

type PinAPI added in v0.4.14

type PinAPI interface {
	// Add creates new pin, be default recursive - pinning the whole referenced
	// tree
	Add(context.Context, Path, ...options.PinAddOption) error

	// Ls returns list of pinned objects on this node
	Ls(context.Context, ...options.PinLsOption) ([]Pin, error)

	// Rm removes pin for object specified by the path
	Rm(context.Context, Path) error

	// Update changes one pin to another, skipping checks for matching paths in
	// the old tree
	Update(ctx context.Context, from Path, to Path, opts ...options.PinUpdateOption) error

	// Verify verifies the integrity of pinned objects
	Verify(context.Context) (<-chan PinStatus, error)
}

PinAPI specifies the interface to pining

type PinStatus added in v0.4.14

type PinStatus interface {
	// Ok indicates whether the pin has been verified to be correct
	Ok() bool

	// BadNodes returns any bad (usually missing) nodes from the pin
	BadNodes() []BadPinNode
}

PinStatus holds information about pin health

type PubSubAPI added in v0.4.18

type PubSubAPI interface {
	// Ls lists subscribed topics by name
	Ls(context.Context) ([]string, error)

	// Peers list peers we are currently pubsubbing with
	Peers(context.Context, ...options.PubSubPeersOption) ([]peer.ID, error)

	// Publish a message to a given pubsub topic
	Publish(context.Context, string, []byte) error

	// Subscribe to messages on a given topic
	Subscribe(context.Context, string, ...options.PubSubSubscribeOption) (PubSubSubscription, error)
}

PubSubAPI specifies the interface to PubSub

type PubSubMessage added in v0.4.18

type PubSubMessage interface {
	// From returns id of a peer from which the message has arrived
	From() peer.ID

	// Data returns the message body
	Data() []byte

	// Seq returns message identifier
	Seq() []byte

	// Topics returns list of topics this message was set to
	Topics() []string
}

PubSubMessage is a single PubSub message

type PubSubSubscription added in v0.4.18

type PubSubSubscription interface {
	io.Closer

	// Next return the next incoming message
	Next(context.Context) (PubSubMessage, error)
}

PubSubSubscription is an active PubSub subscription

type ReadSeekCloser added in v0.4.18

type ReadSeekCloser interface {
	io.Reader
	io.Seeker
	io.Closer
	io.WriterTo
}

A ReadSeekCloser implements interfaces to read, copy, seek and close.

type Reader

type Reader interface {
	ReadSeekCloser
	Size() uint64
	CtxReadFull(context.Context, []byte) (int, error)
}

type ResolvedPath added in v0.4.17

type ResolvedPath interface {
	// Cid returns the CID of the node referenced by the path. Remainder of the
	// path is guaranteed to be within the node.
	//
	// Examples:
	// If you have 3 linked objects: QmRoot -> A -> B:
	//
	// cidB := {"foo": {"bar": 42 }}
	// cidA := {"B": {"/": cidB }}
	// cidRoot := {"A": {"/": cidA }}
	//
	// And resolve paths:
	// * "/ipfs/${cidRoot}"
	//   * Calling Cid() will return `cidRoot`
	//   * Calling Root() will return `cidRoot`
	//   * Calling Remainder() will return “
	//
	// * "/ipfs/${cidRoot}/A"
	//   * Calling Cid() will return `cidA`
	//   * Calling Root() will return `cidRoot`
	//   * Calling Remainder() will return “
	//
	// * "/ipfs/${cidRoot}/A/B/foo"
	//   * Calling Cid() will return `cidB`
	//   * Calling Root() will return `cidRoot`
	//   * Calling Remainder() will return `foo`
	//
	// * "/ipfs/${cidRoot}/A/B/foo/bar"
	//   * Calling Cid() will return `cidB`
	//   * Calling Root() will return `cidRoot`
	//   * Calling Remainder() will return `foo/bar`
	Cid() cid.Cid

	// Root returns the CID of the root object of the path
	//
	// Example:
	// If you have 3 linked objects: QmRoot -> A -> B, and resolve path
	// "/ipfs/QmRoot/A/B", the Root method will return the CID of object QmRoot
	//
	// For more examples see the documentation of Cid() method
	Root() cid.Cid

	// Remainder returns unresolved part of the path
	//
	// Example:
	// If you have 2 linked objects: QmRoot -> A, where A is a CBOR node
	// containing the following data:
	//
	// {"foo": {"bar": 42 }}
	//
	// When resolving "/ipld/QmRoot/A/foo/bar", Remainder will return "foo/bar"
	//
	// For more examples see the documentation of Cid() method
	Remainder() string

	Path
}

ResolvedPath is a path which was resolved to the last resolvable node

func IpfsPath added in v0.4.17

func IpfsPath(c cid.Cid) ResolvedPath

IpfsPath creates new /ipfs path from the provided CID

func IpldPath added in v0.4.17

func IpldPath(c cid.Cid) ResolvedPath

IpldPath creates new /ipld path from the provided CID

func NewResolvedPath added in v0.4.17

func NewResolvedPath(ipath ipfspath.Path, c cid.Cid, root cid.Cid, remainder string) ResolvedPath

NewResolvedPath creates new ResolvedPath. This function performs no checks and is intended to be used by resolver implementations. Incorrect inputs may cause panics. Handle with care.

type SwarmAPI added in v0.4.18

type SwarmAPI interface {
	// Connect to a given peer
	Connect(context.Context, pstore.PeerInfo) error

	// Disconnect from a given address
	Disconnect(context.Context, ma.Multiaddr) error

	// Peers returns the list of peers we are connected to
	Peers(context.Context) ([]ConnectionInfo, error)

	// KnownAddrs returns the list of all addresses this node is aware of
	KnownAddrs(context.Context) (map[peer.ID][]ma.Multiaddr, error)

	// LocalAddrs returns the list of announced listening addresses
	LocalAddrs(context.Context) ([]ma.Multiaddr, error)

	// ListenAddrs returns the list of all listening addresses
	ListenAddrs(context.Context) ([]ma.Multiaddr, error)
}

SwarmAPI specifies the interface to libp2p swarm

type UnixfsAPI

type UnixfsAPI interface {
	// Add imports the data from the reader into merkledag file
	//
	// TODO: a long useful comment on how to use this for many different scenarios
	Add(context.Context, files.File, ...options.UnixfsAddOption) (ResolvedPath, error)

	// Get returns a read-only handle to a file tree referenced by a path
	//
	// Note that some implementations of this API may apply the specified context
	// to operations performed on the returned file
	Get(context.Context, Path) (UnixfsFile, error)

	// Ls returns the list of links in a directory
	Ls(context.Context, Path) ([]*ipld.Link, error)
}

UnixfsAPI is the basic interface to immutable files in IPFS NOTE: This API is heavily WIP, things are guaranteed to break frequently

type UnixfsFile added in v0.4.18

type UnixfsFile interface {
	files.SizeFile
	io.Seeker
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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