Staticcheck (#464)

Using `go get -u honnef.co/go/tools/cmd/staticcheck`
Uneaarthed a couple of real bugs
This commit is contained in:
Raja Subramanian
2022-02-25 12:04:08 +05:30
committed by GitHub
parent 5a4181b581
commit 0170cc1cb6
19 changed files with 32 additions and 41 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ type CongestionControlProbeMode string
const (
CongestionControlProbeModePadding CongestionControlProbeMode = "padding"
CongestionControlProbeModeMedia = "media"
CongestionControlProbeModeMedia CongestionControlProbeMode = "media"
)
type Config struct {
+1 -1
View File
@@ -457,7 +457,7 @@ func (r *RedisRouter) handleRTCMessage(rm *livekit.RTCNodeMessage) error {
}
case *livekit.RTCNodeMessage_KeepAlive:
if time.Now().Sub(time.Unix(rm.SenderTime, 0)) > statsUpdateInterval {
if time.Since(time.Unix(rm.SenderTime, 0)) > statsUpdateInterval {
logger.Infow("keep alive too old, skipping", "senderTime", rm.SenderTime)
break
}
-2
View File
@@ -29,8 +29,6 @@ type MediaTrack struct {
audioLevelMu sync.RWMutex
audioLevel *AudioLevel
done chan struct{}
*MediaTrackReceiver
lock sync.RWMutex
-3
View File
@@ -81,9 +81,6 @@ type ParticipantImpl struct {
// when first connected
connectedAt time.Time
// JSON encoded metadata to pass to clients
metadata string
rtcpCh chan []rtcp.Packet
// hold reference for MediaTrack
+2 -2
View File
@@ -139,7 +139,7 @@ func (s *RedisStore) LockRoom(_ context.Context, name livekit.RoomName, duration
}
// stop waiting past lock duration
if time.Now().Sub(startTime) > duration {
if time.Since(startTime) > duration {
break
}
@@ -282,7 +282,7 @@ func (s *RedisStore) ListEgress(_ context.Context, roomID livekit.RoomID) ([]*li
return nil, err
}
data, err := s.rc.HMGet(s.ctx, EgressKey, ids...).Result()
data, _ := s.rc.HMGet(s.ctx, EgressKey, ids...).Result()
for _, d := range data {
if d == nil {
continue
+2 -2
View File
@@ -40,7 +40,7 @@ func TestCreateRoom(t *testing.T) {
node.Stats.NumTracksIn = 100
node.Stats.NumTracksOut = 100
ra, conf := newTestRoomAllocator(t, conf, node)
ra, _ := newTestRoomAllocator(t, conf, node)
_, err = ra.CreateRoom(context.Background(), &livekit.CreateRoomRequest{Name: "low-limit-room"})
require.ErrorIs(t, err, routing.ErrNodeLimitReached)
@@ -56,7 +56,7 @@ func TestCreateRoom(t *testing.T) {
node.Stats.BytesInPerSec = 1000
node.Stats.BytesOutPerSec = 1000
ra, conf := newTestRoomAllocator(t, conf, node)
ra, _ := newTestRoomAllocator(t, conf, node)
_, err = ra.CreateRoom(context.Background(), &livekit.CreateRoomRequest{Name: "low-limit-room"})
require.ErrorIs(t, err, routing.ErrNodeLimitReached)
+1 -1
View File
@@ -381,7 +381,7 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.LocalPa
return
}
if time.Now().Sub(lastTokenUpdate) > tokenRefreshInterval {
if time.Since(lastTokenUpdate) > tokenRefreshInterval {
pLogger.Debugw("refreshing client token after interval")
// refresh token with the first API Key/secret pair
if err := r.refreshToken(participant); err != nil {
+1 -1
View File
@@ -96,7 +96,7 @@ func (s *RTCService) validate(r *http.Request) (livekit.RoomName, routing.Partic
// this is new connection for existing participant - with publish only permissions
if publishParam != "" {
// Make sure grant has CanPublish set,
if claims.Video.CanPublish != nil && *claims.Video.CanPublish == false {
if claims.Video.CanPublish != nil && !*claims.Video.CanPublish {
return "", routing.ParticipantInit{}, http.StatusUnauthorized, rtc.ErrPermissionDenied
}
// Make sure by default subscribe is off
+1 -1
View File
@@ -279,7 +279,7 @@ func (s *LivekitServer) healthCheck(w http.ResponseWriter, _ *http.Request) {
if s.Node().Stats != nil {
updatedAt = time.Unix(s.Node().Stats.UpdatedAt, 0)
}
if time.Now().Sub(updatedAt) > 4*time.Second {
if time.Since(updatedAt) > 4*time.Second {
w.WriteHeader(http.StatusNotAcceptable)
_, _ = w.Write([]byte(fmt.Sprintf("Not Ready\nNode Updated At %s", updatedAt)))
return
-1
View File
@@ -147,7 +147,6 @@ func TestNack(t *testing.T) {
func TestNewBuffer(t *testing.T) {
type args struct {
options Options
ssrc uint32
}
tests := []struct {
name string
+1 -1
View File
@@ -136,7 +136,7 @@ func (n *nack) getNack(now time.Time, rtt uint32) (shouldSend bool, shouldRemove
var requiredInterval time.Duration
if n.tries > 0 {
// exponentially backoff retries, but cap maximum spacing between retries
requiredInterval := maxInterval
requiredInterval = maxInterval
backoffInterval := time.Duration(float64(rtt)*math.Pow(backoffFactor, float64(n.tries-1))) * time.Millisecond
if backoffInterval < requiredInterval {
requiredInterval = backoffInterval
+1 -1
View File
@@ -120,7 +120,7 @@ func (cs *ConnectionStats) updateScore() float32 {
maxRTT := uint32(0)
maxJitter := uint32(0)
for _, qw := range cs.qualityWindows {
expectedPacketsInInterval += qw.endSeqNum - qw.endSeqNum + 1
expectedPacketsInInterval += qw.endSeqNum - qw.startSeqNum + 1
lostPacketsInInterval += qw.endPacketsLost - qw.startPacketsLost
if qw.maxRTT > maxRTT {
maxRTT = qw.maxRTT
+9 -9
View File
@@ -984,7 +984,7 @@ func TestForwarderGetTranslationParamsAudio(t *testing.T) {
SSRC: 0x12345678,
PayloadSize: 20,
}
extPkt, err := testutils.GetTestExtPacket(params)
extPkt, _ := testutils.GetTestExtPacket(params)
// should lock onto the first packet
expectedTP := TranslationParams{
@@ -1015,7 +1015,7 @@ func TestForwarderGetTranslationParamsAudio(t *testing.T) {
SSRC: 0x12345678,
PayloadSize: 20,
}
extPkt, err = testutils.GetTestExtPacket(params)
extPkt, _ = testutils.GetTestExtPacket(params)
expectedTP = TranslationParams{
shouldDrop: true,
@@ -1032,7 +1032,7 @@ func TestForwarderGetTranslationParamsAudio(t *testing.T) {
Timestamp: 0xabcdef,
SSRC: 0x12345678,
}
extPkt, err = testutils.GetTestExtPacket(params)
extPkt, _ = testutils.GetTestExtPacket(params)
expectedTP = TranslationParams{
shouldDrop: true,
@@ -1049,7 +1049,7 @@ func TestForwarderGetTranslationParamsAudio(t *testing.T) {
SSRC: 0x12345678,
PayloadSize: 20,
}
extPkt, err = testutils.GetTestExtPacket(params)
extPkt, _ = testutils.GetTestExtPacket(params)
expectedTP = TranslationParams{
rtp: &TranslationParamsRTP{
@@ -1069,7 +1069,7 @@ func TestForwarderGetTranslationParamsAudio(t *testing.T) {
Timestamp: 0xabcdef,
SSRC: 0x12345678,
}
extPkt, err = testutils.GetTestExtPacket(params)
extPkt, _ = testutils.GetTestExtPacket(params)
expectedTP = TranslationParams{
rtp: &TranslationParamsRTP{
@@ -1090,7 +1090,7 @@ func TestForwarderGetTranslationParamsAudio(t *testing.T) {
SSRC: 0x12345678,
PayloadSize: 20,
}
extPkt, err = testutils.GetTestExtPacket(params)
extPkt, _ = testutils.GetTestExtPacket(params)
expectedTP = TranslationParams{
rtp: &TranslationParamsRTP{
@@ -1111,7 +1111,7 @@ func TestForwarderGetTranslationParamsAudio(t *testing.T) {
SSRC: 0x87654321,
PayloadSize: 20,
}
extPkt, err = testutils.GetTestExtPacket(params)
extPkt, _ = testutils.GetTestExtPacket(params)
expectedTP = TranslationParams{
rtp: &TranslationParamsRTP{
@@ -1387,7 +1387,7 @@ func TestForwarderGetTranslationParamsVideo(t *testing.T) {
Timestamp: 0xabcdef,
SSRC: 0x12345678,
}
extPkt, err = testutils.GetTestExtPacket(params)
extPkt, _ = testutils.GetTestExtPacket(params)
expectedTP = TranslationParams{
rtp: &TranslationParamsRTP{
@@ -1407,7 +1407,7 @@ func TestForwarderGetTranslationParamsVideo(t *testing.T) {
Timestamp: 0xabcdef,
SSRC: 0x12345678,
}
extPkt, err = testutils.GetTestExtPacket(params)
extPkt, _ = testutils.GetTestExtPacket(params)
expectedTP = TranslationParams{
rtp: &TranslationParamsRTP{
+8 -9
View File
@@ -32,15 +32,14 @@ type rtpExtInfo struct {
type Responder struct {
sync.Mutex
extInfo []rtpExtInfo
lastReport int64
cycles uint32
lastExtSN uint32
pktCtn uint8
lastSn uint16
lastExtInfo uint16
mSSRC uint32
sSSRC uint32
extInfo []rtpExtInfo
lastReport int64
cycles uint32
lastExtSN uint32
pktCtn uint8
lastSn uint16
mSSRC uint32
sSSRC uint32
len uint16
deltaLen uint16
+1 -1
View File
@@ -68,7 +68,7 @@ func RoomStarted() {
func RoomEnded(startedAt time.Time) {
if !startedAt.IsZero() {
promRoomDuration.Observe(float64(time.Now().Sub(startedAt)) / float64(time.Second))
promRoomDuration.Observe(float64(time.Since(startedAt)) / float64(time.Second))
}
promRoomTotal.Sub(1)
atomic.AddInt32(&atomicRoomTotal, -1)
-2
View File
@@ -287,8 +287,6 @@ func (stats *Stats) coalesce() {
// update currentStats
stats.curStats = &curStats
return
}
// find delta between curStats and prevStats and prepare proto payload
+1 -1
View File
@@ -717,7 +717,7 @@ func (c *RTCClient) processTrack(track *webrtc.TrackRemote) {
c.bytesReceived[pId] += uint64(pkt.MarshalSize())
c.lock.Unlock()
numBytes += pkt.MarshalSize()
if time.Now().Sub(lastUpdate) > 30*time.Second {
if time.Since(lastUpdate) > 30*time.Second {
logger.Infow("consumed from participant",
"track", trackId, "pID", pId,
"size", numBytes)
+1 -1
View File
@@ -96,7 +96,7 @@ func (w *TrackWriter) writeNull() {
w.track.WriteSample(sample)
}
case <-w.ctx.Done():
break
return
}
}
}
+1 -1
View File
@@ -185,7 +185,7 @@ func TestMultiNodeRefreshToken(t *testing.T) {
grants, err := verifier.Verify(testApiSecret)
require.NoError(t, err)
if "metadata" != grants.Metadata {
if grants.Metadata != "metadata" {
return "metadata did not match"
}
if *grants.Video.CanPublish {