From: Matthias Kruk Date: Fri, 10 Mar 2023 10:47:02 +0000 (+0900) Subject: include/ipc: Add catchall-topic that receives all pubsub messages X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=3cf8f33416c20451a98af71dc32ebde58abe0e73;p=toolbox include/ipc: Add catchall-topic that receives all pubsub messages 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. --- diff --git a/include/ipc.sh b/include/ipc.sh index b6b6c9d..4d79232 100644 --- a/include/ipc.sh +++ b/include/ipc.sh @@ -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 }