common

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateIdentityFromSolanaKey

func CreateIdentityFromSolanaKey(privateKeyBase58 string) (crypto.PrivKey, peer.ID, error)

CreateIdentityFromSolanaKey converts a Base58-encoded Solana private key to libp2p identity

func CreatePeerIDFromSolanaPublicKey

func CreatePeerIDFromSolanaPublicKey(solanaPublicKey solana.PublicKey) (peer.ID, error)

CreatePeerIDFromSolanaPublicKey creates a libp2p peer ID from a Solana public key

func ExtractSolanaPublicKey

func ExtractSolanaPublicKey(privateKeyBase58 string) (solana.PublicKey, error)

ExtractSolanaPublicKey extracts the Solana public key from a Base58 private key

func PeerIDToSolanaPublicKey

func PeerIDToSolanaPublicKey(peerID peer.ID) (solana.PublicKey, error)

PeerIDToSolanaPublicKey attempts to extract a Solana public key from a libp2p peer ID This only works if the peer uses Ed25519 keys (which our system enforces)

Types

type AuthorizationCache

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

AuthorizationCache provides caching for authorized wallets

type BootstrapNode

type BootstrapNode struct {
	PublicKey solana.PublicKey // Node's Solana public key
	IP        string           // IP address
	QUICPort  int              // QUIC port
	TCPPort   int              // TCP port
}

BootstrapNode represents information about a bootstrap node

type Config

type Config struct {
	WalletPrivateKey     string                   // Base58-encoded Solana private key
	DatabaseName         string                   // Namespace for topics
	GetAuthorizedWallets GetAuthorizedWalletsFunc // Function to get authorized wallets
	GetBootstrapNodes    GetBootstrapNodesFunc    // Function to get bootstrap nodes
	Logger               Logger                   // Logger for all internal operations
	ListenPorts          ListenPorts              // Ports for different transports
	RefreshInterval      time.Duration            // How often to refresh authorized wallets cache (default: 30s)
	Debug                bool                     // Enable debug logging for p2p operations
	SkipBootstrapWait    bool                     // Skip waiting for bootstrap nodes (useful for tests)
}

Config represents the configuration for connecting to the P2P pubsub network

type Event

type Event struct {
	ID         string      `json:"id"`        // Unique event identifier
	FromPeerId string      `json:"from_peer"` // Peer ID of sender
	Message    interface{} `json:"message"`   // The actual message content
	Timestamp  int64       `json:"timestamp"` // Unix timestamp

}

Event represents a message in the pub/sub system

type GetAuthorizedWalletsFunc

type GetAuthorizedWalletsFunc func(ctx context.Context) ([]solana.PublicKey, error)

Function provided by node software to get authorized wallets

type GetBootstrapNodesFunc

type GetBootstrapNodesFunc func(ctx context.Context) ([]BootstrapNode, error)

Function provided by node software to get bootstrap nodes

type ListenPorts

type ListenPorts struct {
	QUIC int // QUIC listen port (default: 4001)
	TCP  int // TCP listen port (default: 4002)
}

ListenPorts represents ports for different transports

type LiveKitLogger

type LiveKitLogger interface {
	Debugw(msg string, keysAndValues ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	Warnw(msg string, err error, keysAndValues ...interface{})
	Errorw(msg string, err error, keysAndValues ...interface{})
}

LiveKitLogger defines the interface expected by LiveKit logging with keyed logging methods ending in 'w' (Debugw, Infow, etc.)

type Logger

type Logger interface {
	Debug(msg string, keysAndValues ...interface{})
	Info(msg string, keysAndValues ...interface{})
	Warn(msg string, keysAndValues ...interface{})
	Error(msg string, keysAndValues ...interface{})
}

Logger interface for structured logging (library-agnostic)

func NewLivekitLoggerAdapter

func NewLivekitLoggerAdapter(logger LiveKitLogger) Logger

NewLivekitLoggerAdapter creates a logger adapter for LiveKit loggers LiveKit loggers typically use methods like Debugw, Infow, Warnw, Errorw that accept keyed logging with variadic key-value pairs

func NewSlogLogger

func NewSlogLogger(logger *slog.Logger) Logger

NewSlogLogger creates a logger using Go's standard slog (recommended for Go 1.23.11+)

type PubSubHandler

type PubSubHandler func(Event)

PubSubHandler is the callback function for handling received messages

type SolanaRegistryGater

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

SolanaRegistryGater implements connection gating based on Solana wallet registry

func NewSolanaRegistryGater

func NewSolanaRegistryGater(getAuthorizedWallets GetAuthorizedWalletsFunc, logger Logger, refreshInterval time.Duration) *SolanaRegistryGater

NewSolanaRegistryGater creates a new connection gater with the provided registry function

func (*SolanaRegistryGater) ClearCache

func (g *SolanaRegistryGater) ClearCache()

ClearCache clears the authorization cache (useful for testing)

func (*SolanaRegistryGater) InterceptAccept

func (g *SolanaRegistryGater) InterceptAccept(network.ConnMultiaddrs) bool

InterceptAccept validates incoming connections (initial filter)

func (*SolanaRegistryGater) InterceptAddrDial

func (g *SolanaRegistryGater) InterceptAddrDial(p peer.ID, m multiaddr.Multiaddr) bool

InterceptAddrDial validates specific address connections

func (*SolanaRegistryGater) InterceptPeerDial

func (g *SolanaRegistryGater) InterceptPeerDial(p peer.ID) bool

InterceptPeerDial validates outgoing connections against registry

func (*SolanaRegistryGater) InterceptSecured

func (g *SolanaRegistryGater) InterceptSecured(direction network.Direction, p peer.ID, connMultiaddr network.ConnMultiaddrs) bool

InterceptSecured performs post-handshake authorization via wallet registry lookup

func (*SolanaRegistryGater) InterceptUpgraded

func (g *SolanaRegistryGater) InterceptUpgraded(network.Conn) (allow bool, reason control.DisconnectReason)

InterceptUpgraded validates connections after protocol upgrade (no additional checks needed)

func (*SolanaRegistryGater) Stop

func (g *SolanaRegistryGater) Stop()

Stop stops the background refresh process

Jump to

Keyboard shortcuts

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