diff --git a/p2p/discovery/mdns.go b/p2p/discovery/mdns.go index f8aa3bc8f0..71eb0a5d9e 100644 --- a/p2p/discovery/mdns.go +++ b/p2p/discovery/mdns.go @@ -110,28 +110,25 @@ func (m *mdnsService) Close() error { func (m *mdnsService) pollForEntries() { ticker := time.NewTicker(m.interval) - for { - select { - case <-ticker.C: - entriesCh := make(chan *mdns.ServiceEntry, 16) - go func() { - for entry := range entriesCh { - m.handleEntry(entry) - } - }() - - qp := mdns.QueryParam{} - qp.Domain = "local" - qp.Entries = entriesCh - qp.Service = ServiceTag - qp.Timeout = time.Second * 5 - - err := mdns.Query(&qp) - if err != nil { - log.Error("mdns lookup error: ", err) + for range ticker.C { + entriesCh := make(chan *mdns.ServiceEntry, 16) + go func() { + for entry := range entriesCh { + m.handleEntry(entry) } - close(entriesCh) + }() + + qp := mdns.QueryParam{} + qp.Domain = "local" + qp.Entries = entriesCh + qp.Service = ServiceTag + qp.Timeout = time.Second * 5 + + err := mdns.Query(&qp) + if err != nil { + log.Error("mdns lookup error: ", err) } + close(entriesCh) } } diff --git a/p2p/nat/nat.go b/p2p/nat/nat.go index 4dd6f0439e..7dac06df1d 100644 --- a/p2p/nat/nat.go +++ b/p2p/nat/nat.go @@ -208,7 +208,7 @@ func (m *mapping) ExternalAddr() (ma.Multiaddr, error) { ctime := m.cacheTime cval := m.cached m.cacheLk.Unlock() - if time.Now().Sub(ctime) < CacheTime { + if time.Since(ctime) < CacheTime { return cval, nil } diff --git a/p2p/net/conn/dial.go b/p2p/net/conn/dial.go index 94fd8fcddb..9d0e6a7c17 100644 --- a/p2p/net/conn/dial.go +++ b/p2p/net/conn/dial.go @@ -86,7 +86,7 @@ func (d *Dialer) Dial(ctx context.Context, raddr ma.Multiaddr, remote peer.ID) ( return } - if d.PrivateKey == nil || EncryptConnections == false { + if d.PrivateKey == nil || !EncryptConnections { log.Warning("dialer %s dialing INSECURELY %s at %s!", d, remote, raddr) connOut = c return diff --git a/p2p/net/conn/dial_test.go b/p2p/net/conn/dial_test.go index a46bf42c71..f26f76f3bb 100644 --- a/p2p/net/conn/dial_test.go +++ b/p2p/net/conn/dial_test.go @@ -514,7 +514,7 @@ func TestConcurrentAccept(t *testing.T) { } limit := delay * time.Duration(n) - took := time.Now().Sub(before) + took := time.Since(before) if took > limit { t.Fatal("took too long!") } @@ -606,7 +606,7 @@ func TestConnectionTimeouts(t *testing.T) { c.Close() } - took := time.Now().Sub(before) + took := time.Since(before) if took > time.Second*5 { t.Fatal("hanging dials shouldnt block good dials") diff --git a/p2p/net/conn/listen.go b/p2p/net/conn/listen.go index b7a4687894..ee6443cc08 100644 --- a/p2p/net/conn/listen.go +++ b/p2p/net/conn/listen.go @@ -93,7 +93,7 @@ func (l *listener) Accept() (net.Conn, error) { return nil, err } - if l.privk == nil || EncryptConnections == false { + if l.privk == nil || !EncryptConnections { log.Warning("listener %s listening INSECURELY!", l) return c, nil } diff --git a/p2p/net/swarm/dial_test.go b/p2p/net/swarm/dial_test.go index 515deb100f..031f3b3a5e 100644 --- a/p2p/net/swarm/dial_test.go +++ b/p2p/net/swarm/dial_test.go @@ -187,7 +187,7 @@ func TestDialWait(t *testing.T) { } else { t.Log("correctly got error:", err) } - duration := time.Now().Sub(before) + duration := time.Since(before) dt := s1.dialT if duration < dt*dialAttempts { @@ -451,7 +451,7 @@ func TestDialBackoffClears(t *testing.T) { } else { t.Log("correctly got error:", err) } - duration := time.Now().Sub(before) + duration := time.Since(before) dt := s1.dialT if duration < dt*dialAttempts { diff --git a/p2p/net/swarm/swarm_net.go b/p2p/net/swarm/swarm_net.go index f13da04083..92d2a801eb 100644 --- a/p2p/net/swarm/swarm_net.go +++ b/p2p/net/swarm/swarm_net.go @@ -124,7 +124,7 @@ func (n *Network) InterfaceListenAddresses() ([]ma.Multiaddr, error) { // For now only returns Connected || NotConnected. Expand into more later. func (n *Network) Connectedness(p peer.ID) inet.Connectedness { c := n.Swarm().ConnectionsToPeer(p) - if c != nil && len(c) > 0 { + if len(c) > 0 { return inet.Connected } return inet.NotConnected diff --git a/p2p/protocol/ping/ping.go b/p2p/protocol/ping/ping.go index dcf6058708..f1d1758c5c 100644 --- a/p2p/protocol/ping/ping.go +++ b/p2p/protocol/ping/ping.go @@ -121,5 +121,5 @@ func ping(s inet.Stream) (time.Duration, error) { return 0, errors.New("ping packet was incorrect!") } - return time.Now().Sub(before), nil + return time.Since(before), nil } diff --git a/p2p/test/backpressure/backpressure_test.go b/p2p/test/backpressure/backpressure_test.go index f9a5d40201..1e32e30a01 100644 --- a/p2p/test/backpressure/backpressure_test.go +++ b/p2p/test/backpressure/backpressure_test.go @@ -318,7 +318,7 @@ func TestStBackpressureStreamWrite(t *testing.T) { receive(s, b) roundsTotal = roundsTotal + b } - roundsTime := time.Now().Sub(roundsStart) + roundsTime := time.Since(roundsStart) // now read continously, while we measure stats. stop := make(chan struct{}) @@ -341,7 +341,7 @@ func TestStBackpressureStreamWrite(t *testing.T) { contTotal += n } stop <- struct{}{} - contTime := time.Now().Sub(contStart) + contTime := time.Since(contStart) // now compare! continuous should've been faster AND larger if roundsTime < contTime {