mirror of
https://github.com/btcsuite/btcd.git
synced 2025-01-18 21:32:30 +01:00
wire: Minor code clean up.
This commit is contained in:
parent
e03fa30e89
commit
95361a2afc
@ -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]
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user