1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-28 21:15:46 -05:00

connection session

This commit is contained in:
v2ray
2016-08-14 17:08:01 +02:00
parent a2651f4dfc
commit a9d583b92f
14 changed files with 82 additions and 29 deletions

View File

@@ -3,6 +3,7 @@ package socks
import (
"errors"
"io"
"net"
"sync"
"time"
@@ -119,7 +120,7 @@ func (this *Server) handleConnection(connection internet.Connection) {
return
}
clientAddr := connection.RemoteAddr().String()
clientAddr := v2net.TCPDestinationFromAddr(connection.RemoteAddr().(*net.TCPAddr))
if err != nil && err == protocol.Socks4Downgrade {
this.handleSocks4(clientAddr, reader, writer, auth4)
} else {
@@ -127,7 +128,7 @@ func (this *Server) handleConnection(connection internet.Connection) {
}
}
func (this *Server) handleSocks5(clientAddr string, reader *v2io.BufferedReader, writer *v2io.BufferedWriter, auth protocol.Socks5AuthenticationRequest) error {
func (this *Server) handleSocks5(clientAddr v2net.Destination, reader *v2io.BufferedReader, writer *v2io.BufferedWriter, auth protocol.Socks5AuthenticationRequest) error {
expectedAuthMethod := protocol.AuthNotRequired
if this.config.AuthType == AuthTypePassword {
expectedAuthMethod = protocol.AuthUserPass
@@ -219,10 +220,14 @@ func (this *Server) handleSocks5(clientAddr string, reader *v2io.BufferedReader,
writer.SetCached(false)
dest := request.Destination()
session := &proxy.SessionInfo{
Source: clientAddr,
Destination: dest,
}
log.Info("Socks: TCP Connect request to ", dest)
log.Access(clientAddr, dest, log.AccessAccepted, "")
this.transport(reader, writer, dest)
this.transport(reader, writer, session)
return nil
}
@@ -258,7 +263,7 @@ func (this *Server) handleUDP(reader io.Reader, writer *v2io.BufferedWriter) err
return nil
}
func (this *Server) handleSocks4(clientAddr string, reader *v2io.BufferedReader, writer *v2io.BufferedWriter, auth protocol.Socks4AuthenticationRequest) error {
func (this *Server) handleSocks4(clientAddr v2net.Destination, reader *v2io.BufferedReader, writer *v2io.BufferedWriter, auth protocol.Socks4AuthenticationRequest) error {
result := protocol.Socks4RequestGranted
if auth.Command == protocol.CmdBind {
result = protocol.Socks4RequestRejected
@@ -277,13 +282,17 @@ func (this *Server) handleSocks4(clientAddr string, reader *v2io.BufferedReader,
writer.SetCached(false)
dest := v2net.TCPDestination(v2net.IPAddress(auth.IP[:]), auth.Port)
session := &proxy.SessionInfo{
Source: clientAddr,
Destination: dest,
}
log.Access(clientAddr, dest, log.AccessAccepted, "")
this.transport(reader, writer, dest)
this.transport(reader, writer, session)
return nil
}
func (this *Server) transport(reader io.Reader, writer io.Writer, destination v2net.Destination) {
ray := this.packetDispatcher.DispatchToOutbound(this.meta, destination)
func (this *Server) transport(reader io.Reader, writer io.Writer, session *proxy.SessionInfo) {
ray := this.packetDispatcher.DispatchToOutbound(this.meta, session)
input := ray.InboundInput()
output := ray.InboundOutput()