]> git.corax.cc Git - toolbox/commitdiff
include/ipc: Add catchall-topic that receives all pubsub messages
authorMatthias Kruk <m@m10k.eu>
Fri, 10 Mar 2023 10:47:02 +0000 (19:47 +0900)
committerMatthias Kruk <m@m10k.eu>
Fri, 10 Mar 2023 11:02:33 +0000 (20:02 +0900)
The current ipc implementation makes it impossible to tunnel all
pubsub messages between two systems because an endpoint would need
to subscribe all topics, including those that will be created after
the endpoint is opened.

This commit allows endpoints to subscribe the topic "*". Subscribers
that subscribe to this topic are called "taps" and receive messages
from all topics.

include/ipc.sh

index b6b6c9d2d7d46b28c51a33eff2573eca8feed12d..4d79232733bfe92958818f824d2e7803e1cf7f72 100644 (file)
@@ -654,7 +654,18 @@ _ipc_endpoint_topic_get_subscribers() {
                fi
 
                echo "$subscriber"
-       done < <(find "$(ipc_get_root)/pubsub/$topic" -mindepth 1 -maxdepth 1 -type l)
+       done < <(find "$(ipc_get_root)/pubsub/$topic" -mindepth 1 -maxdepth 1 -type l 2>/dev/null)
+
+       return 0
+}
+
+_ipc_endpoint_topic_get_subscribers_and_taps() {
+       local topic="$1"
+
+       {
+               _ipc_endpoint_topic_get_subscribers "$topic"
+               _ipc_endpoint_topic_get_subscribers "*"
+       } | sort | uniq
 
        return 0
 }
@@ -690,7 +701,7 @@ ipc_endpoint_publish() {
                        continue
                fi
                ipc_endpoint_send "$endpoint" "$subscriber" "$message" "$topic"
-       done < <(_ipc_endpoint_topic_get_subscribers "$topic")
+       done < <(_ipc_endpoint_topic_get_subscribers_and_taps "$topic")
 
        return 0
 }