修订代码,令trojan支持回落;添加共用端口的回落示例,实测可用.

This commit is contained in:
e1732a364fed
2022-05-06 19:27:34 +08:00
parent 516870604b
commit d0daa68cb6
6 changed files with 62 additions and 7 deletions
+53
View File
@@ -0,0 +1,53 @@
# 本文件先监听 vlesss,然后 各种回落
[app]
default_uuid = "a684455c-b14f-11ea-bf0d-42010aaa0003"
[[listen]]
tag = "vlesstls"
protocol = "vlesss"
ip = "0.0.0.0"
host = "your-domain-name.com"
port = 8443
[[listen]]
tag = "vlessgrpc"
protocol = "vless"
network = "unix" # 监听unix domain socket 必须要 给出 network 为 unix
host = "/dev/shm/grpc.sock" # 你必须要保证 /dev/shm路径存在,且你具有写权限,才行。
advancedLayer = "grpc"
path = "very"
[[listen]]
tag = "vlessws"
protocol = "vless"
network = "unix"
host = "/dev/shm/ws.sock" # 别忘了加双引号
advancedLayer = "ws"
path = "/simple"
[[fallback]]
from = "vlesstls"
alpn = ["http/1.1"]
dest = "/dev/shm/ws.sock"
[[fallback]]
from = "vlesstls"
alpn = ["h2"]
dest = "/dev/shm/grpc.sock"
[[fallback]]
from = "vlessgrpc"
dest = "/dev/shm/h2c.sock"
[[fallback]]
from = "vlessws"
dest = "/dev/shm/h1.sock"
[[fallback]]
dest = 80
+2 -2
View File
@@ -116,8 +116,6 @@ func checkfallback(iics incomingInserverConnState) (targetAddr netLayer.Addr, re
}
if inServerTlsConn := iics.inServerTlsConn; inServerTlsConn != nil {
//默认似乎默认tls不会给出alpn和sni项?获得的是空值,也许是因为我用了自签名+insecure,所以导致server并不会设置连接好后所协商的ServerName
// 而alpn则也是正常的, 不设置肯定就是空值
alpn := inServerTlsConn.GetAlpn()
if alpn != "" {
@@ -125,6 +123,7 @@ func checkfallback(iics incomingInserverConnState) (targetAddr netLayer.Addr, re
thisFallbackType |= httpLayer.Fallback_alpn
}
//默认似乎默认tls不会给出sni项?获得的是空值,也许是因为我用了自签名+insecure,所以导致server并不会设置连接好后所协商的ServerName
sni := inServerTlsConn.GetSni()
if sni != "" {
@@ -145,6 +144,7 @@ func checkfallback(iics incomingInserverConnState) (targetAddr netLayer.Addr, re
if fbResult != nil {
ce.Write(
zap.String("matched", fbResult.Addr.String()),
zap.Any("params", fallback_params),
)
} else {
ce.Write(
-4
View File
@@ -12,10 +12,6 @@ Off Topic
总体而言,vless/vmess/trojan协议借鉴了socks5,有不少类似的地方。
所以制作代理, 有必要学习socks5标准。
为了安全, 我们不建议socks5作为 proxy.Client, 因为socks5的server如果放在公网的话,socks5的client发起的请求会被审查者探测到。
所以这里的 Client 没有被注册到proxy。
*/
package socks5
+4
View File
@@ -58,6 +58,10 @@ func (*Server) HasInnerMux() (int, string) {
return 1, "simplesocks"
}
func (*Server) CanFallback() bool {
return true
}
//若握手步骤数据不对, 会返回 ErrDetail 为 utils.ErrInvalidData 的 utils.ErrInErr
func (s *Server) Handshake(underlay net.Conn) (result net.Conn, msgConn netLayer.MsgConn, targetAddr netLayer.Addr, returnErr error) {
if err := underlay.SetReadDeadline(time.Now().Add(time.Second * 4)); err != nil {
+2
View File
@@ -25,6 +25,8 @@ func NewServer(host, certFile, keyFile string, isInsecure bool, alpnList []strin
//发现服务端必须给出 http/1.1 等,否则不会协商出这个alpn,而我们为了回落,是需要协商出所有可能需要等 alpn的。
//而且我们如果不提供 h1 和 h2 的alpn的话,很容易被审查者察觉的。
if alpnList == nil {
alpnList = []string{"http/1.1", "h2"}
} else {
+1 -1
View File
@@ -43,7 +43,7 @@ func (ef ErrBuffer) Unwarp() error {
func (ef ErrBuffer) Error() string {
return ef.Err.Error()
return ef.Err.Error() + ", with Buffer."
}
// ErrInErr 很适合一个err包含另一个err,并且提供附带数据的情况.