ipfs

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2020 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package ipfs wraps the ipfs core api with some useful client methods for PubSub and IO.

Index

Constants

View Source
const (
	// DefaultBufferSize is used in the buffered PubSub channels.
	DefaultBufferSize = 42

	// DefaultIenc is the input encoding for the data will be added to the IPFS DAG.
	DefaultIenc = "json"

	// DefaultFormatParser is the format of the input data for IPFS.
	DefaultFormatParser = "cbor"

	// DefaultMhType is the multihash to use for DAG put operations.
	DefaultMhType = uint64(math.MaxUint64) // use default hash (sha256 for cbor, sha1 for git..)
)

Variables

View Source
var (

	// DefaultBootstrappers are nodes used for IPFS peer discovery.
	DefaultBootstrappers = []string{

		"/ip4/138.201.67.219/tcp/4001/p2p/QmUd6zHcbkbcs7SMxwLs48qZVX3vpcM8errYS7xEczwRMA",
		"/ip4/138.201.67.219/udp/4001/quic/p2p/QmUd6zHcbkbcs7SMxwLs48qZVX3vpcM8errYS7xEczwRMA",
		"/ip4/138.201.67.220/tcp/4001/p2p/QmNSYxZAiJHeLdkBg38roksAR9So7Y5eojks1yjEcUtZ7i",
		"/ip4/138.201.67.220/udp/4001/quic/p2p/QmNSYxZAiJHeLdkBg38roksAR9So7Y5eojks1yjEcUtZ7i",
		"/ip4/138.201.68.74/tcp/4001/p2p/QmdnXwLrC8p1ueiq2Qya8joNvk3TVVDAut7PrikmZwubtR",
		"/ip4/138.201.68.74/udp/4001/quic/p2p/QmdnXwLrC8p1ueiq2Qya8joNvk3TVVDAut7PrikmZwubtR",
		"/ip4/94.130.135.167/tcp/4001/p2p/QmUEMvxS2e7iDrereVYc5SWPauXPyNwxcy9BXZrC1QTcHE",
		"/ip4/94.130.135.167/udp/4001/quic/p2p/QmUEMvxS2e7iDrereVYc5SWPauXPyNwxcy9BXZrC1QTcHE",
	}

	// ErrRepoAlreadyInitialised is issued when an IPFS repo has already been initialised.
	ErrRepoAlreadyInitialised = fmt.Errorf("specified IPFS repo is already initialised")

	// ErrNoLinks is issued when no links are found in an IPFS DAG node.
	ErrNoLinks = fmt.Errorf("no links found in IPFS DAG node")

	// ErrOffline indicates node is offline.
	ErrOffline = fmt.Errorf("the IPFS node is offline")
)

Functions

This section is empty.

Types

type Client

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

Client is a wrapper that groups and controls access to the IPFS for the starkDB.

func NewIPFSclient

func NewIPFSclient(ctx context.Context) (*Client, error)

NewIPFSclient will initialise the IPFS client.

The IPFS code used in starkDB is based on the IPFS as a library example (go-ipfs v0.5.0)

Note: if no repoPath provided, this function will attempt to use the IPFS default repo path.

func (*Client) AddFile

func (client *Client) AddFile(ctx context.Context, filePath string, pinning bool) (string, error)

AddFile will add a file (or directory) to the IPFS and return the CID.

func (client *Client) AddLink(ctx context.Context, baseCID, childCID, linkLabel string) (string, error)

AddLink will add a link under the specified path. Child path can point to a subdirectory within the patent, it will be created if not present. It will return the new base CID and any error.

func (*Client) Connect

func (client *Client) Connect(ctx context.Context, peers []string, logger chan interface{})

Connect will connect the client to peers. It is adapted from https://github.com/ipfs/go-ipfs/tree/master/docs/examples/go-ipfs-as-a-library

func (*Client) DagGet

func (client *Client) DagGet(ctx context.Context, queryCID string) (interface{}, error)

DagGet will fetch a DAG node from the IPFS using the provided CID.

func (*Client) DagPut

func (client *Client) DagPut(ctx context.Context, data []byte, pinning bool) (string, error)

DagPut will append to an IPFS dag.

func (*Client) EndSession

func (client *Client) EndSession() error

EndSession closes down the client.

func (*Client) GetFile

func (client *Client) GetFile(ctx context.Context, cidStr, outputPath string) error

GetFile will get a file (or directory) from the IPFS using the supplied CID and then write it to the supplied outputPath.

func (*Client) GetNodeData

func (client *Client) GetNodeData(ctx context.Context, nodeCID string) (io.Reader, error)

GetNodeData will output a reader for the raw bytes contained in an IPFS DAG node.

func (client *Client) GetNodeLinks(ctx context.Context, nodeCID string) ([]*ipld.Link, error)

GetNodeLinks returns the links from a node.

func (*Client) GetPSEchan

func (client *Client) GetPSEchan() chan error

GetPSEchan gives access to the PubSub errors channel.

func (*Client) GetPSMchan

func (client *Client) GetPSMchan() chan icore.PubSubMessage

GetPSMchan gives access to the PubSub messages channel.

func (*Client) GetPeers

func (client *Client) GetPeers(ctx context.Context) ([]string, error)

GetPeers will return currently connected peers.

func (*Client) GetPublicIPv4Addr

func (client *Client) GetPublicIPv4Addr() (string, error)

GetPublicIPv4Addr uses the host addresses to return the public ipv4 address of the host machine, if available.

func (*Client) NewDagNode

func (client *Client) NewDagNode(ctx context.Context) (string, error)

NewDagNode will create a new UNIXFS formatted DAG node in the IPFS.

func (*Client) Online

func (client *Client) Online() bool

Online will return true if the node is online.

func (*Client) PrintNodeID

func (client *Client) PrintNodeID() string

PrintNodeID will print the node's identity.

func (client *Client) RmLink(ctx context.Context, baseCID, linkLabel string) (string, error)

RmLink will remove a link under the specified path. It will return the new base CID and any error.

func (*Client) SendMessage

func (client *Client) SendMessage(ctx context.Context, topic string, message []byte) error

SendMessage will broadcast a message via PubSub.

func (*Client) Subscribe

func (client *Client) Subscribe(ctx context.Context, topic string) error

Subscribe will start a Client's PubSub subscription for the provided topic.

Note: see https://blog.ipfs.io/25-pubsub/ for good intro on PubSub

func (*Client) Unpin

func (client *Client) Unpin(ctx context.Context, cidStr string) error

Unpin will unpin a CID from the IPFS.

func (*Client) Unsubscribe

func (client *Client) Unsubscribe() error

Unsubscribe will stop a Client's active PubSub subscription.

Jump to

Keyboard shortcuts

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