mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 15:36:41 -05:00
Add XTLS support to DomainSocket (#241)
This commit is contained in:
parent
65565572d3
commit
cde63bfac1
@ -496,8 +496,8 @@ func (c *StreamConfig) Build() (*internet.StreamConfig, error) {
|
|||||||
config.SecurityType = tm.Type
|
config.SecurityType = tm.Type
|
||||||
}
|
}
|
||||||
if strings.EqualFold(c.Security, "xtls") {
|
if strings.EqualFold(c.Security, "xtls") {
|
||||||
if config.ProtocolName != "tcp" {
|
if config.ProtocolName != "tcp" && config.ProtocolName != "domainsocket" {
|
||||||
return nil, newError("XTLS only supports TCP for now.")
|
return nil, newError("XTLS only supports TCP and DomainSocket for now.")
|
||||||
}
|
}
|
||||||
xtlsSettings := c.XTLSSettings
|
xtlsSettings := c.XTLSSettings
|
||||||
if xtlsSettings == nil {
|
if xtlsSettings == nil {
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/transport/internet"
|
"v2ray.com/core/transport/internet"
|
||||||
"v2ray.com/core/transport/internet/tls"
|
"v2ray.com/core/transport/internet/tls"
|
||||||
|
"v2ray.com/core/transport/internet/xtls"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (internet.Connection, error) {
|
func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (internet.Connection, error) {
|
||||||
@ -27,6 +28,8 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
|
|||||||
|
|
||||||
if config := tls.ConfigFromStreamSettings(streamSettings); config != nil {
|
if config := tls.ConfigFromStreamSettings(streamSettings); config != nil {
|
||||||
return tls.Client(conn, config.GetTLSConfig(tls.WithDestination(dest))), nil
|
return tls.Client(conn, config.GetTLSConfig(tls.WithDestination(dest))), nil
|
||||||
|
} else if config := xtls.ConfigFromStreamSettings(streamSettings); config != nil {
|
||||||
|
return xtls.Client(conn, config.GetXTLSConfig(xtls.WithDestination(dest))), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return conn, nil
|
return conn, nil
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pires/go-proxyproto"
|
"github.com/pires/go-proxyproto"
|
||||||
|
goxtls "github.com/xtls/go"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
@ -18,12 +19,14 @@ import (
|
|||||||
"v2ray.com/core/common/session"
|
"v2ray.com/core/common/session"
|
||||||
"v2ray.com/core/transport/internet"
|
"v2ray.com/core/transport/internet"
|
||||||
"v2ray.com/core/transport/internet/tls"
|
"v2ray.com/core/transport/internet/tls"
|
||||||
|
"v2ray.com/core/transport/internet/xtls"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Listener struct {
|
type Listener struct {
|
||||||
addr *net.UnixAddr
|
addr *net.UnixAddr
|
||||||
ln net.Listener
|
ln net.Listener
|
||||||
tlsConfig *gotls.Config
|
tlsConfig *gotls.Config
|
||||||
|
xtlsConfig *goxtls.Config
|
||||||
config *Config
|
config *Config
|
||||||
addConn internet.ConnHandler
|
addConn internet.ConnHandler
|
||||||
locker *fileLocker
|
locker *fileLocker
|
||||||
@ -73,6 +76,9 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti
|
|||||||
if config := tls.ConfigFromStreamSettings(streamSettings); config != nil {
|
if config := tls.ConfigFromStreamSettings(streamSettings); config != nil {
|
||||||
ln.tlsConfig = config.GetTLSConfig()
|
ln.tlsConfig = config.GetTLSConfig()
|
||||||
}
|
}
|
||||||
|
if config := xtls.ConfigFromStreamSettings(streamSettings); config != nil {
|
||||||
|
ln.xtlsConfig = config.GetXTLSConfig()
|
||||||
|
}
|
||||||
|
|
||||||
go ln.run()
|
go ln.run()
|
||||||
|
|
||||||
@ -103,6 +109,8 @@ func (ln *Listener) run() {
|
|||||||
|
|
||||||
if ln.tlsConfig != nil {
|
if ln.tlsConfig != nil {
|
||||||
conn = tls.Server(conn, ln.tlsConfig)
|
conn = tls.Server(conn, ln.tlsConfig)
|
||||||
|
} else if ln.xtlsConfig != nil {
|
||||||
|
conn = xtls.Server(conn, ln.xtlsConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
ln.addConn(internet.Connection(conn))
|
ln.addConn(internet.Connection(conn))
|
||||||
|
Loading…
Reference in New Issue
Block a user