rename SRTP

pull/2034/head
v2ray 2016-08-07 15:05:05 +02:00
parent 4a7400ef2a
commit 81855469aa
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
3 changed files with 10 additions and 10 deletions

View File

@ -16,36 +16,36 @@ type Config struct {
PayloadType byte PayloadType byte
} }
type ObfuscatorSRTP struct { type SRTP struct {
header uint16 header uint16
number uint16 number uint16
} }
func (this *ObfuscatorSRTP) Overhead() int { func (this *SRTP) Overhead() int {
return 4 return 4
} }
func (this *ObfuscatorSRTP) Open(payload *alloc.Buffer) bool { func (this *SRTP) Open(payload *alloc.Buffer) bool {
payload.SliceFrom(this.Overhead()) payload.SliceFrom(this.Overhead())
return true return true
} }
func (this *ObfuscatorSRTP) Seal(payload *alloc.Buffer) { func (this *SRTP) Seal(payload *alloc.Buffer) {
this.number++ this.number++
payload.PrependUint16(this.number) payload.PrependUint16(this.number)
payload.PrependUint16(this.header) payload.PrependUint16(this.header)
} }
type ObfuscatorSRTPFactory struct { type SRTPFactory struct {
} }
func (this ObfuscatorSRTPFactory) Create(rawSettings internet.AuthenticatorConfig) internet.Authenticator { func (this SRTPFactory) Create(rawSettings internet.AuthenticatorConfig) internet.Authenticator {
return &ObfuscatorSRTP{ return &SRTP{
header: 0xB5E8, header: 0xB5E8,
number: uint16(rand.Intn(65536)), number: uint16(rand.Intn(65536)),
} }
} }
func init() { func init() {
internet.RegisterAuthenticator("srtp", ObfuscatorSRTPFactory{}, func() interface{} { return new(Config) }) internet.RegisterAuthenticator("srtp", SRTPFactory{}, func() interface{} { return new(Config) })
} }

View File

@ -13,7 +13,7 @@ func TestSRTPOpenSeal(t *testing.T) {
content := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'} content := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}
payload := alloc.NewLocalBuffer(2048).Clear().Append(content) payload := alloc.NewLocalBuffer(2048).Clear().Append(content)
srtp := ObfuscatorSRTP{} srtp := SRTP{}
srtp.Seal(payload) srtp.Seal(payload)
assert.Int(payload.Len()).GreaterThan(len(content)) assert.Int(payload.Len()).GreaterThan(len(content))
assert.Bool(srtp.Open(payload)).IsTrue() assert.Bool(srtp.Open(payload)).IsTrue()

View File

@ -42,7 +42,7 @@ func TestConnectionReadWrite(t *testing.T) {
upReader, upWriter := io.Pipe() upReader, upWriter := io.Pipe()
downReader, downWriter := 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 := NewConnection(1, upWriter, &net.UDPAddr{IP: v2net.LocalHostIP.IP(), Port: 1}, &net.UDPAddr{IP: v2net.LocalHostIP.IP(), Port: 2}, auth)
connClient.FetchInputFrom(downReader) connClient.FetchInputFrom(downReader)