diff --git a/waku/v2/rest/waku_rest.go b/waku/v2/rest/waku_rest.go index b7f9db30..e5aaec4c 100644 --- a/waku/v2/rest/waku_rest.go +++ b/waku/v2/rest/waku_rest.go @@ -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() }() diff --git a/waku/v2/rpc/waku_rpc.go b/waku/v2/rpc/waku_rpc.go index 43b14a8c..0af83ef2 100644 --- a/waku/v2/rpc/waku_rpc.go +++ b/waku/v2/rpc/waku_rpc.go @@ -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()