diff options
author | obscuren <geffobscura@gmail.com> | 2015-02-13 22:35:54 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-02-13 22:35:54 +0800 |
commit | 76fa75b39439e6c8c83ebc03fb32aa615227cc44 (patch) | |
tree | 9b755296ae96dd5e4ced28d6de4d5abfdeb33915 /cmd | |
parent | 75d164037fb9bbf75def7c5501727fd634ef124f (diff) | |
parent | 32a9c0ca809508c1648b8f44f3e09725af7a80d3 (diff) | |
download | go-tangerine-76fa75b39439e6c8c83ebc03fb32aa615227cc44.tar go-tangerine-76fa75b39439e6c8c83ebc03fb32aa615227cc44.tar.gz go-tangerine-76fa75b39439e6c8c83ebc03fb32aa615227cc44.tar.bz2 go-tangerine-76fa75b39439e6c8c83ebc03fb32aa615227cc44.tar.lz go-tangerine-76fa75b39439e6c8c83ebc03fb32aa615227cc44.tar.xz go-tangerine-76fa75b39439e6c8c83ebc03fb32aa615227cc44.tar.zst go-tangerine-76fa75b39439e6c8c83ebc03fb32aa615227cc44.zip |
wip
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/bootnode/main.go | 93 | ||||
-rw-r--r-- | cmd/ethereum/flags.go | 48 | ||||
-rw-r--r-- | cmd/ethereum/main.go | 31 | ||||
-rw-r--r-- | cmd/mist/assets/qml/main.qml | 869 | ||||
-rw-r--r-- | cmd/mist/assets/qml/views/info.qml | 12 | ||||
-rw-r--r-- | cmd/mist/bindings.go | 9 | ||||
-rw-r--r-- | cmd/mist/flags.go | 44 | ||||
-rw-r--r-- | cmd/mist/gui.go | 25 | ||||
-rw-r--r-- | cmd/mist/main.go | 29 | ||||
-rw-r--r-- | cmd/mist/ui_lib.go | 8 | ||||
-rw-r--r-- | cmd/peerserver/main.go | 58 | ||||
-rw-r--r-- | cmd/utils/cmd.go | 8 |
12 files changed, 1080 insertions, 154 deletions
diff --git a/cmd/bootnode/main.go b/cmd/bootnode/main.go new file mode 100644 index 000000000..dda9f34d4 --- /dev/null +++ b/cmd/bootnode/main.go @@ -0,0 +1,93 @@ +/* + This file is part of go-ethereum + + go-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + go-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. +*/ + +// Command bootnode runs a bootstrap node for the Discovery Protocol. +package main + +import ( + "crypto/ecdsa" + "encoding/hex" + "flag" + "fmt" + "io/ioutil" + "log" + "os" + + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/p2p/discover" + "github.com/ethereum/go-ethereum/p2p/nat" +) + +func main() { + var ( + listenAddr = flag.String("addr", ":30301", "listen address") + genKey = flag.String("genkey", "", "generate a node key and quit") + nodeKeyFile = flag.String("nodekey", "", "private key filename") + nodeKeyHex = flag.String("nodekeyhex", "", "private key as hex (for testing)") + natdesc = flag.String("nat", "none", "port mapping mechanism (any|none|upnp|pmp|extip:<IP>)") + + nodeKey *ecdsa.PrivateKey + err error + ) + flag.Parse() + logger.AddLogSystem(logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.DebugLevel)) + + if *genKey != "" { + writeKey(*genKey) + os.Exit(0) + } + + natm, err := nat.Parse(*natdesc) + if err != nil { + log.Fatalf("-nat: %v", err) + } + switch { + case *nodeKeyFile == "" && *nodeKeyHex == "": + log.Fatal("Use -nodekey or -nodekeyhex to specify a private key") + case *nodeKeyFile != "" && *nodeKeyHex != "": + log.Fatal("Options -nodekey and -nodekeyhex are mutually exclusive") + case *nodeKeyFile != "": + if nodeKey, err = crypto.LoadECDSA(*nodeKeyFile); err != nil { + log.Fatalf("-nodekey: %v", err) + } + case *nodeKeyHex != "": + if nodeKey, err = crypto.HexToECDSA(*nodeKeyHex); err != nil { + log.Fatalf("-nodekeyhex: %v", err) + } + } + + if _, err := discover.ListenUDP(nodeKey, *listenAddr, natm); err != nil { + log.Fatal(err) + } + select {} +} + +func writeKey(target string) { + key, err := crypto.GenerateKey() + if err != nil { + log.Fatal("could not generate key: %v", err) + } + b := crypto.FromECDSA(key) + if target == "-" { + fmt.Println(hex.EncodeToString(b)) + } else { + if err := ioutil.WriteFile(target, b, 0600); err != nil { + log.Fatal("write error: ", err) + } + } +} diff --git a/cmd/ethereum/flags.go b/cmd/ethereum/flags.go index bcdd7aa84..1e6869a69 100644 --- a/cmd/ethereum/flags.go +++ b/cmd/ethereum/flags.go @@ -21,6 +21,7 @@ package main import ( + "crypto/ecdsa" "flag" "fmt" "log" @@ -28,7 +29,9 @@ import ( "os/user" "path" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/p2p/nat" "github.com/ethereum/go-ethereum/vm" ) @@ -42,14 +45,14 @@ var ( StartWebSockets bool RpcPort int WsPort int - NatType string - PMPGateway string OutboundPort string ShowGenesis bool AddPeer string MaxPeer int GenAddr bool - SeedNode string + BootNodes string + NodeKey *ecdsa.PrivateKey + NAT nat.Interface SecretFile string ExportDir string NonInteractive bool @@ -84,6 +87,7 @@ func defaultDataDir() string { var defaultConfigFile = path.Join(defaultDataDir(), "conf.ini") func Init() { + // TODO: move common flag processing to cmd/util flag.Usage = func() { fmt.Fprintf(os.Stderr, "%s [options] [filename]:\noptions precedence: default < config file < environment variables < command line\n", os.Args[0]) flag.PrintDefaults() @@ -93,18 +97,12 @@ func Init() { flag.StringVar(&Identifier, "id", "", "Custom client identifier") 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.StringVar(&NatType, "nat", "", "NAT support (UPNP|PMP) (none)") - flag.StringVar(&PMPGateway, "pmp", "", "Gateway IP for PMP") - flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers") + flag.IntVar(&RpcPort, "rpcport", 8545, "port to start json-rpc server on") flag.IntVar(&WsPort, "wsport", 40404, "port to start websocket rpc server on") flag.BoolVar(&StartRpc, "rpc", false, "start rpc server") flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server") flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)") - flag.StringVar(&SeedNode, "seednode", "poc-8.ethdev.com:30303", "ip:port of seed node to connect to. Set to blank for skip") - flag.BoolVar(&SHH, "shh", true, "whisper protocol (on)") - flag.BoolVar(&Dial, "dial", true, "dial out connections (on)") flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key") 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") @@ -127,8 +125,38 @@ func Init() { flag.BoolVar(&StartJsConsole, "js", false, "launches javascript console") flag.BoolVar(&PrintVersion, "version", false, "prints version number") + // Network stuff + var ( + nodeKeyFile = flag.String("nodekey", "", "network private key file") + nodeKeyHex = flag.String("nodekeyhex", "", "network private key (for testing)") + natstr = flag.String("nat", "any", "port mapping mechanism (any|none|upnp|pmp|extip:<IP>)") + ) + flag.BoolVar(&Dial, "dial", true, "dial out connections (default on)") + flag.BoolVar(&SHH, "shh", true, "run whisper protocol (default on)") + flag.StringVar(&OutboundPort, "port", "30303", "listening port") + + flag.StringVar(&BootNodes, "bootnodes", "", "space-separated node URLs for discovery bootstrap") + flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers") + flag.Parse() + var err error + if NAT, err = nat.Parse(*natstr); err != nil { + log.Fatalf("-nat: %v", err) + } + switch { + case *nodeKeyFile != "" && *nodeKeyHex != "": + log.Fatal("Options -nodekey and -nodekeyhex are mutually exclusive") + case *nodeKeyFile != "": + if NodeKey, err = crypto.LoadECDSA(*nodeKeyFile); err != nil { + log.Fatalf("-nodekey: %v", err) + } + case *nodeKeyHex != "": + if NodeKey, err = crypto.HexToECDSA(*nodeKeyHex); err != nil { + log.Fatalf("-nodekeyhex: %v", err) + } + } + if VmType >= int(vm.MaxVmTy) { log.Fatal("Invalid VM type ", VmType) } diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go index f8851ecd3..d2b3418cd 100644 --- a/cmd/ethereum/main.go +++ b/cmd/ethereum/main.go @@ -31,6 +31,7 @@ import ( "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/state" ) @@ -61,21 +62,19 @@ func main() { utils.InitConfig(VmType, ConfigFile, Datadir, "ETH") ethereum, err := eth.New(ð.Config{ - Name: ClientIdentifier, - Version: Version, - KeyStore: KeyStore, - DataDir: Datadir, - LogFile: LogFile, - LogLevel: LogLevel, - LogFormat: LogFormat, - Identifier: Identifier, - MaxPeers: MaxPeer, - Port: OutboundPort, - NATType: PMPGateway, - PMPGateway: PMPGateway, - KeyRing: KeyRing, - Shh: SHH, - Dial: Dial, + Name: p2p.MakeName(ClientIdentifier, Version), + KeyStore: KeyStore, + DataDir: Datadir, + LogFile: LogFile, + LogLevel: LogLevel, + MaxPeers: MaxPeer, + Port: OutboundPort, + NAT: NAT, + KeyRing: KeyRing, + Shh: SHH, + Dial: Dial, + BootNodes: BootNodes, + NodeKey: NodeKey, }) if err != nil { @@ -135,7 +134,7 @@ func main() { utils.StartWebSockets(ethereum, WsPort) } - utils.StartEthereum(ethereum, SeedNode) + utils.StartEthereum(ethereum) if StartJsConsole { InitJsConsole(ethereum) diff --git a/cmd/mist/assets/qml/main.qml b/cmd/mist/assets/qml/main.qml index 2b56b7236..8f9a2d3cc 100644 --- a/cmd/mist/assets/qml/main.qml +++ b/cmd/mist/assets/qml/main.qml @@ -11,6 +11,7 @@ import "../ext/http.js" as Http ApplicationWindow { +<<<<<<< HEAD id: root //flags: Qt.FramelessWindowHint @@ -1101,4 +1102,870 @@ ApplicationWindow { addrField.focus = true } } - }
\ No newline at end of file + } +======= + id: root + + property var ethx : Eth.ethx + + width: 1200 + height: 820 + minimumWidth: 300 + + title: "Mist" + + TextField { + id: copyElementHax + visible: false + } + + function copyToClipboard(text) { + copyElementHax.text = text + copyElementHax.selectAll() + copyElementHax.copy() + } + + // Takes care of loading all default plugins + Component.onCompleted: { + var wallet = addPlugin("./views/wallet.qml", {noAdd: true, close: false, section: "ethereum", active: true}); + 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"}); + + mainSplit.setView(wallet.view, wallet.menuItem); + + newBrowserTab(eth.assetPath("html/home.html")); + + // Command setup + gui.sendCommand(0) + } + + function activeView(view, menuItem) { + mainSplit.setView(view, menuItem) + if (view.hideUrl) { + urlPane.visible = false; + mainView.anchors.top = rootView.top + } else { + urlPane.visible = true; + mainView.anchors.top = divider.bottom + } + } + + function addViews(view, path, options) { + var views = mainSplit.addComponent(view, options) + views.menuItem.path = path + + mainSplit.views.push(views); + + if(!options.noAdd) { + gui.addPlugin(path) + } + + return views + } + + function addPlugin(path, options) { + try { + if(typeof(path) === "string" && /^https?/.test(path)) { + console.log('load http') + Http.request(path, function(o) { + if(o.status === 200) { + var view = Qt.createQmlObject(o.responseText, mainView, path) + addViews(view, path, options) + } + }) + + return + } + + var component = Qt.createComponent(path); + if(component.status != Component.Ready) { + if(component.status == Component.Error) { + ethx.note("error: ", component.errorString()); + } + + return + } + + var view = mainView.createView(component, options) + var views = addViews(view, path, options) + + return views + } catch(e) { + console.log(e) + } + } + + function newBrowserTab(url) { + var window = addPlugin("./views/browser.qml", {noAdd: true, close: true, section: "apps", active: true}); + window.view.url = url; + window.menuItem.title = "Mist"; + activeView(window.view, window.menuItem); + } + + menuBar: MenuBar { + Menu { + title: "File" + MenuItem { + text: "Import App" + shortcut: "Ctrl+o" + onTriggered: { + generalFileDialog.show(true, importApp) + } + } + + MenuItem { + text: "Add plugin" + onTriggered: { + generalFileDialog.show(true, function(path) { + addPlugin(path, {close: true, section: "apps"}) + }) + } + } + + MenuItem { + text: "New tab" + shortcut: "Ctrl+t" + onTriggered: { + newBrowserTab("about:blank"); + } + } + + MenuSeparator {} + + MenuItem { + text: "Import key" + shortcut: "Ctrl+i" + onTriggered: { + generalFileDialog.show(true, function(path) { + gui.importKey(path) + }) + } + } + + MenuItem { + text: "Export keys" + shortcut: "Ctrl+e" + onTriggered: { + generalFileDialog.show(false, function(path) { + }) + } + } + + } + + Menu { + title: "Developer" + MenuItem { + iconSource: "../icecream.png" + text: "Debugger" + shortcut: "Ctrl+d" + onTriggered: eth.startDebugger() + } + + MenuItem { + text: "Import Tx" + onTriggered: { + txImportDialog.visible = true + } + } + + MenuItem { + text: "Run JS file" + onTriggered: { + generalFileDialog.show(true, function(path) { + eth.evalJavascriptFile(path) + }) + } + } + + MenuItem { + text: "Dump state" + onTriggered: { + generalFileDialog.show(false, function(path) { + // Empty hash for latest + gui.dumpState("", path) + }) + } + } + + MenuSeparator {} + } + + Menu { + title: "Network" + MenuItem { + text: "Connect to Node" + shortcut: "Ctrl+p" + onTriggered: { + addPeerWin.visible = true + } + } + MenuItem { + text: "Show Peers" + shortcut: "Ctrl+e" + onTriggered: { + peerWindow.visible = true + } + } + } + + Menu { + title: "Help" + MenuItem { + text: "About" + onTriggered: { + aboutWin.visible = true + } + } + } + + Menu { + title: "GLOBAL SHORTCUTS" + visible: false + MenuItem { + visible: false + shortcut: "Ctrl+l" + onTriggered: { + url.focus = true + } + } + } + } + + statusBar: StatusBar { + //height: 32 + id: statusBar + Label { + //y: 6 + id: walletValueLabel + + font.pixelSize: 10 + styleColor: "#797979" + } + + Label { + //y: 6 + objectName: "miningLabel" + visible: true + font.pixelSize: 10 + anchors.right: lastBlockLabel.left + anchors.rightMargin: 5 + } + + Label { + //y: 6 + id: lastBlockLabel + objectName: "lastBlockLabel" + visible: true + text: "" + font.pixelSize: 10 + anchors.right: peerGroup.left + anchors.rightMargin: 5 + } + + ProgressBar { + visible: false + id: downloadIndicator + value: 0 + objectName: "downloadIndicator" + y: -4 + x: statusBar.width / 2 - this.width / 2 + width: 160 + } + + Label { + visible: false + objectName: "downloadLabel" + //y: 7 + anchors.left: downloadIndicator.right + anchors.leftMargin: 5 + font.pixelSize: 10 + text: "0 / 0" + } + + + RowLayout { + id: peerGroup + //y: 7 + anchors.right: parent.right + MouseArea { + onDoubleClicked: peerWindow.visible = true + anchors.fill: parent + } + + Label { + id: peerLabel + font.pixelSize: 10 + text: "0 / 0" + } + } + } + + + property var blockModel: ListModel { + id: blockModel + } + + SplitView { + property var views: []; + + id: mainSplit + anchors.fill: parent + resizing: false + + function setView(view, menu) { + for(var i = 0; i < views.length; i++) { + views[i].view.visible = false + views[i].menuItem.setSelection(false) + } + view.visible = true + menu.setSelection(true) + } + + function addComponent(view, options) { + view.visible = false + view.anchors.fill = mainView + + var menuItem = menu.createMenuItem(view, options); + if( view.hasOwnProperty("menuItem") ) { + view.menuItem = menuItem; + } + + if( view.hasOwnProperty("onReady") ) { + view.onReady.call(view) + } + + if( options.active ) { + setView(view, menuItem) + } + + + return {view: view, menuItem: menuItem} + } + + /********************* + * Main menu. + ********************/ + Rectangle { + id: menu + Layout.minimumWidth: 210 + Layout.maximumWidth: 210 + anchors.top: parent.top + color: "#ececec" + + Component { + id: menuItemTemplate + Rectangle { + id: menuItem + property var view; + property var path; + property var closable; + + property alias title: label.text + property alias icon: icon.source + property alias secondaryTitle: secondary.text + function setSelection(on) { + sel.visible = on + } + + width: 206 + height: 28 + color: "#00000000" + + anchors { + left: parent.left + leftMargin: 4 + } + + Rectangle { + id: sel + visible: false + anchors.fill: parent + color: "#00000000" + Rectangle { + id: r + anchors.fill: parent + border.color: "#CCCCCC" + border.width: 1 + radius: 5 + color: "#FFFFFFFF" + } + Rectangle { + anchors { + top: r.top + bottom: r.bottom + right: r.right + } + width: 10 + color: "#FFFFFFFF" + + Rectangle { + anchors { + left: parent.left + right: parent.right + top: parent.top + } + height: 1 + color: "#CCCCCC" + } + + Rectangle { + anchors { + left: parent.left + right: parent.right + bottom: parent.bottom + } + height: 1 + color: "#CCCCCC" + } + } + } + + MouseArea { + anchors.fill: parent + onClicked: { + activeView(view, menuItem); + } + } + + Image { + id: icon + height: 20 + width: 20 + anchors { + left: parent.left + verticalCenter: parent.verticalCenter + leftMargin: 3 + } + MouseArea { + anchors.fill: parent + onClicked: { + menuItem.closeApp() + } + } + } + + Text { + id: label + anchors { + left: icon.right + verticalCenter: parent.verticalCenter + leftMargin: 3 + } + + color: "#0D0A01" + font.pixelSize: 12 + } + + Text { + id: secondary + anchors { + right: parent.right + rightMargin: 8 + verticalCenter: parent.verticalCenter + } + color: "#AEADBE" + font.pixelSize: 12 + } + + + function closeApp() { + if(!this.closable) { return; } + + if(this.view.hasOwnProperty("onDestroy")) { + this.view.onDestroy.call(this.view) + } + + this.view.destroy() + this.destroy() + for (var i = 0; i < mainSplit.views.length; i++) { + var view = mainSplit.views[i]; + if (view.menuItem === this) { + mainSplit.views.splice(i, 1); + break; + } + } + gui.removePlugin(this.path) + activeView(mainSplit.views[0].view, mainSplit.views[0].menuItem); + } + } + } + + function createMenuItem(view, options) { + if(options === undefined) { + options = {}; + } + + var section; + switch(options.section) { + case "ethereum": + section = menuDefault; + break; + case "legacy": + section = menuLegacy; + break; + default: + section = menuApps; + break; + } + + var comp = menuItemTemplate.createObject(section) + comp.view = view + comp.title = view.title + + if(view.hasOwnProperty("iconSource")) { + comp.icon = view.iconSource; + } + comp.closable = options.close; + + return comp + } + + ColumnLayout { + id: menuColumn + y: 10 + width: parent.width + anchors.left: parent.left + anchors.right: parent.right + spacing: 3 + + Text { + text: "ETHEREUM" + font.bold: true + anchors { + left: parent.left + leftMargin: 5 + } + color: "#888888" + } + + ColumnLayout { + id: menuDefault + spacing: 3 + anchors { + left: parent.left + right: parent.right + } + } + + + Text { + text: "NET" + font.bold: true + anchors { + left: parent.left + leftMargin: 5 + } + color: "#888888" + } + + ColumnLayout { + id: menuApps + spacing: 3 + anchors { + left: parent.left + right: parent.right + } + } + + Text { + text: "DEBUG" + font.bold: true + anchors { + left: parent.left + leftMargin: 5 + } + color: "#888888" + } + + ColumnLayout { + id: menuLegacy + spacing: 3 + anchors { + left: parent.left + right: parent.right + } + } + } + } + + /********************* + * Main view + ********************/ + Rectangle { + id: rootView + anchors.right: parent.right + anchors.left: menu.right + anchors.bottom: parent.bottom + anchors.top: parent.top + color: "#00000000" + + Rectangle { + id: urlPane + height: 40 + color: "#00000000" + anchors { + left: parent.left + right: parent.right + leftMargin: 5 + rightMargin: 5 + top: parent.top + topMargin: 5 + } + TextField { + id: url + objectName: "url" + placeholderText: "DApp URL" + anchors { + left: parent.left + right: parent.right + top: parent.top + topMargin: 5 + rightMargin: 5 + leftMargin: 5 + } + + Keys.onReturnPressed: { + if(/^https?/.test(this.text)) { + newBrowserTab(this.text); + } else { + addPlugin(this.text, {close: true, section: "apps"}) + } + } + } + + } + + // Border + Rectangle { + id: divider + anchors { + left: parent.left + right: parent.right + top: urlPane.bottom + } + z: -1 + height: 1 + color: "#CCCCCC" + } + + Rectangle { + id: mainView + color: "#00000000" + anchors.right: parent.right + anchors.left: parent.left + anchors.bottom: parent.bottom + anchors.top: divider.bottom + + function createView(component) { + var view = component.createObject(mainView) + + return view; + } + } + } + } + + + /****************** + * Dialogs + *****************/ + FileDialog { + id: generalFileDialog + property var callback; + onAccepted: { + var path = this.fileUrl.toString(); + callback.call(this, path); + } + + function show(selectExisting, callback) { + generalFileDialog.callback = callback; + generalFileDialog.selectExisting = selectExisting; + + this.open(); + } + } + + + /****************** + * Wallet functions + *****************/ + function importApp(path) { + var ext = path.split('.').pop() + if(ext == "html" || ext == "htm") { + eth.openHtml(path) + }else if(ext == "qml"){ + addPlugin(path, {close: true, section: "apps"}) + } + } + + + function setWalletValue(value) { + walletValueLabel.text = value + } + + function loadPlugin(name) { + console.log("Loading plugin" + name) + var view = mainView.addPlugin(name) + } + + function setPeers(text) { + peerLabel.text = text + } + + function addPeer(peer) { + // We could just append the whole peer object but it cries if you try to alter them + peerModel.append({ip: peer.ip, port: peer.port, lastResponse:timeAgo(peer.lastSend), latency: peer.latency, version: peer.version, caps: peer.caps}) + } + + function resetPeers(){ + peerModel.clear() + } + + function timeAgo(unixTs){ + var lapsed = (Date.now() - new Date(unixTs*1000)) / 1000 + return (lapsed + " seconds ago") + } + + function convertToPretty(unixTs){ + var a = new Date(unixTs*1000); + var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; + var year = a.getFullYear(); + var month = months[a.getMonth()]; + var date = a.getDate(); + var hour = a.getHours(); + var min = a.getMinutes(); + var sec = a.getSeconds(); + var time = date+' '+month+' '+year+' '+hour+':'+min+':'+sec ; + return time; + } + + /********************** + * Windows + *********************/ + Window { + id: peerWindow + //flags: Qt.CustomizeWindowHint | Qt.Tool | Qt.WindowCloseButtonHint + height: 200 + width: 700 + Rectangle { + anchors.fill: parent + property var peerModel: ListModel { + id: peerModel + } + TableView { + anchors.fill: parent + id: peerTable + model: peerModel + TableViewColumn{width: 200; role: "ip" ; title: "IP" } + TableViewColumn{width: 260; role: "version" ; title: "Version" } + TableViewColumn{width: 180; role: "caps" ; title: "Capabilities" } + } + } + } + + Window { + id: aboutWin + visible: false + title: "About" + minimumWidth: 350 + maximumWidth: 350 + maximumHeight: 280 + minimumHeight: 280 + + Image { + id: aboutIcon + height: 150 + width: 150 + fillMode: Image.PreserveAspectFit + smooth: true + source: "../facet.png" + x: 10 + y: 30 + } + + Text { + anchors.left: aboutIcon.right + anchors.leftMargin: 10 + anchors.top: parent.top + anchors.topMargin: 30 + font.pointSize: 12 + text: "<h2>Mist (0.7.10)</h2><br><h3>Development</h3>Jeffrey Wilcke<br>Viktor TrĂ³n<br>Felix Lange<br>Taylor Gerring<br>Daniel Nagy<br><h3>UX</h3>Alex van de Sande<br>" + } + } + + Window { + id: txImportDialog + minimumWidth: 270 + maximumWidth: 270 + maximumHeight: 50 + minimumHeight: 50 + TextField { + id: txImportField + width: 170 + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.leftMargin: 10 + onAccepted: { + } + } + Button { + anchors.left: txImportField.right + anchors.verticalCenter: parent.verticalCenter + anchors.leftMargin: 5 + text: "Import" + onClicked: { + eth.importTx(txImportField.text) + txImportField.visible = false + } + } + Component.onCompleted: { + addrField.focus = true + } + } + + Window { + id: addPeerWin + visible: false + minimumWidth: 400 + maximumWidth: 400 + maximumHeight: 50 + minimumHeight: 50 + title: "Connect to Node" + + TextField { + id: addrField + placeholderText: "enode://<hex node id>:<IP address>:<port>" + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.right: addPeerButton.left + anchors.leftMargin: 10 + anchors.rightMargin: 10 + onAccepted: { + eth.connectToPeer(addrField.text) + addPeerWin.visible = false + } + } + + Button { + id: addPeerButton + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + anchors.rightMargin: 10 + text: "Connect" + onClicked: { + eth.connectToPeer(addrField.text) + addPeerWin.visible = false + } + } + Component.onCompleted: { + addrField.focus = true + } + } + } +>>>>>>> 32a9c0ca809508c1648b8f44f3e09725af7a80d3 diff --git a/cmd/mist/assets/qml/views/info.qml b/cmd/mist/assets/qml/views/info.qml index 14ee0bce1..b2d2f521c 100644 --- a/cmd/mist/assets/qml/views/info.qml +++ b/cmd/mist/assets/qml/views/info.qml @@ -32,18 +32,6 @@ Rectangle { width: 500 } - Label { - text: "Client ID" - } - TextField { - text: gui.getCustomIdentifier() - width: 500 - placeholderText: "Anonymous" - onTextChanged: { - gui.setCustomIdentifier(text) - } - } - TextArea { objectName: "statsPane" width: parent.width diff --git a/cmd/mist/bindings.go b/cmd/mist/bindings.go index 706c789b1..9623538a3 100644 --- a/cmd/mist/bindings.go +++ b/cmd/mist/bindings.go @@ -64,15 +64,6 @@ func (gui *Gui) Transact(recipient, value, gas, gasPrice, d string) (string, err return gui.xeth.Transact(recipient, value, gas, gasPrice, data) } -func (gui *Gui) SetCustomIdentifier(customIdentifier string) { - gui.clientIdentity.SetCustomIdentifier(customIdentifier) - gui.config.Save("id", customIdentifier) -} - -func (gui *Gui) GetCustomIdentifier() string { - return gui.clientIdentity.GetCustomIdentifier() -} - // functions that allow Gui to implement interface guilogger.LogSystem func (gui *Gui) SetLogLevel(level logger.LogLevel) { gui.logLevel = level diff --git a/cmd/mist/flags.go b/cmd/mist/flags.go index f042b39b0..eb280f71b 100644 --- a/cmd/mist/flags.go +++ b/cmd/mist/flags.go @@ -21,6 +21,7 @@ package main import ( + "crypto/ecdsa" "flag" "fmt" "log" @@ -31,7 +32,9 @@ import ( "runtime" "bitbucket.org/kardianos/osext" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/p2p/nat" "github.com/ethereum/go-ethereum/vm" ) @@ -39,19 +42,18 @@ var ( Identifier string KeyRing string KeyStore string - PMPGateway string StartRpc bool StartWebSockets bool RpcPort int WsPort int - UseUPnP bool - NatType string OutboundPort string ShowGenesis bool AddPeer string MaxPeer int GenAddr bool - SeedNode string + BootNodes string + NodeKey *ecdsa.PrivateKey + NAT nat.Interface SecretFile string ExportDir string NonInteractive bool @@ -99,6 +101,7 @@ func defaultDataDir() string { var defaultConfigFile = path.Join(defaultDataDir(), "conf.ini") func Init() { + // TODO: move common flag processing to cmd/utils flag.Usage = func() { fmt.Fprintf(os.Stderr, "%s [options] [filename]:\noptions precedence: default < config file < environment variables < command line\n", os.Args[0]) flag.PrintDefaults() @@ -108,30 +111,51 @@ func Init() { flag.StringVar(&Identifier, "id", "", "Custom client identifier") 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", true, "enable UPnP support") - flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers") flag.IntVar(&RpcPort, "rpcport", 8545, "port to start json-rpc server on") flag.IntVar(&WsPort, "wsport", 40404, "port to start websocket rpc server on") flag.BoolVar(&StartRpc, "rpc", true, "start rpc server") flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server") flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)") - flag.StringVar(&SeedNode, "seednode", "poc-8.ethdev.com:30303", "ip:port of seed node to connect to. Set to blank for skip") 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)") flag.StringVar(&AssetPath, "asset_path", defaultAssetPath(), "absolute path to GUI assets directory") + // Network stuff + var ( + nodeKeyFile = flag.String("nodekey", "", "network private key file") + nodeKeyHex = flag.String("nodekeyhex", "", "network private key (for testing)") + natstr = flag.String("nat", "any", "port mapping mechanism (any|none|upnp|pmp|extip:<IP>)") + ) + flag.StringVar(&OutboundPort, "port", "30303", "listening port") + flag.StringVar(&BootNodes, "bootnodes", "", "space-separated node URLs for discovery bootstrap") + flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers") + flag.Parse() + var err error + if NAT, err = nat.Parse(*natstr); err != nil { + log.Fatalf("-nat: %v", err) + } + switch { + case *nodeKeyFile != "" && *nodeKeyHex != "": + log.Fatal("Options -nodekey and -nodekeyhex are mutually exclusive") + case *nodeKeyFile != "": + if NodeKey, err = crypto.LoadECDSA(*nodeKeyFile); err != nil { + log.Fatalf("-nodekey: %v", err) + } + case *nodeKeyHex != "": + if NodeKey, err = crypto.HexToECDSA(*nodeKeyHex); err != nil { + log.Fatalf("-nodekeyhex: %v", err) + } + } + if VmType >= int(vm.MaxVmTy) { log.Fatal("Invalid VM type ", VmType) } diff --git a/cmd/mist/gui.go b/cmd/mist/gui.go index edc799abc..dee99859c 100644 --- a/cmd/mist/gui.go +++ b/cmd/mist/gui.go @@ -41,7 +41,6 @@ import ( "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/ui/qt/qwhisper" "github.com/ethereum/go-ethereum/xeth" "github.com/obscuren/qml" @@ -77,9 +76,8 @@ type Gui struct { xeth *xeth.XEth - Session string - clientIdentity *p2p.SimpleClientIdentity - config *ethutil.ConfigManager + Session string + config *ethutil.ConfigManager plugins map[string]plugin @@ -87,7 +85,7 @@ type Gui struct { } // Create GUI, but doesn't start it -func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, clientIdentity *p2p.SimpleClientIdentity, session string, logLevel int) *Gui { +func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, session string, logLevel int) *Gui { db, err := ethdb.NewLDBDatabase("tx_database") if err != nil { panic(err) @@ -95,15 +93,14 @@ func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, clientIden xeth := xeth.New(ethereum) gui := &Gui{eth: ethereum, - txDb: db, - xeth: xeth, - logLevel: logger.LogLevel(logLevel), - Session: session, - open: false, - clientIdentity: clientIdentity, - config: config, - plugins: make(map[string]plugin), - serviceEvents: make(chan ServEv, 1), + txDb: db, + xeth: xeth, + logLevel: logger.LogLevel(logLevel), + Session: session, + open: false, + config: config, + plugins: make(map[string]plugin), + serviceEvents: make(chan ServEv, 1), } data, _ := ethutil.ReadAllFile(path.Join(ethutil.Config.ExecPath, "plugins.json")) json.Unmarshal([]byte(data), &gui.plugins) diff --git a/cmd/mist/main.go b/cmd/mist/main.go index 66872a241..52b5e4e94 100644 --- a/cmd/mist/main.go +++ b/cmd/mist/main.go @@ -52,19 +52,18 @@ func run() error { config := utils.InitConfig(VmType, ConfigFile, Datadir, "ETH") ethereum, err := eth.New(ð.Config{ - Name: ClientIdentifier, - Version: Version, - KeyStore: KeyStore, - DataDir: Datadir, - LogFile: LogFile, - LogLevel: LogLevel, - Identifier: Identifier, - MaxPeers: MaxPeer, - Port: OutboundPort, - NATType: PMPGateway, - PMPGateway: PMPGateway, - KeyRing: KeyRing, - Dial: true, + Name: p2p.MakeName(ClientIdentifier, Version), + KeyStore: KeyStore, + DataDir: Datadir, + LogFile: LogFile, + LogLevel: LogLevel, + MaxPeers: MaxPeer, + Port: OutboundPort, + NAT: NAT, + BootNodes: BootNodes, + NodeKey: NodeKey, + KeyRing: KeyRing, + Dial: true, }) if err != nil { mainlogger.Fatalln(err) @@ -79,12 +78,12 @@ func run() error { utils.StartWebSockets(ethereum, WsPort) } - gui := NewWindow(ethereum, config, ethereum.ClientIdentity().(*p2p.SimpleClientIdentity), KeyRing, LogLevel) + gui := NewWindow(ethereum, config, KeyRing, LogLevel) utils.RegisterInterrupt(func(os.Signal) { gui.Stop() }) - go utils.StartEthereum(ethereum, SeedNode) + go utils.StartEthereum(ethereum) fmt.Println("ETH stack took", time.Since(tstart)) diff --git a/cmd/mist/ui_lib.go b/cmd/mist/ui_lib.go index 7c5802076..ba3ac3b61 100644 --- a/cmd/mist/ui_lib.go +++ b/cmd/mist/ui_lib.go @@ -136,15 +136,15 @@ func (ui *UiLib) Muted(content string) { func (ui *UiLib) Connect(button qml.Object) { if !ui.connected { - ui.eth.Start(SeedNode) + ui.eth.Start() ui.connected = true button.Set("enabled", false) } } -func (ui *UiLib) ConnectToPeer(addr string) { - if err := ui.eth.SuggestPeer(addr); err != nil { - guilogger.Infoln(err) +func (ui *UiLib) ConnectToPeer(nodeURL string) { + if err := ui.eth.SuggestPeer(nodeURL); err != nil { + guilogger.Infoln("SuggestPeer error: " + err.Error()) } } diff --git a/cmd/peerserver/main.go b/cmd/peerserver/main.go deleted file mode 100644 index 341c4dbb9..000000000 --- a/cmd/peerserver/main.go +++ /dev/null @@ -1,58 +0,0 @@ -/* - This file is part of go-ethereum - - go-ethereum is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - go-ethereum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. -*/ -package main - -import ( - "crypto/elliptic" - "flag" - "log" - "os" - - "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/p2p" -) - -var ( - natType = flag.String("nat", "", "NAT traversal implementation") - pmpGateway = flag.String("gateway", "", "gateway address for NAT-PMP") - listenAddr = flag.String("addr", ":30301", "listen address") -) - -func main() { - flag.Parse() - nat, err := p2p.ParseNAT(*natType, *pmpGateway) - if err != nil { - log.Fatal("invalid nat:", err) - } - - logger.AddLogSystem(logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.InfoLevel)) - key, _ := crypto.GenerateKey() - marshaled := elliptic.Marshal(crypto.S256(), key.PublicKey.X, key.PublicKey.Y) - - srv := p2p.Server{ - MaxPeers: 100, - Identity: p2p.NewSimpleClientIdentity("Ethereum(G)", "0.1", "Peer Server Two", marshaled), - ListenAddr: *listenAddr, - NAT: nat, - NoDial: true, - } - if err := srv.Start(); err != nil { - log.Fatal("could not start server:", err) - } - select {} -} diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index 70df289c3..ecb847fc3 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -121,13 +121,11 @@ func exit(err error) { os.Exit(status) } -func StartEthereum(ethereum *eth.Ethereum, SeedNode string) { - clilogger.Infof("Starting %s", ethereum.ClientIdentity()) - err := ethereum.Start(SeedNode) - if err != nil { +func StartEthereum(ethereum *eth.Ethereum) { + clilogger.Infoln("Starting ", ethereum.Name()) + if err := ethereum.Start(); err != nil { exit(err) } - RegisterInterrupt(func(sig os.Signal) { ethereum.Stop() logger.Flush() |