chiark / gitweb /
Add notion of `ephemeral' associations and a goodbye protocol.
[tripe] / proxy / tripe-mitm.c
index ee7036c244b8ea01cf2df54a2c4215c879ad95c6..bd57306d7f08c203e0d2085a10ba62973353363d 100644 (file)
@@ -72,7 +72,6 @@
 
 typedef struct peer {
   sel_file sf;
-  dh_pub kpub;
   const char *name;
   struct filter *f;
 } peer;
@@ -117,26 +116,20 @@ static void dopacket(int fd, unsigned mode, void *vv)
 
 static void addpeer(unsigned ac, char **av)
 {
-  key_packstruct kps[DH_PUBFETCHSZ];
-  key_packdef *kp;
   struct hostent *h;
   struct sockaddr_in sin;
   int len = PKBUFSZ;
   peer *p;
   int fd;
-  int e;
 
   if (ac != 4)
     die(1, "syntax: peer:NAME:PORT:ADDR:PORT");
   if (npeer >= 2)
     die(1, "enough peers already");
+  if (!key_bytag(&keys, av[0]))
+    die(1, "no key named `%s'", av[0]);
   p = &peers[npeer++];
   p->name = xstrdup(av[0]);
-  kp = key_fetchinit(dh_pubfetch, kps, &p->kpub);
-  e = key_fetchbyname(kp, &keys, av[0]);
-  key_fetchdone(kp);
-  if (e)
-    die(1, "key_fetch `%s': %s", av[0], key_strerror(e));
   if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0)
     die(1, "socket: %s", strerror(errno));
   fdflags(fd, O_NONBLOCK, O_NONBLOCK, FD_CLOEXEC, FD_CLOEXEC);
@@ -721,8 +714,10 @@ int main(int argc, char *argv[])
     parse(argv[i]);
   if (npeer != 2)
     die(1, "need two peers");
-  for (;;)
-    sel_select(&sel);
+  for (;;) {
+    if (sel_select(&sel) && errno != EINTR)
+      die(1, "select failed: %s", strerror(errno));
+  }
 
 #undef f_bogus
 }