[SECNET PATCH 06/14] comm: Introduce commcommon->why_unwanted

Ian Jackson ijackson at chiark.greenend.org.uk
Sat Sep 21 17:07:51 BST 2019


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 <ijackson at chiark.greenend.org.uk>
---
 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 dac2ca7..81c1ce4 100644
--- a/secnet.h
+++ b/secnet.h
@@ -46,8 +46,11 @@
 #define MAX_PEER_ADDRS 5
 /* send at most this many copies; honour at most that many addresses */
 
+#define MAX_NAK_MSG 80
+
 struct comm_if;
 struct comm_addr;
+struct priomsg;
 
 typedef char *string_t;
 typedef const char *cstring_t;
@@ -450,7 +453,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 d0dd909..e6eb12e 100644
--- a/site.c
+++ b/site.c
@@ -1815,7 +1815,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.11.0




More information about the sgo-software-discuss mailing list