diff options
author | José Bollo <jose.bollo@iot.bzh> | 2019-07-16 23:39:27 +0200 |
---|---|---|
committer | Jose Bollo <jose.bollo@iot.bzh> | 2019-07-18 15:39:52 +0200 |
commit | 037157919df0a7ee90837037748a6456431e6469 (patch) | |
tree | a33e3494a78052b73aea06b694b98298ea04de36 /src/afb-ws-json1.c | |
parent | a445694bda8773cb80566808b5dcb56f033dee58 (diff) |
Tag broadcasted events with UUID and hop
When API have mutual dependencies, leading to
loops in dependecies, broadcasting an event
never ends because of the loop (see SPEC-2625).
To avoid that weird flood of events, a unic
identifier (UUID) is attached to broadcasted
event and a tiny memory records previously
broadcasted events to avoid re-sending an
already sent event.
The size of the memory can be set using the
macro variable EVENT_BROADCAST_MEMORY_COUNT
whose default value is 8. It can be reduced
to 0.
An other mecanism is added to limit the count
of hops that a broadcasted event can do. That
count can be set using the macro variable
EVENT_BROADCAST_HOP_MAX whose default value
is 10.
Bug-AGL: SPEC-2625
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Change-Id: I45877583dbf478a79d405c3650880a5579ac1f9e
Diffstat (limited to 'src/afb-ws-json1.c')
-rw-r--r-- | src/afb-ws-json1.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/afb-ws-json1.c b/src/afb-ws-json1.c index 4f5cb868..5e71ff1f 100644 --- a/src/afb-ws-json1.c +++ b/src/afb-ws-json1.c @@ -46,7 +46,7 @@ struct afb_wsreq; static void aws_on_hangup_cb(void *closure, struct afb_wsj1 *wsj1); static void aws_on_call_cb(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg); static void aws_on_push_cb(void *closure, const char *event, int eventid, struct json_object *object); -static void aws_on_broadcast_cb(void *closure, const char *event, struct json_object *object); +static void aws_on_broadcast_cb(void *closure, const char *event, struct json_object *object, const uuid_binary_t uuid, uint8_t hop); /* predeclaration of wsreq callbacks */ static void wsreq_destroy(struct afb_xreq *xreq); @@ -207,15 +207,19 @@ static void aws_on_call_cb(void *closure, const char *api, const char *verb, str afb_xreq_process(&wsreq->xreq, ws->apiset); } +static void aws_on_event(struct afb_ws_json1 *aws, const char *event, struct json_object *object) +{ + afb_wsj1_send_event_j(aws->wsj1, event, afb_msg_json_event(event, object)); +} + static void aws_on_push_cb(void *closure, const char *event, int eventid, struct json_object *object) { - aws_on_broadcast_cb(closure, event, object); + aws_on_event(closure, event, object); } -static void aws_on_broadcast_cb(void *closure, const char *event, struct json_object *object) +static void aws_on_broadcast_cb(void *closure, const char *event, struct json_object *object, const uuid_binary_t uuid, uint8_t hop) { - struct afb_ws_json1 *aws = closure; - afb_wsj1_send_event_j(aws->wsj1, event, afb_msg_json_event(event, object)); + aws_on_event(closure, event, afb_msg_json_event(event, object)); } /*************************************************************** |