chiark / gitweb /
comm: Introduce commcommon->why_unwanted
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 21 Sep 2019 14:15:39 +0000 (15:15 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 24 Oct 2019 18:16:17 +0000 (19:16 +0100)
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@chiark.greenend.org.uk>
comm-common.c
comm-common.h
secnet.h
site.c

index 28580be3f3dc5878fe81c8d5935bd72126615e30..48041cd8e2fb857a6643165487522673bb093484 100644 (file)
@@ -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);
 }
index a038947109250bc7395665b104dfbbe3cb573d64..45340e4202e8bfe6a05dd906a4a1090e9ee80eec 100644 (file)
@@ -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);
 
index 5b1e24b402fff7bb8c3426425bb937ae93fdb3f4..95f3413325a8ef3319b3b2402698d583ec0242b5 100644 (file)
--- a/secnet.h
+++ b/secnet.h
 #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 eb146e1baabd1c3e031c86b4960f2d7fd27d35b8..df87ea124203aa6801e6955e2f08ea494a0a0c6d 100644 (file)
--- 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;