aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorZsolt Felfoldi <zsfelfoldi@gmail.com>2016-10-19 19:04:55 +0800
committerFelix Lange <fjl@twurst.com>2016-11-09 09:12:53 +0800
commit49da42983af7a775695166689e5bf701bcec4f81 (patch)
tree2c325a4852695697cc9616a3eac99a432711abdb /cmd
parent7db7109a5b53c339f00e9c05ac826b3dbd1f98e1 (diff)
downloadgo-tangerine-49da42983af7a775695166689e5bf701bcec4f81.tar
go-tangerine-49da42983af7a775695166689e5bf701bcec4f81.tar.gz
go-tangerine-49da42983af7a775695166689e5bf701bcec4f81.tar.bz2
go-tangerine-49da42983af7a775695166689e5bf701bcec4f81.tar.lz
go-tangerine-49da42983af7a775695166689e5bf701bcec4f81.tar.xz
go-tangerine-49da42983af7a775695166689e5bf701bcec4f81.tar.zst
go-tangerine-49da42983af7a775695166689e5bf701bcec4f81.zip
p2p/discv5: added new topic discovery package
Diffstat (limited to 'cmd')
-rw-r--r--cmd/bootnode/main.go13
-rw-r--r--cmd/geth/main.go29
-rw-r--r--cmd/geth/usage.go2
-rw-r--r--cmd/utils/flags.go17
-rw-r--r--cmd/v5test/main.go101
5 files changed, 125 insertions, 37 deletions
diff --git a/cmd/bootnode/main.go b/cmd/bootnode/main.go
index 40d3cdc17..abecac3d8 100644
--- a/cmd/bootnode/main.go
+++ b/cmd/bootnode/main.go
@@ -27,6 +27,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/p2p/discover"
+ "github.com/ethereum/go-ethereum/p2p/discv5"
"github.com/ethereum/go-ethereum/p2p/nat"
)
@@ -38,6 +39,7 @@ func main() {
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>)")
+ runv5 = flag.Bool("v5", false, "run a v5 topic discovery bootnode")
nodeKey *ecdsa.PrivateKey
err error
@@ -79,8 +81,15 @@ func main() {
os.Exit(0)
}
- if _, err := discover.ListenUDP(nodeKey, *listenAddr, natm, ""); err != nil {
- utils.Fatalf("%v", err)
+ if *runv5 {
+ if _, err := discv5.ListenUDP(nodeKey, *listenAddr, natm, ""); err != nil {
+ utils.Fatalf("%v", err)
+ }
+ } else {
+ if _, err := discover.ListenUDP(nodeKey, *listenAddr, natm, ""); err != nil {
+ utils.Fatalf("%v", err)
+ }
}
+
select {}
}
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index 75abdc813..557bf57fa 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -41,7 +41,6 @@ import (
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/node"
- "github.com/ethereum/go-ethereum/p2p/discover"
"gopkg.in/urfave/cli.v1"
)
@@ -120,11 +119,9 @@ participating.
utils.OlympicFlag,
utils.FastSyncFlag,
utils.LightModeFlag,
- utils.NoDefSrvFlag,
utils.LightServFlag,
utils.LightPeersFlag,
utils.LightKDFFlag,
- utils.CacheFlag,
utils.TrieCacheGenFlag,
utils.JSpathFlag,
utils.ListenPortFlag,
@@ -141,6 +138,7 @@ participating.
utils.NATFlag,
utils.NatspecEnabledFlag,
utils.NoDiscoverFlag,
+ utils.DiscoveryV5Flag,
utils.NodeKeyFileFlag,
utils.NodeKeyHexFlag,
utils.RPCEnabledFlag,
@@ -285,31 +283,6 @@ func startNode(ctx *cli.Context, stack *node.Node) {
// Start up the node itself
utils.StartNode(stack)
- if ctx.GlobalBool(utils.LightModeFlag.Name) && !ctx.GlobalBool(utils.NoDefSrvFlag.Name) {
- // add default light server; test phase only
- addPeer := func(url string) {
- node, err := discover.ParseNode(url)
- if err == nil {
- stack.Server().AddPeer(node)
- }
- }
-
- if ctx.GlobalBool(utils.TestNetFlag.Name) {
- // TestNet (John Gerryts @phonikg)
- addPeer("enode://d72af45ba9b60851a8077a4eb07700484b585e5f2e55024e0c93b7ec7d114f2e3fa3c8f3a3358f89da00a609f5a062415deb857ada863b8cdad02b0b0bc90da3@50.112.52.169:30301")
- } else {
- if ctx.GlobalBool(utils.OpposeDAOFork.Name) {
- // Classic (Azure)
- addPeer("enode://fc3d7b57e5d317946bf421411632ec98d5ffcbf94548cd7bc10088e4fef176670f8ec70280d301a9d0b22fe498203f62b323da15b3acc18b02a1fee2a06b7d3f@40.118.3.223:30305")
- } else {
- // MainNet (Azure)
- addPeer("enode://feaf206a308a669a789be45f4dadcb351246051727f12415ad69e44f8080daf0569c10fe1d9944d245dd1f3e1c89cedda8ce03d7e3d5ed8975a35cad4b4f7ec1@40.118.3.223:30303")
- // MainNet (John Gerryts @phonikg)
- addPeer("enode://02b80f0d47c7c157c069d0584067a284cdf188b9267666234b872e70d936a803ad20ea27f78ef1fd6425ae4b7108907e1875adbca96b038004114ac4d1e529a3@50.112.52.169:30300")
- }
- }
- }
-
// Unlock any account specifically requested
accman := stack.AccountManager()
passwords := utils.MakePasswordList(ctx)
diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go
index 75560d017..e4abf6b30 100644
--- a/cmd/geth/usage.go
+++ b/cmd/geth/usage.go
@@ -73,7 +73,6 @@ var AppHelpFlagGroups = []flagGroup{
utils.IdentityFlag,
utils.FastSyncFlag,
utils.LightModeFlag,
- utils.NoDefSrvFlag,
utils.LightServFlag,
utils.LightPeersFlag,
utils.LightKDFFlag,
@@ -123,6 +122,7 @@ var AppHelpFlagGroups = []flagGroup{
utils.MaxPendingPeersFlag,
utils.NATFlag,
utils.NoDiscoverFlag,
+ utils.DiscoveryV5Flag,
utils.NodeKeyFileFlag,
utils.NodeKeyHexFlag,
},
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 40d96a3b5..626c2615d 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -151,10 +151,6 @@ var (
Name: "light",
Usage: "Enable light client mode",
}
- NoDefSrvFlag = cli.BoolFlag{
- Name: "nodefsrv",
- Usage: "Don't add default LES server (only for test version)",
- }
LightServFlag = cli.IntFlag{
Name: "lightserv",
Usage: "Maximum percentage of time allowed for serving LES requests (0-90)",
@@ -368,6 +364,10 @@ var (
Name: "nodiscover",
Usage: "Disables the peer discovery mechanism (manual peer addition)",
}
+ DiscoveryV5Flag = cli.BoolFlag{
+ Name: "v5disc",
+ Usage: "Enables the experimental RLPx V5 (Topic Discovery) mechanism",
+ }
WhisperEnabledFlag = cli.BoolFlag{
Name: "shh",
Usage: "Enable Whisper",
@@ -511,6 +511,10 @@ func MakeListenAddress(ctx *cli.Context) string {
return fmt.Sprintf(":%d", ctx.GlobalInt(ListenPortFlag.Name))
}
+func MakeListenAddressV5(ctx *cli.Context) string {
+ return fmt.Sprintf(":%d", ctx.GlobalInt(ListenPortFlag.Name)+1)
+}
+
// MakeNAT creates a port mapper from set command line flags.
func MakeNAT(ctx *cli.Context) nat.Interface {
natif, err := nat.Parse(ctx.GlobalString(NATFlag.Name))
@@ -641,9 +645,11 @@ func MakeNode(ctx *cli.Context, name, gitCommit string) *node.Node {
Name: name,
Version: vsn,
UserIdent: makeNodeUserIdent(ctx),
- NoDiscovery: ctx.GlobalBool(NoDiscoverFlag.Name),
+ NoDiscovery: ctx.GlobalBool(NoDiscoverFlag.Name) || ctx.GlobalBool(LightModeFlag.Name),
+ DiscoveryV5: ctx.GlobalBool(DiscoveryV5Flag.Name) || ctx.GlobalBool(LightModeFlag.Name) || ctx.GlobalInt(LightServFlag.Name) > 0,
BootstrapNodes: MakeBootstrapNodes(ctx),
ListenAddr: MakeListenAddress(ctx),
+ ListenAddrV5: MakeListenAddressV5(ctx),
NAT: MakeNAT(ctx),
MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name),
MaxPendingPeers: ctx.GlobalInt(MaxPendingPeersFlag.Name),
@@ -701,7 +707,6 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) {
ChainConfig: MakeChainConfig(ctx, stack),
FastSync: ctx.GlobalBool(FastSyncFlag.Name),
LightMode: ctx.GlobalBool(LightModeFlag.Name),
- NoDefSrv: ctx.GlobalBool(NoDefSrvFlag.Name),
LightServ: ctx.GlobalInt(LightServFlag.Name),
LightPeers: ctx.GlobalInt(LightPeersFlag.Name),
MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name),
diff --git a/cmd/v5test/main.go b/cmd/v5test/main.go
new file mode 100644
index 000000000..e537760c6
--- /dev/null
+++ b/cmd/v5test/main.go
@@ -0,0 +1,101 @@
+// Copyright 2015 The go-ethereum Authors
+// 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/>.
+
+// bootnode runs a bootstrap node for the Ethereum Discovery Protocol.
+package main
+
+import (
+ "flag"
+ "fmt"
+ "math/rand"
+ "strconv"
+ "time"
+
+ "github.com/ethereum/go-ethereum/cmd/utils"
+ "github.com/ethereum/go-ethereum/crypto"
+ "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/p2p/discv5"
+ "github.com/ethereum/go-ethereum/p2p/nat"
+)
+
+func main() {
+ var (
+ listenPort = flag.Int("addr", 31000, "beginning of listening port range")
+ natdesc = flag.String("nat", "none", "port mapping mechanism (any|none|upnp|pmp|extip:<IP>)")
+ count = flag.Int("count", 1, "number of v5 topic discovery test nodes (adds default bootnodes to form a test network)")
+ regtopic = flag.String("reg", "", "topic to register on the network")
+ looktopic = flag.String("search", "", "topic to search on the network")
+ )
+ flag.Var(glog.GetVerbosity(), "verbosity", "log verbosity (0-9)")
+ flag.Var(glog.GetVModule(), "vmodule", "log verbosity pattern")
+ glog.SetToStderr(true)
+ flag.Parse()
+
+ natm, err := nat.Parse(*natdesc)
+ if err != nil {
+ utils.Fatalf("-nat: %v", err)
+ }
+
+ for i := 0; i < *count; i++ {
+ listenAddr := ":" + strconv.Itoa(*listenPort+i)
+
+ nodeKey, err := crypto.GenerateKey()
+ if err != nil {
+ utils.Fatalf("could not generate key: %v", err)
+ }
+
+ if net, err := discv5.ListenUDP(nodeKey, listenAddr, natm, ""); err != nil {
+ utils.Fatalf("%v", err)
+ } else {
+ if err := net.SetFallbackNodes(discv5.BootNodes); err != nil {
+ utils.Fatalf("%v", err)
+ }
+ go func() {
+ if *looktopic == "" {
+ for i := 0; i < 20; i++ {
+ time.Sleep(time.Millisecond * time.Duration(2000+rand.Intn(2001)))
+ net.BucketFill()
+ }
+ }
+ switch {
+ case *regtopic != "":
+ // register topic
+ fmt.Println("Starting topic register")
+ stop := make(chan struct{})
+ net.RegisterTopic(discv5.Topic(*regtopic), stop)
+ case *looktopic != "":
+ // search topic
+ fmt.Println("Starting topic search")
+ stop := make(chan struct{})
+ found := make(chan string, 100)
+ go net.SearchTopic(discv5.Topic(*looktopic), stop, found)
+ for s := range found {
+ fmt.Println(time.Now(), s)
+ }
+ default:
+ // just keep doing lookups
+ for {
+ time.Sleep(time.Millisecond * time.Duration(40000+rand.Intn(40001)))
+ net.BucketFill()
+ }
+ }
+ }()
+ }
+ fmt.Printf("Started test node #%d with public key %v\n", i, discv5.PubkeyID(&nodeKey.PublicKey))
+ }
+
+ select {}
+}