chiark / gitweb /
server/peer.c: Abstract out updating a peer's address.
[tripe] / server / tripe.h
index ad2c0bd73068a1a40af673f651dbc980375a36a8..e7c47ecdc44156afdf634407429071b64d9cae36 100644 (file)
@@ -9,19 +9,18 @@
  *
  * This file is part of Trivial IP Encryption (TrIPE).
  *
- * TrIPE is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * TrIPE is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your
+ * option) any later version.
  *
- * TrIPE is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * TrIPE is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with TrIPE; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * along with TrIPE.  If not, see <https://www.gnu.org/licenses/>.
  */
 
 #ifndef TRIPE_H
@@ -67,6 +66,7 @@
 #include <mLib/arena.h>
 #include <mLib/base64.h>
 #include <mLib/bres.h>
+#include <mLib/codec.h>
 #include <mLib/daemonize.h>
 #include <mLib/dstr.h>
 #include <mLib/env.h>
 #include <catacomb/ec.h>
 #include <catacomb/ec-raw.h>
 #include <catacomb/ec-keys.h>
+#include <catacomb/x25519.h>
+#include <catacomb/x448.h>
 
 #include "priv.h"
 #include "protocol.h"
@@ -200,7 +202,7 @@ typedef struct dhops {
   int (*ldpriv)(key_file */*kf*/, key */*k*/, key_data */*d*/,
                kdata */*kd*/, dstr */*t*/, dstr */*e*/);
        /* Load a private key from @d@, storing the data in @kd@.  The key's
-        * file and key object are in @kf@ and @k, mostly in case its
+        * file and key object are in @kf@ and @k@, mostly in case its
         * attributes are interesting; the key tag is in @t@; errors are
         * reported by writing tokens to @e@ and returning nonzero.
         */
@@ -208,7 +210,7 @@ typedef struct dhops {
   int (*ldpub)(key_file */*kf*/, key */*k*/, key_data */*d*/,
               kdata */*kd*/, dstr */*t*/, dstr */*e*/);
        /* Load a public key from @d@, storing the data in @kd@.  The key's
-        * file and key object are in @kf@ and @k, mostly in case its
+        * file and key object are in @kf@ and @k@, mostly in case its
         * attributes are interesting; the key tag is in @t@; errors are
         * reported by writing tokens to @e@ and returning nonzero.
         */
@@ -593,7 +595,6 @@ typedef struct peerspec {
   const tunnel_ops *tops;              /* Tunnel operations */
   unsigned long t_ka;                  /* Keep alive interval */
   addr sa;                             /* Socket address to speak to */
-  size_t sasz;                         /* Socket address size */
   unsigned f;                          /* Flags for the peer */
 #define PSF_KXMASK 255u                        /*   Key-exchange flags to set */
 #define PSF_MOBILE 256u                        /*   Address may change rapidly */
@@ -973,9 +974,8 @@ extern void ks_derivekey(octet */*k*/, size_t /*ksz*/,
  *             the key material; between @k + x@ and @k + y@ is `your'
  *             contribution; and between @k + y@ and @k + z@ is a shared
  *             value we made together.  These are used to construct two
- *             pairs of symmetric keys.  Each pair consists of an encryption
- *             key and a message authentication key.  One pair is used for
- *             outgoing messages, the other for incoming messages.
+ *             collections of symmetric keys: one for outgoing messages, the
+ *             other for incoming messages.
  *
  *             The new key is marked so that it won't be selected for output
  *             by @ksl_encrypt@.  You can still encrypt data with it by
@@ -1409,6 +1409,19 @@ extern void ps_quit(void);
 
 /*----- Peer management ---------------------------------------------------*/
 
+/* --- @p_updateaddr@ --- *
+ *
+ * Arguments:  @peer *p@ = pointer to peer block
+ *             @const addr *a@ = address to associate with this peer
+ *
+ * Returns:    Zero if the address was changed; @+1@ if it was already
+ *             right.
+ *
+ * Use:                Updates our idea of @p@'s address.
+ */
+
+extern int p_updateaddr(peer */*p*/, const addr */*a*/);
+
 /* --- @p_txstart@ --- *
  *
  * Arguments:  @peer *p@ = pointer to peer block
@@ -1729,6 +1742,15 @@ extern const char *timestr(time_t /*t*/);
 
 extern int mystrieq(const char */*x*/, const char */*y*/);
 
+/* --- @addrsz@ --- *
+ *
+ * Arguments:  @const addr *a@ = a network address
+ *
+ * Returns:    The size of the address, for passing into the sockets API.
+ */
+
+extern socklen_t addrsz(const addr */*a*/);
+
 /* --- @seq_reset@ --- *
  *
  * Arguments:  @seqwin *s@ = sequence-checking window