1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-04-19 03:59:11 -04:00

session id

This commit is contained in:
Darien Raymond
2018-02-22 15:26:00 +01:00
parent 80a1e73361
commit 6b872c266c
19 changed files with 143 additions and 55 deletions

View File

@@ -7,6 +7,8 @@ import (
"sync/atomic"
"time"
"v2ray.com/core/common/session"
"v2ray.com/core"
"v2ray.com/core/app/proxyman"
"v2ray.com/core/common"
@@ -41,10 +43,13 @@ type tcpWorker struct {
func (w *tcpWorker) callback(conn internet.Connection) {
ctx, cancel := context.WithCancel(context.Background())
sid := session.NewID()
ctx = session.ContextWithID(ctx, sid)
if w.recvOrigDest {
dest, err := tcp.GetOriginalDestination(conn)
if err != nil {
newError("failed to get original destination").Base(err).WriteToLog()
newError("failed to get original destination").WithContext(ctx).Base(err).WriteToLog()
}
if dest.IsValid() {
ctx = proxy.ContextWithOriginalTarget(ctx, dest)
@@ -59,11 +64,11 @@ func (w *tcpWorker) callback(conn internet.Connection) {
ctx = proxyman.ContextWithProtocolSniffers(ctx, w.sniffers)
}
if err := w.proxy.Process(ctx, net.Network_TCP, conn, w.dispatcher); err != nil {
newError("connection ends").Base(err).WriteToLog()
newError("connection ends").Base(err).WithContext(ctx).WriteToLog()
}
cancel()
if err := conn.Close(); err != nil {
newError("failed to close connection").Base(err).WriteToLog()
newError("failed to close connection").Base(err).WithContext(ctx).WriteToLog()
}
}
@@ -220,6 +225,9 @@ func (w *udpWorker) callback(b *buf.Buffer, source net.Destination, originalDest
if !existing {
go func() {
ctx := context.Background()
sid := session.NewID()
ctx = session.ContextWithID(ctx, sid)
if originalDest.IsValid() {
ctx = proxy.ContextWithOriginalTarget(ctx, originalDest)
}