Merge pull request #2 from fiksn/master
Make the code work with latest btcsuite repo changes
This commit is contained in:
commit
601a21dec7
12
client.go
12
client.go
|
@ -1,19 +1,19 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/btcsuite/btcwire"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
btcnet btcwire.BitcoinNet // Bitcoin Network
|
||||
pver uint32 // Protocl Version
|
||||
userAgent string // User Agent
|
||||
btcnet wire.BitcoinNet // Bitcoin Network
|
||||
pver uint32 // Protocl Version
|
||||
userAgent string // User Agent
|
||||
}
|
||||
|
||||
func NewClient(userAgent string) *Client {
|
||||
return &Client{
|
||||
btcnet: btcwire.MainNet,
|
||||
pver: btcwire.ProtocolVersion,
|
||||
btcnet: wire.MainNet,
|
||||
pver: wire.ProtocolVersion,
|
||||
userAgent: userAgent,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcwire"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
)
|
||||
|
||||
// TODO: Break Client/Peer/Crawler into separate modules.
|
||||
|
@ -24,7 +24,7 @@ type Crawler struct {
|
|||
|
||||
type Result struct {
|
||||
Node *Peer
|
||||
Peers []*btcwire.NetAddress
|
||||
Peers []*wire.NetAddress
|
||||
}
|
||||
|
||||
func NewCrawler(client *Client, seeds []string) *Crawler {
|
||||
|
@ -80,7 +80,7 @@ func (c *Crawler) handleAddress(address string) *Result {
|
|||
}
|
||||
|
||||
// Send getaddr.
|
||||
err = peer.WriteMessage(btcwire.NewMsgGetAddr())
|
||||
err = peer.WriteMessage(wire.NewMsgGetAddr())
|
||||
if err != nil {
|
||||
logger.Warningf("[%s] GetAddr failed: %v", address, err)
|
||||
return &r
|
||||
|
@ -110,7 +110,7 @@ func (c *Crawler) handleAddress(address string) *Result {
|
|||
}
|
||||
|
||||
switch tmsg := msg.(type) {
|
||||
case *btcwire.MsgAddr:
|
||||
case *wire.MsgAddr:
|
||||
r.Peers = append(r.Peers, tmsg.AddrList...)
|
||||
|
||||
if firstReceived == -1 {
|
||||
|
|
|
@ -5,7 +5,7 @@ package main
|
|||
|
||||
import (
|
||||
"encoding/base32"
|
||||
"github.com/btcsuite/btcwire"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -14,7 +14,7 @@ import (
|
|||
var onioncatrange = net.IPNet{IP: net.ParseIP("FD87:d87e:eb43::"),
|
||||
Mask: net.CIDRMask(48, 128)}
|
||||
|
||||
func Tor(na *btcwire.NetAddress) bool {
|
||||
func Tor(na *wire.NetAddress) bool {
|
||||
// bitcoind encodes a .onion address as a 16 byte number by decoding the
|
||||
// address prior to the .onion (i.e. the key hash) base32 into a ten
|
||||
// byte number. it then stores the first 6 bytes of the address as
|
||||
|
@ -29,7 +29,7 @@ func Tor(na *btcwire.NetAddress) bool {
|
|||
// ipString returns a string for the ip from the provided NetAddress. If the
|
||||
// ip is in the range used for tor addresses then it will be transformed into
|
||||
// the relavent .onion address.
|
||||
func ipString(na *btcwire.NetAddress) string {
|
||||
func ipString(na *wire.NetAddress) string {
|
||||
if Tor(na) {
|
||||
// We know now that na.IP is long enogh.
|
||||
base32 := base32.StdEncoding.EncodeToString(na.IP[6:])
|
||||
|
@ -41,7 +41,7 @@ func ipString(na *btcwire.NetAddress) string {
|
|||
|
||||
// NetAddressKey returns a string key in the form of ip:port for IPv4 addresses
|
||||
// or [ip]:port for IPv6 addresses.
|
||||
func NetAddressKey(na *btcwire.NetAddress) string {
|
||||
func NetAddressKey(na *wire.NetAddress) string {
|
||||
port := strconv.FormatUint(uint64(na.Port), 10)
|
||||
addr := net.JoinHostPort(ipString(na), port)
|
||||
return addr
|
||||
|
|
18
peer.go
18
peer.go
|
@ -5,7 +5,7 @@ import (
|
|||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcwire"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
)
|
||||
|
||||
type Peer struct {
|
||||
|
@ -54,13 +54,13 @@ func (p *Peer) Handshake() error {
|
|||
|
||||
logger.Debugf("[%s] Starting handshake.", p.Address)
|
||||
|
||||
nonce, err := btcwire.RandomUint64()
|
||||
nonce, err := wire.RandomUint64()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.nonce = nonce
|
||||
|
||||
msgVersion, err := btcwire.NewMsgVersionFromConn(p.conn, p.nonce, 0)
|
||||
msgVersion, err := wire.NewMsgVersionFromConn(p.conn, p.nonce, 0)
|
||||
msgVersion.UserAgent = p.client.userAgent
|
||||
msgVersion.DisableRelayTx = true
|
||||
if err := p.WriteMessage(msgVersion); err != nil {
|
||||
|
@ -72,7 +72,7 @@ func (p *Peer) Handshake() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
vmsg, ok := msg.(*btcwire.MsgVersion)
|
||||
vmsg, ok := msg.(*wire.MsgVersion)
|
||||
if !ok {
|
||||
return fmt.Errorf("Did not receive version message: %T", vmsg)
|
||||
}
|
||||
|
@ -90,17 +90,17 @@ func (p *Peer) Handshake() error {
|
|||
// accept external connections so we skip it.
|
||||
|
||||
// Send verack.
|
||||
if err := p.WriteMessage(btcwire.NewMsgVerAck()); err != nil {
|
||||
if err := p.WriteMessage(wire.NewMsgVerAck()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Peer) WriteMessage(msg btcwire.Message) error {
|
||||
return btcwire.WriteMessage(p.conn, msg, p.pver, p.client.btcnet)
|
||||
func (p *Peer) WriteMessage(msg wire.Message) error {
|
||||
return wire.WriteMessage(p.conn, msg, p.pver, p.client.btcnet)
|
||||
}
|
||||
|
||||
func (p *Peer) ReadMessage() (btcwire.Message, []byte, error) {
|
||||
return btcwire.ReadMessage(p.conn, p.pver, p.client.btcnet)
|
||||
func (p *Peer) ReadMessage() (wire.Message, []byte, error) {
|
||||
return wire.ReadMessage(p.conn, p.pver, p.client.btcnet)
|
||||
}
|
||||
|
|
4
seed.go
4
seed.go
|
@ -4,7 +4,7 @@ import (
|
|||
"net"
|
||||
"sync"
|
||||
|
||||
"github.com/btcsuite/btcnet"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
)
|
||||
|
||||
func GetSeedsFromDNS(dnsSeeds []string) []string {
|
||||
|
@ -33,7 +33,7 @@ func GetSeedsFromDNS(dnsSeeds []string) []string {
|
|||
seeds := []string{}
|
||||
for ips := range results {
|
||||
for _, ip := range ips {
|
||||
seeds = append(seeds, net.JoinHostPort(ip.String(), btcnet.MainNetParams.DefaultPort))
|
||||
seeds = append(seeds, net.JoinHostPort(ip.String(), chaincfg.MainNetParams.DefaultPort))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue