Skip to content

Commit

Permalink
chore: remove unnecessary conversions (#2680)
Browse files Browse the repository at this point in the history
  • Loading branch information
estensen authored Jan 9, 2024
1 parent 5286cda commit c6e99f1
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion p2p/host/peerstore/pstoreds/protobook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion p2p/host/peerstore/pstoremem/addr_book.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion p2p/host/peerstore/pstoremem/protobook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion p2p/host/resource-manager/scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/connmgr/connmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/gostream/gostream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions p2p/net/mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/swarm/swarm_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion p2p/transport/webtransport/cert_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions p2p/transport/webtransport/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit c6e99f1

Please sign in to comment.