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 10:44:31 +00:00
committed by GitHub
co-authored by Eken Chan
parent b562f21ca2
commit 3fc985dd0e
8 changed files with 288 additions and 332 deletions
+28
View File
@@ -185,6 +185,34 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn internet
}
// handle tcp request
account, ok := user.Account.(*MemoryAccount)
if !ok {
return newError("user account is not valid")
}
switch clientReader.Flow {
case XRO, XRD:
if account.Flow == clientReader.Flow {
if destination.Address.Family().IsDomain() && destination.Address.Domain() == muxCoolAddress {
return newError("XTLS doesn't support Mux").AtWarning()
}
if xtlsConn, ok := iConn.(*xtls.Conn); ok {
xtlsConn.RPRX = true
if clientReader.Flow == XRD {
xtlsConn.DirectMode = true
}
} else {
return newError(`failed to enable XTLS, maybe "security" is not "xtls"`).AtWarning()
}
} else {
return newError("unable to use ", clientReader.Flow).AtWarning()
}
case "":
default:
return newError("unsupported flow type: ", account.Flow).AtWarning()
}
ctx = log.ContextWithAccessMessage(ctx, &log.AccessMessage{
From: conn.RemoteAddr(),