1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-06-05 18:49:14 -04:00

Add trojan over xtls support (#334)

* Add trojan over xtls support

* Add comments

* improve PR quality

* improve PR quality

* add xtls-rprx-origin-udp443 and xtls-rprx-direct-udp443

Co-authored-by: Eken Chan <maskedeken@yahoo.com>
This commit is contained in:
ekenchan
2020-10-20 18:44:31 +08:00
committed by GitHub
parent b562f21ca2
commit 3fc985dd0e
8 changed files with 288 additions and 332 deletions

View File

@@ -21,9 +21,17 @@ var (
const (
maxLength = 8192
// XRO is constant for XTLS origin mode
XRO = "xtls-rprx-origin"
// XRD is constant for XTLS direct mode
XRD = "xtls-rprx-direct"
commandTCP byte = 1
commandUDP byte = 3
// for xtls
commandXRO byte = 0xf1 // XTLS origin mode
commandXRD byte = 0xf2 // XTLS direct mode
)
// ConnWriter is TCP Connection Writer Wrapper for trojan protocol
@@ -31,6 +39,7 @@ type ConnWriter struct {
io.Writer
Target net.Destination
Account *MemoryAccount
Flow string
headerSent bool
}
@@ -67,6 +76,10 @@ func (c *ConnWriter) writeHeader() error {
command := commandTCP
if c.Target.Network == net.Network_UDP {
command = commandUDP
} else if c.Flow == XRO {
command = commandXRO
} else if c.Flow == XRD {
command = commandXRD
}
if _, err := buffer.Write(c.Account.Key); err != nil {
@@ -160,6 +173,7 @@ func (w *PacketWriter) writePacket(payload []byte, dest net.Destination) (int, e
type ConnReader struct {
io.Reader
Target net.Destination
Flow string
headerParsed bool
}
@@ -183,6 +197,10 @@ func (c *ConnReader) ParseHeader() error {
network := net.Network_TCP
if command[0] == commandUDP {
network = net.Network_UDP
} else if command[0] == commandXRO {
c.Flow = XRO
} else if command[0] == commandXRD {
c.Flow = XRD
}
addr, port, err := addrParser.ReadAddressPort(nil, c.Reader)