diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-04-23 23:47:24 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-04-24 16:23:20 +0800 |
commit | 5f735d6fce10b4552b0a6d3eb6503c5a302f4f61 (patch) | |
tree | 781d93a4c91ac664b95d97b96d3ac6605bfbb57c /p2p/discover/table.go | |
parent | 936c8e19ff3db376fdd1ed53772c51c817a72112 (diff) | |
download | dexon-5f735d6fce10b4552b0a6d3eb6503c5a302f4f61.tar.gz dexon-5f735d6fce10b4552b0a6d3eb6503c5a302f4f61.tar.zst dexon-5f735d6fce10b4552b0a6d3eb6503c5a302f4f61.zip |
cmd, eth, p2p, p2p/discover: init and clean up the seed cache
Diffstat (limited to 'p2p/discover/table.go')
-rw-r--r-- | p2p/discover/table.go | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/p2p/discover/table.go b/p2p/discover/table.go index ba2f9b8ec..3702a2114 100644 --- a/p2p/discover/table.go +++ b/p2p/discover/table.go @@ -11,6 +11,9 @@ import ( "sort" "sync" "time" + + "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/logger/glog" ) const ( @@ -58,8 +61,14 @@ type bucket struct { entries []*Node } -func newTable(t transport, ourID NodeID, ourAddr *net.UDPAddr) *Table { - db, _ := newNodeDB("", Version) +func newTable(t transport, ourID NodeID, ourAddr *net.UDPAddr, seedCache string) *Table { + // Load the bootstrap seed cache (use in memory db upon failure) + db, err := newNodeDB(seedCache, Version) + if err != nil { + glog.V(logger.Warn).Infoln("Failed to open bootstrap seed cache:", err) + db, _ = newNodeDB("", Version) + } + // Create the bootstrap table tab := &Table{ net: t, db: db, @@ -81,9 +90,10 @@ func (tab *Table) Self() *Node { return tab.self } -// Close terminates the network listener. +// Close terminates the network listener and flushes the seed cache. func (tab *Table) Close() { tab.net.close() + tab.db.close() } // Bootstrap sets the bootstrap nodes. These nodes are used to connect |