Browse Source

return wg to addrbook

pull/456/head
Anton Kaliaev 8 years ago
parent
commit
4c0d1d3ad2
No known key found for this signature in database GPG Key ID: 7B6881D965918214
1 changed files with 16 additions and 10 deletions
  1. +16
    -10
      addrbook.go

+ 16
- 10
addrbook.go View File

@ -73,7 +73,12 @@ const (
serializationVersion = 1
)
/* AddrBook - concurrency safe peer address manager */
const (
bucketTypeNew = 0x01
bucketTypeOld = 0x02
)
// AddrBook - concurrency safe peer address manager.
type AddrBook struct {
BaseService
@ -86,15 +91,12 @@ type AddrBook struct {
addrLookup map[string]*knownAddress // new & old
addrNew []map[string]*knownAddress
addrOld []map[string]*knownAddress
wg sync.WaitGroup
nOld int
nNew int
}
const (
bucketTypeNew = 0x01
bucketTypeOld = 0x02
)
// NewAddrBook creates a new address book.
// Use Start to begin processing asynchronous address updates.
func NewAddrBook(filePath string, routabilityStrict bool) *AddrBook {
am := &AddrBook{
@ -124,19 +126,22 @@ func (a *AddrBook) init() {
}
}
// OnStart implements Service.
func (a *AddrBook) OnStart() error {
a.BaseService.OnStart()
a.loadFromFile(a.filePath)
a.wg.Add(1)
go a.saveRoutine()
return nil
}
func (a *AddrBook) OnStop() {
a.BaseService.OnStop()
func (a *AddrBook) Wait() {
a.wg.Wait()
}
func (a *AddrBook) Wait() {
a.saveToFile(a.filePath)
// OnStop implements Service.
func (a *AddrBook) OnStop() {
a.BaseService.OnStop()
}
func (a *AddrBook) AddOurAddress(addr *NetAddress) {
@ -399,6 +404,7 @@ out:
}
dumpAddressTicker.Stop()
a.saveToFile(a.filePath)
a.wg.Done()
log.Notice("Address handler done")
}


Loading…
Cancel
Save