mirror of
https://github.com/libp2p/go-libp2p.git
synced 2026-04-22 16:17:19 +08:00
chore: remove unnecessary conversions (#2680)
This commit is contained in:
committed by
GitHub
parent
5286cdafab
commit
c6e99f10af
+2
-2
@@ -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
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user