修订代码,示例;添加 udp_timeout 配置

This commit is contained in:
hahahrfool
2022-04-07 14:03:31 +08:00
parent 2d384314f4
commit 30eb874dc2
5 changed files with 31 additions and 8 deletions

View File

@@ -8,6 +8,7 @@ import (
"net/url"
"os"
"path/filepath"
"time"
"github.com/BurntSushi/toml"
"github.com/hahahrfool/v2ray_simple/httpLayer"
@@ -32,6 +33,8 @@ type AppConf struct {
NoReadV bool `toml:"noreadv"`
AdminPass string `toml:"admin_pass"`
UDP_timeout *int `toml:"udp_timeout"`
}
//标准配置。默认使用toml格式
@@ -122,6 +125,13 @@ func loadConfig() (err error) {
if appConf.NoReadV && !utils.IsFlagPassed("readv") {
netLayer.UseReadv = false
}
if appConf.UDP_timeout != nil {
minutes := *appConf.UDP_timeout
if minutes > 0 {
netLayer.UDP_timeout = time.Minute * time.Duration(minutes)
}
}
}
return

View File

@@ -22,7 +22,7 @@ servers = [
"udp://114.114.114.114:53", # 如果把该url指向我们dokodemo监听的端口就可以达到通过节点请求dns的目的.
#"udp://127.0.0.1:63782", # 如这一行 就是通过我们节点请求dns
{ addr = "udp://8.8.8.8:53", domain = [ "google.com" ] } # 还可以为特定域名指定特定服务器
#{ addr = "udp://8.8.8.8:53", domain = [ "google.com" ] } # 还可以为特定域名指定特定服务器
]
[dns.hosts] # 自己定义的dns解析
@@ -129,6 +129,10 @@ country = ["US"]
# 其它分流匹配示例:
# ip = ["0.0.0.0/8","10.0.0.0/8","fe80::/10","10.0.0.1"]
# 关于ip中使用cidr匹配ipv6可以参考 https://www.mediawiki.org/wiki/Help:Range_blocks/IPv6
# 比如要想路由所有的ipv6地址可用 ip = ["::/0"]
# 域名匹配完全兼容 v2ray请参考 https://www.v2fly.org/config/routing.html#ruleobject
# 下面简单说一下:
# 不包含冒号的项会使用字符串匹配方式 (MATCH), 而如果是 domain:的话,会依次尝试匹配其子域名; 如果是full:的话则会完整匹配该域名
@@ -141,9 +145,8 @@ country = ["US"]
dialTag = "my_grpc"
domain = ["geosite:cn"]
# network = ["tcp","udp"]
# inTag = ["tag1","tag2"]
# country = ["CN"]
# 其它匹配:
# network = ["tcp","udp"] #匹配传输层协议
# inTag = ["tag1","tag2"] #匹配来自哪一个 listen
# country = ["CN"] # 匹配 geoip 以及 cn 顶级域名.
# 关于ip中使用cidr匹配ipv6可以参考 https://www.mediawiki.org/wiki/Help:Range_blocks/IPv6
# 比如要想路由所有的ipv6地址可用 ip = ["::/0"]

View File

@@ -11,13 +11,18 @@
# default_uuid = "a684455c-b14f-11ea-bf0d-42010aaa0003"
#mycountry = "CN" #全局级的 国别分流配置, 见下面route的注释
# mycountry = "CN" #全局级的 国别分流配置, 见下面route的注释
# noreadv = true
# 也可以用命令行参数 -readv=false 来关闭 readv . readv开启 一般是会加速的, 但不排除减速可能.
# 你可以在测速时开关一下readv看看测速的变化, 如果遇到了readv减速的话 可以通过设置把它关闭。
# 配置udp闲置连接的超时时间. 因为udp是无状态协议, 一旦拨号,是没法确定服务端何时关闭连接的
# 这里单位为分钟,我们默认超时时间就为 3分钟. 如果你有特殊需求, 可以自行调节。
# 不建议过大,因为过大的话, 会造成大量占用本地udp端口的情况, 可能会导致 too many open files 错误
# udp_timeout = 3
[[listen]]
tag = "my_socks5" # 可选, 但不可与其他tag重复
protocol = "socks5" # 必填
@@ -61,7 +66,8 @@ utls = true #是否使用 utls 来应用 chrome指纹进行伪装
# path = "/ohmygod_verysimple_is_very_simple" #为了防探测这里越长越随机越好
# route 是在我们代理界是分流的意思。 这一项是可选的,如果没给出的话,就不分流;
# route 是在我们代理界是分流的意思。
# route 是可选的,如果没给出的话,就不分流;
# 写了 country 后, 向该国家的ip发送的请求就会直连, 然后其他的过代理
# country的字母必须是两个而且必须大写。这个也会自动被用于顶级域名的国别分流
# 同时,必须要一个 GeoLite2-Country.mmdb 文件 放在verysimple的相同目录下. 详情见 README.md

View File

@@ -274,6 +274,7 @@ func (dm *DNSMachine) QueryType(domain string, dns_type uint16) (ip net.IP) {
break
}
}
//没备用的,那就只好保持 dm.defaultConn.Conn 的 nil状态, 下一次dns查询就会失败
}
dm.mutex.Unlock()

View File

@@ -10,6 +10,9 @@ import (
const (
MaxUDP_packetLen = 64 * 1024 // 关于 udp包数据长度可参考 https://cloud.tencent.com/developer/article/1021196
)
var (
//udp不能无限监听, 否则每一个udp申请都对应打开了一个本地udp端口一直监听的话时间一长就会导致 too many open files
// 因为实际上udp在网页代理中主要用于dns请求, 所以不妨设的小一点。
// 放心,只要能持续不断地从远程服务器收到数据, 建立的udp连接就会持续地更新Deadline 而续命一段时间.