chiark / gitweb /
Mobile sites: Maintain multiple addresses for some peers (new feature)
[secnet.git] / secnet.h
index b60972fb30fd3cfad9cfe02ee6820cd8fd697ad0..fbb7660da685e8721aac0a56a4e017845ffd69f5 100644 (file)
--- a/secnet.h
+++ b/secnet.h
@@ -303,16 +303,31 @@ struct rsaprivkey_if {
 
 /* COMM interface */
 
+struct comm_addr {
+    /* This struct is pure data; in particular comm's clients may
+       freely copy it. */
+    /* Everyone is also guaranteed that all padding is set to zero, ie
+       that comm_addrs referring to semantically identical peers will
+       compare equal with memcmp.  Anyone who constructs a comm_addr
+       must start by memsetting it with FILLZERO, or some
+       equivalent. */
+    struct comm_if *comm;
+    struct sockaddr_in sin;
+};
+
 /* Return True if the packet was processed, and shouldn't be passed to
    any other potential receivers. */
 typedef bool_t comm_notify_fn(void *state, struct buffer_if *buf,
-                           struct sockaddr_in *source);
+                             const struct comm_addr *source);
 typedef void comm_request_notify_fn(void *commst, void *nst,
                                    comm_notify_fn *fn);
 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,
-                              struct sockaddr_in *dest);
+                              const struct comm_addr *dest);
+typedef const char *comm_addr_to_string_fn(void *commst,
+                                          const struct comm_addr *ca);
+        /* Returned string is in a static buffer. */
 struct comm_if {
     void *st;
     int32_t min_start_pad;
@@ -320,6 +335,7 @@ struct comm_if {
     comm_request_notify_fn *request_notify;
     comm_release_notify_fn *release_notify;
     comm_sendmsg_fn *sendmsg;
+    comm_addr_to_string_fn *addr_to_string;
 };
 
 /* LOG interface */
@@ -495,4 +511,9 @@ extern void log_from_fd(int fd, cstring_t prefix, struct log_if *log);
 
 /***** END of log functions *****/
 
+#define STRING2(x) #x
+#define STRING(x) STRING2(x)
+
+#define FILLZERO(obj) (memset(&(obj),0,sizeof((obj))))
+
 #endif /* secnet_h */