diff --git a/README.md b/README.md index 8f0aa7d..125ec26 100644 --- a/README.md +++ b/README.md @@ -180,7 +180,11 @@ tls lazy encrypt 特性 运行时可以用 -lazy 参数打开(服务端客户 ```sh git clone https://github.com/hahahrfool/v2ray_simple cd v2ray_simple && go build +``` + +可选拷贝示例文件 +```sh #如果使用极简模式,则复制vs.json文件 cp examples/vs.client.json client.json cp examples/vs.server.json server.json @@ -190,6 +194,8 @@ cp examples/vlesss.client.toml client.toml cp examples/vlesss.server.toml server.toml ``` +如果你不拷贝示例文件,也可以通过 [交互模式](#交互模式) 来生成自定义的配置。 + 详细优化的编译参数请参考Makefile文件 如果你是直接下载的可执行文件,则不需要 go build了,直接复制 示例文件即可 @@ -327,7 +333,10 @@ openssl req -new -x509 -days 7305 -key cert.key -out cert.pem ## 开发标准以及理念 -文档尽量多,代码尽量少 +文档尽量多,代码尽量少. 同时本作不追求极致模块化, 可以进行适当耦合. 一切以速度、浅显易懂 优先 + +KISS, Keep it Simple and Stupid + ### 文档 文档、注释尽量详细,且尽量完全使用中文,尽量符合golang的各种推荐标准。 @@ -356,7 +365,7 @@ https://github.com/hahahrfool/v2ray_simple/discussions ## 本项目所使用的开源协议 -MIT协议,即你用的时候也要附带一个MIT文件,然后我不承担任何后果。 +MIT协议,即你用的时候也要附带一个MIT文件,然后作者不承担任何责任、义务、后果。 ## 历史 diff --git a/cli.go b/cli.go index cfdfe6b..60b7ed0 100644 --- a/cli.go +++ b/cli.go @@ -662,3 +662,59 @@ func interactively_hotRemoveServerOrClient() { fmt.Printf(delimiter) printAllState(os.Stdout) } + +//热添加配置文件 +func interactively_hotLoadConfigFile() { + fmt.Printf("即将开始热添加配置文件\n") + fmt.Printf("【注意】我们交互模式只支持热添加listen和dial, 对于dns/route/fallback的热增删, 请期待api server未来的实现.\n") + fmt.Printf("【当前所有配置】为:\n") + fmt.Printf(delimiter) + printAllState(os.Stdout) + + fmt.Printf("请输入你想添加的文件名称\n") + + promptFile := promptui.Prompt{ + Label: "配置文件", + Validate: utils.IsFilePath, + } + + fpath, err := promptFile.Run() + + if err != nil { + fmt.Printf("Prompt failed %v\n", err) + return + } + + fmt.Printf("你输入了 %s\n", fpath) + + standardConf, err = proxy.LoadTomlConfFile(fpath) + if err != nil { + + log.Printf("can not load standard config file: %s\n", err) + return + } + + //listen, dial, dns, route, fallbacks 这几项都可以选择性加载 + + //但是route和fallback的话,动态增删很麻烦,因为route/fallback可能配置相当多条; + + //而dns的话,没法简单增删, 而是会覆盖。 + + //因此我们交互模式暂且只支持 listen和dial的热加载。 dns/route/fallback的热增删可以用apiServer实现. + + //也就是说,理论上要写一个比较好的前端,才能妥善解决 复杂条目的热增删问题。 + + if len(standardConf.Listen) > 0 { + hotLoadListenConfForRuntime(standardConf.Listen) + + } + + if len(standardConf.Dial) > 0 { + hotLoadDialConfForRuntime(standardConf.Dial) + + } + + fmt.Printf("添加成功!当前状态:\n") + fmt.Printf(delimiter) + printAllState(os.Stdout) +} diff --git a/examples/multi.client.toml b/examples/multi.client.toml index a1dbe2a..971b210 100644 --- a/examples/multi.client.toml +++ b/examples/multi.client.toml @@ -130,7 +130,11 @@ country = ["US"] # ip = ["0.0.0.0/8","10.0.0.0/8","fe80::/10","10.0.0.1"] # 域名匹配完全兼容 v2ray,请参考 https://www.v2fly.org/config/routing.html#ruleobject -# domain = ["domain:www.google.com","full:www.twitter.com", "geosite:cn"] +# 下面简单说一下: +# 不包含冒号的项会使用字符串匹配方式 (MATCH), 而如果是 domain:的话,会依次尝试匹配其子域名; 如果是full:的话则会完整匹配该域名 +# 还可以用正则表达式,不过太难了我就不在这里讲了. 懂正则的人有需求就用, 不懂正则就不要用. +# +# domain = ["domain:www.google.com","full:www.twitter.com", "geosite:cn","baidu"] # 比如这个就是 将CN国家的域名 导向自己的grpc节点 [[route]] diff --git a/proxy/creator.go b/proxy/creator.go index 2caeb34..63593d9 100644 --- a/proxy/creator.go +++ b/proxy/creator.go @@ -303,7 +303,7 @@ func configCommonForClient(cli ProxyCommon, dc *DialConf) { } } -//SetAddrStr,setNetwork, setTag, setCantRoute,setListenConf(lc), call configCommon +//SetAddrStr,setNetwork, setTag, setCantRoute,setListenConf(lc),setFallback, call configCommon func configCommonForServer(ser ProxyCommon, lc *ListenConf) { ser.SetAddrStr(lc.GetAddrStrForListenOrDial()) ser.setNetwork(lc.Network)