Update byte counts unconditionally.
Rather than updating the byte counts in the error path and after the error path, do it unconditionally before checking the error.
This commit is contained in:
parent
c51df0ca3c
commit
6f063e0c1b
1 changed files with 5 additions and 9 deletions
14
peer.go
14
peer.go
|
@ -955,13 +955,11 @@ func (p *peer) handlePongMsg(msg *btcwire.MsgPong) {
|
|||
// readMessage reads the next bitcoin message from the peer with logging.
|
||||
func (p *peer) readMessage() (btcwire.Message, []byte, error) {
|
||||
n, msg, buf, err := btcwire.ReadMessageN(p.conn, p.protocolVersion, p.btcnet)
|
||||
if err != nil {
|
||||
p.bytesReceived += uint64(n)
|
||||
atomic.AddUint64(&p.server.bytesReceived, uint64(n))
|
||||
return nil, nil, err
|
||||
}
|
||||
p.bytesReceived += uint64(n)
|
||||
atomic.AddUint64(&p.server.bytesReceived, uint64(n))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Use closures to log expensive operations so they are only run when
|
||||
// the logging level requires it.
|
||||
|
@ -1026,15 +1024,13 @@ func (p *peer) writeMessage(msg btcwire.Message) {
|
|||
|
||||
// Write the message to the peer.
|
||||
n, err := btcwire.WriteMessageN(p.conn, msg, p.protocolVersion, p.btcnet)
|
||||
p.bytesSent += uint64(n)
|
||||
atomic.AddUint64(&p.server.bytesSent, uint64(n))
|
||||
if err != nil {
|
||||
p.bytesSent += uint64(n)
|
||||
atomic.AddUint64(&p.server.bytesSent, uint64(n))
|
||||
p.Disconnect()
|
||||
p.logError("Can't send message: %v", err)
|
||||
return
|
||||
}
|
||||
p.bytesSent += uint64(n)
|
||||
atomic.AddUint64(&p.server.bytesSent, uint64(n))
|
||||
}
|
||||
|
||||
// isAllowedByRegression returns whether or not the passed error is allowed by
|
||||
|
|
Loading…
Reference in a new issue