network

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServiceManager   = "manager"
	ServiceQuorum    = "quorum"
	ServiceValidator = "validator"
	ServiceKeeper    = "keeper"

	// Define base data directory
	BaseDataDir     = "data"
	RegistryDir     = "peer_registry"
	ServiceRegistry = "services.json"
)
View Source
const MessageProtocol = "/triggerx/message/1.0.0"

Variables

This section is empty.

Functions

func LoadIdentity

func LoadIdentity(nodeType string) (crypto.PrivKey, error)

func SetupKeeperWithRegistry added in v0.1.0

func SetupKeeperWithRegistry(ctx context.Context, keeperConfig types.NodeConfig, registry *PeerRegistry) (host.Host, error)

func SetupServiceWithRegistry added in v0.1.0

func SetupServiceWithRegistry(ctx context.Context, serviceName string, registry *PeerRegistry) (host.Host, error)

Types

type Discovery added in v0.1.0

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

func NewDiscovery added in v0.1.0

func NewDiscovery(ctx context.Context, h host.Host, name string) *Discovery

func (*Discovery) ConnectToPeer added in v0.1.0

func (d *Discovery) ConnectToPeer(serviceType string) (peer.ID, error)

ConnectToPeer connects to a specific peer using stored registry info

func (*Discovery) GetConnectedPeers added in v0.1.0

func (d *Discovery) GetConnectedPeers() map[peer.ID]PeerInfo

GetConnectedPeers returns all currently connected peers

func (*Discovery) IsConnected added in v0.1.0

func (d *Discovery) IsConnected(peerID peer.ID) bool

func (*Discovery) SavePeerInfo added in v0.1.0

func (d *Discovery) SavePeerInfo() error

SavePeerInfo saves this peer's info to the registry

type Message added in v0.1.0

type Message struct {
	From       string      `json:"from"`
	To         string      `json:"to"`
	Content    interface{} `json:"content"`
	Timestamp  string      `json:"timestamp"`
	ID         string      `json:"id"`
	RetryCount int         `json:"retryCount"`
	ACK        bool        `json:"ack"`
}

type Messaging added in v0.1.0

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

func NewMessaging added in v0.1.0

func NewMessaging(h host.Host, name string) *Messaging

func (*Messaging) BroadcastMessage added in v0.1.0

func (m *Messaging) BroadcastMessage(content interface{}) error

func (*Messaging) GetHost added in v0.1.0

func (m *Messaging) GetHost() host.Host

func (*Messaging) InitMessageHandling added in v0.1.0

func (m *Messaging) InitMessageHandling(onMessage func(Message))

func (*Messaging) SendMessage added in v0.1.0

func (m *Messaging) SendMessage(to string, peerID peer.ID, content interface{}, ack bool) error

type P2PConfig

type P2PConfig struct {
	Name    string
	Address peer.AddrInfo
}

type PeerIdentity

type PeerIdentity struct {
	PrivKey []byte `json:"priv_key"`
}

type PeerInfo added in v0.1.0

type PeerInfo struct {
	Name    string
	Address string
}

type PeerRegistry added in v0.1.0

type PeerRegistry struct {
	Services map[string]ServiceInfo `json:"services"`
	// contains filtered or unexported fields
}

func NewPeerRegistry added in v0.1.0

func NewPeerRegistry() (*PeerRegistry, error)

func (*PeerRegistry) GetAllServices added in v0.1.0

func (r *PeerRegistry) GetAllServices() map[string]ServiceInfo

func (*PeerRegistry) GetService added in v0.1.0

func (r *PeerRegistry) GetService(serviceName string) (ServiceInfo, bool)

func (*PeerRegistry) UpdateService added in v0.1.0

func (r *PeerRegistry) UpdateService(serviceName string, peerID peer.ID, addrs []string) error

type ServiceInfo added in v0.1.0

type ServiceInfo struct {
	Name      string   `json:"name"`
	PeerID    string   `json:"peer_id"`
	Addresses []string `json:"addresses"`
}

type ServicePrivateKeys

type ServicePrivateKeys struct {
	ManagerPrivKey   string `json:"manager_p2p_private_key"`
	QuorumPrivKey    string `json:"quorum_p2p_private_key"`
	ValidatorPrivKey string `json:"validator_p2p_private_key"`
}

Jump to

Keyboard shortcuts

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