Skip to content

Commit

Permalink
Minor cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
jech committed Apr 23, 2022
1 parent 9ab8474 commit fc9f28f
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 19 deletions.
1 change: 0 additions & 1 deletion codecs/codecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion group/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
8 changes: 4 additions & 4 deletions ice/ice.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ice

import (
"bytes"
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
Expand All @@ -10,6 +9,7 @@ import (
"fmt"
"log"
"os"
"strings"
"sync/atomic"
"time"

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions ice/ice_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ice

import (
"bytes"
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions packetcache/packetcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion rtpconn/rtpconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ type rtpUpTrack struct {
srTime uint64
srNTPTime uint64
srRTPTime uint32
maxLayer uint8
local []conn.DownTrack
bufferedNACKs []uint16
actions []trackAction
Expand Down
2 changes: 1 addition & 1 deletion rtpconn/webclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 0 additions & 4 deletions webserver/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit fc9f28f

Please sign in to comment.