Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC8 Networking Integration #292

Merged
merged 53 commits into from
Feb 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
c8a8aa0
initial hook for crypto handshake (void, off by default)
zelig Jan 18, 2015
88167f3
add privkey to clientIdentity + tests
zelig Jan 18, 2015
d227f61
fix protocol to accomodate privkey
zelig Jan 18, 2015
4e52adb
add crypto auth logic to p2p
zelig Jan 18, 2015
b855f67
rewrite to comply with latest spec
zelig Jan 18, 2015
714b955
fix crash
zelig Jan 19, 2015
3b6385b
handshake test to crypto
zelig Jan 19, 2015
076c382
handshake test to crypto
zelig Jan 19, 2015
489d956
completed the test. FAIL now. it crashes at diffie-hellman. ECIES -> …
zelig Jan 19, 2015
1803c65
integrate cryptoId into peer and connection lifecycle
zelig Jan 19, 2015
e252c63
first stab at integrating crypto in our p2p
zelig Jan 19, 2015
2e86856
add minor comments to the test
zelig Jan 20, 2015
923504c
add equality check for nonce and remote nonce
zelig Jan 20, 2015
58fc2c6
important fix for peer pubkey. when taken from identity, chop first f…
zelig Jan 20, 2015
364b783
changes that fix it all:
zelig Jan 20, 2015
4afde4e
add code documentation
zelig Jan 21, 2015
1f2adb0
add initial peer level test (failing)
zelig Jan 21, 2015
20aade5
chop first byte when cryptoid.PubKeyS is set from identity.Pubkey() s…
zelig Jan 21, 2015
faa069a
peer-level integration test for crypto handshake
zelig Jan 21, 2015
54252ed
add temporary forced session token generation
zelig Jan 21, 2015
4499743
apply handshake related improvements from p2p.crypto branch
zelig Jan 26, 2015
68205de
make crypto handshake calls package level, store privateKey on peer +…
zelig Jan 26, 2015
7176595
get rid of Private Key in ClientIdentity
zelig Jan 26, 2015
488a042
fix clientidentity test after privkey removed
zelig Jan 29, 2015
2e48d39
key generation abstracted out, for testing with deterministic keys
zelig Jan 29, 2015
410b35e
crypto: make it easier to run Sha3 on multiple inputs
fjl Jan 27, 2015
8c3095f
rlp: fix encoding of arrays with byte element type
fjl Jan 30, 2015
12224c7
p2p/discover: new package implementing the Node Discovery Protocol
fjl Jan 27, 2015
739066e
p2p/discover: add some helper functions
fjl Feb 5, 2015
5bdc115
p2p: integrate p2p/discover
fjl Feb 5, 2015
8e8ec8f
cmd/peerserver: is gone
fjl Feb 5, 2015
56f777b
cmd/ethereum, cmd/mist, core, eth, javascript, xeth: fixes for new p2…
fjl Feb 5, 2015
8564eb9
p2p/discover: add node URL functions, distinguish TCP/UDP ports
fjl Feb 6, 2015
e34d134
p2p: fixes for actual connections
fjl Feb 6, 2015
2cf4fed
cmd/mist, eth, javascript, p2p: use Node URLs for peer suggestions
fjl Feb 6, 2015
028775a
cmd/ethereum, cmd/mist: add flag for discovery bootstrap nodes
fjl Feb 6, 2015
9915d3c
p2p/discover: deflake UDP tests
fjl Feb 9, 2015
f1ebad2
eth: don't warn if no BootNodes are specified
fjl Feb 9, 2015
0c7df37
crypto: add key loading functions
fjl Feb 10, 2015
a3cd218
cmd/mist, cmd/ethereum: add CLI arguments for node key
fjl Feb 10, 2015
a21b30c
eth: remove unused Ethereum sync fields
fjl Feb 10, 2015
4242b05
cmd/bootnode: new command (replaces cmd/peerserver)
fjl Feb 10, 2015
1543833
p2p/nat: new package for port mapping stuff
fjl Feb 10, 2015
d0a2e65
cmd/ethereum, cmd/mist, eth, p2p: use package p2p/nat
fjl Feb 11, 2015
82f0bd9
p2p/discover: code review fixes
fjl Feb 12, 2015
170eb3a
p2p/discover: map listening port using configured mechanism
fjl Feb 13, 2015
5110f80
p2p: improve read deadlines
fjl Feb 13, 2015
22ee366
p2p: fix goroutine leak for invalid peers
fjl Feb 13, 2015
7101f44
p2p: add I/O timeout for encrytion handshake
fjl Feb 13, 2015
5cc1256
p2p: ensure we don't dial ourself
fjl Feb 13, 2015
cf754b9
p2p/discover: fix race in ListenUDP
fjl Feb 13, 2015
fd3e106
p2p: handle disconnect before protocol handshake
fjl Feb 13, 2015
32a9c0c
p2p: bump devp2p protcol version to 3
fjl Feb 13, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions cmd/bootnode/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
48 changes: 38 additions & 10 deletions cmd/ethereum/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
package main

import (
"crypto/ecdsa"
"flag"
"fmt"
"log"
"os"
"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"
)

Expand All @@ -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
Expand Down Expand Up @@ -83,6 +86,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()
Expand All @@ -92,18 +96,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")
Expand All @@ -125,8 +123,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)
}
Expand Down
30 changes: 15 additions & 15 deletions cmd/ethereum/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -61,20 +62,19 @@ func main() {
utils.InitConfig(VmType, ConfigFile, Datadir, "ETH")

ethereum, err := eth.New(&eth.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,
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 {
Expand Down Expand Up @@ -134,7 +134,7 @@ func main() {
utils.StartWebSockets(ethereum, WsPort)
}

utils.StartEthereum(ethereum, SeedNode)
utils.StartEthereum(ethereum)

if StartJsConsole {
InitJsConsole(ethereum)
Expand Down
32 changes: 9 additions & 23 deletions cmd/mist/assets/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ ApplicationWindow {
Menu {
title: "Network"
MenuItem {
text: "Add Peer"
text: "Connect to Node"
shortcut: "Ctrl+p"
onTriggered: {
addPeerWin.visible = true
Expand Down Expand Up @@ -838,48 +838,34 @@ ApplicationWindow {
Window {
id: addPeerWin
visible: false
minimumWidth: 300
maximumWidth: 300
minimumWidth: 400
maximumWidth: 400
maximumHeight: 50
minimumHeight: 50
title: "Connect to peer"
title: "Connect to Node"

ComboBox {
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.currentText)
eth.connectToPeer(addrField.text)
addPeerWin.visible = false
}

editable: true
model: ListModel { id: pastPeers }

Component.onCompleted: {
pastPeers.insert(0, {text: "poc-8.ethdev.com:30303"})
/*
var ips = eth.pastPeers()
for(var i = 0; i < ips.length; i++) {
pastPeers.append({text: ips.get(i)})
}

pastPeers.insert(0, {text: "poc-7.ethdev.com:30303"})
*/
}
}

Button {
id: addPeerButton
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
anchors.rightMargin: 10
text: "Add"
text: "Connect"
onClicked: {
eth.connectToPeer(addrField.currentText)
eth.connectToPeer(addrField.text)
addPeerWin.visible = false
}
}
Expand Down
12 changes: 0 additions & 12 deletions cmd/mist/assets/qml/views/info.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions cmd/mist/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading