1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-18 02:16:10 -05:00

remove hard type convertion on tcp config

This commit is contained in:
Darien Raymond 2017-04-18 12:55:09 +02:00
parent 47b155b77f
commit ad996f4db8
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

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