fix(c-bindings): simplify discv5 API

This commit is contained in:
Richard Ramos 2023-01-04 14:46:22 -04:00 committed by RichΛrd
parent 26daf72a23
commit 2c9c763c30
3 changed files with 12 additions and 17 deletions

View File

@ -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)
}

View File

@ -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)

View File

@ -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()
}