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
This commit is contained in:
zelig 2014-12-14 18:26:13 +00:00
parent 50e1dcc43a
commit ae7c1e3e55

@ -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) {