mirror of https://github.com/v2ray/v2ray-core
merge conflict
commit
306ffabef0
|
@ -123,6 +123,7 @@ func (this *Server) handleConnection(conn *hub.Connection) {
|
||||||
log.Warning("HTTP: Malformed proxy host (", host, "): ", err)
|
log.Warning("HTTP: Malformed proxy host (", host, "): ", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
log.Access(conn.RemoteAddr(), request.URL, log.AccessAccepted, "")
|
||||||
if strings.ToUpper(request.Method) == "CONNECT" {
|
if strings.ToUpper(request.Method) == "CONNECT" {
|
||||||
this.handleConnect(request, dest, reader, conn)
|
this.handleConnect(request, dest, reader, conn)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -110,14 +110,15 @@ func (this *Server) handleConnection(connection *hub.Connection) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clientAddr := connection.RemoteAddr().String()
|
||||||
if err != nil && err == protocol.Socks4Downgrade {
|
if err != nil && err == protocol.Socks4Downgrade {
|
||||||
this.handleSocks4(reader, writer, auth4)
|
this.handleSocks4(clientAddr, reader, writer, auth4)
|
||||||
} else {
|
} else {
|
||||||
this.handleSocks5(reader, writer, auth)
|
this.handleSocks5(clientAddr, reader, writer, auth)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Server) handleSocks5(reader *v2io.BufferedReader, writer *v2io.BufferedWriter, auth protocol.Socks5AuthenticationRequest) error {
|
func (this *Server) handleSocks5(clientAddr string, reader *v2io.BufferedReader, writer *v2io.BufferedWriter, auth protocol.Socks5AuthenticationRequest) error {
|
||||||
expectedAuthMethod := protocol.AuthNotRequired
|
expectedAuthMethod := protocol.AuthNotRequired
|
||||||
if this.config.AuthType == AuthTypePassword {
|
if this.config.AuthType == AuthTypePassword {
|
||||||
expectedAuthMethod = protocol.AuthUserPass
|
expectedAuthMethod = protocol.AuthUserPass
|
||||||
|
@ -161,6 +162,7 @@ func (this *Server) handleSocks5(reader *v2io.BufferedReader, writer *v2io.Buffe
|
||||||
}
|
}
|
||||||
if status != byte(0) {
|
if status != byte(0) {
|
||||||
log.Warning("Socks: Invalid user account: ", upRequest.AuthDetail())
|
log.Warning("Socks: Invalid user account: ", upRequest.AuthDetail())
|
||||||
|
log.Access(clientAddr, "", log.AccessRejected, proxy.ErrorInvalidAuthentication)
|
||||||
return proxy.ErrorInvalidAuthentication
|
return proxy.ErrorInvalidAuthentication
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,6 +211,7 @@ func (this *Server) handleSocks5(reader *v2io.BufferedReader, writer *v2io.Buffe
|
||||||
|
|
||||||
dest := request.Destination()
|
dest := request.Destination()
|
||||||
log.Info("Socks: TCP Connect request to ", dest)
|
log.Info("Socks: TCP Connect request to ", dest)
|
||||||
|
log.Access(clientAddr, dest, log.AccessAccepted, "")
|
||||||
|
|
||||||
this.transport(reader, writer, dest)
|
this.transport(reader, writer, dest)
|
||||||
return nil
|
return nil
|
||||||
|
@ -246,7 +249,7 @@ func (this *Server) handleUDP(reader io.Reader, writer *v2io.BufferedWriter) err
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Server) handleSocks4(reader *v2io.BufferedReader, writer *v2io.BufferedWriter, auth protocol.Socks4AuthenticationRequest) error {
|
func (this *Server) handleSocks4(clientAddr string, reader *v2io.BufferedReader, writer *v2io.BufferedWriter, auth protocol.Socks4AuthenticationRequest) error {
|
||||||
result := protocol.Socks4RequestGranted
|
result := protocol.Socks4RequestGranted
|
||||||
if auth.Command == protocol.CmdBind {
|
if auth.Command == protocol.CmdBind {
|
||||||
result = protocol.Socks4RequestRejected
|
result = protocol.Socks4RequestRejected
|
||||||
|
@ -257,6 +260,7 @@ func (this *Server) handleSocks4(reader *v2io.BufferedReader, writer *v2io.Buffe
|
||||||
|
|
||||||
if result == protocol.Socks4RequestRejected {
|
if result == protocol.Socks4RequestRejected {
|
||||||
log.Warning("Socks: Unsupported socks 4 command ", auth.Command)
|
log.Warning("Socks: Unsupported socks 4 command ", auth.Command)
|
||||||
|
log.Access(clientAddr, "", log.AccessRejected, ErrorUnsupportedSocksCommand)
|
||||||
return ErrorUnsupportedSocksCommand
|
return ErrorUnsupportedSocksCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,6 +268,7 @@ func (this *Server) handleSocks4(reader *v2io.BufferedReader, writer *v2io.Buffe
|
||||||
writer.SetCached(false)
|
writer.SetCached(false)
|
||||||
|
|
||||||
dest := v2net.TCPDestination(v2net.IPAddress(auth.IP[:]), auth.Port)
|
dest := v2net.TCPDestination(v2net.IPAddress(auth.IP[:]), auth.Port)
|
||||||
|
log.Access(clientAddr, dest, log.AccessAccepted, "")
|
||||||
this.transport(reader, writer, dest)
|
this.transport(reader, writer, dest)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ func (this *Server) handleUDPPayload(payload *alloc.Buffer, source v2net.Destina
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("Socks: Send packet to ", request.Destination(), " with ", request.Data.Len(), " bytes")
|
log.Info("Socks: Send packet to ", request.Destination(), " with ", request.Data.Len(), " bytes")
|
||||||
|
log.Access(source, request.Destination, log.AccessAccepted, "")
|
||||||
this.udpServer.Dispatch(source, request.Destination(), request.Data, func(destination v2net.Destination, payload *alloc.Buffer) {
|
this.udpServer.Dispatch(source, request.Destination(), request.Data, func(destination v2net.Destination, payload *alloc.Buffer) {
|
||||||
response := &protocol.Socks5UDPRequest{
|
response := &protocol.Socks5UDPRequest{
|
||||||
Fragment: 0,
|
Fragment: 0,
|
||||||
|
|
|
@ -18,6 +18,7 @@ type InboundDetourHandlerDynamic struct {
|
||||||
config *InboundDetourConfig
|
config *InboundDetourConfig
|
||||||
portsInUse map[v2net.Port]bool
|
portsInUse map[v2net.Port]bool
|
||||||
ichs []proxy.InboundHandler
|
ichs []proxy.InboundHandler
|
||||||
|
ich2Recyle []proxy.InboundHandler
|
||||||
lastRefresh time.Time
|
lastRefresh time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,11 +75,25 @@ func (this *InboundDetourHandlerDynamic) Close() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *InboundDetourHandlerDynamic) RecyleHandles() {
|
||||||
|
if this.ich2Recyle != nil {
|
||||||
|
for _, ich := range this.ich2Recyle {
|
||||||
|
if ich == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
port := ich.Port()
|
||||||
|
ich.Close()
|
||||||
|
delete(this.portsInUse, port)
|
||||||
|
}
|
||||||
|
this.ich2Recyle = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (this *InboundDetourHandlerDynamic) refresh() error {
|
func (this *InboundDetourHandlerDynamic) refresh() error {
|
||||||
this.lastRefresh = time.Now()
|
this.lastRefresh = time.Now()
|
||||||
|
|
||||||
config := this.config
|
config := this.config
|
||||||
ich2Recycle := this.ichs
|
this.ich2Recyle = this.ichs
|
||||||
newIchs := make([]proxy.InboundHandler, config.Allocation.Concurrency)
|
newIchs := make([]proxy.InboundHandler, config.Allocation.Concurrency)
|
||||||
|
|
||||||
for idx, _ := range newIchs {
|
for idx, _ := range newIchs {
|
||||||
|
@ -102,6 +117,7 @@ func (this *InboundDetourHandlerDynamic) refresh() error {
|
||||||
this.ichs = newIchs
|
this.ichs = newIchs
|
||||||
this.Unlock()
|
this.Unlock()
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
go func(recycles []proxy.InboundHandler) {
|
go func(recycles []proxy.InboundHandler) {
|
||||||
time.Sleep(time.Minute)
|
time.Sleep(time.Minute)
|
||||||
for _, ich := range recycles {
|
for _, ich := range recycles {
|
||||||
|
@ -114,6 +130,8 @@ func (this *InboundDetourHandlerDynamic) refresh() error {
|
||||||
}
|
}
|
||||||
}(ich2Recycle)
|
}(ich2Recycle)
|
||||||
|
|
||||||
|
=======
|
||||||
|
>>>>>>> 045e1dcc5329b68fee3fc0f94b1c50d6ee303b27
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +144,8 @@ func (this *InboundDetourHandlerDynamic) Start() error {
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
time.Sleep(time.Duration(this.config.Allocation.Refresh) * time.Minute)
|
time.Sleep(time.Duration(this.config.Allocation.Refresh)*time.Minute - 1)
|
||||||
|
this.RecyleHandles()
|
||||||
err := this.refresh()
|
err := this.refresh()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Point: Failed to refresh dynamic allocations: ", err)
|
log.Error("Point: Failed to refresh dynamic allocations: ", err)
|
||||||
|
|
Loading…
Reference in New Issue