From: Mark Wooding Date: Sun, 6 May 2012 23:31:03 +0000 (+0100) Subject: server/peer.c: Delay updating peer stats. X-Git-Tag: 1.0.0pre11~9 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/tripe/commitdiff_plain/88622d1dc9b1c03e95552817151047e574b312d4?ds=sidebyside server/peer.c: Delay updating peer stats. 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. --- diff --git a/server/peer.c b/server/peer.c index 68e32e58..a62b20a8 100644 --- a/server/peer.c +++ b/server/peer.c @@ -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: