Skip to content

Commit

Permalink
add a new option "use_proxy" as a proxy switch
Browse files Browse the repository at this point in the history
  • Loading branch information
SwimmingTiger committed Dec 18, 2021
1 parent 31444c9 commit f8958fb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
6 changes: 6 additions & 0 deletions Config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Config struct {
AgentListenIp string `json:"agent_listen_ip"`
AgentListenPort uint16 `json:"agent_listen_port"`
Proxy []string `json:"proxy"`
UseProxy bool `json:"use_proxy"`
DirectConnectWithProxy bool `json:"direct_connect_with_proxy"`
DirectConnectAfterProxy bool `json:"direct_connect_after_proxy"`
PoolUseTls bool `json:"pool_use_tls"`
Expand Down Expand Up @@ -95,6 +96,7 @@ func NewConfig() (config *Config) {

config.DisconnectWhenLostAsicboost = DownSessionDisconnectWhenLostAsicboost
config.IpWorkerNameFormat = DefaultIpWorkerNameFormat
config.UseProxy = true
config.DirectConnectAfterProxy = true

config.Advanced.PoolConnectionNumberPerSubAccount = UpSessionNumPerSubAccount
Expand Down Expand Up @@ -136,6 +138,10 @@ func (conf *Config) Init() {
glog.Info("[OPTION] Fixed worker name enabled, all worker name will be replaced to ", conf.FixedWorkerName, " on the server.")
}

if !conf.UseProxy && len(conf.Proxy) > 0 {
conf.Proxy = []string{}
glog.Info("[OPTION] Proxy disabled")
}
for i := range conf.Proxy {
if conf.Proxy[i] == "system" {
conf.Proxy[i] = GetProxyURLFromEnv()
Expand Down
1 change: 1 addition & 0 deletions agent_conf.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"agent_listen_ip": "0.0.0.0",
"agent_listen_port": 3333,
"proxy": [],
"use_proxy": true,
"direct_connect_with_proxy": false,
"direct_connect_after_proxy": true,
"pool_use_tls": false,
Expand Down
11 changes: 6 additions & 5 deletions docs/ConfigFileDetails-zhCN.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
| agent_listen_ip | BTCAgent监听IP | BTCAgent代理的监听IP,矿机需要通过这个IP来连接到代理。需要填写已经分配给运行代理的电脑的IP,或者填写`0.0.0.0`。建议填写`0.0.0.0`,它表示“所有可用的IP”。 |
| agent_listen_port | BTCAgent监听端口 | BTCAgent代理的监听端口,矿机需要通过这个端口来连接到代理。如果你在同一台电脑上运行多个代理,每个代理的端口都应该不同。<br><br>可用的端口范围是1到65535,但是建议使用2000到5000范围内的端口。因为使用低于1024的端口需要root权限(管理员权限),高于5000的端口容易被其他程序随机占用。 |
| proxy | 网络代理 | 在连接矿池时使用的网络代理。<br><br>字符串数组,每个字符串为一个代理,最快的将被使用。<br><br>查看下面的“使用网络代理”小节来了解代理字符串的格式。 |
| direct_connect_with_proxy | 在使用代理时也尝试直连 | 在使用代理连接矿池时也会尝试直连矿池(不通过代理),如果直连更快就会使用直连,如果无法直连矿池或者直连更慢就会使用代理。 |
| direct_connect_after_proxy | 代理连接失败则尝试直连 | 如果无法通过代理连接到矿池,就会尝试直连,可以避免代理故障时无法连接到矿池。当然你也可以设置多个代理来减少故障的可能性。 |
| use_proxy | 是否使用网络代理 | 网络代理的开关,默认为`true`(如果网络代理不为空就会使用)。设为`false`可禁用网络代理。 |
| direct_connect_with_proxy | 直连比代理快时使用直连 | 在通过代理连接矿池的同时也会尝试直连矿池(不通过代理),如果直连更快就会使用直连,如果无法直连矿池或者直连更慢就会使用代理。 |
| direct_connect_after_proxy | 代理连接失败时使用直连 | 如果无法通过代理连接到矿池,就会尝试直连,可以避免代理故障时无法连接到矿池。当然你也可以设置多个代理来减少故障的可能性。 |
| pool_use_tls | 连接矿池时启用SSL/TLS加密 | 连接到SSL/TLS加密的矿池服务器,防止中间人进行网络窃听。<br><br>注意:支持SSL/TLS加密的矿池服务器的地址和端口与普通服务器不同,如果您填写的矿池地址端口不支持SSL/TLS加密,启用该选项会导致智能代理连不上矿池。<br><br>此外,启用该选项只会加密到矿池的连接,不会加密到矿机的连接,所以不需要修改矿机的设置。 |
| pools | 矿池地址、端口、子账户名 | [<br>&nbsp;&nbsp;&nbsp;&nbsp;["矿池地址1", 矿池端口1, "子账户名1"],<br>&nbsp;&nbsp;&nbsp;&nbsp;["矿池地址2", 矿池端口2, "子账户名2"],<br>&nbsp;&nbsp;&nbsp;&nbsp;["矿池地址3", 矿池端口3, "子账户名3"]<br>] |

Expand All @@ -65,7 +66,7 @@
* http 代理
```
"proxy": [
"http://127.0.0.1:8089"
"http://127.0.0.1:8889"
],
```
* https 代理 (即 SSL/TLS 加密的 HTTP 代理)
Expand All @@ -89,14 +90,14 @@
"proxy": [
"socks5://127.0.0.1:1089",
"socks5://192.168.1.1:1089",
"http://127.0.0.1:8089"
"http://127.0.0.1:8889"
],
```
* 使用需要用户名密码认证的代理
```
"proxy": [
"socks5://username:password@127.0.0.1:1089",
"http://username:password@192.168.1.1:8089",
"http://username:password@192.168.1.1:8889",
"https://username:password@127.0.0.1:4433"
],
```
12 changes: 7 additions & 5 deletions docs/ConfigFileDetails.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"agent_listen_ip": "0.0.0.0",
"agent_listen_port": 3333,
"proxy": [],
"use_proxy": true,
"direct_connect_with_proxy": false,
"direct_connect_after_proxy": true,
"pool_use_tls": false,
Expand Down Expand Up @@ -47,8 +48,9 @@ You can delete the `http_debug` and `advanced` configuration sections from the c
| agent_listen_ip | BTCAgent listen IP | The listen IP of BTCAgent, miners should connect to your BTCAgent via this IP. It should be an IP address assigned to the computer running BTCAgent, or `0.0.0.0`. The `0.0.0.0` means "all possible IP addresses" and we recommend using it. |
| agent_listen_port | BTCAgent listen port | The listen port of BTCAgent, miners should connect to your BTCAgent via this port. If you run multiple BTCAgent processes on one computer, each process should use a different port.<br><br>The valid range of the port is 1 to 65535, and the recommended range is 2000 to 5000. Use of ports lower than 1024 requires root privileges, and ports higher than 5000 may be randomly occupied by other programs. |
| proxy | Network proxy | The network proxy used when connecting to the mining pool.<br><br>String array, each string is a proxy, the fastest will be used.<br><br>See the "Use proxy" section below to understand the format of the proxy string. |
| direct_connect_with_proxy | Try to connect directly when using a proxy | While connecting to the mining pool through a proxy, it also tries to connect directly to the mining pool (not through a proxy). If the direct connection is faster, it will be used. If it is not possible to connect directly to the mining pool or it's slower, the proxy will be used. |
| direct_connect_after_proxy | Try to connect directly after the proxy connection fails | If you cannot connect to the mining pool through a proxy, try to connect to the mining pool directly (not through a proxy). This may help when the proxy fails. Of course, you can also set up multiple proxies to reduce the possibility of failure. |
| use_proxy | Use network proxy | The switch of the network proxy, the default is `true` (use proxy if not empty), set to `false` to disable the network proxy. |
| direct_connect_with_proxy | Use direct connection if it is faster than all proxies | While connecting to the mining pool through proxies, it also tries to connect directly to the mining pool (not through any proxy). If the direct connection is faster than all proxies, it will be used. If it is not possible to connect directly to the mining pool or it's slower, the fastest proxy will be used. |
| direct_connect_after_proxy | Use direct connection after all proxies fail | If BTCAgent cannot connect to the mining pool through any proxy, it will try to connect to the mining pool directly (not through a proxy). This may help when proxy fails. Of course, you can also set up multiple proxies to reduce the possibility of failure. |
| pool_use_tls | Use SSL/TLS encrypted connection to pool | Connect to the mining pool server encrypted with SSL/TLS to prevent network traffic from being monitored by the middleman.<br><br>Note: The address and port of the server that supports SSL/TLS encryption may be different from the normal server. If the server address and port you fill in does not support SSL/TLS encryption, enabling this option will cause BTCAgent to fail to connect to the server.<br><br>In addition, after enabling this option, the connection from your miners to this BTCAgent is still in plain text and will not be encrypted by SSL/TLS. So you don&apos;t need to change the miner settings. |
| pools | Mining pool server host, port, sub-account | [<br>&nbsp;&nbsp;&nbsp;&nbsp;["pool-server-host-1", server-port1, "sub-account-1"],<br>&nbsp;&nbsp;&nbsp;&nbsp;["pool-server-host-2", server-port2, "sub-account-2"],<br>&nbsp;&nbsp;&nbsp;&nbsp;["pool-server-host-3", server-port3, "sub-account-3"]<br>] |

Expand All @@ -65,7 +67,7 @@ In [agent_conf.json](../agent_conf.default.json#L12):
* http proxy
```
"proxy": [
"http://127.0.0.1:8089"
"http://127.0.0.1:8889"
],
```
* https proxy (http proxy with SSL/TLS)
Expand All @@ -89,14 +91,14 @@ In [agent_conf.json](../agent_conf.default.json#L12):
"proxy": [
"socks5://127.0.0.1:1089",
"socks5://192.168.1.1:1089",
"http://127.0.0.1:8089"
"http://127.0.0.1:8889"
],
```
* proxy that requires authentication
```
"proxy": [
"socks5://username:password@127.0.0.1:1089",
"http://username:password@192.168.1.1:8089",
"http://username:password@192.168.1.1:8889",
"https://username:password@127.0.0.1:4433"
],
```

0 comments on commit f8958fb

Please sign in to comment.