Skip to content

Commit a390ca5

Browse files
committed
les, cmd/util: disable topic discovery with --nodiscover
1 parent 12379c6 commit a390ca5

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

cmd/utils/flags.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,10 @@ func MakeNode(ctx *cli.Context, name, gitCommit string) *node.Node {
654654
vsn += "-" + gitCommit[:8]
655655
}
656656

657+
// if we're running a light client or server, force enable the v5 peer discovery unless it is explicitly disabled with --nodiscover
658+
// note that explicitly specifying --v5disc overrides --nodiscover, in which case the later only disables v4 discovery
659+
forceV5Discovery := (ctx.GlobalBool(LightModeFlag.Name) || ctx.GlobalInt(LightServFlag.Name) > 0) && !ctx.GlobalBool(NoDiscoverFlag.Name)
660+
657661
config := &node.Config{
658662
DataDir: MakeDataDir(ctx),
659663
KeyStoreDir: ctx.GlobalString(KeyStoreDirFlag.Name),
@@ -662,8 +666,8 @@ func MakeNode(ctx *cli.Context, name, gitCommit string) *node.Node {
662666
Name: name,
663667
Version: vsn,
664668
UserIdent: makeNodeUserIdent(ctx),
665-
NoDiscovery: ctx.GlobalBool(NoDiscoverFlag.Name) || ctx.GlobalBool(LightModeFlag.Name),
666-
DiscoveryV5: ctx.GlobalBool(DiscoveryV5Flag.Name) || ctx.GlobalBool(LightModeFlag.Name) || ctx.GlobalInt(LightServFlag.Name) > 0,
669+
NoDiscovery: ctx.GlobalBool(NoDiscoverFlag.Name) || ctx.GlobalBool(LightModeFlag.Name), // always disable v4 discovery in light client mode
670+
DiscoveryV5: ctx.GlobalBool(DiscoveryV5Flag.Name) || forceV5Discovery,
667671
DiscoveryV5Addr: MakeDiscoveryV5Address(ctx),
668672
BootstrapNodes: MakeBootstrapNodes(ctx),
669673
BootstrapNodesV5: MakeBootstrapNodesV5(ctx),

les/serverpool.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,9 @@ func (pool *serverPool) selectPeerWait(reqID uint64, canSend func(*peer) (bool,
348348
func (pool *serverPool) eventLoop() {
349349
lookupCnt := 0
350350
var convTime mclock.AbsTime
351-
pool.discSetPeriod <- time.Millisecond * 100
351+
if pool.discSetPeriod != nil {
352+
pool.discSetPeriod <- time.Millisecond * 100
353+
}
352354
for {
353355
select {
354356
case entry := <-pool.timeout:
@@ -393,12 +395,16 @@ func (pool *serverPool) eventLoop() {
393395
lookupCnt++
394396
if pool.fastDiscover && (lookupCnt == 50 || time.Duration(mclock.Now()-convTime) > time.Minute) {
395397
pool.fastDiscover = false
396-
pool.discSetPeriod <- time.Minute
398+
if pool.discSetPeriod != nil {
399+
pool.discSetPeriod <- time.Minute
400+
}
397401
}
398402
}
399403

400404
case <-pool.quit:
401-
close(pool.discSetPeriod)
405+
if pool.discSetPeriod != nil {
406+
close(pool.discSetPeriod)
407+
}
402408
pool.connWg.Wait()
403409
pool.saveNodes()
404410
pool.wg.Done()

0 commit comments

Comments
 (0)