mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -05:00
fix destination from addr
This commit is contained in:
parent
ccf1bf25b6
commit
cc92973daf
@ -17,8 +17,15 @@ type Destination interface {
|
||||
IsUDP() bool // True if destination is reachable via UDP
|
||||
}
|
||||
|
||||
func TCPDestinationFromAddr(addr *net.TCPAddr) Destination {
|
||||
return TCPDestination(IPAddress(addr.IP), Port(addr.Port))
|
||||
func DestinationFromAddr(addr net.Addr) Destination {
|
||||
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
|
||||
@ -26,10 +33,6 @@ func TCPDestination(address Address, port Port) Destination {
|
||||
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
|
||||
func UDPDestination(address Address, port Port) Destination {
|
||||
return &udpDestination{address: address, port: port}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package dokodemo
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
@ -151,7 +150,7 @@ func (this *DokodemoDoor) HandleTCPConnection(conn internet.Connection) {
|
||||
log.Info("Dokodemo: Handling request to ", dest)
|
||||
|
||||
ray := this.packetDispatcher.DispatchToOutbound(this.meta, &proxy.SessionInfo{
|
||||
Source: v2net.TCPDestinationFromAddr(conn.RemoteAddr().(*net.TCPAddr)),
|
||||
Source: v2net.DestinationFromAddr(conn.RemoteAddr()),
|
||||
Destination: dest,
|
||||
})
|
||||
defer ray.InboundOutput().Release()
|
||||
|
@ -120,7 +120,7 @@ func (this *Server) handleConnection(conn internet.Connection) {
|
||||
}
|
||||
log.Access(conn.RemoteAddr(), request.URL, log.AccessAccepted, "")
|
||||
session := &proxy.SessionInfo{
|
||||
Source: v2net.TCPDestinationFromAddr(conn.RemoteAddr().(*net.TCPAddr)),
|
||||
Source: v2net.DestinationFromAddr(conn.RemoteAddr()),
|
||||
Destination: dest,
|
||||
}
|
||||
if strings.ToUpper(request.Method) == "CONNECT" {
|
||||
|
@ -4,7 +4,6 @@ package shadowsocks
|
||||
import (
|
||||
"crypto/rand"
|
||||
"io"
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
@ -206,7 +205,7 @@ func (this *Server) handleConnection(conn internet.Connection) {
|
||||
log.Info("Shadowsocks: Tunnelling request to ", dest)
|
||||
|
||||
ray := this.packetDispatcher.DispatchToOutbound(this.meta, &proxy.SessionInfo{
|
||||
Source: v2net.TCPDestinationFromAddr(conn.RemoteAddr().(*net.TCPAddr)),
|
||||
Source: v2net.DestinationFromAddr(conn.RemoteAddr()),
|
||||
Destination: dest,
|
||||
})
|
||||
defer ray.InboundOutput().Release()
|
||||
|
@ -3,7 +3,6 @@ package socks
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -120,7 +119,7 @@ func (this *Server) handleConnection(connection internet.Connection) {
|
||||
return
|
||||
}
|
||||
|
||||
clientAddr := v2net.TCPDestinationFromAddr(connection.RemoteAddr().(*net.TCPAddr))
|
||||
clientAddr := v2net.DestinationFromAddr(connection.RemoteAddr())
|
||||
if err != nil && err == protocol.Socks4Downgrade {
|
||||
this.handleSocks4(clientAddr, reader, writer, auth4)
|
||||
} else {
|
||||
|
@ -2,7 +2,6 @@ package inbound
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
@ -165,7 +164,7 @@ func (this *VMessInboundHandler) HandleConnection(connection internet.Connection
|
||||
connection.SetReusable(request.Option.Has(protocol.RequestOptionConnectionReuse))
|
||||
|
||||
ray := this.packetDispatcher.DispatchToOutbound(this.meta, &proxy.SessionInfo{
|
||||
Source: v2net.TCPDestinationFromAddr(connection.RemoteAddr().(*net.TCPAddr)),
|
||||
Source: v2net.DestinationFromAddr(connection.RemoteAddr()),
|
||||
Destination: request.Destination(),
|
||||
})
|
||||
input := ray.InboundInput()
|
||||
|
Loading…
Reference in New Issue
Block a user