From 4804588197c3626b8a19b3c200774b04ecb08fde Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Fri, 17 Feb 2023 13:30:59 -0400 Subject: [PATCH] fix(c-bindings): relayTopics should trigger signal handler --- mobile/api.go | 6 ++---- mobile/api_relay.go | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/mobile/api.go b/mobile/api.go index 8a1580f8..f3de70b0 100644 --- a/mobile/api.go +++ b/mobile/api.go @@ -272,13 +272,11 @@ func Start() string { } for _, topic := range wakuState.relayTopics { - topic := topic - sub, err := wakuState.node.Relay().SubscribeToTopic(wakuState.ctx, topic) + err := relaySubscribe(topic) if err != nil { wakuState.node.Stop() - return MakeJSONResponse(fmt.Errorf("could not subscribe to topic: %s, %w", topic, err)) + return MakeJSONResponse(err) } - wakuState.node.Broadcaster().Unregister(&topic, sub.C) } return MakeJSONResponse(nil) diff --git a/mobile/api_relay.go b/mobile/api_relay.go index 764cd480..efc0379b 100644 --- a/mobile/api_relay.go +++ b/mobile/api_relay.go @@ -79,11 +79,7 @@ func RelayPublishEncodeSymmetric(messageJSON string, topic string, symmetricKey return PrepareJSONResponse(hash, err) } -func RelaySubscribe(topic string) string { - if wakuState.node == nil { - return MakeJSONResponse(errWakuNodeNotReady) - } - +func relaySubscribe(topic string) error { topicToSubscribe := getTopic(topic) relaySubsMutex.Lock() @@ -91,12 +87,12 @@ func RelaySubscribe(topic string) string { _, ok := relaySubscriptions[topicToSubscribe] if ok { - return MakeJSONResponse(nil) + return nil } subscription, err := wakuState.node.Relay().SubscribeToTopic(context.Background(), topicToSubscribe) if err != nil { - return MakeJSONResponse(err) + return err } relaySubscriptions[topicToSubscribe] = subscription @@ -107,7 +103,15 @@ func RelaySubscribe(topic string) string { } }(subscription) - return MakeJSONResponse(nil) + return nil +} + +func RelaySubscribe(topic string) string { + if wakuState.node == nil { + return MakeJSONResponse(errWakuNodeNotReady) + } + + return MakeJSONResponse(relaySubscribe(topic)) } func RelayUnsubscribe(topic string) string {