Giter VIP home page Giter VIP logo

tcproute2's Introduction

TcpRoute2

Build Status release GitHub license platform

TcpRoute , TCP 层的路由器。对于 TCP 连接自动从多个线路(允许任意嵌套)、多个域名解析结果中选择最优线路。

TcpRoute 使用激进的选路策略,对 DNS 解析获得的多个IP同时尝试连接,同时使用多个线路进行连接,最终使用最快建立的连接。支持 TcpRoute 级别 Hosts 文件,支持黑白名单。提供代理、hosts 信誉度功能,只通过不安全的代理转发 https 等加密连接,提高安全性。当配合 redsocks、Proxifier 作为全局代理时可以启动“强制TcpRoute Dns解析”,强制将浏览器本地 DNS 解析改为代理服务器进行DNS解析来更好的优化网络连接,避免 Dns 污染造成的网络故障。

增加了反运营商 http 劫持功能,有两种方式,简易拆包反劫持及ttl反劫持。

通过 socks5 代理协议对外提供服务。

代理功能拆分成了独立的库,详细代理url格式及选项请参见 ProxyClient,目前支持直连、socks4、socks4a、socks5、http、https 等线路。其中 socks5 支持用户名、密码认证,http、https 支持用户名、密码基本认证。

安装

releases 有各个系统的 zip 包。根据系统下载对应的 zip 文件。解压后复制 config.toml.example 为 config.toml ,并根据 toml 内说明配置好上游代理即可。

Windows 下有图形界面,TcpRoute2-windows-gui-386.zip、TcpRoute2-windows-gui-amd64.zip 即带图形界面的版本。

配置

默认使用当前目录下的 config.toml 文件。

# TcpRoute2 配置文件
# https://github.com/GameXG/TcpRoute2
# 为 TOML 格式,格式说明:https://segmentfault.com/a/1190000000477752

# TcpRoute 监听地址
# 目前只对外提供 socks5 协议。
#
# addr = "127.0.0.1:7070"
# 默认值,表示监听 127.0.0.1 的 7070 端口,仅本机使用 TcpRoute 时建议这样配置。
# 将浏览器代理设置为 socks5 127.0.0.1:7070 即可使用 TcpRoute 代理访问网络。
#
# addr = ":7070"
# 监听所有 ip 地址的 7070 端口,允许其他计算机使用 TcpRoute 访问网络时建议这样配置。
# 将浏览器代理设置为 socks5 TcpRoute计算机IP:7070 即可使用 TcpRoute 代理访问网络。

addr="127.0.0.1:7070"


####################
# 客户端dns解析纠正功能
####################
# 当发现浏览器等客户端进行了本地dns解析时本功能将强制转换为 TcpRoute 进行dns解析。
# 使用 redsocks、Proxifier 实现全局代理时,应用程序会进行本地dns解析,启用这个功能将强制为代理进行dns解析。
# 开启这个功能将避免应用程序本地dns解析时无法避免 dns 污染的问题,同时代理负责DNS解析也能更好的优化网络访问。
#
# chrome 默认是远端dns解析,当不使用 redsocks、Proxifier 时不需要这个功能。
# firefox 很早之前默认是本地 dns 解析,不过可以修改为远端dns解析。目前是什么情况就不知道了。
#
# https 协议下 TcpRoute 是通过 SNI 功能来获得的目标网站域名。
# 因为 WinXP 系统下 IE 所有版本都不支持 SNI 功能,所以 windows xp IE 下 https 强制远端解析功能无效。
#
# 例子:
# PreHttpPorts=[80,]
# PreHttpsPorts=[443,]
# 这个是默认值,对 80 端口的 http 请求启用,对 443 端口的 tls 连接启用。
#
# PreHttpPorts=[0,]
# PreHttpsPorts=[0,]
# 关闭这个功能
#
# 原理:
# TcpRoute 接收到目的地址是域名的请求将不执行“客户端dns解析纠正功能”,
# 但当目的地址是 ip 时,将会读取客户端发出的请求,http 读取 hosts 字段获得域名,https 通过 SNI 功能获得域名。
# 之后将目标网站ip替换为域名,再执行转发操作。


