fix: start rpc/rest with no relay

This commit is contained in:
Richard Ramos 2023-01-03 10:59:23 -04:00 committed by RichΛrd
parent 183d7822bf
commit 408b1de802
2 changed files with 28 additions and 13 deletions

View File

@ -33,7 +33,6 @@ func NewWakuRest(node *node.WakuNode, address string, port int, enableAdmin bool
}
_ = NewDebugService(node, mux)
relayService := NewRelayService(node, mux, relayCacheCapacity, log)
listenAddr := fmt.Sprintf("%s:%d", address, port)
@ -42,20 +41,27 @@ func NewWakuRest(node *node.WakuNode, address string, port int, enableAdmin bool
Handler: mux,
}
server.RegisterOnShutdown(func() {
relayService.Stop()
})
wrpc.node = node
wrpc.server = server
wrpc.relayService = relayService
if node.Relay() != nil {
relayService := NewRelayService(node, mux, relayCacheCapacity, log)
server.RegisterOnShutdown(func() {
relayService.Stop()
})
wrpc.relayService = relayService
}
return wrpc
}
func (r *WakuRest) Start(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
go r.relayService.Start(ctx)
if r.node.Relay() != nil {
go r.relayService.Start(ctx)
}
go func() {
_ = r.server.ListenAndServe()
}()

View File

@ -51,10 +51,13 @@ func NewWakuRpc(node *node.WakuNode, address string, port int, enableAdmin bool,
wrpc.log.Error("registering debug service", zap.Error(err))
}
relayService := NewRelayService(node, cacheCapacity, log)
err = s.RegisterService(relayService, "Relay")
if err != nil {
wrpc.log.Error("registering relay service", zap.Error(err))
var relayService *RelayService
if node.Relay() != nil {
relayService = NewRelayService(node, cacheCapacity, log)
err = s.RegisterService(relayService, "Relay")
if err != nil {
wrpc.log.Error("registering relay service", zap.Error(err))
}
}
err = s.RegisterService(&StoreService{node, log}, "Store")
@ -95,7 +98,10 @@ func NewWakuRpc(node *node.WakuNode, address string, port int, enableAdmin bool,
server.RegisterOnShutdown(func() {
filterService.Stop()
relayService.Stop()
if relayService != nil {
relayService.Stop()
}
if wrpc.privateService != nil {
wrpc.privateService.Stop()
}
@ -110,7 +116,10 @@ func NewWakuRpc(node *node.WakuNode, address string, port int, enableAdmin bool,
}
func (r *WakuRpc) Start() {
go r.relayService.Start()
if r.relayService != nil {
go r.relayService.Start()
}
go r.filterService.Start()
if r.privateService != nil {
go r.privateService.Start()