server/peer.c: Engage the interval timer only while there are peers.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 19 May 2018 20:54:22 +0000 (21:54 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 25 Jan 2019 12:10:32 +0000 (12:10 +0000)
The reason we need the interval timer is (a) to top up the entropy pool,
and (b) to clean up old keysets.  If there are no peers, we do no key
exchange, so we don't need any random bits, and there are no keysets to
clear away.  So we can save wakeups in this case.

For now, there are stub versions of `iv_(add|rm)reason' in `test.c', but
these will vanish once we split `main' out into its own file.  (Spoiler
alert!)

server/peer.c
server/test.c
server/tripe.c

index fb01616..59a42cd 100644 (file)
@@ -992,6 +992,7 @@ peer *p_create(peerspec *spec)
   T( trace(T_TUNNEL, "peer: attached interface %s to peer `%s'",
           p->ifname, p_name(p)); )
   p_setkatimer(p);
+  iv_addreason();
   if (kx_setup(&p->kx, p, &p->ks, p->spec.f & PSF_KXMASK))
     goto tidy_4;
   a_notify("ADD",
@@ -1010,6 +1011,7 @@ tidy_4:
   if (spec->t_ka) sel_rmtimer(&p->tka);
   xfree(p->ifname);
   p->t->ops->destroy(p->t);
+  iv_rmreason();
 tidy_3:
   if (fd >= 0) close(fd);
 tidy_2:
@@ -1141,6 +1143,7 @@ void p_destroy(peer *p, int bye)
   }
   sym_remove(&byname, p->byname);
   am_remove(&byaddr, p->byaddr);
+  iv_rmreason();
   DESTROY(p);
 }
 
index 152a6fe..989bfd3 100644 (file)
@@ -90,6 +90,9 @@ static const char *getarg(void)
 static void lastarg(void)
   { if (*args) die(2, "unexpected argument `%s'", *args); }
 
+void iv_addreason(void) { ; }
+void iv_rmreason(void) { ; }
+
 int main(int argc, char *argv[])
 {
   const char *kr = "keyring";
index b4f4cc9..bf217b3 100644 (file)
@@ -418,8 +418,6 @@ int main(int argc, char *argv[])
     a_switcherr();
   }
 
-  iv_addreason();
-
   lp_run();
   return (0);
 }