client

package
v0.72.1-nightly Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultBootstrapPeers

func DefaultBootstrapPeers() []string

DefaultBootstrapPeers returns the default peer multiaddrs. These can be overridden by environment variables or config.

func DefaultDatabaseEndpoints

func DefaultDatabaseEndpoints() []string

DefaultDatabaseEndpoints returns default DB HTTP endpoints. These can be overridden by environment variables or config.

func IsInternalContext

func IsInternalContext(ctx context.Context) bool

IsInternalContext checks if a context is marked for internal operations

func MapAddrsToDBEndpoints

func MapAddrsToDBEndpoints(addrs []multiaddr.Multiaddr, dbPort int) []string

MapAddrsToDBEndpoints converts a set of peer multiaddrs to DB HTTP endpoints using dbPort.

func WithInternalAuth

func WithInternalAuth(ctx context.Context) context.Context

WithInternalAuth creates a context that bypasses authentication for internal system operations. This should only be used by the system itself (migrations, internal tasks, etc.)

func WithNamespace

func WithNamespace(ctx context.Context, ns string) context.Context

WithNamespace applies pubsub namespace override to the context. It is a convenience helper for client callers to ensure subsystems receive the same, consistent namespace override.

Types

type Client

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

Client implements the NetworkClient interface

func (*Client) Config

func (c *Client) Config() *ClientConfig

Config returns a snapshot copy of the client's configuration

func (*Client) Connect

func (c *Client) Connect() error

Connect establishes connection to the network

func (*Client) Database

func (c *Client) Database() DatabaseClient

Database returns the database client

func (*Client) Disconnect

func (c *Client) Disconnect() error

Disconnect closes the connection to the network

func (*Client) Health

func (c *Client) Health() (*HealthStatus, error)

Health returns the current health status

func (*Client) Network

func (c *Client) Network() NetworkInfo

Network returns the network info client

func (*Client) PubSub

func (c *Client) PubSub() PubSubClient

PubSub returns the pub/sub client

func (*Client) Storage added in v0.69.13

func (c *Client) Storage() StorageClient

Storage returns the storage client

type ClientConfig

type ClientConfig struct {
	AppName           string        `json:"app_name"`
	DatabaseName      string        `json:"database_name"`
	BootstrapPeers    []string      `json:"peers"`
	DatabaseEndpoints []string      `json:"database_endpoints"`
	GatewayURL        string        `json:"gateway_url"` // Gateway URL for HTTP API access (e.g., "http://localhost:6001")
	ConnectTimeout    time.Duration `json:"connect_timeout"`
	RetryAttempts     int           `json:"retry_attempts"`
	RetryDelay        time.Duration `json:"retry_delay"`
	QuietMode         bool          `json:"quiet_mode"` // Suppress debug/info logs
	APIKey            string        `json:"api_key"`    // API key for gateway auth
	JWT               string        `json:"jwt"`        // Optional JWT bearer token
}

ClientConfig represents configuration for network clients

func DefaultClientConfig

func DefaultClientConfig(appName string) *ClientConfig

DefaultClientConfig returns a default client configuration

type ColumnInfo

type ColumnInfo struct {
	Name     string `json:"name"`
	Type     string `json:"type"`
	Nullable bool   `json:"nullable"`
	Default  string `json:"default"`
}

ColumnInfo contains information about a table column

type DatabaseClient

type DatabaseClient interface {
	Query(ctx context.Context, sql string, args ...interface{}) (*QueryResult, error)
	Transaction(ctx context.Context, queries []string) error
	CreateTable(ctx context.Context, schema string) error
	DropTable(ctx context.Context, tableName string) error
	GetSchema(ctx context.Context) (*SchemaInfo, error)
}

DatabaseClient provides database operations for applications

type DatabaseClientImpl

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

DatabaseClientImpl implements DatabaseClient

func (*DatabaseClientImpl) CreateTable

func (d *DatabaseClientImpl) CreateTable(ctx context.Context, schema string) error

CreateTable creates a new table

func (*DatabaseClientImpl) DropTable

func (d *DatabaseClientImpl) DropTable(ctx context.Context, tableName string) error

DropTable drops a table

func (*DatabaseClientImpl) GetSchema

func (d *DatabaseClientImpl) GetSchema(ctx context.Context) (*SchemaInfo, error)

GetSchema returns schema information

func (*DatabaseClientImpl) Query

func (d *DatabaseClientImpl) Query(ctx context.Context, sql string, args ...interface{}) (*QueryResult, error)

Query executes a SQL query

func (*DatabaseClientImpl) Transaction

func (d *DatabaseClientImpl) Transaction(ctx context.Context, queries []string) error

Transaction executes multiple queries in a transaction

type HealthStatus

type HealthStatus struct {
	Status       string            `json:"status"` // "healthy", "degraded", "unhealthy"
	Checks       map[string]string `json:"checks"`
	LastUpdated  time.Time         `json:"last_updated"`
	ResponseTime time.Duration     `json:"response_time"`
}

HealthStatus contains health check information

type IPFSClusterPeerInfo added in v0.72.0

type IPFSClusterPeerInfo struct {
	PeerID    string   `json:"peer_id"`   // Cluster peer ID (different from IPFS peer ID)
	Addresses []string `json:"addresses"` // Cluster multiaddresses (e.g., /ip4/x.x.x.x/tcp/9098)
}

IPFSClusterPeerInfo contains IPFS Cluster peer information for cluster discovery

type IPFSPeerInfo added in v0.72.0

type IPFSPeerInfo struct {
	PeerID         string   `json:"peer_id"`
	SwarmAddresses []string `json:"swarm_addresses"`
}

IPFSPeerInfo contains IPFS peer information for discovery

