mirror of
https://github.com/e1732a364fed/v2ray_simple.git
synced 2025-12-24 13:27:56 +08:00
修订代码,文档;logfile标准配置以及-sp行为改变,见下:
在标准 toml 配置中 配置 logfile 配置文件路径。 如 `logfile = "/var/log/verysimple/vs_log"` 将 -sp 的行为 改为 打印完毕后立即退出。
This commit is contained in:
@@ -284,9 +284,12 @@ v0协议是直接兼容现有v2ray/xray的,比如可以客户端用任何现
|
||||
|
||||
支持 quic以及hysteria 阻控,与xray/v2ray兼容(详情见wiki),还新开发了“手动挡”模式
|
||||
|
||||
api服务器;tproxy 透明代理; http伪装头
|
||||
api服务器;tproxy 透明代理; http伪装头.
|
||||
|
||||
本作也是支持 trojan-go 声称的 “可插拔模块”的,没什么复杂的。而且还可以用build tag 来开启或关闭某项功能,更胜一筹。
|
||||
|
||||
总之,可以看到,几乎在每一个技术上 本作都有一定的优化,超越其他内核,非常 Nice。
|
||||
|
||||
总之,可以看到,几乎在每一个技术上 本作都有一定的优化,非常 Nice。
|
||||
## 技术详情
|
||||
### 关于vless v1
|
||||
|
||||
|
||||
@@ -771,7 +771,7 @@ func interactively_adjust_loglevel() {
|
||||
|
||||
if i < len(list) && i >= 0 {
|
||||
utils.LogLevel = i
|
||||
utils.InitLog()
|
||||
utils.InitLog("")
|
||||
|
||||
fmt.Printf("调节 日志等级完毕. 现在等级为\n")
|
||||
fmt.Printf(list[i])
|
||||
|
||||
@@ -65,13 +65,24 @@ func isFlexible() bool {
|
||||
return interactive_mode || apiServerRunning
|
||||
}
|
||||
|
||||
//在开始正式代理前, 先运行一些需要运行的命令与函数
|
||||
func runPreCommands() {
|
||||
//运行一些 执行后立即退出程序的 命令
|
||||
func runExitCommands() (atLeastOneCalled bool) {
|
||||
if cmdPrintVer {
|
||||
atLeastOneCalled = true
|
||||
printVersion_simple()
|
||||
}
|
||||
|
||||
if cmdPrintSupportedProtocols {
|
||||
atLeastOneCalled = true
|
||||
printSupportedProtocols()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
//在开始正式代理前, 先运行一些需要运行的命令与函数
|
||||
func runPreCommands() {
|
||||
|
||||
if !nodownload {
|
||||
tryDownloadMMDB()
|
||||
}
|
||||
@@ -82,7 +93,7 @@ func generateAndPrintUUID() {
|
||||
}
|
||||
|
||||
func printSupportedProtocols() {
|
||||
|
||||
fmt.Printf("Support tcp/udp/tproxy/unix domain socket/tls/uTls by default.\n")
|
||||
proxy.PrintAllServerNames()
|
||||
proxy.PrintAllClientNames()
|
||||
advLayer.PrintAllProtocolNames()
|
||||
|
||||
@@ -12,14 +12,15 @@ import (
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/pkg/profile"
|
||||
"go.uber.org/zap"
|
||||
|
||||
vs "github.com/e1732a364fed/v2ray_simple"
|
||||
"github.com/e1732a364fed/v2ray_simple/httpLayer"
|
||||
"github.com/e1732a364fed/v2ray_simple/netLayer"
|
||||
"github.com/e1732a364fed/v2ray_simple/netLayer/tproxy"
|
||||
"github.com/e1732a364fed/v2ray_simple/proxy"
|
||||
"github.com/e1732a364fed/v2ray_simple/utils"
|
||||
"github.com/pkg/profile"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -28,7 +29,7 @@ var (
|
||||
startMProf bool
|
||||
listenURL string //用于命令行模式
|
||||
dialURL string //用于命令行模式
|
||||
jsonMode int
|
||||
//jsonMode int
|
||||
|
||||
standardConf proxy.StandardConf
|
||||
simpleConf proxy.SimpleConf
|
||||
@@ -45,11 +46,15 @@ var (
|
||||
routingEnv proxy.RoutingEnv
|
||||
)
|
||||
|
||||
const (
|
||||
defaultLogFile = "vs_log"
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&configFileName, "c", "client.toml", "config file name")
|
||||
flag.BoolVar(&startPProf, "pp", false, "pprof")
|
||||
flag.BoolVar(&startMProf, "mp", false, "memory pprof")
|
||||
flag.IntVar(&jsonMode, "jm", 0, "json mode, 0:verysimple mode; 1: v2ray mode(not implemented yet)")
|
||||
//flag.IntVar(&jsonMode, "jm", 0, "json mode, 0:verysimple mode; 1: v2ray mode(not implemented yet)")
|
||||
|
||||
flag.StringVar(&listenURL, "L", "", "listen URL, only used when no config file is provided.")
|
||||
flag.StringVar(&dialURL, "D", "", "dial URL, only used when no config file is provided.")
|
||||
@@ -58,7 +63,7 @@ func init() {
|
||||
|
||||
flag.IntVar(&utils.LogLevel, "ll", utils.DefaultLL, "log level,0=debug, 1=info, 2=warning, 3=error, 4=dpanic, 5=panic, 6=fatal")
|
||||
|
||||
flag.StringVar(&utils.LogOutFileName, "lf", "vs_log", "output file for log; If empty, no log file will be used.")
|
||||
flag.StringVar(&utils.LogOutFileName, "lf", defaultLogFile, "output file for log; If empty, no log file will be used.")
|
||||
|
||||
flag.BoolVar(&netLayer.UseReadv, "readv", netLayer.DefaultReadvOption, "toggle the use of 'readv' syscall")
|
||||
|
||||
@@ -103,31 +108,15 @@ func mainFunc() (result int) {
|
||||
}
|
||||
}()
|
||||
|
||||
flag.Parse()
|
||||
utils.ParseFlags()
|
||||
|
||||
if cmdPrintVer {
|
||||
printVersion_simple()
|
||||
//根据 cmdPrintVer 的定义, 我们直接退出
|
||||
if runExitCommands() {
|
||||
return
|
||||
} else {
|
||||
printVersion()
|
||||
|
||||
}
|
||||
|
||||
if !utils.IsFlagGiven("lf") {
|
||||
if strings.Contains(configFileName, "server") {
|
||||
utils.LogOutFileName += "_server"
|
||||
} else if strings.Contains(configFileName, "client") {
|
||||
utils.LogOutFileName += "_client"
|
||||
}
|
||||
}
|
||||
|
||||
if utils.LogOutFileName != "" {
|
||||
utils.ShouldLogToFile = true
|
||||
}
|
||||
|
||||
utils.InitLog()
|
||||
|
||||
if startPProf {
|
||||
f, _ := os.OpenFile("cpu.pprof", os.O_CREATE|os.O_RDWR, 0644)
|
||||
defer f.Close()
|
||||
@@ -142,16 +131,57 @@ func mainFunc() (result int) {
|
||||
defer p.Stop()
|
||||
}
|
||||
|
||||
utils.Info("Program started")
|
||||
defer utils.Info("Program exited")
|
||||
|
||||
var err error
|
||||
var mode int
|
||||
var mainFallback *httpLayer.ClassicFallback
|
||||
|
||||
standardConf, simpleConf, mode, mainFallback, err = proxy.LoadConfig(configFileName, listenURL, dialURL)
|
||||
var loadConfigErr error
|
||||
|
||||
if err != nil && !isFlexible() {
|
||||
standardConf, simpleConf, mode, mainFallback, loadConfigErr = proxy.LoadConfig(configFileName, listenURL, dialURL, 0)
|
||||
|
||||
if loadConfigErr == nil {
|
||||
|
||||
if appConf := standardConf.App; appConf != nil {
|
||||
|
||||
if appConf.LogFile != nil && utils.GivenFlags["lf"] == nil {
|
||||
utils.LogOutFileName = *appConf.LogFile
|
||||
|
||||
}
|
||||
|
||||
if appConf.LogLevel != nil && utils.GivenFlags["ll"] == nil {
|
||||
utils.LogLevel = *appConf.LogLevel
|
||||
|
||||
}
|
||||
if appConf.NoReadV && utils.GivenFlags["readv"] == nil {
|
||||
netLayer.UseReadv = false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if utils.LogOutFileName == defaultLogFile {
|
||||
|
||||
if strings.Contains(configFileName, "server") {
|
||||
utils.LogOutFileName += "_server"
|
||||
} else if strings.Contains(configFileName, "client") {
|
||||
utils.LogOutFileName += "_client"
|
||||
}
|
||||
}
|
||||
|
||||
utils.InitLog("Program started")
|
||||
defer utils.Info("Program exited")
|
||||
|
||||
{
|
||||
wdir, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if ce := utils.CanLogInfo("Working at"); ce != nil {
|
||||
ce.Write(zap.String("dir", wdir))
|
||||
}
|
||||
}
|
||||
|
||||
if loadConfigErr != nil && !isFlexible() {
|
||||
log.Printf("no config exist, and no api server or interactive cli enabled, exiting...")
|
||||
return -1
|
||||
}
|
||||
|
||||
7
doc.go
7
doc.go
@@ -16,6 +16,13 @@ netLayer.Relay / netLayer.RelayUDP 」 ] }
|
||||
|
||||
用 netLayer操纵路由,用tlsLayer嗅探tls,用httpLayer操纵回落,可选经过高级层, 都搞好后,传到proxy,然后就开始转发
|
||||
|
||||
Tags
|
||||
|
||||
本包提供 noquic, grpc_full 这两个 build tag。
|
||||
|
||||
若 grpc_full 给出,则引用 advLayer/grpc 包,否则默认引用 advLayer/grpcSimple 包。
|
||||
若 noquic给出,则不引用 advLayer/quic,否则 默认引用 advLayer/quic。
|
||||
|
||||
|
||||
*/
|
||||
package v2ray_simple
|
||||
|
||||
@@ -4,11 +4,17 @@
|
||||
[app] # app 项是可选的
|
||||
|
||||
# 日志等级,默认为1. 0=debug, 1=info, 2=warning, 3=error, 4=dpanic, 5=panic, 6=fatal,
|
||||
# 推荐开发时用0, 测试时使用1, 日常使用时 使用2或3; 显然日志越少越快, 设为6或者更大值的话性能是最好的.
|
||||
# 推荐开发时用0, 日常使用时 使用1或2; 显然日志越少越快, 设为6或者更大值的话性能是最好的.
|
||||
#loglevel = 1
|
||||
|
||||
# 如果 default_uuid 给出了,且某个 需要uuid的地方没给出,则会使用 default_uuid 的值
|
||||
# 日志文件地址, 如果路径不存在,会自动创建父文件夹;
|
||||
# 若未给出 或 给出的值为 vs_log,则会自动在工作目录 生成 vs_log文件, 且:
|
||||
# 若配置文件名称包含client,则改为生成 vs_log_client 文件;
|
||||
# 若配置文件名称包含 server, 则改为生成 vs_log_server 文件;
|
||||
# 若设为空字符串,则不生成日志文件.
|
||||
#logfile = "/var/log/verysimple/vs_log"
|
||||
|
||||
# 如果 default_uuid 给出了,且某个 需要uuid的地方没给出,则会使用 default_uuid 的值
|
||||
# default_uuid = "a684455c-b14f-11ea-bf0d-42010aaa0003"
|
||||
|
||||
# mycountry = "CN" #全局级的 国别分流配置, 见下面route的注释
|
||||
|
||||
31
go.sum
31
go.sum
@@ -8,8 +8,6 @@ dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1
|
||||
dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU=
|
||||
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/toml v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
|
||||
github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
|
||||
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
|
||||
@@ -56,7 +54,6 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
|
||||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
|
||||
github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
|
||||
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
|
||||
@@ -136,8 +133,6 @@ github.com/marten-seemann/qtls-go1-18 v0.1.1 h1:qp7p7XXUFL7fpBvSS1sWD+uSqPvzNQK4
|
||||
github.com/marten-seemann/qtls-go1-18 v0.1.1/go.mod h1:mJttiymBAByA49mhlNZZGrH5u1uXYZJ+RW28Py7f4m4=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4=
|
||||
github.com/miekg/dns v1.1.47 h1:J9bWiXbqMbnZPcY8Qi2E3EWIBsIm6MZzzJB9VRg5gL8=
|
||||
github.com/miekg/dns v1.1.47/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME=
|
||||
github.com/miekg/dns v1.1.48 h1:Ucfr7IIVyMBz4lRE8qmGUuZ4Wt3/ZGu9hmcMT3Uu4tQ=
|
||||
github.com/miekg/dns v1.1.48/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
@@ -153,7 +148,6 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
|
||||
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
||||
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
|
||||
github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E=
|
||||
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
|
||||
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
|
||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
|
||||
@@ -162,8 +156,6 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
|
||||
github.com/onsi/gomega v1.13.0 h1:7lLHu94wT9Ij0o6EWWclhu0aOh32VxhkwEJvzuWPeak=
|
||||
github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY=
|
||||
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
|
||||
github.com/oschwald/maxminddb-golang v1.8.0 h1:Uh/DSnGoxsyp/KYbY1AuP0tYEwfs0sCph9p/UMXK/Hk=
|
||||
github.com/oschwald/maxminddb-golang v1.8.0/go.mod h1:RXZtst0N6+FY/3qCNmZMBApR19cdQj43/NM9VkrNAis=
|
||||
github.com/oschwald/maxminddb-golang v1.9.0 h1:tIk4nv6VT9OiPyrnDAfJS1s1xKDQMZOsGojab6EjC1Y=
|
||||
github.com/oschwald/maxminddb-golang v1.9.0/go.mod h1:TK+s/Z2oZq0rSl4PSeAEoP0bgm82Cp5HyvYbt8K3zLY=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
@@ -177,8 +169,6 @@ github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
|
||||
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/refraction-networking/utls v1.0.0 h1:6XQHSjDmeBCF9sPq8p2zMVGq7Ud3rTD2q88Fw8Tz1tA=
|
||||
github.com/refraction-networking/utls v1.0.0/go.mod h1:tz9gX959MEFfFN5whTIocCLUG57WiILqtdVxI8c6Wj0=
|
||||
github.com/refraction-networking/utls v1.1.0 h1:dKXJwSqni/t5csYJ+aQcEgqB7AMWYi6EUc9u3bEmjX0=
|
||||
github.com/refraction-networking/utls v1.1.0/go.mod h1:tz9gX959MEFfFN5whTIocCLUG57WiILqtdVxI8c6Wj0=
|
||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||
@@ -213,9 +203,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
|
||||
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
|
||||
github.com/tobyxdd/quic-go v0.27.1-0.20220414074155-271e5f3ac478 h1:/6nptMH0dGAsaE4/ai70AyOmhRlPBy+lAcvw3x8T0m4=
|
||||
github.com/tobyxdd/quic-go v0.27.1-0.20220414074155-271e5f3ac478/go.mod h1:AzgQoPda7N+3IqMMMkywBKggIFo2KT6pfnlrQ2QieeI=
|
||||
@@ -229,13 +218,11 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA=
|
||||
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
|
||||
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
|
||||
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
|
||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||
go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
|
||||
go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
|
||||
@@ -249,13 +236,9 @@ golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACk
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd h1:XcWmESyNjXJMLahc3mqVQJcgSTDxFxhETVlfk9uGc38=
|
||||
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f h1:OeJjE6G4dgCY4PIXvIRQbE8+RX+uXZyGhUy/ksMGJoc=
|
||||
golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20220407100705-7b9b53b0aca4 h1:K3x+yU+fbot38x5bQbU2QqUAVyYLEktdNH2GxZLnM3U=
|
||||
golang.org/x/exp v0.0.0-20220407100705-7b9b53b0aca4/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
|
||||
golang.org/x/exp v0.0.0-20220428152302-39d4317da171 h1:TfdoLivD44QwvssI9Sv1xwa5DcL5XQr4au4sZ2F2NV4=
|
||||
golang.org/x/exp v0.0.0-20220428152302-39d4317da171/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
|
||||
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
@@ -265,8 +248,6 @@ golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHl
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57 h1:LQmS1nU0twXLA96Kt7U9qtHJEbBk3z6Q0V4UXjZkpr4=
|
||||
golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
@@ -287,8 +268,6 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA=
|
||||
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
@@ -315,7 +294,6 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191224085550-c709ea063b76/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -329,8 +307,6 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220315194320-039c03cc5b86 h1:A9i04dxx7Cribqbs8jf3FQLogkL/CV2YN7hj9KWJCkc=
|
||||
golang.org/x/sys v0.0.0-20220315194320-039c03cc5b86/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc=
|
||||
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
@@ -358,14 +334,11 @@ golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4f
|
||||
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.1.9 h1:j9KsMiaP1c3B0OTQGth0/k+miLGTgLsAFUCrF2vLcF8=
|
||||
golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
|
||||
golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20=
|
||||
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f h1:GGU+dLjvlC3qDwqYgL6UgRmHXhOOgns0bZu2Ty5mm6U=
|
||||
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
@@ -385,7 +358,6 @@ google.golang.org/genproto v0.0.0-20181202183823-bd91e49a0898/go.mod h1:7Ep/1NZk
|
||||
google.golang.org/genproto v0.0.0-20190306203927-b5d61aea6440/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/genproto v0.0.0-20220426171045-31bebdecfb46 h1:G1IeWbjrqEq9ChWxEuRPJu6laA67+XgTFHVSAvepr38=
|
||||
google.golang.org/genproto v0.0.0-20220426171045-31bebdecfb46/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo=
|
||||
@@ -398,7 +370,6 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
|
||||
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
||||
google.golang.org/grpc v1.45.0 h1:NEpgUqV3Z+ZjkqMsxMg11IaDrXY4RY6CQukSGK0uI1M=
|
||||
google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ=
|
||||
google.golang.org/grpc v1.46.0 h1:oCjezcn6g6A75TGoKYBPgKmVBLexhYLM6MebdrPApP8=
|
||||
google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
|
||||
|
||||
9
main.go
9
main.go
@@ -78,7 +78,7 @@ func ListenSer(inServer proxy.Server, defaultOutClientForThis proxy.Client, env
|
||||
|
||||
newConnChan, closer = superSer.StartListen()
|
||||
if newConnChan == nil {
|
||||
utils.Error("superSer.StartListen can't extablish baseConn")
|
||||
utils.Error("superSer.StartListen failed ")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -86,7 +86,9 @@ func ListenSer(inServer proxy.Server, defaultOutClientForThis proxy.Client, env
|
||||
for {
|
||||
newConn, ok := <-newConnChan
|
||||
if !ok {
|
||||
utils.Error("read from Super AdvLayer not ok")
|
||||
if ce := utils.CanLogErr("Read chan from Super AdvLayer closed"); ce != nil {
|
||||
ce.Write(zap.String("advLayer", inServer.AdvancedLayer()))
|
||||
}
|
||||
|
||||
if closer != nil {
|
||||
closer.Close()
|
||||
@@ -94,7 +96,6 @@ func ListenSer(inServer proxy.Server, defaultOutClientForThis proxy.Client, env
|
||||
|
||||
return
|
||||
}
|
||||
//utils.Debug("quic Got New Conn")
|
||||
|
||||
iics := incomingInserverConnState{
|
||||
wrappedConn: newConn,
|
||||
@@ -107,7 +108,7 @@ func ListenSer(inServer proxy.Server, defaultOutClientForThis proxy.Client, env
|
||||
|
||||
}()
|
||||
|
||||
if ce := utils.CanLogInfo("Listening Super"); ce != nil {
|
||||
if ce := utils.CanLogInfo("Listening Super AdvLayer"); ce != nil {
|
||||
|
||||
ce.Write(
|
||||
zap.String("protocol", proxy.GetFullName(inServer)),
|
||||
|
||||
@@ -15,7 +15,7 @@ type testConfStruct struct {
|
||||
func testDns_withConf(t *testing.T, config string) {
|
||||
|
||||
utils.LogLevel = utils.Log_debug
|
||||
utils.InitLog()
|
||||
utils.InitLog("")
|
||||
|
||||
config += `
|
||||
[dns.hosts]
|
||||
@@ -73,7 +73,7 @@ servers = [
|
||||
]
|
||||
`
|
||||
utils.LogLevel = utils.Log_debug
|
||||
utils.InitLog()
|
||||
utils.InitLog("")
|
||||
|
||||
var c testConfStruct
|
||||
_, e := toml.Decode(config, &c)
|
||||
|
||||
@@ -5,6 +5,12 @@ Package netLayer contains definitions in network layer AND transport layer.
|
||||
|
||||
以后如果要添加 kcp 或 raw socket 等底层协议时,也要在此包 或子包里实现.
|
||||
|
||||
Tags
|
||||
|
||||
本包提供 embed_geoip 这个 build tag。
|
||||
|
||||
若给出 embed_geoip,则会尝试内嵌 GeoLite2-Country.mmdb.tgz 文件;默认不内嵌。
|
||||
|
||||
*/
|
||||
package netLayer
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ var (
|
||||
// readv pool, 缓存 mr和buffers,进一步减轻内存分配负担
|
||||
readvPool sync.Pool
|
||||
|
||||
// 是否会在转发过程中使用readv
|
||||
UseReadv bool
|
||||
)
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ BenchmarkClassicCopy_SimulateRealWorld_ReadV-8 66138 17907 ns/op
|
||||
//我们不断向一个net.Conn 发送大数据
|
||||
func TestReadVCopy(t *testing.T) {
|
||||
|
||||
utils.InitLog()
|
||||
utils.InitLog("")
|
||||
|
||||
listenAddr := GetRandLocalAddr(true, false)
|
||||
listener, err := net.Listen("tcp", listenAddr)
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
// TryCopy 尝试 循环 从 readConn 读取数据并写入 writeConn, 直到错误发生。
|
||||
//会接连尝试 splice、循环readv 以及 原始Copy方法
|
||||
//会接连尝试 splice、循环readv 以及 原始Copy方法。如果 UseReadv 的值为false,则不会使用readv。
|
||||
func TryCopy(writeConn io.Writer, readConn io.Reader) (allnum int64, err error) {
|
||||
var multiWriter utils.MultiWriter
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
|
||||
func TestTCP(protocol string, version int, port string, t *testing.T) {
|
||||
utils.LogLevel = utils.Log_debug
|
||||
utils.InitLog()
|
||||
utils.InitLog("")
|
||||
|
||||
url := protocol + "://a684455c-b14f-11ea-bf0d-42010aaa0003@127.0.0.1:" + port + "?version=" + strconv.Itoa(version)
|
||||
server, hase, _ := ServerFromURL(url)
|
||||
@@ -114,7 +114,7 @@ func TestTCP(protocol string, version int, port string, t *testing.T) {
|
||||
// 其他tcp测试因为比较简单,不需要第二步测试,而这里需要
|
||||
func TestUDP(protocol string, version int, proxyPort string, use_multi int, t *testing.T) {
|
||||
utils.LogLevel = utils.Log_debug
|
||||
utils.InitLog()
|
||||
utils.InitLog("")
|
||||
|
||||
t.Log("fakeServerEndLocalServer port is ", proxyPort)
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/e1732a364fed/v2ray_simple/httpLayer"
|
||||
@@ -15,9 +14,10 @@ import (
|
||||
)
|
||||
|
||||
type AppConf struct {
|
||||
LogLevel *int `toml:"loglevel"` //需要为指针, 否则无法判断0到底是未给出的默认值还是 显式声明的0
|
||||
DefaultUUID string `toml:"default_uuid"`
|
||||
MyCountryISO_3166 string `toml:"mycountry" json:"mycountry"` //加了mycountry后,就会自动按照geoip分流,也会对顶级域名进行国别分流
|
||||
LogLevel *int `toml:"loglevel"` //需要为指针, 否则无法判断0到底是未给出的默认值还是 显式声明的0
|
||||
LogFile *string `toml:"logfile"`
|
||||
DefaultUUID string `toml:"default_uuid"`
|
||||
MyCountryISO_3166 string `toml:"mycountry" json:"mycountry"` //加了mycountry后,就会自动按照geoip分流,也会对顶级域名进行国别分流
|
||||
|
||||
NoReadV bool `toml:"noreadv"`
|
||||
|
||||
@@ -59,7 +59,7 @@ func LoadTomlConfFile(fileNamePath string) (StandardConf, error) {
|
||||
|
||||
// 先检查configFileName是否存在,存在就尝试加载文件到 standardConf 或者 simpleConf,否则尝试 listenURL, dialURL 参数.
|
||||
// 若 返回的是 simpleConf, 则还可能返回 mainFallback.
|
||||
func LoadConfig(configFileName, listenURL, dialURL string) (standardConf StandardConf, simpleConf SimpleConf, confMode int, mainFallback *httpLayer.ClassicFallback, err error) {
|
||||
func LoadConfig(configFileName, listenURL, dialURL string, jsonMode int) (standardConf StandardConf, simpleConf SimpleConf, confMode int, mainFallback *httpLayer.ClassicFallback, err error) {
|
||||
|
||||
fpath := utils.GetFilePath(configFileName)
|
||||
if fpath != "" {
|
||||
@@ -75,20 +75,6 @@ func LoadConfig(configFileName, listenURL, dialURL string) (standardConf Standar
|
||||
|
||||
confMode = StandardMode
|
||||
|
||||
//loglevel 和 noreadv这种会被 命令行覆盖的配置,需要直接在 loadConfig函数中先处理一遍
|
||||
if appConf := standardConf.App; appConf != nil {
|
||||
|
||||
if appConf.LogLevel != nil && !utils.IsFlagGiven("ll") {
|
||||
utils.LogLevel = *appConf.LogLevel
|
||||
utils.InitLog()
|
||||
|
||||
}
|
||||
if appConf.NoReadV && !utils.IsFlagGiven("readv") {
|
||||
netLayer.UseReadv = false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return
|
||||
} else {
|
||||
|
||||
@@ -111,45 +97,3 @@ func LoadConfig(configFileName, listenURL, dialURL string) (standardConf Standar
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func LoadEnvFromStandardConf(standardConf *StandardConf) (routingEnv RoutingEnv, Default_uuid string) {
|
||||
|
||||
if len(standardConf.Fallbacks) != 0 {
|
||||
routingEnv.MainFallback = httpLayer.NewClassicFallbackFromConfList(standardConf.Fallbacks)
|
||||
}
|
||||
|
||||
if dnsConf := standardConf.DnsConf; dnsConf != nil {
|
||||
routingEnv.DnsMachine = netLayer.LoadDnsMachine(dnsConf)
|
||||
}
|
||||
|
||||
var hasAppLevelMyCountry bool
|
||||
|
||||
if appConf := standardConf.App; appConf != nil {
|
||||
|
||||
Default_uuid = appConf.DefaultUUID
|
||||
|
||||
hasAppLevelMyCountry = appConf.MyCountryISO_3166 != ""
|
||||
|
||||
if appConf.UDP_timeout != nil {
|
||||
minutes := *appConf.UDP_timeout
|
||||
if minutes > 0 {
|
||||
netLayer.UDP_timeout = time.Minute * time.Duration(minutes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if standardConf.Route != nil || hasAppLevelMyCountry {
|
||||
|
||||
netLayer.LoadMaxmindGeoipFile("")
|
||||
|
||||
routingEnv.RoutePolicy = netLayer.NewRoutePolicy()
|
||||
if hasAppLevelMyCountry {
|
||||
routingEnv.RoutePolicy.AddRouteSet(netLayer.NewRouteSetForMyCountry(standardConf.App.MyCountryISO_3166))
|
||||
|
||||
}
|
||||
|
||||
netLayer.LoadRulesForRoutePolicy(standardConf.Route, routingEnv.RoutePolicy)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
57
proxy/env.go
Normal file
57
proxy/env.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/e1732a364fed/v2ray_simple/httpLayer"
|
||||
"github.com/e1732a364fed/v2ray_simple/netLayer"
|
||||
)
|
||||
|
||||
//used in real relay progress. See source code of v2ray_simple for details.
|
||||
type RoutingEnv struct {
|
||||
RoutePolicy *netLayer.RoutePolicy
|
||||
MainFallback *httpLayer.ClassicFallback
|
||||
DnsMachine *netLayer.DNSMachine
|
||||
}
|
||||
|
||||
func LoadEnvFromStandardConf(standardConf *StandardConf) (routingEnv RoutingEnv, Default_uuid string) {
|
||||
|
||||
if len(standardConf.Fallbacks) != 0 {
|
||||
routingEnv.MainFallback = httpLayer.NewClassicFallbackFromConfList(standardConf.Fallbacks)
|
||||
}
|
||||
|
||||
if dnsConf := standardConf.DnsConf; dnsConf != nil {
|
||||
routingEnv.DnsMachine = netLayer.LoadDnsMachine(dnsConf)
|
||||
}
|
||||
|
||||
var hasAppLevelMyCountry bool
|
||||
|
||||
if appConf := standardConf.App; appConf != nil {
|
||||
|
||||
Default_uuid = appConf.DefaultUUID
|
||||
|
||||
hasAppLevelMyCountry = appConf.MyCountryISO_3166 != ""
|
||||
|
||||
if appConf.UDP_timeout != nil {
|
||||
minutes := *appConf.UDP_timeout
|
||||
if minutes > 0 {
|
||||
netLayer.UDP_timeout = time.Minute * time.Duration(minutes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if standardConf.Route != nil || hasAppLevelMyCountry {
|
||||
|
||||
netLayer.LoadMaxmindGeoipFile("")
|
||||
|
||||
routingEnv.RoutePolicy = netLayer.NewRoutePolicy()
|
||||
if hasAppLevelMyCountry {
|
||||
routingEnv.RoutePolicy.AddRouteSet(netLayer.NewRouteSetForMyCountry(standardConf.App.MyCountryISO_3166))
|
||||
|
||||
}
|
||||
|
||||
netLayer.LoadRulesForRoutePolicy(standardConf.Route, routingEnv.RoutePolicy)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -41,13 +41,6 @@ func (mh *MuxMarkerConn) IsMux() {}
|
||||
// 也有可能是有人通过 nc 来测试,也会遇到这种读不到 firstpayload的情况
|
||||
const FirstPayloadTimeout = time.Millisecond * 100
|
||||
|
||||
//used in real relay progress. See source code of v2ray_simple for details.
|
||||
type RoutingEnv struct {
|
||||
RoutePolicy *netLayer.RoutePolicy
|
||||
MainFallback *httpLayer.ClassicFallback
|
||||
DnsMachine *netLayer.DNSMachine
|
||||
}
|
||||
|
||||
// Client 用于向 服务端 拨号.
|
||||
//服务端是一种 “泛目标”代理,所以我们客户端的 Handshake 要传入目标地址, 来告诉它 我们 想要到达的 目标地址.
|
||||
// 一个Client 掌握从最底层的tcp等到最上层的 代理协议间的所有数据;
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestTCP_trojan_mux(t *testing.T) {
|
||||
//tcp测试我们直接使用http请求来测试
|
||||
func testTCP(t *testing.T, protocol string, version int, network string, innermux bool) {
|
||||
utils.LogLevel = utils.Log_debug
|
||||
utils.InitLog()
|
||||
utils.InitLog("")
|
||||
|
||||
var testClientConfFormatStr = `
|
||||
[[listen]]
|
||||
|
||||
@@ -18,7 +18,7 @@ func TestVlesss(t *testing.T) {
|
||||
|
||||
func testTls(protocol string, t *testing.T) {
|
||||
utils.LogLevel = utils.Log_debug
|
||||
utils.InitLog()
|
||||
utils.InitLog("")
|
||||
|
||||
port := netLayer.RandPortStr(true, false)
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestUDP_trojan_through_udp(t *testing.T) {
|
||||
//udp测试我们直接使用dns请求来测试.
|
||||
func testUDP(t *testing.T, protocol string, version int, network string, multi bool, fullcone bool, mux bool) {
|
||||
utils.LogLevel = utils.Log_debug
|
||||
utils.InitLog()
|
||||
utils.InitLog("")
|
||||
|
||||
//同时监听两个dokodemo, 发向不同raddr, 这样就可以模拟 多raddr目标时的 情况
|
||||
//vless v1的udp_multi的dialfunc 需要单一 client 拨号多个raddr 才能被触发, 所以还要使用socks5测试两次
|
||||
|
||||
25
utils/log.go
25
utils/log.go
@@ -29,11 +29,8 @@ var (
|
||||
LogLevel int
|
||||
ZapLogger *zap.Logger
|
||||
|
||||
//日志输出文件名称
|
||||
LogOutFileName string
|
||||
|
||||
//在 go test时,我们依然想要查看命令行输出, 但是不希望产生多余文件.
|
||||
// 所以只有在main.go 中我们才设置 ShouldLogToFile=true
|
||||
ShouldLogToFile bool
|
||||
)
|
||||
|
||||
func LogLevelStrList() (sl []string) {
|
||||
@@ -50,7 +47,7 @@ func LogLevelStr(lvl int) string {
|
||||
|
||||
func getZapLogFileWriteSyncer(fn string) zapcore.WriteSyncer {
|
||||
return zapcore.AddSync(&lumberjack.Logger{
|
||||
Filename: fn,
|
||||
Filename: fn, //如果给出的路径不存在,则 lumberjack 包 会自动帮助我们创建文件夹
|
||||
MaxSize: 10,
|
||||
MaxBackups: 10,
|
||||
MaxAge: 30,
|
||||
@@ -84,7 +81,7 @@ func capitalLevelEncoderWith5Chars(l zapcore.Level, enc zapcore.PrimitiveArrayEn
|
||||
}
|
||||
|
||||
//本作大量用到zap打印输出, 所以必须调用InitLog函数来初始化,否则就会闪退
|
||||
func InitLog() {
|
||||
func InitLog(firstMsg string) {
|
||||
atomicLevel := zap.NewAtomicLevel()
|
||||
atomicLevel.SetLevel(zapcore.Level(LogLevel - 1))
|
||||
|
||||
@@ -97,7 +94,9 @@ func InitLog() {
|
||||
EncodeTime: zapcore.TimeEncoderOfLayout("2006-01-02 15:04:05.000"),
|
||||
}), zapcore.AddSync(os.Stdout), atomicLevel)
|
||||
|
||||
if ShouldLogToFile && LogOutFileName != "" {
|
||||
willLogToFile := LogOutFileName != ""
|
||||
|
||||
if willLogToFile {
|
||||
jsonConf := zap.NewProductionEncoderConfig()
|
||||
jsonConf.EncodeTime = zapcore.TimeEncoderOfLayout("060102 150405.000") //用一种比较简短的方式输出时间,年月日 时分秒.毫秒。 年只需输出后两位数字即可, 不管Y2K问题
|
||||
jsonConf.LevelKey = "L"
|
||||
@@ -113,7 +112,17 @@ func InitLog() {
|
||||
|
||||
}
|
||||
|
||||
ZapLogger.Info("zap log init complete.")
|
||||
if firstMsg != "" {
|
||||
ZapLogger.Info(firstMsg)
|
||||
}
|
||||
|
||||
if willLogToFile {
|
||||
ZapLogger.Info("zap log init complete.", zap.String("logfile", GetFilePath(LogOutFileName)))
|
||||
|
||||
} else {
|
||||
ZapLogger.Info("zap log init complete.")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func CanLogLevel(l int, msg string) *zapcore.CheckedEntry {
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
func TestZaplog(t *testing.T) {
|
||||
|
||||
LogLevel = Log_info
|
||||
InitLog()
|
||||
InitLog("")
|
||||
|
||||
if ce := CanLogDebug("test1"); ce != nil {
|
||||
ce.Write(
|
||||
|
||||
@@ -34,7 +34,7 @@ func IsFlagGiven(name string) bool {
|
||||
// 如果我们有大量的参数需要判断是否给出过, 那么不如先提取到到map里。
|
||||
//
|
||||
// 实际上flag包的底层也是用的一个map, 但是它是私有的, 而且我们也不宜用unsafe暴露出来.
|
||||
func GetActualFlags() (m map[string]*flag.Flag) {
|
||||
func GetGivenFlags() (m map[string]*flag.Flag) {
|
||||
m = make(map[string]*flag.Flag)
|
||||
flag.Visit(func(f *flag.Flag) {
|
||||
m[f.Name] = f
|
||||
@@ -43,6 +43,14 @@ func GetActualFlags() (m map[string]*flag.Flag) {
|
||||
return
|
||||
}
|
||||
|
||||
var GivenFlags map[string]*flag.Flag
|
||||
|
||||
//call flag.Parse() and assign given flags to GivenFlags.
|
||||
func ParseFlags() {
|
||||
flag.Parse()
|
||||
GivenFlags = GetGivenFlags()
|
||||
}
|
||||
|
||||
//移除 = "" 和 = false 的项
|
||||
func GetPurgedTomlStr(v any) (string, error) {
|
||||
buf := GetBuf()
|
||||
|
||||
Reference in New Issue
Block a user