cmd/bootnode, eth, p2p, p2p/discover: clean up the seeder and mesh into eth.

This commit is contained in:
Péter Szilágyi
2015-04-24 11:19:33 +03:00
parent 971702e7a1
commit 6def110c37
9 changed files with 168 additions and 144 deletions

View File

@ -125,6 +125,8 @@ type Ethereum struct {
blockDb common.Database // Block chain database
stateDb common.Database // State changes database
extraDb common.Database // Extra database (txs, etc)
seedDb *discover.Cache // Peer database seeding the bootstrap
// Closed when databases are flushed and closed
databasesClosed chan bool
@ -179,7 +181,10 @@ func New(config *Config) (*Ethereum, error) {
if err != nil {
return nil, err
}
seedDbPath := path.Join(config.DataDir, "seeds")
seedDb, err := discover.NewPersistentCache(path.Join(config.DataDir, "seeds"))
if err != nil {
return nil, err
}
// Perform database sanity checks
d, _ := blockDb.Get([]byte("ProtocolVersion"))
@ -207,6 +212,7 @@ func New(config *Config) (*Ethereum, error) {
blockDb: blockDb,
stateDb: stateDb,
extraDb: extraDb,
seedDb: seedDb,
eventMux: &event.TypeMux{},
accountManager: config.AccountManager,
DataDir: config.DataDir,
@ -244,7 +250,7 @@ func New(config *Config) (*Ethereum, error) {
NAT: config.NAT,
NoDial: !config.Dial,
BootstrapNodes: config.parseBootNodes(),
SeedCache: seedDbPath,
SeedCache: seedDb,
}
if len(config.Port) > 0 {
eth.net.ListenAddr = ":" + config.Port
@ -423,6 +429,7 @@ done:
}
}
s.seedDb.Close()
s.blockDb.Close()
s.stateDb.Close()
s.extraDb.Close()
@ -450,7 +457,7 @@ func (self *Ethereum) SuggestPeer(nodeURL string) error {
}
func (s *Ethereum) Stop() {
s.txSub.Unsubscribe() // quits txBroadcastLoop
s.txSub.Unsubscribe() // quits txBroadcastLoop
s.protocolManager.Stop()
s.txPool.Stop()