minor fixes from review

This commit is contained in:
Ethan Buchman 2017-11-20 19:30:05 +00:00
parent feb3230160
commit c4b695f78d
3 changed files with 15 additions and 8 deletions

View File

@ -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()

View File

@ -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) {

View File

@ -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)