1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-06-21 18:29:55 -04:00

introduce address family in v2net

This commit is contained in:
v2ray
2016-08-14 18:14:12 +02:00
parent a9d583b92f
commit 4419f1e3d6
15 changed files with 73 additions and 78 deletions

View File

@@ -47,7 +47,7 @@ func NewFreedomConnection(config *Config, space app.Space, meta *proxy.OutboundH
// @Private
func (this *FreedomConnection) ResolveIP(destination v2net.Destination) v2net.Destination {
if !destination.Address().IsDomain() {
if !destination.Address().Family().IsDomain() {
return destination
}
@@ -76,7 +76,7 @@ func (this *FreedomConnection) Dispatch(destination v2net.Destination, payload *
defer ray.OutboundOutput().Close()
var conn internet.Connection
if this.domainStrategy == DomainStrategyUseIP && destination.Address().IsDomain() {
if this.domainStrategy == DomainStrategyUseIP && destination.Address().Family().IsDomain() {
destination = this.ResolveIP(destination)
}
err := retry.Timed(5, 100).On(func() error {

View File

@@ -132,14 +132,14 @@ func (this *Server) handlerUDPPayload(payload *alloc.Buffer, source v2net.Destin
writer := crypto.NewCryptionWriter(stream, response)
switch {
case request.Address.IsIPv4():
switch request.Address.Family() {
case v2net.AddressFamilyIPv4:
writer.Write([]byte{AddrTypeIPv4})
writer.Write(request.Address.IP())
case request.Address.IsIPv6():
case v2net.AddressFamilyIPv6:
writer.Write([]byte{AddrTypeIPv6})
writer.Write(request.Address.IP())
case request.Address.IsDomain():
case v2net.AddressFamilyDomain:
writer.Write([]byte{AddrTypeDomain, byte(len(request.Address.Domain()))})
writer.Write([]byte(request.Address.Domain()))
}

View File

@@ -26,12 +26,12 @@ func (request *Socks5UDPRequest) Destination() v2net.Destination {
func (request *Socks5UDPRequest) Write(buffer *alloc.Buffer) {
buffer.AppendBytes(0, 0, request.Fragment)
switch {
case request.Address.IsIPv4():
switch request.Address.Family() {
case v2net.AddressFamilyIPv4:
buffer.AppendBytes(AddrTypeIPv4).Append(request.Address.IP())
case request.Address.IsIPv6():
case v2net.AddressFamilyIPv6:
buffer.AppendBytes(AddrTypeIPv6).Append(request.Address.IP())
case request.Address.IsDomain():
case v2net.AddressFamilyDomain:
buffer.AppendBytes(AddrTypeDomain, byte(len(request.Address.Domain()))).Append([]byte(request.Address.Domain()))
}
buffer.AppendUint16(request.Port.Value())

View File

@@ -238,12 +238,12 @@ func (this *Server) handleUDP(reader io.Reader, writer *v2io.BufferedWriter) err
udpAddr := this.udpAddress
response.Port = udpAddr.Port()
switch {
case udpAddr.Address().IsIPv4():
switch udpAddr.Address().Family() {
case v2net.AddressFamilyIPv4:
response.SetIPv4(udpAddr.Address().IP())
case udpAddr.Address().IsIPv6():
case v2net.AddressFamilyIPv6:
response.SetIPv6(udpAddr.Address().IP())
case udpAddr.Address().IsDomain():
case v2net.AddressFamilyDomain:
response.SetDomain(udpAddr.Address().Domain())
}

View File

@@ -8,6 +8,7 @@ import (
"github.com/v2ray/v2ray-core/common/crypto"
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/proxy/vmess"
"github.com/v2ray/v2ray-core/transport"
@@ -62,14 +63,14 @@ func (this *ClientSession) EncodeRequestHeader(header *protocol.RequestHeader, w
buffer = append(buffer, this.responseHeader, byte(header.Option), byte(0), byte(0), byte(header.Command))
buffer = header.Port.Bytes(buffer)
switch {
case header.Address.IsIPv4():
switch header.Address.Family() {
case v2net.AddressFamilyIPv4:
buffer = append(buffer, AddrTypeIPv4)
buffer = append(buffer, header.Address.IP()...)
case header.Address.IsIPv6():
case v2net.AddressFamilyIPv6:
buffer = append(buffer, AddrTypeIPv6)
buffer = append(buffer, header.Address.IP()...)
case header.Address.IsDomain():
case v2net.AddressFamilyDomain:
buffer = append(buffer, AddrTypeDomain, byte(len(header.Address.Domain())))
buffer = append(buffer, header.Address.Domain()...)
}