From 8f3bd3f2095b32f1e8fdac8044995303d9f590d4 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Tue, 23 Jan 2018 22:25:39 -0500 Subject: [PATCH] p2p: addrBook.Save() on DialPeersAsync --- p2p/pex/addrbook.go | 9 +++++++++ p2p/switch.go | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/p2p/pex/addrbook.go b/p2p/pex/addrbook.go index b7f60682d..3a3be6e44 100644 --- a/p2p/pex/addrbook.go +++ b/p2p/pex/addrbook.go @@ -27,6 +27,7 @@ const ( // AddrBook is an address book used for tracking peers // so we can gossip about them to others and select // peers to dial. +// TODO: break this up? type AddrBook interface { cmn.Service @@ -53,6 +54,9 @@ type AddrBook interface { // TODO: remove ListOfKnownAddresses() []*knownAddress + + // Persist to disk + Save() } var _ AddrBook = (*addrBook)(nil) @@ -314,6 +318,11 @@ func (a *addrBook) size() int { //---------------------------------------------------------- +// Save persists the address book to disk. +func (a *addrBook) Save() { + a.saveToFile(a.filePath) // thread safe +} + func (a *addrBook) saveRoutine() { defer a.wg.Done() diff --git a/p2p/switch.go b/p2p/switch.go index fb9a6ac25..7b09279ce 100644 --- a/p2p/switch.go +++ b/p2p/switch.go @@ -35,6 +35,7 @@ const ( type AddrBook interface { AddAddress(addr *NetAddress, src *NetAddress) error + Save() } //----------------------------------------------------------------------------- @@ -337,6 +338,9 @@ func (sw *Switch) DialPeersAsync(addrBook AddrBook, peers []string, persistent b // TODO: move this out of here ? addrBook.AddAddress(netAddr, ourAddr) } + // Persist some peers to disk right away. + // NOTE: integration tests depend on this + addrBook.Save() } // permute the list, dial them in random order.