mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-22 13:16:07 +03:00
3fb67f065a
* Add fingerprint xray_random xray_random means to pick a random uTLS fingerprint at the core startup This way, the fingerprint is stable for a user for some days. While there is no identifiable signature for the whole xray community * Fingerprint "random" refine Exclude old fingerprint from RNG
56 lines
1.9 KiB
Go
56 lines
1.9 KiB
Go
package tcp
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/xtls/xray-core/common"
|
|
"github.com/xtls/xray-core/common/net"
|
|
"github.com/xtls/xray-core/common/session"
|
|
"github.com/xtls/xray-core/transport/internet"
|
|
"github.com/xtls/xray-core/transport/internet/stat"
|
|
"github.com/xtls/xray-core/transport/internet/tls"
|
|
"github.com/xtls/xray-core/transport/internet/xtls"
|
|
)
|
|
|
|
// Dial dials a new TCP connection to the given destination.
|
|
func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (stat.Connection, error) {
|
|
newError("dialing TCP to ", dest).WriteToLog(session.ExportIDToError(ctx))
|
|
conn, err := internet.DialSystem(ctx, dest, streamSettings.SocketSettings)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if config := tls.ConfigFromStreamSettings(streamSettings); config != nil {
|
|
tlsConfig := config.GetTLSConfig(tls.WithDestination(dest))
|
|
if fingerprint, ok := tls.GetFingerprint(ctx, config.Fingerprint); ok {
|
|
conn = tls.UClient(conn, tlsConfig, fingerprint)
|
|
if err := conn.(*tls.UConn).Handshake(); err != nil {
|
|
return nil, err
|
|
}
|
|
} else {
|
|
conn = tls.Client(conn, tlsConfig)
|
|
}
|
|
} else if config := xtls.ConfigFromStreamSettings(streamSettings); config != nil {
|
|
xtlsConfig := config.GetXTLSConfig(xtls.WithDestination(dest))
|
|
conn = xtls.Client(conn, xtlsConfig)
|
|
}
|
|
|
|
tcpSettings := streamSettings.ProtocolSettings.(*Config)
|
|
if tcpSettings.HeaderSettings != nil {
|
|
headerConfig, err := tcpSettings.HeaderSettings.GetInstance()
|
|
if err != nil {
|
|
return nil, newError("failed to get header settings").Base(err).AtError()
|
|
}
|
|
auth, err := internet.CreateConnectionAuthenticator(headerConfig)
|
|
if err != nil {
|
|
return nil, newError("failed to create header authenticator").Base(err).AtError()
|
|
}
|
|
conn = auth.Client(conn)
|
|
}
|
|
return stat.Connection(conn), nil
|
|
}
|
|
|
|
func init() {
|
|
common.Must(internet.RegisterTransportDialer(protocolName, Dial))
|
|
}
|