diff --git a/wire/message.go b/wire/message.go index aaf803dd..fe9fa48c 100644 --- a/wire/message.go +++ b/wire/message.go @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2015 The btcsuite developers +// Copyright (c) 2013-2016 The btcsuite developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -243,19 +243,17 @@ func WriteMessageN(w io.Writer, msg Message, pver uint32, btcnet BitcoinNet) (in // Write header. n, err := w.Write(hw.Bytes()) + totalBytes += n if err != nil { - totalBytes += n return totalBytes, err } - totalBytes += n // Write payload. n, err = w.Write(payload) + totalBytes += n if err != nil { - totalBytes += n return totalBytes, err } - totalBytes += n return totalBytes, nil } @@ -278,11 +276,10 @@ func WriteMessage(w io.Writer, msg Message, pver uint32, btcnet BitcoinNet) erro func ReadMessageN(r io.Reader, pver uint32, btcnet BitcoinNet) (int, Message, []byte, error) { totalBytes := 0 n, hdr, err := readMessageHeader(r) + totalBytes += n if err != nil { - totalBytes += n return totalBytes, nil, nil, err } - totalBytes += n // Enforce maximum message payload. if hdr.length > MaxMessagePayload { @@ -331,11 +328,10 @@ func ReadMessageN(r io.Reader, pver uint32, btcnet BitcoinNet) (int, Message, [] // Read payload. payload := make([]byte, hdr.length) n, err = io.ReadFull(r, payload) + totalBytes += n if err != nil { - totalBytes += n return totalBytes, nil, nil, err } - totalBytes += n // Test checksum. checksum := DoubleSha256(payload)[0:4] diff --git a/wire/msgversion.go b/wire/msgversion.go index 6c76e239..4466f0f0 100644 --- a/wire/msgversion.go +++ b/wire/msgversion.go @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2015 The btcsuite developers +// Copyright (c) 2013-2016 The btcsuite developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -61,10 +61,7 @@ type MsgVersion struct { // HasService returns whether the specified service is supported by the peer // that generated the message. func (msg *MsgVersion) HasService(service ServiceFlag) bool { - if msg.Services&service == service { - return true - } - return false + return msg.Services&service == service } // AddService adds service as a supported service by the peer generating the