-
Notifications
You must be signed in to change notification settings - Fork 3
/
request.go
39 lines (29 loc) · 944 Bytes
/
request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Package node
// @Description: 节点发送的请求方法
package node
import (
"encoding/binary"
"github.com/chain-lab/go-norn/common"
"github.com/chain-lab/go-norn/p2p"
"github.com/chain-lab/go-norn/utils"
)
func requestBlockWithHash(blockHash common.Hash, p *Peer) {
p.peer.Send(p2p.StatusCodeGetBlockBodiesMsg, blockHash[:])
}
func requestSyncStatusMsg(height int64, p *Peer) {
byteHeight := make([]byte, 8)
binary.LittleEndian.PutUint64(byteHeight, uint64(height))
p.peer.Send(p2p.StatusCodeSyncStatusReq, byteHeight)
}
func requestSyncGetBlock(height int64, p *Peer) {
byteHeight := make([]byte, 8)
binary.LittleEndian.PutUint64(byteHeight, uint64(height))
p.peer.Send(p2p.StatusCodeSyncGetBlocksMsg, byteHeight)
}
func requestTimeSync(msg *p2p.TimeSyncMsg, p *Peer) {
byteTimeSyncMsg, err := utils.SerializeTimeSyncMsg(msg)
if err != nil {
return
}
p.peer.Send(p2p.StatusCodeTimeSyncReq, byteTimeSyncMsg)
}