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.
11 // MsgPing implements the Message interface and represents a bitcoin ping
14 // For versions BIP0031Version and earlier, it is used primarily to confirm
15 // that a connection is still valid. A transmission error is typically
16 // interpreted as a closed connection and that the peer should be removed.
17 // For versions AFTER BIP0031Version it contains an identifier which can be
18 // returned in the pong message to determine network timing.
20 // The payload for this message just consists of a nonce used for identifying
23 // Unique value associated with message that is used to identify
24 // specific ping message.
28 // BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
29 // This is part of the Message interface implementation.
30 func (msg *MsgPing) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error {
31 // There was no nonce for BIP0031Version and earlier.
32 // NOTE: > is not a mistake here. The BIP0031 was defined as AFTER
33 // the version unlike most others.
34 if pver > BIP0031Version {
35 err := readElement(r, &msg.Nonce)
44 // BtcEncode encodes the receiver to w using the bitcoin protocol encoding.
45 // This is part of the Message interface implementation.
46 func (msg *MsgPing) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error {
47 // There was no nonce for BIP0031Version and earlier.
48 // NOTE: > is not a mistake here. The BIP0031 was defined as AFTER
49 // the version unlike most others.
50 if pver > BIP0031Version {
51 err := writeElement(w, msg.Nonce)
60 // Command returns the protocol command string for the message. This is part
61 // of the Message interface implementation.
62 func (msg *MsgPing) Command() string {
66 // MaxPayloadLength returns the maximum length the payload can be for the
67 // receiver. This is part of the Message interface implementation.
68 func (msg *MsgPing) MaxPayloadLength(pver uint32) uint32 {
70 // There was no nonce for BIP0031Version and earlier.
71 // NOTE: > is not a mistake here. The BIP0031 was defined as AFTER
72 // the version unlike most others.
73 if pver > BIP0031Version {
81 // NewMsgPing returns a new bitcoin ping message that conforms to the Message
82 // interface. See MsgPing for details.
83 func NewMsgPing(nonce uint64) *MsgPing {