1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-02 15:36:41 -05:00

log access info in shadowsocks

This commit is contained in:
v2ray 2016-01-30 22:57:20 +01:00
parent 026f17fdcc
commit fcf8a74a3a

View File

@ -12,6 +12,7 @@ import (
v2io "github.com/v2ray/v2ray-core/common/io" v2io "github.com/v2ray/v2ray-core/common/io"
"github.com/v2ray/v2ray-core/common/log" "github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/serial"
"github.com/v2ray/v2ray-core/proxy" "github.com/v2ray/v2ray-core/proxy"
"github.com/v2ray/v2ray-core/proxy/internal" "github.com/v2ray/v2ray-core/proxy/internal"
"github.com/v2ray/v2ray-core/transport/hub" "github.com/v2ray/v2ray-core/transport/hub"
@ -88,11 +89,15 @@ func (this *Shadowsocks) handlerUDPPayload(payload *alloc.Buffer, source v2net.D
request, err := ReadRequest(reader, NewAuthenticator(HeaderKeyGenerator(key, iv)), true) request, err := ReadRequest(reader, NewAuthenticator(HeaderKeyGenerator(key, iv)), true)
if err != nil { if err != nil {
log.Access(source, serial.StringLiteral(""), log.AccessRejected, serial.StringLiteral(err.Error()))
log.Warning("Shadowsocks: Invalid request from ", source, ": ", err)
return return
} }
dest := v2net.UDPDestination(request.Address, request.Port) dest := v2net.UDPDestination(request.Address, request.Port)
log.Access(source, dest, log.AccessAccepted, serial.StringLiteral(""))
log.Info("Shadowsocks: Tunnelling request to ", dest) log.Info("Shadowsocks: Tunnelling request to ", dest)
packet := v2net.NewPacket(dest, request.UDPPayload, false) packet := v2net.NewPacket(dest, request.UDPPayload, false)
ray := this.space.PacketDispatcher().DispatchToOutbound(packet) ray := this.space.PacketDispatcher().DispatchToOutbound(packet)
close(ray.InboundInput()) close(ray.InboundInput())
@ -143,6 +148,7 @@ func (this *Shadowsocks) handleConnection(conn *hub.TCPConn) {
_, err := io.ReadFull(conn, buffer.Value[:this.config.Cipher.IVSize()]) _, err := io.ReadFull(conn, buffer.Value[:this.config.Cipher.IVSize()])
if err != nil { if err != nil {
log.Access(conn.RemoteAddr(), serial.StringLiteral(""), log.AccessRejected, serial.StringLiteral(err.Error()))
log.Error("Shadowsocks: Failed to read IV: ", err) log.Error("Shadowsocks: Failed to read IV: ", err)
return return
} }
@ -158,10 +164,16 @@ func (this *Shadowsocks) handleConnection(conn *hub.TCPConn) {
request, err := ReadRequest(reader, NewAuthenticator(HeaderKeyGenerator(iv, key)), false) request, err := ReadRequest(reader, NewAuthenticator(HeaderKeyGenerator(iv, key)), false)
if err != nil { if err != nil {
log.Access(conn.RemoteAddr(), serial.StringLiteral(""), log.AccessRejected, serial.StringLiteral(err.Error()))
log.Warning("Shadowsocks: Invalid request from ", conn.RemoteAddr(), ": ", err)
return return
} }
packet := v2net.NewPacket(v2net.TCPDestination(request.Address, request.Port), nil, true) dest := v2net.TCPDestination(request.Address, request.Port)
log.Access(conn.RemoteAddr(), dest, log.AccessAccepted, serial.StringLiteral(""))
log.Info("Shadowsocks: Tunnelling request to ", dest)
packet := v2net.NewPacket(dest, nil, true)
ray := this.space.PacketDispatcher().DispatchToOutbound(packet) ray := this.space.PacketDispatcher().DispatchToOutbound(packet)
var writeFinish sync.Mutex var writeFinish sync.Mutex