fix(c-bindings): relayTopics should trigger signal handler

This commit is contained in:
Richard Ramos 2023-02-17 13:30:59 -04:00 committed by RichΛrd
parent 20f310a815
commit 4804588197
2 changed files with 14 additions and 12 deletions

View File

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

View File

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