mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2025-01-27 04:40:07 +08:00
fix: address lints
This commit is contained in:
parent
90f363555f
commit
4808543c09
@ -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
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
@ -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 {
|
||||
|
@ -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)}
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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())
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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()
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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) {
|
||||
@ -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))
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user