ipfs

package
v0.90.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddResponse

type AddResponse struct {
	Name string `json:"name"`
	Cid  string `json:"cid"`
	Size int64  `json:"size"`
}

AddResponse represents the response from adding content to IPFS

type Client

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

Client wraps an IPFS Cluster HTTP API client for storage operations

func NewClient

func NewClient(cfg Config, logger *zap.Logger) (*Client, error)

NewClient creates a new IPFS Cluster client wrapper

func (*Client) Add

func (c *Client) Add(ctx context.Context, reader io.Reader, name string) (*AddResponse, error)

Add adds content to IPFS and returns the CID

func (*Client) Close

func (c *Client) Close(ctx context.Context) error

Close closes the IPFS client connection

func (*Client) Get

func (c *Client) Get(ctx context.Context, cid string, ipfsAPIURL string) (io.ReadCloser, error)

Get retrieves content from IPFS by CID Note: This uses the IPFS HTTP API (typically on port 5001), not the Cluster API

func (*Client) GetPeerCount

func (c *Client) GetPeerCount(ctx context.Context) (int, error)

GetPeerCount returns the number of cluster peers

func (*Client) Health

func (c *Client) Health(ctx context.Context) error

Health checks if the IPFS Cluster API is healthy

func (*Client) Pin

func (c *Client) Pin(ctx context.Context, cid string, name string, replicationFactor int) (*PinResponse, error)

Pin pins a CID with specified replication factor IPFS Cluster expects pin options (including name) as query parameters, not in JSON body

func (*Client) PinStatus

func (c *Client) PinStatus(ctx context.Context, cid string) (*PinStatus, error)

PinStatus retrieves the status of a pinned CID

func (*Client) Unpin

func (c *Client) Unpin(ctx context.Context, cid string) error

Unpin removes a pin from a CID

type ClusterConfigManager

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

ClusterConfigManager manages IPFS Cluster configuration files

func NewClusterConfigManager

func NewClusterConfigManager(cfg *config.Config, logger *zap.Logger) (*ClusterConfigManager, error)

NewClusterConfigManager creates a new IPFS Cluster config manager

func (*ClusterConfigManager) DiscoverClusterPeersFromGateway added in v0.72.0

func (cm *ClusterConfigManager) DiscoverClusterPeersFromGateway() ([]ClusterPeerInfo, error)

DiscoverClusterPeersFromGateway queries the central gateway for registered IPFS Cluster peers

func (*ClusterConfigManager) DiscoverClusterPeersFromLibP2P

func (cm *ClusterConfigManager) DiscoverClusterPeersFromLibP2P(h host.Host) error

DiscoverClusterPeersFromLibP2P uses libp2p host to find other cluster peers

func (*ClusterConfigManager) EnsureConfig

func (cm *ClusterConfigManager) EnsureConfig() error

EnsureConfig ensures the IPFS Cluster service.json exists and is properly configured

func (*ClusterConfigManager) FixIPFSConfigAddresses

func (cm *ClusterConfigManager) FixIPFSConfigAddresses() error

FixIPFSConfigAddresses fixes localhost addresses in IPFS config

func (*ClusterConfigManager) RepairPeerConfiguration added in v0.72.0

func (cm *ClusterConfigManager) RepairPeerConfiguration() error

RepairPeerConfiguration attempts to fix configuration issues and re-synchronize peers

func (*ClusterConfigManager) UpdateAllClusterPeers

func (cm *ClusterConfigManager) UpdateAllClusterPeers() error

UpdateAllClusterPeers discovers all cluster peers from the gateway and updates local config

func (*ClusterConfigManager) UpdatePeerAddresses added in v0.72.0

func (cm *ClusterConfigManager) UpdatePeerAddresses(addrs []string) error

UpdatePeerAddresses updates the peer_addresses in service.json with given multiaddresses

type ClusterPeerInfo added in v0.90.0

type ClusterPeerInfo struct {
	ID           string    `json:"id"`
	Multiaddress string    `json:"multiaddress"`
	NodeName     string    `json:"node_name"`
	LastSeen     time.Time `json:"last_seen"`
}

ClusterPeerInfo represents information about an IPFS Cluster peer

type ClusterServiceConfig

type ClusterServiceConfig struct {
	Cluster struct {
		Peername           string   `json:"peername"`
		Secret             string   `json:"secret"`
		ListenMultiaddress []string `json:"listen_multiaddress"`
		PeerAddresses      []string `json:"peer_addresses"`
		LeaveOnShutdown    bool     `json:"leave_on_shutdown"`
	} `json:"cluster"`

	Consensus struct {
		CRDT struct {
			ClusterName  string   `json:"cluster_name"`
			TrustedPeers []string `json:"trusted_peers"`
			Batching     struct {
				MaxBatchSize int    `json:"max_batch_size"`
				MaxBatchAge  string `json:"max_batch_age"`
			} `json:"batching"`
			RepairInterval string `json:"repair_interval"`
		} `json:"crdt"`
	} `json:"consensus"`

	API struct {
		RestAPI struct {
			HTTPListenMultiaddress string `json:"http_listen_multiaddress"`
		} `json:"restapi"`
		IPFSProxy struct {
			ListenMultiaddress string `json:"listen_multiaddress"`
			NodeMultiaddress   string `json:"node_multiaddress"`
		} `json:"ipfsproxy"`
		PinSvcAPI struct {
			HTTPListenMultiaddress string `json:"http_listen_multiaddress"`
		} `json:"pinsvcapi"`
	} `json:"api"`

	IPFSConnector struct {
		IPFSHTTP struct {
			NodeMultiaddress string `json:"node_multiaddress"`
		} `json:"ipfshttp"`
	} `json:"ipfs_connector"`

	Raw map[string]interface{} `json:"-"`
}

ClusterServiceConfig represents the service.json configuration

type Config

type Config struct {
	// ClusterAPIURL is the base URL for IPFS Cluster HTTP API (e.g., "http://localhost:9094")
	// If empty, defaults to "http://localhost:9094"
	ClusterAPIURL string

	// Timeout is the timeout for client operations
	// If zero, defaults to 60 seconds
	Timeout time.Duration
}

Config holds configuration for the IPFS client

type IPFSClient

type IPFSClient interface {
	Add(ctx context.Context, reader io.Reader, name string) (*AddResponse, error)
	Pin(ctx context.Context, cid string, name string, replicationFactor int) (*PinResponse, error)
	PinStatus(ctx context.Context, cid string) (*PinStatus, error)
	Get(ctx context.Context, cid string, ipfsAPIURL string) (io.ReadCloser, error)
	Unpin(ctx context.Context, cid string) error
	Health(ctx context.Context) error
	GetPeerCount(ctx context.Context) (int, error)
	Close(ctx context.Context) error
}

IPFSClient defines the interface for IPFS operations

type PinResponse

type PinResponse struct {
	Cid  string `json:"cid"`
	Name string `json:"name"`
}

PinResponse represents the response from pinning a CID

type PinStatus

type PinStatus struct {
	Cid               string   `json:"cid"`
	Name              string   `json:"name"`
	Status            string   `json:"status"` // "pinned", "pinning", "queued", "unpinned", "error"
	ReplicationMin    int      `json:"replication_min"`
	ReplicationMax    int      `json:"replication_max"`
	ReplicationFactor int      `json:"replication_factor"`
	Peers             []string `json:"peers"`
	Error             string   `json:"error,omitempty"`
}

PinStatus represents the status of a pinned CID

Jump to

Keyboard shortcuts

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