1 // Copyright (c) 2016 The btcsuite developers
2 // Use of this source code is governed by an ISC
3 // license that can be found in the LICENSE file.
4 5 package wire
6 7 import (
8 "fmt"
9 "io"
10 )
11 12 // MsgSendHeaders implements the Message interface and represents a bitcoin
13 // sendheaders message. It is used to request the peer send block headers
14 // rather than inventory vectors.
15 //
16 // This message has no payload and was not added until protocol versions
17 // starting with SendHeadersVersion.
18 type MsgSendHeaders struct{}
19 20 // BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
21 // This is part of the Message interface implementation.
22 func (msg *MsgSendHeaders) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error {
23 if pver < SendHeadersVersion {
24 str := fmt.Sprintf("sendheaders message invalid for protocol "+
25 "version %d", pver)
26 return messageError("MsgSendHeaders.BtcDecode", str)
27 }
28 29 return nil
30 }
31 32 // BtcEncode encodes the receiver to w using the bitcoin protocol encoding.
33 // This is part of the Message interface implementation.
34 func (msg *MsgSendHeaders) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error {
35 if pver < SendHeadersVersion {
36 str := fmt.Sprintf("sendheaders message invalid for protocol "+
37 "version %d", pver)
38 return messageError("MsgSendHeaders.BtcEncode", str)
39 }
40 41 return nil
42 }
43 44 // Command returns the protocol command string for the message. This is part
45 // of the Message interface implementation.
46 func (msg *MsgSendHeaders) Command() string {
47 return CmdSendHeaders
48 }
49 50 // MaxPayloadLength returns the maximum length the payload can be for the
51 // receiver. This is part of the Message interface implementation.
52 func (msg *MsgSendHeaders) MaxPayloadLength(pver uint32) uint32 {
53 return 0
54 }
55 56 // NewMsgSendHeaders returns a new bitcoin sendheaders message that conforms to
57 // the Message interface. See MsgSendHeaders for details.
58 func NewMsgSendHeaders() *MsgSendHeaders {
59 return &MsgSendHeaders{}
60 }
61