Documentation ¶
Overview ¶
Package ipfshttp implements an IPFS Cluster IPFSConnector component. It uses the IPFS HTTP API to communicate to IPFS.
Index ¶
- Constants
- type Config
- type Connector
- func (ipfs *Connector) ConfigKey(keypath string) (interface{}, error)
- func (ipfs *Connector) ConnectSwarms() error
- func (ipfs *Connector) FreeSpace() (uint64, error)
- func (ipfs *Connector) ID() (api.IPFSID, error)
- func (ipfs *Connector) Pin(ctx context.Context, hash *cid.Cid, recursive bool) error
- func (ipfs *Connector) PinLs(ctx context.Context, typeFilter string) (map[string]api.IPFSPinStatus, error)
- func (ipfs *Connector) PinLsCid(ctx context.Context, hash *cid.Cid) (api.IPFSPinStatus, error)
- func (ipfs *Connector) RepoSize() (uint64, error)
- func (ipfs *Connector) SetClient(c *rpc.Client)
- func (ipfs *Connector) Shutdown() error
- func (ipfs *Connector) SwarmPeers() (api.SwarmPeers, error)
- func (ipfs *Connector) Unpin(ctx context.Context, hash *cid.Cid) error
Constants ¶
const ( DefaultProxyAddr = "/ip4/127.0.0.1/tcp/9095" DefaultNodeAddr = "/ip4/127.0.0.1/tcp/5001" DefaultConnectSwarmsDelay = 30 * time.Second DefaultProxyReadTimeout = 10 * time.Minute DefaultProxyReadHeaderTimeout = 5 * time.Second DefaultProxyWriteTimeout = 10 * time.Minute DefaultProxyIdleTimeout = 60 * time.Second DefaultPinMethod = "refs" DefaultIPFSRequestTimeout = 5 * time.Minute DefaultPinTimeout = 24 * time.Hour DefaultUnpinTimeout = 3 * time.Hour )
Default values for Config.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶ added in v0.2.0
type Config struct { config.Saver // Listen parameters for the IPFS Proxy. Used by the IPFS // connector component. ProxyAddr ma.Multiaddr // 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 // Maximum duration before timing out reading a full request ProxyReadTimeout time.Duration // Maximum duration before timing out reading the headers of a request ProxyReadHeaderTimeout time.Duration // Maximum duration before timing out write of the response ProxyWriteTimeout time.Duration // Server-side amount of time a Keep-Alive connection will be // kept idle before being reused ProxyIdleTimeout 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 ¶ added in v0.2.0
ConfigKey provides a human-friendly identifier for this type of Config.
func (*Config) Default ¶ added in v0.2.0
Default sets the fields of this Config to sensible default values.
func (*Config) LoadJSON ¶ added in v0.2.0
LoadJSON parses a JSON representation of this Config as generated by ToJSON.
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
Connector implements the IPFSConnector interface and provides a component which does two tasks:
On one side, it proxies HTTP requests to the configured IPFS daemon. It is able to intercept these requests though, and perform extra operations on them.
On the other side, it is used to perform on-demand requests against the configured IPFS daemom (such as a pin request).
func NewConnector ¶
NewConnector creates the component and leaves it ready to be started
func (*Connector) ConfigKey ¶
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 ¶
ConnectSwarms requests the ipfs addresses of other peers and triggers ipfs swarm connect requests
func (*Connector) FreeSpace ¶ added in v0.2.0
FreeSpace returns the amount of unused space in the ipfs repository. This value is derived from the RepoSize and StorageMax values given by "repo stats". The value is in bytes.
func (*Connector) ID ¶
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) 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 ¶
PinLsCid performs a "pin ls --type=recursive <hash> "request and returns an api.IPFSPinStatus for that hash.
func (*Connector) RepoSize ¶
RepoSize returns the current repository size of the ipfs daemon as provided by "repo stats". The value is in bytes.
func (*Connector) Shutdown ¶
Shutdown stops any listeners and stops the component from taking any requests.
func (*Connector) SwarmPeers ¶ added in v0.3.3
func (ipfs *Connector) SwarmPeers() (api.SwarmPeers, error)
SwarmPeers returns the peers currently connected to this ipfs daemon