Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
fix: address lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Jul 16, 2021
1 parent 64eadc3 commit f01fdfd
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 35 deletions.
7 changes: 1 addition & 6 deletions addr/sorting.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ func (al AddrList) Less(i, j int) bool {
fda := isFDCostlyTransport(a)
fdb := isFDCostlyTransport(b)
if !fda {
if fdb {
return true
}

// if neither consume fd's, assume equal ordering
return false
return fdb
}

// if 'b' doesnt take a file descriptor
Expand Down
14 changes: 5 additions & 9 deletions metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ func TestLatencyEWMAFun(t *testing.T) {
}

for {
select {
case <-time.After(200 * time.Millisecond):
m.RecordLatency(id, next())
print()
}
time.Sleep(200 * time.Millisecond)
m.RecordLatency(id, next())
print()
}
}

Expand All @@ -55,10 +53,8 @@ func TestLatencyEWMA(t *testing.T) {
}

for i := 0; i < 10; i++ {
select {
case <-time.After(200 * time.Millisecond):
m.RecordLatency(id, next())
}
time.Sleep(200 * time.Millisecond)
m.RecordLatency(id, next())
}

lat := m.LatencyEWMA(id)
Expand Down
1 change: 1 addition & 0 deletions pstoreds/ds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func badgerStore(tb testing.TB) (ds.Batching, func()) {
return store, closer
}

