ipfshttp

package
v0.0.0-...-6646f2c Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2019 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package ipfshttp implements an IPFS Cluster IPFSConnector component. It uses the IPFS HTTP API to communicate to IPFS.

Index

Constants

View Source
const (
	DefaultNodeAddr           = "/ip4/127.0.0.1/tcp/5001"
	DefaultConnectSwarmsDelay = 30 * time.Second
	DefaultPinMethod          = "refs"
	DefaultIPFSRequestTimeout = 5 * time.Minute
	DefaultPinTimeout         = 24 * time.Hour
	DefaultUnpinTimeout       = 3 * time.Hour
)

Default values for Config.

Variables

View Source
var DNSTimeout = 5 * time.Second

DNSTimeout is used when resolving DNS multiaddresses in this module

Functions

This section is empty.

Types

type Config

type Config struct {
	config.Saver

	// Host/Port for the IPFS daemon.
	NodeAddr ma.Multiaddr

	// ConnectSwarmsDelay specifies how long to wait after startup before
	// attempting to open connections from this peer's IPFS daemon to the
	// IPFS daemons of other peers.
	ConnectSwarmsDelay time.Duration

	// "pin" or "refs". "pin" uses a "pin/add" call. "refs" uses a
	// "refs -r" call followed by "pin/add". "refs" allows fetching in
	// parallel but should be used with GC disabled.
	PinMethod string

	// IPFS Daemon HTTP Client POST timeout
	IPFSRequestTimeout time.Duration

	// Pin Operation timeout
	PinTimeout time.Duration

	// Unpin Operation timeout
	UnpinTimeout time.Duration
}

Config is used to initialize a Connector and allows to customize its behaviour. It implements the config.ComponentConfig interface.

func (*Config) ConfigKey

func (cfg *Config) ConfigKey() string

ConfigKey provides a human-friendly identifier for this type of Config.

func (*Config) Default

func (cfg *Config) Default() error

Default sets the fields of this Config to sensible default values.

func (*Config) LoadJSON

func (cfg *Config) LoadJSON(raw []byte) error

LoadJSON parses a JSON representation of this Config as generated by ToJSON.

func (*Config) ToJSON

func (cfg *Config) ToJSON() (raw []byte, err error)

ToJSON generates a human-friendly JSON representation of this Config.

func (*Config) Validate

func (cfg *Config) Validate() error

Validate checks that the fields of this Config have sensible values, at least in appearance.

type Connector

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

Connector implements the IPFSConnector interface and provides a component which is used to perform on-demand requests against the configured IPFS daemom (such as a pin request).

func NewConnector

func NewConnector(cfg *Config) (*Connector, error)

NewConnector creates the component and leaves it ready to be started

func (*Connector) BlockGet

func (ipfs *Connector) BlockGet(c cid.Cid) ([]byte, error)

BlockGet retrieves an ipfs block with the given cid

func (*Connector) BlockPut

func (ipfs *Connector) BlockPut(b api.NodeWithMeta) error

BlockPut triggers an ipfs block put on the given data, inserting the block into the ipfs daemon's repo.

func (*Connector) ConfigKey

func (ipfs *Connector) ConfigKey(keypath string) (interface{}, error)

ConfigKey fetches the IPFS daemon configuration and retrieves the value for a given configuration key. For example, "Datastore/StorageMax" will return the value for StorageMax in the Datastore configuration object.

func (*Connector) ConnectSwarms

func (ipfs *Connector) ConnectSwarms() error

ConnectSwarms requests the ipfs addresses of other peers and triggers ipfs swarm connect requests

func (*Connector) FileGet

func (ipfs *Connector) FileGet(fg []string) ([]byte, error)

get file from IPFS service

func (*Connector) FilesCp

func (ipfs *Connector) FilesCp(l []string) error

copy file to Hive

func (*Connector) FilesFlush

func (ipfs *Connector) FilesFlush(l []string) error

file flushs

func (*Connector) FilesLs

func (ipfs *Connector) FilesLs(l []string) (api.FilesLs, error)

list file or directory

func (*Connector) FilesMkdir

func (ipfs *Connector) FilesMkdir(mk []string) error

create a directotry

func (*Connector) FilesMv

func (ipfs *Connector) FilesMv(mv []string) error

move files

func (*Connector) FilesRead

func (ipfs *Connector) FilesRead(l []string) ([]byte, error)

read file

func (*Connector) FilesRm

func (ipfs *Connector) FilesRm(rm []string) error

remove file

func (*Connector) FilesStat

func (ipfs *Connector) FilesStat(st []string) (api.FilesStat, error)

get file statistic

func (*Connector) FilesWrite

func (ipfs *Connector) FilesWrite(fr api.FilesWrite) error

write file

func (*Connector) ID

func (ipfs *Connector) ID() (api.IPFSID, error)

ID performs an ID request against the configured IPFS daemon. It returns the fetched information. If the request fails, or the parsing fails, it returns an error and an empty IPFSID which also contains the error message.

func (*Connector) NamePublish

func (ipfs *Connector) NamePublish(np []string) (api.NamePublish, error)

NamePublish publish ipfs path with uid

func (*Connector) Pin

func (ipfs *Connector) Pin(ctx context.Context, hash cid.Cid, maxDepth int) error

Pin performs a pin request against the configured IPFS daemon.

func (*Connector) PinLs

func (ipfs *Connector) PinLs(ctx context.Context, typeFilter string) (map[string]api.IPFSPinStatus, error)

PinLs performs a "pin ls --type typeFilter" request against the configured IPFS daemon and returns a map of cid strings and their status.

func (*Connector) PinLsCid

func (ipfs *Connector) PinLsCid(ctx context.Context, hash cid.Cid) (api.IPFSPinStatus, error)

PinLsCid performs a "pin ls <hash>" request. It first tries with "type=recursive" and then, if not found, with "type=direct". It returns an api.IPFSPinStatus for that hash.

func (*Connector) RepoStat

func (ipfs *Connector) RepoStat() (api.IPFSRepoStat, error)

RepoStat returns the DiskUsage and StorageMax repo/stat values from the ipfs daemon, in bytes, wrapped as an IPFSRepoStat object.

func (*Connector) SetClient

func (ipfs *Connector) SetClient(c *rpc.Client)

SetClient makes the component ready to perform RPC requests.

func (*Connector) Shutdown

func (ipfs *Connector) Shutdown() error

Shutdown stops any listeners and stops the component from taking any requests.

func (*Connector) SwarmPeers

func (ipfs *Connector) SwarmPeers() (api.SwarmPeers, error)

SwarmPeers returns the peers currently connected to this ipfs daemon.

func (*Connector) UidInfo

func (ipfs *Connector) UidInfo(uid string) (api.UIDSecret, error)

log in Hive cluster and get new id

func (*Connector) UidLogin

func (ipfs *Connector) UidLogin(params []string) error

log in Hive cluster to recreate user home

func (*Connector) UidNew

func (ipfs *Connector) UidNew(name string) (api.UIDSecret, error)

create a virtual id.

func (*Connector) UidRenew

func (ipfs *Connector) UidRenew(l []string) (api.UIDRenew, error)

log in Hive cluster and get new id

func (*Connector) Unpin

func (ipfs *Connector) Unpin(ctx context.Context, hash cid.Cid) error

Unpin performs an unpin request against the configured IPFS daemon.

Jump to

Keyboard shortcuts

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