comm clientinfo: Provide clientinfo interface
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 23 Apr 2017 11:36:44 +0000 (12:36 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 23 Apr 2017 16:14:43 +0000 (17:14 +0100)
This will allow a comm client to provide information from its
configuration dicts to the comm, so that a comm can be shared by
multiple clients but still have client-specific configuration.

Currently, this new interface has no callers, and no consumers.
No comm clients call comm_if->_clientinfo(); they all just pass NULL.
No comms take any notice of the clientinfo information; they always
return NULL for the clientinfo*.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
comm-common.c
comm-common.h
polypath.c
secnet.h
site.c
udp.c
util.c

index a384ba6..4bbc871 100644 (file)
 #include "secnet.h"
 #include "comm-common.h"
 
+struct comm_clientinfo *comm_clientinfo_ignore(void *state, dict_t *dict,
+                                              struct cloc cloc)
+{
+    return 0;
+}
+
 void comm_request_notify(void *commst, void *nst, comm_notify_fn *fn)
 {
     struct commcommon *st=commst;
index b517f95..ebb71b8 100644 (file)
@@ -40,6 +40,8 @@ struct commcommon { /* must be first so that void* is comm_common* */
     struct buffer_if *rbuf;
 };
 
+struct comm_clientinfo *comm_clientinfo_ignore(void *state, dict_t*,
+                                              struct cloc cloc);
 void comm_request_notify(void *commst, void *nst, comm_notify_fn *fn);
 void comm_release_notify(void *commst, void *nst, comm_notify_fn *fn);
 
@@ -55,6 +57,7 @@ void comm_apply(struct commcommon *cc, void *st);
     NEW(st);                                           \
     (cc)->loc=loc;                                     \
     (cc)->cl.description=desc;                         \
+    (cc)->ops.clientinfo=comm_clientinfo_ignore;       \
     (cc)->ops.sendmsg=prefix##sendmsg;                 \
     (cc)->ops.addr_to_string=prefix##addr_to_string;   \
     comm_apply((cc),(st))
index cea465e..0f68a49 100644 (file)
@@ -443,7 +443,8 @@ static void polypath_afterpoll_monitor(void *state, struct pollfd *fds,
 
 /* Actual udp packet sending work */
 static bool_t polypath_sendmsg(void *commst, struct buffer_if *buf,
-                         const struct comm_addr *dest)
+                         const struct comm_addr *dest,
+                         struct comm_clientinfo *clientinfo)
 {
     struct polypath *st=commst;
     struct interf *interf;
index 63307ac..8c628f6 100644 (file)
--- a/secnet.h
+++ b/secnet.h
@@ -437,6 +437,15 @@ struct comm_addr {
     int ix; /* see comment `Re comm_addr.ix' in udp.c */
 };
 
+struct comm_clientinfo; /* private for comm */
+
+typedef struct comm_clientinfo *comm_clientinfo_fn(void *state, dict_t*,
+                                                  struct cloc cloc);
+/* A comm client may call this during configuration, and then pass
+ * the resulting comm_clientinfo* to some or all sendmsg calls.
+ * The semantics depend on the dict and defined by the comm, and
+ * should be documented in README. */
+
 /* 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,
@@ -446,7 +455,8 @@ typedef void comm_request_notify_fn(void *commst, void *nst,
 typedef void comm_release_notify_fn(void *commst, void *nst,
                                    comm_notify_fn *fn);
 typedef bool_t comm_sendmsg_fn(void *commst, struct buffer_if *buf,
-                              const struct comm_addr *dest);
+                              const struct comm_addr *dest,
+                              struct comm_clientinfo* /* 0 OK */);
   /* Only returns false if (we know that) the local network
    * environment is such that this address cannot work; transient
    * or unknown/unexpected failures return true. */
@@ -455,6 +465,7 @@ typedef const char *comm_addr_to_string_fn(void *commst,
         /* Returned string is in a static buffer. */
 struct comm_if {
     void *st;
+    comm_clientinfo_fn *clientinfo;
     comm_request_notify_fn *request_notify;
     comm_release_notify_fn *release_notify;
     comm_sendmsg_fn *sendmsg;
diff --git a/site.c b/site.c
index 412567b..4ce4c24 100644 (file)
--- a/site.c
+++ b/site.c
@@ -1187,7 +1187,7 @@ static bool_t comm_addr_sendmsg(struct site *st,
                                const struct comm_addr *dest,
                                struct buffer_if *buf)
 {
-    return dest->comm->sendmsg(dest->comm->st, buf, dest);
+    return dest->comm->sendmsg(dest->comm->st, buf, dest, 0);
 }
 
 static uint32_t site_status(void *st)
diff --git a/udp.c b/udp.c
index 451e6e9..1535f29 100644 (file)
--- a/udp.c
+++ b/udp.c
@@ -201,7 +201,8 @@ static void udp_socks_afterpoll(void *state, struct pollfd *fds, int nfds)
 }
 
 static bool_t udp_sendmsg(void *commst, struct buffer_if *buf,
-                         const struct comm_addr *dest)
+                         const struct comm_addr *dest,
+                         struct comm_clientinfo *clientinfo)
 {
     struct udp *st=commst;
     struct udpcommon *uc=&st->uc;
diff --git a/util.c b/util.c
index a91c073..7036061 100644 (file)
--- a/util.c
+++ b/util.c
@@ -448,7 +448,7 @@ void send_nak(const struct comm_addr *dest, uint32_t our_index,
                " %s; sending NAK\n",
                comm_addr_to_string(dest),
                our_index, their_index, msgtype, logwhy);
-    dest->comm->sendmsg(dest->comm->st, buf, dest);
+    dest->comm->sendmsg(dest->comm->st, buf, dest, 0);
 }
 
 int consttime_memeq(const void *s1in, const void *s2in, size_t n)