From 8a5f37dad7d1ec7c8e36501948f7cdd883256355 Mon Sep 17 00:00:00 2001 From: v2ray Date: Sun, 12 Jun 2016 22:54:33 +0200 Subject: [PATCH] check if address is set --- proxy/dokodemo/config_json.go | 4 +++- proxy/dokodemo/dokodemo.go | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/proxy/dokodemo/config_json.go b/proxy/dokodemo/config_json.go index f13e3de5..1d6c0a59 100644 --- a/proxy/dokodemo/config_json.go +++ b/proxy/dokodemo/config_json.go @@ -22,7 +22,9 @@ func (this *Config) UnmarshalJSON(data []byte) error { if err := json.Unmarshal(data, rawConfig); err != nil { return errors.New("Dokodemo: Failed to parse config: " + err.Error()) } - this.Address = rawConfig.Host.Address + if rawConfig.Host != nil { + this.Address = rawConfig.Host.Address + } this.Port = rawConfig.PortValue this.Network = rawConfig.NetworkList this.Timeout = rawConfig.TimeoutValue diff --git a/proxy/dokodemo/dokodemo.go b/proxy/dokodemo/dokodemo.go index 9848b0c9..6f588dea 100644 --- a/proxy/dokodemo/dokodemo.go +++ b/proxy/dokodemo/dokodemo.go @@ -129,7 +129,7 @@ func (this *DokodemoDoor) ListenTCP() error { func (this *DokodemoDoor) HandleTCPConnection(conn *hub.Connection) { defer conn.Close() - dest := v2net.TCPDestination(this.address, this.port) + var dest v2net.Destination if this.config.FollowRedirect { originalDest := GetOriginalDestination(conn) if originalDest != nil { @@ -137,6 +137,14 @@ func (this *DokodemoDoor) HandleTCPConnection(conn *hub.Connection) { dest = originalDest } } + if dest == nil && this.address != nil && this.port > v2net.Port(0) { + dest = v2net.TCPDestination(this.address, this.port) + } + + if dest == nil { + log.Info("Dokodemo: Unknown destination, stop forwarding...") + return + } ray := this.packetDispatcher.DispatchToOutbound(dest) defer ray.InboundOutput().Release()