1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

better handling of nil stream settings

This commit is contained in:
Darien Raymond 2018-09-07 15:00:46 +02:00
parent 3d3f0a96d6
commit 6c4850634b
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 16 additions and 11 deletions

View File

@ -24,20 +24,16 @@ func RegisterTransportDialer(protocol string, dialer Dialer) error {
func Dial(ctx context.Context, dest net.Destination) (Connection, error) {
if dest.Network == net.Network_TCP {
streamSettings := StreamSettingsFromContext(ctx)
var protocol string
if streamSettings != nil {
protocol = streamSettings.ProtocolName
} else {
protocol = "tcp"
pSettings, err := CreateTransportConfigByName(protocol)
if streamSettings == nil {
s, err := ToMemoryStreamConfig(nil)
if err != nil {
return nil, newError("failed to create default config for protocol: ", protocol).Base(err)
return nil, newError("failed to create default stream settings").Base(err)
}
ctx = ContextWithStreamSettings(ctx, &MemoryStreamConfig{
ProtocolName: protocol,
ProtocolSettings: pSettings,
})
streamSettings = s
ctx = ContextWithStreamSettings(ctx, streamSettings)
}
protocol = streamSettings.ProtocolName
dialer := transportDialerCache[protocol]
if dialer == nil {
return nil, newError(protocol, " dialer not registered").AtError()

View File

@ -29,6 +29,15 @@ type Listener interface {
func ListenTCP(ctx context.Context, address net.Address, port net.Port, handler ConnHandler) (Listener, error) {
settings := StreamSettingsFromContext(ctx)
if settings == nil {
s, err := ToMemoryStreamConfig(nil)
if err != nil {
return nil, newError("failed to create default stream settings").Base(err)
}
settings = s
ctx = ContextWithStreamSettings(ctx, settings)
}
protocol := settings.ProtocolName
listenFunc := transportListenerCache[protocol]
if listenFunc == nil {