From ca0c7e3bb8da379da80f4898a9bb3da80c83f7ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ramon=20Gabarr=C3=B3=20Sol=C3=A9?= Date: Wed, 17 Apr 2024 07:28:42 +0200 Subject: [PATCH 01/17] Support standard streamid syntax --- srt/server.go | 2 +- stream/streamid.go | 82 +++++++++++++++++++++++++++++++++------------- 2 files changed, 61 insertions(+), 23 deletions(-) diff --git a/srt/server.go b/srt/server.go index 3afb3e8..3b42326 100644 --- a/srt/server.go +++ b/srt/server.go @@ -332,7 +332,7 @@ func (s *ServerImpl) registerForStats(ctx context.Context, conn *srtConn) { func (s *ServerImpl) GetStatistics() []*relay.StreamStatistics { streams := s.relay.GetStatistics() for _, stream := range streams { - stream.URL = fmt.Sprintf("srt://%s?streamid=play/%s", s.config.PublicAddress, stream.Name) + stream.URL = fmt.Sprintf("srt://%s?streamid=#!::m=request,r=%s", s.config.PublicAddress, stream.Name) } return streams } diff --git a/stream/streamid.go b/stream/streamid.go index d83fbc8..4302648 100644 --- a/stream/streamid.go +++ b/stream/streamid.go @@ -65,35 +65,73 @@ func NewStreamID(name string, password string, mode Mode) (*StreamID, error) { // The second slash and password is optional and defaults to empty. // If error is not nil then StreamID will remain unchanged. func (s *StreamID) FromString(src string) error { - split := strings.Split(src, "/") - password := "" - if len(split) == 3 { - password = split[2] - } else if len(split) != 2 { - return InvalidSlashes - } - modeStr := split[0] - name := split[1] + if strings.HasPrefix(src, "#!::") { + for _, kv := range strings.Split(src[len("#!::"):], ",") { + kv2 := strings.SplitN(kv, "=", 2) + if len(kv2) != 2 { + return fmt.Errorf("invalid value") + } - if len(name) == 0 { - return MissingName + key, value := kv2[0], kv2[1] + + switch key { + case "u": + // s.user = value + + case "r": + s.name = value + + case "h": + + case "s": + s.password = value + + case "t": + + case "m": + switch value { + case "request": + s.mode = ModePlay + + case "publish": + s.mode = ModePublish + + default: + return InvalidMode + } + + default: + return fmt.Errorf("unsupported key '%s'", key) + } + } + } else { + split := strings.Split(src, "/") + + s.password = "" + if len(split) == 3 { + s.password = split[2] + } else if len(split) != 2 { + return InvalidSlashes + } + modeStr := split[0] + s.name = split[1] + + switch modeStr { + case "play": + s.mode = ModePlay + case "publish": + s.mode = ModePublish + default: + return InvalidMode + } } - var mode Mode - switch modeStr { - case "play": - mode = ModePlay - case "publish": - mode = ModePublish - default: - return InvalidMode + if len(s.name) == 0 { + return MissingName } s.str = src - s.mode = mode - s.name = name - s.password = password return nil } From 42654e434892eb4a6fb5c6f692de690379304bc3 Mon Sep 17 00:00:00 2001 From: Paulson McIntyre Date: Mon, 25 Nov 2024 15:20:03 -0500 Subject: [PATCH 02/17] No jetbrains files --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bc1061e..2cf3874 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ srtrelay config.toml -/.vscode \ No newline at end of file +# VSCode +/.vscode +# Jetbrains +/.idea +*.iml \ No newline at end of file From 89c20b625ee671486862fb6a4060f65c8d67c5d2 Mon Sep 17 00:00:00 2001 From: Paulson McIntyre Date: Mon, 25 Nov 2024 15:20:13 -0500 Subject: [PATCH 03/17] Use const for stream id prefix --- stream/streamid.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/stream/streamid.go b/stream/streamid.go index 4302648..06d84fc 100644 --- a/stream/streamid.go +++ b/stream/streamid.go @@ -8,6 +8,8 @@ import ( "github.com/IGLOU-EU/go-wildcard/v2" ) +const IDPrefix = "#!::" + var ( InvalidSlashes = errors.New("Invalid number of slashes, must be 1 or 2") InvalidMode = errors.New("Invalid mode") @@ -43,7 +45,7 @@ type StreamID struct { password string } -// Creates new StreamID +// NewStreamID creates new StreamID // returns error if mode is invalid. // id is nil on error func NewStreamID(name string, password string, mode Mode) (*StreamID, error) { @@ -66,8 +68,8 @@ func NewStreamID(name string, password string, mode Mode) (*StreamID, error) { // If error is not nil then StreamID will remain unchanged. func (s *StreamID) FromString(src string) error { - if strings.HasPrefix(src, "#!::") { - for _, kv := range strings.Split(src[len("#!::"):], ",") { + if strings.HasPrefix(src, IDPrefix) { + for _, kv := range strings.Split(src[len(IDPrefix):], ",") { kv2 := strings.SplitN(kv, "=", 2) if len(kv2) != 2 { return fmt.Errorf("invalid value") From c4b59bcb2e89ac6697389ba864c18d71fe3ad0a8 Mon Sep 17 00:00:00 2001 From: Paulson McIntyre Date: Tue, 26 Nov 2024 02:51:30 -0500 Subject: [PATCH 04/17] doc++ --- stream/streamid.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stream/streamid.go b/stream/streamid.go index 06d84fc..1c270f8 100644 --- a/stream/streamid.go +++ b/stream/streamid.go @@ -43,6 +43,7 @@ type StreamID struct { mode Mode name string password string + // user string } // NewStreamID creates new StreamID @@ -63,8 +64,8 @@ func NewStreamID(name string, password string, mode Mode) (*StreamID, error) { } // FromString reads a streamid from a string. -// The accepted stream id format is //. -// The second slash and password is optional and defaults to empty. +// The accepted old stream id format is //. The second slash and password is +// optional and defaults to empty. The new format is `#!::m=(request|publish),r=(stream-key),u=(user),s=(password)` // If error is not nil then StreamID will remain unchanged. func (s *StreamID) FromString(src string) error { From 637f8df2af3b2c80a1c4d262b13d1910b5cd2127 Mon Sep 17 00:00:00 2001 From: Paulson McIntyre Date: Tue, 26 Nov 2024 03:24:13 -0500 Subject: [PATCH 05/17] Moved InvalidValue to a var & caps to match others in code --- stream/streamid.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stream/streamid.go b/stream/streamid.go index 1c270f8..ec4dd6d 100644 --- a/stream/streamid.go +++ b/stream/streamid.go @@ -15,6 +15,7 @@ var ( InvalidMode = errors.New("Invalid mode") MissingName = errors.New("Missing name after slash") InvalidNamePassword = errors.New("Name/Password is not allowed to contain slashes") + InvalidValue = fmt.Errorf("Invalid value") ) // Mode - client mode @@ -73,7 +74,7 @@ func (s *StreamID) FromString(src string) error { for _, kv := range strings.Split(src[len(IDPrefix):], ",") { kv2 := strings.SplitN(kv, "=", 2) if len(kv2) != 2 { - return fmt.Errorf("invalid value") + return InvalidValue } key, value := kv2[0], kv2[1] From 5524fa24215b30d9c7316a1bcd2ca301af343c0a Mon Sep 17 00:00:00 2001 From: Paulson McIntyre Date: Tue, 26 Nov 2024 03:24:40 -0500 Subject: [PATCH 06/17] Added a bunch of unit tests for new srt format in `TestParseStreamID` --- stream/streamid_test.go | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/stream/streamid_test.go b/stream/streamid_test.go index 5d4e204..4e3d925 100644 --- a/stream/streamid_test.go +++ b/stream/streamid_test.go @@ -1,6 +1,7 @@ package stream import ( + "fmt" "testing" ) @@ -13,6 +14,7 @@ func TestParseStreamID(t *testing.T) { wantPass string wantErr error }{ + // Old school {"MissingSlash", "s1", 0, "", "", InvalidSlashes}, {"InvalidName", "play//s1", 0, "", "", MissingName}, {"InvalidMode", "foobar/bla", 0, "", "", InvalidMode}, @@ -22,15 +24,41 @@ func TestParseStreamID(t *testing.T) { {"ValidPlay", "play/s1", ModePlay, "s1", "", nil}, {"ValidPublish", "publish/abcdef", ModePublish, "abcdef", "", nil}, {"ValidPlaySpace", "play/bla fasel", ModePlay, "bla fasel", "", nil}, + // New hotness - Bad + {"NewInvalidPubEmptyName", "#!::m=publish", ModePublish, "", "", MissingName}, + {"NewInvalidPlayEmptyName", "#!::m=request", ModePlay, "", "", MissingName}, + {"NewInvalidPubBadKey", "#!::m=publish,y=bar", ModePublish, "", "", fmt.Errorf("unsupported key '%s'", "y")}, + {"NewInvalidPlayBadKey", "#!::m=request,x=foo", ModePlay, "", "", fmt.Errorf("unsupported key '%s'", "x")}, + {"NewInvalidPubNoEquals", "#!::m=publish,r", ModePublish, "abc", "", InvalidValue}, + {"NewInvalidPlayNoEquals", "#!::m=request,r", ModePlay, "abc", "", InvalidValue}, + {"NewInvalidPubNoValue", "#!::m=publish,r=", ModePublish, "abc", "", MissingName}, + {"NewInvalidPlayNoValue", "#!::m=request,s=", ModePlay, "abc", "", MissingName}, + {"NewInvalidPubBadKey", "#!::m=publish,x=", ModePublish, "abc", "", fmt.Errorf("unsupported key '%s'", "x")}, + {"NewInvalidPlayBadKey", "#!::m=request,y=", ModePlay, "abc", "", fmt.Errorf("unsupported key '%s'", "y")}, + // New hotness - Standard + {"NewValidNameRequest", "#!::m=publish,r=abc", ModePublish, "abc", "", nil}, + {"NewValidPlay", "#!::m=request,r=abc", ModePlay, "abc", "", nil}, + {"NewValidNameRequestRev", "#!::r=abc,m=publish", ModePublish, "abc", "", nil}, + {"NewValidPlayRev", "#!::r=abc,m=request", ModePlay, "abc", "", nil}, + {"NewValidPassPub", "#!::m=publish,r=abc,s=bob", ModePublish, "abc", "bob", nil}, + {"NewValidPassPlay", "#!::m=request,r=abc,s=alice", ModePlay, "abc", "alice", nil}, + {"NewValidPassPubOrder", "#!::s=bob,m=publish,r=abc123", ModePublish, "abc123", "bob", nil}, + {"NewValidPassPlayOrder", "#!::m=request,s=alice,r=def", ModePlay, "def", "alice", nil}, + // New Hotness - Unicode + {"NewValidUnicodePub", "#!::m=publish,r=#![äöü,s=bob", ModePublish, "#![äöü", "bob", nil}, + {"NewValidUnicodePlay", "#!::m=request,r=#![äöü,s=alice", ModePlay, "#![äöü", "alice", nil}, + {"NewValidUnicodePassPub", "#!::m=publish,s=#![äöü,r=bob", ModePublish, "bob", "#![äöü", nil}, + {"NewValidUnicodePassPlay", "#!::m=request,s=#![äöü,r=alice", ModePlay, "alice", "#![äöü", nil}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var streamid StreamID err := streamid.FromString(tt.streamID) - if err != tt.wantErr { - t.Errorf("ParseStreamID() error = %v, wantErr %v", err, tt.wantErr) - } + if err != nil { + if err.Error() != tt.wantErr.Error() { // Only really care about str value for this, otherwise: if !errors.Is(err, tt.wantErr) { + t.Errorf("ParseStreamID() error = %v, wantErr %v", err, tt.wantErr) + } if streamid.String() != "" { t.Error("str should be empty on failed parse") } From 40842106602bf0587bc9a03a3c502b1dd1263aa0 Mon Sep 17 00:00:00 2001 From: Paulson McIntyre Date: Tue, 26 Nov 2024 03:32:50 -0500 Subject: [PATCH 07/17] "Fixing" package name overwrite Not really a bug but could confuse others later. --- srt/server.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/srt/server.go b/srt/server.go index 3b42326..a54a524 100644 --- a/srt/server.go +++ b/srt/server.go @@ -331,8 +331,9 @@ func (s *ServerImpl) registerForStats(ctx context.Context, conn *srtConn) { func (s *ServerImpl) GetStatistics() []*relay.StreamStatistics { streams := s.relay.GetStatistics() - for _, stream := range streams { - stream.URL = fmt.Sprintf("srt://%s?streamid=#!::m=request,r=%s", s.config.PublicAddress, stream.Name) + for _, st := range streams { + //stream.URL = fmt.Sprintf("srt://%s?streamid=#!::m=request,r=%s", s.config.PublicAddress, stream.Name) + st.URL = fmt.Sprintf("srt://%s?streamid=play/%s", s.config.PublicAddress, st.Name) } return streams } From 53946999fbad3f8c6a32b5f899acae39616fe9a1 Mon Sep 17 00:00:00 2001 From: Paulson McIntyre Date: Tue, 26 Nov 2024 06:58:53 -0500 Subject: [PATCH 08/17] Fixing failure on wrapped errors --- api/server.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/server.go b/api/server.go index 789dec7..0395b42 100644 --- a/api/server.go +++ b/api/server.go @@ -3,6 +3,7 @@ package api import ( "context" "encoding/json" + "errors" "log" "net/http" "sync" @@ -49,7 +50,7 @@ func (s *Server) Listen(ctx context.Context) error { go func() { defer s.done.Done() err := serv.ListenAndServe() - if err != nil && err != http.ErrServerClosed { + if err != nil && !errors.Is(err, http.ErrServerClosed) { log.Println(err) } }() From f0a039365ccd4e767bea7eb01c121b0772b6f9b9 Mon Sep 17 00:00:00 2001 From: Paulson McIntyre Date: Tue, 26 Nov 2024 07:04:37 -0500 Subject: [PATCH 09/17] Returning exported interface rather than unexported struct --- auth/http.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/http.go b/auth/http.go index fdcba27..e01c080 100644 --- a/auth/http.go +++ b/auth/http.go @@ -33,7 +33,7 @@ type HTTPAuthConfig struct { } // NewHttpAuth creates an Authenticator with a HTTP backend -func NewHTTPAuth(config HTTPAuthConfig) *httpAuth { +func NewHTTPAuth(config HTTPAuthConfig) Authenticator { return &httpAuth{ config: config, client: &http.Client{ From f27dc044c414ebbadc2b18ec3fabf02284eca6c2 Mon Sep 17 00:00:00 2001 From: Paulson McIntyre Date: Tue, 26 Nov 2024 07:32:05 -0500 Subject: [PATCH 10/17] Added support for new form `username` field Basic unit tests in place --- auth/http.go | 1 + stream/streamid.go | 10 +++-- stream/streamid_test.go | 84 +++++++++++++++++++++++------------------ 3 files changed, 55 insertions(+), 40 deletions(-) diff --git a/auth/http.go b/auth/http.go index e01c080..3b57dc3 100644 --- a/auth/http.go +++ b/auth/http.go @@ -53,6 +53,7 @@ func (h *httpAuth) Authenticate(streamid stream.StreamID) bool { "call": {streamid.Mode().String()}, "app": {h.config.Application}, "name": {streamid.Name()}, + "username": {streamid.Username()}, h.config.PasswordParam: {streamid.Password()}, }) if err != nil { diff --git a/stream/streamid.go b/stream/streamid.go index ec4dd6d..17c61e2 100644 --- a/stream/streamid.go +++ b/stream/streamid.go @@ -44,7 +44,7 @@ type StreamID struct { mode Mode name string password string - // user string + username string } // NewStreamID creates new StreamID @@ -66,7 +66,7 @@ func NewStreamID(name string, password string, mode Mode) (*StreamID, error) { // FromString reads a streamid from a string. // The accepted old stream id format is //. The second slash and password is -// optional and defaults to empty. The new format is `#!::m=(request|publish),r=(stream-key),u=(user),s=(password)` +// optional and defaults to empty. The new format is `#!::m=(request|publish),r=(stream-key),u=(username),s=(password)` // If error is not nil then StreamID will remain unchanged. func (s *StreamID) FromString(src string) error { @@ -81,7 +81,7 @@ func (s *StreamID) FromString(src string) error { switch key { case "u": - // s.user = value + s.username = value case "r": s.name = value @@ -182,3 +182,7 @@ func (s StreamID) Name() string { func (s StreamID) Password() string { return s.password } + +func (s StreamID) Username() string { + return s.username +} diff --git a/stream/streamid_test.go b/stream/streamid_test.go index 4e3d925..5a04c88 100644 --- a/stream/streamid_test.go +++ b/stream/streamid_test.go @@ -7,48 +7,55 @@ import ( func TestParseStreamID(t *testing.T) { tests := []struct { - name string - streamID string - wantMode Mode - wantName string - wantPass string - wantErr error + name string + streamID string + wantMode Mode + wantName string + wantPass string + wantUsername string + wantErr error }{ // Old school - {"MissingSlash", "s1", 0, "", "", InvalidSlashes}, - {"InvalidName", "play//s1", 0, "", "", MissingName}, - {"InvalidMode", "foobar/bla", 0, "", "", InvalidMode}, - {"InvalidSlash", "foobar/bla//", 0, "", "", InvalidSlashes}, - {"EmptyPass", "play/s1/", ModePlay, "s1", "", nil}, - {"ValidPass", "play/s1/#![äöü", ModePlay, "s1", "#![äöü", nil}, - {"ValidPlay", "play/s1", ModePlay, "s1", "", nil}, - {"ValidPublish", "publish/abcdef", ModePublish, "abcdef", "", nil}, - {"ValidPlaySpace", "play/bla fasel", ModePlay, "bla fasel", "", nil}, + {"MissingSlash", "s1", 0, "", "", "", InvalidSlashes}, + {"InvalidName", "play//s1", 0, "", "", "", MissingName}, + {"InvalidMode", "foobar/bla", 0, "", "", "", InvalidMode}, + {"InvalidSlash", "foobar/bla//", 0, "", "", "", InvalidSlashes}, + {"EmptyPass", "play/s1/", ModePlay, "s1", "", "", nil}, + {"ValidPass", "play/s1/#![äöü", ModePlay, "s1", "#![äöü", "", nil}, + {"ValidPlay", "play/s1", ModePlay, "s1", "", "", nil}, + {"ValidPublish", "publish/abcdef", ModePublish, "abcdef", "", "", nil}, + {"ValidPlaySpace", "play/bla fasel", ModePlay, "bla fasel", "", "", nil}, // New hotness - Bad - {"NewInvalidPubEmptyName", "#!::m=publish", ModePublish, "", "", MissingName}, - {"NewInvalidPlayEmptyName", "#!::m=request", ModePlay, "", "", MissingName}, - {"NewInvalidPubBadKey", "#!::m=publish,y=bar", ModePublish, "", "", fmt.Errorf("unsupported key '%s'", "y")}, - {"NewInvalidPlayBadKey", "#!::m=request,x=foo", ModePlay, "", "", fmt.Errorf("unsupported key '%s'", "x")}, - {"NewInvalidPubNoEquals", "#!::m=publish,r", ModePublish, "abc", "", InvalidValue}, - {"NewInvalidPlayNoEquals", "#!::m=request,r", ModePlay, "abc", "", InvalidValue}, - {"NewInvalidPubNoValue", "#!::m=publish,r=", ModePublish, "abc", "", MissingName}, - {"NewInvalidPlayNoValue", "#!::m=request,s=", ModePlay, "abc", "", MissingName}, - {"NewInvalidPubBadKey", "#!::m=publish,x=", ModePublish, "abc", "", fmt.Errorf("unsupported key '%s'", "x")}, - {"NewInvalidPlayBadKey", "#!::m=request,y=", ModePlay, "abc", "", fmt.Errorf("unsupported key '%s'", "y")}, + {"NewInvalidPubEmptyName", "#!::m=publish", ModePublish, "", "", "", MissingName}, + {"NewInvalidPlayEmptyName", "#!::m=request", ModePlay, "", "", "", MissingName}, + {"NewInvalidPubBadKey", "#!::m=publish,y=bar", ModePublish, "", "", "", fmt.Errorf("unsupported key '%s'", "y")}, + {"NewInvalidPlayBadKey", "#!::m=request,x=foo", ModePlay, "", "", "", fmt.Errorf("unsupported key '%s'", "x")}, + {"NewInvalidPubNoEquals", "#!::m=publish,r", ModePublish, "abc", "", "", InvalidValue}, + {"NewInvalidPlayNoEquals", "#!::m=request,r", ModePlay, "abc", "", "", InvalidValue}, + {"NewInvalidPubNoValue", "#!::m=publish,r=", ModePublish, "abc", "", "", MissingName}, + {"NewInvalidPlayNoValue", "#!::m=request,s=", ModePlay, "abc", "", "", MissingName}, + {"NewInvalidPubBadKey", "#!::m=publish,x=", ModePublish, "abc", "", "", fmt.Errorf("unsupported key '%s'", "x")}, + {"NewInvalidPlayBadKey", "#!::m=request,y=", ModePlay, "abc", "", "", fmt.Errorf("unsupported key '%s'", "y")}, // New hotness - Standard - {"NewValidNameRequest", "#!::m=publish,r=abc", ModePublish, "abc", "", nil}, - {"NewValidPlay", "#!::m=request,r=abc", ModePlay, "abc", "", nil}, - {"NewValidNameRequestRev", "#!::r=abc,m=publish", ModePublish, "abc", "", nil}, - {"NewValidPlayRev", "#!::r=abc,m=request", ModePlay, "abc", "", nil}, - {"NewValidPassPub", "#!::m=publish,r=abc,s=bob", ModePublish, "abc", "bob", nil}, - {"NewValidPassPlay", "#!::m=request,r=abc,s=alice", ModePlay, "abc", "alice", nil}, - {"NewValidPassPubOrder", "#!::s=bob,m=publish,r=abc123", ModePublish, "abc123", "bob", nil}, - {"NewValidPassPlayOrder", "#!::m=request,s=alice,r=def", ModePlay, "def", "alice", nil}, + {"NewValidNameRequest", "#!::m=publish,r=abc", ModePublish, "abc", "", "", nil}, + {"NewValidPlay", "#!::m=request,r=abc", ModePlay, "abc", "", "", nil}, + {"NewValidNameRequestRev", "#!::r=abc,m=publish", ModePublish, "abc", "", "", nil}, + {"NewValidPlayRev", "#!::r=abc,m=request", ModePlay, "abc", "", "", nil}, + {"NewValidPassPub", "#!::m=publish,r=abc,s=bob", ModePublish, "abc", "bob", "", nil}, + {"NewValidPassPlay", "#!::m=request,r=abc,s=alice", ModePlay, "abc", "alice", "", nil}, + {"NewValidPassPubOrder", "#!::s=bob,m=publish,r=abc123", ModePublish, "abc123", "bob", "", nil}, + {"NewValidPassPlayOrder", "#!::m=request,s=alice,r=def", ModePlay, "def", "alice", "", nil}, + {"NewValidPubUsername", "#!::s=bob,m=publish,r=abc123,u=eve", ModePublish, "abc123", "bob", "eve", nil}, + {"NewValidPlayUsername", "#!::m=request,s=alice,r=def,u=bar", ModePlay, "def", "alice", "bar", nil}, + {"NewValidPubUsernameOrder", "#!::s=bob,m=publish,u=eve,r=abc123", ModePublish, "abc123", "bob", "eve", nil}, + {"NewValidPlayUsernameOrder", "#!::m=request,u=bar,s=alice,r=def", ModePlay, "def", "alice", "bar", nil}, // New Hotness - Unicode - {"NewValidUnicodePub", "#!::m=publish,r=#![äöü,s=bob", ModePublish, "#![äöü", "bob", nil}, - {"NewValidUnicodePlay", "#!::m=request,r=#![äöü,s=alice", ModePlay, "#![äöü", "alice", nil}, - {"NewValidUnicodePassPub", "#!::m=publish,s=#![äöü,r=bob", ModePublish, "bob", "#![äöü", nil}, - {"NewValidUnicodePassPlay", "#!::m=request,s=#![äöü,r=alice", ModePlay, "alice", "#![äöü", nil}, + {"NewValidUnicodePub", "#!::m=publish,r=#![äöü,s=bob", ModePublish, "#![äöü", "bob", "", nil}, + {"NewValidUnicodePlay", "#!::m=request,r=#![äöü,s=alice", ModePlay, "#![äöü", "alice", "", nil}, + {"NewValidUnicodePassPub", "#!::m=publish,s=#![äöü,r=bob", ModePublish, "bob", "#![äöü", "", nil}, + {"NewValidUnicodePassPlay", "#!::m=request,s=#![äöü,r=alice", ModePlay, "alice", "#![äöü", "", nil}, + {"NewValidUnicodeUserPub", "#!::s=bye,m=publish,u=#![äöü,r=art", ModePublish, "art", "bye", "#![äöü", nil}, + {"NewValidUnicodeUserPlay", "#!::m=request,u=#![äöü,r=eve,s=hai", ModePlay, "eve", "hai", "#![äöü", nil}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -76,6 +83,9 @@ func TestParseStreamID(t *testing.T) { if str := streamid.String(); str != tt.streamID { t.Errorf("String() got String = %v, want %v", str, tt.streamID) } + if str := streamid.Username(); str != tt.wantUsername { + t.Errorf("Username() got String = %v, want %v", str, tt.wantUsername) + } }) } } From 5d42f7686bdc091d55101489100c7b8d11abb832 Mon Sep 17 00:00:00 2001 From: Paulson McIntyre Date: Tue, 26 Nov 2024 07:32:39 -0500 Subject: [PATCH 11/17] != => errors.Is --- stream/streamid_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stream/streamid_test.go b/stream/streamid_test.go index 5a04c88..d9fa88a 100644 --- a/stream/streamid_test.go +++ b/stream/streamid_test.go @@ -1,6 +1,7 @@ package stream import ( + "errors" "fmt" "testing" ) @@ -110,7 +111,7 @@ func TestNewStreamID(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { id, err := NewStreamID(tt.argName, tt.argPassword, tt.argMode) - if err != tt.wantErr { + if !errors.Is(err, tt.wantErr) { t.Errorf("ParseStreamID() error = %v, wantErr %v", err, tt.wantErr) } if err != nil { From 8c1ddab61e0cac68cfc4b1f9211c3668e2665f5a Mon Sep 17 00:00:00 2001 From: Paulson McIntyre Date: Tue, 26 Nov 2024 07:37:10 -0500 Subject: [PATCH 12/17] Fixing comment case --- auth/http.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/http.go b/auth/http.go index 3b57dc3..68a4c0e 100644 --- a/auth/http.go +++ b/auth/http.go @@ -32,7 +32,7 @@ type HTTPAuthConfig struct { PasswordParam string // POST Parameter containing stream passphrase } -// NewHttpAuth creates an Authenticator with a HTTP backend +// NewHTTPAuth creates an Authenticator with a HTTP backend func NewHTTPAuth(config HTTPAuthConfig) Authenticator { return &httpAuth{ config: config, From 3f7a858b876399fa24081e4488466a86e7756595 Mon Sep 17 00:00:00 2001 From: Paulson McIntyre Date: Thu, 28 Nov 2024 10:03:42 -0500 Subject: [PATCH 13/17] Using new format for get stats --- srt/server.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/srt/server.go b/srt/server.go index a54a524..2b2d59d 100644 --- a/srt/server.go +++ b/srt/server.go @@ -332,8 +332,8 @@ func (s *ServerImpl) registerForStats(ctx context.Context, conn *srtConn) { func (s *ServerImpl) GetStatistics() []*relay.StreamStatistics { streams := s.relay.GetStatistics() for _, st := range streams { - //stream.URL = fmt.Sprintf("srt://%s?streamid=#!::m=request,r=%s", s.config.PublicAddress, stream.Name) - st.URL = fmt.Sprintf("srt://%s?streamid=play/%s", s.config.PublicAddress, st.Name) + st.URL = fmt.Sprintf("srt://%s?streamid=#!::m=request,r=%s", s.config.PublicAddress, st.Name) // New format + //st.URL = fmt.Sprintf("srt://%s?streamid=play/%s", s.config.PublicAddress, st.Name) // Old format } return streams } From ac70c5325a300a4ccd0124c6a17591957a77bbf5 Mon Sep 17 00:00:00 2001 From: Paulson McIntyre Date: Thu, 28 Nov 2024 10:07:16 -0500 Subject: [PATCH 14/17] Test update Using new format for get stats --- srt/server_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/srt/server_test.go b/srt/server_test.go index d7d3187..c22c791 100644 --- a/srt/server_test.go +++ b/srt/server_test.go @@ -46,7 +46,8 @@ func TestServerImpl_GetStatistics(t *testing.T) { streams := s.GetStatistics() expected := []*relay.StreamStatistics{ - {Name: "s1", URL: "srt://testserver.de:1337?streamid=play/s1", Clients: 2, Created: streams[0].Created}, + //{Name: "s1", URL: "srt://testserver.de:1337?streamid=play/s1", Clients: 2, Created: streams[0].Created}, + {Name: "s1", URL: "srt://testserver.de:1337?streamid=#!::m=request,r=s1", Clients: 2, Created: streams[0].Created}, } if err := compareStats(streams, expected); err != nil { t.Error(err) From 01a9bfdf7414dd0a5ee4f73d0fbd4d8d077d7351 Mon Sep 17 00:00:00 2001 From: Paulson McIntyre Date: Thu, 28 Nov 2024 10:07:47 -0500 Subject: [PATCH 15/17] Fix builtin overlap --- srt/server_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/srt/server_test.go b/srt/server_test.go index c22c791..c7fe456 100644 --- a/srt/server_test.go +++ b/srt/server_test.go @@ -66,8 +66,8 @@ func (s *testSocket) Read(b []byte) (int, error) { if !ok { return 0, io.EOF } - len := copy(b, buf) - return len, nil + length := copy(b, buf) + return length, nil } func (s *testSocket) Write(b []byte) (int, error) { From 31cfd3435d7dbf1e91f420a2eb3deedf946a5b47 Mon Sep 17 00:00:00 2001 From: Paulson McIntyre Date: Thu, 28 Nov 2024 10:16:28 -0500 Subject: [PATCH 16/17] doc++ --- srt/server_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/srt/server_test.go b/srt/server_test.go index c7fe456..311f5ed 100644 --- a/srt/server_test.go +++ b/srt/server_test.go @@ -46,8 +46,8 @@ func TestServerImpl_GetStatistics(t *testing.T) { streams := s.GetStatistics() expected := []*relay.StreamStatistics{ - //{Name: "s1", URL: "srt://testserver.de:1337?streamid=play/s1", Clients: 2, Created: streams[0].Created}, - {Name: "s1", URL: "srt://testserver.de:1337?streamid=#!::m=request,r=s1", Clients: 2, Created: streams[0].Created}, + //{Name: "s1", URL: "srt://testserver.de:1337?streamid=play/s1", Clients: 2, Created: streams[0].Created}, // Old Format + {Name: "s1", URL: "srt://testserver.de:1337?streamid=#!::m=request,r=s1", Clients: 2, Created: streams[0].Created}, // New Format } if err := compareStats(streams, expected); err != nil { t.Error(err) From 8399e70d769667df4f039a30587a03fb17fd8216 Mon Sep 17 00:00:00 2001 From: Anton Schubert Date: Thu, 26 Dec 2024 15:25:43 +0100 Subject: [PATCH 17/17] remove comments --- srt/server.go | 1 - srt/server_test.go | 1 - 2 files changed, 2 deletions(-) diff --git a/srt/server.go b/srt/server.go index 2b2d59d..8b61971 100644 --- a/srt/server.go +++ b/srt/server.go @@ -333,7 +333,6 @@ func (s *ServerImpl) GetStatistics() []*relay.StreamStatistics { streams := s.relay.GetStatistics() for _, st := range streams { st.URL = fmt.Sprintf("srt://%s?streamid=#!::m=request,r=%s", s.config.PublicAddress, st.Name) // New format - //st.URL = fmt.Sprintf("srt://%s?streamid=play/%s", s.config.PublicAddress, st.Name) // Old format } return streams } diff --git a/srt/server_test.go b/srt/server_test.go index 311f5ed..5217b44 100644 --- a/srt/server_test.go +++ b/srt/server_test.go @@ -46,7 +46,6 @@ func TestServerImpl_GetStatistics(t *testing.T) { streams := s.GetStatistics() expected := []*relay.StreamStatistics{ - //{Name: "s1", URL: "srt://testserver.de:1337?streamid=play/s1", Clients: 2, Created: streams[0].Created}, // Old Format {Name: "s1", URL: "srt://testserver.de:1337?streamid=#!::m=request,r=s1", Clients: 2, Created: streams[0].Created}, // New Format } if err := compareStats(streams, expected); err != nil {