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
1 changed files with 24 additions and 14 deletions

View File

@ -4,23 +4,23 @@ import (
"fmt" "fmt"
"io" "io"
"log" "log"
"net"
"os" "os"
"os/signal" "os/signal"
"path" "path"
"path/filepath" "path/filepath"
"regexp" "regexp"
"runtime" "runtime"
"time"
"bitbucket.org/kardianos/osext" "bitbucket.org/kardianos/osext"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/miner" "github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/wire"
"github.com/ethereum/go-ethereum/xeth" "github.com/ethereum/go-ethereum/xeth"
) )
@ -144,17 +144,32 @@ func NewDatabase() ethutil.Database {
return db return db
} }
func NewClientIdentity(clientIdentifier, version, customIdentifier string) *wire.SimpleClientIdentity { func NewClientIdentity(clientIdentifier, version, customIdentifier string, pubkey string) *p2p.SimpleClientIdentity {
return wire.NewSimpleClientIdentity(clientIdentifier, version, customIdentifier) 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 { func NatType(natType string, gateway string) (nat p2p.NAT) {
ethereum, err := eth.New(db, clientIdentity, keyManager, eth.CapDefault, usePnp) 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 { if err != nil {
clilogger.Fatalln("eth start err:", err) clilogger.Fatalln("eth start err:", err)
} }
ethereum.Port = OutboundPort
ethereum.MaxPeers = MaxPeer
return ethereum return ethereum
} }
@ -268,11 +283,6 @@ func StartMining(ethereum *eth.Ethereum) bool {
if gminer == nil { if gminer == nil {
gminer = miner.New(addr, ethereum) 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() gminer.Start()
}() }()
RegisterInterrupt(func(os.Signal) { RegisterInterrupt(func(os.Signal) {