mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-09-17 23:10:27 +00:00
refactor (remove TimeoutOnly)
This commit is contained in:
@@ -227,7 +227,7 @@ func (w *ServerWorker) handleStatusNew(ctx context.Context, meta *FrameMetadata,
|
||||
errors.LogInfoInner(ctx, err, "XUDP hit ", meta.GlobalID)
|
||||
}
|
||||
if mb != nil {
|
||||
ctx = session.ContextWithTimeoutOnly(ctx, true)
|
||||
ctx = context.WithoutCancel(ctx)
|
||||
// Actually, it won't return an error in Xray-core's implementations.
|
||||
link, err := w.dispatcher.Dispatch(ctx, meta.Target)
|
||||
if err != nil {
|
||||
|
||||
+12
-25
@@ -11,20 +11,18 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
inboundSessionKey ctx.SessionKey = 1
|
||||
outboundSessionKey ctx.SessionKey = 2
|
||||
contentSessionKey ctx.SessionKey = 3
|
||||
isReverseMuxKey ctx.SessionKey = 4 // is reverse mux
|
||||
sockoptSessionKey ctx.SessionKey = 5 // used by dokodemo to only receive sockopt.Mark
|
||||
trackedConnectionErrorKey ctx.SessionKey = 6 // used by observer to get outbound error
|
||||
dispatcherKey ctx.SessionKey = 7 // used by ss2022 inbounds to get dispatcher
|
||||
timeoutOnlyKey ctx.SessionKey = 8 // mux context's child contexts to only cancel when its own traffic times out
|
||||
allowedNetworkKey ctx.SessionKey = 9 // muxcool server control incoming request tcp/udp
|
||||
fullHandlerKey ctx.SessionKey = 10 // outbound gets full handler
|
||||
mitmAlpn11Key ctx.SessionKey = 11 // used by TLS dialer
|
||||
mitmServerNameKey ctx.SessionKey = 12 // used by TLS dialer
|
||||
|
||||
streamSettingsKey ctx.SessionKey = 13
|
||||
inboundSessionKey ctx.SessionKey = iota
|
||||
outboundSessionKey
|
||||
contentSessionKey
|
||||
isReverseMuxKey // is reverse mux
|
||||
sockoptSessionKey // used by dokodemo to only receive sockopt.Mark
|
||||
trackedConnectionErrorKey // used by observer to get outbound error
|
||||
dispatcherKey // used by ss2022 inbounds to get dispatcher
|
||||
allowedNetworkKey // muxcool server control incoming request tcp/udp
|
||||
fullHandlerKey // outbound gets full handler
|
||||
mitmAlpn11Key // used by TLS dialer
|
||||
mitmServerNameKey // used by TLS dialer
|
||||
streamSettingsKey
|
||||
)
|
||||
|
||||
func ContextWithInbound(ctx context.Context, inbound *Inbound) context.Context {
|
||||
@@ -137,17 +135,6 @@ func DispatcherFromContext(ctx context.Context) routing.Dispatcher {
|
||||
return nil
|
||||
}
|
||||
|
||||
func ContextWithTimeoutOnly(ctx context.Context, only bool) context.Context {
|
||||
return context.WithValue(ctx, timeoutOnlyKey, only)
|
||||
}
|
||||
|
||||
func TimeoutOnlyFromContext(ctx context.Context) bool {
|
||||
if val, ok := ctx.Value(timeoutOnlyKey).(bool); ok {
|
||||
return val
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func ContextWithAllowedNetwork(ctx context.Context, network net.Network) context.Context {
|
||||
return context.WithValue(ctx, allowedNetworkKey, network)
|
||||
}
|
||||
|
||||
@@ -214,10 +214,6 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, d internet.
|
||||
}
|
||||
}
|
||||
|
||||
if session.TimeoutOnlyFromContext(ctx) {
|
||||
ctx = context.WithoutCancel(ctx)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
terminate := func() {
|
||||
cancel()
|
||||
|
||||
@@ -388,10 +388,6 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
||||
defer conn.Close()
|
||||
errors.LogInfo(ctx, "connection opened to ", destination, ", local endpoint ", conn.LocalAddr(), ", remote endpoint ", conn.RemoteAddr())
|
||||
|
||||
if session.TimeoutOnlyFromContext(ctx) {
|
||||
ctx = context.WithoutCancel(ctx)
|
||||
}
|
||||
|
||||
plcy := h.policy()
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
timer := signal.CancelAfterInactivity(ctx, cancel, plcy.Timeouts.ConnectionIdle)
|
||||
|
||||
@@ -127,10 +127,6 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
||||
p = c.policyManager.ForLevel(user.Level)
|
||||
}
|
||||
|
||||
if session.TimeoutOnlyFromContext(ctx) {
|
||||
ctx = context.WithoutCancel(ctx)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
timer := signal.CancelAfterInactivity(ctx, cancel, p.Timeouts.ConnectionIdle)
|
||||
|
||||
|
||||
@@ -67,10 +67,6 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
||||
defer conn.Close()
|
||||
errors.LogInfo(ctx, "tunneling request to ", target, " via ", target.Network, ":", c.server.Destination.NetAddr())
|
||||
|
||||
if session.TimeoutOnlyFromContext(ctx) {
|
||||
ctx = context.WithoutCancel(ctx)
|
||||
}
|
||||
|
||||
sessionPolicy := c.policyManager.ForLevel(0)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle)
|
||||
|
||||
@@ -95,10 +95,6 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
||||
}
|
||||
request.User = user
|
||||
|
||||
if session.TimeoutOnlyFromContext(ctx) {
|
||||
ctx = context.WithoutCancel(ctx)
|
||||
}
|
||||
|
||||
sessionPolicy := c.policyManager.ForLevel(user.Level)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle)
|
||||
|
||||
@@ -83,10 +83,6 @@ func (o *Outbound) Process(ctx context.Context, link *transport.Link, dialer int
|
||||
return errors.New("failed to connect to server").Base(err)
|
||||
}
|
||||
|
||||
if session.TimeoutOnlyFromContext(ctx) {
|
||||
ctx = context.WithoutCancel(ctx)
|
||||
}
|
||||
|
||||
if network == net.Network_TCP {
|
||||
serverConn := o.method.DialEarlyConn(connection, singbridge.ToSocksaddr(destination))
|
||||
var handshake bool
|
||||
|
||||
@@ -117,10 +117,6 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
||||
errors.LogInfoInner(ctx, err, "failed to clear deadline after handshake")
|
||||
}
|
||||
|
||||
if session.TimeoutOnlyFromContext(ctx) {
|
||||
ctx = context.WithoutCancel(ctx)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
timer := signal.CancelAfterInactivity(ctx, cancel, p.Timeouts.ConnectionIdle)
|
||||
|
||||
|
||||
@@ -81,10 +81,6 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
||||
return errors.New("user account is not valid")
|
||||
}
|
||||
|
||||
if session.TimeoutOnlyFromContext(ctx) {
|
||||
ctx = context.WithoutCancel(ctx)
|
||||
}
|
||||
|
||||
sessionPolicy := c.policyManager.ForLevel(user.Level)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle)
|
||||
|
||||
@@ -294,10 +294,6 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
||||
ob.CanSpliceCopy = 3
|
||||
}
|
||||
|
||||
if session.TimeoutOnlyFromContext(ctx) {
|
||||
ctx = context.WithoutCancel(ctx)
|
||||
}
|
||||
|
||||
sessionPolicy := h.policyManager.ForLevel(request.User.Level)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle)
|
||||
|
||||
@@ -131,10 +131,6 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
||||
|
||||
behaviorSeed := crc64.Checksum(hashkdf.Sum(nil), crc64.MakeTable(crc64.ISO))
|
||||
|
||||
if session.TimeoutOnlyFromContext(ctx) {
|
||||
ctx = context.WithoutCancel(ctx)
|
||||
}
|
||||
|
||||
session := encoding.NewClientSession(ctx, int64(behaviorSeed))
|
||||
sessionPolicy := h.policyManager.ForLevel(request.User.Level)
|
||||
|
||||
|
||||
@@ -165,10 +165,6 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
||||
return errors.New("invalid target ", ob.Target)
|
||||
}
|
||||
|
||||
if session.TimeoutOnlyFromContext(ctx) {
|
||||
ctx = context.WithoutCancel(ctx)
|
||||
}
|
||||
|
||||
sessionPolicy := h.policyManager.ForLevel(0)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle)
|
||||
|
||||
@@ -122,7 +122,7 @@ func getGrpcClient(ctx context.Context, dest net.Destination, streamSettings *in
|
||||
|
||||
gctx = c.ContextWithID(gctx, c.IDFromContext(ctx))
|
||||
gctx = session.ContextWithOutbounds(gctx, session.OutboundsFromContext(ctx))
|
||||
gctx = session.ContextWithTimeoutOnly(gctx, true)
|
||||
gctx = context.WithoutCancel(gctx)
|
||||
|
||||
c, err := internet.DialSystem(gctx, net.TCPDestination(address, port), sockopt)
|
||||
if err == nil {
|
||||
|
||||
Reference in New Issue
Block a user