1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-02-16 05:05:21 -05:00

move port out of address

This commit is contained in:
v2ray
2015-12-16 23:53:38 +01:00
parent 4be7cd7908
commit 34a0cb0b70
34 changed files with 194 additions and 172 deletions

View File

@@ -6,6 +6,7 @@ import (
type Config interface {
Address() v2net.Address
Port() v2net.Port
Network() v2net.NetworkList
Timeout() int
}

View File

@@ -16,6 +16,7 @@ type DokodemoDoor struct {
config Config
accepting bool
address v2net.Address
port v2net.Port
space app.Space
}
@@ -24,6 +25,7 @@ func NewDokodemoDoor(space app.Space, config Config) *DokodemoDoor {
config: config,
space: space,
address: config.Address(),
port: config.Port(),
}
}
@@ -71,7 +73,7 @@ func (this *DokodemoDoor) handleUDPPackets(udpConn *net.UDPConn) {
return
}
packet := v2net.NewPacket(v2net.NewUDPDestination(this.address), buffer, false)
packet := v2net.NewPacket(v2net.UDPDestination(this.address, this.port), buffer, false)
ray := this.space.PacketDispatcher().DispatchToOutbound(packet)
close(ray.InboundInput())
@@ -112,7 +114,7 @@ func (this *DokodemoDoor) AcceptTCPConnections(tcpListener *net.TCPListener) {
func (this *DokodemoDoor) HandleTCPConnection(conn *net.TCPConn) {
defer conn.Close()
packet := v2net.NewPacket(v2net.NewTCPDestination(this.address), nil, true)
packet := v2net.NewPacket(v2net.TCPDestination(this.address, this.port), nil, true)
ray := this.space.PacketDispatcher().DispatchToOutbound(packet)
var inputFinish, outputFinish sync.Mutex

View File

@@ -43,7 +43,7 @@ func TestDokodemoTCP(t *testing.T) {
ProtocolValue: "dokodemo-door",
SettingsValue: &json.DokodemoConfig{
Host: v2netjson.NewIPHost(net.ParseIP("127.0.0.1")),
Port: port,
PortValue: port,
NetworkList: &networkList,
TimeoutValue: 0,
},
@@ -105,7 +105,7 @@ func TestDokodemoUDP(t *testing.T) {
ProtocolValue: "dokodemo-door",
SettingsValue: &json.DokodemoConfig{
Host: v2netjson.NewIPHost(net.ParseIP("127.0.0.1")),
Port: port,
PortValue: port,
NetworkList: &networkList,
TimeoutValue: 0,
},

View File

@@ -8,19 +8,23 @@ import (
type DokodemoConfig struct {
Host *v2netjson.Host `json:"address"`
Port v2net.Port `json:"port"`
PortValue v2net.Port `json:"port"`
NetworkList *v2netjson.NetworkList `json:"network"`
TimeoutValue int `json:"timeout"`
}
func (this *DokodemoConfig) Address() v2net.Address {
if this.Host.IsIP() {
return v2net.IPAddress(this.Host.IP(), this.Port)
return v2net.IPAddress(this.Host.IP())
} else {
return v2net.DomainAddress(this.Host.Domain(), this.Port)
return v2net.DomainAddress(this.Host.Domain())
}
}
func (this *DokodemoConfig) Port() v2net.Port {
return this.PortValue
}
func (this *DokodemoConfig) Network() v2net.NetworkList {
return this.NetworkList
}