Browse Source

moar split out of wire

master
Loki Verloren 6 months ago
parent
commit
6b85085e12
63 changed files with 934 additions and 830 deletions
  1. 29
    29
      addrmgr/addrmanager.go
  2. 5
    5
      addrmgr/known/known.go
  3. 20
    20
      addrmgr/network/network.go
  4. 2
    1
      blockchain/chainio.go
  5. 7
    7
      blockchain/weight.go
  6. 4
    3
      btcutil/filter/filter.go
  7. 6
    6
      btcutil/gcs/gcs.go
  8. 4
    4
      connmgr/seed.go
  9. 2
    2
      database/ffldb/db.go
  10. 36
    35
      mempool/estimator/mempool.go
  11. 16
    16
      mempool/rule/error.go
  12. 2
    1
      mining/cpuminer/cpuminer.go
  13. 18
    17
      mining/mining.go
  14. 3
    2
      netsync/manager/manager.go
  15. 4
    3
      node/rpc/rpchandlers.go
  16. 2
    1
      node/rpc/wsclient.go
  17. 3
    2
      node/server.go
  18. 12
    10
      node/serverpeer.go
  19. 2
    2
      node/util.go
  20. 6
    3
      peer/log.go
  21. 48
    43
      peer/peer.go
  22. 5
    5
      txscript/script.go
  23. 6
    9
      wire/blockheader.go
  24. 0
    34
      wire/error.go
  25. 14
    14
      wire/fixed/fixedIO_test.go
  26. 3
    2
      wire/invvect.go
  27. 53
    96
      wire/message.go
  28. 76
    0
      wire/message/error.go
  29. 25
    21
      wire/msgaddr.go
  30. 40
    37
      wire/msgalert.go
  31. 10
    8
      wire/msgblock.go
  32. 13
    11
      wire/msgcfcheckpt.go
  33. 17
    15
      wire/msgcfheaders.go
  34. 11
    9
      wire/msgcfilter.go
  35. 7
    5
      wire/msgfeefilter.go
  36. 9
    7
      wire/msgfilteradd.go
  37. 4
    3
      wire/msgfilterclear.go
  38. 16
    33
      wire/msgfilterload.go
  39. 3
    1
      wire/msggetaddr.go
  40. 16
    13
      wire/msggetblocks.go
  41. 8
    5
      wire/msggetcfcheckpt.go
  42. 10
    7
      wire/msggetcfheaders.go
  43. 9
    7
      wire/msggetcfilters.go
  44. 9
    7
      wire/msggetdata.go
  45. 15
    13
      wire/msggetheaders.go
  46. 13
    11
      wire/msgheaders.go
  47. 9
    7
      wire/msginv.go
  48. 4
    3
      wire/msgmempool.go
  49. 17
    15
      wire/msgmerkleblock.go
  50. 9
    7
      wire/msgnotfound.go
  51. 5
    3
      wire/msgping.go
  52. 7
    5
      wire/msgpong.go
  53. 19
    53
      wire/msgreject.go
  54. 4
    3
      wire/msgsendheaders.go
  55. 49
    45
      wire/msgtx.go
  56. 3
    1
      wire/msgverack.go
  57. 26
    21
      wire/msgversion.go
  58. 6
    4
      wire/msgversion_test.go
  59. 11
    9
      wire/na/netaddress.go
  60. 1
    1
      wire/na/netaddress_test.go
  61. 40
    0
      wire/reject/reject.go
  62. 99
    66
      wire/rw/rw.go
  63. 2
    2
      wire/rw/rw_test.go

+ 29
- 29
addrmgr/addrmanager.go View File

@@ -24,13 +24,13 @@ import (
24 24
 	"time"
25 25
 
26 26
 	"git.parallelcoin.io/dev/btcd/addrmgr/network"
27
+	"git.parallelcoin.io/dev/btcd/wire/na"
27 28
 	"git.parallelcoin.io/dev/btcd/wire/service"
28 29
 
29 30
 	"git.parallelcoin.io/dev/btcd/addrmgr/amc"
30 31
 	"git.parallelcoin.io/dev/btcd/addrmgr/known"
31 32
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
32 33
 	"git.parallelcoin.io/dev/btcd/node/cnf"
33
-	"git.parallelcoin.io/dev/btcd/wire"
34 34
 )
35 35
 
36 36
 // AddrManager provides a concurrency safe address manager for caching potential
@@ -76,7 +76,7 @@ type serializedAddrManager struct {
76 76
 }
77 77
 
78 78
 type localAddress struct {
79
-	na    *wire.NetAddress
79
+	na    *na.NetAddress
80 80
 	score AddressPriority
81 81
 }
82 82
 
