p2p: use discovery by default

This makes the zero Config slightly more useful. It also fixes package
node tests because Node detects reuse of the datadir through the
NodeDatabase.
This commit is contained in:
Felix Lange 2017-04-11 01:18:26 +02:00
parent 075642f105
commit 0df01af538
5 changed files with 11 additions and 16 deletions

View file

@ -57,10 +57,7 @@ var defaultNodeConfig = node.Config{
Name: clientIdentifier, Name: clientIdentifier,
Version: params.VersionWithCommit(gitCommit), Version: params.VersionWithCommit(gitCommit),
DataDir: node.DefaultDataDir(), DataDir: node.DefaultDataDir(),
P2P: p2p.Config{ P2P: p2p.Config{MaxPeers: 25},
MaxPeers: 25,
Discovery: true,
},
HTTPModules: []string{"eth", "net", "web3"}, HTTPModules: []string{"eth", "net", "web3"},
WSModules: []string{"eth", "net", "web3"}, WSModules: []string{"eth", "net", "web3"},
} }

View file

@ -695,7 +695,7 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
cfg.MaxPendingPeers = ctx.GlobalInt(MaxPendingPeersFlag.Name) cfg.MaxPendingPeers = ctx.GlobalInt(MaxPendingPeersFlag.Name)
} }
if ctx.GlobalIsSet(NoDiscoverFlag.Name) || ctx.GlobalBool(LightModeFlag.Name) { if ctx.GlobalIsSet(NoDiscoverFlag.Name) || ctx.GlobalBool(LightModeFlag.Name) {
cfg.Discovery = false cfg.NoDiscovery = true
} }
// if we're running a light client or server, force enable the v5 peer discovery // if we're running a light client or server, force enable the v5 peer discovery
@ -720,7 +720,7 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
// --dev mode can't use p2p networking. // --dev mode can't use p2p networking.
cfg.MaxPeers = 0 cfg.MaxPeers = 0
cfg.ListenAddr = ":0" cfg.ListenAddr = ":0"
cfg.Discovery = false cfg.NoDiscovery = true
cfg.DiscoveryV5 = false cfg.DiscoveryV5 = false
} }
} }

View file

@ -257,7 +257,6 @@ func initialize() {
Config: p2p.Config{ Config: p2p.Config{
PrivateKey: nodeid, PrivateKey: nodeid,
MaxPeers: maxPeers, MaxPeers: maxPeers,
Discovery: true,
Name: common.MakeName("wnode", "5.0"), Name: common.MakeName("wnode", "5.0"),
Protocols: shh.Protocols(), Protocols: shh.Protocols(),
ListenAddr: *argIP, ListenAddr: *argIP,

View file

@ -115,7 +115,6 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) {
DataDir: datadir, DataDir: datadir,
KeyStoreDir: filepath.Join(datadir, "keystore"), // Mobile should never use internal keystores! KeyStoreDir: filepath.Join(datadir, "keystore"), // Mobile should never use internal keystores!
P2P: p2p.Config{ P2P: p2p.Config{
Discovery: true,
DiscoveryV5: true, DiscoveryV5: true,
DiscoveryV5Addr: ":0", DiscoveryV5Addr: ":0",
BootstrapNodesV5: config.BootstrapNodes.nodes, BootstrapNodesV5: config.BootstrapNodes.nodes,

View file

@ -69,9 +69,9 @@ type Config struct {
// Zero defaults to preset values. // Zero defaults to preset values.
MaxPendingPeers int `toml:",omitempty"` MaxPendingPeers int `toml:",omitempty"`
// Discovery specifies whether the peer discovery mechanism should be started // NoDiscowery can be used to disable the peer discovery mechanism.
// or not. Disabling is usually useful for protocol debugging (manual topology). // Disabling is useful for protocol debugging (manual topology).
Discovery bool NoDiscovery bool
// DiscoveryV5 specifies whether the the new topic-discovery based V5 discovery // DiscoveryV5 specifies whether the the new topic-discovery based V5 discovery
// protocol should be started or not. // protocol should be started or not.
@ -370,7 +370,7 @@ func (srv *Server) Start() (err error) {
srv.peerOpDone = make(chan struct{}) srv.peerOpDone = make(chan struct{})
// node table // node table
if srv.Discovery { if !srv.NoDiscovery {
ntab, err := discover.ListenUDP(srv.PrivateKey, srv.ListenAddr, srv.NAT, srv.NodeDatabase, srv.NetRestrict) ntab, err := discover.ListenUDP(srv.PrivateKey, srv.ListenAddr, srv.NAT, srv.NodeDatabase, srv.NetRestrict)
if err != nil { if err != nil {
return err return err
@ -393,7 +393,7 @@ func (srv *Server) Start() (err error) {
} }
dynPeers := (srv.MaxPeers + 1) / 2 dynPeers := (srv.MaxPeers + 1) / 2
if !srv.Discovery { if srv.NoDiscovery {
dynPeers = 0 dynPeers = 0
} }
dialer := newDialState(srv.StaticNodes, srv.BootstrapNodes, srv.ntab, dynPeers, srv.NetRestrict) dialer := newDialState(srv.StaticNodes, srv.BootstrapNodes, srv.ntab, dynPeers, srv.NetRestrict)