mirror of https://github.com/v2ray/v2ray-core
better handling of nil stream settings
parent
3d3f0a96d6
commit
6c4850634b
|
@ -24,20 +24,16 @@ func RegisterTransportDialer(protocol string, dialer Dialer) error {
|
||||||
func Dial(ctx context.Context, dest net.Destination) (Connection, error) {
|
func Dial(ctx context.Context, dest net.Destination) (Connection, error) {
|
||||||
if dest.Network == net.Network_TCP {
|
if dest.Network == net.Network_TCP {
|
||||||
streamSettings := StreamSettingsFromContext(ctx)
|
streamSettings := StreamSettingsFromContext(ctx)
|
||||||
var protocol string
|
if streamSettings == nil {
|
||||||
if streamSettings != nil {
|
s, err := ToMemoryStreamConfig(nil)
|
||||||
protocol = streamSettings.ProtocolName
|
|
||||||
} else {
|
|
||||||
protocol = "tcp"
|
|
||||||
pSettings, err := CreateTransportConfigByName(protocol)
|
|
||||||
if err != 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{
|
streamSettings = s
|
||||||
ProtocolName: protocol,
|
ctx = ContextWithStreamSettings(ctx, streamSettings)
|
||||||
ProtocolSettings: pSettings,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protocol = streamSettings.ProtocolName
|
||||||
dialer := transportDialerCache[protocol]
|
dialer := transportDialerCache[protocol]
|
||||||
if dialer == nil {
|
if dialer == nil {
|
||||||
return nil, newError(protocol, " dialer not registered").AtError()
|
return nil, newError(protocol, " dialer not registered").AtError()
|
||||||
|
|
|
@ -29,6 +29,15 @@ type Listener interface {
|
||||||
|
|
||||||
func ListenTCP(ctx context.Context, address net.Address, port net.Port, handler ConnHandler) (Listener, error) {
|
func ListenTCP(ctx context.Context, address net.Address, port net.Port, handler ConnHandler) (Listener, error) {
|
||||||
settings := StreamSettingsFromContext(ctx)
|
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
|
protocol := settings.ProtocolName
|
||||||
listenFunc := transportListenerCache[protocol]
|
listenFunc := transportListenerCache[protocol]
|
||||||
if listenFunc == nil {
|
if listenFunc == nil {
|
||||||
|
|
Loading…
Reference in New Issue