ipfs

package
v0.0.0-...-4e740ad Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(rpcAddr string) (*rpc.HttpApi, error)

NewClient creates a new IPFS RPC client using the provided RPC address.

Types

type Client

type Client interface {
	NodeInfo(ctx context.Context, peerID string) (NodeInfo, error)
	Ping(ctx context.Context, peerID string) ([]PingInfo, error)
	Add(ctx context.Context, fileName, filePath string) (string, string, error)
	DownloadFile(ctx context.Context, cid string) ([]byte, error)
	ListConnectedNodes(ctx context.Context) ([]Node, error)
	ListPins(ctx context.Context) (any, error)
	PinObject(ctx context.Context, name, objectPath string) error
	DeleteFile(ctx context.Context, objectPath string) error
	DisplayFileContent(ctx context.Context, filePath string) (string, error)
	DownloadDir(ctx context.Context, cid string, outputPath string) error
	ListDir(ctx context.Context, dirPath string) ([]DirFileDetail, error)
}

Client is an interface that provides methods for interacting with an IPFS node.

func NewClientImpl

func NewClientImpl(rpc *rpc.HttpApi) Client

NewClientImpl creates a new IPFS client implementation.

type ClientImpl

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

ClientImpl is the implementation of the IPFS client.

func (*ClientImpl) Add

func (c *ClientImpl) Add(ctx context.Context, fileName, filePath string) (string, string, error)

Add adds a file or directory to IPFS and returns the immutable path and root CID of the added object.

func (*ClientImpl) DeleteFile

func (c *ClientImpl) DeleteFile(ctx context.Context, objectPath string) error

DeleteFile unpins the IPFS object at the given path and then performs a garbage collection to remove the unpinned object.

func (*ClientImpl) DisplayFileContent

func (c *ClientImpl) DisplayFileContent(ctx context.Context, filePath string) (string, error)

DisplayFileContent returns the contents of the file at the given path as a string. If the path is empty, it returns an error.

func (*ClientImpl) DownloadDir

func (c *ClientImpl) DownloadDir(ctx context.Context, cid string, outputPath string) error

DownloadDir retrieves the IPFS object (directory) at the given CID and writes it to the specified output path.

func (*ClientImpl) DownloadFile

func (c *ClientImpl) DownloadFile(ctx context.Context, cid string) ([]byte, error)

DownloadFile downloads the IPFS object with the given CID and returns its contents as a byte slice. If the object is not a file, an error is returned.

func (*ClientImpl) ListConnectedNodes

func (c *ClientImpl) ListConnectedNodes(ctx context.Context) ([]Node, error)

ListConnectedNodes returns a list of all the nodes that the current IPFS node is connected to. For each node, the function returns the node ID, address, connection direction, and latency.

func (*ClientImpl) ListDir

func (c *ClientImpl) ListDir(ctx context.Context, dirPath string) ([]DirFileDetail, error)

ListDir returns a list of all the files and directories in the specified directory path. For each file/directory, the function returns the name, CID, size, and type.

func (*ClientImpl) ListPins

func (c *ClientImpl) ListPins(ctx context.Context) (any, error)

ListPins returns a list of all the IPFS objects that are currently pinned.

func (*ClientImpl) NodeInfo

func (c *ClientImpl) NodeInfo(ctx context.Context, peerID string) (NodeInfo, error)

NodeInfo returns information about the local IPFS node, including its addresses, agent version, ID, supported protocols, and public key.

func (*ClientImpl) PinObject

func (c *ClientImpl) PinObject(ctx context.Context, name, objectPath string) error

PinObject pins the IPFS object at the given path, ensuring that it is not garbage collected.

func (*ClientImpl) Ping

func (c *ClientImpl) Ping(ctx context.Context, peerID string) ([]PingInfo, error)

Ping sends a ping request to the IPFS peer with the given ID and returns the ping response, which includes information about the success, text, and duration of the ping.

type DirFileDetail

type DirFileDetail struct {
	Name string  `json:"name"` // the name of the file or directory.
	Cid  cid.Cid `json:"cid"`  // the CID of the file or directory.

	Size uint64         `json:"size"` // the size of the file in bytes (or the size of the symlink).
	Type iface.FileType `json:"type"` // the type of the file.
}

DirFileDetail represents details about a file or directory in IPFS.

type Node

type Node struct {
	ID        string `json:"id"`        // the ID of the node.
	Address   string `json:"address"`   // the address of the node.
	Direction string `json:"direction"` // the direction of the connection (inbound or outbound).
	Latency   int64  `json:"latency"`   // the latency of the connection to the node.
}

Node represents an IPFS node.

type NodeInfo

type NodeInfo struct {
	Addresses    []string `json:"addresses"`    // the addresses of the node.
	AgentVersion string   `json:"AgentVersion"` // the version of the IPFS agent.
	ID           string   `json:"id"`           // the ID of the node.
	Protocols    []string `json:"protocols"`    // the protocols supported by the node.
	PublicKey    string   `json:"PublicKey"`    // the public key of the node.
}

NodeInfo contains information about an IPFS node. TODO: look into 'AgentVersion' and 'PublicKey' fields

type PingInfo

type PingInfo struct {
	Success bool          `json:"success"` // whether the ping was successful.
	Text    string        `json:"text"`    // the text output of the ping.
	Time    time.Duration `json:"time"`    // the duration of the ping.
}

PingInfo contains the result of an IPFS ping operation.

Jump to

Keyboard shortcuts

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