Skip to content

Commit

Permalink
wire: Minor code clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
jongillham committed Jan 26, 2016
1 parent e03fa30 commit 95361a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
14 changes: 5 additions & 9 deletions wire/message.go
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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]
Expand Down
7 changes: 2 additions & 5 deletions wire/msgversion.go
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 95361a2

Please sign in to comment.