mirror of https://github.com/v2ray/v2ray-core
commit
087415850b
|
@ -14,6 +14,7 @@ import (
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
"v2ray.com/core/common/buf"
|
"v2ray.com/core/common/buf"
|
||||||
"v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
|
"v2ray.com/core/common/log"
|
||||||
"v2ray.com/core/common/protocol"
|
"v2ray.com/core/common/protocol"
|
||||||
"v2ray.com/core/common/session"
|
"v2ray.com/core/common/session"
|
||||||
"v2ray.com/core/features/outbound"
|
"v2ray.com/core/features/outbound"
|
||||||
|
@ -281,5 +282,11 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
accessMessage := log.AccessMessageFromContext(ctx)
|
||||||
|
if accessMessage != nil {
|
||||||
|
accessMessage.Detour = "[" + handler.Tag() + "]"
|
||||||
|
log.Record(accessMessage)
|
||||||
|
}
|
||||||
|
|
||||||
handler.Dispatch(ctx, link)
|
handler.Dispatch(ctx, link)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,17 @@ package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
"context"
|
||||||
|
|
||||||
"v2ray.com/core/common/serial"
|
"v2ray.com/core/common/serial"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type logKey int
|
||||||
|
|
||||||
|
const (
|
||||||
|
accessMessageKey logKey = iota
|
||||||
|
)
|
||||||
|
|
||||||
type AccessStatus string
|
type AccessStatus string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -18,6 +25,7 @@ type AccessMessage struct {
|
||||||
To interface{}
|
To interface{}
|
||||||
Status AccessStatus
|
Status AccessStatus
|
||||||
Reason interface{}
|
Reason interface{}
|
||||||
|
Detour interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *AccessMessage) String() string {
|
func (m *AccessMessage) String() string {
|
||||||
|
@ -28,6 +36,19 @@ func (m *AccessMessage) String() string {
|
||||||
builder.WriteByte(' ')
|
builder.WriteByte(' ')
|
||||||
builder.WriteString(serial.ToString(m.To))
|
builder.WriteString(serial.ToString(m.To))
|
||||||
builder.WriteByte(' ')
|
builder.WriteByte(' ')
|
||||||
|
builder.WriteString(serial.ToString(m.Detour))
|
||||||
|
builder.WriteByte(' ')
|
||||||
builder.WriteString(serial.ToString(m.Reason))
|
builder.WriteString(serial.ToString(m.Reason))
|
||||||
return builder.String()
|
return builder.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ContextWithAccessMessage(ctx context.Context, accessMessage *AccessMessage) context.Context {
|
||||||
|
return context.WithValue(ctx, accessMessageKey, accessMessage)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AccessMessageFromContext(ctx context.Context) *AccessMessage {
|
||||||
|
if accessMessage, ok := ctx.Value(accessMessageKey).(*AccessMessage); ok {
|
||||||
|
return accessMessage
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -131,10 +131,11 @@ Start:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newError("malformed proxy host: ", host).AtWarning().Base(err)
|
return newError("malformed proxy host: ", host).AtWarning().Base(err)
|
||||||
}
|
}
|
||||||
log.Record(&log.AccessMessage{
|
ctx = log.ContextWithAccessMessage(ctx, &log.AccessMessage{
|
||||||
From: conn.RemoteAddr(),
|
From: conn.RemoteAddr(),
|
||||||
To: request.URL,
|
To: request.URL,
|
||||||
Status: log.AccessAccepted,
|
Status: log.AccessAccepted,
|
||||||
|
Reason: "",
|
||||||
})
|
})
|
||||||
|
|
||||||
if strings.EqualFold(request.Method, "CONNECT") {
|
if strings.EqualFold(request.Method, "CONNECT") {
|
||||||
|
|
|
@ -134,7 +134,7 @@ func (s *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection
|
||||||
|
|
||||||
dest := request.Destination()
|
dest := request.Destination()
|
||||||
if inbound.Source.IsValid() {
|
if inbound.Source.IsValid() {
|
||||||
log.Record(&log.AccessMessage{
|
ctx = log.ContextWithAccessMessage(ctx, &log.AccessMessage{
|
||||||
From: inbound.Source,
|
From: inbound.Source,
|
||||||
To: dest,
|
To: dest,
|
||||||
Status: log.AccessAccepted,
|
Status: log.AccessAccepted,
|
||||||
|
@ -175,7 +175,7 @@ func (s *Server) handleConnection(ctx context.Context, conn internet.Connection,
|
||||||
inbound.User = s.user
|
inbound.User = s.user
|
||||||
|
|
||||||
dest := request.Destination()
|
dest := request.Destination()
|
||||||
log.Record(&log.AccessMessage{
|
ctx = log.ContextWithAccessMessage(ctx, &log.AccessMessage{
|
||||||
From: conn.RemoteAddr(),
|
From: conn.RemoteAddr(),
|
||||||
To: dest,
|
To: dest,
|
||||||
Status: log.AccessAccepted,
|
Status: log.AccessAccepted,
|
||||||
|
|
|
@ -117,7 +117,7 @@ func (s *Server) processTCP(ctx context.Context, conn internet.Connection, dispa
|
||||||
dest := request.Destination()
|
dest := request.Destination()
|
||||||
newError("TCP Connect request to ", dest).WriteToLog(session.ExportIDToError(ctx))
|
newError("TCP Connect request to ", dest).WriteToLog(session.ExportIDToError(ctx))
|
||||||
if inbound != nil && inbound.Source.IsValid() {
|
if inbound != nil && inbound.Source.IsValid() {
|
||||||
log.Record(&log.AccessMessage{
|
ctx = log.ContextWithAccessMessage(ctx, &log.AccessMessage{
|
||||||
From: inbound.Source,
|
From: inbound.Source,
|
||||||
To: dest,
|
To: dest,
|
||||||
Status: log.AccessAccepted,
|
Status: log.AccessAccepted,
|
||||||
|
@ -229,7 +229,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
|
||||||
|
|
||||||
newError("send packet to ", request.Destination(), " with ", payload.Len(), " bytes").AtDebug().WriteToLog(session.ExportIDToError(ctx))
|
newError("send packet to ", request.Destination(), " with ", payload.Len(), " bytes").AtDebug().WriteToLog(session.ExportIDToError(ctx))
|
||||||
if inbound := session.InboundFromContext(ctx); inbound != nil && inbound.Source.IsValid() {
|
if inbound := session.InboundFromContext(ctx); inbound != nil && inbound.Source.IsValid() {
|
||||||
log.Record(&log.AccessMessage{
|
ctx = log.ContextWithAccessMessage(ctx, &log.AccessMessage{
|
||||||
From: inbound.Source,
|
From: inbound.Source,
|
||||||
To: request.Destination(),
|
To: request.Destination(),
|
||||||
Status: log.AccessAccepted,
|
Status: log.AccessAccepted,
|
||||||
|
|
|
@ -250,7 +250,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection i
|
||||||
}
|
}
|
||||||
|
|
||||||
if request.Command != protocol.RequestCommandMux {
|
if request.Command != protocol.RequestCommandMux {
|
||||||
log.Record(&log.AccessMessage{
|
ctx = log.ContextWithAccessMessage(ctx, &log.AccessMessage{
|
||||||
From: connection.RemoteAddr(),
|
From: connection.RemoteAddr(),
|
||||||
To: request.Destination(),
|
To: request.Destination(),
|
||||||
Status: log.AccessAccepted,
|
Status: log.AccessAccepted,
|
||||||
|
|
Loading…
Reference in New Issue