diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/ethereum/cmd.go | 2 | ||||
-rw-r--r-- | cmd/ethereum/flags.go | 6 | ||||
-rw-r--r-- | cmd/ethereum/main.go | 4 | ||||
-rw-r--r-- | cmd/ethereum/repl/repl.go | 2 | ||||
-rw-r--r-- | cmd/mist/assets/qml/main.qml | 1 | ||||
-rw-r--r-- | cmd/mist/assets/qml/views/whisper.qml | 47 | ||||
-rw-r--r-- | cmd/mist/flags.go | 4 | ||||
-rw-r--r-- | cmd/mist/gui.go | 44 | ||||
-rw-r--r-- | cmd/mist/main.go | 16 | ||||
-rw-r--r-- | cmd/mist/ui_lib.go | 31 | ||||
-rw-r--r-- | cmd/utils/cmd.go | 38 | ||||
-rw-r--r-- | cmd/utils/websockets.go | 2 |
12 files changed, 140 insertions, 57 deletions
diff --git a/cmd/ethereum/cmd.go b/cmd/ethereum/cmd.go index 8710d6136..d8b9ea487 100644 --- a/cmd/ethereum/cmd.go +++ b/cmd/ethereum/cmd.go @@ -21,9 +21,9 @@ import ( "io/ioutil" "os" - "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/cmd/ethereum/repl" "github.com/ethereum/go-ethereum/cmd/utils" + "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/javascript" ) diff --git a/cmd/ethereum/flags.go b/cmd/ethereum/flags.go index 783944cf2..556735491 100644 --- a/cmd/ethereum/flags.go +++ b/cmd/ethereum/flags.go @@ -38,7 +38,8 @@ var ( StartRpc bool StartWebSockets bool RpcPort int - UseUPnP bool + NatType string + PMPGateway string OutboundPort string ShowGenesis bool AddPeer string @@ -84,7 +85,8 @@ func Init() { flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use") flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)") flag.StringVar(&OutboundPort, "port", "30303", "listening port") - flag.BoolVar(&UseUPnP, "upnp", false, "enable UPnP support") + flag.StringVar(&NatType, "nat", "", "NAT support (UPNP|PMP) (none)") + flag.StringVar(&PMPGateway, "pmp", "", "Gateway IP for PMP") flag.IntVar(&MaxPeer, "maxpeer", 10, "maximum desired peers") flag.IntVar(&RpcPort, "rpcport", 8080, "port to start json-rpc server on") flag.BoolVar(&StartRpc, "rpc", false, "start rpc server") diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go index 9efc8e9dc..da09e0b58 100644 --- a/cmd/ethereum/main.go +++ b/cmd/ethereum/main.go @@ -69,9 +69,9 @@ func main() { // create, import, export keys utils.KeyTasks(keyManager, KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive) - clientIdentity := utils.NewClientIdentity(ClientIdentifier, Version, Identifier) + clientIdentity := utils.NewClientIdentity(ClientIdentifier, Version, Identifier, string(keyManager.PublicKey())) - ethereum := utils.NewEthereum(db, clientIdentity, keyManager, UseUPnP, OutboundPort, MaxPeer) + ethereum := utils.NewEthereum(db, clientIdentity, keyManager, utils.NatType(NatType, PMPGateway), OutboundPort, MaxPeer) if Dump { var block *types.Block diff --git a/cmd/ethereum/repl/repl.go b/cmd/ethereum/repl/repl.go index a5146fecd..4a7880ff4 100644 --- a/cmd/ethereum/repl/repl.go +++ b/cmd/ethereum/repl/repl.go @@ -24,7 +24,7 @@ import ( "os" "path" - "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/javascript" "github.com/ethereum/go-ethereum/logger" diff --git a/cmd/mist/assets/qml/main.qml b/cmd/mist/assets/qml/main.qml index 9f1f214a6..285757080 100644 --- a/cmd/mist/assets/qml/main.qml +++ b/cmd/mist/assets/qml/main.qml @@ -50,6 +50,7 @@ ApplicationWindow { addPlugin("./views/miner.qml", {noAdd: true, close: false, section: "ethereum", active: true}); addPlugin("./views/transaction.qml", {noAdd: true, close: false, section: "legacy"}); + addPlugin("./views/whisper.qml", {noAdd: true, close: false, section: "legacy"}); addPlugin("./views/chain.qml", {noAdd: true, close: false, section: "legacy"}); addPlugin("./views/pending_tx.qml", {noAdd: true, close: false, section: "legacy"}); addPlugin("./views/info.qml", {noAdd: true, close: false, section: "legacy"}); diff --git a/cmd/mist/assets/qml/views/whisper.qml b/cmd/mist/assets/qml/views/whisper.qml new file mode 100644 index 000000000..b50841ba5 --- /dev/null +++ b/cmd/mist/assets/qml/views/whisper.qml @@ -0,0 +1,47 @@ + +import QtQuick 2.0 +import QtQuick.Controls 1.0; +import QtQuick.Layouts 1.0; +import QtQuick.Dialogs 1.0; +import QtQuick.Window 2.1; +import QtQuick.Controls.Styles 1.1 +import Ethereum 1.0 + +Rectangle { + id: root + property var title: "Whisper" + property var iconSource: "../facet.png" + property var menuItem + + objectName: "whisperView" + anchors.fill: parent + + property var identity: "" + Component.onCompleted: { + identity = shh.newIdentity() + console.log("New identity:", identity) + + var t = shh.watch({topics: ["chat"]}) + } + + RowLayout { + TextField { + id: to + placeholderText: "To" + } + TextField { + id: data + placeholderText: "Data" + } + TextField { + id: topics + placeholderText: "topic1, topic2, topic3, ..." + } + Button { + text: "Send" + onClicked: { + shh.post(eth.toHex(data.text), "", identity, topics.text.split(","), 500, 50) + } + } + } +} diff --git a/cmd/mist/flags.go b/cmd/mist/flags.go index 2ae0a0487..1d77532d9 100644 --- a/cmd/mist/flags.go +++ b/cmd/mist/flags.go @@ -36,10 +36,12 @@ var ( Identifier string KeyRing string KeyStore string + PMPGateway string StartRpc bool StartWebSockets bool RpcPort int UseUPnP bool + NatType string OutboundPort string ShowGenesis bool AddPeer string @@ -111,10 +113,12 @@ func Init() { flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)") flag.BoolVar(&UseSeed, "seed", true, "seed peers") flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key") + flag.StringVar(&NatType, "nat", "", "NAT support (UPNP|PMP) (none)") flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)") flag.StringVar(&ExportDir, "export", "", "exports the session keyring to files in the directory given") flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)") flag.StringVar(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use") + flag.StringVar(&PMPGateway, "pmp", "", "Gateway IP for PMP") flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file") flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)") flag.IntVar(&LogLevel, "loglevel", int(logger.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)") diff --git a/cmd/mist/gui.go b/cmd/mist/gui.go index 773688ffc..0339f601e 100644 --- a/cmd/mist/gui.go +++ b/cmd/mist/gui.go @@ -30,14 +30,15 @@ import ( "strings" "time" - "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" + "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/wire" + "github.com/ethereum/go-ethereum/p2p" + "github.com/ethereum/go-ethereum/ui/qt/qwhisper" "github.com/ethereum/go-ethereum/xeth" "gopkg.in/qml.v1" ) @@ -87,7 +88,8 @@ type Gui struct { eth *eth.Ethereum // The public Ethereum library - uiLib *UiLib + uiLib *UiLib + whisper *qwhisper.Whisper txDb *ethdb.LDBDatabase @@ -97,7 +99,7 @@ type Gui struct { pipe *xeth.JSXEth Session string - clientIdentity *wire.SimpleClientIdentity + clientIdentity *p2p.SimpleClientIdentity config *ethutil.ConfigManager plugins map[string]plugin @@ -107,7 +109,7 @@ type Gui struct { } // Create GUI, but doesn't start it -func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, clientIdentity *wire.SimpleClientIdentity, session string, logLevel int) *Gui { +func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, clientIdentity *p2p.SimpleClientIdentity, session string, logLevel int) *Gui { db, err := ethdb.NewLDBDatabase("tx_database") if err != nil { panic(err) @@ -138,10 +140,12 @@ func (gui *Gui) Start(assetPath string) { gui.engine = qml.NewEngine() context := gui.engine.Context() gui.uiLib = NewUiLib(gui.engine, gui.eth, assetPath) + gui.whisper = qwhisper.New(gui.eth.Whisper()) // Expose the eth library and the ui library to QML context.SetVar("gui", gui) context.SetVar("eth", gui.uiLib) + context.SetVar("shh", gui.whisper) // Load the main QML interface data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) @@ -391,6 +395,8 @@ func (gui *Gui) update() { gui.setPeerInfo() }() + gui.whisper.SetView(gui.win.Root().ObjectByName("whisperView")) + for _, plugin := range gui.plugins { guilogger.Infoln("Loading plugin ", plugin.Name) @@ -409,8 +415,7 @@ func (gui *Gui) update() { miningLabel := gui.getObjectByName("miningLabel") events := gui.eth.EventMux().Subscribe( - eth.ChainSyncEvent{}, - eth.PeerListEvent{}, + //eth.PeerListEvent{}, core.NewBlockEvent{}, core.TxPreEvent{}, core.TxPostEvent{}, @@ -460,9 +465,6 @@ func (gui *Gui) update() { gui.setWalletValue(object.Balance(), nil) state.UpdateStateObject(object) - - case eth.PeerListEvent: - gui.setPeerInfo() } case <-peerUpdateTicker.C: @@ -472,16 +474,18 @@ func (gui *Gui) update() { lastBlockLabel.Set("text", statusText) miningLabel.Set("text", "Mining @ "+strconv.FormatInt(gui.uiLib.miner.GetPow().GetHashrate(), 10)+"Khash") - blockLength := gui.eth.BlockPool().BlocksProcessed - chainLength := gui.eth.BlockPool().ChainLength + /* + blockLength := gui.eth.BlockPool().BlocksProcessed + chainLength := gui.eth.BlockPool().ChainLength - var ( - pct float64 = 1.0 / float64(chainLength) * float64(blockLength) - dlWidget = gui.win.Root().ObjectByName("downloadIndicator") - dlLabel = gui.win.Root().ObjectByName("downloadLabel") - ) - dlWidget.Set("value", pct) - dlLabel.Set("text", fmt.Sprintf("%d / %d", blockLength, chainLength)) + var ( + pct float64 = 1.0 / float64(chainLength) * float64(blockLength) + dlWidget = gui.win.Root().ObjectByName("downloadIndicator") + dlLabel = gui.win.Root().ObjectByName("downloadLabel") + ) + dlWidget.Set("value", pct) + dlLabel.Set("text", fmt.Sprintf("%d / %d", blockLength, chainLength)) + */ case <-statsUpdateTicker.C: gui.setStatsPane() @@ -509,7 +513,7 @@ Heap Alloc: %d CGNext: %x NumGC: %d `, Version, runtime.Version(), - eth.ProtocolVersion, eth.P2PVersion, + eth.ProtocolVersion, 2, runtime.NumCPU, runtime.NumGoroutine(), runtime.NumCgoCall(), memStats.Alloc, memStats.HeapAlloc, memStats.NextGC, memStats.NumGC, diff --git a/cmd/mist/main.go b/cmd/mist/main.go index 14336b4e8..3ea6e8e91 100644 --- a/cmd/mist/main.go +++ b/cmd/mist/main.go @@ -23,8 +23,8 @@ import ( "runtime" "time" - "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/cmd/utils" + "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/logger" "gopkg.in/qml.v1" ) @@ -58,8 +58,8 @@ func run() error { // create, import, export keys utils.KeyTasks(keyManager, KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive) - clientIdentity := utils.NewClientIdentity(ClientIdentifier, Version, Identifier) - ethereum = utils.NewEthereum(db, clientIdentity, keyManager, UseUPnP, OutboundPort, MaxPeer) + clientIdentity := utils.NewClientIdentity(ClientIdentifier, Version, Identifier, string(keyManager.PublicKey())) + ethereum := utils.NewEthereum(db, clientIdentity, keyManager, utils.NatType(NatType, PMPGateway), OutboundPort, MaxPeer) if ShowGenesis { utils.ShowGenesis(ethereum) @@ -69,6 +69,10 @@ func run() error { utils.StartRpc(ethereum, RpcPort) } + if StartWebSockets { + utils.StartWebSockets(ethereum) + } + gui := NewWindow(ethereum, config, clientIdentity, KeyRing, LogLevel) gui.stdLog = stdLog @@ -100,16 +104,10 @@ func main() { utils.HandleInterrupt() - if StartWebSockets { - utils.StartWebSockets(ethereum) - } - // we need to run the interrupt callbacks in case gui is closed // this skips if we got here by actual interrupt stopping the GUI if !interrupted { utils.RunInterruptCallbacks(os.Interrupt) } - // this blocks the thread - ethereum.WaitForShutdown() logger.Flush() } diff --git a/cmd/mist/ui_lib.go b/cmd/mist/ui_lib.go index fdbde50fd..68f333563 100644 --- a/cmd/mist/ui_lib.go +++ b/cmd/mist/ui_lib.go @@ -24,11 +24,12 @@ import ( "strconv" "strings" - "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/ethutil" + "github.com/ethereum/go-ethereum/event/filter" "github.com/ethereum/go-ethereum/javascript" "github.com/ethereum/go-ethereum/miner" "github.com/ethereum/go-ethereum/state" @@ -57,6 +58,7 @@ type UiLib struct { jsEngine *javascript.JSRE filterCallbacks map[int][]int + filterManager *filter.FilterManager miner *miner.Miner } @@ -64,6 +66,7 @@ type UiLib struct { func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib { lib := &UiLib{JSXEth: xeth.NewJSXEth(eth), engine: engine, eth: eth, assetPath: assetPath, jsEngine: javascript.NewJSRE(eth), filterCallbacks: make(map[int][]int)} //, filters: make(map[int]*xeth.JSFilter)} lib.miner = miner.New(eth.KeyManager().Address(), eth) + lib.filterManager = filter.NewFilterManager(eth.EventMux()) return lib } @@ -123,7 +126,8 @@ func (self *UiLib) LookupAddress(name string) string { } func (self *UiLib) PastPeers() *ethutil.List { - return ethutil.NewList(eth.PastPeers()) + return ethutil.NewList([]string{}) + //return ethutil.NewList(eth.PastPeers()) } func (self *UiLib) ImportTx(rlpTx string) { @@ -191,7 +195,7 @@ func (ui *UiLib) Connect(button qml.Object) { } func (ui *UiLib) ConnectToPeer(addr string) { - ui.eth.ConnectToPeer(addr) + ui.eth.SuggestPeer(addr) } func (ui *UiLib) AssetPath(p string) string { @@ -226,7 +230,7 @@ func (self *UiLib) NewFilter(object map[string]interface{}) (id int) { filter.MessageCallback = func(messages state.Messages) { self.win.Root().Call("invokeFilterCallback", xeth.ToJSMessages(messages), id) } - id = self.eth.InstallFilter(filter) + id = self.filterManager.InstallFilter(filter) return id } @@ -239,12 +243,12 @@ func (self *UiLib) NewFilterString(typ string) (id int) { fmt.Println("QML is lagging") } } - id = self.eth.InstallFilter(filter) + id = self.filterManager.InstallFilter(filter) return id } func (self *UiLib) Messages(id int) *ethutil.List { - filter := self.eth.GetFilter(id) + filter := self.filterManager.GetFilter(id) if filter != nil { messages := xeth.ToJSMessages(filter.Find()) @@ -255,7 +259,7 @@ func (self *UiLib) Messages(id int) *ethutil.List { } func (self *UiLib) UninstallFilter(id int) { - self.eth.UninstallFilter(id) + self.filterManager.UninstallFilter(id) } func mapToTxParams(object map[string]interface{}) map[string]string { @@ -372,3 +376,16 @@ func (self *UiLib) ToggleMining() bool { return false } } + +func (self *UiLib) ToHex(data string) string { + return "0x" + ethutil.Bytes2Hex([]byte(data)) +} + +/* +// XXX Refactor me & MOVE +func (self *Ethereum) InstallFilter(filter *core.Filter) (id int) { + return self.filterManager.InstallFilter(filter) +} +func (self *Ethereum) UninstallFilter(id int) { self.filterManager.UninstallFilter(id) } +func (self *Ethereum) GetFilter(id int) *core.Filter { return self.filterManager.GetFilter(id) } +*/ diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index db7bcd35e..3e3ac617a 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("cannot resolve PMP gateway IP %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) { diff --git a/cmd/utils/websockets.go b/cmd/utils/websockets.go index d3ba50e78..29f9b8aeb 100644 --- a/cmd/utils/websockets.go +++ b/cmd/utils/websockets.go @@ -1,7 +1,7 @@ package utils import ( - "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/websocket" "github.com/ethereum/go-ethereum/xeth" |