libp2p

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColoniesProcotolID = protocol.ID("/colonies/rpc/1.0.0")
	ConnectTimeout     = 60 * time.Second // Increased for relay circuit establishment
	StreamTimeout      = 90 * time.Second // Increased for relay latency
)

Variables

This section is empty.

Functions

func GetLibP2PClientBackendFactory

func GetLibP2PClientBackendFactory() backends.ClientBackendFactory

GetLibP2PClientBackendFactory returns a libp2p client backend factory This function is used to avoid import cycles while allowing registration

Types

type CachedPeer

type CachedPeer struct {
	PeerID     string    `json:"peer_id"`
	Addrs      []string  `json:"addrs"`
	LastSeen   time.Time `json:"last_seen"`
	Rendezvous string    `json:"rendezvous"`
}

CachedPeer represents a cached peer entry for serialization

type DHTCache

type DHTCache struct {
	Version int          `json:"version"`
	Updated time.Time    `json:"updated"`
	Peers   []CachedPeer `json:"peers"`
}

DHTCache represents the DHT peer cache structure

type LibP2PClientBackend

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

LibP2PClientBackend implements peer-to-peer client backend using libp2p

func NewLibP2PClientBackend

func NewLibP2PClientBackend(config *backends.ClientConfig) (*LibP2PClientBackend, error)

NewLibP2PClientBackend creates a new libp2p client backend

func (*LibP2PClientBackend) CheckHealth

func (l *LibP2PClientBackend) CheckHealth() error

CheckHealth checks the health of libp2p connections

func (*LibP2PClientBackend) Close

func (l *LibP2PClientBackend) Close() error

Close closes the libp2p backend and cleans up resources

func (*LibP2PClientBackend) EstablishRealtimeConn

func (l *LibP2PClientBackend) EstablishRealtimeConn(jsonString string) (backends.RealtimeConnection, error)

EstablishRealtimeConn establishes a real-time connection via libp2p pubsub

func (*LibP2PClientBackend) SendMessage

func (l *LibP2PClientBackend) SendMessage(method string, jsonString string, prvKey string, insecure bool, ctx context.Context) (string, error)

SendMessage sends an RPC message with authentication via libp2p stream

func (*LibP2PClientBackend) SendRawMessage

func (l *LibP2PClientBackend) SendRawMessage(jsonString string, insecure bool) (string, error)

SendRawMessage sends a raw JSON message via libp2p stream

type LibP2PClientBackendFactory

type LibP2PClientBackendFactory struct{}

LibP2PClientBackendFactory creates libp2p client backends

func NewLibP2PClientBackendFactory

func NewLibP2PClientBackendFactory() *LibP2PClientBackendFactory

NewLibP2PClientBackendFactory creates a new libp2p client backend factory

func (*LibP2PClientBackendFactory) CreateBackend

CreateBackend creates a new libp2p client backend

func (*LibP2PClientBackendFactory) GetBackendType

GetBackendType returns the backend type this factory creates

type PubSubRealtimeConnection

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

PubSubRealtimeConnection implements RealtimeConnection using libp2p pubsub

func NewPubSubRealtimeConnection

func NewPubSubRealtimeConnection(topic *pubsub.Topic, subscription *pubsub.Subscription, ctx context.Context, localPeerID string) *PubSubRealtimeConnection

NewPubSubRealtimeConnection creates a new pubsub-based realtime connection

func (*PubSubRealtimeConnection) Close

func (p *PubSubRealtimeConnection) Close() error

Close closes the pubsub realtime connection

func (*PubSubRealtimeConnection) ReadMessage

func (p *PubSubRealtimeConnection) ReadMessage() (messageType int, data []byte, err error)

ReadMessage reads a message from the pubsub subscription

func (*PubSubRealtimeConnection) SetReadLimit

func (p *PubSubRealtimeConnection) SetReadLimit(limit int64)

SetReadLimit sets the maximum size for incoming messages

func (*PubSubRealtimeConnection) WriteMessage

func (p *PubSubRealtimeConnection) WriteMessage(messageType int, data []byte) error

WriteMessage writes a message to the pubsub topic

type ServerPeer

type ServerPeer struct {
	ID             peer.ID
	Addrs          []multiaddr.Multiaddr
	LastSeen       time.Time
	Active         bool
	LastAttempt    time.Time // Last connection attempt
	FailedAttempts int       // Number of consecutive failed attempts
}

ServerPeer represents a known Colonies server peer

Jump to

Keyboard shortcuts

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