diff --git a/p2p/addrbook.go b/p2p/addrbook.go index 7591c3074..fee179cb1 100644 --- a/p2p/addrbook.go +++ b/p2p/addrbook.go @@ -324,6 +324,30 @@ func (a *AddrBook) GetSelection() []*NetAddress { return allAddr[:numAddresses] } +// ListOfKnownAddresses returns the new and old addresses. +func (a *AddrBook) ListOfKnownAddresses() []*knownAddress { + a.mtx.Lock() + defer a.mtx.Unlock() + + addrs := []*knownAddress{} + for _, addr := range a.addrLookup { + addrs = append(addrs, addr.copy()) + } + return addrs +} + +func (ka *knownAddress) copy() *knownAddress { + return &knownAddress{ + Addr: ka.Addr, + Src: ka.Src, + Attempts: ka.Attempts, + LastAttempt: ka.LastAttempt, + LastSuccess: ka.LastSuccess, + BucketType: ka.BucketType, + Buckets: ka.Buckets, + } +} + /* Loading & Saving */ type addrBookJSON struct {