connmgr

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 20 Imported by: 5

Documentation

Index

Constants

View Source
const (
	UploadID         string = "/upload"
	DownloadID       string = "/download"
	QueryID          string = "/query"
	ClaimOwnershipID string = "/claim-ownership"
)

Variables

This section is empty.

Functions

func BuildErrorMessage

func BuildErrorMessage(message string, err error) types.ErrorMessage

func BuildResponseMessage

func BuildResponseMessage(response bool, message ...string) types.ResponseMessage

func ClaimOwnership

func ClaimOwnership(ctx context.Context, connectionManager ConnectionManager, connectionID string, root string, privateKey *secp256k1.PrivateKey) (*types.ResponseMessage, error)

ClaimOwnership claims ownership of an existing DAG root on a relay. The DAG must already exist on the relay. This is useful when a DAG was uploaded by another user and you want to claim ownership (e.g., for preventing garbage collection). The function signs the root hash with the provided private key to prove ownership.

func ClaimOwnershipAll

func ClaimOwnershipAll(ctx context.Context, connectionManager ConnectionManager, root string, privateKey *secp256k1.PrivateKey) map[string]*ClaimOwnershipResult

ClaimOwnershipAll claims ownership of a DAG root on all connected relays. Returns a map of connection IDs to their responses or errors.

func DownloadDag

func DownloadDag(ctx context.Context, connectionManager ConnectionManager, connectionID string, root string, privatekey *secp256k1.PrivateKey, filter *types.DownloadFilter, progressChan chan<- types.DownloadProgress) (context.Context, *types.DagData, error)

func QueryDag

func QueryDag(ctx context.Context, connectionManager ConnectionManager, connectionID string, query types.QueryFilter) ([]string, error)

func QueryEvents

func QueryEvents(ctx context.Context, connectionManager ConnectionManager, connectionID string, filters []nostr.Filter, subscriptionId *string) ([]nostr.Event, error)

func ReadEnvelopeFromStream

func ReadEnvelopeFromStream(stream types.Stream, timeoutDuration time.Duration) (*types.MessageEnvelope, error)

func ReadJsonMessageFromStream

func ReadJsonMessageFromStream[T any](stream types.Stream) (*T, error)

func ReadMessageFromStream

func ReadMessageFromStream[T any](stream types.Stream, options ...ReadOption) (*T, error)

func SendUniversalEvent

func SendUniversalEvent(ctx context.Context, connectionManager ConnectionManager, event *nostr.Event, subscriptionId *string) (map[string]*nostr.OKEnvelope, error)

func SendUniversalEventSingle

func SendUniversalEventSingle(ctx context.Context, connectionManager ConnectionManager, connectionID string, event *nostr.Event, subscriptionId *string) (*nostr.OKEnvelope, error)

func SetupConnection

func SetupConnection(useLibp2p bool, address string) (types.Connector, error)

func UploadDag

func UploadDag(ctx context.Context, connectionManager ConnectionManager, dag *merkle_dag.Dag, privatekey *secp256k1.PrivateKey, progressChan chan<- types.UploadProgress) error

func UploadDagSingle

func UploadDagSingle(ctx context.Context, connectionManager ConnectionManager, connectionID string, dag *merkle_dag.Dag, privatekey *secp256k1.PrivateKey, progressChan chan<- types.UploadProgress) error

func WaitForAdvancedQueryMessage

func WaitForAdvancedQueryMessage(stream types.Stream) (*types.AdvancedQueryMessage, error)

func WaitForDownloadMessage

func WaitForDownloadMessage(stream types.Stream) (*types.DownloadMessage, error)

func WaitForQueryMessage

func WaitForQueryMessage(stream types.Stream) (*types.QueryMessage, error)

func WaitForResponse

func WaitForResponse(stream types.Stream) (*types.ResponseMessage, error)

func WaitForUploadMessage

func WaitForUploadMessage(stream types.Stream) (*types.UploadMessage, error)

func WriteErrorToStream

func WriteErrorToStream(stream types.Stream, message string, err error) error

func WriteJsonMessageToStream

func WriteJsonMessageToStream[T any](stream types.Stream, message T) error

func WriteMessageToStream

func WriteMessageToStream[T any](stream types.Stream, message T, options ...WriteOption) error

func WriteResponseToStream

func WriteResponseToStream(stream types.Stream, response bool) error

Types

type ClaimOwnershipResult

type ClaimOwnershipResult struct {
	Response *types.ResponseMessage
	Error    error
}

ClaimOwnershipResult holds the result of a claim ownership operation for a single connection.

type ConnectionManager

type ConnectionManager interface {
	ConnectWithLibp2p(ctx context.Context, connectionId string, serverAddress string, opts ...libp2p.Option) error
	ConnectWithWebsocket(ctx context.Context, connectionId string, url string) error
	Disconnect(connectionID string) error
	GetStream(ctx context.Context, connectionID string, protocolID string) (types.Stream, error)
	ListConnections() map[string]types.Connector
}

type GenericConnectionManager

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

func NewGenericConnectionManager

func NewGenericConnectionManager() *GenericConnectionManager

func (*GenericConnectionManager) ConnectWithLibp2p

func (gcm *GenericConnectionManager) ConnectWithLibp2p(ctx context.Context, connectionId string, serverAddress string, opts ...libp2p.Option) error

func (*GenericConnectionManager) ConnectWithWebsocket

func (gcm *GenericConnectionManager) ConnectWithWebsocket(ctx context.Context, connectionId string, url string) error

func (*GenericConnectionManager) Disconnect

func (gcm *GenericConnectionManager) Disconnect(connectionID string) error

func (*GenericConnectionManager) GetStream

func (gcm *GenericConnectionManager) GetStream(ctx context.Context, connectionID string, protocolID string) (types.Stream, error)

func (*GenericConnectionManager) ListConnections

func (gcm *GenericConnectionManager) ListConnections() map[string]types.Connector

type ReadOption

type ReadOption func(*readOptions)

func WithRetries

func WithRetries(maxRetries int) ReadOption

func WithRetryDelay

func WithRetryDelay(delay time.Duration) ReadOption

func WithTimeout

func WithTimeout(timeout time.Duration) ReadOption

type WriteOption

type WriteOption func(*writeOptions)

func WithWriteRetries

func WithWriteRetries(maxRetries int) WriteOption

func WithWriteRetryDelay

func WithWriteRetryDelay(delay time.Duration) WriteOption

func WithWriteTimeout

func WithWriteTimeout(timeout time.Duration) WriteOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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