From ae7c1e3e55610cc28bb4f79ede5660dd89c019c5 Mon Sep 17 00:00:00 2001 From: zelig Date: Sun, 14 Dec 2014 18:26:13 +0000 Subject: adapt to new backend - eth p2p pkgs - new Ethereum initialiser - no caps param - use nat type - add NatType func to map nat type string to p2p.NAT - add pubkey to client identity --- cmd/utils/cmd.go | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'cmd') diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index db7bcd35e..24d5970bd 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -4,23 +4,23 @@ import ( "fmt" "io" "log" + "net" "os" "os/signal" "path" "path/filepath" "regexp" "runtime" - "time" "bitbucket.org/kardianos/osext" - "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/miner" + "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/rpc" - "github.com/ethereum/go-ethereum/wire" "github.com/ethereum/go-ethereum/xeth" ) @@ -144,17 +144,32 @@ func NewDatabase() ethutil.Database { return db } -func NewClientIdentity(clientIdentifier, version, customIdentifier string) *wire.SimpleClientIdentity { - return wire.NewSimpleClientIdentity(clientIdentifier, version, customIdentifier) +func NewClientIdentity(clientIdentifier, version, customIdentifier string, pubkey string) *p2p.SimpleClientIdentity { + return p2p.NewSimpleClientIdentity(clientIdentifier, version, customIdentifier, pubkey) } -func NewEthereum(db ethutil.Database, clientIdentity wire.ClientIdentity, keyManager *crypto.KeyManager, usePnp bool, OutboundPort string, MaxPeer int) *eth.Ethereum { - ethereum, err := eth.New(db, clientIdentity, keyManager, eth.CapDefault, usePnp) +func NatType(natType string, gateway string) (nat p2p.NAT) { + switch natType { + case "UPNP": + nat = p2p.UPNP() + case "PMP": + ip := net.ParseIP(gateway) + if ip != nil { + clilogger.Fatalf("bad PMP gateway '%s'", gateway) + } + nat = p2p.PMP(ip) + case "": + default: + clilogger.Fatalf("unrecognised NAT type '%s'", natType) + } + return +} + +func NewEthereum(db ethutil.Database, clientIdentity p2p.ClientIdentity, keyManager *crypto.KeyManager, nat p2p.NAT, OutboundPort string, MaxPeer int) *eth.Ethereum { + ethereum, err := eth.New(db, clientIdentity, keyManager, nat, OutboundPort, MaxPeer) if err != nil { clilogger.Fatalln("eth start err:", err) } - ethereum.Port = OutboundPort - ethereum.MaxPeers = MaxPeer return ethereum } @@ -268,11 +283,6 @@ func StartMining(ethereum *eth.Ethereum) bool { if gminer == nil { gminer = miner.New(addr, ethereum) } - // Give it some time to connect with peers - time.Sleep(3 * time.Second) - for !ethereum.IsUpToDate() { - time.Sleep(5 * time.Second) - } gminer.Start() }() RegisterInterrupt(func(os.Signal) { -- cgit v1.2.3