From 6543facd51fe1dd37e3fcec3c5ec9f21f5d50837 Mon Sep 17 00:00:00 2001 From: v2ray Date: Thu, 17 Dec 2015 00:58:45 +0100 Subject: [PATCH] converting from host to address directly --- common/net/json/host.go | 10 ++++++++++ proxy/dokodemo/json/json.go | 6 +----- proxy/vmess/outbound/json/outbound.go | 6 +----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/common/net/json/host.go b/common/net/json/host.go index 41fade702..80088f58b 100644 --- a/common/net/json/host.go +++ b/common/net/json/host.go @@ -3,6 +3,8 @@ package json import ( "encoding/json" "net" + + v2net "github.com/v2ray/v2ray-core/common/net" ) type Host struct { @@ -51,3 +53,11 @@ func (this *Host) IP() net.IP { func (this *Host) Domain() string { return this.domain } + +func (this *Host) Address() v2net.Address { + if this.IsIP() { + return v2net.IPAddress(this.IP()) + } else { + return v2net.DomainAddress(this.Domain()) + } +} diff --git a/proxy/dokodemo/json/json.go b/proxy/dokodemo/json/json.go index 839a6f4f6..7ae29db6a 100644 --- a/proxy/dokodemo/json/json.go +++ b/proxy/dokodemo/json/json.go @@ -14,11 +14,7 @@ type DokodemoConfig struct { } func (this *DokodemoConfig) Address() v2net.Address { - if this.Host.IsIP() { - return v2net.IPAddress(this.Host.IP()) - } else { - return v2net.DomainAddress(this.Host.Domain()) - } + return this.Host.Address() } func (this *DokodemoConfig) Port() v2net.Port { diff --git a/proxy/vmess/outbound/json/outbound.go b/proxy/vmess/outbound/json/outbound.go index fa273468f..b31196cdc 100644 --- a/proxy/vmess/outbound/json/outbound.go +++ b/proxy/vmess/outbound/json/outbound.go @@ -37,11 +37,7 @@ func (t *ConfigTarget) UnmarshalJSON(data []byte) error { log.Error("Address is not set in VMess outbound config.") return proxyconfig.BadConfiguration } - if rawConfig.Address.IsIP() { - t.Destination = v2net.TCPDestination(v2net.IPAddress(rawConfig.Address.IP()), rawConfig.Port) - } else { - t.Destination = v2net.TCPDestination(v2net.DomainAddress(rawConfig.Address.Domain()), rawConfig.Port) - } + t.Destination = v2net.TCPDestination(rawConfig.Address.Address(), rawConfig.Port) return nil }