1 // Copyright (c) 2013-2015 The btcsuite developers
2 // Use of this source code is governed by an ISC
3 // license that can be found in the LICENSE file.
12 // MsgPong implements the Message interface and represents a bitcoin pong
13 // message which is used primarily to confirm that a connection is still valid
14 // in response to a bitcoin ping message (MsgPing).
16 // This message was not added until protocol versions AFTER BIP0031Version.
18 // Unique value associated with message that is used to identify
19 // specific ping message.
23 // BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
24 // This is part of the Message interface implementation.
25 func (msg *MsgPong) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error {
26 // NOTE: <= is not a mistake here. The BIP0031 was defined as AFTER
27 // the version unlike most others.
28 if pver <= BIP0031Version {
29 str := fmt.Sprintf("pong message invalid for protocol "+
31 return messageError("MsgPong.BtcDecode", str)
34 return readElement(r, &msg.Nonce)
37 // BtcEncode encodes the receiver to w using the bitcoin protocol encoding.
38 // This is part of the Message interface implementation.
39 func (msg *MsgPong) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error {
40 // NOTE: <= is not a mistake here. The BIP0031 was defined as AFTER
41 // the version unlike most others.
42 if pver <= BIP0031Version {
43 str := fmt.Sprintf("pong message invalid for protocol "+
45 return messageError("MsgPong.BtcEncode", str)
48 return writeElement(w, msg.Nonce)
51 // Command returns the protocol command string for the message. This is part
52 // of the Message interface implementation.
53 func (msg *MsgPong) Command() string {
57 // MaxPayloadLength returns the maximum length the payload can be for the
58 // receiver. This is part of the Message interface implementation.
59 func (msg *MsgPong) MaxPayloadLength(pver uint32) uint32 {
61 // The pong message did not exist for BIP0031Version and earlier.
62 // NOTE: > is not a mistake here. The BIP0031 was defined as AFTER
63 // the version unlike most others.
64 if pver > BIP0031Version {
72 // NewMsgPong returns a new bitcoin pong message that conforms to the Message
73 // interface. See MsgPong for details.
74 func NewMsgPong(nonce uint64) *MsgPong {