diff --git a/node/node.go b/node/node.go index 4025ff6..c284450 100644 --- a/node/node.go +++ b/node/node.go @@ -1,6 +1,7 @@ package node import ( + "context" "git.lumeweb.com/LumeWeb/libs5-go/config" "git.lumeweb.com/LumeWeb/libs5-go/encoding" "git.lumeweb.com/LumeWeb/libs5-go/protocol" @@ -48,19 +49,19 @@ func (n *Node) Db() *bolt.DB { return nil } -func (n *Node) Start() error { +func (n *Node) Start(ctx context.Context) error { protocol.RegisterProtocols() protocol.RegisterSignedProtocols() - return n.services.Start() + return n.services.Start(ctx) } -func (n *Node) Init() error { - return n.services.Init() +func (n *Node) Init(ctx context.Context) error { + return n.services.Init(ctx) } -func (n *Node) Stop() error { - return n.services.Stop() +func (n *Node) Stop(ctx context.Context) error { + return n.services.Stop(ctx) } func (n *Node) WaitOnConnectedPeers() { diff --git a/node/services.go b/node/services.go index 83b5f31..e5b2561 100644 --- a/node/services.go +++ b/node/services.go @@ -1,6 +1,7 @@ package node import ( + "context" "git.lumeweb.com/LumeWeb/libs5-go/service" ) @@ -69,9 +70,9 @@ func (s *ServicesImpl) IsStarted() bool { return s.started } -func (s *ServicesImpl) Init() error { +func (s *ServicesImpl) Init(ctx context.Context) error { for _, svc := range s.All() { - err := svc.Init() + err := svc.Init(ctx) if err != nil { return err } @@ -80,9 +81,9 @@ func (s *ServicesImpl) Init() error { return nil } -func (s *ServicesImpl) Start() error { +func (s *ServicesImpl) Start(ctx context.Context) error { for _, svc := range s.All() { - err := svc.Start() + err := svc.Start(ctx) if err != nil { return err } @@ -92,9 +93,9 @@ func (s *ServicesImpl) Start() error { return nil } -func (s *ServicesImpl) Stop() error { +func (s *ServicesImpl) Stop(ctx context.Context) error { for _, svc := range s.All() { - err := svc.Stop() + err := svc.Stop(ctx) if err != nil { return err } diff --git a/service/default/http.go b/service/default/http.go index f8227d3..c4299f6 100644 --- a/service/default/http.go +++ b/service/default/http.go @@ -1,6 +1,7 @@ package _default import ( + "context" "git.lumeweb.com/LumeWeb/libs5-go/build" "git.lumeweb.com/LumeWeb/libs5-go/net" "git.lumeweb.com/LumeWeb/libs5-go/service" @@ -46,15 +47,15 @@ func (h *HTTPServiceDefault) GetHttpRouter(inject map[string]jape.Handler) *http return jape.Mux(routes) } -func (h *HTTPServiceDefault) Start() error { +func (h *HTTPServiceDefault) Start(ctx context.Context) error { return nil } -func (h *HTTPServiceDefault) Stop() error { +func (h *HTTPServiceDefault) Stop(ctx context.Context) error { return nil } -func (h *HTTPServiceDefault) Init() error { +func (h *HTTPServiceDefault) Init(ctx context.Context) error { return nil } diff --git a/service/default/p2p.go b/service/default/p2p.go index 47cdea0..1657b2c 100644 --- a/service/default/p2p.go +++ b/service/default/p2p.go @@ -85,7 +85,7 @@ func (p *P2PServiceDefault) Peers() structs.Map { return p.peers } -func (p *P2PServiceDefault) Start() error { +func (p *P2PServiceDefault) Start(ctx context.Context) error { config := p.Config() if len(config.P2P.Peers.Initial) > 0 { initialPeers := config.P2P.Peers.Initial @@ -109,11 +109,11 @@ func (p *P2PServiceDefault) Start() error { return nil } -func (p *P2PServiceDefault) Stop() error { +func (p *P2PServiceDefault) Stop(ctx context.Context) error { return nil } -func (p *P2PServiceDefault) Init() error { +func (p *P2PServiceDefault) Init(ctx context.Context) error { if p.inited { return nil } diff --git a/service/default/registry.go b/service/default/registry.go index 978baa1..7aa47ea 100644 --- a/service/default/registry.go +++ b/service/default/registry.go @@ -1,6 +1,7 @@ package _default import ( + "context" "errors" "git.lumeweb.com/LumeWeb/libs5-go/encoding" "git.lumeweb.com/LumeWeb/libs5-go/net" @@ -29,15 +30,15 @@ type RegistryServiceDefault struct { service.ServiceBase } -func (r *RegistryServiceDefault) Start() error { +func (r *RegistryServiceDefault) Start(ctx context.Context) error { return nil } -func (r *RegistryServiceDefault) Stop() error { +func (r *RegistryServiceDefault) Stop(ctx context.Context) error { return nil } -func (r *RegistryServiceDefault) Init() error { +func (r *RegistryServiceDefault) Init(ctx context.Context) error { return utils.CreateBucket(registryBucketName, r.Db()) } diff --git a/service/default/storage.go b/service/default/storage.go index d5b765b..55d8380 100644 --- a/service/default/storage.go +++ b/service/default/storage.go @@ -1,6 +1,7 @@ package _default import ( + "context" "errors" "fmt" "git.lumeweb.com/LumeWeb/libs5-go/encoding" @@ -40,7 +41,7 @@ func NewStorage(params service.ServiceParams) *StorageService { } } -func (s *StorageService) Start() error { +func (s *StorageService) Start(ctx context.Context) error { err := utils.CreateBucket(cacheBucketName, s.Db()) @@ -51,11 +52,11 @@ func (s *StorageService) Start() error { return nil } -func (s *StorageService) Stop() error { +func (s *StorageService) Stop(ctx context.Context) error { return nil } -func (s *StorageService) Init() error { +func (s *StorageService) Init(ctx context.Context) error { return nil } diff --git a/service/service.go b/service/service.go index 24a58d5..ff7c3cc 100644 --- a/service/service.go +++ b/service/service.go @@ -1,6 +1,7 @@ package service import ( + "context" "git.lumeweb.com/LumeWeb/libs5-go/config" "go.etcd.io/bbolt" "go.uber.org/zap" @@ -11,9 +12,9 @@ type ServicesSetter interface { } type Service interface { - Start() error - Stop() error - Init() error + Start(ctx context.Context) error + Stop(ctx context.Context) error + Init(ctx context.Context) error Logger() *zap.Logger Config() *config.NodeConfig Db() *bbolt.DB @@ -25,10 +26,10 @@ type Services interface { HTTP() HTTPService Storage() StorageService All() []Service - Init() error + Init(ctx context.Context) error IsStarted() bool - Start() error - Stop() error + Start(ctx context.Context) error + Stop(ctx context.Context) error } type ServiceParams struct {