load srtp in main

pull/2034/head
v2ray 8 years ago
parent 6ffc24f895
commit c7d6302292
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

@ -25,6 +25,8 @@ import (
_ "github.com/v2ray/v2ray-core/transport/internet/kcp" _ "github.com/v2ray/v2ray-core/transport/internet/kcp"
_ "github.com/v2ray/v2ray-core/transport/internet/tcp" _ "github.com/v2ray/v2ray-core/transport/internet/tcp"
_ "github.com/v2ray/v2ray-core/transport/internet/udp" _ "github.com/v2ray/v2ray-core/transport/internet/udp"
_ "github.com/v2ray/v2ray-core/transport/internet/authenticators/srtp"
) )
var ( var (

@ -1,4 +1,4 @@
package obsrtp package srtp
import ( import (
"math/rand" "math/rand"

@ -7,6 +7,7 @@ import (
"github.com/v2ray/v2ray-core/common" "github.com/v2ray/v2ray-core/common"
"github.com/v2ray/v2ray-core/common/log" "github.com/v2ray/v2ray-core/common/log"
"github.com/v2ray/v2ray-core/transport/internet"
) )
func (this *Config) UnmarshalJSON(data []byte) error { func (this *Config) UnmarshalJSON(data []byte) error {
@ -66,7 +67,13 @@ func (this *Config) UnmarshalJSON(data []byte) error {
} }
} }
if len(jsonConfig.HeaderConfig) > 0 { if len(jsonConfig.HeaderConfig) > 0 {
this.HeaderConfig = jsonConfig.HeaderConfig name, config, err := internet.CreateAuthenticatorConfig(jsonConfig.HeaderConfig)
if err != nil {
log.Error("KCP|Config: Failed to parse header config: ", err)
return err
}
this.HeaderType = name
this.HeaderConfig = config
} }
return nil return nil

@ -10,7 +10,7 @@ import (
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/testing/assert" "github.com/v2ray/v2ray-core/testing/assert"
"github.com/v2ray/v2ray-core/transport/internet" "github.com/v2ray/v2ray-core/transport/internet"
"github.com/v2ray/v2ray-core/transport/internet/internal/obsrtp" "github.com/v2ray/v2ray-core/transport/internet/authenticators/srtp"
. "github.com/v2ray/v2ray-core/transport/internet/kcp" . "github.com/v2ray/v2ray-core/transport/internet/kcp"
) )
@ -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(obsrtp.ObfuscatorSRTPFactory{}.Create(nil), NewSimpleAuthenticator()) auth := internet.NewAuthenticatorChain(srtp.ObfuscatorSRTPFactory{}.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)

@ -16,14 +16,16 @@ var (
func DialKCP(src v2net.Address, dest v2net.Destination) (internet.Connection, error) { func DialKCP(src v2net.Address, dest v2net.Destination) (internet.Connection, error) {
udpDest := v2net.UDPDestination(dest.Address(), dest.Port()) udpDest := v2net.UDPDestination(dest.Address(), dest.Port())
log.Info("Dialling KCP to ", udpDest) log.Info("KCP|Dialer: Dialing KCP to ", udpDest)
conn, err := internet.DialToDest(src, udpDest) conn, err := internet.DialToDest(src, udpDest)
if err != nil { if err != nil {
log.Error("KCP|Dialer: Failed to dial to dest: ", err)
return nil, err return nil, err
} }
cpip, err := effectiveConfig.GetAuthenticator() cpip, err := effectiveConfig.GetAuthenticator()
if err != nil { if err != nil {
log.Error("KCP|Dialer: Failed to create authenticator: ", err)
return nil, err return nil, err
} }
conv := uint16(atomic.AddUint32(&globalConv, 1)) conv := uint16(atomic.AddUint32(&globalConv, 1))

Loading…
Cancel
Save