####################
# 线路
####################
#
# TcpRoute 将根据一定的策略使用这里指定的线路(上游代理)将收到的请求请求转发出去。
#
# 目前的策略是 TcpPing ,即同时使用多个线路建立连接,最终使用最快建立连接的线路处理请求。
# 当某条线路访问某网站出现异常(响应超时、连接重置等)时将会被记录下来,下次访问同一网站时将跳过这个线路。
# 允许通过黑白名单指定每个线路允许、拒绝访问指定的网站。
#
# 目前上游代理支持 直连、http、https、socks4、socks4a、socks5 及 ss 协议,其中 http、https、socks5、ss 支持密码认证。
# 注意:直连也必须手工指定,当不指定时将不会使用直连转发请求。
#
##########
# 线路(上游代理)配置说明
##########
# [[UpStreams]]
#
# Name="direct"
# 线路名字,主要是日志使用。默认值为 ProxyUrl 项的内容。
#
#
# ProxyUrl="direct://0.0.0.0:0000"
# 线路(上游代理) URL
# 提供代理的类型、地址、用户认证方式等信息。
# 默认值为:"direct://0.0.0.0:0000"
#
# 支持 直连、http、https、socks4、socks4a、socks5 等协议,其中 http、https、socks5等支持密码认证。
# 允许多层嵌套代理。代理部分已经拆分成了独立的库,详细配置信息可以到 https://github.com/GameXG/ProxyClient 参看。
#
# 可以通过参数指定一些特殊选项,例如,https 代理是否验证服务器 tls 证书。
# 参数格式为:?参数名1=参数值1&参数名2=参数值2
# 例如:https://123.123.123.123:8088?insecureskipverify=true
#     全体协议可选参数: upProxy=http://145.2.1.3:8080 用于指定代理的上层代理,即代理嵌套。默认值:direct://0.0.0.0:0000
#
# 支持的代理协议:
# http 代理 http://123.123.123.123:8088
#     可选功能: 用户认证功能。格式:http://user:[email protected]:8080
#     可选参数:standardheader=false true表示 CONNNET 请求包含标准的 Accept、Accept-Encoding、Accept-Language、User-Agent等头。默认值:false
#
# https 代理 https://123.123.123.123:8088
#     可选功能: 用户认证功能,同 http 代理。
#     可选参数:standardheader=false 同上 http 代理
#     可选参数:insecureskipverify=false true表示跳过 https 证书验证。默认false。
#     可选参数:domain=域名 指定https验证证书时使用的域名,默认为 host:port
#
# socks4 代理 socks4://123.123.123.123:5050
#     注意:socks4 协议不支持远端 dns 解析
#
# socks4a 代理 socks4a://123.123.123.123:5050
#
# socks5 代理 socks5://123.123.123.123:5050
#     可选功能:用户认证功能。支持无认证、用户名密码认证,格式同 http 代理。
#
# 等代理
#
# 直连 direct://0.0.0.0:0000
#     可选参数: LocalAddr=0.0.0.0:0 表示tcp连接绑定的本地ip及端口,默认值 0.0.0.0:0。
#     可选参数: SplitHttp=false true 表示拆分 http 请求(分多个tcp包发送),可以解决简单的运营商 http 劫持。默认值:false 。
#              原理是:当发现目标地址为 80 端口,发送的内容包含 GET、POST、HTTP、HOST 等关键字时,会将关键字拆分到两个包在发送出去。
#              注意: Web 防火墙类软件、设备可能会重组 HTTP 包,造成拆分无效。目前已知 ESET Smart Security 会造成这个功能无效,即使暂停防火墙也一样无效。
#              G|ET /pa|th H|TTTP/1.0
#              HO|ST:www.aa|dd.com
#     可选参数: sleep=0  建立连接后延迟多少毫秒发送数据,配合 ttl 反劫持系统时建议设置为10置50。默认值 0 。
#
# DnsResolve=true
# 是否执行本地dns解析,只建议直连、socks4 线路设置为 true 。
# 设置为 true 时将由 TcpRoute 进行本地 DNS 解析,目前主要是同时使用本地操作系统dns解析及 TcpRoute hosts dns解析。
# 解析获得多个IP时将会同时建立到多个ip的连接,最终使用最快建立连接的ip。
# 设置为 false 时将由上游代理负责dns解析。建议 http、https、socks4a、socks5 等代理都设置为 false 。
# 默认值 false
#
#
# Credit=0
# 线路的信誉度
# 代理线路不安全时建议使用这个选项。
# 当信誉度低于 0 时将不会通过这个线路建立明文协议(http、ftp、stmp等)的连接。
# 各协议需要的信誉度:https://github.com/GameXG/TcpRoute2/blob/master/netchan/dialchan_filter.go#L19
# 默认值 0
#
#
# Sleep=80
# 使用本线路前等待的时间(单位毫秒)
# 主要目的是降低上游代理的负担。
# 建议直连线路设置为 0 ,代理线路设置为 80(毫秒) 。
# 国内 baidu、qq tcping一般是30ms,这里设置为80ms(0.08秒),
# 可以使得大部分国内站点不会尝试通过代理访问,降低上游代理的负担。
# 0.08秒的延迟很低,并且建立连接后会缓存最快连接记录,不会再次延迟,所以不建议删除。
# 当目标网站匹配域名白名单、黑名单,即手工指定线路时,Sleep 参数无效。
# 默认值 0
#
#
# CorrectDelay=0
# 修正延迟
# 某协议缺陷,协议并不会报告是否连接到了目标网站,所以无法获得真实的建立到到目标网站的耗时。
# 无法获得准确的到目标网站的耗时将使得 tcpping 策略无法准确的评估各个线路的速度,所以增加了这个选项用来手工修正。
# tcpping 策略评估最快建立连接的线路时会以 “建立连接的实际耗时 + CorrectDelay” 进行评估,选出最快建立连接的线路。
#
#
######
# 域名白名单
######
# 当前线路的域名白名单(线路级别),白名单内的域名将只从当前线路转发。
# 当一个域名同时存在多个线路白名单内时,将会同时从多个线路尝试建立连接。
# 单个线路可以配置多个白名单,每个白名单一个 [[UpStreams.Whitelist]] 即可。
# 当不存在 [[UpStreams.Whitelist]] 项目时即表示不配置白名单。
# 当目标网站匹配域名白名单、黑名单,即手工指定线路时,线路的 Sleep 参数无效。
#
# [[UpStreams.Whitelist]]
#
# Path="direct.txt"
# 允许本地文件及 http 、https 白名单文件。
# 本地路径是相对路径时,实际路径是相对于 config.toml 文件所在目录。TcpRoute 会检测 hosts 文件修改并自动重新载入。
# http、https 域名文件将按 UpdateInterval 间隔定时更新。
# 不允许单个 [[UpStreams.Whitelist]] 下面出现多个 Path 指定多个白名单文件。
# 多个白名单需要分别放到不同的 [[UpStreams.Whitelist]] 下面。
# 默认值:必填
#
# Path="https://raw.githubusercontent.com/renzhn/MEOW/master/doc/sample-config/direct"
# 感谢 renzhn MEOW 维护的境内网站白名单
#
# Path="https://raw.githubusercontent.com/GameXG/TcpRoute2/master/direct.txt"
# 感谢 puteulanus 整理的 unblock youku 最小国内网站白名单。
#
#
# UpdateInterval="24h"
# 网络 hosts 文件更新间隔
# 最小有效值 1 分钟, 格式为:"1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
# 下载失败时 UpdateInterval 不会生效,将等待 1 分钟重试。
# 默认值: "24h"
#
#
# Type="suffix"
# 域名类型
# 指定域名文件的匹配类型
# base 完整匹配,默认值。即 www.abc.com 只匹配 www.abc.com ,不匹配 aaa.www.abc.com 。
# suffix 后缀匹配。即 abc.com 匹配 abc.com、www.abc.com、aaa.www.abc.com,不匹配 aaaabc.com。
#     注意,想匹配 *.cn 的域名请直接使用 cn ,而不要使用 .cn ,程序内部会自动增加"."。
# pan 泛解析匹配。即 *.abc.com 匹配 www.abc.com 、aaa.www.abc.com。不匹配 .abc.com。?.abc.com 匹配 a.abc.com。
# regex 正则匹配。即 ^.+?.com$ 匹配 www.abc.com 、aaa.www.abc.com。注意:完整匹配时不要忘记 ^$ 。
# 默认值:"base"
#
######
# 域名黑名单
######
# 同域名白名单
# [[UpStreams.Blacklist]]
# 同白名单。
#
# Path="proxy.txt"
#
# Path="https://raw.githubusercontent.com/renzhn/MEOW/master/doc/sample-config/proxy"
# 感谢 renzhn MEOW 维护的网站黑名单
#
# UpdateInterval="24h"
# Type="suffix"


# 直连线路例子:
# 注意:直连也必须手工指定,当不指定时将不会使用直连转发请求。
[[UpStreams]]
Name="direct"
ProxyUrl="direct://0.0.0.0:0000"
DnsResolve=true
# DnsResolve 表示是否执行本地dns解析,直连线路建议指定为 true。

# 直连线路域名白名单
# 各个线路的白名单、黑名单是独立的,可以通过多个 [[UpStreams.Whitelist]] 指定多个白名单。
[[UpStreams.Whitelist]]
Path="https://raw.githubusercontent.com/GameXG/TcpRoute2/master/direct.txt"
# 感谢 puteulanus 整理的 unblock youku 最小国内网站白名单。
UpdateInterval="24h"
Type="suffix"

# 代理线路例子:
[[UpStreams]]
Name="proxy1"
ProxyUrl="socks5://123.123.123.123:5050"
Credit=0
# Credit 表示代理信誉度,低于0的将不会通过当前线路转发明文协议(http、ftp等)的请求。
Sleep=80
# Sleep表示使用本线路前等待的时间,单位毫秒。
CorrectDelay=0
# CorrectDelay 表示当前线路修正延迟,某协议建议设置为 50-100 之间的值,非某协议代理设置为 0。


####################
# Hosts 功能
####################
# 独立与操作系统的 hosts,只对于代理生效。
# 允许通过多个 [[hosts]] 项来同时使用多个 hosts 文件 。
#
# [[Hosts]]
#
# Path="hosts/racaljk_hosts.txt"
# hosts 路径,同域名白名单,允许本地、http、https文件。
# 默认值:必填
#
# Path="https://raw.githubusercontent.com/racaljk/hosts/master/hosts"
# 感谢 https://github.com/racaljk/hosts 项目维护 hosts
#
#
# Type="base"
# hosts 域名类型,同域名白名单。标准的 hosts 文件都是 base 类型。
# 默认值:"base"
#
#
# UpdateInterval="24h"
# 网络 hosts 文件更新间隔
# 最小有效值 1 分钟, 格式:"1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
# 下载失败时 UpdateInterval 不会生效,将等待 1 分钟重试。
# 默认值:"24h"
#
#
# Credit=-100
# hosts 信誉度
# 同线路信誉信誉度,对于小于 0 的 hosts文件将只用于 https 等自带加密的协议。
# 在某些情况下为了防止 http 明文协议分析阻断连接,建议设置为小于 0 的值。
# 默认值:0

# 一个例子
[[Hosts]]
Path="https://raw.githubusercontent.com/racaljk/hosts/master/hosts"
# 感谢 https://github.com/racaljk/hosts 项目维护 hosts
Credit=-100

强制代理服务器 DNS 解析功能

redsocks、Proxifier 全局代理及部分应用会执行本地DNS解析,这样将无法很好的执行优化。启用这个功能后 TcpRoute2 将在发现客户端执行了本地 DNS 解析时强制改为代理服务器进行DNS解析来更好的优化网络连接。

解决了路由器通过 redsocks 配置成全局透明代理时无法应对dns污染的问题。

由于 https 协议是通过 SNI 功能来获得的目标网站域名,所以 WinXP 系统下 IE 所有版本都无法使用 https 强制远端解析功能。

信誉度功能

增加了代理信誉度、dns信誉度的功能,对于信誉度低的代理将只允许 https 、smtp ssl 等本身支持服务器认证的协议。这样使用不安全的代理也能比较安全。

Hosts 功能

增加了代理级别的 hosts 文件,支持本地及网络hosts文件。通过hosts即使在不存在上层代理的情况下也可以优化网络访问。hosts 文件同样也有信誉度功能。

感谢 https://github.com/racaljk/hosts 项目维护 hosts 。

白名单、黑名单功能

允许指定的域名走指定的线路,指定的域名不走指定的线路。 黑白名单是线路级别的,而不是全局的,每个线路都有自己的黑白名单。

感谢 https://github.com/renzhn/MEOW 维护了国内域名白名单。

防运营商 HTTP 劫持功能

拆包反劫持功能

通过拆分 http 请求到多个 tcp 包来实现简易http反劫持功能,只能应付简单的http劫持。 通过 SplitHttp 选项开启,默认关闭。 注意:部分杀毒软件、防火墙会重组 http 请求tcp包,造成这个功能无效。

基本不会造成性能损耗。

实现原理:当目标端口是80时,发出的请求一旦包含 GET、POST、HTTP、HOST则会被拆分到多个TCP包发送。

ttl 反劫持功能

ttl 反劫持是独立的程序,需要单独启动ttl反劫持程序,并将直连线路的 sleep 设置为10至50之间的值。

实现原理:当发现 http 连接建立时,将会发送错误数据、连接重置命令混淆http连接。通过设置 ttl 值使得错误数据、重置命令不会到达目标网站,只会在网络中传递,经过并干扰可能存在的http劫持系统。

sleep 的目的是建立连接后不立刻发送数据,而是等待 ttl 反劫持程序发送混淆内容后再发送实际数据。 一般ttl反劫持程序发送混淆数据的耗时为10-30毫秒,sleep设置为大于这个值即可。

ttl 反劫持程序地址:https://github.com/GameXG/ProxyClient/tree/master/ttl

具体细节

  • 对 DNS 解析获得的多个IP同时尝试连接,最终使用最快建立的连接。
  • 同时使用直连及代理建立连接(可设置延迟),最终使用最快建立的连接。
  • 缓存10分钟上次检测到的最快线路方便以后使用。
  • 解析不存在域名获得域名纠错IP,并添加到 IP黑名单

tcproute2's People

Contributors

gamexg avatar jamesits avatar kookxiang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tcproute2's Issues

关于无数据返回的判断

发现一个奇怪的问题,有一些IP可以连接上,但是没有响应数据。但是在另外一条线路是正常响应了数据的。
按照说明文档,这种问题似乎会启用备用线路连接?不过实际情况是没有去使用例外一条线路。
目前必须通过黑名单来手动指定某些域名使用另外的线路,才能解决这些问题。

版本是 v0.5.9

建议定时将缓存写入本地

可以以host方式写入本地

# hosts 域名类型,标准的 hosts 文件都是 base 类型。
# base 完整匹配,默认值。即 www.abc.com 只匹配 www.abc.com ,不匹配 aaa.www.abc.com 。
# suffix 后缀匹配。即 abc.com 匹配 abc.com、www.abc.com、aaa.www.abc.com,不匹配 aaaabc.com。
# pan 泛解析匹配。即 *.abc.com 匹配 www.abc.com 、aaa.www.abc.com。不匹配 .abc.com。?.abc.com 匹配 a.abc.com。
# regex 正则匹配。即 ^.+?.com$ 匹配 www.abc.com 、aaa.www.abc.com。注意:完整匹配时不要忘记 ^$ 。

