github.com/BlockABC/godash@v0.0.0-20191112120524-f4aa3a32c566/wire/protocol.go (about) 1 // Copyright (c) 2013-2016 The btcsuite developers 2 // Copyright (c) 2016 The Dash developers 3 // Use of this source code is governed by an ISC 4 // license that can be found in the LICENSE file. 5 6 package wire 7 8 import ( 9 "fmt" 10 "strconv" 11 "strings" 12 ) 13 14 const ( 15 // ProtocolVersion is the latest protocol version this package supports. 16 ProtocolVersion uint32 = 70012 17 18 // MultipleAddressVersion is the protocol version which added multiple 19 // addresses per message (pver >= MultipleAddressVersion). 20 MultipleAddressVersion uint32 = 209 21 22 // NetAddressTimeVersion is the protocol version which added the 23 // timestamp field (pver >= NetAddressTimeVersion). 24 NetAddressTimeVersion uint32 = 31402 25 26 // BIP0031Version is the protocol version AFTER which a pong message 27 // and nonce field in ping were added (pver > BIP0031Version). 28 BIP0031Version uint32 = 60000 29 30 // BIP0035Version is the protocol version which added the mempool 31 // message (pver >= BIP0035Version). 32 BIP0035Version uint32 = 60002 33 34 // BIP0037Version is the protocol version which added new connection 35 // bloom filtering related messages and extended the version message 36 // with a relay flag (pver >= BIP0037Version). 37 BIP0037Version uint32 = 70001 38 39 // BIP0111Version is the protocol version which added the SFNodeBloom 40 // service flag. 41 BIP0111Version uint32 = 70011 42 43 // SendHeadersVersion is the protocol version which added a new 44 // sendheaders message. 45 SendHeadersVersion uint32 = 70012 46 47 // RejectVersion is the protocol version which added a new reject 48 // message. 49 RejectVersion uint32 = 70002 50 ) 51 52 // ServiceFlag identifies services supported by a bitcoin peer. 53 type ServiceFlag uint64 54 55 const ( 56 // SFNodeNetwork is a flag used to indicate a peer is a full node. 57 SFNodeNetwork ServiceFlag = 1 << iota 58 59 // SFNodeGetUTXO is a flag used to indicate a peer supports the 60 // getutxos and utxos commands (BIP0064). 61 SFNodeGetUTXO 62 63 // SFNodeBloom is a flag used to indiciate a peer supports bloom 64 // filtering. 65 SFNodeBloom 66 ) 67 68 // Map of service flags back to their constant names for pretty printing. 69 var sfStrings = map[ServiceFlag]string{ 70 SFNodeNetwork: "SFNodeNetwork", 71 SFNodeGetUTXO: "SFNodeGetUTXO", 72 SFNodeBloom: "SFNodeBloom", 73 } 74 75 // orderedSFStrings is an ordered list of service flags from highest to 76 // lowest. 77 var orderedSFStrings = []ServiceFlag{ 78 SFNodeNetwork, 79 SFNodeGetUTXO, 80 SFNodeBloom, 81 } 82 83 // String returns the ServiceFlag in human-readable form. 84 func (f ServiceFlag) String() string { 85 // No flags are set. 86 if f == 0 { 87 return "0x0" 88 } 89 90 // Add individual bit flags. 91 s := "" 92 for _, flag := range orderedSFStrings { 93 if f&flag == flag { 94 s += sfStrings[flag] + "|" 95 f -= flag 96 } 97 } 98 99 // Add any remaining flags which aren't accounted for as hex. 100 s = strings.TrimRight(s, "|") 101 if f != 0 { 102 s += "|0x" + strconv.FormatUint(uint64(f), 16) 103 } 104 s = strings.TrimLeft(s, "|") 105 return s 106 } 107 108 // BitcoinNet represents which bitcoin network a message belongs to. 109 type BitcoinNet uint32 110 111 // Constants used to indicate the message bitcoin network. They can also be 112 // used to seek to the next message when a stream's state is unknown, but 113 // this package does not provide that functionality since it's generally a 114 // better idea to simply disconnect clients that are misbehaving over TCP. 115 const ( 116 // MainNet represents the main bitcoin network. 117 MainNet BitcoinNet = 0xd9b4bef9 118 119 // TestNet represents the regression test network. 120 TestNet BitcoinNet = 0xdab5bffa 121 122 // TestNet3 represents the test network (version 3). 123 TestNet3 BitcoinNet = 0x0709110b 124 125 // SimNet represents the simulation test network. 126 SimNet BitcoinNet = 0x12141c16 127 ) 128 129 // bnStrings is a map of bitcoin networks back to their constant names for 130 // pretty printing. 131 var bnStrings = map[BitcoinNet]string{ 132 MainNet: "MainNet", 133 TestNet: "TestNet", 134 TestNet3: "TestNet3", 135 SimNet: "SimNet", 136 } 137 138 // String returns the BitcoinNet in human-readable form. 139 func (n BitcoinNet) String() string { 140 if s, ok := bnStrings[n]; ok { 141 return s 142 } 143 144 return fmt.Sprintf("Unknown BitcoinNet (%d)", uint32(n)) 145 }