mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-06 00:31:03 +00:00
Merge branch 'master' into websockwt
This commit is contained in:
47 files changed
+437
-184
No files matched your search
@@ -41,7 +41,7 @@ func CreateAuthenticator(name string, config AuthenticatorConfig) (Authenticator
|
||||
if !found {
|
||||
return nil, ErrAuthenticatorNotFound
|
||||
}
|
||||
return factory.Create(config.(AuthenticatorConfig)), nil
|
||||
return factory.Create(config), nil
|
||||
}
|
||||
|
||||
func CreateAuthenticatorConfig(rawConfig []byte) (string, AuthenticatorConfig, error) {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package internet_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
. "github.com/v2ray/v2ray-core/transport/internet"
|
||||
_ "github.com/v2ray/v2ray-core/transport/internet/authenticators/noop"
|
||||
_ "github.com/v2ray/v2ray-core/transport/internet/authenticators/srtp"
|
||||
_ "github.com/v2ray/v2ray-core/transport/internet/authenticators/utp"
|
||||
)
|
||||
|
||||
func TestAllAuthenticatorLoadable(t *testing.T) {
|
||||
assert := assert.On(t)
|
||||
|
||||
noopAuth, err := CreateAuthenticator("none", nil)
|
||||
assert.Error(err).IsNil()
|
||||
assert.Int(noopAuth.Overhead()).Equals(0)
|
||||
|
||||
srtp, err := CreateAuthenticator("srtp", nil)
|
||||
assert.Error(err).IsNil()
|
||||
assert.Int(srtp.Overhead()).Equals(4)
|
||||
|
||||
utp, err := CreateAuthenticator("utp", nil)
|
||||
assert.Error(err).IsNil()
|
||||
assert.Int(utp.Overhead()).Equals(4)
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package utp
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
"github.com/v2ray/v2ray-core/transport/internet"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Version byte
|
||||
}
|
||||
|
||||
type UTP struct {
|
||||
header byte
|
||||
extension byte
|
||||
connectionId uint16
|
||||
}
|
||||
|
||||
func (this *UTP) Overhead() int {
|
||||
return 4
|
||||
}
|
||||
|
||||
func (this *UTP) Open(payload *alloc.Buffer) bool {
|
||||
payload.SliceFrom(this.Overhead())
|
||||
return true
|
||||
}
|
||||
|
||||
func (this *UTP) Seal(payload *alloc.Buffer) {
|
||||
payload.PrependUint16(this.connectionId)
|
||||
payload.PrependBytes(this.header, this.extension)
|
||||
}
|
||||
|
||||
type UTPFactory struct{}
|
||||
|
||||
func (this UTPFactory) Create(rawSettings internet.AuthenticatorConfig) internet.Authenticator {
|
||||
return &UTP{
|
||||
header: 1,
|
||||
extension: 0,
|
||||
connectionId: uint16(rand.Intn(65536)),
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
internet.RegisterAuthenticator("utp", UTPFactory{}, func() interface{} { return new(Config) })
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package utp_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
. "github.com/v2ray/v2ray-core/transport/internet/authenticators/utp"
|
||||
)
|
||||
|
||||
func TestUTPOpenSeal(t *testing.T) {
|
||||
assert := assert.On(t)
|
||||
|
||||
content := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}
|
||||
payload := alloc.NewLocalBuffer(2048).Clear().Append(content)
|
||||
utp := UTP{}
|
||||
utp.Seal(payload)
|
||||
assert.Int(payload.Len()).GreaterThan(len(content))
|
||||
assert.Bool(utp.Open(payload)).IsTrue()
|
||||
assert.Bytes(content).Equals(payload.Bytes())
|
||||
}
|
||||
@@ -28,6 +28,10 @@ const (
|
||||
StreamSecurityTypeTLS StreamSecurityType = 1
|
||||
)
|
||||
|
||||
var (
|
||||
globalSessionCache = tls.NewLRUClientSessionCache(128)
|
||||
)
|
||||
|
||||
type TLSSettings struct {
|
||||
AllowInsecure bool
|
||||
Certs []tls.Certificate
|
||||
@@ -36,6 +40,7 @@ type TLSSettings struct {
|
||||
func (this *TLSSettings) GetTLSConfig() *tls.Config {
|
||||
config := &tls.Config{
|
||||
InsecureSkipVerify: this.AllowInsecure,
|
||||
ClientSessionCache: globalSessionCache,
|
||||
}
|
||||
|
||||
config.Certificates = this.Certs
|
||||
|
||||
@@ -56,7 +56,7 @@ func Dial(src v2net.Address, dest v2net.Destination, settings *StreamSettings) (
|
||||
}
|
||||
|
||||
config := settings.TLSSettings.GetTLSConfig()
|
||||
if dest.Address().IsDomain() {
|
||||
if dest.Address().Family().IsDomain() {
|
||||
config.ServerName = dest.Address().Domain()
|
||||
}
|
||||
tlsConn := tls.Client(connection, config)
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
"github.com/v2ray/v2ray-core/transport/ray"
|
||||
)
|
||||
|
||||
@@ -95,12 +96,14 @@ type UDPServer struct {
|
||||
sync.RWMutex
|
||||
conns map[string]*TimedInboundRay
|
||||
packetDispatcher dispatcher.PacketDispatcher
|
||||
meta *proxy.InboundHandlerMeta
|
||||
}
|
||||
|
||||
func NewUDPServer(packetDispatcher dispatcher.PacketDispatcher) *UDPServer {
|
||||
func NewUDPServer(meta *proxy.InboundHandlerMeta, packetDispatcher dispatcher.PacketDispatcher) *UDPServer {
|
||||
return &UDPServer{
|
||||
conns: make(map[string]*TimedInboundRay),
|
||||
packetDispatcher: packetDispatcher,
|
||||
meta: meta,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +132,11 @@ func (this *UDPServer) locateExistingAndDispatch(name string, payload *alloc.Buf
|
||||
return false
|
||||
}
|
||||
|
||||
func (this *UDPServer) Dispatch(source v2net.Destination, destination v2net.Destination, payload *alloc.Buffer, callback UDPResponseCallback) {
|
||||
func (this *UDPServer) Dispatch(session *proxy.SessionInfo, payload *alloc.Buffer, callback UDPResponseCallback) {
|
||||
source := session.Source
|
||||
destination := session.Destination
|
||||
|
||||
// TODO: Add user to destString
|
||||
destString := source.String() + "-" + destination.String()
|
||||
log.Debug("UDP Server: Dispatch request: ", destString)
|
||||
if this.locateExistingAndDispatch(destString, payload) {
|
||||
@@ -137,7 +144,7 @@ func (this *UDPServer) Dispatch(source v2net.Destination, destination v2net.Dest
|
||||
}
|
||||
|
||||
log.Info("UDP Server: establishing new connection for ", destString)
|
||||
inboundRay := this.packetDispatcher.DispatchToOutbound(destination)
|
||||
inboundRay := this.packetDispatcher.DispatchToOutbound(this.meta, session)
|
||||
timedInboundRay := NewTimedInboundRay(destString, inboundRay, this)
|
||||
outputStream := timedInboundRay.InboundInput()
|
||||
if outputStream != nil {
|
||||
|
||||
Reference in new issue
Block a user