//lint:ignore U1000 disabled for now
func leveldbStore(tb testing.TB) (ds.TxnDatastore, func()) {
dataPath, err := ioutil.TempDir(os.TempDir(), "leveldb")
if err != nil {
Expand Down
30 changes: 12 additions & 18 deletions pstoremem/addr_book.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewAddrBook() *memoryAddrBook {

ab := &memoryAddrBook{
segments: func() (ret addrSegments) {
for i, _ := range ret {
for i := range ret {
ret[i] = &addrSegment{
addrs: make(map[peer.ID]map[string]*expiringAddr),
signedPeerRecords: make(map[peer.ID]*peerRecordState)}
Expand Down Expand Up @@ -136,7 +136,7 @@ func (mab *memoryAddrBook) PeersWithAddrs() peer.IDSlice {
for _, s := range mab.segments {
s.RLock()
for pid, amap := range s.addrs {
if amap != nil && len(amap) > 0 {
if len(amap) > 0 {
pidSet.Add(pid)
}
}
Expand Down Expand Up @@ -196,7 +196,7 @@ func (mab *memoryAddrBook) ConsumePeerRecord(recordEnvelope *record.Envelope, tt

func (mab *memoryAddrBook) addAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Duration) {
if err := p.Validate(); err != nil {
log.Warningf("tried to set addrs for invalid peer ID %s: %s", p, err)
log.Warnw("tried to set addrs for invalid peer ID", "peer", p, "error", err)
return
}

Expand All @@ -223,7 +223,7 @@ func (mab *memoryAddrBook) addAddrsUnlocked(s *addrSegment, p peer.ID, addrs []m
addrSet := make(map[string]struct{}, len(addrs))
for _, addr := range addrs {
if addr == nil {
log.Warnf("was passed nil multiaddr for %s", p)
log.Warnw("was passed nil multiaddr", "peer", p)
continue
}
k := string(addr.Bytes())
Expand Down Expand Up @@ -253,7 +253,7 @@ func (mab *memoryAddrBook) addAddrsUnlocked(s *addrSegment, p peer.ID, addrs []m
// SetAddr calls mgr.SetAddrs(p, addr, ttl)
func (mab *memoryAddrBook) SetAddr(p peer.ID, addr ma.Multiaddr, ttl time.Duration) {
if err := p.Validate(); err != nil {
log.Warningf("tried to set addrs for invalid peer ID %s: %s", p, err)
log.Warnw("tried to set addrs for invalid peer ID", "peer", p, "error", err)
return
}

Expand All @@ -264,7 +264,7 @@ func (mab *memoryAddrBook) SetAddr(p peer.ID, addr ma.Multiaddr, ttl time.Durati
// This is used when we receive the best estimate of the validity of an address.
func (mab *memoryAddrBook) SetAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Duration) {
if err := p.Validate(); err != nil {
log.Warningf("tried to set addrs for invalid peer ID %s: %s", p, err)
log.Warnw("tried to set addrs for invalid peer ID", "peer", p, "error", err)
return
}

Expand All @@ -281,7 +281,7 @@ func (mab *memoryAddrBook) SetAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Du
exp := time.Now().Add(ttl)
for _, addr := range addrs {
if addr == nil {
log.Warnf("was passed nil multiaddr for %s", p)
log.Warnw("was passed nil multiaddr", "peer", p)
continue
}
aBytes := addr.Bytes()
Expand All @@ -306,7 +306,7 @@ func (mab *memoryAddrBook) SetAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Du
// the given oldTTL to have the given newTTL.
func (mab *memoryAddrBook) UpdateAddrs(p peer.ID, oldTTL time.Duration, newTTL time.Duration) {
if err := p.Validate(); err != nil {
log.Warningf("tried to set addrs for invalid peer ID %s: %s", p, err)
log.Warnw("tried to set addrs for invalid peer ID", "peer", p, "error", err)
return
}

Expand Down Expand Up @@ -412,7 +412,7 @@ func (mab *memoryAddrBook) ClearAddrs(p peer.ID) {
// given peer ID will be published.
func (mab *memoryAddrBook) AddrStream(ctx context.Context, p peer.ID) <-chan ma.Multiaddr {
if err := p.Validate(); err != nil {
log.Warningf("tried to get addrs for invalid peer ID %s: %s", p, err)
log.Warnw("tried to set addrs for invalid peer ID", "peer", p, "error", err)
ch := make(chan ma.Multiaddr)
close(ch)
return ch
Expand All @@ -432,10 +432,8 @@ func (mab *memoryAddrBook) AddrStream(ctx context.Context, p peer.ID) <-chan ma.
}

type addrSub struct {
pubch chan ma.Multiaddr
lk sync.Mutex
buffer []ma.Multiaddr
ctx context.Context
pubch chan ma.Multiaddr
ctx context.Context
}

func (s *addrSub) pubAddr(a ma.Multiaddr) {
Expand Down Expand Up @@ -503,11 +501,7 @@ func (mgr *AddrSubManager) AddrStream(ctx context.Context, p peer.ID, initial []
out := make(chan ma.Multiaddr)

mgr.mu.Lock()
if _, ok := mgr.subs[p]; ok {
mgr.subs[p] = append(mgr.subs[p], sub)
} else {
mgr.subs[p] = []*addrSub{sub}
}
mgr.subs[p] = append(mgr.subs[p], sub)
mgr.mu.Unlock()

sort.Sort(addr.AddrList(initial))
Expand Down
2 changes: 1 addition & 1 deletion test/addr_book_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func testAddAddress(ab pstore.AddrBook) func(*testing.T) {
// 1 second left
ab.AddAddrs(id, addrs, 3*time.Second)
// 3 seconds left
time.Sleep(2)
time.Sleep(2 * time.Second)
// 1 seconds left.

// We still have the address.
Expand Down
2 changes: 1 addition & 1 deletion test/benchmarks_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func benchmarkAddGetAndClearAddrs(ps pstore.Peerstore, addrs chan *peerpair) fun
func benchmarkGet1000PeersWithAddrs(ps pstore.Peerstore, addrs chan *peerpair) func(*testing.B) {
return func(b *testing.B) {
var peers = make([]*peerpair, 1000)
for i, _ := range peers {
for i := range peers {
pp := <-addrs
ps.AddAddrs(pp.ID, pp.Addr, pstore.PermanentAddrTTL)
peers[i] = pp
Expand Down
3 changes: 3 additions & 0 deletions test/keybook_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ func testKeyBookPeers(kb pstore.KeyBook) func(t *testing.T) {

// Add a private key.
priv, _, err := pt.RandTestKeyPair(ic.RSA, 2048)
if err != nil {
t.Fatal(err)
}
p2, err := peer.IDFromPrivateKey(priv)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit f01fdfd

Please sign in to comment.