Browse Source

minor fixes from review

pull/859/head
Ethan Buchman 7 years ago
parent
commit
c4b695f78d
3 changed files with 15 additions and 8 deletions
  1. +6
    -1
      p2p/addrbook.go
  2. +2
    -3
      p2p/addrbook_test.go
  3. +7
    -4
      p2p/pex_reactor.go

+ 6
- 1
p2p/addrbook.go 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()


+ 2
- 3
p2p/addrbook_test.go 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) {


+ 7
- 4
p2p/pex_reactor.go 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)


Loading…
Cancel
Save