rpc

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 48 Imported by: 30

README

coreiface.CoreAPI over http rpc

IPFS CoreAPI implementation using HTTP API

This packages implements coreiface.CoreAPI over the HTTP API.

Documentation

https://pkg.go.dev/github.com/ipfs/kubo/client/rpc

Example

Pin file on your local IPFS node based on its CID:

package main

import (
    "context"
    "fmt"

    "github.com/ipfs/kubo/client/rpc"
    path "github.com/ipfs/boxo/coreiface/path"
)

func main() {
    // "Connect" to local node
    node, err := rpc.NewLocalApi()
    if err != nil {
        fmt.Printf(err)
        return
    }
    // Pin a given file by its CID
    ctx := context.Background()
    cid := "bafkreidtuosuw37f5xmn65b3ksdiikajy7pwjjslzj2lxxz2vc4wdy3zku"
    p := path.New(cid)
    err = node.Pin().Add(ctx, p)
    if err != nil {
    	fmt.Printf(err)
        return
    }
    return
}

Documentation

Index

Constants

View Source
const (
	DefaultPathName = ".ipfs"
	DefaultPathRoot = "~/" + DefaultPathName
	DefaultApiFile  = "api"
	EnvDir          = "IPFS_PATH"
)

Variables

View Source
var ErrApiNotFound = errors.New("ipfs api address could not be found")

ErrApiNotFound if we fail to find a running daemon.

Functions

func ApiAddr

func ApiAddr(ipfspath string) (ma.Multiaddr, error)

ApiAddr reads api file in specified ipfs path.

Types

type BlockAPI

type BlockAPI HttpApi

func (*BlockAPI) Get

func (api *BlockAPI) Get(ctx context.Context, p path.Path) (io.Reader, error)

func (*BlockAPI) Put

func (api *BlockAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.BlockPutOption) (iface.BlockStat, error)

func (*BlockAPI) Rm

func (api *BlockAPI) Rm(ctx context.Context, p path.Path, opts ...caopts.BlockRmOption) error

func (*BlockAPI) Stat

func (api *BlockAPI) Stat(ctx context.Context, p path.Path) (iface.BlockStat, error)

type Error

type Error = cmds.Error

type HttpApi

type HttpApi struct {
	Headers http.Header
	// contains filtered or unexported fields
}

HttpApi implements github.com/ipfs/interface-go-ipfs-core/CoreAPI using IPFS HTTP API.

For interface docs see https://godoc.org/github.com/ipfs/interface-go-ipfs-core#CoreAPI

func NewApi

func NewApi(a ma.Multiaddr) (*HttpApi, error)

NewApi constructs HttpApi with specified endpoint.

func NewApiWithClient

func NewApiWithClient(a ma.Multiaddr, c *http.Client) (*HttpApi, error)

NewApiWithClient constructs HttpApi with specified endpoint and custom http client.

func NewLocalApi

func NewLocalApi() (*HttpApi, error)

NewLocalApi tries to construct new HttpApi instance communicating with local IPFS daemon

Daemon api address is pulled from the $IPFS_PATH/api file. If $IPFS_PATH env var is not present, it defaults to ~/.ipfs.

func NewPathApi

func NewPathApi(ipfspath string) (*HttpApi, error)

NewPathApi constructs new HttpApi by pulling api address from specified ipfspath. Api file should be located at $ipfspath/api.

func NewURLApiWithClient

func NewURLApiWithClient(url string, c *http.Client) (*HttpApi, error)

func (*HttpApi) Block

func (api *HttpApi) Block() iface.BlockAPI

func (*HttpApi) Dag

func (api *HttpApi) Dag() iface.APIDagService

func (*HttpApi) Key

func (api *HttpApi) Key() iface.KeyAPI

func (*HttpApi) Name

func (api *HttpApi) Name() iface.NameAPI

func (*HttpApi) Object

func (api *HttpApi) Object() iface.ObjectAPI

func (*HttpApi) Pin

func (api *HttpApi) Pin() iface.PinAPI

func (*HttpApi) PubSub

func (api *HttpApi) PubSub() iface.PubSubAPI

func (*HttpApi) Request

func (api *HttpApi) Request(command string, args ...string) RequestBuilder

func (*HttpApi) ResolveNode

func (api *HttpApi) ResolveNode(ctx context.Context, p path.Path) (ipld.Node, error)

func (*HttpApi) ResolvePath

func (api *HttpApi) ResolvePath(ctx context.Context, p path.Path) (path.ImmutablePath, []string, error)

func (*HttpApi) Routing

func (api *HttpApi) Routing() iface.RoutingAPI

func (*HttpApi) Swarm

func (api *HttpApi) Swarm() iface.SwarmAPI

func (*HttpApi) Unixfs

func (api *HttpApi) Unixfs() iface.UnixfsAPI

func (*HttpApi) WithOptions

func (api *HttpApi) WithOptions(opts ...caopts.ApiOption) (iface.CoreAPI, error)

type HttpDagServ

type HttpDagServ httpNodeAdder

func (*HttpDagServ) Add

func (api *HttpDagServ) Add(ctx context.Context, nd format.Node) error

func (*HttpDagServ) AddMany

func (api *HttpDagServ) AddMany(ctx context.Context, nds []format.Node) error

func (*HttpDagServ) Get

func (api *HttpDagServ) Get(ctx context.Context, c cid.Cid) (format.Node, error)

func (*HttpDagServ) GetMany

func (api *HttpDagServ) GetMany(ctx context.Context, cids []cid.Cid) <-chan *format.NodeOption

func (*HttpDagServ) Pinning

func (api *HttpDagServ) Pinning() format.NodeAdder

func (*HttpDagServ) Remove

func (api *HttpDagServ) Remove(ctx context.Context, c cid.Cid) error

func (*HttpDagServ) RemoveMany

func (api *HttpDagServ) RemoveMany(ctx context.Context, cids []cid.Cid) error

type KeyAPI

type KeyAPI HttpApi

func (*KeyAPI) Generate

func (api *KeyAPI) Generate(ctx context.Context, name string, opts ...caopts.KeyGenerateOption) (iface.Key, error)

func (*KeyAPI) List

func (api *KeyAPI) List(ctx context.Context) ([]iface.Key, error)

func (*KeyAPI) Remove

func (api *KeyAPI) Remove(ctx context.Context, name string) (iface.Key, error)

func (*KeyAPI) Rename

func (api *KeyAPI) Rename(ctx context.Context, oldName string, newName string, opts ...caopts.KeyRenameOption) (iface.Key, bool, error)

func (*KeyAPI) Self

func (api *KeyAPI) Self(ctx context.Context) (iface.Key, error)

func (*KeyAPI) Sign added in v0.25.0

func (api *KeyAPI) Sign(ctx context.Context, name string, data []byte) (iface.Key, []byte, error)

func (*KeyAPI) Verify added in v0.25.0

func (api *KeyAPI) Verify(ctx context.Context, keyOrName string, signature, data []byte) (iface.Key, bool, error)

type NameAPI

type NameAPI HttpApi

func (*NameAPI) Publish

func (api *NameAPI) Publish(ctx context.Context, p path.Path, opts ...caopts.NamePublishOption) (ipns.Name, error)

func (*NameAPI) Resolve

func (api *NameAPI) Resolve(ctx context.Context, name string, opts ...caopts.NameResolveOption) (path.Path, error)

func (*NameAPI) Search

func (api *NameAPI) Search(ctx context.Context, name string, opts ...caopts.NameResolveOption) (<-chan iface.IpnsResult, error)

type ObjectAPI

type ObjectAPI HttpApi
func (api *ObjectAPI) AddLink(ctx context.Context, base path.Path, name string, child path.Path, opts ...caopts.ObjectAddLinkOption) (path.ImmutablePath, error)

func (*ObjectAPI) Diff

func (api *ObjectAPI) Diff(ctx context.Context, a path.Path, b path.Path) ([]iface.ObjectChange, error)
func (api *ObjectAPI) RmLink(ctx context.Context, base path.Path, link string) (path.ImmutablePath, error)

type PinAPI

type PinAPI HttpApi

func (*PinAPI) Add

func (api *PinAPI) Add(ctx context.Context, p path.Path, opts ...caopts.PinAddOption) error

func (*PinAPI) IsPinned

func (api *PinAPI) IsPinned(ctx context.Context, p path.Path, opts ...caopts.PinIsPinnedOption) (string, bool, error)

IsPinned returns whether or not the given cid is pinned and an explanation of why its pinned.

func (*PinAPI) Ls

func (api *PinAPI) Ls(ctx context.Context, opts ...caopts.PinLsOption) (<-chan iface.Pin, error)

func (*PinAPI) Rm

func (api *PinAPI) Rm(ctx context.Context, p path.Path, opts ...caopts.PinRmOption) error

