ipfs

package
v0.72.0-nightly Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2025 License: AGPL-3.0 Imports: 22 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() (bool, error)

DiscoverClusterPeersFromGateway queries bootstrap peers' /v1/network/status endpoint to discover IPFS Cluster peer information and updates the local service.json

func (*ClusterConfigManager) DiscoverClusterPeersFromLibP2P

func (cm *ClusterConfigManager) DiscoverClusterPeersFromLibP2P(host host.Host) (bool, error)

DiscoverClusterPeersFromLibP2P loads IPFS cluster peer addresses from the peerstore file. If peerstore is empty, it means there are no peers to connect to. Returns true if peers were loaded and configured, false otherwise (non-fatal)

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 to use 127.0.0.1 This is necessary because IPFS doesn't accept "localhost" as a valid IP address in multiaddrs This function always ensures the config is correct, regardless of current state

func (*ClusterConfigManager) RepairPeerConfiguration added in v0.72.0

func (cm *ClusterConfigManager) RepairPeerConfiguration() (bool, error)

RepairPeerConfiguration automatically discovers and repairs peer configuration Tries multiple methods: gateway /v1/network/status, config-based discovery, peer multiaddr

func (*ClusterConfigManager) UpdateAllClusterPeers

func (cm *ClusterConfigManager) UpdateAllClusterPeers() (bool, error)

UpdateAllClusterPeers discovers all cluster peers from the local cluster API and updates peer_addresses in service.json. This allows IPFS Cluster to automatically connect to all discovered peers in the cluster. Returns true if update was successful, false if cluster is not available yet (non-fatal)

func (*ClusterConfigManager) UpdatePeerAddresses added in v0.72.0

func (cm *ClusterConfigManager) UpdatePeerAddresses(peerAPIURL string) (bool, error)

UpdatePeerAddresses updates peer_addresses and peerstore with peer information Returns true if update was successful, false if peer is not available yet (non-fatal)

type ClusterServiceConfig

type ClusterServiceConfig struct {
	Cluster struct {
		Peername           string   `json:"peername"`
		Secret             string   `json:"secret"`
		LeaveOnShutdown    bool     `json:"leave_on_shutdown"`
		ListenMultiaddress []string `json:"listen_multiaddress"`
		PeerAddresses      []string `json:"peer_addresses"`
	} `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 {
		IPFSProxy struct {
			ListenMultiaddress string `json:"listen_multiaddress"`
			NodeMultiaddress   string `json:"node_multiaddress"`
		} `json:"ipfsproxy"`
		PinSvcAPI struct {
			HTTPListenMultiaddress string `json:"http_listen_multiaddress"`
		} `json:"pinsvcapi"`
		RestAPI struct {
			HTTPListenMultiaddress string `json:"http_listen_multiaddress"`
		} `json:"restapi"`
	} `json:"api"`
	IPFSConnector struct {
		IPFSHTTP struct {
			NodeMultiaddress string `json:"node_multiaddress"`
		} `json:"ipfshttp"`
	} `json:"ipfs_connector"`
	// Keep rest of fields as raw JSON to preserve structure
	Raw map[string]interface{} `json:"-"`
}

ClusterServiceConfig represents the structure of service.json

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