1 // Copyright (c) 2013-2016 The btcsuite developers
2 // Use of this source code is governed by an ISC
3 // license that can be found in the LICENSE file.
14 // ProtocolVersion is the latest protocol version this package supports.
15 ProtocolVersion uint32 = 70013
17 // MultipleAddressVersion is the protocol version which added multiple
18 // addresses per message (pver >= MultipleAddressVersion).
19 MultipleAddressVersion uint32 = 209
21 // NetAddressTimeVersion is the protocol version which added the
22 // timestamp field (pver >= NetAddressTimeVersion).
23 NetAddressTimeVersion uint32 = 31402
25 // BIP0031Version is the protocol version AFTER which a pong message
26 // and nonce field in ping were added (pver > BIP0031Version).
27 BIP0031Version uint32 = 60000
29 // BIP0035Version is the protocol version which added the mempool
30 // message (pver >= BIP0035Version).
31 BIP0035Version uint32 = 60002
33 // BIP0037Version is the protocol version which added new connection
34 // bloom filtering related messages and extended the version message
35 // with a relay flag (pver >= BIP0037Version).
36 BIP0037Version uint32 = 70001
38 // RejectVersion is the protocol version which added a new reject
40 RejectVersion uint32 = 70002
42 // BIP0111Version is the protocol version which added the SFNodeBloom
44 BIP0111Version uint32 = 70011
46 // SendHeadersVersion is the protocol version which added a new
47 // sendheaders message.
48 SendHeadersVersion uint32 = 70012
50 // FeeFilterVersion is the protocol version which added a new
52 FeeFilterVersion uint32 = 70013
55 // ServiceFlag identifies services supported by a bitcoin peer.
56 type ServiceFlag uint64
59 // SFNodeNetwork is a flag used to indicate a peer is a full node.
60 SFNodeNetwork ServiceFlag = 1 << iota
62 // SFNodeGetUTXO is a flag used to indicate a peer supports the
63 // getutxos and utxos commands (BIP0064).
66 // SFNodeBloom is a flag used to indicate a peer supports bloom
70 // SFNodeWitness is a flag used to indicate a peer supports blocks
71 // and transactions including witness data (BIP0144).
75 // Map of service flags back to their constant names for pretty printing.
76 var sfStrings = map[ServiceFlag]string{
77 SFNodeNetwork: "SFNodeNetwork",
78 SFNodeGetUTXO: "SFNodeGetUTXO",
79 SFNodeBloom: "SFNodeBloom",
80 SFNodeWitness: "SFNodeWitness",
83 // orderedSFStrings is an ordered list of service flags from highest to
85 var orderedSFStrings = []ServiceFlag{
92 // String returns the ServiceFlag in human-readable form.
93 func (f ServiceFlag) String() string {
99 // Add individual bit flags.
101 for _, flag := range orderedSFStrings {
103 s += sfStrings[flag] + "|"
108 // Add any remaining flags which aren't accounted for as hex.
109 s = strings.TrimRight(s, "|")
111 s += "|0x" + strconv.FormatUint(uint64(f), 16)
113 s = strings.TrimLeft(s, "|")
117 // BitcoinNet represents which bitcoin network a message belongs to.
118 type BitcoinNet uint32
120 // Constants used to indicate the message bitcoin network. They can also be
121 // used to seek to the next message when a stream's state is unknown, but
122 // this package does not provide that functionality since it's generally a
123 // better idea to simply disconnect clients that are misbehaving over TCP.
125 // MainNet represents the main bitcoin network.
126 MainNet BitcoinNet = 0xd9b4bef9
128 // TestNet represents the regression test network.
129 TestNet BitcoinNet = 0xdab5bffa
131 // TestNet3 represents the test network (version 3).
132 TestNet3 BitcoinNet = 0x0709110b
134 // SimNet represents the simulation test network.
135 SimNet BitcoinNet = 0x12141c16
138 // bnStrings is a map of bitcoin networks back to their constant names for
140 var bnStrings = map[BitcoinNet]string{
143 TestNet3: "TestNet3",
147 // String returns the BitcoinNet in human-readable form.
148 func (n BitcoinNet) String() string {
149 if s, ok := bnStrings[n]; ok {
153 return fmt.Sprintf("Unknown BitcoinNet (%d)", uint32(n))