From 780f3f09eb7833c57a0847ce3cd473dbb6ba3b36 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 21 Sep 2019 15:15:39 +0100 Subject: [PATCH] comm: Introduce commcommon->why_unwanted This will "accumulate" a message. It will give the information about why the closest approach to wanting this message ultimately rejected it. No overall functional change with current code: nothing ever either updates this yet, or uses it. Users will come next. Signed-off-by: Ian Jackson --- comm-common.c | 5 ++++- comm-common.h | 6 ++++-- secnet.h | 6 +++++- site.c | 3 ++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/comm-common.c b/comm-common.c index 28580be..48041cd 100644 --- a/comm-common.c +++ b/comm-common.c @@ -57,8 +57,10 @@ bool_t comm_notify(struct commcommon *cc, struct comm_notify_list *notify = &cc->notify; struct comm_notify_entry *n; + priomsg_reset(&cc->why_unwanted); + LIST_FOREACH(n, notify, entry) { - if (n->fn(n->state, buf, ca)) { + if (n->fn(n->state, buf, ca, &cc->why_unwanted)) { return True; } } @@ -76,4 +78,5 @@ void comm_apply(struct commcommon *cc, void *st) cc->ops.release_notify=comm_release_notify; LIST_INIT(&cc->notify); cc->rbuf=NULL; + priomsg_new(&cc->why_unwanted, MAX_NAK_MSG); } diff --git a/comm-common.h b/comm-common.h index a038947..45340e4 100644 --- a/comm-common.h +++ b/comm-common.h @@ -38,6 +38,7 @@ struct commcommon { /* must be first so that void* is comm_common* */ struct cloc loc; struct comm_notify_list notify; struct buffer_if *rbuf; + struct priomsg why_unwanted; }; struct comm_clientinfo *comm_clientinfo_ignore(void *state, dict_t*, @@ -48,8 +49,9 @@ void comm_release_notify(void *commst, void *nst, comm_notify_fn *fn); bool_t comm_notify(struct commcommon*, struct buffer_if *buf, const struct comm_addr *ca); /* Either: returns True, with message delivered and buffer freed. - * Or: False, if no-one wanted it - buffer still allocd'd. - * Ie, like comm_notify_fn. */ + * Or: False, if no-one wanted it - buffer still allocd'd; + * in that case, cc->why_unwanted has info + * Ie, roughly like comm_notify_fn. */ void comm_apply(struct commcommon *cc, void *st); diff --git a/secnet.h b/secnet.h index 5b1e24b..95f3413 100644 --- a/secnet.h +++ b/secnet.h @@ -46,9 +46,12 @@ #define MAX_PEER_ADDRS 5 /* send at most this many copies; honour at most that many addresses */ +#define MAX_NAK_MSG 80 + struct hash_if; struct comm_if; struct comm_addr; +struct priomsg; typedef char *string_t; typedef const char *cstring_t; @@ -465,7 +468,8 @@ typedef struct comm_clientinfo *comm_clientinfo_fn(void *state, dict_t*, /* Return True if the packet was processed, and shouldn't be passed to any other potential receivers. (buf is freed iff True returned.) */ typedef bool_t comm_notify_fn(void *state, struct buffer_if *buf, - const struct comm_addr *source); + const struct comm_addr *source, + struct priomsg *whynot); typedef void comm_request_notify_fn(void *commst, void *nst, comm_notify_fn *fn); typedef void comm_release_notify_fn(void *commst, void *nst, diff --git a/site.c b/site.c index eb146e1..df87ea1 100644 --- a/site.c +++ b/site.c @@ -1867,7 +1867,8 @@ static bool_t setup_late_msg_ok(struct site *st, this current site instance (and should therefore not be processed by other sites), even if the packet was otherwise ignored. */ static bool_t site_incoming(void *sst, struct buffer_if *buf, - const struct comm_addr *source) + const struct comm_addr *source, + struct priomsg *whynot) { struct site *st=sst; -- 2.30.2