1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 17:46:58 -05:00

fix destination from addr

This commit is contained in:
v2ray 2016-08-14 23:20:23 +02:00
parent ccf1bf25b6
commit cc92973daf
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
6 changed files with 14 additions and 15 deletions

View File

@ -17,8 +17,15 @@ type Destination interface {
IsUDP() bool // True if destination is reachable via UDP IsUDP() bool // True if destination is reachable via UDP
} }
func TCPDestinationFromAddr(addr *net.TCPAddr) Destination { func DestinationFromAddr(addr net.Addr) Destination {
return TCPDestination(IPAddress(addr.IP), Port(addr.Port)) switch addr := addr.(type) {
case *net.TCPAddr:
return TCPDestination(IPAddress(addr.IP), Port(addr.Port))
case *net.UDPAddr:
return UDPDestination(IPAddress(addr.IP), Port(addr.Port))
default:
panic("Unknown address type.")
}
} }
// TCPDestination creates a TCP destination with given address // TCPDestination creates a TCP destination with given address
@ -26,10 +33,6 @@ func TCPDestination(address Address, port Port) Destination {
return &tcpDestination{address: address, port: port} return &tcpDestination{address: address, port: port}
} }
func UDPDestinationFromAddr(addr *net.UDPAddr) Destination {
return UDPDestination(IPAddress(addr.IP), Port(addr.Port))
}
// UDPDestination creates a UDP destination with given address // UDPDestination creates a UDP destination with given address
func UDPDestination(address Address, port Port) Destination { func UDPDestination(address Address, port Port) Destination {
return &udpDestination{address: address, port: port} return &udpDestination{address: address, port: port}

View File

@ -1,7 +1,6 @@
package dokodemo package dokodemo
import ( import (
"net"
"sync" "sync"
"github.com/v2ray/v2ray-core/app" "github.com/v2ray/v2ray-core/app"
@ -151,7 +150,7 @@ func (this *DokodemoDoor) HandleTCPConnection(conn internet.Connection) {
log.Info("Dokodemo: Handling request to ", dest) log.Info("Dokodemo: Handling request to ", dest)
ray := this.packetDispatcher.DispatchToOutbound(this.meta, &proxy.SessionInfo{ ray := this.packetDispatcher.DispatchToOutbound(this.meta, &proxy.SessionInfo{
Source: v2net.TCPDestinationFromAddr(conn.RemoteAddr().(*net.TCPAddr)), Source: v2net.DestinationFromAddr(conn.RemoteAddr()),
Destination: dest, Destination: dest,
}) })
defer ray.InboundOutput().Release() defer ray.InboundOutput().Release()

View File

@ -120,7 +120,7 @@ func (this *Server) handleConnection(conn internet.Connection) {
} }
log.Access(conn.RemoteAddr(), request.URL, log.AccessAccepted, "") log.Access(conn.RemoteAddr(), request.URL, log.AccessAccepted, "")
session := &proxy.SessionInfo{ session := &proxy.SessionInfo{
Source: v2net.TCPDestinationFromAddr(conn.RemoteAddr().(*net.TCPAddr)), Source: v2net.DestinationFromAddr(conn.RemoteAddr()),
Destination: dest, Destination: dest,
} }
if strings.ToUpper(request.Method) == "CONNECT" { if strings.ToUpper(request.Method) == "CONNECT" {

View File

@ -4,7 +4,6 @@ package shadowsocks
import ( import (
"crypto/rand" "crypto/rand"
"io" "io"
"net"
"sync" "sync"
"github.com/v2ray/v2ray-core/app" "github.com/v2ray/v2ray-core/app"
@ -206,7 +205,7 @@ func (this *Server) handleConnection(conn internet.Connection) {
log.Info("Shadowsocks: Tunnelling request to ", dest) log.Info("Shadowsocks: Tunnelling request to ", dest)
ray := this.packetDispatcher.DispatchToOutbound(this.meta, &proxy.SessionInfo{ ray := this.packetDispatcher.DispatchToOutbound(this.meta, &proxy.SessionInfo{
Source: v2net.TCPDestinationFromAddr(conn.RemoteAddr().(*net.TCPAddr)), Source: v2net.DestinationFromAddr(conn.RemoteAddr()),
Destination: dest, Destination: dest,
}) })
defer ray.InboundOutput().Release() defer ray.InboundOutput().Release()

View File

@ -3,7 +3,6 @@ package socks
import ( import (
"errors" "errors"
"io" "io"
"net"
"sync" "sync"
"time" "time"
@ -120,7 +119,7 @@ func (this *Server) handleConnection(connection internet.Connection) {
return return
} }
clientAddr := v2net.TCPDestinationFromAddr(connection.RemoteAddr().(*net.TCPAddr)) clientAddr := v2net.DestinationFromAddr(connection.RemoteAddr())
if err != nil && err == protocol.Socks4Downgrade { if err != nil && err == protocol.Socks4Downgrade {
this.handleSocks4(clientAddr, reader, writer, auth4) this.handleSocks4(clientAddr, reader, writer, auth4)
} else { } else {

View File

@ -2,7 +2,6 @@ package inbound
import ( import (
"io" "io"
"net"
"sync" "sync"
"github.com/v2ray/v2ray-core/app" "github.com/v2ray/v2ray-core/app"
@ -165,7 +164,7 @@ func (this *VMessInboundHandler) HandleConnection(connection internet.Connection
connection.SetReusable(request.Option.Has(protocol.RequestOptionConnectionReuse)) connection.SetReusable(request.Option.Has(protocol.RequestOptionConnectionReuse))
ray := this.packetDispatcher.DispatchToOutbound(this.meta, &proxy.SessionInfo{ ray := this.packetDispatcher.DispatchToOutbound(this.meta, &proxy.SessionInfo{
Source: v2net.TCPDestinationFromAddr(connection.RemoteAddr().(*net.TCPAddr)), Source: v2net.DestinationFromAddr(connection.RemoteAddr()),
Destination: request.Destination(), Destination: request.Destination(),
}) })
input := ray.InboundInput() input := ray.InboundInput()