From 9b9a3fb20a336efb33902289e2b2eab6a9391e26 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Fri, 5 Feb 2016 01:17:06 +1100 Subject: [PATCH] Fix the mess that is the connectionLoop after messages are decoded --- client.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/client.go b/client.go index 3cd3d668..34921bd7 100644 --- a/client.go +++ b/client.go @@ -69,6 +69,7 @@ var ( // Number of completed connections to a client we're already connected with. duplicateClientConns = expvar.NewInt("duplicateClientConns") receivedMessageTypes = expvar.NewMap("receivedMessageTypes") + receivedKeepalives = expvar.NewInt("receivedKeepalives") supportedExtensionMessages = expvar.NewMap("supportedExtensionMessages") ) @@ -1386,21 +1387,19 @@ func (me *Client) connectionLoop(t *torrent, c *connection) error { me.mu.Unlock() var msg pp.Message err := decoder.Decode(&msg) - receivedMessageTypes.Add(strconv.FormatInt(int64(msg.Type), 10), 1) me.mu.Lock() - c.lastMessageReceived = time.Now() - if c.closed.IsSet() { + if me.stopped() || c.closed.IsSet() || err == io.EOF { return nil } if err != nil { - if me.stopped() || err == io.EOF { - return nil - } return err } + c.lastMessageReceived = time.Now() if msg.Keepalive { + receivedKeepalives.Add(1) continue } + receivedMessageTypes.Add(strconv.FormatInt(int64(msg.Type), 10), 1) switch msg.Type { case pp.Choke: c.PeerChoked = true -- 2.48.1