ipfs

package
v1.2.3-rc2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 43 Imported by: 1

Documentation

Index

Constants

View Source
const MagicInternalIPFSAddress = "memory://in-memory-node/"
View Source
const (

	// PvtIpfsFolderPerm is what permissions we give to a private ipfs repo
	PvtIpfsFolderPerm = 0755
)

Variables

This section is empty.

Functions

func AddFileToNodes

func AddFileToNodes(ctx context.Context, filePath string, clients ...Client) (string, error)

func AddTextToNodes

func AddTextToNodes(ctx context.Context, fileContent []byte, clients ...Client) (string, error)

func ParsePeersString

func ParsePeersString(peers []string) ([]peer.AddrInfo, error)

Types

type Client

type Client struct {
	API icore.CoreAPI
	// contains filtered or unexported fields
}

Client is a front-end for an ipfs node's API endpoints. You can create Client instances manually by connecting to an ipfs node's API multiaddr using NewClientUsingRemoteHandler, or automatically from an active Node instance using NewClient.

func NewClient

func NewClient(api icore.CoreAPI) Client

func NewClientUsingRemoteHandler

func NewClientUsingRemoteHandler(ctx context.Context, apiAddr string) (Client, error)

NewClientUsingRemoteHandler creates an API client for the given ipfs node API multiaddress. NOTE: the API address is _not_ the same as the swarm address

func (Client) APIAddress

func (cl Client) APIAddress() string

APIAddress returns Api address that was used to connect to the node.

func (Client) Get

func (cl Client) Get(ctx context.Context, cid, outputPath string) error

Get fetches a file or directory from the ipfs network.

func (Client) GetCidSize

func (cl Client) GetCidSize(ctx context.Context, cid string) (uint64, error)

func (Client) GetTreeNode

func (cl Client) GetTreeNode(ctx context.Context, cid string) (IPLDTreeNode, error)

func (Client) HasCID

func (cl Client) HasCID(ctx context.Context, cid string) (bool, error)

HasCID returns true if the node has the given CID locally, whether pinned or not.

func (Client) ID

func (cl Client) ID(ctx context.Context) (string, error)

ID returns the node's ipfs ID.

func (Client) Put

func (cl Client) Put(ctx context.Context, inputPath string) (string, error)

Put uploads and pins a file or directory to the ipfs network. Timeouts and cancellation should be handled by passing an appropriate context value.

func (Client) Stat

func (cl Client) Stat(ctx context.Context, cid string) (*StatResult, error)

Stat returns information about an IPLD CID on the ipfs network.

func (Client) SwarmAddresses

func (cl Client) SwarmAddresses(ctx context.Context) ([]string, error)

SwarmAddresses returns a list of swarm addresses the node has announced.

func (Client) SwarmConnect added in v1.1.0

func (cl Client) SwarmConnect(ctx context.Context, peers []peer.AddrInfo)

SwarmConnect establishes concurrent connections to each peer from the provided `peers` list. It spawns a goroutine for each peer connection. In the event of a connection failure, a warning log containing the error and peer details is generated.

func (Client) SwarmMultiAddresses

func (cl Client) SwarmMultiAddresses(ctx context.Context) ([]ma.Multiaddr, error)

type IPLDTreeNode

type IPLDTreeNode struct {
	Cid      cid.Cid
	Path     []string
	Children []IPLDTreeNode
}

func FlattenTreeNode

func FlattenTreeNode(ctx context.Context, rootNode IPLDTreeNode) ([]IPLDTreeNode, error)

type IPLDType

type IPLDType int
const (
	IPLDUnknown IPLDType = iota
	IPLDFile
	IPLDDirectory
)

type Node

type Node struct {

	// RepoPath is the path to the ipfs node's data repository.
	RepoPath string

	// APIPort is the port that the node's ipfs API is listening on.
	APIPort int
	// contains filtered or unexported fields
}

Node is a wrapper around an in-process IPFS node that can be used to interact with the IPFS network without requiring an `ipfs` binary.

func NewNodeWithConfig added in v1.0.4

func NewNodeWithConfig(ctx context.Context, cm *system.CleanupManager, cfg types.IpfsConfig) (*Node, error)

NewNodeWithConfig creates a new in-process IPFS node with the given configuration.

func (*Node) Client

func (n *Node) Client() Client

Client returns an API client for interacting with the node.

func (*Node) Close

func (n *Node) Close(ctx context.Context) error

func (*Node) ID

func (n *Node) ID() string

ID returns the node's ipfs ID.

func (*Node) LogDetails

func (n *Node) LogDetails()

LogDetails logs connection details for the node's swarm and API servers.

func (*Node) SwarmAddresses

func (n *Node) SwarmAddresses() ([]string, error)

SwarmAddresses returns the node's swarm addresses.

type StatResult

type StatResult struct {
	Type IPLDType
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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