p2p/nat: delay auto discovery until first use

Port mapper auto discovery used to run immediately after parsing the
--nat flag, giving it a slight performance boost. But this is becoming
inconvenient because we create node.Node for all geth operations
including account management and bare chain interaction. Delay
autodiscovery until the first use instead, which avoids any network
interaction until the node is actually started.
This commit is contained in:
Felix Lange 2016-09-06 00:26:54 +02:00
parent 7c12e8ea44
commit f5c432bcab
1 changed files with 1 additions and 5 deletions

View File

@ -197,11 +197,7 @@ type autodisc struct {
func startautodisc(what string, doit func() Interface) Interface { func startautodisc(what string, doit func() Interface) Interface {
// TODO: monitor network configuration and rerun doit when it changes. // TODO: monitor network configuration and rerun doit when it changes.
ad := &autodisc{what: what, doit: doit} return &autodisc{what: what, doit: doit}
// Start the auto discovery as early as possible so it is already
// in progress when the rest of the stack calls the methods.
go ad.wait()
return ad
} }
func (n *autodisc) AddMapping(protocol string, extport, intport int, name string, lifetime time.Duration) error { func (n *autodisc) AddMapping(protocol string, extport, intport int, name string, lifetime time.Duration) error {