diff --git a/library/api_discovery.go b/library/api_discovery.go index 054db932..1ba0cdce 100644 --- a/library/api_discovery.go +++ b/library/api_discovery.go @@ -17,17 +17,3 @@ func waku_dns_discovery(url *C.char, nameserver *C.char, ms C.int) *C.char { response := mobile.DnsDiscovery(C.GoString(url), C.GoString(nameserver), int(ms)) return C.CString(response) } - -// Starts DiscoveryV5 service to discover and connect to new peers -//export waku_discv5_start -func waku_discv5_start() *C.char { - response := mobile.StartDiscoveryV5() - return C.CString(response) -} - -// Stops DiscoveryV5 service -//export waku_discv5_stop -func waku_discv5_stop() *C.char { - response := mobile.StopDiscoveryV5() - return C.CString(response) -} diff --git a/mobile/api.go b/mobile/api.go index 2bb5c63e..31e3537a 100644 --- a/mobile/api.go +++ b/mobile/api.go @@ -207,6 +207,13 @@ func Start() string { return MakeJSONResponse(err) } + if wakuNode.DiscV5() != nil { + if err := wakuNode.DiscV5().Start(context.Background()); err != nil { + wakuNode.Stop() + return MakeJSONResponse(err) + } + } + wakuStarted = true return MakeJSONResponse(nil) diff --git a/waku/v2/discv5/discover.go b/waku/v2/discv5/discover.go index a0b19b1a..fe076e21 100644 --- a/waku/v2/discv5/discover.go +++ b/waku/v2/discv5/discover.go @@ -209,11 +209,13 @@ func (d *DiscoveryV5) Stop() { d.cancel() - d.listener.Close() - d.listener = nil d.started = false - d.log.Info("stopped Discovery V5") + if d.listener != nil { + d.listener.Close() + d.listener = nil + d.log.Info("stopped Discovery V5") + } d.wg.Wait() }