Przeglądaj źródła

remove hard type convertion on tcp config

Darien Raymond 8 lat temu
rodzic
commit
ad996f4db8
1 zmienionych plików z 11 dodań i 3 usunięć
  1. 11 3
      transport/internet/tcp/dialer.go

+ 11 - 3
transport/internet/tcp/dialer.go

@@ -11,12 +11,18 @@ import (
 	v2tls "v2ray.com/core/transport/internet/tls"
 )
 
+func getTCPSettingsFromContext(ctx context.Context) *Config {
+	rawTCPSettings := internet.TransportSettingsFromContext(ctx)
+	if rawTCPSettings == nil {
+		return nil
+	}
+	return rawTCPSettings.(*Config)
+}
+
 func Dial(ctx context.Context, dest v2net.Destination) (internet.Connection, error) {
 	log.Trace(newError("dailing TCP to ", dest))
 	src := internet.DialerSourceFromContext(ctx)
 
-	tcpSettings := internet.TransportSettingsFromContext(ctx).(*Config)
-
 	conn, err := internet.DialSystem(ctx, src, dest)
 	if err != nil {
 		return nil, err
@@ -31,7 +37,9 @@ func Dial(ctx context.Context, dest v2net.Destination) (internet.Connection, err
 			conn = tls.Client(conn, config)
 		}
 	}
-	if tcpSettings.HeaderSettings != nil {
+
+	tcpSettings := getTCPSettingsFromContext(ctx)
+	if tcpSettings != nil && tcpSettings.HeaderSettings != nil {
 		headerConfig, err := tcpSettings.HeaderSettings.GetInstance()
 		if err != nil {
 			return nil, newError("failed to get header settings").Base(err).AtError()