Skip to content

Commit f1404a4

Browse files
committed
p2p server discv5 bootnodes
1 parent 49b1a18 commit f1404a4

File tree

8 files changed

+60
-2
lines changed

8 files changed

+60
-2
lines changed

cmd/bootnode/main.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func main() {
4040
nodeKeyHex = flag.String("nodekeyhex", "", "private key as hex (for testing)")
4141
natdesc = flag.String("nat", "none", "port mapping mechanism (any|none|upnp|pmp|extip:<IP>)")
4242
runv5 = flag.Bool("v5", false, "run a v5 topic discovery bootnode")
43+
v5test = flag.Bool("v5test", false, "run a v5 topic discovery test node (adds default bootnodes to form a test network)")
4344

4445
nodeKey *ecdsa.PrivateKey
4546
err error
@@ -81,9 +82,15 @@ func main() {
8182
os.Exit(0)
8283
}
8384

84-
if *runv5 {
85-
if _, err := discv5.ListenUDP(nodeKey, *listenAddr, natm, ""); err != nil {
85+
if *runv5 || *v5test {
86+
if ntab, err := discv5.ListenUDP(nodeKey, *listenAddr, natm, ""); err != nil {
8687
utils.Fatalf("%v", err)
88+
} else {
89+
if *v5test {
90+
if err := ntab.SetFallbackNodes(discv5.BootNodes); err != nil {
91+
utils.Fatalf("%v", err)
92+
}
93+
}
8794
}
8895
} else {
8996
if _, err := discover.ListenUDP(nodeKey, *listenAddr, natm, ""); err != nil {

cmd/geth/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ participating.
143143
utils.LightKDFFlag,
144144
utils.JSpathFlag,
145145
utils.ListenPortFlag,
146+
utils.ListenPortV5Flag,
146147
utils.MaxPeersFlag,
147148
utils.MaxPendingPeersFlag,
148149
utils.EtherbaseFlag,
@@ -157,6 +158,7 @@ participating.
157158
utils.NATFlag,
158159
utils.NatspecEnabledFlag,
159160
utils.NoDiscoverFlag,
161+
utils.DiscoveryV5Flag,
160162
utils.NodeKeyFileFlag,
161163
utils.NodeKeyHexFlag,
162164
utils.RPCEnabledFlag,

cmd/geth/usage.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,12 @@ var AppHelpFlagGroups = []flagGroup{
113113
Flags: []cli.Flag{
114114
utils.BootnodesFlag,
115115
utils.ListenPortFlag,
116+
utils.ListenPortV5Flag,
116117
utils.MaxPeersFlag,
117118
utils.MaxPendingPeersFlag,
118119
utils.NATFlag,
119120
utils.NoDiscoverFlag,
121+
utils.DiscoveryV5Flag,
120122
utils.NodeKeyFileFlag,
121123
utils.NodeKeyHexFlag,
122124
},

cmd/utils/flags.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ var (
345345
Usage: "Network listening port",
346346
Value: 30303,
347347
}
348+
ListenPortV5Flag = cli.IntFlag{
349+
Name: "v5port",
350+
Usage: "Experimental RLPx V5 (Topic Discovery) listening port",
351+
Value: 30304,
352+
}
348353
BootnodesFlag = cli.StringFlag{
349354
Name: "bootnodes",
350355
Usage: "Comma separated enode URLs for P2P discovery bootstrap",
@@ -367,6 +372,10 @@ var (
367372
Name: "nodiscover",
368373
Usage: "Disables the peer discovery mechanism (manual peer addition)",
369374
}
375+
DiscoveryV5Flag = cli.BoolFlag{
376+
Name: "v5disc",
377+
Usage: "Enables the experimental RLPx V5 (Topic Discovery) mechanism",
378+
}
370379
WhisperEnabledFlag = cli.BoolFlag{
371380
Name: "shh",
372381
Usage: "Enable Whisper",
@@ -510,6 +519,10 @@ func MakeListenAddress(ctx *cli.Context) string {
510519
return fmt.Sprintf(":%d", ctx.GlobalInt(ListenPortFlag.Name))
511520
}
512521

522+
func MakeListenAddressV5(ctx *cli.Context) string {
523+
return fmt.Sprintf(":%d", ctx.GlobalInt(ListenPortV5Flag.Name))
524+
}
525+
513526
// MakeNAT creates a port mapper from set command line flags.
514527
func MakeNAT(ctx *cli.Context) nat.Interface {
515528
natif, err := nat.Parse(ctx.GlobalString(NATFlag.Name))
@@ -641,8 +654,10 @@ func MakeNode(ctx *cli.Context, name, gitCommit string) *node.Node {
641654
Version: vsn,
642655
UserIdent: makeNodeUserIdent(ctx),
643656
NoDiscovery: ctx.GlobalBool(NoDiscoverFlag.Name),
657+
DiscoveryV5: ctx.GlobalBool(DiscoveryV5Flag.Name),
644658
BootstrapNodes: MakeBootstrapNodes(ctx),
645659
ListenAddr: MakeListenAddress(ctx),
660+
ListenAddrV5: MakeListenAddressV5(ctx),
646661
NAT: MakeNAT(ctx),
647662
MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name),
648663
MaxPendingPeers: ctx.GlobalInt(MaxPendingPeersFlag.Name),

node/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,16 @@ type Config struct {
9595
// or not. Disabling is usually useful for protocol debugging (manual topology).
9696
NoDiscovery bool
9797

98+
DiscoveryV5 bool
99+
98100
// Bootstrap nodes used to establish connectivity with the rest of the network.
99101
BootstrapNodes []*discover.Node
100102

101103
// Network interface address on which the node should listen for inbound peers.
102104
ListenAddr string
103105

106+
ListenAddrV5 string
107+
104108
// If set to a non-nil value, the given NAT port mapper is used to make the
105109
// listening port available to the Internet.
106110
NAT nat.Interface

node/node.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,13 @@ func (n *Node) Start() error {
157157
PrivateKey: n.config.NodeKey(),
158158
Name: n.config.NodeName(),
159159
Discovery: !n.config.NoDiscovery,
160+
DiscoveryV5: n.config.DiscoveryV5,
160161
BootstrapNodes: n.config.BootstrapNodes,
161162
StaticNodes: n.config.StaticNodes(),
162163
TrustedNodes: n.config.TrusterNodes(),
163164
NodeDatabase: n.config.NodeDB(),
164165
ListenAddr: n.config.ListenAddr,
166+
ListenAddrV5: n.config.ListenAddrV5,
165167
NAT: n.config.NAT,
166168
Dialer: n.config.Dialer,
167169
NoDial: n.config.NoDial,

p2p/discv5/net.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ func debugLog(s string) {
5858
}
5959
}
6060

61+
// BootNodes are the enode URLs of the P2P bootstrap nodes for the experimental RLPx v5 "Topic Discovery" network
62+
// warning: local bootnodes for testing!!!
63+
var BootNodes = []*Node{
64+
MustParseNode("enode://fcb7ff7a1437465711900bebc8831b6814d9f3176f3745e8549808af897ede4b51f8e32b52caf1a1c4aee90dc14f2aaeebf8b099f5d19245fd00ab160f59b9c8@127.0.0.1:30001"),
65+
MustParseNode("enode://9ec7e836e3eff84c5f51b169d8bd26a90e9c0a1c5a5b01125722fbcc7808803451fdde5c31e0fbf32fa730e11bef3a4ec35c751bd896a3db601155c1313d48a2@127.0.0.1:30002"),
66+
MustParseNode("enode://1949788c417a52653b438a33a2b08a70dc495b24c83d0ae533be13b1c7da0af0159bd0b50823fee4a1bc8f24f81e23435fe167df972256968d881f98f1eeb5de@127.0.0.1:30003"),
67+
MustParseNode("enode://2a09e932145093688ce0fe885256dfac432402a5546c5b467afe988e205bbaf1a5793f4b625638ba5ba214549965aaacf4881201a82f92bfbaf37e40e7fe7132@127.0.0.1:30004"),
68+
MustParseNode("enode://fc3d5a1696c48e02a45a78a6e94554f4292265de3c7461dd2b27ec664b09a23613c6f6be9fe7ab18f4788390abd592c272d549c583af6e92b5b8254f335d71bc@127.0.0.1:30005"),
69+
}
70+
6171
// Network manages the table and all protocol interaction.
6272
type Network struct {
6373
db *nodeDB // database of known nodes

p2p/server.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/ethereum/go-ethereum/logger"
2929
"github.com/ethereum/go-ethereum/logger/glog"
3030
"github.com/ethereum/go-ethereum/p2p/discover"
31+
"github.com/ethereum/go-ethereum/p2p/discv5"
3132
"github.com/ethereum/go-ethereum/p2p/nat"
3233
)
3334

@@ -72,6 +73,8 @@ type Config struct {
7273
// or not. Disabling is usually useful for protocol debugging (manual topology).
7374
Discovery bool
7475

76+
DiscoveryV5 bool
77+
7578
// Name sets the node name of this server.
7679
// Use common.MakeName to create a name that follows existing conventions.
7780
Name string
@@ -105,6 +108,8 @@ type Config struct {
105108
// the server is started.
106109
ListenAddr string
107110

111+
ListenAddrV5 string
112+
108113
// If set to a non-nil value, the given NAT port mapper
109114
// is used to make the listening port available to the
110115
// Internet.
@@ -352,6 +357,17 @@ func (srv *Server) Start() (err error) {
352357
srv.ntab = ntab
353358
}
354359

360+
if srv.DiscoveryV5 {
361+
ntab, err := discv5.ListenUDP(srv.PrivateKey, srv.ListenAddrV5, srv.NAT, "") //srv.NodeDatabase)
362+
if err != nil {
363+
return err
364+
}
365+
if err := ntab.SetFallbackNodes(discv5.BootNodes); err != nil {
366+
return err
367+
}
368+
//srv.ntab = ntab
369+
}
370+
355371
dynPeers := (srv.MaxPeers + 1) / 2
356372
if !srv.Discovery {
357373
dynPeers = 0

0 commit comments

Comments
 (0)