mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-10-29 06:31:56 +00:00
refactor (remove TimeoutOnly)
This commit is contained in:
1 parent
b53f8b56a4
commit
723ef2b8e6
14 files changed
+14
-71
No files matched your search
@@ -227,7 +227,7 @@ func (w *ServerWorker) handleStatusNew(ctx context.Context, meta *FrameMetadata,
|
|||||||
errors.LogInfoInner(ctx, err, "XUDP hit ", meta.GlobalID)
|
errors.LogInfoInner(ctx, err, "XUDP hit ", meta.GlobalID)
|
||||||
}
|
}
|
||||||
if mb != nil {
|
if mb != nil {
|
||||||
ctx = session.ContextWithTimeoutOnly(ctx, true)
|
ctx = context.WithoutCancel(ctx)
|
||||||
// Actually, it won't return an error in Xray-core's implementations.
|
// Actually, it won't return an error in Xray-core's implementations.
|
||||||
link, err := w.dispatcher.Dispatch(ctx, meta.Target)
|
link, err := w.dispatcher.Dispatch(ctx, meta.Target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+12
-25
@@ -11,20 +11,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
inboundSessionKey ctx.SessionKey = 1
|
inboundSessionKey ctx.SessionKey = iota
|
||||||
outboundSessionKey ctx.SessionKey = 2
|
outboundSessionKey
|
||||||
contentSessionKey ctx.SessionKey = 3
|
contentSessionKey
|
||||||
isReverseMuxKey ctx.SessionKey = 4 // is reverse mux
|
isReverseMuxKey // is reverse mux
|
||||||
sockoptSessionKey ctx.SessionKey = 5 // used by dokodemo to only receive sockopt.Mark
|
sockoptSessionKey // used by dokodemo to only receive sockopt.Mark
|
||||||
trackedConnectionErrorKey ctx.SessionKey = 6 // used by observer to get outbound error
|
trackedConnectionErrorKey // used by observer to get outbound error
|
||||||
dispatcherKey ctx.SessionKey = 7 // used by ss2022 inbounds to get dispatcher
|
dispatcherKey // 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 // muxcool server control incoming request tcp/udp
|
||||||
allowedNetworkKey ctx.SessionKey = 9 // muxcool server control incoming request tcp/udp
|
fullHandlerKey // outbound gets full handler
|
||||||
fullHandlerKey ctx.SessionKey = 10 // outbound gets full handler
|
mitmAlpn11Key // used by TLS dialer
|
||||||
mitmAlpn11Key ctx.SessionKey = 11 // used by TLS dialer
|
mitmServerNameKey // used by TLS dialer
|
||||||
mitmServerNameKey ctx.SessionKey = 12 // used by TLS dialer
|
streamSettingsKey
|
||||||
|
|
||||||
streamSettingsKey ctx.SessionKey = 13
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func ContextWithInbound(ctx context.Context, inbound *Inbound) context.Context {
|
func ContextWithInbound(ctx context.Context, inbound *Inbound) context.Context {
|
||||||
@@ -137,17 +135,6 @@ func DispatcherFromContext(ctx context.Context) routing.Dispatcher {
|
|||||||
return nil
|
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 {
|
func ContextWithAllowedNetwork(ctx context.Context, network net.Network) context.Context {
|
||||||
return context.WithValue(ctx, allowedNetworkKey, network)
|
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)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
terminate := func() {
|
terminate := func() {
|
||||||
cancel()
|
cancel()
|
||||||
|
|||||||
@@ -388,10 +388,6 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
errors.LogInfo(ctx, "connection opened to ", destination, ", local endpoint ", conn.LocalAddr(), ", remote endpoint ", conn.RemoteAddr())
|
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()
|
plcy := h.policy()
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
timer := signal.CancelAfterInactivity(ctx, cancel, plcy.Timeouts.ConnectionIdle)
|
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)
|
p = c.policyManager.ForLevel(user.Level)
|
||||||
}
|
}
|
||||||
|
|
||||||
if session.TimeoutOnlyFromContext(ctx) {
|
|
||||||
ctx = context.WithoutCancel(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
timer := signal.CancelAfterInactivity(ctx, cancel, p.Timeouts.ConnectionIdle)
|
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()
|
defer conn.Close()
|
||||||
errors.LogInfo(ctx, "tunneling request to ", target, " via ", target.Network, ":", c.server.Destination.NetAddr())
|
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)
|
sessionPolicy := c.policyManager.ForLevel(0)
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle)
|
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
|
request.User = user
|
||||||
|
|
||||||
if session.TimeoutOnlyFromContext(ctx) {
|
|
||||||
ctx = context.WithoutCancel(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
sessionPolicy := c.policyManager.ForLevel(user.Level)
|
sessionPolicy := c.policyManager.ForLevel(user.Level)
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle)
|
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)
|
return errors.New("failed to connect to server").Base(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if session.TimeoutOnlyFromContext(ctx) {
|
|
||||||
ctx = context.WithoutCancel(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
if network == net.Network_TCP {
|
if network == net.Network_TCP {
|
||||||
serverConn := o.method.DialEarlyConn(connection, singbridge.ToSocksaddr(destination))
|
serverConn := o.method.DialEarlyConn(connection, singbridge.ToSocksaddr(destination))
|
||||||
var handshake bool
|
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")
|
errors.LogInfoInner(ctx, err, "failed to clear deadline after handshake")
|
||||||
}
|
}
|
||||||
|
|
||||||
if session.TimeoutOnlyFromContext(ctx) {
|
|
||||||
ctx = context.WithoutCancel(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
timer := signal.CancelAfterInactivity(ctx, cancel, p.Timeouts.ConnectionIdle)
|
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")
|
return errors.New("user account is not valid")
|
||||||
}
|
}
|
||||||
|
|
||||||
if session.TimeoutOnlyFromContext(ctx) {
|
|
||||||
ctx = context.WithoutCancel(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
sessionPolicy := c.policyManager.ForLevel(user.Level)
|
sessionPolicy := c.policyManager.ForLevel(user.Level)
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle)
|
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
|
ob.CanSpliceCopy = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
if session.TimeoutOnlyFromContext(ctx) {
|
|
||||||
ctx = context.WithoutCancel(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
sessionPolicy := h.policyManager.ForLevel(request.User.Level)
|
sessionPolicy := h.policyManager.ForLevel(request.User.Level)
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle)
|
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))
|
behaviorSeed := crc64.Checksum(hashkdf.Sum(nil), crc64.MakeTable(crc64.ISO))
|
||||||
|
|
||||||
if session.TimeoutOnlyFromContext(ctx) {
|
|
||||||
ctx = context.WithoutCancel(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
session := encoding.NewClientSession(ctx, int64(behaviorSeed))
|
session := encoding.NewClientSession(ctx, int64(behaviorSeed))
|
||||||
sessionPolicy := h.policyManager.ForLevel(request.User.Level)
|
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)
|
return errors.New("invalid target ", ob.Target)
|
||||||
}
|
}
|
||||||
|
|
||||||
if session.TimeoutOnlyFromContext(ctx) {
|
|
||||||
ctx = context.WithoutCancel(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
sessionPolicy := h.policyManager.ForLevel(0)
|
sessionPolicy := h.policyManager.ForLevel(0)
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle)
|
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 = c.ContextWithID(gctx, c.IDFromContext(ctx))
|
||||||
gctx = session.ContextWithOutbounds(gctx, session.OutboundsFromContext(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)
|
c, err := internet.DialSystem(gctx, net.TCPDestination(address, port), sockopt)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
Reference in new issue
Block a user