@@ -103,7 +103,7 @@ const (
103 103
 
104 104
 // updateAddress is a helper function to either update an address already known
105 105
 // to the address manager, or to add the address if not already known.
106
-func (a *AddrManager) updateAddress(netAddr, srcAddr *wire.NetAddress) {
106
+func (a *AddrManager) updateAddress(netAddr, srcAddr *na.NetAddress) {
107 107
 	// Filter out non-routable addresses. Note that non-routable
108 108
 	// also includes invalid and local addresses.
109 109
 	if !network.IsRoutable(netAddr) {
@@ -234,7 +234,7 @@ func (a *AddrManager) pickTried(bucket int) *list.Element {
234 234
 	return oldestElem
235 235
 }
236 236
 
237
-func (a *AddrManager) getNewBucket(netAddr, srcAddr *wire.NetAddress) int {
237
+func (a *AddrManager) getNewBucket(netAddr, srcAddr *na.NetAddress) int {
238 238
 	// bitcoind:
239 239
 	// doublesha256(key + sourcegroup + int64(doublesha256(key + group + sourcegroup))%bucket_per_source_group) % num_new_buckets
240 240
 
@@ -256,7 +256,7 @@ func (a *AddrManager) getNewBucket(netAddr, srcAddr *wire.NetAddress) int {
256 256
 	return int(binary.LittleEndian.Uint64(hash2) % amc.NewBucketCount)
257 257
 }
258 258
 
259
-func (a *AddrManager) getTriedBucket(netAddr *wire.NetAddress) int {
259
+func (a *AddrManager) getTriedBucket(netAddr *na.NetAddress) int {
260 260
 	// bitcoind hashes this as:
261 261
 	// doublesha256(key + group + truncate_to_64bits(doublesha256(key)) % buckets_per_group) % num_buckets
262 262
 	data1 := []byte{}
@@ -486,9 +486,9 @@ func (a *AddrManager) deserializePeers(cfg *cnf.Config, filePath string) error {
486 486
 	return nil
487 487
 }
488 488
 
489
-// DeserializeNetAddress converts a given address string to a *wire.NetAddress.
489
+// DeserializeNetAddress converts a given address string to a *na.NetAddress.
490 490
 func (a *AddrManager) DeserializeNetAddress(cfg *cnf.Config, addr string,
491
-	services service.Flag) (*wire.NetAddress, error) {
491
+	services service.Flag) (*na.NetAddress, error) {
492 492
 
493 493
 	host, portStr, err := net.SplitHostPort(addr)
494 494
 	if err != nil {
@@ -537,7 +537,7 @@ func (a *AddrManager) Stop() error {
537 537
 // AddAddresses adds new addresses to the address manager.  It enforces a max
538 538
 // number of addresses and silently ignores duplicate addresses.  It is
539 539
 // safe for concurrent access.
540
-func (a *AddrManager) AddAddresses(addrs []*wire.NetAddress, srcAddr *wire.NetAddress) {
540
+func (a *AddrManager) AddAddresses(addrs []*na.NetAddress, srcAddr *na.NetAddress) {
541 541
 	a.mtx.Lock()
542 542
 	defer a.mtx.Unlock()
543 543
 
@@ -549,7 +549,7 @@ func (a *AddrManager) AddAddresses(addrs []*wire.NetAddress, srcAddr *wire.NetAd
549 549
 // AddAddress adds a new address to the address manager.  It enforces a max
550 550
 // number of addresses and silently ignores duplicate addresses.  It is
551 551
 // safe for concurrent access.
552
-func (a *AddrManager) AddAddress(addr, srcAddr *wire.NetAddress) {
552
+func (a *AddrManager) AddAddress(addr, srcAddr *na.NetAddress) {
553 553
 	a.mtx.Lock()
554 554
 	defer a.mtx.Unlock()
555 555
 
@@ -557,14 +557,14 @@ func (a *AddrManager) AddAddress(addr, srcAddr *wire.NetAddress) {
557 557
 }
558 558
 
559 559
 // AddAddressByIP adds an address where we are given an ip:port and not a
560
-// wire.NetAddress.
560
+// na.NetAddress.
561 561
 func (a *AddrManager) AddAddressByIP(addrIP string) error {
562 562
 	// Split IP and port
563 563
 	addr, portStr, err := net.SplitHostPort(addrIP)
564 564
 	if err != nil {
565 565
 		return err
566 566
 	}
567
-	// Put it in wire.Netaddress
567
+	// Put it in na.Netaddress
568 568
 	ip := net.ParseIP(addr)
569 569
 	if ip == nil {
570 570
 		return fmt.Errorf("invalid ip address %s", addr)
@@ -573,7 +573,7 @@ func (a *AddrManager) AddAddressByIP(addrIP string) error {
573 573
 	if err != nil {
574 574
 		return fmt.Errorf("invalid port %s: %v", portStr, err)
575 575
 	}
576
-	na := wire.NewNetAddressIPPort(ip, uint16(port), 0)
576
+	na := na.NewNetAddressIPPort(ip, uint16(port), 0)
577 577
 	a.AddAddress(na, na) // XXX use correct src address
578 578
 	return nil
579 579
 }
@@ -602,7 +602,7 @@ func (a *AddrManager) NeedMoreAddresses() bool {
602 602
 
603 603
 // AddressCache returns the current address cache.  It must be treated as
604 604
 // read-only (but since it is a copy now, this is not as dangerous).
605
-func (a *AddrManager) AddressCache() []*wire.NetAddress {
605
+func (a *AddrManager) AddressCache() []*na.NetAddress {
606 606
 	allAddr := a.getAddresses()
607 607
 
608 608
 	numAddresses := len(allAddr) * amc.GetAddrPercent / 100
@@ -624,7 +624,7 @@ func (a *AddrManager) AddressCache() []*wire.NetAddress {
624 624
 
625 625
 // getAddresses returns all of the addresses currently found within the
626 626
 // manager's address cache.
627
-func (a *AddrManager) getAddresses() []*wire.NetAddress {
627
+func (a *AddrManager) getAddresses() []*na.NetAddress {
628 628
 	a.mtx.Lock()
629 629
 	defer a.mtx.Unlock()
630 630
 
@@ -633,7 +633,7 @@ func (a *AddrManager) getAddresses() []*wire.NetAddress {
633 633
 		return nil
634 634
 	}
635 635
 
636
-	addrs := make([]*wire.NetAddress, 0, addrIndexLen)
636
+	addrs := make([]*na.NetAddress, 0, addrIndexLen)
637 637
 	for _, v := range a.addrIndex {
638 638
 		addrs = append(addrs, v.NA)
639 639
 	}
@@ -660,7 +660,7 @@ func (a *AddrManager) reset() {
660 660
 // HostToNetAddress returns a netaddress given a host address.  If the address
661 661
 // is a Tor .onion address this will be taken care of.  Else if the host is
662 662
 // not an IP address it will be resolved (via Tor if required).
663
-func (a *AddrManager) HostToNetAddress(cfg *cnf.Config, host string, port uint16, services service.Flag) (*wire.NetAddress, error) {
663
+func (a *AddrManager) HostToNetAddress(cfg *cnf.Config, host string, port uint16, services service.Flag) (*na.NetAddress, error) {
664 664
 	// Tor address is 16 char base32 + ".onion"
665 665
 	var ip net.IP
666 666
 	if len(host) == 22 && host[16:] == ".onion" {
@@ -685,13 +685,13 @@ func (a *AddrManager) HostToNetAddress(cfg *cnf.Config, host string, port uint16
685 685
 		ip = ips[0]
686 686
 	}
687 687
 
688
-	return wire.NewNetAddressIPPort(ip, port, services), nil
688
+	return na.NewNetAddressIPPort(ip, port, services), nil
689 689
 }
690 690
 
691 691
 // ipString returns a string for the ip from the provided NetAddress. If the
692 692
 // ip is in the range used for Tor addresses then it will be transformed into
693 693
 // the relevant .onion address.
694
-func ipString(na *wire.NetAddress) string {
694
+func ipString(na *na.NetAddress) string {
695 695
 	if network.IsOnionCatTor(na) {
696 696
 		// We know now that na.IP is long enough.
697 697
 		base32 := base32.StdEncoding.EncodeToString(na.IP[6:])
@@ -703,7 +703,7 @@ func ipString(na *wire.NetAddress) string {
703 703
 
704 704
 // NetAddressKey returns a string key in the form of ip:port for IPv4 addresses
705 705
 // or [ip]:port for IPv6 addresses.
706
-func NetAddressKey(na *wire.NetAddress) string {
706
+func NetAddressKey(na *na.NetAddress) string {
707 707
 	port := strconv.FormatUint(uint64(na.Port), 10)
708 708
 
709 709
 	return net.JoinHostPort(ipString(na), port)
@@ -780,13 +780,13 @@ func (a *AddrManager) GetAddress() *known.Address {
780 780
 	}
781 781
 }
782 782
 
783
-func (a *AddrManager) find(addr *wire.NetAddress) *known.Address {
783
+func (a *AddrManager) find(addr *na.NetAddress) *known.Address {
784 784
 	return a.addrIndex[NetAddressKey(addr)]
785 785
 }
786 786
 
787 787
 // Attempt increases the given address' attempt counter and updates
788 788
 // the last attempt time.
789
-func (a *AddrManager) Attempt(addr *wire.NetAddress) {
789
+func (a *AddrManager) Attempt(addr *na.NetAddress) {
790 790
 	a.mtx.Lock()
791 791
 	defer a.mtx.Unlock()
792 792
 
@@ -804,7 +804,7 @@ func (a *AddrManager) Attempt(addr *wire.NetAddress) {
804 804
 // Connected Marks the given address as currently connected and working at the
805 805
 // current time.  The address must already be known to AddrManager else it will
806 806
 // be ignored.
807
-func (a *AddrManager) Connected(addr *wire.NetAddress) {
807
+func (a *AddrManager) Connected(addr *na.NetAddress) {
808 808
 	a.mtx.Lock()
809 809
 	defer a.mtx.Unlock()
810 810
 
@@ -827,7 +827,7 @@ func (a *AddrManager) Connected(addr *wire.NetAddress) {
827 827
 // Good marks the given address as good.  To be called after a successful
828 828
 // connection and version exchange.  If the address is unknown to the address
829 829
 // manager it will be ignored.
830
-func (a *AddrManager) Good(addr *wire.NetAddress) {
830
+func (a *AddrManager) Good(addr *na.NetAddress) {
831 831
 	a.mtx.Lock()
832 832
 	defer a.mtx.Unlock()
833 833
 
@@ -914,7 +914,7 @@ func (a *AddrManager) Good(addr *wire.NetAddress) {
914 914
 }
915 915
 
916 916
 // SetServices sets the services for the giiven address to the provided value.
917
-func (a *AddrManager) SetServices(addr *wire.NetAddress, services service.Flag) {
917
+func (a *AddrManager) SetServices(addr *na.NetAddress, services service.Flag) {
918 918
 	a.mtx.Lock()
919 919
 	defer a.mtx.Unlock()
920 920
 
@@ -934,7 +934,7 @@ func (a *AddrManager) SetServices(addr *wire.NetAddress, services service.Flag)
934 934
 
935 935
 // AddLocalAddress adds na to the list of known local addresses to advertise
936 936
 // with the given priority.
937
-func (a *AddrManager) AddLocalAddress(na *wire.NetAddress, priority AddressPriority) error {
937
+func (a *AddrManager) AddLocalAddress(na *na.NetAddress, priority AddressPriority) error {
938 938
 	if !network.IsRoutable(na) {
939 939
 		return fmt.Errorf("address %s is not routable", na.IP)
940 940
 	}
@@ -959,7 +959,7 @@ func (a *AddrManager) AddLocalAddress(na *wire.NetAddress, priority AddressPrior
959 959
 
960 960
 // getReachabilityFrom returns the relative reachability of the provided local
961 961
 // address to the provided remote address.
962
-func getReachabilityFrom(localAddr, remoteAddr *wire.NetAddress) int {
962
+func getReachabilityFrom(localAddr, remoteAddr *na.NetAddress) int {
963 963
 	const (
964 964
 		Unreachable = 0
965 965
 		Default     = iota
@@ -1040,13 +1040,13 @@ func getReachabilityFrom(localAddr, remoteAddr *wire.NetAddress) int {
1040 1040
 
1041 1041
 // GetBestLocalAddress returns the most appropriate local address to use
1042 1042
 // for the given remote address.
1043
-func (a *AddrManager) GetBestLocalAddress(remoteAddr *wire.NetAddress) *wire.NetAddress {
1043
+func (a *AddrManager) GetBestLocalAddress(remoteAddr *na.NetAddress) *na.NetAddress {
1044 1044
 	a.lamtx.Lock()
1045 1045
 	defer a.lamtx.Unlock()
1046 1046
 
1047 1047
 	bestreach := 0
1048 1048
 	var bestscore AddressPriority
1049
-	var bestAddress *wire.NetAddress
1049
+	var bestAddress *na.NetAddress
1050 1050
 	for _, la := range a.localAddresses {
1051 1051
 		reach := getReachabilityFrom(la.na, remoteAddr)
1052 1052
 		if reach > bestreach ||
@@ -1071,7 +1071,7 @@ func (a *AddrManager) GetBestLocalAddress(remoteAddr *wire.NetAddress) *wire.Net
1071 1071
 			ip = net.IPv4zero
1072 1072
 		}
1073 1073
 		services := service.NodeNetwork | service.NodeWitness | service.NodeBloom
1074
-		bestAddress = wire.NewNetAddressIPPort(ip, 0, services)
1074
+		bestAddress = na.NewNetAddressIPPort(ip, 0, services)
1075 1075
 	}
1076 1076
 
1077 1077
 	return bestAddress

+ 5
- 5
addrmgr/known/known.go View File

@@ -8,15 +8,15 @@ import (
8 8
 	"time"
9 9
 
10 10
 	"git.parallelcoin.io/dev/btcd/addrmgr/amc"
11
-	"git.parallelcoin.io/dev/btcd/wire"
11
+	"git.parallelcoin.io/dev/btcd/wire/na"
12 12
 	"git.parallelcoin.io/dev/btcd/wire/service"
13 13
 )
14 14
 
15 15
 // Address tracks information about a known network address that is used
16 16
 // to determine how viable an address is.
17 17
 type Address struct {
18
-	NA          *wire.NetAddress
19
-	SrcAddr     *wire.NetAddress
18
+	NA          *na.NetAddress
19
+	SrcAddr     *na.NetAddress
20 20
 	Attempts    int
21 21
 	Lastattempt time.Time
22 22
 	Lastsuccess time.Time
@@ -24,9 +24,9 @@ type Address struct {
24 24
 	Refs        int // reference count of new buckets
25 25
 }
26 26
 
27
-// NetAddress returns the underlying wire.NetAddress associated with the
27
+// NetAddress returns the underlying na.NetAddress associated with the
28 28
 // known address.
29
-func (ka *Address) NetAddress() *wire.NetAddress {
29
+func (ka *Address) NetAddress() *na.NetAddress {
30 30
 	return ka.NA
31 31
 }
32 32
 

+ 20
- 20
addrmgr/network/network.go View File

@@ -8,7 +8,7 @@ import (
8 8
 	"fmt"
9 9
 	"net"
10 10
 
11
-	"git.parallelcoin.io/dev/btcd/wire"
11
+	"git.parallelcoin.io/dev/btcd/wire/na"
12 12
 )
13 13
 
14 14
 var (
@@ -100,12 +100,12 @@ func ipNet(ip string, ones, bits int) net.IPNet {
100 100
 }
101 101
 
102 102
 // IsIPv4 returns whether or not the given address is an IPv4 address.
103
-func IsIPv4(na *wire.NetAddress) bool {
103
+func IsIPv4(na *na.NetAddress) bool {
104 104
 	return na.IP.To4() != nil
105 105
 }
106 106
 
107 107
 // IsLocal returns whether or not the given address is a local address.
108
-func IsLocal(na *wire.NetAddress) bool {
108
+func IsLocal(na *na.NetAddress) bool {
109 109
 	return na.IP.IsLoopback() || zero4Net.Contains(na.IP)
110 110
 }
111 111
 
@@ -113,14 +113,14 @@ func IsLocal(na *wire.NetAddress) bool {
113 113
 // used by bitcoin to support Tor (fd87:d87e:eb43::/48).  Note that this range
114 114
 // is the same range used by OnionCat, which is part of the RFC4193 unique local
115 115
 // IPv6 range.
116
-func IsOnionCatTor(na *wire.NetAddress) bool {
116
+func IsOnionCatTor(na *na.NetAddress) bool {
117 117
 	return onionCatNet.Contains(na.IP)
118 118
 }
119 119
 
120 120
 // IsRFC1918 returns whether or not the passed address is part of the IPv4
121 121
 // private network address space as defined by RFC1918 (10.0.0.0/8,
122 122
 // 172.16.0.0/12, or 192.168.0.0/16).
123
-func IsRFC1918(na *wire.NetAddress) bool {
123
+func IsRFC1918(na *na.NetAddress) bool {
124 124
 	for _, rfc := range RFC1918Nets {
125 125
 		if rfc.Contains(na.IP) {
126 126
 			return true
@@ -131,56 +131,56 @@ func IsRFC1918(na *wire.NetAddress) bool {
131 131
 
132 132
 // IsRFC2544 returns whether or not the passed address is part of the IPv4
133 133
 // address space as defined by RFC2544 (198.18.0.0/15)
134
-func IsRFC2544(na *wire.NetAddress) bool {
134
+func IsRFC2544(na *na.NetAddress) bool {
135 135
 	return RFC2544Net.Contains(na.IP)
136 136
 }
137 137
 
138 138
 // IsRFC3849 returns whether or not the passed address is part of the IPv6
139 139
 // documentation range as defined by RFC3849 (2001:DB8::/32).
140
-func IsRFC3849(na *wire.NetAddress) bool {
140
+func IsRFC3849(na *na.NetAddress) bool {
141 141
 	return RFC3849Net.Contains(na.IP)
142 142
 }
143 143
 
144 144
 // IsRFC3927 returns whether or not the passed address is part of the IPv4
145 145
 // autoconfiguration range as defined by RFC3927 (169.254.0.0/16).
146
-func IsRFC3927(na *wire.NetAddress) bool {
146
+func IsRFC3927(na *na.NetAddress) bool {
147 147
 	return RFC3927Net.Contains(na.IP)
148 148
 }
149 149
 
150 150
 // IsRFC3964 returns whether or not the passed address is part of the IPv6 to
151 151
 // IPv4 encapsulation range as defined by RFC3964 (2002::/16).
152
-func IsRFC3964(na *wire.NetAddress) bool {
152
+func IsRFC3964(na *na.NetAddress) bool {
153 153
 	return RFC3964Net.Contains(na.IP)
154 154
 }
155 155
 
156 156
 // IsRFC4193 returns whether or not the passed address is part of the IPv6
157 157
 // unique local range as defined by RFC4193 (FC00::/7).
158
-func IsRFC4193(na *wire.NetAddress) bool {
158
+func IsRFC4193(na *na.NetAddress) bool {
159 159
 	return RFC4193Net.Contains(na.IP)
160 160
 }
161 161
 
162 162
 // IsRFC4380 returns whether or not the passed address is part of the IPv6
163 163
 // teredo tunneling over UDP range as defined by RFC4380 (2001::/32).
164
-func IsRFC4380(na *wire.NetAddress) bool {
164
+func IsRFC4380(na *na.NetAddress) bool {
165 165
 	return RFC4380Net.Contains(na.IP)
166 166
 }
167 167
 
168 168
 // IsRFC4843 returns whether or not the passed address is part of the IPv6
169 169
 // ORCHID range as defined by RFC4843 (2001:10::/28).
170
-func IsRFC4843(na *wire.NetAddress) bool {
170
+func IsRFC4843(na *na.NetAddress) bool {
171 171
 	return RFC4843Net.Contains(na.IP)
172 172
 }
173 173
 
174 174
 // IsRFC4862 returns whether or not the passed address is part of the IPv6
175 175
 // stateless address autoconfiguration range as defined by RFC4862 (FE80::/64).
176
-func IsRFC4862(na *wire.NetAddress) bool {
176
+func IsRFC4862(na *na.NetAddress) bool {
177 177
 	return RFC4862Net.Contains(na.IP)
178 178
 }
179 179
 
180 180
 // IsRFC5737 returns whether or not the passed address is part of the IPv4
181 181
 // documentation address space as defined by RFC5737 (192.0.2.0/24,
182 182
 // 198.51.100.0/24, 203.0.113.0/24)
183
-func IsRFC5737(na *wire.NetAddress) bool {
183
+func IsRFC5737(na *na.NetAddress) bool {
184 184
 	for _, RFC := range RFC5737Net {
185 185
 		if RFC.Contains(na.IP) {
186 186
 			return true
@@ -192,19 +192,19 @@ func IsRFC5737(na *wire.NetAddress) bool {
192 192
 
193 193
 // IsRFC6052 returns whether or not the passed address is part of the IPv6
194 194
 // well-known prefix range as defined by RFC6052 (64:FF9B::/96).
195
-func IsRFC6052(na *wire.NetAddress) bool {
195
+func IsRFC6052(na *na.NetAddress) bool {
196 196
 	return RFC6052Net.Contains(na.IP)
197 197
 }
198 198
 
199 199
 // IsRFC6145 returns whether or not the passed address is part of the IPv6 to
200 200
 // IPv4 translated address range as defined by RFC6145 (::FFFF:0:0:0/96).
201
-func IsRFC6145(na *wire.NetAddress) bool {
201
+func IsRFC6145(na *na.NetAddress) bool {
202 202
 	return RFC6145Net.Contains(na.IP)
203 203
 }
204 204
 
205 205
 // IsRFC6598 returns whether or not the passed address is part of the IPv4
206 206
 // shared address space specified by RFC6598 (100.64.0.0/10)
207
-func IsRFC6598(na *wire.NetAddress) bool {
207
+func IsRFC6598(na *na.NetAddress) bool {
208 208
 	return RFC6598Net.Contains(na.IP)
209 209
 }
210 210
 
@@ -212,7 +212,7 @@ func IsRFC6598(na *wire.NetAddress) bool {
212 212
 // considered invalid under the following circumstances:
213 213
 // IPv4: It is either a zero or all bits set address.
214 214
 // IPv6: It is either a zero or RFC3849 documentation address.
215
-func IsValid(na *wire.NetAddress) bool {
215
+func IsValid(na *na.NetAddress) bool {
216 216
 	// IsUnspecified returns if address is 0, so only all bits set, and
217 217
 	// RFC3849 need to be explicitly checked.
218 218
 	return na.IP != nil && !(na.IP.IsUnspecified() ||
@@ -222,7 +222,7 @@ func IsValid(na *wire.NetAddress) bool {
222 222
 // IsRoutable returns whether or not the passed address is routable over
223 223
 // the public internet.  This is true as long as the address is valid and is not
224 224
 // in any reserved ranges.
225
-func IsRoutable(na *wire.NetAddress) bool {
225
+func IsRoutable(na *na.NetAddress) bool {
226 226
 	return IsValid(na) && !(IsRFC1918(na) || IsRFC2544(na) ||
227 227
 		IsRFC3927(na) || IsRFC4862(na) || IsRFC3849(na) ||
228 228
 		IsRFC4843(na) || IsRFC5737(na) || IsRFC6598(na) ||
@@ -234,7 +234,7 @@ func IsRoutable(na *wire.NetAddress) bool {
234 234
 // "local" for a local address, the string "tor:key" where key is the /4 of the
235 235
 // onion address for Tor address, and the string "unroutable" for an unroutable
236 236
 // address.
237
-func GroupKey(na *wire.NetAddress) string {
237
+func GroupKey(na *na.NetAddress) string {
238 238
 	if IsLocal(na) {
239 239
 		return "local"
240 240
 	}

+ 2
- 1
blockchain/chainio.go View File

@@ -16,13 +16,14 @@ import (
16 16
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
17 17
 	"git.parallelcoin.io/dev/btcd/database"
18 18
 	"git.parallelcoin.io/dev/btcd/wire"
19
+	"git.parallelcoin.io/dev/btcd/wire/rw"
19 20
 )
20 21
 
21 22
 const (
22 23
 	// blockHdrSize is the size of a block header.  This is simply the
23 24
 	// constant from wire and is only provided here for convenience since
24 25
 	// wire.MaxBlockHeaderPayload is quite long.
25
-	blockHdrSize = wire.MaxBlockHeaderPayload
26
+	blockHdrSize = rw.MaxBlockHeaderPayload
26 27
 
27 28
 	// latestUtxoSetBucketVersion is the current version of the utxo set
28 29
 	// bucket that is used to track all unspent outputs.

+ 7
- 7
blockchain/weight.go View File

@@ -32,15 +32,15 @@ const (
32 32
 	// receives compared to "base" data. A scale factor of 4, denotes that
33 33
 	// witness data is 1/4 as cheap as regular non-witness data.
34 34
 	WitnessScaleFactor = 4
35
+)
35 36
 
36
-	// MinTxOutputWeight is the minimum possible weight for a transaction
37
-	// output.
38
-	MinTxOutputWeight = WitnessScaleFactor * wire.MinTxOutPayload
37
+// MinTxOutputWeight is the minimum possible weight for a transaction
38
+// output.
39
+var MinTxOutputWeight = WitnessScaleFactor * wire.MinTxOutPayload
39 40
 
40
-	// MaxOutputsPerBlock is the maximum number of transaction outputs there
41
-	// can be in a block of max weight size.
42
-	MaxOutputsPerBlock = MaxBlockWeight / MinTxOutputWeight
43
-)
41
+// MaxOutputsPerBlock is the maximum number of transaction outputs there
42
+// can be in a block of max weight size.
43
+var MaxOutputsPerBlock = uint32(MaxBlockWeight / MinTxOutputWeight)
44 44
 
45 45
 // GetBlockWeight computes the value of the weight metric for a given block.
46 46
 // Currently the weight metric is simply the sum of the block's serialized size

+ 4
- 3
btcutil/filter/filter.go View File

@@ -15,6 +15,7 @@ import (
15 15
 	"git.parallelcoin.io/dev/btcd/txscript"
16 16
 	"git.parallelcoin.io/dev/btcd/util"
17 17
 	"git.parallelcoin.io/dev/btcd/wire"
18
+	"git.parallelcoin.io/dev/btcd/wire/rw"
18 19
 )
19 20
 
20 21
 // ln2Squared is simply the square of the natural log of 2.
@@ -36,7 +37,7 @@ type Filter struct {
36 37
 //
37 38
 // For more information on what values to use for both elements and fprate,
38 39
 // see https://en.wikipedia.org/wiki/Bloom_filter.
39
-func New(elements, tweak uint32, fprate float64, flags wire.BloomUpdateType) *Filter {
40
+func New(elements, tweak uint32, fprate float64, flags rw.BloomUpdateType) *Filter {
40 41
 	// Massage the false positive rate to sane values.
41 42
 	if fprate > 1.0 {
42 43
 		fprate = 1.0
@@ -245,10 +246,10 @@ func (bf *Filter) AddOutPoint(outpoint *wire.OutPoint) {
245 246
 // This function MUST be called with the filter lock held.
246 247
 func (bf *Filter) maybeAddOutpoint(pkScript []byte, outHash *chainhash.Hash, outIdx uint32) {
247 248
 	switch bf.msgFilterLoad.Flags {
248
-	case wire.BloomUpdateAll:
249
+	case rw.BloomUpdateAll:
249 250
 		outpoint := wire.NewOutPoint(outHash, outIdx)
250 251
 		bf.addOutPoint(outpoint)
251
-	case wire.BloomUpdateP2PubkeyOnly:
252
+	case rw.BloomUpdateP2PubkeyOnly:
252 253
 		class := txscript.GetScriptClass(pkScript)
253 254
 		if class == txscript.PubKeyTy || class == txscript.MultiSigTy {
254 255
 			outpoint := wire.NewOutPoint(outHash, outIdx)

+ 6
- 6
btcutil/gcs/gcs.go View File

@@ -11,8 +11,8 @@ import (
11 11
 	"io"
12 12
 	"sort"
13 13
 
14
+	"git.parallelcoin.io/dev/btcd/wire/rw"
14 15
 	"github.com/aead/siphash"
15
-	"git.parallelcoin.io/dev/btcd/wire"
16 16
 	"github.com/kkdai/bstream"
17 17
 )
18 18
 
@@ -202,7 +202,7 @@ func FromBytes(N uint32, P uint8, M uint64, d []byte) (*Filter, error) {
202 202
 // filter as returned by NBytes().
203 203
 func FromNBytes(P uint8, M uint64, d []byte) (*Filter, error) {
204 204
 	buffer := bytes.NewBuffer(d)
205
-	N, err := wire.ReadVarInt(buffer, varIntProtoVer)
205
+	N, err := rw.ReadVarInt(buffer, varIntProtoVer)
206 206
 	if err != nil {
207 207
 		return nil, err
208 208
 	}
@@ -224,9 +224,9 @@ func (f *Filter) Bytes() ([]byte, error) {
224 224
 // not include P (returned by a separate method) or the key used by SipHash.
225 225
 func (f *Filter) NBytes() ([]byte, error) {
226 226
 	var buffer bytes.Buffer
227
-	buffer.Grow(wire.VarIntSerializeSize(uint64(f.n)) + len(f.filterData))
227
+	buffer.Grow(rw.VarIntSerializeSize(uint64(f.n)) + len(f.filterData))
228 228
 
229
-	err := wire.WriteVarInt(&buffer, varIntProtoVer, uint64(f.n))
229
+	err := rw.WriteVarInt(&buffer, varIntProtoVer, uint64(f.n))
230 230
 	if err != nil {
231 231
 		return nil, err
232 232
 	}
@@ -252,9 +252,9 @@ func (f *Filter) PBytes() ([]byte, error) {
252 252
 // does not include the key used by SipHash.
253 253
 func (f *Filter) NPBytes() ([]byte, error) {
254 254
 	var buffer bytes.Buffer
255
-	buffer.Grow(wire.VarIntSerializeSize(uint64(f.n)) + 1 + len(f.filterData))
255
+	buffer.Grow(rw.VarIntSerializeSize(uint64(f.n)) + 1 + len(f.filterData))
256 256
 
257
-	err := wire.WriteVarInt(&buffer, varIntProtoVer, uint64(f.n))
257
+	err := rw.WriteVarInt(&buffer, varIntProtoVer, uint64(f.n))
258 258
 	if err != nil {
259 259
 		return nil, err
260 260
 	}

+ 4
- 4
connmgr/seed.go View File

@@ -13,7 +13,7 @@ import (
13 13
 
14 14
 	"git.parallelcoin.io/dev/btcd/chaincfg"
15 15
 	"git.parallelcoin.io/dev/btcd/node/cnf"
16
-	"git.parallelcoin.io/dev/btcd/wire"
16
+	"git.parallelcoin.io/dev/btcd/wire/na"
17 17
 	"git.parallelcoin.io/dev/btcd/wire/service"
18 18
 )
19 19
 
@@ -26,7 +26,7 @@ const (
26 26
 
27 27
 // OnSeed is the signature of the callback function which is invoked when DNS
28 28
 // seeding is succesfull.
29
-type OnSeed func(cfg *cnf.Config, addrs []*wire.NetAddress)
29
+type OnSeed func(cfg *cnf.Config, addrs []*na.NetAddress)
30 30
 
31 31
 // LookupFunc is the signature of the DNS lookup function.
32 32
 type LookupFunc func(*cnf.Config, string) ([]net.IP, error)
@@ -58,11 +58,11 @@ func SeedFromDNS(cfg *cnf.Config, chainParams *chaincfg.Params, reqServices serv
58 58
 			if numPeers == 0 {
59 59
 				return
60 60
 			}
61
-			addresses := make([]*wire.NetAddress, len(seedpeers))
61
+			addresses := make([]*na.NetAddress, len(seedpeers))
62 62
 			// if this errors then we have *real* problems
63 63
 			intPort, _ := strconv.Atoi(chainParams.DefaultPort)
64 64
 			for i, peer := range seedpeers {
65
-				addresses[i] = wire.NewNetAddressTimestamp(
65
+				addresses[i] = na.NewNetAddressTimestamp(
66 66
 					// bitcoind seeds with addresses from
67 67
 					// a time randomly selected between 3
68 68
 					// and 7 days ago.

+ 2
- 2
database/ffldb/db.go View File

@@ -18,7 +18,7 @@ import (
18 18
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
19 19
 	"git.parallelcoin.io/dev/btcd/database"
20 20
 	"git.parallelcoin.io/dev/btcd/database/internal/treap"
21
-	"git.parallelcoin.io/dev/btcd/wire"
21
+	"git.parallelcoin.io/dev/btcd/wire/rw"
22 22
 	"git.parallelcoin.io/dev/btcd/wire/service"
23 23
 	"github.com/btcsuite/goleveldb/leveldb"
24 24
 	"github.com/btcsuite/goleveldb/leveldb/comparer"
@@ -36,7 +36,7 @@ const (
36 36
 	// blockHdrSize is the size of a block header.  This is simply the
37 37
 	// constant from wire and is only provided here for convenience since
38 38
 	// wire.MaxBlockHeaderPayload is quite long.
39
-	blockHdrSize = wire.MaxBlockHeaderPayload
39
+	blockHdrSize = rw.MaxBlockHeaderPayload
40 40
 
41 41
 	// blockHdrOffset defines the offsets into a block index row for the
42 42
 	// block header.

+ 36
- 35
mempool/estimator/mempool.go View File

@@ -9,6 +9,7 @@ import (
9 9
 	"time"
10 10
 
11 11
 	"git.parallelcoin.io/dev/btcd/txscript/sig"
12
+	"git.parallelcoin.io/dev/btcd/wire/reject"
12 13
 
13 14
 	"git.parallelcoin.io/dev/btcd/blockchain"
14 15
 	"git.parallelcoin.io/dev/btcd/blockchain/indexers"
@@ -398,7 +399,7 @@ func (mp *TxPool) maybeAddOrphan(t *tx.Tx, tag Tag) error {
398 399
 		str := fmt.Sprintf("orphan transaction size of %d bytes is "+
399 400
 			"larger than max allowed size of %d bytes",
400 401
 			serializedLen, mp.Cfg.Policy.MaxOrphanTxSize)
401
-		return rule.CreateTxErr(wire.RejectNonstandard, str)
402
+		return rule.CreateTxErr(reject.Nonstandard, str)
402 403
 	}
403 404
 
404 405
 	// Add the orphan if the none of the above disqualified it.
@@ -623,7 +624,7 @@ func (mp *TxPool) CheckPoolDoubleSpend(tx *tx.Tx) (bool, error) {
623 624
 			str := fmt.Sprintf("output %v already spent by "+
624 625
 				"transaction %v in the memory pool",
625 626
 				txIn.PreviousOutPoint, conflict.Hash())
626
-			return false, rule.CreateTxErr(wire.RejectDuplicate, str)
627
+			return false, rule.CreateTxErr(reject.Duplicate, str)
627 628
 		}
628 629
 
629 630
 		isReplacement = true
@@ -873,7 +874,7 @@ func (mp *TxPool) validateReplacement(tx *tx.Tx,
873 874
 		str := fmt.Sprintf("replacement transaction %v evicts more "+
874 875
 			"transactions than permitted: max is %v, evicts %v",
875 876
 			tx.Hash(), MaxReplacementEvictions, len(conflicts))
876
-		return nil, rule.CreateTxErr(wire.RejectNonstandard, str)
877
+		return nil, rule.CreateTxErr(reject.Nonstandard, str)
877 878
 	}
878 879
 
879 880
 	// The set of conflicts (transactions we'll replace) and ancestors
@@ -885,7 +886,7 @@ func (mp *TxPool) validateReplacement(tx *tx.Tx,
885 886
 		}
886 887
 		str := fmt.Sprintf("replacement transaction %v spends parent "+
887 888
 			"transaction %v", tx.Hash(), ancestorHash)
888
-		return nil, rule.CreateTxErr(wire.RejectInvalid, str)
889
+		return nil, rule.CreateTxErr(reject.Invalid, str)
889 890
 	}
890 891
 
891 892
 	// The replacement should have a higher fee rate than each of the
@@ -908,7 +909,7 @@ func (mp *TxPool) validateReplacement(tx *tx.Tx,
908 909
 				"insufficient fee rate: needs more than %v, "+
909 910
 				"has %v", tx.Hash(), mp.Descs[hash].FeePerKB,
910 911
 				txFeeRate)
911
-			return nil, rule.CreateTxErr(wire.RejectInsufficientFee, str)
912
+			return nil, rule.CreateTxErr(reject.InsufficientFee, str)
912 913
 		}
913 914
 
914 915
 		conflictsFee += mp.Descs[hash].Fee
@@ -928,7 +929,7 @@ func (mp *TxPool) validateReplacement(tx *tx.Tx,
928 929
 		str := fmt.Sprintf("replacement transaction %v has an "+
929 930
 			"insufficient absolute fee: needs %v, has %v",
930 931
 			tx.Hash(), conflictsFee+minFee, txFee)
931
-		return nil, rule.CreateTxErr(wire.RejectInsufficientFee, str)
932
+		return nil, rule.CreateTxErr(reject.InsufficientFee, str)
932 933
 	}
933 934
 
934 935
 	// Finally, it should not spend any new unconfirmed outputs, other than
@@ -945,7 +946,7 @@ func (mp *TxPool) validateReplacement(tx *tx.Tx,
945 946
 		str := fmt.Sprintf("replacement transaction spends new "+
946 947
 			"unconfirmed input %v not found in conflicting "+
947 948
 			"transactions", txIn.PreviousOutPoint)
948
-		return nil, rule.CreateTxErr(wire.RejectInvalid, str)
949
+		return nil, rule.CreateTxErr(reject.Invalid, str)
949 950
 	}
950 951
 
951 952
 	return conflicts, nil
@@ -971,7 +972,7 @@ func (mp *TxPool) maybeAcceptTransaction(t *tx.Tx, isNew, rateLimit, rejectDupOr
971 972
 		if !segwitActive {
972 973
 			str := fmt.Sprintf("transaction %v has witness data, "+
973 974
 				"but segwit isn't active yet", txHash)
974
-			return nil, nil, rule.CreateTxErr(wire.RejectNonstandard, str)
975
+			return nil, nil, rule.CreateTxErr(reject.Nonstandard, str)
975 976
 		}
976 977
 	}
977 978
 
@@ -983,7 +984,7 @@ func (mp *TxPool) maybeAcceptTransaction(t *tx.Tx, isNew, rateLimit, rejectDupOr
983 984
 		mp.isOrphanInPool(txHash)) {
984 985
 
985 986
 		str := fmt.Sprintf("already have transaction %v", txHash)
986
-		return nil, nil, rule.CreateTxErr(wire.RejectDuplicate, str)
987
+		return nil, nil, rule.CreateTxErr(reject.Duplicate, str)
987 988
 	}
988 989
 
989 990
 	// Perform preliminary sanity checks on the transaction.  This makes
@@ -1001,7 +1002,7 @@ func (mp *TxPool) maybeAcceptTransaction(t *tx.Tx, isNew, rateLimit, rejectDupOr
1001 1002
 	if blockchain.IsCoinBase(t) {
1002 1003
 		str := fmt.Sprintf("transaction %v is an individual coinbase",
1003 1004
 			txHash)
1004
-		return nil, nil, rule.CreateTxErr(wire.RejectInvalid, str)
1005
+		return nil, nil, rule.CreateTxErr(reject.Invalid, str)
1005 1006
 	}
1006 1007
 
1007 1008
 	// Get the current height of the main chain.  A standalone transaction
@@ -1024,7 +1025,7 @@ func (mp *TxPool) maybeAcceptTransaction(t *tx.Tx, isNew, rateLimit, rejectDupOr
1024 1025
 			// a non standard error.
1025 1026
 			rejectCode, found := rule.ExtractRejectCode(err)
1026 1027
 			if !found {
1027
-				rejectCode = wire.RejectNonstandard
1028
+				rejectCode = reject.Nonstandard
1028 1029
 			}
1029 1030
 			str := fmt.Sprintf("transaction %v is not standard: %v",
1030 1031
 				txHash, err)
@@ -1065,7 +1066,7 @@ func (mp *TxPool) maybeAcceptTransaction(t *tx.Tx, isNew, rateLimit, rejectDupOr
1065 1066
 		prevOut.Index = uint32(txOutIdx)
1066 1067
 		entry := utxoView.LookupEntry(prevOut)
1067 1068
 		if entry != nil && !entry.IsSpent() {
1068
-			return nil, nil, rule.CreateTxErr(wire.RejectDuplicate,
1069
+			return nil, nil, rule.CreateTxErr(reject.Duplicate,
1069 1070
 				"transaction already exists")
1070 1071
 		}
1071 1072
 		utxoView.RemoveEntry(prevOut)
@@ -1102,7 +1103,7 @@ func (mp *TxPool) maybeAcceptTransaction(t *tx.Tx, isNew, rateLimit, rejectDupOr
1102 1103
 	}
1103 1104
 	if !blockchain.SequenceLockActive(sequenceLock, nextBlockHeight,
1104 1105
 		medianTimePast) {
1105
-		return nil, nil, rule.CreateTxErr(wire.RejectNonstandard,
1106
+		return nil, nil, rule.CreateTxErr(reject.Nonstandard,
1106 1107
 			"transaction's sequence locks on inputs not met")
1107 1108
 	}
1108 1109
 
@@ -1129,7 +1130,7 @@ func (mp *TxPool) maybeAcceptTransaction(t *tx.Tx, isNew, rateLimit, rejectDupOr
1129 1130
 			// a non standard error.
1130 1131
 			rejectCode, found := rule.ExtractRejectCode(err)
1131 1132
 			if !found {
1132
-				rejectCode = wire.RejectNonstandard
1133
+				rejectCode = reject.Nonstandard
1133 1134
 			}
1134 1135
 			str := fmt.Sprintf("transaction %v has a non-standard "+
1135 1136
 				"input: %v", txHash, err)
@@ -1157,7 +1158,7 @@ func (mp *TxPool) maybeAcceptTransaction(t *tx.Tx, isNew, rateLimit, rejectDupOr
1157 1158
 	if sigOpCost > mp.Cfg.Policy.MaxSigOpCostPerTx {
1158 1159
 		str := fmt.Sprintf("transaction %v sigop cost is too high: %d > %d",
1159 1160
 			txHash, sigOpCost, mp.Cfg.Policy.MaxSigOpCostPerTx)
1160
-		return nil, nil, rule.CreateTxErr(wire.RejectNonstandard, str)
1161
+		return nil, nil, rule.CreateTxErr(reject.Nonstandard, str)
1161 1162
 	}
1162 1163
 
1163 1164
 	// Don't allow transactions with fees too low to get into a mined block.
@@ -1178,7 +1179,7 @@ func (mp *TxPool) maybeAcceptTransaction(t *tx.Tx, isNew, rateLimit, rejectDupOr
1178 1179
 		str := fmt.Sprintf("transaction %v has %d fees which is under "+
1179 1180
 			"the required amount of %d", txHash, txFee,
1180 1181
 			minFee)
1181
-		return nil, nil, rule.CreateTxErr(wire.RejectInsufficientFee, str)
1182
+		return nil, nil, rule.CreateTxErr(reject.InsufficientFee, str)
1182 1183
 	}
1183 1184
 
1184 1185
 	// Require that free transactions have sufficient priority to be mined
@@ -1192,7 +1193,7 @@ func (mp *TxPool) maybeAcceptTransaction(t *tx.Tx, isNew, rateLimit, rejectDupOr
1192 1193
 			str := fmt.Sprintf("transaction %v has insufficient "+
1193 1194
 				"priority (%g <= %g)", txHash,
1194 1195
 				currentPriority, mining.MinHighPriority)
1195
-			return nil, nil, rule.CreateTxErr(wire.RejectInsufficientFee, str)
1196
+			return nil, nil, rule.CreateTxErr(reject.InsufficientFee, str)
1196 1197
 		}
1197 1198
 	}
1198 1199
 
@@ -1210,7 +1211,7 @@ func (mp *TxPool) maybeAcceptTransaction(t *tx.Tx, isNew, rateLimit, rejectDupOr
1210 1211
 		if mp.PennyTotal >= mp.Cfg.Policy.FreeTxRelayLimit*10*1000 {
1211 1212
 			str := fmt.Sprintf("transaction %v has been rejected "+
1212 1213
 				"by the rate limiter due to low fees", txHash)
1213
-			return nil, nil, rule.CreateTxErr(wire.RejectInsufficientFee, str)
1214
+			return nil, nil, rule.CreateTxErr(reject.InsufficientFee, str)
1214 1215
 		}
1215 1216
 		oldTotal := mp.PennyTotal
1216 1217
 
@@ -1441,7 +1442,7 @@ func (mp *TxPool) ProcessTransaction(tx *tx.Tx, allowOrphan, rateLimit bool, tag
1441 1442
 		str := fmt.Sprintf("orphan transaction %v references "+
1442 1443
 			"outputs of unknown or fully-spent "+
1443 1444
 			"transaction %v", tx.Hash(), missingParents[0])
1444
-		return nil, rule.CreateTxErr(wire.RejectDuplicate, str)
1445
+		return nil, rule.CreateTxErr(reject.Duplicate, str)
1445 1446
 	}
1446 1447
 
1447 1448
 	// Potentially add the orphan transaction to the orphan pool.
@@ -1624,13 +1625,13 @@ func CheckTransactionStandard(tx *tx.Tx, height int32,
1624 1625
 		str := fmt.Sprintf("transaction version %d is not in the "+
1625 1626
 			"valid range of %d-%d", msgTx.Version, 1,
1626 1627
 			maxTxVersion)
1627
-		return rule.CreateTxErr(wire.RejectNonstandard, str)
1628
+		return rule.CreateTxErr(reject.Nonstandard, str)
1628 1629
 	}
1629 1630
 
1630 1631
 	// The transaction must be finalized to be standard and therefore
1631 1632
 	// considered for inclusion in a block.
1632 1633
 	if !blockchain.IsFinalizedTransaction(tx, height, medianTimePast) {
1633
-		return rule.CreateTxErr(wire.RejectNonstandard,
1634
+		return rule.CreateTxErr(reject.Nonstandard,
1634 1635
 			"transaction is not finalized")
1635 1636
 	}
1636 1637
 
@@ -1642,7 +1643,7 @@ func CheckTransactionStandard(tx *tx.Tx, height int32,
1642 1643
 	if txWeight > MaxStandardTxWeight {
1643 1644
 		str := fmt.Sprintf("weight of transaction %v is larger than max "+
1644 1645
 			"allowed weight of %v", txWeight, MaxStandardTxWeight)
1645
-		return rule.CreateTxErr(wire.RejectNonstandard, str)
1646
+		return rule.CreateTxErr(reject.Nonstandard, str)
1646 1647
 	}
1647 1648
 
1648 1649
 	for i, txIn := range msgTx.TxIn {
@@ -1655,7 +1656,7 @@ func CheckTransactionStandard(tx *tx.Tx, height int32,
1655 1656
 				"script size of %d bytes is large than max "+
1656 1657
 				"allowed size of %d bytes", i, sigScriptLen,
1657 1658
 				MaxStandardSigScriptSize)
1658
-			return rule.CreateTxErr(wire.RejectNonstandard, str)
1659
+			return rule.CreateTxErr(reject.Nonstandard, str)
1659 1660
 		}
1660 1661
 
1661 1662
 		// Each transaction input signature script must only contain
@@ -1663,7 +1664,7 @@ func CheckTransactionStandard(tx *tx.Tx, height int32,
1663 1664
 		if !txscript.IsPushOnlyScript(txIn.SignatureScript) {
1664 1665
 			str := fmt.Sprintf("transaction input %d: signature "+
1665 1666
 				"script is not push only", i)
1666
-			return rule.CreateTxErr(wire.RejectNonstandard, str)
1667
+			return rule.CreateTxErr(reject.Nonstandard, str)
1667 1668
 		}
1668 1669
 	}
1669 1670
 
@@ -1677,7 +1678,7 @@ func CheckTransactionStandard(tx *tx.Tx, height int32,
1677 1678
 			// Attempt to extract a reject code from the error so
1678 1679
 			// it can be retained.  When not possible, fall back to
1679 1680
 			// a non standard error.
1680
-			rejectCode := wire.RejectNonstandard
1681
+			rejectCode := reject.Nonstandard
1681 1682
 			if rejCode, found := rule.ExtractRejectCode(err); found {
1682 1683
 				rejectCode = rejCode
1683 1684
 			}
@@ -1693,7 +1694,7 @@ func CheckTransactionStandard(tx *tx.Tx, height int32,
1693 1694
 		} else if IsDust(txOut, minRelayTxFee) {
1694 1695
 			str := fmt.Sprintf("transaction output %d: payment "+
1695 1696
 				"of %d is dust", i, txOut.Value)
1696
-			return rule.CreateTxErr(wire.RejectDust, str)
1697
+			return rule.CreateTxErr(reject.Dust, str)
1697 1698
 		}
1698 1699
 	}
1699 1700
 
@@ -1701,7 +1702,7 @@ func CheckTransactionStandard(tx *tx.Tx, height int32,
1701 1702
 	// only carries data.
1702 1703
 	if numNullDataOutputs > 1 {
1703 1704
 		str := "more than one transaction output in a nulldata script"
1704
-		return rule.CreateTxErr(wire.RejectNonstandard, str)
1705
+		return rule.CreateTxErr(reject.Nonstandard, str)
1705 1706
 	}
1706 1707
 
1707 1708
 	return nil
@@ -1737,13 +1738,13 @@ func CheckInputsStandard(t *tx.Tx, utxoView *blockchain.UtxoViewpoint) error {
1737 1738
 					"%d signature operations which is more "+
1738 1739
 					"than the allowed max amount of %d",
1739 1740
 					i, numSigOps, MaxStandardP2SHSigOps)
1740
-				return rule.CreateTxErr(wire.RejectNonstandard, str)
1741
+				return rule.CreateTxErr(reject.Nonstandard, str)
1741 1742
 			}
1742 1743
 
1743 1744
 		case txscript.NonStandardTy:
1744 1745
 			str := fmt.Sprintf("transaction input #%d has a "+
1745 1746
 				"non-standard script form", i)
1746
-			return rule.CreateTxErr(wire.RejectNonstandard, str)
1747
+			return rule.CreateTxErr(reject.Nonstandard, str)
1747 1748
 		}
1748 1749
 	}
1749 1750
 
@@ -1762,38 +1763,38 @@ func CheckPkScriptStandard(pkScript []byte, scriptClass txscript.ScriptClass) er
1762 1763
 		if err != nil {
1763 1764
 			str := fmt.Sprintf("multi-signature script parse "+
1764 1765
 				"failure: %v", err)
1765
-			return rule.CreateTxErr(wire.RejectNonstandard, str)
1766
+			return rule.CreateTxErr(reject.Nonstandard, str)
1766 1767
 		}
1767 1768
 
1768 1769
 		// A standard multi-signature public key script must contain
1769 1770
 		// from 1 to MaxStandardMultiSigKeys public keys.
1770 1771
 		if numPubKeys < 1 {
1771 1772
 			str := "multi-signature script with no pubkeys"
1772
-			return rule.CreateTxErr(wire.RejectNonstandard, str)
1773
+			return rule.CreateTxErr(reject.Nonstandard, str)
1773 1774
 		}
1774 1775
 		if numPubKeys > MaxStandardMultiSigKeys {
1775 1776
 			str := fmt.Sprintf("multi-signature script with %d "+
1776 1777
 				"public keys which is more than the allowed "+
1777 1778
 				"max of %d", numPubKeys, MaxStandardMultiSigKeys)
1778
-			return rule.CreateTxErr(wire.RejectNonstandard, str)
1779
+			return rule.CreateTxErr(reject.Nonstandard, str)
1779 1780
 		}
1780 1781
 
1781 1782
 		// A standard multi-signature public key script must have at
1782 1783
 		// least 1 signature and no more signatures than available
1783 1784
 		// public keys.
1784 1785
 		if numSigs < 1 {
1785
-			return rule.CreateTxErr(wire.RejectNonstandard,
1786
+			return rule.CreateTxErr(reject.Nonstandard,
1786 1787
 				"multi-signature script with no signatures")
1787 1788
 		}
1788 1789
 		if numSigs > numPubKeys {
1789 1790
 			str := fmt.Sprintf("multi-signature script with %d "+
1790 1791
 				"signatures which is more than the available "+
1791 1792
 				"%d public keys", numSigs, numPubKeys)
1792
-			return rule.CreateTxErr(wire.RejectNonstandard, str)
1793
+			return rule.CreateTxErr(reject.Nonstandard, str)
1793 1794
 		}
1794 1795
 
1795 1796
 	case txscript.NonStandardTy:
1796
-		return rule.CreateTxErr(wire.RejectNonstandard,
1797
+		return rule.CreateTxErr(reject.Nonstandard,
1797 1798
 			"non-standard script form")
1798 1799
 	}
1799 1800
 

+ 16
- 16
mempool/rule/error.go View File

@@ -6,7 +6,7 @@ package rule
6 6
 
7 7
 import (
8 8
 	"git.parallelcoin.io/dev/btcd/blockchain"
9
-	"git.parallelcoin.io/dev/btcd/wire"
9
+	"git.parallelcoin.io/dev/btcd/wire/reject"
10 10
 )
11 11
 
12 12
 // Err identifies a rule violation.  It is used to indicate that
@@ -33,8 +33,8 @@ func (e Err) Error() string {
33 33
 // specifically due to a rule violation and access the ErrorCode field to
34 34
 // ascertain the specific reason for the rule violation.
35 35
 type TxErr struct {
36
-	RejectCode  wire.RejectCode // The code to send with reject messages
37
-	Description string          // Human readable description of the issue
36
+	RejectCode  reject.Code // The code to send with reject messages
37
+	Description string      // Human readable description of the issue
38 38
 }
39 39
 
40 40
 // Error satisfies the error interface and prints human-readable errors.
@@ -44,7 +44,7 @@ func (e TxErr) Error() string {
44 44
 
45 45
 // CreateTxErr creates an underlying TxErr with the given a set of
46 46
 // arguments and returns a Err that encapsulates it.
47
-func CreateTxErr(c wire.RejectCode, desc string) Err {
47
+func CreateTxErr(c reject.Code, desc string) Err {
48 48
 	return Err{
49 49
 		Err: TxErr{RejectCode: c, Description: desc},
50 50
 	}
@@ -61,7 +61,7 @@ func ChainErr(chainErr blockchain.RuleError) Err {
61 61
 // ExtractRejectCode attempts to return a relevant reject code for a given error
62 62
 // by examining the error for known types.  It will return true if a code
63 63
 // was successfully extracted.
64
-func ExtractRejectCode(err error) (wire.RejectCode, bool) {
64
+func ExtractRejectCode(err error) (reject.Code, bool) {
65 65
 	// Pull the underlying error out of a Err.
66 66
 	if rerr, ok := err.(Err); ok {
67 67
 		err = rerr.Err
@@ -70,15 +70,15 @@ func ExtractRejectCode(err error) (wire.RejectCode, bool) {
70 70
 	switch err := err.(type) {
71 71
 	case blockchain.RuleError:
72 72
 		// Convert the chain error to a reject code.
73
-		var code wire.RejectCode
73
+		var code reject.Code
74 74
 		switch err.ErrorCode {
75 75
 		// Rejected due to duplicate.
76 76
 		case blockchain.ErrDuplicateBlock:
77
-			code = wire.RejectDuplicate
77
+			code = reject.Duplicate
78 78
 
79 79
 		// Rejected due to obsolete version.
80 80
 		case blockchain.ErrBlockVersionTooOld:
81
-			code = wire.RejectObsolete
81
+			code = reject.Obsolete
82 82
 
83 83
 		// Rejected due to checkpoint.
84 84
 		case blockchain.ErrCheckpointTimeTooOld:
@@ -88,11 +88,11 @@ func ExtractRejectCode(err error) (wire.RejectCode, bool) {
88 88
 		case blockchain.ErrBadCheckpoint:
89 89
 			fallthrough
90 90
 		case blockchain.ErrForkTooOld:
91
-			code = wire.RejectCheckpoint
91
+			code = reject.Checkpoint
92 92
 
93 93
 		// Everything else is due to the block or transaction being invalid.
94 94
 		default:
95
-			code = wire.RejectInvalid
95
+			code = reject.Invalid
96 96
 		}
97 97
 
98 98
 		return code, true
@@ -101,15 +101,15 @@ func ExtractRejectCode(err error) (wire.RejectCode, bool) {
101 101
 		return err.RejectCode, true
102 102
 
103 103
 	case nil:
104
-		return wire.RejectInvalid, false
104
+		return reject.Invalid, false
105 105
 	}
106 106
 
107
-	return wire.RejectInvalid, false
107
+	return reject.Invalid, false
108 108
 }
109 109
 
110 110
 // ErrToRejectErr examines the underlying type of the error and returns a reject
111 111
 // code and string appropriate to be sent in a wire.MsgReject message.
112
-func ErrToRejectErr(err error) (wire.RejectCode, string) {
112
+func ErrToRejectErr(err error) (reject.Code, string) {
113 113
 	// Return the reject code along with the error text if it can be
114 114
 	// extracted from the error.
115 115
 	rejectCode, found := ExtractRejectCode(err)
@@ -123,11 +123,11 @@ func ErrToRejectErr(err error) (wire.RejectCode, string) {
123 123
 	// string rather than allowing the following code that dereferences the
124 124
 	// err to panic.
125 125
 	if err == nil {
126
-		return wire.RejectInvalid, "rejected"
126
+		return reject.Invalid, "rejected"
127 127
 	}
128 128
 
129 129
 	// When the underlying error is not one of the above cases, just return
130
-	// wire.RejectInvalid with a generic rejected string plus the error
130
+	// reject.Invalid with a generic rejected string plus the error
131 131
 	// text.
132
-	return wire.RejectInvalid, "rejected: " + err.Error()
132
+	return reject.Invalid, "rejected: " + err.Error()
133 133
 }

+ 2
- 1
mining/cpuminer/cpuminer.go View File

@@ -21,6 +21,7 @@ import (
21 21
 	"git.parallelcoin.io/dev/btcd/mining"
22 22
 	"git.parallelcoin.io/dev/btcd/util/diff"
23 23
 	"git.parallelcoin.io/dev/btcd/wire"
24
+	"git.parallelcoin.io/dev/btcd/wire/rw"
24 25
 )
25 26
 
26 27
 const (
@@ -212,7 +213,7 @@ func (m *CPUMiner) solveBlock(msgBlock *wire.MsgBlock, blockHeight int32,
212 213
 
213 214
 	// Choose a random extra nonce offset for this block template and
214 215
 	// worker.
215
-	enOffset, err := wire.RandomUint64()
216
+	enOffset, err := rw.RandomUint64()
216 217
 	if err != nil {
217 218
 		log.Errorf("Unexpected error while generating random "+
218 219
 			"extra nonce offset: %v", err)

+ 18
- 17
mining/mining.go View File

@@ -5,13 +5,16 @@
5 5
 package mining
6 6
 
7 7
 import (
8
-	"git.parallelcoin.io/dev/btcd/txscript/sig"
9
-	"git.parallelcoin.io/dev/btcd/txscript/hash"
10 8
 	"bytes"
11 9
 	"container/heap"
12 10
 	"fmt"
13 11
 	"time"
14 12
 
13
+	"git.parallelcoin.io/dev/btcd/wire/rw"
14
+
15
+	"git.parallelcoin.io/dev/btcd/txscript/hash"
16
+	"git.parallelcoin.io/dev/btcd/txscript/sig"
17
+
15 18
 	"git.parallelcoin.io/dev/btcd/blockchain"
16 19
 	"git.parallelcoin.io/dev/btcd/btcutil/ad"
17 20
 	"git.parallelcoin.io/dev/btcd/btcutil/amt"
@@ -24,20 +27,18 @@ import (
24 27
 	"git.parallelcoin.io/dev/btcd/wire"
25 28
 )
26 29
 
27
-const (
28
-	// MinHighPriority is the minimum priority value that allows a
29
-	// transaction to be considered high priority.
30
-	MinHighPriority = amt.SatoshiPerBitcoin * 144.0 / 250
30
+// MinHighPriority is the minimum priority value that allows a
31
+// transaction to be considered high priority.
32
+const MinHighPriority = amt.SatoshiPerBitcoin * 144.0 / 250
31 33
 
32
-	// blockHeaderOverhead is the max number of bytes it takes to serialize
33
-	// a block header and max possible transaction count.
34
-	blockHeaderOverhead = wire.MaxBlockHeaderPayload + wire.MaxVarIntPayload
34
+// blockHeaderOverhead is the max number of bytes it takes to serialize
35
+// a block header and max possible transaction count.
36
+var blockHeaderOverhead = rw.MaxBlockHeaderPayload + rw.MaxVarIntPayload
35 37
 
36
-	// CoinbaseFlags is added to the coinbase script of a generated block
37
-	// and is used to monitor BIP16 support as well as blocks that are
38
-	// generated via btcd.
39
-	CoinbaseFlags = "/P2SH/btcd/"
40
-)
38
+// CoinbaseFlags is added to the coinbase script of a generated block
39
+// and is used to monitor BIP16 support as well as blocks that are
40
+// generated via btcd.
41
+const CoinbaseFlags = "/P2SH/btcd/"
41 42
 
42 43
 // TxDesc is a descriptor about a transaction in a transaction source along with
43 44
 // additional metadata.
@@ -604,7 +605,7 @@ mempoolLoop:
604 605
 	// possible transaction count size, plus the size of the coinbase
605 606
 	// transaction.
606 607
 	blockWeight := uint32((blockHeaderOverhead * blockchain.WitnessScaleFactor) +
607
-		blockchain.GetTransactionWeight(coinbaseTx))
608
+		int(blockchain.GetTransactionWeight(coinbaseTx)))
608 609
 	blockSigOpCost := coinbaseSigOpCost
609 610
 	totalFees := int64(0)
610 611
 
@@ -798,8 +799,8 @@ mempoolLoop:
798 799
 	// Now that the actual transactions have been selected, update the
799 800
 	// block weight for the real transaction count and coinbase value with
800 801
 	// the total fees accordingly.
801
-	blockWeight -= wire.MaxVarIntPayload -
802
-		(uint32(wire.VarIntSerializeSize(uint64(len(blockTxns)))) *
802
+	blockWeight -= rw.MaxVarIntPayload -
803
+		(uint32(rw.VarIntSerializeSize(uint64(len(blockTxns)))) *
803 804
 			blockchain.WitnessScaleFactor)
804 805
 	coinbaseTx.MsgTx().TxOut[0].Value += totalFees
805 806
 	txFees[0] = -totalFees

+ 3
- 2
netsync/manager/manager.go View File

@@ -23,6 +23,7 @@ import (
23 23
 	peerpkg "git.parallelcoin.io/dev/btcd/peer"
24 24
 	"git.parallelcoin.io/dev/btcd/wire"
25 25
 	"git.parallelcoin.io/dev/btcd/wire/inv"
26
+	"git.parallelcoin.io/dev/btcd/wire/message"
26 27
 	"git.parallelcoin.io/dev/btcd/wire/service"
27 28
 )
28 29
 
@@ -636,7 +637,7 @@ func (sm *Sync) HandleTxMsg(tmsg *TxMsg) {
636 637
 		// Convert the error into an appropriate reject message and
637 638
 		// send it.
638 639
 		code, reason := rule.ErrToRejectErr(err)
639
-		peer.PushRejectMsg(wire.CmdTx, code, reason, txHash, false)
640
+		peer.PushRejectMsg(message.CmdTx, code, reason, txHash, false)
640 641
 		return
641 642
 	}
642 643
 
@@ -742,7 +743,7 @@ func (sm *Sync) HandleBlockMsg(bmsg *BlockMsg) {
742 743
 		// Convert the error into an appropriate reject message and
743 744
 		// send it.
744 745
 		code, reason := rule.ErrToRejectErr(err)
745
-		peer.PushRejectMsg(wire.CmdBlock, code, reason, blockHash, false)
746
+		peer.PushRejectMsg(message.CmdBlock, code, reason, blockHash, false)
746 747
 		return
747 748
 	}
748 749
 

+ 4
- 3
node/rpc/rpchandlers.go View File

@@ -20,6 +20,7 @@ import (
20 20
 	"git.parallelcoin.io/dev/btcd/util"
21 21
 	"git.parallelcoin.io/dev/btcd/util/diff"
22 22
 	"git.parallelcoin.io/dev/btcd/wire/inv"
23
+	"git.parallelcoin.io/dev/btcd/wire/rw"
23 24
 
24 25
 	"git.parallelcoin.io/dev/btcd/blockchain"
25 26
 	"git.parallelcoin.io/dev/btcd/btcec"
@@ -1776,7 +1777,7 @@ func HandleHelp(s *Server, cmd interface{}, closeChan <-chan struct{}) (interfac
1776 1777
 // HandlePing implements the ping command.
1777 1778
 func HandlePing(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
1778 1779
 	// Ask server to ping \o_
1779
-	nonce, err := wire.RandomUint64()
1780
+	nonce, err := rw.RandomUint64()
1780 1781
 	if err != nil {
1781 1782
 		return nil, InternalError("Not sending ping - failed to "+
1782 1783
 			"generate nonce: "+err.Error(), "")
@@ -2302,8 +2303,8 @@ func HandleVerifyMessage(s *Server, cmd interface{}, closeChan <-chan struct{})
2302 2303
 	// Validate the signature - this just shows that it was valid at all.
2303 2304
 	// we will compare it with the key next.
2304 2305
 	var buf bytes.Buffer
2305
-	wire.WriteVarString(&buf, 0, "Bitcoin Signed Message:\n")
2306
-	wire.WriteVarString(&buf, 0, c.Message)
2306
+	rw.WriteVarString(&buf, 0, "Bitcoin Signed Message:\n")
2307
+	rw.WriteVarString(&buf, 0, c.Message)
2307 2308
 	expectedMessageHash := chainhash.DoubleHashB(buf.Bytes())
2308 2309
 	pk, wasCompressed, err := btcec.RecoverCompact(btcec.S256(), sig,
2309 2310
 		expectedMessageHash)

+ 2
- 1
node/rpc/wsclient.go View File

@@ -15,6 +15,7 @@ import (
15 15
 	"git.parallelcoin.io/dev/btcd/node/ws"
16 16
 	sem "git.parallelcoin.io/dev/btcd/util/semaphore"
17 17
 	"git.parallelcoin.io/dev/btcd/wire"
18
+	"git.parallelcoin.io/dev/btcd/wire/rw"
18 19
 	"github.com/btcsuite/websocket"
19 20
 )
20 21
 
@@ -107,7 +108,7 @@ type Client struct {
107 108
 func NewWebsocketClient(server *Server, conn *websocket.Conn,
108 109
 	remoteAddr string, authenticated bool, isAdmin bool) (*Client, error) {
109 110
 
110
-	sessionID, err := wire.RandomUint64()
111
+	sessionID, err := rw.RandomUint64()
111 112
 	if err != nil {
112 113
 		return nil, err
113 114
 	}

+ 3
- 2
node/server.go View File

@@ -11,6 +11,7 @@ import (
11 11
 	"time"
12 12
 
13 13
 	"git.parallelcoin.io/dev/btcd/wire/inv"
14
+	"git.parallelcoin.io/dev/btcd/wire/na"
14 15
 
15 16
 	"git.parallelcoin.io/dev/btcd/txscript/hash"
16 17
 	"git.parallelcoin.io/dev/btcd/txscript/sig"
@@ -1079,7 +1080,7 @@ func (s *Server) PeerHandler(cfg *cnf.Config) {
1079 1080
 	if !cfg.DisableDNSSeed {
1080 1081
 		// Add peers discovered through DNS to the address manager.
1081 1082
 		connmgr.SeedFromDNS(cfg, cfg.StateActiveNet.Params, defaults.RequiredServices,
1082
-			util.Lookup, func(cfg *cnf.Config, addrs []*wire.NetAddress) {
1083
+			util.Lookup, func(cfg *cnf.Config, addrs []*na.NetAddress) {
1083 1084
 				// Bitcoind uses a lookup of the dns seeder here. This
1084 1085
 				// is rather strange since the values looked up by the
1085 1086
 				// DNS seed lookups will vary quite a lot.
@@ -1429,7 +1430,7 @@ out:
1429 1430
 					log.Srvr.Warnf("UPnP can't get external address: %v", err)
1430 1431
 					continue out
1431 1432
 				}
1432
-				na := wire.NewNetAddressIPPort(externalip, uint16(listenPort),
1433
+				na := na.NewNetAddressIPPort(externalip, uint16(listenPort),
1433 1434
 					s.Services)
1434 1435
 				err = s.AddrManager.AddLocalAddress(na, addrmgr.UpnpPrio)
1435 1436
 				if err != nil {

+ 12
- 10
node/serverpeer.go View File

@@ -12,6 +12,8 @@ import (
12 12
 	"git.parallelcoin.io/dev/btcd/btcutil/filter"
13 13
 	"git.parallelcoin.io/dev/btcd/btcutil/tx"
14 14
 	"git.parallelcoin.io/dev/btcd/wire/inv"
15
+	"git.parallelcoin.io/dev/btcd/wire/na"
16
+	"git.parallelcoin.io/dev/btcd/wire/reject"
15 17
 	"git.parallelcoin.io/dev/btcd/wire/service"
16 18
 	"git.parallelcoin.io/dev/btcd/wire/version"
17 19
 
@@ -72,14 +74,14 @@ func (sp *ServerPeer) NewestBlock(ncfg *cnf.Config) (*chainhash.Hash, int32, err
72 74
 
73 75
 // AddKnownAddresses adds the given addresses to the set of known addresses to
74 76
 // the peer to prevent sending duplicate addresses.
75
-func (sp *ServerPeer) AddKnownAddresses(addresses []*wire.NetAddress) {
77
+func (sp *ServerPeer) AddKnownAddresses(addresses []*na.NetAddress) {
76 78
 	for _, na := range addresses {
77 79
 		sp.KnownAddresses[addrmgr.NetAddressKey(na)] = struct{}{}
78 80
 	}
79 81
 }
80 82
 
81 83
 // AddressKnown true if the given address is already known to the peer.
82
-func (sp *ServerPeer) AddressKnown(na *wire.NetAddress) bool {
84
+func (sp *ServerPeer) AddressKnown(na *na.NetAddress) bool {
83 85
 	_, exists := sp.KnownAddresses[addrmgr.NetAddressKey(na)]
84 86
 	return exists
85 87
 }
@@ -105,9 +107,9 @@ func (sp *ServerPeer) RelayTxDisabled() bool {
105 107
 
106 108
 // ServerPushAddrMsg sends an addr message to the connected peer using the
107 109
 // provided addresses.
108
-func (sp *ServerPeer) ServerPushAddrMsg(addresses []*wire.NetAddress) {
110
+func (sp *ServerPeer) ServerPushAddrMsg(addresses []*na.NetAddress) {
109 111
 	// Filter addresses already known to the peer.
110
-	addrs := make([]*wire.NetAddress, 0, len(addresses))
112
+	addrs := make([]*na.NetAddress, 0, len(addresses))
111 113
 	for _, addr := range addresses {
112 114
 		if !sp.AddressKnown(addr) {
113 115
 			addrs = append(addrs, addr)
@@ -197,7 +199,7 @@ func (sp *ServerPeer) OnVersion(ncfg *cnf.Config, _ *peer.Peer, msg *wire.MsgVer
197 199
 			missingServices)
198 200
 		reason := fmt.Sprintf("required services %#x not offered",
199 201
 			uint64(missingServices))
200
-		return wire.NewMsgReject(msg.Command(), wire.RejectNonstandard, reason)
202
+		return wire.NewMsgReject(msg.Command(), reject.Nonstandard, reason)
201 203
 	}
202 204
 
203 205
 	// Update the address manager and request known addresses from the
@@ -231,7 +233,7 @@ func (sp *ServerPeer) OnVersion(ncfg *cnf.Config, _ *peer.Peer, msg *wire.MsgVer
231 233
 			lna := addrManager.GetBestLocalAddress(remoteAddr)
232 234
 			if network.IsRoutable(lna) {
233 235
 				// Filter addresses the peer already knows about.
234
-				addresses := []*wire.NetAddress{lna}
236
+				addresses := []*na.NetAddress{lna}
235 237
 				sp.ServerPushAddrMsg(addresses)
236 238
 			}
237 239
 		}
@@ -1050,7 +1052,7 @@ func (sp *ServerPeer) OnAddr(ncfg *cnf.Config, _ *peer.Peer, msg *wire.MsgAddr)
1050 1052
 		return
1051 1053
 	}
1052 1054
 
1053
-	for _, na := range msg.AddrList {
1055
+	for _, nn := range msg.AddrList {
1054 1056
 		// Don't add more address if we're disconnecting.
1055 1057
 		if !sp.GetConnected() {
1056 1058
 			return
@@ -1060,12 +1062,12 @@ func (sp *ServerPeer) OnAddr(ncfg *cnf.Config, _ *peer.Peer, msg *wire.MsgAddr)
1060 1062
 		// in the future so this address is one of the first to be
1061 1063
 		// removed when space is needed.
1062 1064
 		now := time.Now()
1063
-		if na.Timestamp.After(now.Add(time.Minute * 10)) {
1064
-			na.Timestamp = now.Add(-1 * time.Hour * 24 * 5)
1065
+		if nn.Timestamp.After(now.Add(time.Minute * 10)) {
1066
+			nn.Timestamp = now.Add(-1 * time.Hour * 24 * 5)
1065 1067
 		}
1066 1068
 
1067 1069
 		// Add address to known addresses for this peer.
1068
-		sp.AddKnownAddresses([]*wire.NetAddress{na})
1070
+		sp.AddKnownAddresses([]*na.NetAddress{nn})
1069 1071
 	}
1070 1072
 
1071 1073
 	// Add addresses to server address manager.  The address manager handles

+ 2
- 2
node/util.go View File

@@ -19,7 +19,7 @@ import (
19 19
 	"git.parallelcoin.io/dev/btcd/util"
20 20
 	"git.parallelcoin.io/dev/btcd/util/checkpoint"
21 21
 	"git.parallelcoin.io/dev/btcd/util/upnp"
22
-	"git.parallelcoin.io/dev/btcd/wire"
22
+	"git.parallelcoin.io/dev/btcd/wire/na"
23 23
 	"git.parallelcoin.io/dev/btcd/wire/service"
24 24
 )
25 25
 
@@ -257,7 +257,7 @@ func AddLocalAddress(cfg *cnf.Config, addrMgr *addrmgr.AddrManager, addr string,
257 257
 				continue
258 258
 			}
259 259
 
260
-			netAddr := wire.NewNetAddressIPPort(ifaceIP, uint16(port), services)
260
+			netAddr := na.NewNetAddressIPPort(ifaceIP, uint16(port), services)
261 261
 			addrMgr.AddLocalAddress(netAddr, addrmgr.BoundPrio)
262 262
 		}
263 263
 	} else {

+ 6
- 3
peer/log.go View File

@@ -9,11 +9,14 @@ import (
9 9
 	"strings"
10 10
 	"time"
11 11
 
12
+	"git.parallelcoin.io/dev/btcd/wire/message"
13
+	"git.parallelcoin.io/dev/btcd/wire/rw"
14
+
15
+	"git.parallelcoin.io/dev/btcd/btclog"
12 16
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
13 17
 	"git.parallelcoin.io/dev/btcd/txscript"
14 18
 	"git.parallelcoin.io/dev/btcd/wire"
15 19
 	"git.parallelcoin.io/dev/btcd/wire/inv"
16
-	"git.parallelcoin.io/dev/btcd/btclog"
17 20
 )
18 21
 
19 22
 const (
@@ -213,11 +216,11 @@ func messageSummary(msg wire.Message) string {
213 216
 		// characters which are even remotely dangerous such as HTML
214 217
 		// control characters, etc.  Also limit them to sane length for
215 218
 		// logging.
216
-		rejCommand := sanitizeString(msg.Cmd, wire.CommandSize)
219
+		rejCommand := sanitizeString(msg.Cmd, rw.CommandSize)
217 220
 		rejReason := sanitizeString(msg.Reason, maxRejectReasonLen)
218 221
 		summary := fmt.Sprintf("cmd %v, code %v, reason %v", rejCommand,
219 222
 			msg.Code, rejReason)
220
-		if rejCommand == wire.CmdBlock || rejCommand == wire.CmdTx {
223
+		if rejCommand == message.CmdBlock || rejCommand == message.CmdTx {
221 224
 			summary += fmt.Sprintf(", hash %v", msg.Hash)
222 225
 		}
223 226
 		return summary

+ 48
- 43
peer/peer.go View File

@@ -18,6 +18,11 @@ import (
18 18
 	"sync/atomic"
19 19
 	"time"
20 20
 
21
+	"git.parallelcoin.io/dev/btcd/wire/message"
22
+	"git.parallelcoin.io/dev/btcd/wire/na"
23
+	"git.parallelcoin.io/dev/btcd/wire/reject"
24
+	"git.parallelcoin.io/dev/btcd/wire/rw"
25
+
21 26
 	"git.parallelcoin.io/dev/btcd/node/cnf"
22 27
 	"git.parallelcoin.io/dev/btcd/peer/mru"
23 28
 
@@ -296,12 +301,12 @@ func minUint32(a, b uint32) uint32 {
296 301
 // newNetAddress attempts to extract the IP address and port from the passed
297 302
 // net.Addr interface and create a bitcoin NetAddress structure using that
298 303
 // information.
299
-func newNetAddress(addr net.Addr, services service.Flag) (*wire.NetAddress, error) {
304
+func newNetAddress(addr net.Addr, services service.Flag) (*na.NetAddress, error) {
300 305
 	// addr will be a net.TCPAddr when not using a proxy.
301 306
 	if tcpAddr, ok := addr.(*net.TCPAddr); ok {
302 307
 		ip := tcpAddr.IP
303 308
 		port := uint16(tcpAddr.Port)
304
-		na := wire.NewNetAddressIPPort(ip, port, services)
309
+		na := na.NewNetAddressIPPort(ip, port, services)
305 310
 		return na, nil
306 311
 	}
307 312
 
@@ -312,7 +317,7 @@ func newNetAddress(addr net.Addr, services service.Flag) (*wire.NetAddress, erro
312 317
 			ip = net.ParseIP("0.0.0.0")
313 318
 		}
314 319
 		port := uint16(proxiedAddr.Port)
315
-		na := wire.NewNetAddressIPPort(ip, port, services)
320
+		na := na.NewNetAddressIPPort(ip, port, services)
316 321
 		return na, nil
317 322
 	}
318 323
 
@@ -328,7 +333,7 @@ func newNetAddress(addr net.Addr, services service.Flag) (*wire.NetAddress, erro
328 333
 	if err != nil {
329 334
 		return nil, err
330 335
 	}
331
-	na := wire.NewNetAddressIPPort(ip, uint16(port), services)
336
+	na := na.NewNetAddressIPPort(ip, uint16(port), services)
332 337
 	return na, nil
333 338
 }
334 339
 
@@ -393,12 +398,12 @@ type StatsSnap struct {
393 398
 type HashFunc func(ncfg *cnf.Config) (hash *chainhash.Hash, height int32, err error)
394 399
 
395 400
 // AddrFunc is a func which takes an address and returns a related address.
396
-type AddrFunc func(ncfg *cnf.Config, remoteAddr *wire.NetAddress) *wire.NetAddress
401
+type AddrFunc func(ncfg *cnf.Config, remoteAddr *na.NetAddress) *na.NetAddress
397 402
 
398 403
 // HostToNetAddrFunc is a func which takes a host, port, services and returns
399 404
 // the netaddress.
400 405
 type HostToNetAddrFunc func(ncfg *cnf.Config, host string, port uint16,
401
-	services service.Flag) (*wire.NetAddress, error)
406
+	services service.Flag) (*na.NetAddress, error)
402 407
 
403 408
 // NOTE: The overall data flow of a peer is split into 3 goroutines.  Inbound
404 409
 // messages are read via the inHandler goroutine and generally dispatched to
@@ -444,7 +449,7 @@ type Peer struct {
444 449
 	inbound bool
445 450
 
446 451
 	flagsMtx             sync.Mutex // protects the peer flags below
447
-	na                   *wire.NetAddress
452
+	na                   *na.NetAddress
448 453
 	id                   int32
449 454
 	userAgent            string
450 455
 	services             service.Flag
@@ -580,7 +585,7 @@ func (p *Peer) GetID() int32 {
580 585
 // GetNetworkAddress returns the peer network address.
581 586
 //
582 587
 // This function is safe for concurrent access.
583
-func (p *Peer) GetNetworkAddress() *wire.NetAddress {
588
+func (p *Peer) GetNetworkAddress() *na.NetAddress {
584 589
 	p.flagsMtx.Lock()
585 590
 	na := p.na
586 591
 	p.flagsMtx.Unlock()
@@ -823,7 +828,7 @@ func (p *Peer) IsWitnessEnabled() bool {
823 828
 // message will be sent if there are no entries in the provided addresses slice.
824 829
 //
825 830
 // This function is safe for concurrent access.
826
-func (p *Peer) PushAddrMsg(addresses []*wire.NetAddress) ([]*wire.NetAddress, error) {
831
+func (p *Peer) PushAddrMsg(addresses []*na.NetAddress) ([]*na.NetAddress, error) {
827 832
 	addressCount := len(addresses)
828 833
 
829 834
 	// Nothing to send.
@@ -832,7 +837,7 @@ func (p *Peer) PushAddrMsg(addresses []*wire.NetAddress) ([]*wire.NetAddress, er
832 837
 	}
833 838
 
834 839
 	msg := wire.NewMsgAddr()
835
-	msg.AddrList = make([]*wire.NetAddress, addressCount)
840
+	msg.AddrList = make([]*na.NetAddress, addressCount)
836 841
 	copy(msg.AddrList, addresses)
837 842
 
838 843
 	// Randomize the addresses sent if there are more than the maximum allowed.
@@ -946,7 +951,7 @@ func (p *Peer) PushGetHeadersMsg(locator blockchain.BlockLocator, stopHash *chai
946 951
 // function to block until the reject message has actually been sent.
947 952
 //
948 953
 // This function is safe for concurrent access.
949
-func (p *Peer) PushRejectMsg(command string, code wire.RejectCode, reason string, hash *chainhash.Hash, wait bool) {
954
+func (p *Peer) PushRejectMsg(command string, code reject.Code, reason string, hash *chainhash.Hash, wait bool) {
950 955
 	// Don't bother sending the reject message if the protocol version
951 956
 	// is too low.
952 957
 	if p.GetVersionKnown() && p.GetProtocolVersion() < version.Reject {
@@ -954,7 +959,7 @@ func (p *Peer) PushRejectMsg(command string, code wire.RejectCode, reason string
954 959
 	}
955 960
 
956 961
 	msg := wire.NewMsgReject(command, code, reason)
957
-	if command == wire.CmdTx || command == wire.CmdBlock {
962
+	if command == message.CmdTx || command == message.CmdBlock {
958 963
 		if hash == nil {
959 964
 			log.Warnf("Sending a reject message for command "+
960 965
 				"type %v which should have specified a hash "+
@@ -1095,7 +1100,7 @@ func (p *Peer) isAllowedReadError(err error) bool {
1095 1100
 	}
1096 1101
 
1097 1102
 	// Don't allow the error if it's not specifically a malformed message error.
1098
-	if _, ok := err.(*wire.MessageError); !ok {
1103
+	if _, ok := err.(*message.Error); !ok {
1099 1104
 		return false
1100 1105
 	}
1101 1106
 
@@ -1147,31 +1152,31 @@ func (p *Peer) maybeAddDeadline(pendingResponses map[string]time.Time, msgCmd st
1147 1152
 	// response won't be received in time.
1148 1153
 	deadline := time.Now().Add(stallResponseTimeout)
1149 1154
 	switch msgCmd {
1150
-	case wire.CmdVersion:
1155
+	case message.CmdVersion:
1151 1156
 		// Expects a verack message.
1152
-		pendingResponses[wire.CmdVerAck] = deadline
1157
+		pendingResponses[message.CmdVerAck] = deadline
1153 1158
 
1154
-	case wire.CmdMemPool:
1159
+	case message.CmdMemPool:
1155 1160
 		// Expects an inv message.
1156
-		pendingResponses[wire.CmdInv] = deadline
1161
+		pendingResponses[message.CmdInv] = deadline
1157 1162
 
1158
-	case wire.CmdGetBlocks:
1163
+	case message.CmdGetBlocks:
1159 1164
 		// Expects an inv message.
1160
-		pendingResponses[wire.CmdInv] = deadline
1165
+		pendingResponses[message.CmdInv] = deadline
1161 1166
 
1162
-	case wire.CmdGetData:
1167
+	case message.CmdGetData:
1163 1168
 		// Expects a block, merkleblock, tx, or notfound message.
1164
-		pendingResponses[wire.CmdBlock] = deadline
1165
-		pendingResponses[wire.CmdMerkleBlock] = deadline
1166
-		pendingResponses[wire.CmdTx] = deadline
1167
-		pendingResponses[wire.CmdNotFound] = deadline
1169
+		pendingResponses[message.CmdBlock] = deadline
1170
+		pendingResponses[message.CmdMerkleBlock] = deadline
1171
+		pendingResponses[message.CmdTx] = deadline
1172
+		pendingResponses[message.CmdNotFound] = deadline
1168 1173
 
1169
-	case wire.CmdGetHeaders:
1174
+	case message.CmdGetHeaders:
1170 1175
 		// Expects a headers message.  Use a longer deadline since it
1171 1176
 		// can take a while for the remote peer to load all of the
1172 1177
 		// headers.
1173 1178
 		deadline = time.Now().Add(stallResponseTimeout * 3)
1174
-		pendingResponses[wire.CmdHeaders] = deadline
1179
+		pendingResponses[message.CmdHeaders] = deadline
1175 1180
 	}
1176 1181
 }
1177 1182
 
@@ -1217,17 +1222,17 @@ out:
1217 1222
 				// one of a group of responses, remove
1218 1223
 				// everything in the expected group accordingly.
1219 1224
 				switch msgCmd := msg.message.Command(); msgCmd {
1220
-				case wire.CmdBlock:
1225
+				case message.CmdBlock:
1221 1226
 					fallthrough
1222
-				case wire.CmdMerkleBlock:
1227
+				case message.CmdMerkleBlock:
1223 1228
 					fallthrough
1224
-				case wire.CmdTx:
1229
+				case message.CmdTx:
1225 1230
 					fallthrough
1226
-				case wire.CmdNotFound:
1227
-					delete(pendingResponses, wire.CmdBlock)
1228
-					delete(pendingResponses, wire.CmdMerkleBlock)
1229
-					delete(pendingResponses, wire.CmdTx)
1230
-					delete(pendingResponses, wire.CmdNotFound)
1231
+				case message.CmdNotFound:
1232
+					delete(pendingResponses, message.CmdBlock)
1233
+					delete(pendingResponses, message.CmdMerkleBlock)
1234
+					delete(pendingResponses, message.CmdTx)
1235
+					delete(pendingResponses, message.CmdNotFound)
1231 1236
 
1232 1237
 				default:
1233 1238
 					delete(pendingResponses, msgCmd)
@@ -1366,7 +1371,7 @@ out:
1366 1371
 				// at least that much of the message was valid, but that is not
1367 1372
 				// currently exposed by wire, so just used malformed for the
1368 1373
 				// command.
1369
-				p.PushRejectMsg("malformed", wire.RejectMalformed, errMsg, nil,
1374
+				p.PushRejectMsg("malformed", reject.Malformed, errMsg, nil,
1370 1375
 					true)
1371 1376
 			}
1372 1377
 			break out
@@ -1379,7 +1384,7 @@ out:
1379 1384
 		switch msg := rmsg.(type) {
1380 1385
 		case *wire.MsgVersion:
1381 1386
 			// Limit to one version message per peer.
1382
-			p.PushRejectMsg(msg.Command(), wire.RejectDuplicate,
1387
+			p.PushRejectMsg(msg.Command(), reject.Duplicate,
1383 1388
 				"duplicate version message", nil, true)
1384 1389
 			break out
1385 1390
 
@@ -1796,7 +1801,7 @@ out:
1796 1801
 	for {
1797 1802
 		select {
1798 1803
 		case <-pingTicker.C:
1799
-			nonce, err := wire.RandomUint64()
1804
+			nonce, err := rw.RandomUint64()
1800 1805
 			if err != nil {
1801 1806
 				log.Errorf("Not sending ping to %s: %v", p, err)
1802 1807
 				continue
@@ -1899,7 +1904,7 @@ func (p *Peer) readRemoteVersionMsg(ncfg *cnf.Config) error {
1899 1904
 	msg, ok := remoteMsg.(*wire.MsgVersion)
1900 1905
 	if !ok {
1901 1906
 		reason := "a version message must precede all others"
1902
-		rejectMsg := wire.NewMsgReject(msg.Command(), wire.RejectMalformed,
1907
+		rejectMsg := wire.NewMsgReject(msg.Command(), reject.Malformed,
1903 1908
 			reason)
1904 1909
 		_ = p.writeMessage(ncfg, rejectMsg, wire.LatestEncoding)
1905 1910
 		return errors.New(reason)
@@ -1972,7 +1977,7 @@ func (p *Peer) readRemoteVersionMsg(ncfg *cnf.Config) error {
1972 1977
 		// disconnecting.
1973 1978
 		reason := fmt.Sprintf("protocol version must be %d or greater",
1974 1979
 			MinAcceptableProtocolVersion)
1975
-		rejectMsg := wire.NewMsgReject(msg.Command(), wire.RejectObsolete,
1980
+		rejectMsg := wire.NewMsgReject(msg.Command(), reject.Obsolete,
1976 1981
 			reason)
1977 1982
 		_ = p.writeMessage(ncfg, rejectMsg, wire.LatestEncoding)
1978 1983
 		return errors.New(reason)
@@ -2002,12 +2007,12 @@ func (p *Peer) localVersionMsg(ncfg *cnf.Config) (*wire.MsgVersion, error) {
2002 2007
 		proxyaddress, _, err := net.SplitHostPort(p.cfg.Proxy)
2003 2008
 		// invalid proxy means poorly configured, be on the safe side.
2004 2009
 		if err != nil || p.na.IP.String() == proxyaddress {
2005
-			theirNA = wire.NewNetAddressIPPort(net.IP([]byte{0, 0, 0, 0}), 0,
2010
+			theirNA = na.NewNetAddressIPPort(net.IP([]byte{0, 0, 0, 0}), 0,
2006 2011
 				theirNA.Services)
2007 2012
 		}
2008 2013
 	}
2009 2014
 
2010
-	// Create a wire.NetAddress with only the services set to use as the
2015
+	// Create a na.NetAddress with only the services set to use as the
2011 2016
 	// "addrme" in the version message.
2012 2017
 	//
2013 2018
 	// Older nodes previously added the IP and port information to the
@@ -2016,7 +2021,7 @@ func (p *Peer) localVersionMsg(ncfg *cnf.Config) (*wire.MsgVersion, error) {
2016 2021
 	// accepted inbound connections.
2017 2022
 	//
2018 2023
 	// Also, the timestamp is unused in the version message.
2019
-	ourNA := &wire.NetAddress{
2024
+	ourNA := &na.NetAddress{
2020 2025
 		Services: p.cfg.Services,
2021 2026
 	}
2022 2027
 
@@ -2225,7 +2230,7 @@ func NewOutboundPeer(ncfg *cnf.Config, cfg *Config, addr string) (*Peer, error)
2225 2230
 		}
2226 2231
 		p.na = na
2227 2232
 	} else {
2228
-		p.na = wire.NewNetAddressIPPort(net.ParseIP(host), uint16(port), 0)
2233
+		p.na = na.NewNetAddressIPPort(net.ParseIP(host), uint16(port), 0)
2229 2234
 	}
2230 2235
 
2231 2236
 	return p, nil

+ 5
- 5
txscript/script.go View File

@@ -1,14 +1,15 @@
1
-
2 1
 package txscript
3 2
 
4 3
 import (
5
-	"git.parallelcoin.io/dev/btcd/txscript/hash"
6
-	"git.parallelcoin.io/dev/btcd/txscript/er"
7 4
 	"bytes"
8 5
 	"encoding/binary"
9 6
 	"fmt"
10 7
 	"time"
11 8
 
9
+	"git.parallelcoin.io/dev/btcd/txscript/er"
10
+	"git.parallelcoin.io/dev/btcd/txscript/hash"
11
+	"git.parallelcoin.io/dev/btcd/wire/rw"
12
+
12 13
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
13 14
 	"git.parallelcoin.io/dev/btcd/wire"
14 15
 )
@@ -369,7 +370,6 @@ func removeOpcodeByData(pkscript []parsedOpcode, data []byte) []parsedOpcode {
369 370
 
370 371
 }
371 372
 
372
-
373 373
 // calcWitnessSignatureHash computes the sighash digest of a transaction's
374 374
 // segwit input using the new, optimized digest calculation algorithm defined
375 375
 // in BIP0143: https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki.
@@ -447,7 +447,7 @@ func calcWitnessSignatureHash(subScript []parsedOpcode, sigHashes *hash.TxSig,
447 447
 		// the original script, with all code separators removed,
448 448
 		// serialized with a var int length prefix.
449 449
 		rawScript, _ := unparseScript(subScript)
450
-		wire.WriteVarBytes(&sigHash, 0, rawScript)
450
+		rw.WriteVarBytes(&sigHash, 0, rawScript)
451 451
 	}
452 452
 
453 453
 	// Next, add the input amount, and sequence number of the input being

+ 6
- 9
wire/blockheader.go View File

@@ -5,14 +5,11 @@ import (
5 5
 	"io"
6 6
 	"time"
7 7
 
8
+	"git.parallelcoin.io/dev/btcd/wire/rw"
9
+
8 10
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
9 11
 )
10 12
 
11
-// MaxBlockHeaderPayload is the maximum number of bytes a block header can be.
12
-// Version 4 bytes + Timestamp 4 bytes + Bits 4 bytes + Nonce 4 bytes +
13
-// PrevBlock and MerkleRoot hashes.
14
-const MaxBlockHeaderPayload = 16 + (chainhash.HashSize * 2)
15
-
16 13
 // BlockHeader defines information about a block and is used in the bitcoin
17 14
 // block (MsgBlock) and headers (MsgHeaders) messages.
18 15
 type BlockHeader struct {
@@ -46,7 +43,7 @@ func (h *BlockHeader) BlockHash() chainhash.Hash {
46 43
 	// transactions.  Ignore the error returns since there is no way the
47 44
 	// encode could fail except being out of memory which would cause a
48 45
 	// run-time panic.
49
-	buf := bytes.NewBuffer(make([]byte, 0, MaxBlockHeaderPayload))
46
+	buf := bytes.NewBuffer(make([]byte, 0, rw.MaxBlockHeaderPayload))
50 47
 	_ = writeBlockHeader(buf, 0, h)
51 48
 
52 49
 	return chainhash.DoubleHashH(buf.Bytes())
@@ -110,8 +107,8 @@ func NewBlockHeader(version int32, prevHash, merkleRootHash *chainhash.Hash,
110 107
 // decoding block headers stored to disk, such as in a database, as opposed to
111 108
 // decoding from the wire.
112 109
 func readBlockHeader(r io.Reader, pver uint32, bh *BlockHeader) error {
113
-	return ReadElements(r, &bh.Version, &bh.PrevBlock, &bh.MerkleRoot,
114
-		(*Uint32Time)(&bh.Timestamp), &bh.Bits, &bh.Nonce)
110
+	return rw.ReadElements(r, &bh.Version, &bh.PrevBlock, &bh.MerkleRoot,
111
+		(*rw.Uint32Time)(&bh.Timestamp), &bh.Bits, &bh.Nonce)
115 112
 }
116 113
 
117 114
 // writeBlockHeader writes a bitcoin block header to w.  See Serialize for
@@ -119,6 +116,6 @@ func readBlockHeader(r io.Reader, pver uint32, bh *BlockHeader) error {
119 116
 // opposed to encoding for the wire.
120 117
 func writeBlockHeader(w io.Writer, pver uint32, bh *BlockHeader) error {
121 118
 	sec := uint32(bh.Timestamp.Unix())
122
-	return WriteElements(w, bh.Version, &bh.PrevBlock, &bh.MerkleRoot,
119
+	return rw.WriteElements(w, bh.Version, &bh.PrevBlock, &bh.MerkleRoot,
123 120
 		sec, bh.Bits, bh.Nonce)
124 121
 }

+ 0
- 34
wire/error.go View File

@@ -1,34 +0,0 @@
1
-// Copyright (c) 2013-2015 The btcsuite developers
2
-// Use of this source code is governed by an ISC
3
-// license that can be found in the LICENSE file.
4
-
5
-package wire
6
-
7
-import (
8
-	"fmt"
9
-)
10
-
11
-// MessageError describes an issue with a message.
12
-// An example of some potential issues are messages from the wrong bitcoin
13
-// network, invalid commands, mismatched checksums, and exceeding max payloads.
14
-//
15
-// This provides a mechanism for the caller to type assert the error to
16
-// differentiate between general io errors such as io.EOF and issues that
17
-// resulted from malformed messages.
18
-type MessageError struct {
19
-	Func        string // Function name
20
-	Description string // Human readable description of the issue
21
-}
22
-
23
-// Error satisfies the error interface and prints human-readable errors.
24
-func (e *MessageError) Error() string {
25
-	if e.Func != "" {
26
-		return fmt.Sprintf("%v: %v", e.Func, e.Description)
27
-	}
28
-	return e.Description
29
-}
30
-
31
-// messageError creates an error for the given function and description.
32
-func messageError(f string, desc string) *MessageError {
33
-	return &MessageError{Func: f, Description: desc}
34
-}

wire/fixedIO_test.go → wire/fixed/fixedIO_test.go View File

@@ -2,16 +2,16 @@
2 2
 // Use of this source code is governed by an ISC
3 3
 // license that can be found in the LICENSE file.
4 4
 
5
-package wire
5
+package fixed
6 6
 
7 7
 import (
8 8
 	"bytes"
9 9
 	"io"
10 10
 )
11 11
 
12
-// fixedWriter implements the io.Writer interface and intentially allows
12
+// Writer implements the io.Writer interface and intentially allows
13 13
 // testing of error paths by forcing short writes.
14
-type fixedWriter struct {
14
+type Writer struct {
15 15
 	b   []byte
16 16
 	pos int
17 17
 }
@@ -21,7 +21,7 @@ type fixedWriter struct {
21 21
 // io.ErrShortWrite is returned and the writer is left unchanged.
22 22
 //
23 23
 // This satisfies the io.Writer interface.
24
-func (w *fixedWriter) Write(p []byte) (n int, err error) {
24
+func (w *Writer) Write(p []byte) (n int, err error) {
25 25
 	lenp := len(p)
26 26
 	if w.pos+lenp > cap(w.b) {
27 27
 		return 0, io.ErrShortWrite
@@ -32,21 +32,21 @@ func (w *fixedWriter) Write(p []byte) (n int, err error) {
32 32
 }
33 33
 
34 34
 // Bytes returns the bytes already written to the fixed writer.
35
-func (w *fixedWriter) Bytes() []byte {
35
+func (w *Writer) Bytes() []byte {
36 36
 	return w.b
37 37
 }
38 38
 
39
-// newFixedWriter returns a new io.Writer that will error once more bytes than
39
+// NewWriter returns a new io.Writer that will error once more bytes than
40 40
 // the specified max have been written.
41
-func newFixedWriter(max int) io.Writer {
41
+func NewWriter(max int) io.Writer {
42 42
 	b := make([]byte, max)
43
-	fw := fixedWriter{b, 0}
43
+	fw := Writer{b, 0}
44 44
 	return &fw
45 45
 }
46 46
 
47
-// fixedReader implements the io.Reader interface and intentially allows
47
+// Reader implements the io.Reader interface and intentially allows
48 48
 // testing of error paths by forcing short reads.
49
-type fixedReader struct {
49
+type Reader struct {
50 50
 	buf   []byte
51 51
 	pos   int
52 52
 	iobuf *bytes.Buffer
@@ -57,21 +57,21 @@ type fixedReader struct {
57 57
 // the fixed writer, an error is returned.
58 58
 //
59 59
 // This satisfies the io.Reader interface.
60
-func (fr *fixedReader) Read(p []byte) (n int, err error) {
60
+func (fr *Reader) Read(p []byte) (n int, err error) {
61 61
 	n, err = fr.iobuf.Read(p)
62 62
 	fr.pos += n
63 63
 	return
64 64
 }
65 65
 
66
-// newFixedReader returns a new io.Reader that will error once more bytes than
66
+// NewReader returns a new io.Reader that will error once more bytes than
67 67
 // the specified max have been read.
68
-func newFixedReader(max int, buf []byte) io.Reader {
68
+func NewReader(max int, buf []byte) io.Reader {
69 69
 	b := make([]byte, max)
70 70
 	if buf != nil {
71 71
 		copy(b[:], buf)
72 72
 	}
73 73
 
74 74
 	iobuf := bytes.NewBuffer(b)
75
-	fr := fixedReader{b, 0, iobuf}
75
+	fr := Reader{b, 0, iobuf}
76 76
 	return &fr
77 77
 }

+ 3
- 2
wire/invvect.go View File

@@ -4,15 +4,16 @@ import (
4 4
 	"io"
5 5
 
6 6
 	"git.parallelcoin.io/dev/btcd/wire/inv"
7
+	"git.parallelcoin.io/dev/btcd/wire/rw"
7 8
 )
8 9
 
9 10
 // readInvVect reads an encoded InvVect from r depending on the protocol
10 11
 // version.
11 12
 func readInvVect(r io.Reader, pver uint32, iv *inv.Vect) error {
12
-	return ReadElements(r, &iv.Type, &iv.Hash)
13
+	return rw.ReadElements(r, &iv.Type, &iv.Hash)
13 14
 }
14 15
 
15 16
 // writeInvVect serializes an InvVect to w depending on the protocol version.
16 17
 func writeInvVect(w io.Writer, pver uint32, iv *inv.Vect) error {
17
-	return WriteElements(w, iv.Type, &iv.Hash)
18
+	return rw.WriteElements(w, iv.Type, &iv.Hash)
18 19
 }

+ 53
- 96
wire/message.go View File

@@ -6,56 +6,13 @@ import (
6 6
 	"io"
7 7
 	"unicode/utf8"
8 8
 
9
+	"git.parallelcoin.io/dev/btcd/wire/message"
10
+	"git.parallelcoin.io/dev/btcd/wire/rw"
11
+
9 12
 	"git.parallelcoin.io/dev/btcd/chaincfg/chainhash"
10 13
 	"git.parallelcoin.io/dev/btcd/wire/service"
11 14
 )
12 15
 
13
-// MessageHeaderSize is the number of bytes in a bitcoin message header.
14
-// Bitcoin network (magic) 4 bytes + command 12 bytes + payload length 4 bytes +
15
-// checksum 4 bytes.
16
-const MessageHeaderSize = 24
17
-
18
-// CommandSize is the fixed size of all commands in the common bitcoin message
19
-// header.  Shorter commands must be zero padded.
20
-const CommandSize = 12
21
-
22
-// MaxMessagePayload is the maximum bytes a message can be regardless of other
23
-// individual limits imposed by messages themselves.
24
-const MaxMessagePayload = (1024 * 1024 * 32) // 32MB
25
-
26
-// Commands used in bitcoin message headers which describe the type of message.
27
-const (
28
-	CmdVersion      = "version"
29
-	CmdVerAck       = "verack"
30
-	CmdGetAddr      = "getaddr"
31
-	CmdAddr         = "addr"
32
-	CmdGetBlocks    = "getblocks"
33
-	CmdInv          = "inv"
34
-	CmdGetData      = "getdata"
35
-	CmdNotFound     = "notfound"
36
-	CmdBlock        = "block"
37
-	CmdTx           = "tx"
38
-	CmdGetHeaders   = "getheaders"
39
-	CmdHeaders      = "headers"
40
-	CmdPing         = "ping"
41
-	CmdPong         = "pong"
42
-	CmdAlert        = "alert"
43
-	CmdMemPool      = "mempool"
44
-	CmdFilterAdd    = "filteradd"
45
-	CmdFilterClear  = "filterclear"
46
-	CmdFilterLoad   = "filterload"
47
-	CmdMerkleBlock  = "merkleblock"
48
-	CmdReject       = "reject"
49
-	CmdSendHeaders  = "sendheaders"
50
-	CmdFeeFilter    = "feefilter"
51
-	CmdGetCFilters  = "getcfilters"
52
-	CmdGetCFHeaders = "getcfheaders"
53
-	CmdGetCFCheckpt = "getcfcheckpt"
54
-	CmdCFilter      = "cfilter"
55
-	CmdCFHeaders    = "cfheaders"
56
-	CmdCFCheckpt    = "cfcheckpt"
57
-)
58
-
59 16
 // MessageEncoding represents the wire message encoding format to be used.
60 17
 type MessageEncoding uint32
61 18
 
@@ -90,91 +47,91 @@ type Message interface {
90 47
 func makeEmptyMessage(command string) (Message, error) {
91 48
 	var msg Message
92 49
 	switch command {
93
-	case CmdVersion:
50
+	case message.CmdVersion:
94 51
 		msg = &MsgVersion{}
95 52
 
96
-	case CmdVerAck:
53
+	case message.CmdVerAck:
97 54
 		msg = &MsgVerAck{}
98 55
 
99
-	case CmdGetAddr:
56
+	case message.CmdGetAddr:
100 57
 		msg = &MsgGetAddr{}
101 58
 
102
-	case CmdAddr:
59
+	case message.CmdAddr:
103 60
 		msg = &MsgAddr{}
104 61
 
105
-	case CmdGetBlocks:
62
+	case message.CmdGetBlocks:
106 63
 		msg = &MsgGetBlocks{}
107 64
 
108
-	case CmdBlock:
65
+	case message.CmdBlock:
109 66
 		msg = &MsgBlock{}
110 67
 
111
-	case CmdInv:
68
+	case message.CmdInv:
112 69
 		msg = &MsgInv{}
113 70
 
114
-	case CmdGetData:
71
+	case message.CmdGetData:
115 72
 		msg = &MsgGetData{}
116 73
 
117
-	case CmdNotFound:
74
+	case message.CmdNotFound:
118 75
 		msg = &MsgNotFound{}
119 76
 
120
-	case CmdTx:
77
+	case message.CmdTx:
121 78
 		msg = &MsgTx{}
122 79
 
123
-	case CmdPing:
80
+	case message.CmdPing:
124 81
 		msg = &MsgPing{}
125 82
 
126
-	case CmdPong:
83
+	case message.CmdPong:
127 84
 		msg = &MsgPong{}
128 85
 
129
-	case CmdGetHeaders:
86
+	case message.CmdGetHeaders:
130 87
 		msg = &MsgGetHeaders{}
131 88
 
132
-	case CmdHeaders:
89
+	case message.CmdHeaders:
133 90
 		msg = &MsgHeaders{}
134 91
 
135
-	case CmdAlert:
92
+	case message.CmdAlert:
136 93
 		msg = &MsgAlert{}
137 94
 
138
-	case CmdMemPool:
95
+	case message.CmdMemPool:
139 96
 		msg = &MsgMemPool{}
140 97
 
141
-	case CmdFilterAdd:
98
+	case message.CmdFilterAdd:
142 99
 		msg = &MsgFilterAdd{}
143 100
 
144
-	case CmdFilterClear:
101
+	case message.CmdFilterClear:
145 102
 		msg = &MsgFilterClear{}
146 103
 
147
-	case CmdFilterLoad:
104
+	case message.CmdFilterLoad:
148 105
 		msg = &MsgFilterLoad{}
149 106
 
150
-	case CmdMerkleBlock:
107
+	case message.CmdMerkleBlock:
151 108
 		msg = &MsgMerkleBlock{}
152 109
 
153
-	case CmdReject:
110
+	case message.CmdReject:
154 111
 		msg = &MsgReject{}
155 112
 
156
-	case CmdSendHeaders:
113
+	case message.CmdSendHeaders:
157 114
 		msg = &MsgSendHeaders{}
158 115
 
159
-	case CmdFeeFilter:
116
+	case message.CmdFeeFilter:
160 117
 		msg = &MsgFeeFilter{}
161 118
 
162
-	case CmdGetCFilters:
119
+	case message.CmdGetCFilters:
163 120
 		msg = &MsgGetCFilters{}
164 121
 
165
-	case CmdGetCFHeaders:
122
+	case message.CmdGetCFHeaders:
166 123
 		msg = &MsgGetCFHeaders{}
167 124
 
168
-	case CmdGetCFCheckpt:
125
+	case message.CmdGetCFCheckpt:
169 126
 		msg = &MsgGetCFCheckpt{}
170 127
 
171
-	case CmdCFilter:
128
+	case message.CmdCFilter:
172 129
 		msg = &MsgCFilter{}
173 130
 
174
-	case CmdCFHeaders:
131
+	case message.CmdCFHeaders:
175 132
 		msg = &MsgCFHeaders{}
176 133
 
177
-	case CmdCFCheckpt:
134
+	case message.CmdCFCheckpt:
178 135
 		msg = &MsgCFCheckpt{}
179 136
 
180 137
 	default:
@@ -197,7 +154,7 @@ func readMessageHeader(r io.Reader) (int, *messageHeader, error) {
197 154
 	// to read the entire header into a buffer first in case there is a
198 155
 	// short read so the proper amount of read bytes are known.  This works
199 156
 	// since the header is a fixed size.
200
-	var headerBytes [MessageHeaderSize]byte
157
+	var headerBytes [message.HeaderSize]byte
201 158
 	n, err := io.ReadFull(r, headerBytes[:])
202 159
 	if err != nil {
203 160
 		return n, nil, err
@@ -206,8 +163,8 @@ func readMessageHeader(r io.Reader) (int, *messageHeader, error) {
206 163
 
207 164
 	// Create and populate a messageHeader struct from the raw header bytes.
208 165
 	hdr := messageHeader{}
209
-	var command [CommandSize]byte
210
-	ReadElements(hr, &hdr.magic, &command, &hdr.length, &hdr.checksum)
166
+	var command [rw.CommandSize]byte
167
+	rw.ReadElements(hr, &hdr.magic, &command, &hdr.length, &hdr.checksum)
211 168
 
212 169
 	// Strip trailing zeros from command string.
213 170
 	hdr.command = string(bytes.TrimRight(command[:], string(0)))
@@ -263,12 +220,12 @@ func WriteMessageWithEncodingN(w io.Writer, msg Message, pver uint32,
263 220
 	totalBytes := 0
264 221
 
265 222
 	// Enforce max command size.
266
-	var command [CommandSize]byte
223
+	var command [rw.CommandSize]byte
267 224
 	cmd := msg.Command()
268
-	if len(cmd) > CommandSize {
225
+	if len(cmd) > rw.CommandSize {
269 226
 		str := fmt.Sprintf("command [%s] is too long [max %v]",
270
-			cmd, CommandSize)
271
-		return totalBytes, messageError("WriteMessage", str)
227
+			cmd, rw.CommandSize)
228
+		return totalBytes, message.NewError("WriteMessage", str)
272 229
 	}
273 230
 	copy(command[:], []byte(cmd))
274 231
 
@@ -282,11 +239,11 @@ func WriteMessageWithEncodingN(w io.Writer, msg Message, pver uint32,
282 239
 	lenp := len(payload)
283 240
 
284 241
 	// Enforce maximum overall message payload.
285
-	if lenp > MaxMessagePayload {
242
+	if lenp > message.MaxPayload {
286 243
 		str := fmt.Sprintf("message payload is too large - encoded "+
287 244
 			"%d bytes, but maximum message payload is %d bytes",
288
-			lenp, MaxMessagePayload)
289
-		return totalBytes, messageError("WriteMessage", str)
245
+			lenp, message.MaxPayload)
246
+		return totalBytes, message.NewError("WriteMessage", str)
290 247
 	}
291 248
 
292 249
 	// Enforce maximum message payload based on the message type.
@@ -295,7 +252,7 @@ func WriteMessageWithEncodingN(w io.Writer, msg Message, pver uint32,
295 252
 		str := fmt.Sprintf("message payload is too large - encoded "+
296 253
 			"%d bytes, but maximum message payload size for "+
297 254
 			"messages of type [%s] is %d.", lenp, cmd, mpl)
298
-		return totalBytes, messageError("WriteMessage", str)
255
+		return totalBytes, message.NewError("WriteMessage", str)
299 256
 	}
300 257
 
301 258
 	// Create header for the message.
@@ -308,8 +265,8 @@ func WriteMessageWithEncodingN(w io.Writer, msg Message, pver uint32,
308 265
 	// Encode the header for the message.  This is done to a buffer
309 266
 	// rather than directly to the writer since writeElements doesn't
310 267
 	// return the number of bytes written.
311
-	hw := bytes.NewBuffer(make([]byte, 0, MessageHeaderSize))
312
-	WriteElements(hw, hdr.magic, command, hdr.length, hdr.checksum)
268
+	hw := bytes.NewBuffer(make([]byte, 0, message.HeaderSize))
269
+	rw.WriteElements(hw, hdr.magic, command, hdr.length, hdr.checksum)
313 270
 
314 271
 	// Write header.
315 272
 	n, err := w.Write(hw.Bytes())
@@ -341,11 +298,11 @@ func ReadMessageWithEncodingN(r io.Reader, pver uint32, btcnet service.Net,
341 298
 	}
342 299
 
343 300
 	// Enforce maximum message payload.
344
-	if hdr.length > MaxMessagePayload {
301
+	if hdr.length > message.MaxPayload {
345 302
 		str := fmt.Sprintf("message payload is too large - header "+
346 303
 			"indicates %d bytes, but max message payload is %d "+
347
-			"bytes.", hdr.length, MaxMessagePayload)
348
-		return totalBytes, nil, nil, messageError("ReadMessage", str)
304
+			"bytes.", hdr.length, message.MaxPayload)
305
+		return totalBytes, nil, nil, message.NewError("ReadMessage", str)
349 306
 
350 307
 	}
351 308
 
@@ -353,7 +310,7 @@ func ReadMessageWithEncodingN(r io.Reader, pver uint32, btcnet service.Net,
353 310
 	if hdr.magic != btcnet {
354 311
 		discardInput(r, hdr.length)
355 312
 		str := fmt.Sprintf("message from other network [%v]", hdr.magic)
356
-		return totalBytes, nil, nil, messageError("ReadMessage", str)
313
+		return totalBytes, nil, nil, message.NewError("ReadMessage", str)
357 314
 	}
358 315
 
359 316
 	// Check for malformed commands.
@@ -361,14 +318,14 @@ func ReadMessageWithEncodingN(r io.Reader, pver uint32, btcnet service.Net,
361 318
 	if !utf8.ValidString(command) {
362 319
 		discardInput(r, hdr.length)
363 320
 		str := fmt.Sprintf("invalid command %v", []byte(command))
364
-		return totalBytes, nil, nil, messageError("ReadMessage", str)
321
+		return totalBytes, nil, nil, message.NewError("ReadMessage", str)
365 322
 	}
366 323
 
367 324
 	// Create struct of appropriate message type based on the command.
368 325
 	msg, err := makeEmptyMessage(command)
369 326
 	if err != nil {
370 327
 		discardInput(r, hdr.length)
371
-		return totalBytes, nil, nil, messageError("ReadMessage",
328
+		return totalBytes, nil, nil, message.NewError("ReadMessage",
372 329
 			err.Error())
373 330
 	}
374 331
 
@@ -381,7 +338,7 @@ func ReadMessageWithEncodingN(r io.Reader, pver uint32, btcnet service.Net,
381 338
 		str := fmt.Sprintf("payload exceeds max length - header "+
382 339
 			"indicates %v bytes, but max payload size for "+
383 340
 			"messages of type [%v] is %v.", hdr.length, command, mpl)
384
-		return totalBytes, nil, nil, messageError("ReadMessage", str)
341
+		return totalBytes, nil, nil, message.NewError("ReadMessage", str)
385 342
 	}
386 343
 
387 344
 	// Read payload.
@@ -398,7 +355,7 @@ func ReadMessageWithEncodingN(r io.Reader, pver uint32, btcnet service.Net,
398 355
 		str := fmt.Sprintf("payload checksum failed - header "+
399 356
 			"indicates %v, but actual checksum is %v.",
400 357
 			hdr.checksum, checksum)
401
-		return totalBytes, nil, nil, messageError("ReadMessage", str)
358
+		return totalBytes, nil, nil, message.NewError("ReadMessage", str)
402 359
 	}
403 360
 
404 361
 	// Unmarshal message.  NOTE: This must be a *bytes.Buffer since the

+ 76
- 0
wire/message/error.go View File

@@ -0,0 +1,76 @@
1
+// Copyright (c) 2013-2015 The btcsuite developers
2
+// Use of this source code is governed by an ISC
3
+// license that can be found in the LICENSE file.
4
+
5
+package message
6
+
7
+import (
8
+	"fmt"
9
+)
10
+
11
+// Error describes an issue with a message.
12
+// An example of some potential issues are messages from the wrong bitcoin
13
+// network, invalid commands, mismatched checksums, and exceeding max payloads.
14
+//
15
+// This provides a mechanism for the caller to type assert the error to
16
+// differentiate between general io errors such as io.EOF and issues that
17
+// resulted from malformed messages.
18
+type Error struct {
19
+	Func        string // Function name
20
+	Description string // Human readable description of the issue
21
+}
22
+
23
+// Error satisfies the error interface and prints human-readable errors.
24
+func (e *Error) Error() string {
25
+	if e.Func != "" {
26
+		return fmt.Sprintf("%v: %v", e.Func, e.Description)
27
+	}
28
+	return e.Description
29
+}
30
+
31
+// NewError creates an error for the given function and description.
32
+func NewError(f string, desc string) *Error {
33
+	return &Error{Func: f, Description: desc}
34
+}
35
+
36
+// HeaderSize is the number of bytes in a bitcoin message header.
37
+// Bitcoin network (magic) 4 bytes + command 12 bytes + payload length 4 bytes +
38
+// checksum 4 bytes.
39
+const HeaderSize = 24
40
+
41
+// MaxPayload is the maximum bytes a message can be regardless of other
42
+// individual limits imposed by messages themselves.
43
+const MaxPayload = (1024 * 1024 * 32) // 32MB
44
+
45
+// Commands used in bitcoin message headers which describe the type of message.
46
+const (
47
+	CmdVersion      = "version"
48
+	CmdVerAck       = "verack"
49
+	CmdGetAddr      = "getaddr"
50
+	CmdAddr         = "addr"
51
+	CmdGetBlocks    = "getblocks"
52
+	CmdInv          = "inv"
53
+	CmdGetData      = "getdata"
54
+	CmdNotFound     = "notfound"
55
+	CmdBlock        = "block"
56
+	CmdTx           = "tx"
57
+	CmdGetHeaders   = "getheaders"
58
+	CmdHeaders      = "headers"
59
+	CmdPing         = "ping"
60
+	CmdPong         = "pong"
61
+	CmdAlert        = "alert"
62
+	CmdMemPool      = "mempool"
63
+	CmdFilterAdd    = "filteradd"
64
+	CmdFilterClear  = "filterclear"
65
+	CmdFilterLoad   = "filterload"
66
+	CmdMerkleBlock  = "merkleblock"
67
+	CmdReject       = "reject"
68
+	CmdSendHeaders  = "sendheaders"
69
+	CmdFeeFilter    = "feefilter"
70
+	CmdGetCFilters  = "getcfilters"
71
+	CmdGetCFHeaders = "getcfheaders"
72
+	CmdGetCFCheckpt = "getcfcheckpt"
73
+	CmdCFilter      = "cfilter"
74
+	CmdCFHeaders    = "cfheaders"
75
+	CmdCFCheckpt    = "cfcheckpt"
76
+)

+ 25
- 21
wire/msgaddr.go View File

@@ -8,6 +8,10 @@ import (
8 8
 	"fmt"
9 9
 	"io"
10 10
 
11
+	"git.parallelcoin.io/dev/btcd/wire/na"
12
+	"git.parallelcoin.io/dev/btcd/wire/rw"
13
+
14
+	"git.parallelcoin.io/dev/btcd/wire/message"
11 15
 	"git.parallelcoin.io/dev/btcd/wire/version"
12 16
 )
13 17
 
@@ -26,15 +30,15 @@ const MaxAddrPerMsg = 1000
26 30
 // Use the AddAddress function to build up the list of known addresses when
27 31
 // sending an addr message to another peer.
28 32
 type MsgAddr struct {
29
-	AddrList []*NetAddress
33
+	AddrList []*na.NetAddress
30 34
 }
31 35
 
32 36
 // AddAddress adds a known active peer to the message.
33
-func (msg *MsgAddr) AddAddress(na *NetAddress) error {
37
+func (msg *MsgAddr) AddAddress(na *na.NetAddress) error {
34 38
 	if len(msg.AddrList)+1 > MaxAddrPerMsg {
35 39
 		str := fmt.Sprintf("too many addresses in message [max %v]",
36 40
 			MaxAddrPerMsg)
37
-		return messageError("MsgAddr.AddAddress", str)
41
+		return message.NewError("MsgAddr.AddAddress", str)
38 42
 	}
39 43
 
40 44
 	msg.AddrList = append(msg.AddrList, na)
@@ -42,7 +46,7 @@ func (msg *MsgAddr) AddAddress(na *NetAddress) error {
42 46
 }
43 47
 
44 48
 // AddAddresses adds multiple known active peers to the message.
45
-func (msg *MsgAddr) AddAddresses(netAddrs ...*NetAddress) error {
49
+func (msg *MsgAddr) AddAddresses(netAddrs ...*na.NetAddress) error {
46 50
 	for _, na := range netAddrs {
47 51
 		err := msg.AddAddress(na)
48 52
 		if err != nil {
@@ -54,13 +58,13 @@ func (msg *MsgAddr) AddAddresses(netAddrs ...*NetAddress) error {
54 58
 
55 59
 // ClearAddresses removes all addresses from the message.
56 60
 func (msg *MsgAddr) ClearAddresses() {
57
-	msg.AddrList = []*NetAddress{}
61
+	msg.AddrList = []*na.NetAddress{}
58 62
 }
59 63
 
60 64
 // BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
61 65
 // This is part of the Message interface implementation.
62 66
 func (msg *MsgAddr) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error {
63
-	count, err := ReadVarInt(r, pver)
67
+	count, err := rw.ReadVarInt(r, pver)
64 68
 	if err != nil {
65 69
 		return err
66 70
 	}
@@ -69,18 +73,18 @@ func (msg *MsgAddr) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) err
69 73
 	if count > MaxAddrPerMsg {
70 74
 		str := fmt.Sprintf("too many addresses for message "+
71 75
 			"[count %v, max %v]", count, MaxAddrPerMsg)
72
-		return messageError("MsgAddr.BtcDecode", str)
76
+		return message.NewError("MsgAddr.BtcDecode", str)
73 77
 	}
74 78
 
75
-	addrList := make([]NetAddress, count)
76
-	msg.AddrList = make([]*NetAddress, 0, count)
79
+	addrList := make([]na.NetAddress, count)
80
+	msg.AddrList = make([]*na.NetAddress, 0, count)
77 81
 	for i := uint64(0); i < count; i++ {
78
-		na := &addrList[i]
79
-		err := ReadNetAddress(r, pver, na, true)
82
+		nn := &addrList[i]
83
+		err := na.ReadNetAddress(r, pver, nn, true)
80 84
 		if err != nil {
81 85
 			return err
82 86
 		}
83
-		msg.AddAddress(na)
87
+		msg.AddAddress(nn)
84 88
 	}
85 89
 	return nil
86 90
 }
@@ -94,22 +98,22 @@ func (msg *MsgAddr) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) err
94 98
 	if pver < version.MultipleAddress && count > 1 {
95 99
 		str := fmt.Sprintf("too many addresses for message of "+
96 100
 			"protocol version %v [count %v, max 1]", pver, count)
97
-		return messageError("MsgAddr.BtcEncode", str)
101
+		return message.NewError("MsgAddr.BtcEncode", str)
98 102
 
99 103
 	}
100 104
 	if count > MaxAddrPerMsg {
101 105
 		str := fmt.Sprintf("too many addresses for message "+
102 106
 			"[count %v, max %v]", count, MaxAddrPerMsg)
103
-		return messageError("MsgAddr.BtcEncode", str)
107
+		return message.NewError("MsgAddr.BtcEncode", str)
104 108
 	}
105 109
 
106
-	err := WriteVarInt(w, pver, uint64(count))
110
+	err := rw.WriteVarInt(w, pver, uint64(count))
107 111
 	if err != nil {
108 112
 		return err
109 113
 	}
110 114
 
111
-	for _, na := range msg.AddrList {
112
-		err = WriteNetAddress(w, pver, na, true)
115
+	for _, nn := range msg.AddrList {
116
+		err = na.WriteNetAddress(w, pver, nn, true)
113 117
 		if err != nil {
114 118
 			return err
115 119
 		}
@@ -121,7 +125,7 @@ func (msg *MsgAddr) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) err
121 125
 // Command returns the protocol command string for the message.  This is part
122 126
 // of the Message interface implementation.