@ -15,7 +15,6 @@ import (
"time"
"time"
. "github.com/tendermint/go-common"
. "github.com/tendermint/go-common"
"github.com/tendermint/go-crypto"
)
)
const (
const (
@ -86,7 +85,6 @@ type AddrBook struct {
addrLookup map [ string ] * knownAddress // new & old
addrLookup map [ string ] * knownAddress // new & old
addrNew [ ] map [ string ] * knownAddress
addrNew [ ] map [ string ] * knownAddress
addrOld [ ] map [ string ] * knownAddress
addrOld [ ] map [ string ] * knownAddress
wg sync . WaitGroup
nOld int
nOld int
nNew int
nNew int
}
}
@ -128,7 +126,6 @@ func (a *AddrBook) init() {
func ( a * AddrBook ) OnStart ( ) error {
func ( a * AddrBook ) OnStart ( ) error {
a . BaseService . OnStart ( )
a . BaseService . OnStart ( )
a . loadFromFile ( a . filePath )
a . loadFromFile ( a . filePath )
a . wg . Add ( 1 )
go a . saveRoutine ( )
go a . saveRoutine ( )
return nil
return nil
}
}
@ -139,6 +136,7 @@ func (a *AddrBook) OnStop() {
func ( a * AddrBook ) Wait ( ) {
func ( a * AddrBook ) Wait ( ) {
a . wg . Wait ( )
a . wg . Wait ( )
a . saveToFile ( a . filePath )
}
}
func ( a * AddrBook ) AddOurAddress ( addr * NetAddress ) {
func ( a * AddrBook ) AddOurAddress ( addr * NetAddress ) {
@ -309,6 +307,8 @@ type addrBookJSON struct {
}
}
func ( a * AddrBook ) saveToFile ( filePath string ) {
func ( a * AddrBook ) saveToFile ( filePath string ) {
log . Info ( "Saving AddrBook to file" , "size" , a . Size ( ) )
// Compile Addrs
// Compile Addrs
addrs := [ ] * knownAddress { }
addrs := [ ] * knownAddress { }
for _ , ka := range a . addrLookup {
for _ , ka := range a . addrLookup {
@ -386,7 +386,6 @@ out:
for {
for {
select {
select {
case <- dumpAddressTicker . C :
case <- dumpAddressTicker . C :
log . Info ( "Saving AddrBook to file" , "size" , a . Size ( ) )
a . saveToFile ( a . filePath )
a . saveToFile ( a . filePath )
case <- a . Quit :
case <- a . Quit :
break out
break out
@ -394,7 +393,6 @@ out:
}
}
dumpAddressTicker . Stop ( )
dumpAddressTicker . Stop ( )
a . saveToFile ( a . filePath )
a . saveToFile ( a . filePath )
a . wg . Done ( )
log . Notice ( "Address handler done" )
log . Notice ( "Address handler done" )
}
}