func (*PinAPI) Update

func (api *PinAPI) Update(ctx context.Context, from path.Path, to path.Path, opts ...caopts.PinUpdateOption) error

func (*PinAPI) Verify

func (api *PinAPI) Verify(ctx context.Context) (<-chan iface.PinStatus, error)

type PubsubAPI

type PubsubAPI HttpApi

func (*PubsubAPI) Ls

func (api *PubsubAPI) Ls(ctx context.Context) ([]string, error)

func (*PubsubAPI) Peers

func (api *PubsubAPI) Peers(ctx context.Context, opts ...caopts.PubSubPeersOption) ([]peer.ID, error)

func (*PubsubAPI) Publish

func (api *PubsubAPI) Publish(ctx context.Context, topic string, message []byte) error

func (*PubsubAPI) Subscribe

func (api *PubsubAPI) Subscribe(ctx context.Context, topic string, opts ...caopts.PubSubSubscribeOption) (iface.PubSubSubscription, error)

type Request

type Request struct {
	Ctx     context.Context
	ApiBase string
	Command string
	Args    []string
	Opts    map[string]string
	Body    io.Reader
	Headers map[string]string
}

func NewRequest

func NewRequest(ctx context.Context, url, command string, args ...string) *Request

func (*Request) Send

func (r *Request) Send(c *http.Client) (*Response, error)

type RequestBuilder

type RequestBuilder interface {
	Arguments(args ...string) RequestBuilder
	BodyString(body string) RequestBuilder
	BodyBytes(body []byte) RequestBuilder
	Body(body io.Reader) RequestBuilder
	FileBody(body io.Reader) RequestBuilder
	Option(key string, value interface{}) RequestBuilder
	Header(name, value string) RequestBuilder
	Send(ctx context.Context) (*Response, error)
	Exec(ctx context.Context, res interface{}) error
}

type Response

type Response struct {
	Output io.ReadCloser
	Error  *Error
}

func (*Response) Cancel

func (r *Response) Cancel() error

Cancel aborts running request (without draining request body).

func (*Response) Close

func (r *Response) Close() error

type RoutingAPI

type RoutingAPI HttpApi

func (*RoutingAPI) FindPeer added in v0.27.0

func (api *RoutingAPI) FindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo, error)

func (*RoutingAPI) FindProviders added in v0.27.0

func (api *RoutingAPI) FindProviders(ctx context.Context, p path.Path, opts ...options.RoutingFindProvidersOption) (<-chan peer.AddrInfo, error)

func (*RoutingAPI) Get

func (api *RoutingAPI) Get(ctx context.Context, key string) ([]byte, error)

func (*RoutingAPI) Provide added in v0.27.0

func (api *RoutingAPI) Provide(ctx context.Context, p path.Path, opts ...options.RoutingProvideOption) error

func (*RoutingAPI) Put

func (api *RoutingAPI) Put(ctx context.Context, key string, value []byte, opts ...options.RoutingPutOption) error

type SwarmAPI

type SwarmAPI HttpApi

func (*SwarmAPI) Connect

func (api *SwarmAPI) Connect(ctx context.Context, pi peer.AddrInfo) error

func (*SwarmAPI) Disconnect

func (api *SwarmAPI) Disconnect(ctx context.Context, addr multiaddr.Multiaddr) error

func (*SwarmAPI) KnownAddrs

func (api *SwarmAPI) KnownAddrs(ctx context.Context) (map[peer.ID][]multiaddr.Multiaddr, error)

func (*SwarmAPI) ListenAddrs

func (api *SwarmAPI) ListenAddrs(ctx context.Context) ([]multiaddr.Multiaddr, error)

func (*SwarmAPI) LocalAddrs

func (api *SwarmAPI) LocalAddrs(ctx context.Context) ([]multiaddr.Multiaddr, error)

func (*SwarmAPI) Peers

func (api *SwarmAPI) Peers(ctx context.Context) ([]iface.ConnectionInfo, error)

type UnixfsAPI

type UnixfsAPI HttpApi

func (*UnixfsAPI) Add

func (*UnixfsAPI) Get

func (api *UnixfsAPI) Get(ctx context.Context, p path.Path) (files.Node, error)

func (*UnixfsAPI) Ls

func (api *UnixfsAPI) Ls(ctx context.Context, p path.Path, opts ...caopts.UnixfsLsOption) (<-chan iface.DirEntry, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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