Documentation
¶
Index ¶
- type AddResponse
- type Client
- func (c *Client) Add(ctx context.Context, reader io.Reader, name string) (*AddResponse, error)
- func (c *Client) Close(ctx context.Context) error
- func (c *Client) Get(ctx context.Context, cid string, ipfsAPIURL string) (io.ReadCloser, error)
- func (c *Client) GetPeerCount(ctx context.Context) (int, error)
- func (c *Client) Health(ctx context.Context) error
- func (c *Client) Pin(ctx context.Context, cid string, name string, replicationFactor int) (*PinResponse, error)
- func (c *Client) PinStatus(ctx context.Context, cid string) (*PinStatus, error)
- func (c *Client) Unpin(ctx context.Context, cid string) error
- type ClusterConfigManager
- func (cm *ClusterConfigManager) DiscoverClusterPeersFromGateway() (bool, error)
- func (cm *ClusterConfigManager) DiscoverClusterPeersFromLibP2P(host host.Host) (bool, error)
- func (cm *ClusterConfigManager) EnsureConfig() error
- func (cm *ClusterConfigManager) FixIPFSConfigAddresses() error
- func (cm *ClusterConfigManager) RepairPeerConfiguration() (bool, error)
- func (cm *ClusterConfigManager) UpdateAllClusterPeers() (bool, error)
- func (cm *ClusterConfigManager) UpdatePeerAddresses(peerAPIURL string) (bool, error)
- type ClusterServiceConfig
- type Config
- type IPFSClient
- type PinResponse
- type PinStatus
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 (*Client) Get ¶
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 ¶
GetPeerCount returns the number of cluster peers
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
type ClusterConfigManager ¶
type ClusterConfigManager struct {
// contains filtered or unexported fields
}
ClusterConfigManager manages IPFS Cluster configuration files
func NewClusterConfigManager ¶
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 ¶
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