minor fixes from review
This commit is contained in:
parent
feb3230160
commit
c4b695f78d
|
@ -191,7 +191,12 @@ func (a *AddrBook) size() int {
|
|||
return a.nNew + a.nOld
|
||||
}
|
||||
|
||||
// PickAddress picks an address to connect to with new/old bias.
|
||||
// PickAddress picks an address to connect to.
|
||||
// The address is picked randomly from an old or new bucket according
|
||||
// to the newBias argument, which must be between [0, 100] (or else is truncated to that range)
|
||||
// and determines how biased we are to pick an address from a new bucket.
|
||||
// PickAddress returns nil if the AddrBook is empty or if we try to pick
|
||||
// from an empty bucket.
|
||||
func (a *AddrBook) PickAddress(newBias int) *NetAddress {
|
||||
a.mtx.Lock()
|
||||
defer a.mtx.Unlock()
|
||||
|
|
|
@ -112,6 +112,7 @@ func TestAddrBookLookup(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAddrBookPromoteToOld(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
fname := createTempFileName("addrbook_test")
|
||||
|
||||
randAddrs := randNetAddressPairs(t, 100)
|
||||
|
@ -143,9 +144,7 @@ func TestAddrBookPromoteToOld(t *testing.T) {
|
|||
t.Errorf("selection could not be bigger than the book")
|
||||
}
|
||||
|
||||
if book.Size() != 100 {
|
||||
t.Errorf("Size is not 100. Got %v", book.Size())
|
||||
}
|
||||
assert.Equal(book.Size(), 100, "expecting book size to be 100")
|
||||
}
|
||||
|
||||
func TestAddrBookHandlesDuplicates(t *testing.T) {
|
||||
|
|
|
@ -252,10 +252,13 @@ func (r *PEXReactor) ensurePeers() {
|
|||
if try == nil {
|
||||
continue
|
||||
}
|
||||
_, alreadySelected := toDial[try.IP.String()]
|
||||
alreadyDialing := r.Switch.IsDialing(try)
|
||||
alreadyConnected := r.Switch.Peers().Has(try.IP.String())
|
||||
if alreadySelected || alreadyDialing || alreadyConnected {
|
||||
if _, selected := toDial[try.IP.String()]; selected {
|
||||
continue
|
||||
}
|
||||
if dialling := r.Switch.IsDialing(try); dialling {
|
||||
continue
|
||||
}
|
||||
if connected := r.Switch.Peers().Has(try.IP.String()); connected {
|
||||
continue
|
||||
}
|
||||
r.Logger.Info("Will dial address", "addr", try)
|
||||
|
|
Loading…
Reference in New Issue