2020-01-17 10:17:19 +00:00
|
|
|
package payload
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
2020-01-17 10:17:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Ping payload for ping/pong payloads.
|
|
|
|
type Ping struct {
|
|
|
|
// Index of the last block.
|
|
|
|
LastBlockIndex uint32
|
|
|
|
// Timestamp.
|
2020-02-08 12:53:08 +00:00
|
|
|
Timestamp uint32
|
2020-01-17 10:17:19 +00:00
|
|
|
// Nonce of the server.
|
2020-02-08 12:53:08 +00:00
|
|
|
Nonce uint32
|
2020-01-17 10:17:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewPing creates new Ping payload.
|
|
|
|
func NewPing(blockIndex uint32, nonce uint32) *Ping {
|
|
|
|
return &Ping{
|
|
|
|
LastBlockIndex: blockIndex,
|
|
|
|
Timestamp: uint32(time.Now().UTC().Unix()),
|
|
|
|
Nonce: nonce,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeBinary implements Serializable interface.
|
|
|
|
func (p *Ping) DecodeBinary(br *io.BinReader) {
|
|
|
|
p.LastBlockIndex = br.ReadU32LE()
|
|
|
|
p.Timestamp = br.ReadU32LE()
|
|
|
|
p.Nonce = br.ReadU32LE()
|
|
|
|
}
|
|
|
|
|
|
|
|
// EncodeBinary implements Serializable interface.
|
|
|
|
func (p *Ping) EncodeBinary(bw *io.BinWriter) {
|
|
|
|
bw.WriteU32LE(p.LastBlockIndex)
|
|
|
|
bw.WriteU32LE(p.Timestamp)
|
|
|
|
bw.WriteU32LE(p.Nonce)
|
|
|
|
}
|