type MessageHandler

type MessageHandler func(topic string, data []byte) error

MessageHandler is called when a pub/sub message is received

type NetworkClient

type NetworkClient interface {
	// Database operations (namespaced per app)
	Database() DatabaseClient

	// Pub/Sub messaging
	PubSub() PubSubClient

	// Network information
	Network() NetworkInfo

	// Storage operations (IPFS)
	Storage() StorageClient

	// Lifecycle
	Connect() error
	Disconnect() error
	Health() (*HealthStatus, error)

	// Config access (snapshot copy)
	Config() *ClientConfig
}

NetworkClient provides the main interface for applications to interact with the network

func NewClient

func NewClient(config *ClientConfig) (NetworkClient, error)

NewClient creates a new network client

type NetworkInfo

type NetworkInfo interface {
	GetPeers(ctx context.Context) ([]PeerInfo, error)
	GetStatus(ctx context.Context) (*NetworkStatus, error)
	ConnectToPeer(ctx context.Context, peerAddr string) error
	DisconnectFromPeer(ctx context.Context, peerID string) error
}

NetworkInfo provides network status and peer information

type NetworkInfoImpl

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

NetworkInfoImpl implements NetworkInfo

func (*NetworkInfoImpl) ConnectToPeer

func (n *NetworkInfoImpl) ConnectToPeer(ctx context.Context, peerAddr string) error

ConnectToPeer connects to a specific peer

func (*NetworkInfoImpl) DisconnectFromPeer

func (n *NetworkInfoImpl) DisconnectFromPeer(ctx context.Context, peerID string) error

DisconnectFromPeer disconnects from a specific peer

func (*NetworkInfoImpl) GetPeers

func (n *NetworkInfoImpl) GetPeers(ctx context.Context) ([]PeerInfo, error)

GetPeers returns information about connected peers

func (*NetworkInfoImpl) GetStatus

func (n *NetworkInfoImpl) GetStatus(ctx context.Context) (*NetworkStatus, error)

GetStatus returns network status

type NetworkStatus

type NetworkStatus struct {
	NodeID       string               `json:"node_id"`
	PeerID       string               `json:"peer_id"`
	Connected    bool                 `json:"connected"`
	PeerCount    int                  `json:"peer_count"`
	DatabaseSize int64                `json:"database_size"`
	Uptime       time.Duration        `json:"uptime"`
	IPFS         *IPFSPeerInfo        `json:"ipfs,omitempty"`
	IPFSCluster  *IPFSClusterPeerInfo `json:"ipfs_cluster,omitempty"`
}

NetworkStatus contains overall network status

type PeerInfo

type PeerInfo struct {
	ID        string    `json:"id"`
	Addresses []string  `json:"addresses"`
	Connected bool      `json:"connected"`
	LastSeen  time.Time `json:"last_seen"`
}

PeerInfo contains information about a network peer

type PubSubClient

type PubSubClient interface {
	Subscribe(ctx context.Context, topic string, handler MessageHandler) error
	Publish(ctx context.Context, topic string, data []byte) error
	Unsubscribe(ctx context.Context, topic string) error
	ListTopics(ctx context.Context) ([]string, error)
}

PubSubClient provides publish/subscribe messaging

type QueryResult

type QueryResult struct {
	Columns []string        `json:"columns"`
	Rows    [][]interface{} `json:"rows"`
	Count   int64           `json:"count"`
}

QueryResult represents the result of a database query

type SchemaInfo

type SchemaInfo struct {
	Tables []TableInfo `json:"tables"`
}

SchemaInfo contains database schema information

type StorageClient added in v0.69.13

type StorageClient interface {
	// Upload uploads content to IPFS and pins it
	Upload(ctx context.Context, reader io.Reader, name string) (*StorageUploadResult, error)

	// Pin pins an existing CID
	Pin(ctx context.Context, cid string, name string) (*StoragePinResult, error)

	// Status gets the pin status for a CID
	Status(ctx context.Context, cid string) (*StorageStatus, error)

	// Get retrieves content from IPFS by CID
	Get(ctx context.Context, cid string) (io.ReadCloser, error)

	// Unpin removes a pin from a CID
	Unpin(ctx context.Context, cid string) error
}

StorageClient provides IPFS storage operations

type StorageClientImpl added in v0.69.13

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

StorageClientImpl implements StorageClient using HTTP requests to the gateway

func (*StorageClientImpl) Get added in v0.69.13

Get retrieves content from IPFS by CID

func (*StorageClientImpl) Pin added in v0.69.13

Pin pins an existing CID

func (*StorageClientImpl) Status added in v0.69.13

func (s *StorageClientImpl) Status(ctx context.Context, cid string) (*StorageStatus, error)

Status gets the pin status for a CID

func (*StorageClientImpl) Unpin added in v0.69.13

func (s *StorageClientImpl) Unpin(ctx context.Context, cid string) error

Unpin removes a pin from a CID

func (*StorageClientImpl) Upload added in v0.69.13

func (s *StorageClientImpl) Upload(ctx context.Context, reader io.Reader, name string) (*StorageUploadResult, error)

Upload uploads content to IPFS and pins it

type StoragePinResult added in v0.69.13

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

StoragePinResult represents the result of pinning a CID

type StorageStatus added in v0.69.13

type StorageStatus 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"`
}

StorageStatus represents the status of a pinned CID

type StorageUploadResult added in v0.69.13

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

StorageUploadResult represents the result of uploading content to IPFS

type TableInfo

type TableInfo struct {
	Name    string       `json:"name"`
	Columns []ColumnInfo `json:"columns"`
}

TableInfo contains information about a database table

Jump to

Keyboard shortcuts

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