chiark / gitweb /
server/peer.c: Delay updating peer stats.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 6 May 2012 23:31:03 +0000 (00:31 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 7 May 2012 14:32:06 +0000 (15:32 +0100)
Previously we'd update as soon as we'd found a peer, but that's not
quite right.  We're going to have p_decrypt change our mind about which
peer this if we get a decryption error, so it'd be bad if we'd
prematurely updated the wrong peer.

server/peer.c

index 68e32e58de87bab89701e622af59b4c9e2bb6cb0..a62b20a8dfd32a5c298a4dcc36fff27351366ee4 100644 (file)
@@ -228,7 +228,6 @@ static int p_decrypt(peer **pp, addr *a, size_t n,
     }
     if (!err) {
       T( trace(T_PEER, "peer: updating address for `%s'", p_name(p)); )
-      p_rxupdstats(p, n);
       pa = am_find(&byaddr, a, sizeof(peer_byaddr), &f); assert(!f);
       am_remove(&byaddr, p->byaddr);
       p->byaddr = pa;
@@ -237,6 +236,7 @@ static int p_decrypt(peer **pp, addr *a, size_t n,
       a_notify("NEWADDR", "?PEER", p, "?ADDR", a, A_END);
     }
   }
+  p_rxupdstats(p, n);
   if (err) {
     if (p) p->st.n_reject++;
     a_warn("PEER", "?PEER", p, "decrypt-failed",
@@ -321,7 +321,6 @@ static void p_read(int fd, unsigned mode, void *v)
 
   /* --- Pick the packet apart --- */
 
-  if (p) p_rxupdstats(p, n);
   buf_init(&b, buf_i, n);
   if ((ch = buf_getbyte(&b)) < 0) {
     a_warn("PEER", "?PEER", p, "bad-packet", "no-type", A_END);
@@ -352,21 +351,25 @@ static void p_read(int fd, unsigned mode, void *v)
       break;
     case MSG_KEYEXCH:
       if (!p) goto unexp;
+      p_rxupdstats(p, n);
       kx_message(&p->kx, ch & MSG_TYPEMASK, &b);
       break;
     case MSG_MISC:
       switch (ch & MSG_TYPEMASK) {
        case MISC_NOP:
          if (!p) goto unexp;
+         p_rxupdstats(p, n);
          T( trace(T_PEER, "peer: received NOP packet"); )
          break;
        case MISC_PING:
          if (!p) goto unexp;
+         p_rxupdstats(p, n);
          buf_put(p_txstart(p, MSG_MISC | MISC_PONG), BCUR(&b), BLEFT(&b));
          p_txend(p);
          break;
        case MISC_PONG:
          if (!p) goto unexp;
+         p_rxupdstats(p, n);
          p_ponged(p, MISC_PONG, &b);
          break;
        case MISC_EPING: