修订代码,文档,示例

This commit is contained in:
e1732a364fed
2000-01-01 00:00:00 +00:00
parent bdb73ffc9d
commit 78faa9ebae
7 changed files with 51 additions and 37 deletions

View File

@@ -105,6 +105,28 @@ func printSupportedProtocols() {
advLayer.PrintAllProtocolNames()
}
func printAllState(w io.Writer, withoutTProxy bool) {
fmt.Fprintln(w, "activeConnectionCount", vs.ActiveConnectionCount)
fmt.Fprintln(w, "allDownloadBytesSinceStart", vs.AllDownloadBytesSinceStart)
fmt.Fprintln(w, "allUploadBytesSinceStart", vs.AllUploadBytesSinceStart)
for i, s := range allServers {
fmt.Fprintln(w, "inServer", i, proxy.GetFullName(s), s.AddrStr())
}
if !withoutTProxy && len(tproxyList) > 0 {
for i, tc := range tproxyList {
fmt.Fprintln(w, "inServer", i+len(allServers), "tproxy", tc.String())
}
}
for i, c := range allClients {
fmt.Fprintln(w, "outClient", i, proxy.GetFullName(c), c.AddrStr())
}
}
//see https://dev.maxmind.com/geoip/geolite2-free-geolocation-data?lang=en
func tryDownloadMMDB() {
fp := utils.GetFilePath(netLayer.GeoipFileName)
@@ -171,28 +193,6 @@ func tryDownloadMMDB() {
}
func printAllState(w io.Writer, withoutTProxy bool) {
fmt.Fprintln(w, "activeConnectionCount", vs.ActiveConnectionCount)
fmt.Fprintln(w, "allDownloadBytesSinceStart", vs.AllDownloadBytesSinceStart)
fmt.Fprintln(w, "allUploadBytesSinceStart", vs.AllUploadBytesSinceStart)
for i, s := range allServers {
fmt.Fprintln(w, "inServer", i, proxy.GetFullName(s), s.AddrStr())
}
if !withoutTProxy && len(tproxyList) > 0 {
for i, tc := range tproxyList {
fmt.Fprintln(w, "inServer", i+len(allServers), "tproxy", tc.String())
}
}
for i, c := range allClients {
fmt.Fprintln(w, "outClient", i, proxy.GetFullName(c), c.AddrStr())
}
}
//试图从自己已经配置好的节点去下载geosite源码文件, 如果没有节点则直连下载。
// 我们只需要一个dial配置即可. listen我们不使用配置文件的配置而是自行监听一个随机端口用于http代理
func tryDownloadGeositeSource() {

View File

@@ -7,15 +7,17 @@
# tproxy无法在 交互模式/apiServer中配置 或 热加载, 只能用 标准toml配置文件启用. (因为涉及到 iptables
# tproxy只支持客户端, 且只支持linux系统, 一般用于软路由/树莓派等.
[[listen]]
protocol = "tproxy" # tproxy只支持客户端, 且只支持linux系统, 一般用于软路由/树莓派等.
host = "0.0.0.0" # 这里不要填 127.0.0.1了,否则只会转发本机流量,而一般作为透明代理都是为了转发局域网内其它设备的流量的。
protocol = "tproxy"
ip = "0.0.0.0" # 这里不要填 127.0.0.1了,否则只会转发本机流量,而一般作为透明代理都是为了转发局域网内其它设备的流量的。
port = 12345
# sockopt.tproxy = true # 不需要明示指明 tproxy这个 sockopt, 因为protocol指出tproxy后就会自动配置该项.
# 不用指明network, 只要指明了tproxy, 就会同时自动监听 tcp和 dup.
#extra = { auto_iptables = true } # 如果给出了 auto_iptables, 且只有一个 tproxy的listen, 则程序会自动在开始监听前配置好iptables并在程序退出前 清除iptables中被程序改动的部分。
#extra = { auto_iptables = true } # 如果给出了 auto_iptables, 且 【protocol 为 tproxy 的listen】【只有一个】, 则程序会自动在开始监听前配置好iptables并在程序退出前 清除iptables中被程序改动的部分。
# auto_iptables 会一字不差地运行 上面 给出的 toutyrater 的教程中的 iptables命令。

View File

@@ -19,6 +19,9 @@
# 如果 default_uuid 给出了,且某个 需要uuid的地方没给出则会使用 default_uuid 的值
# default_uuid = "a684455c-b14f-11ea-bf0d-42010aaa0003"
# 一般而言 default_uuid 适合用于服务端因为客户端一般除了vless拨号以外还有socks5/http监听如果你设了 default_uuid,
# 那么会同时设置socks5的uuid虽然uuid对于socks5是无效的socks5使用用户名密码但是感觉也不太对劲。
# mycountry = "CN" #全局级的 国别分流配置, 见下面route的注释
# noreadv = true

View File

@@ -43,7 +43,7 @@ func NewClassicFallbackFromConfList(fcl []*FallbackConf) *ClassicFallback {
var aMask byte
if len(fc.Alpn) > 2 {
//理论上alpn可以为任意值但是由于我们要回落搞那么多奇葩的alpn只会增加被审查的概率
// 所以这里在代码直接就禁止这种做法就ok了
// 所以这里在代码直接就禁止这种做法就ok了
} else {
for _, v := range fc.Alpn {
if v == H2_Str {

View File

@@ -64,8 +64,9 @@ type Fallback interface {
}
type FallbackResult struct {
Addr netLayer.Addr
Xver int
Addr netLayer.Addr
Xver int
ToTag string
}
func (r *FallbackResult) GetFallback(ftype byte, _ ...string) *FallbackResult {
@@ -85,6 +86,8 @@ type FallbackConf struct {
//必填
Dest any `toml:"dest" json:"dest"` //see netLayer.NewAddrFromAny for details about "any" addr
ToTag string `toml:"toTag" json:"toTag"` //有些回落 像 unix domain socket 的话,地址可能很长,写起来不方便,所以还是 写到 toTag 里比较简单 明了
//几种匹配方式,可选
Path string `toml:"path" json:"path"`

View File

@@ -77,7 +77,15 @@ wget https://github.com/v2fly/domain-list-community/archive/refs/tags/$tag.tar.x
*/
var GeositeListMap = make(map[string]*GeositeList)
var (
GeositeListMap = make(map[string]*GeositeList)
geositeFolder = "geosite/data"
)
func HasGeositeFolder() bool {
geositeFolder = utils.GetFilePath(geositeFolder)
return utils.DirExist(geositeFolder)
}
// v2fly经典匹配配置
//full:v2ray.com, domain:v2ray.com, domain意思是匹配子域名,
@@ -145,14 +153,13 @@ func (mdh MapGeositeDomainHaser) HasDomain(d string) bool {
//
//该 geosite/data 就是 github.com/v2fly/domain-list-community 项目的 data文件夹.
func LoadGeositeFiles() (err error) {
dir := "geosite/data"
dir = utils.GetFilePath(dir)
if !utils.DirExist(dir) {
if !HasGeositeFolder() {
return os.ErrNotExist
}
ref := make(map[string]*GeositeRawList)
err = filepath.WalkDir(dir, func(path string, info fs.DirEntry, err error) error {
err = filepath.WalkDir(geositeFolder, func(path string, info fs.DirEntry, err error) error {
if err != nil {
return err
}
@@ -183,10 +190,6 @@ func LoadGeositeFiles() (err error) {
return nil
}
func HasGeositeFolder() bool {
return utils.DirExist(utils.GetFilePath("geosite/data"))
}
// DownloadCommunity_DomainListFiles 从 v2fly/domain-list-community 下载数据文件, 并放到 geosite文件夹中。
// 如果已存在geosite文件夹return immediately.
//

View File

@@ -70,6 +70,9 @@ func GetFilePath(fileName string) string {
}
}
// 下面的 runtime.Caller 查找调用函数对应的源文件所在目录。只适合普通go build的情况如果是release版因为使用了 trimpath参数
// 就找不到源文件的路径了。不过一般使用发布版的人 也不是 git clone的而是直接下载的所以本来也找不到, 所以无所谓。
if _, srcFile, _, ok := runtime.Caller(0); ok {
p := filepath.Join(filepath.Dir(srcFile), fileName)
if _, err := os.Stat(p); err == nil {