From fc9f28fd686a579def33c44830ab4ffd8160612f Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Sat, 23 Apr 2022 18:22:28 +0200 Subject: [PATCH] Minor cleanups. --- codecs/codecs.go | 1 - group/client.go | 2 +- ice/ice.go | 8 ++++---- ice/ice_test.go | 5 ++--- packetcache/packetcache.go | 4 ---- rtpconn/rtpconn.go | 1 - rtpconn/webclient.go | 2 +- webserver/webserver.go | 4 ---- 8 files changed, 8 insertions(+), 19 deletions(-) diff --git a/codecs/codecs.go b/codecs/codecs.go index e72c2e8..4e49fc1 100644 --- a/codecs/codecs.go +++ b/codecs/codecs.go @@ -9,7 +9,6 @@ import ( ) var errTruncated = errors.New("truncated packet") -var errUnsupportedCodec = errors.New("unsupported codec") // Keyframe determines if packet is the start of a keyframe. // It returns (true, true) if that is the case, (false, true) if that is diff --git a/group/client.go b/group/client.go index dfc9a6f..9dab255 100644 --- a/group/client.go +++ b/group/client.go @@ -46,7 +46,7 @@ func (p Password) Match(pw string) (bool, error) { theirKey := pbkdf2.Key( []byte(pw), salt, p.Iterations, len(key), h, ) - return bytes.Compare(key, theirKey) == 0, nil + return bytes.Equal(key, theirKey), nil default: return false, errors.New("unknown password type") } diff --git a/ice/ice.go b/ice/ice.go index da0eb30..9942781 100644 --- a/ice/ice.go +++ b/ice/ice.go @@ -1,7 +1,6 @@ package ice import ( - "bytes" "crypto/hmac" "crypto/sha1" "encoding/base64" @@ -10,6 +9,7 @@ import ( "fmt" "log" "os" + "strings" "sync/atomic" "time" @@ -63,12 +63,12 @@ func getServer(server Server) (webrtc.ICEServer, error) { } mac := hmac.New(sha1.New, []byte(cred)) mac.Write([]byte(username)) - buf := bytes.Buffer{} + buf := strings.Builder{} e := base64.NewEncoder(base64.StdEncoding, &buf) e.Write(mac.Sum(nil)) e.Close() s.Username = username - s.Credential = string(buf.Bytes()) + s.Credential = buf.String() s.CredentialType = webrtc.ICECredentialTypePassword default: return webrtc.ICEServer{}, errors.New("unsupported credential type") @@ -245,7 +245,7 @@ func RelayTest(timeout time.Duration) (time.Duration, error) { if err != nil { return 0, err } - return time.Now().Sub(tm), nil + return time.Since(tm), nil case <-timer.C: return 0, errTimeout } diff --git a/ice/ice_test.go b/ice/ice_test.go index 4b2efae..cd84e16 100644 --- a/ice/ice_test.go +++ b/ice/ice_test.go @@ -1,7 +1,6 @@ package ice import ( - "bytes" "crypto/hmac" "crypto/sha1" "encoding/base64" @@ -57,11 +56,11 @@ func TestHMAC(t *testing.T) { mac := hmac.New(sha1.New, []byte(s.Credential.(string))) mac.Write([]byte(sss.Username)) - buf := bytes.Buffer{} + buf := strings.Builder{} e := base64.NewEncoder(base64.StdEncoding, &buf) e.Write(mac.Sum(nil)) e.Close() - ss.Credential = string(buf.Bytes()) + ss.Credential = buf.String() if err != nil || !reflect.DeepEqual(sss, ss) { t.Errorf("Got %v, expected %v", sss, ss) diff --git a/packetcache/packetcache.go b/packetcache/packetcache.go index 95dc0be..5b457d2 100644 --- a/packetcache/packetcache.go +++ b/packetcache/packetcache.go @@ -12,9 +12,6 @@ import ( // a multiple of 8. const BufSize = 1504 -// The maximum number of packets that constitute a keyframe. -const maxFrame = 1024 - // entry represents a cached packet. type entry struct { seqno uint16 @@ -118,7 +115,6 @@ func (bitmap *bitmap) set(seqno uint16) { } bitmap.bitmap |= (1 << uint16(seqno-bitmap.first)) - return } // BitmapGet shifts up to 17 bits out of the bitmap. It returns a boolean diff --git a/rtpconn/rtpconn.go b/rtpconn/rtpconn.go index 0050b24..9f5739e 100644 --- a/rtpconn/rtpconn.go +++ b/rtpconn/rtpconn.go @@ -410,7 +410,6 @@ type rtpUpTrack struct { srTime uint64 srNTPTime uint64 srRTPTime uint32 - maxLayer uint8 local []conn.DownTrack bufferedNACKs []uint16 actions []trackAction diff --git a/rtpconn/webclient.go b/rtpconn/webclient.go index 443089c..f0b66e2 100644 --- a/rtpconn/webclient.go +++ b/rtpconn/webclient.go @@ -165,7 +165,7 @@ func addUpConn(c *webClient, id, label string, offer string) (*rtpUpConnection, c.up = make(map[string]*rtpUpConnection) } if c.down != nil && c.down[id] != nil { - return nil, false, errors.New("Adding duplicate connection") + return nil, false, errors.New("adding duplicate connection") } old := c.up[id] diff --git a/webserver/webserver.go b/webserver/webserver.go index 3dba39c..95642c5 100644 --- a/webserver/webserver.go +++ b/webserver/webserver.go @@ -123,7 +123,6 @@ func httpError(w http.ResponseWriter, err error) { log.Printf("HTTP server error: %v", err) http.Error(w, "500 Internal Server Error", http.StatusInternalServerError) - return } const ( @@ -352,7 +351,6 @@ func groupStatusHandler(w http.ResponseWriter, r *http.Request) { e := json.NewEncoder(w) e.Encode(d) - return } func publicHandler(w http.ResponseWriter, r *http.Request) { @@ -366,7 +364,6 @@ func publicHandler(w http.ResponseWriter, r *http.Request) { g := group.GetPublic() e := json.NewEncoder(w) e.Encode(g) - return } func adminMatch(username, password string) (bool, error) { @@ -418,7 +415,6 @@ func statsHandler(w http.ResponseWriter, r *http.Request, dataDir string) { if err != nil { log.Printf("stats.json: %v", err) } - return } var wsUpgrader = websocket.Upgrader{