diff options
Diffstat (limited to 'components/wisp_relay/broadcaster.c')
| -rw-r--r-- | components/wisp_relay/broadcaster.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/components/wisp_relay/broadcaster.c b/components/wisp_relay/broadcaster.c new file mode 100644 index 0000000..738cbdb --- /dev/null +++ b/components/wisp_relay/broadcaster.c | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | #include "broadcaster.h" | ||
| 2 | #include "relay_core.h" | ||
| 3 | #include "router.h" | ||
| 4 | #include "sub_manager.h" | ||
| 5 | #include "esp_log.h" | ||
| 6 | |||
| 7 | static const char *TAG = "broadcaster"; | ||
| 8 | |||
| 9 | void broadcaster_fanout_json(relay_ctx_t *ctx, const char *event_json, | ||
| 10 | size_t event_len, int event_kind, | ||
| 11 | const char *event_pubkey_hex, | ||
| 12 | uint64_t event_created_at) | ||
| 13 | { | ||
| 14 | if (!ctx || !ctx->sub_manager) return; | ||
| 15 | |||
| 16 | sub_match_result_t matches; | ||
| 17 | sub_manager_match_json(ctx->sub_manager, event_json, event_len, event_kind, | ||
| 18 | event_pubkey_hex, event_created_at, &matches); | ||
| 19 | |||
| 20 | if (matches.count == 0) { | ||
| 21 | ESP_LOGD(TAG, "No subscribers for event kind=%d", event_kind); | ||
| 22 | return; | ||
| 23 | } | ||
| 24 | |||
| 25 | ESP_LOGD(TAG, "Broadcasting event kind=%d to %d subscriptions", | ||
| 26 | event_kind, matches.count); | ||
| 27 | |||
| 28 | for (uint8_t i = 0; i < matches.count; i++) { | ||
| 29 | sub_match_entry_t *entry = &matches.matches[i]; | ||
| 30 | router_send_event(ctx, entry->conn_fd, entry->sub_id, | ||
| 31 | event_json, event_len); | ||
| 32 | } | ||
| 33 | } | ||