Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2565 #19

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions common/log/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func (m *AccessMessage) String() string {
}

func ContextWithAccessMessage(ctx context.Context, accessMessage *AccessMessage) context.Context {
if ctx.Value(accessMessageKey) != nil {
return ctx
}
return context.WithValue(ctx, accessMessageKey, accessMessage)
}

Expand Down
3 changes: 3 additions & 0 deletions common/protocol/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const (
)

func ContextWithRequestHeader(ctx context.Context, request *RequestHeader) context.Context {
if ctx.Value(requestKey) != nil {
return ctx
}
return context.WithValue(ctx, requestKey, request)
}

Expand Down
9 changes: 4 additions & 5 deletions proxy/shadowsocks/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,20 @@ func (s *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection
continue
}

currentPacketCtx := ctx
dest := request.Destination()
if inbound.Source.IsValid() {
currentPacketCtx = log.ContextWithAccessMessage(ctx, &log.AccessMessage{
ctx = log.ContextWithAccessMessage(ctx, &log.AccessMessage{
From: inbound.Source,
To: dest,
Status: log.AccessAccepted,
Reason: "",
Email: request.User.Email,
})
}
newError("tunnelling request to ", dest).WriteToLog(session.ExportIDToError(currentPacketCtx))
newError("tunnelling request to ", dest).WriteToLog(session.ExportIDToError(ctx))

currentPacketCtx = protocol.ContextWithRequestHeader(currentPacketCtx, request)
udpServer.Dispatch(currentPacketCtx, dest, data)
ctx = protocol.ContextWithRequestHeader(ctx, request)
udpServer.Dispatch(ctx, dest, data)
}
}

Expand Down
8 changes: 4 additions & 4 deletions proxy/socks/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,19 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
payload.Release()
continue
}
currentPacketCtx := 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() {
currentPacketCtx = log.ContextWithAccessMessage(ctx, &log.AccessMessage{
ctx = log.ContextWithAccessMessage(ctx, &log.AccessMessage{
From: inbound.Source,
To: request.Destination(),
Status: log.AccessAccepted,
Reason: "",
})
}

currentPacketCtx = protocol.ContextWithRequestHeader(currentPacketCtx, request)
udpServer.Dispatch(currentPacketCtx, request.Destination(), payload)
ctx = protocol.ContextWithRequestHeader(ctx, request)
udpServer.Dispatch(ctx, request.Destination(), payload)
}
}
}
Expand Down