-
Notifications
You must be signed in to change notification settings - Fork 0
/
protocol.go
147 lines (119 loc) · 3.85 KB
/
protocol.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright (c) 2013-2016 The btcsuite developers
// Copyright (c) 2015-2018 The Hdfchain developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package wire
import (
"fmt"
"strconv"
"strings"
)
const (
// InitialProcotolVersion is the initial protocol version for the
// network.
InitialProcotolVersion uint32 = 1
// ProtocolVersion is the latest protocol version this package supports.
ProtocolVersion uint32 = 7
// NodeBloomVersion is the protocol version which added the SFNodeBloom
// service flag (unused).
NodeBloomVersion uint32 = 2
// SendHeadersVersion is the protocol version which added a new
// sendheaders message.
SendHeadersVersion uint32 = 3
// MaxBlockSizeVersion is the protocol version which increased the
// original blocksize.
MaxBlockSizeVersion uint32 = 4
// FeeFilterVersion is the protocol version which added a new
// feefilter message.
FeeFilterVersion uint32 = 5
// NodeCFVersion is the protocol version which adds the SFNodeCF service
// flag and the cfheaders, cfilter, cftypes, getcfheaders, getcfilter and
// getcftypes messages.
NodeCFVersion uint32 = 6
// CFilterV2Version is the protocol version which adds the getcfilterv2 and
// cfiltverv2 messages.
CFilterV2Version uint32 = 7
)
// ServiceFlag identifies services supported by a Hdfchain peer.
type ServiceFlag uint64
const (
// SFNodeNetwork is a flag used to indicate a peer is a full node.
SFNodeNetwork ServiceFlag = 1 << iota
// SFNodeBloom is a flag used to indicate a peer supports bloom
// filtering.
SFNodeBloom
// SFNodeCF is a flag used to indicate a peer supports v1 gcs filters
// (CFs).
SFNodeCF
)
// Map of service flags back to their constant names for pretty printing.
var sfStrings = map[ServiceFlag]string{
SFNodeNetwork: "SFNodeNetwork",
SFNodeBloom: "SFNodeBloom",
SFNodeCF: "SFNodeCF",
}
// orderedSFStrings is an ordered list of service flags from highest to
// lowest.
var orderedSFStrings = []ServiceFlag{
SFNodeNetwork,
SFNodeBloom,
SFNodeCF,
}
// String returns the ServiceFlag in human-readable form.
func (f ServiceFlag) String() string {
// No flags are set.
if f == 0 {
return "0x0"
}
// Add individual bit flags.
s := ""
for _, flag := range orderedSFStrings {
if f&flag == flag {
s += sfStrings[flag] + "|"
f -= flag
}
}
// Add any remaining flags which aren't accounted for as hex.
s = strings.TrimRight(s, "|")
if f != 0 {
s += "|0x" + strconv.FormatUint(uint64(f), 16)
}
s = strings.TrimLeft(s, "|")
return s
}
// CurrencyNet represents which Hdfchain network a message belongs to.
type CurrencyNet uint32
// Constants used to indicate the message Hdfchain network. They can also be
// used to seek to the next message when a stream's state is unknown, but
// this package does not provide that functionality since it's generally a
// better idea to simply disconnect clients that are misbehaving over TCP.
const (
// MainNet represents the main Hdfchain network.
MainNet CurrencyNet = 0xd9b400f9
// RegNet represents the regression test network.
RegNet CurrencyNet = 0xdab500fa
// RegTest represents the regression test network.
//
// DEPRECATED. This will be removed in the next major version bump.
// Use Regnet instead.
RegTest CurrencyNet = RegNet
// TestNet3 represents the 3rd test network.
TestNet3 CurrencyNet = 0xb194aa75
// SimNet represents the simulation test network.
SimNet CurrencyNet = 0x12141c16
)
// bnStrings is a map of Hdfchain networks back to their constant names for
// pretty printing.
var bnStrings = map[CurrencyNet]string{
MainNet: "MainNet",
TestNet3: "TestNet3",
RegNet: "RegNet",
SimNet: "SimNet",
}
// String returns the CurrencyNet in human-readable form.
func (n CurrencyNet) String() string {
if s, ok := bnStrings[n]; ok {
return s
}
return fmt.Sprintf("Unknown CurrencyNet (%d)", uint32(n))
}