1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

rename SRTP

This commit is contained in:
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
}
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) })
}

View File

@ -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()

View File

@ -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)