mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 17:46:58 -05:00
Adjust Trojan over XTLS
This commit is contained in:
parent
358810b37f
commit
c325faef38
@ -100,26 +100,27 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||||||
if destination.Address.Family().IsDomain() && destination.Address.Domain() == muxCoolAddress {
|
if destination.Address.Family().IsDomain() && destination.Address.Domain() == muxCoolAddress {
|
||||||
return newError(account.Flow + " doesn't support Mux").AtWarning()
|
return newError(account.Flow + " doesn't support Mux").AtWarning()
|
||||||
}
|
}
|
||||||
|
|
||||||
if destination.Network == net.Network_UDP {
|
if destination.Network == net.Network_UDP {
|
||||||
if !allowUDP443 && destination.Port == 443 {
|
if !allowUDP443 && destination.Port == 443 {
|
||||||
return newError(account.Flow + " stopped UDP/443").AtInfo()
|
return newError(account.Flow + " stopped UDP/443").AtInfo()
|
||||||
}
|
}
|
||||||
} else { // enable XTLS only if making TCP request
|
} else { // enable XTLS only if making TCP request
|
||||||
if xtlsConn, ok := iConn.(*xtls.Conn); ok {
|
if xtlsConn, ok := iConn.(*xtls.Conn); ok {
|
||||||
connWriter.Flow = account.Flow
|
|
||||||
xtlsConn.RPRX = true
|
xtlsConn.RPRX = true
|
||||||
|
connWriter.Flow = account.Flow
|
||||||
if account.Flow == XRD {
|
if account.Flow == XRD {
|
||||||
xtlsConn.DirectMode = true
|
xtlsConn.DirectMode = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return newError(`failed to enable XTLS, maybe "security" is not "xtls"`).AtWarning()
|
return newError(`failed to use ` + account.Flow + `, maybe "security" is not "xtls"`).AtWarning()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "":
|
case "":
|
||||||
|
if _, ok := iConn.(*xtls.Conn); ok {
|
||||||
|
panic(`To avoid misunderstanding, you must fill in Trojan "flow" when using XTLS.`)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return newError("unsupported flow type: ", account.Flow).AtWarning()
|
return newError("unsupported flow " + account.Flow).AtWarning()
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionPolicy := c.policyManager.ForLevel(user.Level)
|
sessionPolicy := c.policyManager.ForLevel(user.Level)
|
||||||
|
@ -21,17 +21,17 @@ var (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
maxLength = 8192
|
maxLength = 8192
|
||||||
// XRO is constant for XTLS origin mode
|
|
||||||
XRO = "xtls-rprx-origin"
|
|
||||||
// XRD is constant for XTLS direct mode
|
// XRD is constant for XTLS direct mode
|
||||||
XRD = "xtls-rprx-direct"
|
XRD = "xtls-rprx-direct"
|
||||||
|
// XRO is constant for XTLS origin mode
|
||||||
|
XRO = "xtls-rprx-origin"
|
||||||
|
|
||||||
commandTCP byte = 1
|
commandTCP byte = 1
|
||||||
commandUDP byte = 3
|
commandUDP byte = 3
|
||||||
|
|
||||||
// for xtls
|
// for XTLS
|
||||||
|
commandXRD byte = 0xf0 // XTLS direct mode
|
||||||
commandXRO byte = 0xf1 // XTLS origin mode
|
commandXRO byte = 0xf1 // XTLS origin mode
|
||||||
commandXRD byte = 0xf2 // XTLS direct mode
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConnWriter is TCP Connection Writer Wrapper for trojan protocol
|
// ConnWriter is TCP Connection Writer Wrapper for trojan protocol
|
||||||
|
@ -194,24 +194,22 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn internet
|
|||||||
case XRO, XRD:
|
case XRO, XRD:
|
||||||
if account.Flow == clientReader.Flow {
|
if account.Flow == clientReader.Flow {
|
||||||
if destination.Address.Family().IsDomain() && destination.Address.Domain() == muxCoolAddress {
|
if destination.Address.Family().IsDomain() && destination.Address.Domain() == muxCoolAddress {
|
||||||
return newError("XTLS doesn't support Mux").AtWarning()
|
return newError(clientReader.Flow + " doesn't support Mux").AtWarning()
|
||||||
}
|
}
|
||||||
|
|
||||||
if xtlsConn, ok := iConn.(*xtls.Conn); ok {
|
if xtlsConn, ok := iConn.(*xtls.Conn); ok {
|
||||||
xtlsConn.RPRX = true
|
xtlsConn.RPRX = true
|
||||||
|
|
||||||
if clientReader.Flow == XRD {
|
if clientReader.Flow == XRD {
|
||||||
xtlsConn.DirectMode = true
|
xtlsConn.DirectMode = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return newError(`failed to enable XTLS, maybe "security" is not "xtls"`).AtWarning()
|
return newError(`failed to use ` + clientReader.Flow + `, maybe "security" is not "xtls"`).AtWarning()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return newError("unable to use ", clientReader.Flow).AtWarning()
|
return newError("unable to use ", clientReader.Flow).AtWarning()
|
||||||
}
|
}
|
||||||
case "":
|
case "":
|
||||||
default:
|
default:
|
||||||
return newError("unsupported flow type: ", account.Flow).AtWarning()
|
return newError("unsupported flow " + account.Flow).AtWarning()
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = log.ContextWithAccessMessage(ctx, &log.AccessMessage{
|
ctx = log.ContextWithAccessMessage(ctx, &log.AccessMessage{
|
||||||
|
Loading…
Reference in New Issue
Block a user