以后可以方便用户直接编辑,每次打开重新载入即可,就不用每次关闭之后打开重复判断线路。

关机时报错

windows10关机前未退出程序就会“提示应用程序错误”“应用程序无法正常启动(0x0000142)。”

-config 参数是不是没用?提示这个。

xuan880 反馈
-config 参数是不是没用?提示这个。
➜ ~ tcproute --config ~/.tcproute/config.toml
flag provided but not defined: -config
Usage of tcproute:
-addr
Change value of Addr. (default 127.0.0.1:7070)
-upstreams
Change value of UpStreams. (default [{direct direct://0.0.0.0:0000 true 0 0 0} {shadowsocks ss://rc4-md5:[email protected]:12345 false 3 100 50}])

Generated environment variables:
SERVERCONFIG_ADDR
SERVERCONFIG_UPSTREAMS

[race]upstream_tcpping

WARNING: DATA RACE
Read by goroutine 173:
runtime.chansend()
C:/workdir/go/src/runtime/chan.go:107 +0x0
main.(_tcppingUpStream).DialTimeout.func2.3.3.1()
D:/golang/src/github.com/gamexg/TcpRoute2/upstream_tcpping.go:212 +0x10a
main.(_tcppingUpStream).DialTimeout.func2.3.3()
D:/golang/src/github.com/gamexg/TcpRoute2/upstream_tcpping.go:213 +0x46

Previous write by goroutine 311:
runtime.closechan()
C:/workdir/go/src/runtime/chan.go:295 +0x0
main.(_tcppingUpStream).DialTimeout()
D:/golang/src/github.com/gamexg/TcpRoute2/upstream_tcpping.go:244 +0xd5f
main.(_hSocksHandle).handleSocks5()
D:/golang/src/github.com/gamexg/TcpRoute2/handler_socks.go:162 +0x10f0
main.(_hSocksHandle).Handle()
D:/golang/src/github.com/gamexg/TcpRoute2/handler_socks.go:73 +0x2ab
main.(_Server).handlerConn()
D:/golang/src/github.com/gamexg/TcpRoute2/server.go:121 +0x65e

Goroutine 173 (running) created at:
time.goFunc()
C:/workdir/go/src/time/sleep.go:129 +0x74

Goroutine 311 (finished) created at:
main.(_Server).Server()
D:/golang/src/github.com/gamexg/TcpRoute2/server.go:95 +0x3f5
main.(_Server).ListAndServe()
D:/golang/src/github.com/gamexg/TcpRoute2/server.go:67 +0x14d
main.main()

D:/golang/src/github.com/gamexg/TcpRoute2/main.go:62 +0xcda

请问是否能编译一个苹果M1的release包呢?

我最近换了苹果arm芯片设备,找了arm的binary包,结果不能用。

感觉是需要重新编译,但是go完全是0基础,自己折腾了很久才编译成功,也运行起来了。

我觉得是否考虑再发一次release,其中带上M1的release文件?这样如果有其他人也遇到同样问题,就不用折腾了。

handler

预期可以处理 socks 代理协议、http普通代理、透明代理。
其中比较特殊的是即使通过socks代理协议的连接如果发现是http协议那么也会路由到http透明代理检测域名并重新进行dns查询,好处理在linux全局代理下无法处理dns污染的情况。

可能存在的内存问题

目前在用 v0.5.9,开了一个晚上内存占用逐渐升到了500M以上,用作前置代理的privoxy只有30M左右。
系统是Centos 6

[race]DialTCPSAddrTimeout

WARNING: DATA RACE
Write by goroutine 326:
github.com/gamexg/proxyclient.(*httpProxyClient).DialTCPSAddrTimeout.func1()
D:/golang/src/github.com/gamexg/proxyclient/httpproxy.go:135 +0x5db

Previous write by goroutine 309:
github.com/gamexg/proxyclient.(_httpProxyClient).DialTCPSAddrTimeout()
D:/golang/src/github.com/gamexg/proxyclient/httpproxy.go:239 +0xc29
github.com/gamexg/proxyclient.(_httpProxyClient).DialTimeout()
D:/golang/src/github.com/gamexg/proxyclient/httpproxy.go:83 +0x106
main.(_tcppingUpStream).DialTimeout()
D:/golang/src/github.com/gamexg/TcpRoute2/upstream_tcpping.go:103 +0x224
main.(_hSocksHandle).handleSocks5()
D:/golang/src/github.com/gamexg/TcpRoute2/handler_socks.go:162 +0x10f0
main.(_hSocksHandle).Handle()
D:/golang/src/github.com/gamexg/TcpRoute2/handler_socks.go:73 +0x2ab
main.(_Server).handlerConn()
D:/golang/src/github.com/gamexg/TcpRoute2/server.go:121 +0x65e

Goroutine 326 (running) created at:
github.com/gamexg/proxyclient.(_httpProxyClient).DialTCPSAddrTimeout()
D:/golang/src/github.com/gamexg/proxyclient/httpproxy.go:235 +0xb41
github.com/gamexg/proxyclient.(_httpProxyClient).DialTimeout()
D:/golang/src/github.com/gamexg/proxyclient/httpproxy.go:83 +0x106
main.(_tcppingUpStream).DialTimeout()
D:/golang/src/github.com/gamexg/TcpRoute2/upstream_tcpping.go:103 +0x224
main.(_hSocksHandle).handleSocks5()
D:/golang/src/github.com/gamexg/TcpRoute2/handler_socks.go:162 +0x10f0
main.(_hSocksHandle).Handle()
D:/golang/src/github.com/gamexg/TcpRoute2/handler_socks.go:73 +0x2ab
main.(_Server).handlerConn()
D:/golang/src/github.com/gamexg/TcpRoute2/server.go:121 +0x65e

Goroutine 309 (running) created at:
main.(_Server).Server()
D:/golang/src/github.com/gamexg/TcpRoute2/server.go:95 +0x3f5
main.(_Server).ListAndServe()
D:/golang/src/github.com/gamexg/TcpRoute2/server.go:67 +0x14d
main.main()
D:/golang/src/github.com/gamexg/TcpRoute2/main.go:62 +0xcda

窗口优化

1.加个图标
2.加入通知栏(最小化到通知栏)
3.默认最小化启动

只配置直连,无法访问www.taobao.com

配置文件是最精简的,只有一个直连,www.taobao.com打不开,但是www.baidu.com可以
配置文件

addr=":7072"
PreHttpPorts=[80,]
PreHttpsPorts=[443,]
[[UpStreams]]
Name="direct"
ProxyUrl="direct://0.0.0.0:0000"
DnsResolve=true

addr=":7072"
PreHttpPorts=[80,]
PreHttpsPorts=[443,]
[[UpStreams]]
Name="direct"
ProxyUrl="direct://0.0.0.0:0000"
DnsResolve=true

日志

TcpRoute2 version 0.5.8
2016/07/24 00:28:03 协议处理错误:%!(EXTRA *errors.errorString=无法连接目标网站( www.taobao.com:443 ),详细错误:所有线路建立连接失败。)
2016/07/24 00:28:06 [DNS]未发现 DNS 域名纠错功能,无需屏蔽纠错 IP 。
2016/07/24 00:28:08 为 www.baidu.com:443 找到了最快的稳定连接 115.239.211.112:443 ,线路:direct.
2016/07/24 00:28:09 为 ss0.baidu.com:443 找到了最快的稳定连接 61.164.156.33:443 ,线路:direct.
2016/07/24 00:28:09 为 ss2.baidu.com:443 找到了最快的稳定连接 61.164.156.33:443 ,线路:direct.
2016/07/24 00:28:10 为 sp0.baidu.com:443 找到了最快的稳定连接 115.239.210.27:443 ,线路:direct.
2016/07/24 00:28:10 为 clients4.google.com:443 找到了最快的稳定连接 [2404:6800:4005:804::200e]:443 ,线路:direct.
缓存命中:www.baidu.com:443 代理:direct IP:115.239.211.112:443

[race]upstream_cache

WARNING: DATA RACE
Read by goroutine 100:
container/list.(_List).MoveToFront()
C:/workdir/go/src/container/list/list.go:169 +0x91
github.com/golang/groupcache/lru.(_Cache).Get()
D:/golang/src/github.com/golang/groupcache/lru/lru.go:79 +0x11e
main.(_upStreamConnCache).get()
D:/golang/src/github.com/gamexg/TcpRoute2/upstream_cache.go:96 +0xbd
main.(_upStreamConnCache).GetOptimal()
D:/golang/src/github.com/gamexg/TcpRoute2/upstream_cache.go:126 +0x116
main.(_tcppingUpStream).DialTimeout()
D:/golang/src/github.com/gamexg/TcpRoute2/upstream_tcpping.go:89 +0xc3
main.(_hSocksHandle).handleSocks5()
D:/golang/src/github.com/gamexg/TcpRoute2/handler_socks.go:162 +0x10f0
main.(_hSocksHandle).Handle()
D:/golang/src/github.com/gamexg/TcpRoute2/handler_socks.go:73 +0x2ab
main.(_Server).handlerConn()
D:/golang/src/github.com/gamexg/TcpRoute2/server.go:121 +0x65e

Previous write by goroutine 343:
container/list.(_List).MoveToFront()
C:/workdir/go/src/container/list/list.go:169 +0xf7
github.com/golang/groupcache/lru.(_Cache).Get()
D:/golang/src/github.com/golang/groupcache/lru/lru.go:79 +0x11e
main.(_upStreamConnCache).get()
D:/golang/src/github.com/gamexg/TcpRoute2/upstream_cache.go:96 +0xbd
main.(_upStreamConnCache).GetOptimal()
D:/golang/src/github.com/gamexg/TcpRoute2/upstream_cache.go:126 +0x116
main.(_tcppingUpStream).DialTimeout()
D:/golang/src/github.com/gamexg/TcpRoute2/upstream_tcpping.go:89 +0xc3
main.(_hSocksHandle).handleSocks5()
D:/golang/src/github.com/gamexg/TcpRoute2/handler_socks.go:162 +0x10f0
main.(_hSocksHandle).Handle()
D:/golang/src/github.com/gamexg/TcpRoute2/handler_socks.go:73 +0x2ab
main.(_Server).handlerConn()
D:/golang/src/github.com/gamexg/TcpRoute2/server.go:121 +0x65e

Goroutine 100 (running) created at:
main.(_Server).Server()
D:/golang/src/github.com/gamexg/TcpRoute2/server.go:95 +0x3f5
main.(_Server).ListAndServe()
D:/golang/src/github.com/gamexg/TcpRoute2/server.go:67 +0x14d
main.main()
D:/golang/src/github.com/gamexg/TcpRoute2/main.go:62 +0xcc5

Goroutine 343 (running) created at:
main.(_Server).Server()
D:/golang/src/github.com/gamexg/TcpRoute2/server.go:95 +0x3f5
main.(_Server).ListAndServe()
D:/golang/src/github.com/gamexg/TcpRoute2/server.go:67 +0x14d
main.main()
D:/golang/src/github.com/gamexg/TcpRoute2/main.go:62 +0xcc5

HTTP拆包方案貌似无效,请教我怎么玩转ttl 混淆

RT

我的栗子
[UpStreams]]
Name="direct"
ProxyUrl="direct://0.0.0.0:0000"
DnsResolve=true
Credit=0
Sleep=80
CorrectDelay=0
SplitHttp=true

直连线路域名白名单

各个线路的白名单、黑名单是独立的,可以通过多个 [[UpStreams.Whitelist]] 指定多个白名单。

[[UpStreams.Whitelist]]
Path="chinalist.txt"
Type="suffix"

但似乎没效果了,;;;相对TTL,怎么用,请教教我。GO语言不懂

最小范围直连白名单

来源是 unblock youku 的urls.js:https://github.com/Unblocker/Unblock-Youku/blob/master/shared/urls.js
我正则匹配了所有规则里的域名,然后进行了排序去重。

unblock youku的主要工作是解除在海外因为地域限制造成无法使用的音乐和视频服务,它的列表里应该囊括了大部分国内必需直连的域名。
这样基本可以在不影响体验的情况下,最大程度保证TcpRoute2选择最优线路的特性。

作为验证测试,把这份列表加入了海外代理的白名单中,百度音乐、土豆、优酷、爱奇艺和B站全部无法正常播放,准确率应该是很高的。

111.13.127.46
118.244.244.124
122.72.82.31
123.126.99.39
123.126.99.57
180.153.225.136
182.16.230.98
210.129.145.150
211.151.157.15
211.151.50.10
220.181.154.137
220.181.185.150
3g.music.qq.com
61.135.196.99
a.play.api.3g.youku.com
a10.video.qq.com
ac.qq.com
access.tv.sohu.com
aid.video.qq.com
aidbak.video.qq.com
api.3g.tudou.com
api.3g.youku.com
api.letv.com
api.live.letv.com
api.mob.app.letv.com
api.tv.sohu.com
api.www.letv.com
api.youku.com
bkvv.video.qq.com
bobo.video.qq.com
cache.m.iqiyi.com
cache.video.qiyi.com
cache.vip.qiyi.com
chrome.2345.com
client.api.ttpod.com
data.video.qiyi.com
dpool.sina.com.cn
dyn.ugc.pps.tv
dynamic.app.m.letv.com
dynamic.live.app.m.letv.com
dynamic.meizi.app.m.letv.com
dynamic.search.app.m.letv.com
epg.api.pptv.com
flvs.video.qq.com
geo.js.kankan.xunlei.com
hot.vrs.letv.com
hot.vrs.sohu.com
i.play.api.3g.youku.com
i.y.qq.com
ice.video.qq.com
iface.iqiyi.com
iface2.iqiyi.com
info.zb.qq.com
info.zb.video.qq.com
inner.kandian.com
interface.bilibili.com
internal.check.duokanbox.com
ip.apps.cntv.cn
ip.kankan.xunlei.com
ip.kugou.com
ip2.kugou.com
iplocation.geo.qiyi.com
ipservice.163.com
listso.m.areainfo.ppstream.com
live.g3proxy.lecloud.com
live.gslb.letv.com
live.tv.sohu.com
m.letv.com
mobi.kuwo.cn
mobilefeedback.kugou.com
mqqplayer.3g.qq.com
music.163.com
music.baidu.com
music.sina.com.cn
my.tv.sohu.com
openapi.youku.com
pad.tv.sohu.com
pay.tudou.com
pay.video.qq.com
pay.youku.com
paybak.video.qq.com
play.api.3g.tudou.com
play.api.3g.youku.com
play.api.pptv.com
play.baidu.com
play.youku.com
proxy.music.qq.com
proxymc.qq.com
qzs.qq.com
s.plcloud.music.qq.com
serviceinfo.sdk.duomi.com
sns.video.qq.com
so.open.163.com
spark.api.xiami.com
st.live.letv.com
static.api.sports.letv.com
static.itv.letv.com
tingapi.ting.baidu.com
tjsa.video.qq.com
tms.is.ysten.com:8080
tt.video.qq.com
tv.api.3g.tudou.com
tv.api.3g.youku.com
tv.weibo.com
v.api.hunantv.com
v.iask.com
v.pps.tv
v.youku.com
v5.pc.duomi.com
vbj.video.qq.com
vcq.video.qq.com
vdn.apps.cntv.cn
vdn.live.cntv.cn
video.sina.com.cn
vip.sports.cntv.cn
vsh.video.qq.com
vv.video.qq.com
vxml.56.com
web-play.pplive.cn
web-play.pptv.com
wtv.v.iask.com
www.tudou.com
www.xiami.com
www.yinyuetai.com
xyy.video.qq.com
zb.s.qq.com

func ChanDialTimeout内有bug吧

netchan\DialChan.go内

portInt, err := strconv.Atoi(prot)
if err != nil || portInt < 0 {
return fmt.Errorf("端口错误:", portInt)
}

缺少%v

dnschan race

WARNING: DATA RACE
Read by goroutine 24:
runtime.chansend()
C:/workdir/go/src/runtime/chan.go:107 +0x0
github.com/gamexg/TcpRoute2/netchan.(_systemDNS).query.func2()
D:/golang/src/github.com/gamexg/TcpRoute2/netchan/dnschan.go:183 +0x166
github.com/gamexg/TcpRoute2/netchan.(_systemDNS).query()
D:/golang/src/github.com/gamexg/TcpRoute2/netchan/dnschan.go:185 +0x172
github.com/gamexg/TcpRoute2/netchan.(*DnsQuery).query.func1()
D:/golang/src/github.com/gamexg/TcpRoute2/netchan/dnschan.go:111 +0xf2

Previous write by goroutine 20:
runtime.closechan()
C:/workdir/go/src/runtime/chan.go:295 +0x0
github.com/gamexg/TcpRoute2/netchan.(_DnsQuery).Stop.func2()
D:/golang/src/github.com/gamexg/TcpRoute2/netchan/dnschan.go:137 +0x63
github.com/gamexg/TcpRoute2/netchan.(_DnsQuery).Stop()
D:/golang/src/github.com/gamexg/TcpRoute2/netchan/dnschan.go:138 +0x43
github.com/gamexg/TcpRoute2/netchan.ChanDialTimeout.func4()
D:/golang/src/github.com/gamexg/TcpRoute2/netchan/DialChan.go:119 +0x79

Goroutine 24 (running) created at:
github.com/gamexg/TcpRoute2/netchan.(*DnsQuery).query()
D:/golang/src/github.com/gamexg/TcpRoute2/netchan/dnschan.go:112 +0x18a

Goroutine 20 (finished) created at:
github.com/gamexg/TcpRoute2/netchan.ChanDialTimeout()
D:/golang/src/github.com/gamexg/TcpRoute2/netchan/DialChan.go:120 +0x9a4
main.(*tcppingUpStream).DialTimeout.func2.1()
D:/golang/src/github.com/gamexg/TcpRoute2/upstream_tcpping.go:147 +0x30c

Socket限制

dial tcp: lookup example_url on example_url:example_port: dial udp example_url:example_port: socket: too many open files

[race]

WARNING: DATA RACE
Write by goroutine 93:
github.com/gamexg/TcpRoute2/netchan.ChanDialTimeout.func5()
D:/golang/src/github.com/gamexg/TcpRoute2/netchan/DialChan.go:155 +0x422

Previous write by goroutine 91:
github.com/gamexg/TcpRoute2/netchan.ChanDialTimeout.func5()
D:/golang/src/github.com/gamexg/TcpRoute2/netchan/DialChan.go:155 +0x422

Goroutine 93 (running) created at:
github.com/gamexg/TcpRoute2/netchan.ChanDialTimeout()
D:/golang/src/github.com/gamexg/TcpRoute2/netchan/DialChan.go:165 +0xb93
main.(*tcppingUpStream).DialTimeout.func2.1()
D:/golang/src/github.com/gamexg/TcpRoute2/upstream_tcpping.go:147 +0x30c

Goroutine 91 (running) created at:
github.com/gamexg/TcpRoute2/netchan.ChanDialTimeout()
D:/golang/src/github.com/gamexg/TcpRoute2/netchan/DialChan.go:165 +0xb93
main.(*tcppingUpStream).DialTimeout.func2.1()
D:/golang/src/github.com/gamexg/TcpRoute2/upstream_tcpping.go:147 +0x30c

建议 accept 出错时尝试让出运行权

diff --git a/server.go b/server.go
index e5bff82..c578ecc 100644
--- a/server.go
+++ b/server.go
@@ -5,6 +5,7 @@ import (
        "net"
        "io"
        "log"
+       "runtime"
 )

 //
@@ -76,21 +77,12 @@ func (srv *Server) Server() error {
                rw, e := ln.Accept()
                if e != nil {
                        if ne, ok := e.(net.Error); ok && ne.Temporary() {
-                               if tempDelay == 0 {
-                                       tempDelay = 5 * time.Millisecond
-                               } else {
-                                       tempDelay *= 2
-                               }
-                               if max := 1 * time.Second; tempDelay > max {
-                                       tempDelay = max
-                               }
-                               log.Printf("Accept error: %v; retrying in %v", e, tempDelay)
-                               time.Sleep(tempDelay)
+                               log.Printf("Accept error: %v", e)
+                               runtime.Gosched()
                                continue
                        }
                        return e
                }
-               tempDelay = 0

                go srv.handlerConn(rw)
        }

关于配置文件的问题。

[[UpStreams]] 和 [[Hosts]] 有多条线路,多个 hosts 的话。除了链接本身必须填写外。

其它参数 也必须都重复填写吗?

例如是这样?

[[UpStreams]]
Name="proxy 1"
ProxyUrl="socks5://1.1.1.1:5050"
Credit=0
Sleep=80
CorrectDelay=0
[[UpStreams]]
Name="proxy 2"
ProxyUrl="socks5://2.2.2.2:5050"
Credit=0
Sleep=80
CorrectDelay=0

还是这样?

[[UpStreams]]
Name="proxy 1"
ProxyUrl="socks5://1.1.1.1:5050"
[[UpStreams]]
Name="proxy 2"
ProxyUrl="socks5://2.2.2.2:5050"

Credit=0
Sleep=80
CorrectDelay=0

[race]DialTimeout

WARNING: DATA RACE
Read by goroutine 173:
main.(_tcppingUpStream).DialTimeout.func2.3.3.1()
D:/golang/src/github.com/gamexg/TcpRoute2/upstream_tcpping.go:212 +0x9b
main.(_tcppingUpStream).DialTimeout.func2.3.3()
D:/golang/src/github.com/gamexg/TcpRoute2/upstream_tcpping.go:213 +0x46

Previous write by goroutine 402:
main.(*tcppingUpStream).DialTimeout.func2.3()
D:/golang/src/github.com/gamexg/TcpRoute2/upstream_tcpping.go:229 +0xf7c

Goroutine 173 (running) created at:
time.goFunc()
C:/workdir/go/src/time/sleep.go:129 +0x74

Goroutine 402 (finished) created at:
main.(*tcppingUpStream).DialTimeout.func2()

D:/golang/src/github.com/gamexg/TcpRoute2/upstream_tcpping.go:240 +0x436

http、https 透明代理

本来计划 #5 ,不过考虑一下还是直接做成 http、https 透明代理吧。

优点:

  • 更好的性能
  • 更少的依赖

缺点:

  • 对于不支持 SNI 的浏览器无法连接https站点。 windows xp 下IE 有这个问题,详见:wikipedia
  • 对于 80 端口的非 http 协议无法识别,无法正常工作。
  • 对于 443 端口的非 https 协议无法识别,无法正常工作。

计划实现方式:

80端口:读取http协议头,并根据 host 确定需要连接的域名,然后同socks5协议执行tcpping
443端口:读取sni确定host,然后同socks5协议

如何调整缓存时间?

比如访问某个网站,已经记录某个线路最快,似乎软件里缓存10分钟

我想设置成1小时甚至半天,请问有办法吗

httpProxy 无法使用

本来计划前段使用nginx 处理ssl,然后转发到后端的 httpProxy 处理代理请求,但是这样还是碰到了 nginx 不支持 CONNECT 的问题。

本来计划把前端的 ngixn 替换成 haproxy ,不过最后还是没有切换。主要问题是 haproxy docker 动态路由需要的组件比较多,麻烦;haproxy 不处理tls的话就无法缓存http了,后端是apache,慢连接性能不好;而且 以后单独使用 httpProxy 还需要搭配 haproxy 太不方便了。

最后考虑还是将 httpProxy 改为 httpsProxy ,由自身作为 tls 前段,根据 SNI 来确定是自身处理还是转发到 nginx 处理。

fatal error: concurrent map writes

fatal error: concurrent map writes

goroutine 3590 [running]:
runtime.throw(0x7be280, 0x15)
/home/travis/.gimme/versions/go/src/runtime/panic.go:530 +0x7f fp=0x114e1d70 sp=0x114e1d64
runtime.mapassign1(0x6d51c0, 0x113f92e0, 0x114e1e00, 0x114e1df4)
/home/travis/.gimme/versions/go/src/runtime/hashmap.go:540 +0x44e fp=0x114e1dd0 sp=0x114e1d70
github.com/golang/groupcache/lru.(_Cache).Add(0x114282f0, 0x6d4b40, 0x11794400, 0x6c0b00, 0x112dcea0)
/home/travis/gopath/src/github.com/golang/groupcache/lru/lru.go:67 +0x237 fp=0x114e1e0c sp=0x114e1dd0
github.com/gamexg/TcpRoute2/domains.(_Domains).cacheSet(0x111b6b40, 0x113f3b80, 0xe, 0x112dcea0)
/home/travis/gopath/src/github.com/gamexg/TcpRoute2/domains/domains.go:332 +0x84 fp=0x114e1e38 sp=0x114e1e0c
github.com/gamexg/TcpRoute2/domains.(_Domains).Find(0x111b6b40, 0x113f3b80, 0xe, 0xb2c97000)
/home/travis/gopath/src/github.com/gamexg/TcpRoute2/domains/domains.go:319 +0x66d fp=0x114e1ef4 sp=0x114e1e38
github.com/gamexg/TcpRoute2/netchan.(_hostsDns).query.func1(0x1122c6c0, 0x113f3b80, 0xe, 0x114e1f88)
/home/travis/gopath/src/github.com/gamexg/TcpRoute2/netchan/dnschan_hosts.go:76 +0x88 fp=0x114e1f4c sp=0x114e1ef4
github.com/gamexg/TcpRoute2/netchan.(_hostsDns).query(0x1122c6c0, 0x113f3b80, 0xe, 0x113c6980, 0x113c6a80)
/home/travis/gopath/src/github.com/gamexg/TcpRoute2/netchan/dnschan_hosts.go:81 +0x60 fp=0x114e1fb0 sp=0x114e1f4c
github.com/gamexg/TcpRoute2/netchan.(_DnsQuery).query.func1(0x112dce80, 0xd94470, 0x1122c6c0, 0x112dce50)
/home/travis/gopath/src/github.com/gamexg/TcpRoute2/netchan/dnschan.go:123 +0x8f fp=0x114e1fc8 sp=0x114e1fb0
runtime.goexit()
/home/travis/.gimme/versions/go/src/runtime/asm_386.s:1583 +0x1 fp=0x114e1fcc sp=0x114e1fc8
created by github.com/gamexg/TcpRoute2/netchan.(*DnsQuery).query
/home/travis/gopath/src/github.com/gamexg/TcpRoute2/netchan/dnschan.go:124 +0xe1

如下场景能否使用TcpRoute2?

现在有这样一个场景:
局域网里的电脑a,b,c,...使用代理,都通过电脑AA上公网。
现在AA电脑有一些限制,不允许一些APP(APP1,APP2,...)上网,其他APP允许上网。
作为电脑b,能否在b上面装一些工具或者进行些设置(不在AA上设置和安装工具),让APP1,APP2,像其他APP一样,也能上网。

我尝试tcpRoute2配置了一下,但是没有成功,不知道是我配置有问题,还是这种方式不可行?
#######################
addr="127.0.0.1:7070"
#代理线路例子:
[[UpStreams]]
Name="proxyLB"
ProxyUrl="https://aaaa:[email protected]:1086?domain=cccc.cn"
Credit=0
#Credit 表示代理信誉度,低于0的将不会通过当前线路转发明文协议(http、ftp等)的请求。
Sleep=80
#Sleep表示使用本线路前等待的时间,单位毫秒。
CorrectDelay=0
#CorrectDelay 表示当前线路修正延迟,ss 协议建议设置为 50-100 之间的值,非 ss 协议代理设置为 0。

#######################
TcpRoute2 version 0.5.12
2020/10/05 18:37:47 未配置是否启用 客户端dns解析纠正功能,默认将在发现浏览器进行了dns本地解析时强制改为为代理服务器进行dns解析。
2020/10/05 18:37:50 线路 proxyLB 连接 www.baidu.com:80 失败,错误:无法连接代理服务器 10.1.101.1:1086 ,错误:dial tcp :0->10.1.101.1:1086: connectex: An operation was attempted on something that is not a socket.
2020/10/05 18:37:50 协议处理错误:无法连接目标网站( www.baidu.com:80 ),详细错误:所有线路建立连接失败。
2020/10/05 18:38:23 [DNS]未发现 DNS 域名纠错功能,无需屏蔽纠错 IP 。
#######################

重构

现在的版本是tcp级别的,新的版本计划实现到http级别。
另外计划将socks5 server实现也抽象出来,同时也将socks4、socks4a、http、https等也一起抽象出来。
目前经常需要重新拨号,很烦,可以考虑使用 http2 来实现一个协议,方案有两种:1、自签证书;2、数据填充。
另外 ProxyClient 是否实现到 RoundTripper 接口还是用 Transport 来实现?

另外由于计划是通过http级别允许针对特定url执行特定的规则,计划提供多个切换器,这样可能配置文件麻烦了,也许实现lua?先参考下 haproxy 之类的配置吧。

[race]handler_socks

WARNING: DATA RACE
Write by goroutine 389:
sync/atomic.AddInt64()
C:/workdir/go/src/runtime/race_amd64.s:262 +0xb
main._forwardConn()
D:/golang/src/github.com/gamexg/TcpRoute2/handler.go:95 +0x53d

Previous read by goroutine 312:
main.(_hSocksHandle).handleSocks5()
D:/golang/src/github.com/gamexg/TcpRoute2/handler_socks.go:216 +0x1fac
main.(_hSocksHandle).Handle()
D:/golang/src/github.com/gamexg/TcpRoute2/handler_socks.go:73 +0x2ab
main.(*Server).handlerConn()
D:/golang/src/github.com/gamexg/TcpRoute2/server.go:121 +0x65e

Goroutine 389 (running) created at:
main.forwardConn()
D:/golang/src/github.com/gamexg/TcpRoute2/handler.go:53 +0x143
main.(_hSocksHandle).handleSocks5()
D:/golang/src/github.com/gamexg/TcpRoute2/handler_socks.go:206 +0x1eec
main.(_hSocksHandle).Handle()
D:/golang/src/github.com/gamexg/TcpRoute2/handler_socks.go:73 +0x2ab
main.(*Server).handlerConn()
D:/golang/src/github.com/gamexg/TcpRoute2/server.go:121 +0x65e

Goroutine 312 (running) created at:
main.(_Server).Server()
D:/golang/src/github.com/gamexg/TcpRoute2/server.go:95 +0x3f5
main.(_Server).ListAndServe()
D:/golang/src/github.com/gamexg/TcpRoute2/server.go:67 +0x14d
main.main()

D:/golang/src/github.com/gamexg/TcpRoute2/main.go:62 +0xcda

域名匹配功能

#28 #23 的需求,域名匹配功能。

域名匹配策略也需要独立抽取出来了,正好同时用在 hosts 里面。
域名匹配策略有hosts标准匹配、字符串尾匹配、泛解析匹配及正则匹配。

标准匹配直接使用map来做。
尾匹配通过加.然后循环比较,泛解析、正则都转换为正则。为了性能在加个 lru 缓存。

未匹配虽然可以通过分割后通过 map 做,但是感觉性能要求没这么高,而且有缓存,直接循环处理。

待解决的问题

本地dns解析自带广告过滤功能,所以的广告隐私域名ip全部解析为127.0.0.1。问题在下面,应该丢弃连接127.0.0.1:

2017/11/07 20:08:11 线路 direct 连接 push.zhanzhang.baidu.com:80 失败,错误:dial tcp :0->127.0.0.1:80: connectex: No connection could be made because the target machine actively refused it.
2017/11/07 20:08:11 线路 direct 连接 bdimg.share.baidu.com:80 失败,错误:dial tcp :0->127.0.0.1:80: connectex: No connection could be made because the target machine actively refused it.
2017/11/07 20:08:11 线路 proxy1 连接 bdimg.share.baidu.com:80 失败,错误:请求代理服务器建立连接失败:socks5代理服务器 命令响应错误,ver=0
2017/11/07 20:08:11 协议处理错误:无法连接目标网站( bdimg.share.baidu.com:80 ),详细错误:所有线路建立连接失败。
2017/11/07 20:08:11 线路 proxy1 连接 push.zhanzhang.baidu.com:80 失败,错误:请求代理服务器建立连接失败:socks5代理服务器 命令响应错误,ver=0
2017/11/07 20:08:11 协议处理错误:无法连接目标网站( push.zhanzhang.baidu.com:80 ),详细错误:所有线路建立连接失败。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.