From 5df25ffa59b83e2f37b00f4dbb14ca8abdb9bad1 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Sat, 10 Apr 2021 22:24:11 +0200 Subject: [PATCH] Fix lookupTopic --- src/App.h | 2 +- src/TopicTree.h | 32 ++++++++++++++++---------------- src/WebSocket.h | 9 +++++++-- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/App.h b/src/App.h index e9d9741..aa1f0a5 100644 --- a/src/App.h +++ b/src/App.h @@ -114,7 +114,7 @@ public: for (auto *webSocketContext : webSocketContexts) { auto *webSocketContextData = webSocketContext->getExt(); - Topic *t = webSocketContextData->lookupTopic(topic); + Topic *t = webSocketContextData->topicTree.lookupTopic(topic); if (t) { subscribers += t->subs.size(); } diff --git a/src/TopicTree.h b/src/TopicTree.h index 82d06e3..a404ba5 100644 --- a/src/TopicTree.h +++ b/src/TopicTree.h @@ -139,22 +139,6 @@ struct Intersection { }; struct TopicTree { -private: - std::function cb; - - Topic *root = new Topic; - - /* Global messageId for deduplication of overlapping topics and ordering between topics */ - unsigned int messageId = 0; - - /* Sender holes */ - std::map> senderHoles; - - /* The triggered topics */ - Topic *triggeredTopics[64]; - int numTriggeredTopics = 0; - Subscriber *min = (Subscriber *) UINTPTR_MAX; - /* Returns Topic, or nullptr. Topic can be root if empty string given. */ Topic *lookupTopic(std::string_view topic) { /* Lookup exact Topic ptr from string */ @@ -175,6 +159,22 @@ private: return iterator; } +private: + std::function cb; + + Topic *root = new Topic; + + /* Global messageId for deduplication of overlapping topics and ordering between topics */ + unsigned int messageId = 0; + + /* Sender holes */ + std::map> senderHoles; + + /* The triggered topics */ + Topic *triggeredTopics[64]; + int numTriggeredTopics = 0; + Subscriber *min = (Subscriber *) UINTPTR_MAX; + /* Cull or trim unused Topic nodes from leaf to root */ void trimTree(Topic *topic) { while (!topic->subs.size() && !topic->children.size() && !topic->terminatingWildcardChild && !topic->wildcardChild) { diff --git a/src/WebSocket.h b/src/WebSocket.h index 64f864f..39ca0b2 100644 --- a/src/WebSocket.h +++ b/src/WebSocket.h @@ -230,9 +230,14 @@ public: (us_socket_context_t *) us_socket_context(SSL, (us_socket_t *) this) ); - Topic *t = webSocketContextData->lookupTopic(topic); + WebSocketData *webSocketData = (WebSocketData *) us_socket_ext(SSL, (us_socket_t *) this); + if (!webSocketData->subscriber) { + return false; + } + + Topic *t = webSocketContextData->topicTree.lookupTopic(topic); if (t) { - return t->subs.find(this) != t->subs.end(); + return t->subs.find(webSocketData->subscriber) != t->subs.end(); } return false;