diff --git a/transport/internet/authenticators/srtp/srtp.go b/transport/internet/authenticators/srtp/srtp.go index bba706a52..0b4d9f006 100644 --- a/transport/internet/authenticators/srtp/srtp.go +++ b/transport/internet/authenticators/srtp/srtp.go @@ -16,36 +16,36 @@ type Config struct { PayloadType byte } -type ObfuscatorSRTP struct { +type SRTP struct { header uint16 number uint16 } -func (this *ObfuscatorSRTP) Overhead() int { +func (this *SRTP) Overhead() int { return 4 } -func (this *ObfuscatorSRTP) Open(payload *alloc.Buffer) bool { +func (this *SRTP) Open(payload *alloc.Buffer) bool { payload.SliceFrom(this.Overhead()) return true } -func (this *ObfuscatorSRTP) Seal(payload *alloc.Buffer) { +func (this *SRTP) Seal(payload *alloc.Buffer) { this.number++ payload.PrependUint16(this.number) payload.PrependUint16(this.header) } -type ObfuscatorSRTPFactory struct { +type SRTPFactory struct { } -func (this ObfuscatorSRTPFactory) Create(rawSettings internet.AuthenticatorConfig) internet.Authenticator { - return &ObfuscatorSRTP{ +func (this SRTPFactory) Create(rawSettings internet.AuthenticatorConfig) internet.Authenticator { + return &SRTP{ header: 0xB5E8, number: uint16(rand.Intn(65536)), } } func init() { - internet.RegisterAuthenticator("srtp", ObfuscatorSRTPFactory{}, func() interface{} { return new(Config) }) + internet.RegisterAuthenticator("srtp", SRTPFactory{}, func() interface{} { return new(Config) }) } diff --git a/transport/internet/authenticators/srtp/srtp_test.go b/transport/internet/authenticators/srtp/srtp_test.go index db25e99e8..7353ef5df 100644 --- a/transport/internet/authenticators/srtp/srtp_test.go +++ b/transport/internet/authenticators/srtp/srtp_test.go @@ -13,7 +13,7 @@ func TestSRTPOpenSeal(t *testing.T) { content := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'} payload := alloc.NewLocalBuffer(2048).Clear().Append(content) - srtp := ObfuscatorSRTP{} + srtp := SRTP{} srtp.Seal(payload) assert.Int(payload.Len()).GreaterThan(len(content)) assert.Bool(srtp.Open(payload)).IsTrue() diff --git a/transport/internet/kcp/connection_test.go b/transport/internet/kcp/connection_test.go index 8c6c067a5..c4ab5af4a 100644 --- a/transport/internet/kcp/connection_test.go +++ b/transport/internet/kcp/connection_test.go @@ -42,7 +42,7 @@ func TestConnectionReadWrite(t *testing.T) { upReader, upWriter := io.Pipe() downReader, downWriter := io.Pipe() - auth := internet.NewAuthenticatorChain(srtp.ObfuscatorSRTPFactory{}.Create(nil), NewSimpleAuthenticator()) + auth := internet.NewAuthenticatorChain(srtp.SRTPFactory{}.Create(nil), NewSimpleAuthenticator()) connClient := NewConnection(1, upWriter, &net.UDPAddr{IP: v2net.LocalHostIP.IP(), Port: 1}, &net.UDPAddr{IP: v2net.LocalHostIP.IP(), Port: 2}, auth) connClient.FetchInputFrom(downReader)