Browse Source

chore: remove unnecessary conversions (#2680)

pull/2688/head
Håvard Anda Estensen 10 months ago
committed by GitHub
parent
commit
c6e99f10af
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      options.go
  2. 2
      p2p/host/peerstore/pstoreds/protobook.go
  3. 2
      p2p/host/peerstore/pstoremem/addr_book.go
  4. 2
      p2p/host/peerstore/pstoremem/protobook.go
  5. 2
      p2p/host/resource-manager/scope_test.go
  6. 2
      p2p/net/connmgr/connmgr.go
  7. 2
      p2p/net/gostream/gostream_test.go
  8. 4
      p2p/net/mock/mock_test.go
  9. 2
      p2p/net/swarm/swarm_metrics.go
  10. 2
      p2p/transport/webtransport/cert_manager_test.go
  11. 4
      p2p/transport/webtransport/transport_test.go

4
options.go

@ -349,7 +349,7 @@ func EnableAutoRelayWithPeerSource(peerSource autorelay.PeerSource, opts ...auto
// forcing the local node to believe it is reachable externally.
func ForceReachabilityPublic() Option {
return func(cfg *Config) error {
public := network.Reachability(network.ReachabilityPublic)
public := network.ReachabilityPublic
cfg.AutoNATConfig.ForceReachability = &public
return nil
}
@ -359,7 +359,7 @@ func ForceReachabilityPublic() Option {
// forceing the local node to believe it is behind a NAT and not reachable externally.
func ForceReachabilityPrivate() Option {
return func(cfg *Config) error {
private := network.Reachability(network.ReachabilityPrivate)
private := network.ReachabilityPrivate
cfg.AutoNATConfig.ForceReachability = &private
return nil
}

2
p2p/host/peerstore/pstoreds/protobook.go

@ -17,7 +17,7 @@ type protoSegment struct {
type protoSegments [256]*protoSegment
func (s *protoSegments) get(p peer.ID) *protoSegment {
return s[byte(p[len(p)-1])]
return s[p[len(p)-1]]
}
var errTooManyProtocols = errors.New("too many protocols")

2
p2p/host/peerstore/pstoremem/addr_book.go

@ -49,7 +49,7 @@ func (segments *addrSegments) get(p peer.ID) *addrSegment {
if len(p) == 0 { // it's not terribly useful to use an empty peer ID, but at least we should not panic
return segments[0]
}
return segments[uint8(p[len(p)-1])]
return segments[p[len(p)-1]]
}
type clock interface {

2
p2p/host/peerstore/pstoremem/protobook.go

@ -17,7 +17,7 @@ type protoSegment struct {
type protoSegments [256]*protoSegment
func (s *protoSegments) get(p peer.ID) *protoSegment {
return s[byte(p[len(p)-1])]
return s[p[len(p)-1]]
}
var errTooManyProtocols = errors.New("too many protocols")

2
p2p/host/resource-manager/scope_test.go

@ -97,7 +97,7 @@ func TestCheckMemory(t *testing.T) {
return true
}
return (err != nil) == (uint64(res)+uint64(rc.memory) > (uint64(limit) >> uint64(8-priShift)))
return (err != nil) == (res+uint64(rc.memory) > (limit >> uint64(8-priShift)))
}
require.NoError(t, quick.Check(f, nil))

2
p2p/net/connmgr/connmgr.go

@ -73,7 +73,7 @@ type segments struct {
}
func (ss *segments) get(p peer.ID) *segment {
return ss.buckets[byte(p[len(p)-1])]
return ss.buckets[p[len(p)-1]]
}
func (ss *segments) countPeers() (count int) {

2
p2p/net/gostream/gostream_test.go

@ -129,7 +129,7 @@ func TestServerClient(t *testing.T) {
t.Fatal(err)
}
if string(resp) != "yes it is\n" {
if resp != "yes it is\n" {
t.Errorf("Bad response: %s", resp)
}

4
p2p/net/mock/mock_test.go

@ -463,11 +463,11 @@ func TestRateLimiting(t *testing.T) {
}
rl.UpdateBandwidth(100)
if !within(rl.Limit(1), time.Duration(time.Millisecond*10), time.Millisecond) {
if !within(rl.Limit(1), time.Millisecond*10, time.Millisecond) {
t.Fatal()
}
if within(rl.Limit(1), time.Duration(time.Millisecond*10), time.Millisecond) {
if within(rl.Limit(1), time.Millisecond*10, time.Millisecond) {
t.Fatal()
}
}

2
p2p/net/swarm/swarm_metrics.go

@ -166,7 +166,7 @@ func appendConnectionState(tags []string, cs network.ConnectionState) []string {
// This shouldn't happen, unless the transport doesn't properly set the Transport field in the ConnectionState.
tags = append(tags, "unknown")
} else {
tags = append(tags, string(cs.Transport))
tags = append(tags, cs.Transport)
}
// These might be empty, depending on the transport.
// For example, QUIC doesn't set security nor muxer.

2
p2p/transport/webtransport/cert_manager_test.go

@ -166,7 +166,7 @@ func TestGetCurrentBucketStartTimeIsWithinBounds(t *testing.T) {
offset = offset % certValidity
// Bound this to 100 years
timeSinceUnixEpoch = time.Duration(timeSinceUnixEpoch % (time.Hour * 24 * 365 * 100))
timeSinceUnixEpoch = timeSinceUnixEpoch % (time.Hour * 24 * 365 * 100)
// Start a bit further in the future to avoid edge cases around epoch
timeSinceUnixEpoch += time.Hour * 24 * 365
start := time.UnixMilli(timeSinceUnixEpoch.Milliseconds())

4
p2p/transport/webtransport/transport_test.go

@ -650,7 +650,7 @@ func serverSendsBackValidCert(t *testing.T, timeSinceUnixEpoch time.Duration, ke
}
// Bound this to 100 years
timeSinceUnixEpoch = time.Duration(timeSinceUnixEpoch % (time.Hour * 24 * 365 * 100))
timeSinceUnixEpoch = timeSinceUnixEpoch % (time.Hour * 24 * 365 * 100)
// Start a bit further in the future to avoid edge cases around epoch
timeSinceUnixEpoch += time.Hour * 24 * 365
start := time.UnixMilli(timeSinceUnixEpoch.Milliseconds())
@ -729,7 +729,7 @@ func TestServerRotatesCertCorrectly(t *testing.T) {
}
// Bound this to 100 years
timeSinceUnixEpoch = time.Duration(timeSinceUnixEpoch % (time.Hour * 24 * 365 * 100))
timeSinceUnixEpoch = timeSinceUnixEpoch % (time.Hour * 24 * 365 * 100)
// Start a bit further in the future to avoid edge cases around epoch
timeSinceUnixEpoch += time.Hour * 24 * 365
start := time.UnixMilli(timeSinceUnixEpoch.Milliseconds())

Loading…
Cancel
Save