mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-05-08 13:39:08 -04:00
session id
This commit is contained in:
@@ -53,7 +53,7 @@ func (d *DokodemoDoor) policy() core.Policy {
|
||||
}
|
||||
|
||||
func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn internet.Connection, dispatcher core.Dispatcher) error {
|
||||
newError("processing connection from: ", conn.RemoteAddr()).AtDebug().WriteToLog()
|
||||
newError("processing connection from: ", conn.RemoteAddr()).AtDebug().WithContext(ctx).WriteToLog()
|
||||
dest := net.Destination{
|
||||
Network: network,
|
||||
Address: d.address,
|
||||
|
||||
@@ -56,7 +56,7 @@ func (h *Handler) resolveIP(ctx context.Context, domain string) net.Address {
|
||||
|
||||
ips, err := h.dns.LookupIP(domain)
|
||||
if err != nil {
|
||||
newError("failed to get IP address for domain ", domain).Base(err).WriteToLog()
|
||||
newError("failed to get IP address for domain ", domain).Base(err).WithContext(ctx).WriteToLog()
|
||||
}
|
||||
if len(ips) == 0 {
|
||||
return nil
|
||||
@@ -75,7 +75,7 @@ func (h *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
|
||||
Port: net.Port(server.Port),
|
||||
}
|
||||
}
|
||||
newError("opening connection to ", destination).WriteToLog()
|
||||
newError("opening connection to ", destination).WithContext(ctx).WriteToLog()
|
||||
|
||||
input := outboundRay.OutboundInput()
|
||||
output := outboundRay.OutboundOutput()
|
||||
@@ -88,7 +88,7 @@ func (h *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
|
||||
Address: ip,
|
||||
Port: destination.Port,
|
||||
}
|
||||
newError("changing destination to ", destination).WriteToLog()
|
||||
newError("changing destination to ", destination).WithContext(ctx).WriteToLog()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ Start:
|
||||
}
|
||||
}
|
||||
|
||||
newError("request to Method [", request.Method, "] Host [", request.Host, "] with URL [", request.URL, "]").WriteToLog()
|
||||
newError("request to Method [", request.Method, "] Host [", request.Host, "] with URL [", request.URL, "]").WithContext(ctx).WriteToLog()
|
||||
conn.SetReadDeadline(time.Time{})
|
||||
|
||||
defaultPort := net.Port(80)
|
||||
@@ -276,7 +276,7 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, wri
|
||||
result = nil
|
||||
}
|
||||
} else {
|
||||
newError("failed to read response from ", request.Host).Base(err).AtWarning().WriteToLog()
|
||||
newError("failed to read response from ", request.Host).Base(err).AtWarning().WithContext(ctx).WriteToLog()
|
||||
response = &http.Response{
|
||||
Status: "Service Unavailable",
|
||||
StatusCode: 503,
|
||||
|
||||
@@ -80,7 +80,7 @@ func (s *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection
|
||||
request, data, err := DecodeUDPPacket(s.user, payload)
|
||||
if err != nil {
|
||||
if source, ok := proxy.SourceFromContext(ctx); ok {
|
||||
newError("dropping invalid UDP packet from: ", source).Base(err).WriteToLog()
|
||||
newError("dropping invalid UDP packet from: ", source).Base(err).WithContext(ctx).WriteToLog()
|
||||
log.Record(&log.AccessMessage{
|
||||
From: source,
|
||||
To: "",
|
||||
@@ -93,13 +93,13 @@ func (s *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection
|
||||
}
|
||||
|
||||
if request.Option.Has(RequestOptionOneTimeAuth) && s.account.OneTimeAuth == Account_Disabled {
|
||||
newError("client payload enables OTA but server doesn't allow it").WriteToLog()
|
||||
newError("client payload enables OTA but server doesn't allow it").WithContext(ctx).WriteToLog()
|
||||
payload.Release()
|
||||
continue
|
||||
}
|
||||
|
||||
if !request.Option.Has(RequestOptionOneTimeAuth) && s.account.OneTimeAuth == Account_Enabled {
|
||||
newError("client payload disables OTA but server forces it").WriteToLog()
|
||||
newError("client payload disables OTA but server forces it").WithContext(ctx).WriteToLog()
|
||||
payload.Release()
|
||||
continue
|
||||
}
|
||||
@@ -113,7 +113,7 @@ func (s *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection
|
||||
Reason: "",
|
||||
})
|
||||
}
|
||||
newError("tunnelling request to ", dest).WriteToLog()
|
||||
newError("tunnelling request to ", dest).WithContext(ctx).WriteToLog()
|
||||
|
||||
ctx = protocol.ContextWithUser(ctx, request.User)
|
||||
udpServer.Dispatch(ctx, dest, data, func(payload *buf.Buffer) {
|
||||
@@ -121,7 +121,7 @@ func (s *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection
|
||||
|
||||
data, err := EncodeUDPPacket(request, payload.Bytes())
|
||||
if err != nil {
|
||||
newError("failed to encode UDP packet").Base(err).AtWarning().WriteToLog()
|
||||
newError("failed to encode UDP packet").Base(err).AtWarning().WithContext(ctx).WriteToLog()
|
||||
return
|
||||
}
|
||||
defer data.Release()
|
||||
@@ -159,7 +159,7 @@ func (s *Server) handleConnection(ctx context.Context, conn internet.Connection,
|
||||
Status: log.AccessAccepted,
|
||||
Reason: "",
|
||||
})
|
||||
newError("tunnelling request to ", dest).WriteToLog()
|
||||
newError("tunnelling request to ", dest).WithContext(ctx).WriteToLog()
|
||||
|
||||
ctx = protocol.ContextWithUser(ctx, request.User)
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ func (c *Client) Process(ctx context.Context, ray ray.OutboundRay, dialer proxy.
|
||||
}
|
||||
|
||||
if err := conn.SetDeadline(time.Now().Add(p.Timeouts.Handshake)); err != nil {
|
||||
newError("failed to set deadline for handshake").Base(err).WriteToLog()
|
||||
newError("failed to set deadline for handshake").Base(err).WithContext(ctx).WriteToLog()
|
||||
}
|
||||
udpRequest, err := ClientHandshake(request, conn, conn)
|
||||
if err != nil {
|
||||
@@ -94,7 +94,7 @@ func (c *Client) Process(ctx context.Context, ray ray.OutboundRay, dialer proxy.
|
||||
}
|
||||
|
||||
if err := conn.SetDeadline(time.Time{}); err != nil {
|
||||
newError("failed to clear deadline after handshake").Base(err).WriteToLog()
|
||||
newError("failed to clear deadline after handshake").Base(err).WithContext(ctx).WriteToLog()
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
||||
@@ -91,7 +91,7 @@ func (s *Server) processTCP(ctx context.Context, conn internet.Connection, dispa
|
||||
|
||||
if request.Command == protocol.RequestCommandTCP {
|
||||
dest := request.Destination()
|
||||
newError("TCP Connect request to ", dest).WriteToLog()
|
||||
newError("TCP Connect request to ", dest).WithContext(ctx).WriteToLog()
|
||||
if source, ok := proxy.SourceFromContext(ctx); ok {
|
||||
log.Record(&log.AccessMessage{
|
||||
From: source,
|
||||
@@ -163,7 +163,7 @@ func (v *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
|
||||
udpServer := udp.NewDispatcher(dispatcher)
|
||||
|
||||
if source, ok := proxy.SourceFromContext(ctx); ok {
|
||||
newError("client UDP connection from ", source).WriteToLog()
|
||||
newError("client UDP connection from ", source).WithContext(ctx).WriteToLog()
|
||||
}
|
||||
|
||||
reader := buf.NewReader(conn)
|
||||
@@ -177,7 +177,7 @@ func (v *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
|
||||
request, data, err := DecodeUDPPacket(payload.Bytes())
|
||||
|
||||
if err != nil {
|
||||
newError("failed to parse UDP request").Base(err).WriteToLog()
|
||||
newError("failed to parse UDP request").Base(err).WithContext(ctx).WriteToLog()
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ func (v *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
|
||||
continue
|
||||
}
|
||||
|
||||
newError("send packet to ", request.Destination(), " with ", len(data), " bytes").AtDebug().WriteToLog()
|
||||
newError("send packet to ", request.Destination(), " with ", len(data), " bytes").AtDebug().WithContext(ctx).WriteToLog()
|
||||
if source, ok := proxy.SourceFromContext(ctx); ok {
|
||||
log.Record(&log.AccessMessage{
|
||||
From: source,
|
||||
@@ -200,12 +200,12 @@ func (v *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
|
||||
udpServer.Dispatch(ctx, request.Destination(), dataBuf, func(payload *buf.Buffer) {
|
||||
defer payload.Release()
|
||||
|
||||
newError("writing back UDP response with ", payload.Len(), " bytes").AtDebug().WriteToLog()
|
||||
newError("writing back UDP response with ", payload.Len(), " bytes").AtDebug().WithContext(ctx).WriteToLog()
|
||||
|
||||
udpMessage, err := EncodeUDPPacket(request, payload.Bytes())
|
||||
defer udpMessage.Release()
|
||||
if err != nil {
|
||||
newError("failed to write UDP response").AtWarning().Base(err).WriteToLog()
|
||||
newError("failed to write UDP response").AtWarning().Base(err).WithContext(ctx).WriteToLog()
|
||||
}
|
||||
|
||||
conn.Write(udpMessage.Bytes())
|
||||
|
||||
@@ -63,8 +63,7 @@ func (c *ClientSession) EncodeRequestHeader(header *protocol.RequestHeader, writ
|
||||
timestamp := protocol.NewTimestampGenerator(protocol.NowTime(), 30)()
|
||||
account, err := header.User.GetTypedAccount()
|
||||
if err != nil {
|
||||
newError("failed to get user account: ", err).AtError().WriteToLog()
|
||||
return nil
|
||||
return newError("failed to get user account: ", err).AtError()
|
||||
}
|
||||
idHash := c.idHash(account.(*vmess.InternalAccount).AnyValidID().Bytes())
|
||||
common.Must2(idHash.Write(timestamp.Bytes(nil)))
|
||||
@@ -200,8 +199,7 @@ func (c *ClientSession) DecodeResponseHeader(reader io.Reader) (*protocol.Respon
|
||||
defer buffer.Release()
|
||||
|
||||
if err := buffer.AppendSupplier(buf.ReadFullFrom(c.responseReader, 4)); err != nil {
|
||||
newError("failed to read response header").Base(err).WriteToLog()
|
||||
return nil, err
|
||||
return nil, newError("failed to read response header").Base(err)
|
||||
}
|
||||
|
||||
if buffer.Byte(0) != c.responseHeader {
|
||||
@@ -217,8 +215,7 @@ func (c *ClientSession) DecodeResponseHeader(reader io.Reader) (*protocol.Respon
|
||||
dataLen := int(buffer.Byte(3))
|
||||
|
||||
if err := buffer.Reset(buf.ReadFullFrom(c.responseReader, dataLen)); err != nil {
|
||||
newError("failed to read response command").Base(err).WriteToLog()
|
||||
return nil, err
|
||||
return nil, newError("failed to read response command").Base(err)
|
||||
}
|
||||
command, err := UnmarshalCommand(cmdID, buffer.Bytes())
|
||||
if err == nil {
|
||||
|
||||
@@ -242,10 +242,10 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection i
|
||||
Reason: "",
|
||||
})
|
||||
|
||||
newError("received request for ", request.Destination()).WriteToLog()
|
||||
newError("received request for ", request.Destination()).WithContext(ctx).WriteToLog()
|
||||
|
||||
if err := connection.SetReadDeadline(time.Time{}); err != nil {
|
||||
newError("unable to set back read deadline").Base(err).WriteToLog()
|
||||
newError("unable to set back read deadline").Base(err).WithContext(ctx).WriteToLog()
|
||||
}
|
||||
|
||||
sessionPolicy = h.policyManager.ForLevel(request.User.Level)
|
||||
@@ -292,7 +292,7 @@ func (h *Handler) generateCommand(ctx context.Context, request *protocol.Request
|
||||
if h.inboundHandlerManager != nil {
|
||||
handler, err := h.inboundHandlerManager.GetHandler(ctx, tag)
|
||||
if err != nil {
|
||||
newError("failed to get detour handler: ", tag).Base(err).AtWarning().WriteToLog()
|
||||
newError("failed to get detour handler: ", tag).Base(err).AtWarning().WithContext(ctx).WriteToLog()
|
||||
return nil
|
||||
}
|
||||
proxyHandler, port, availableMin := handler.GetRandomInboundProxy()
|
||||
@@ -302,7 +302,7 @@ func (h *Handler) generateCommand(ctx context.Context, request *protocol.Request
|
||||
availableMin = 255
|
||||
}
|
||||
|
||||
newError("pick detour handler for port ", port, " for ", availableMin, " minutes.").AtDebug().WriteToLog()
|
||||
newError("pick detour handler for port ", port, " for ", availableMin, " minutes.").AtDebug().WithContext(ctx).WriteToLog()
|
||||
user := inboundHandler.GetUser(request.User.Email)
|
||||
if user == nil {
|
||||
return nil
|
||||
|
||||
@@ -65,7 +65,7 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
|
||||
if !ok {
|
||||
return newError("target not specified").AtError()
|
||||
}
|
||||
newError("tunneling request to ", target, " via ", rec.Destination()).WriteToLog()
|
||||
newError("tunneling request to ", target, " via ", rec.Destination()).WithContext(ctx).WriteToLog()
|
||||
|
||||
command := protocol.RequestCommandTCP
|
||||
if target.Network == net.Network_UDP {
|
||||
|
||||
Reference in New Issue
Block a user