package node import ( "git.lumeweb.com/LumeWeb/libs5-go/config" "git.lumeweb.com/LumeWeb/libs5-go/protocol" "git.lumeweb.com/LumeWeb/libs5-go/protocol/signed" "git.lumeweb.com/LumeWeb/libs5-go/service" bolt "go.etcd.io/bbolt" "go.uber.org/zap" ) type Node struct { nodeConfig *config.NodeConfig services service.Services } func (n *Node) Services() service.Services { return n.services } func NewNode(config *config.NodeConfig, services service.Services) *Node { return &Node{ nodeConfig: config, services: services, // Services are passed in, not created here } } func (n *Node) IsStarted() bool { return n.services.IsStarted() } func (n *Node) Config() *config.NodeConfig { return n.nodeConfig } func (n *Node) Logger() *zap.Logger { if n.nodeConfig != nil { return n.nodeConfig.Logger } return nil } func (n *Node) Db() *bolt.DB { if n.nodeConfig != nil { return n.nodeConfig.DB } return nil } func (n *Node) Start() error { protocol.RegisterProtocols() signed.RegisterSignedProtocols() return n.services.Start() } func (n *Node) Stop() error { return n.services.Stop() } func (n *Node) WaitOnConnectedPeers() { n.services.P2P().WaitOnConnectedPeers() } func DefaultNode(config *config.NodeConfig) *Node { params := service.ServiceParams{ Logger: config.Logger, Config: config, Db: config.DB, } // Initialize services first p2pService := service.NewP2P(params) registryService := service.NewRegistry(params) httpService := service.NewHTTP(params) storageService := service.NewStorage(params) // Aggregate services services := NewServices(ServicesParams{ P2P: p2pService, Registry: registryService, HTTP: httpService, Storage: storageService, }) // Now create the node with the services return NewNode(config, services) }