-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmodeSelector.go
96 lines (83 loc) · 2.37 KB
/
modeSelector.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"net/http"
"strings"
"github.com/azak-azkaran/cascade/utils"
)
func HandleCustomProxies(list []string) {
if len(list) == 0 {
return
}
for i := 0; i < len(list); i++ {
rule := list[i]
if strings.Contains(rule, "->") {
split := strings.Split(rule, "->")
AddDifferentProxyConnection(split[0], split[1])
} else {
AddDirectConnection(rule)
}
}
}
func ModeSelection(config *Yaml) *Yaml {
var success bool
utils.Sugar.Info("Running check on: ", config.CheckAddress)
rep, err := utils.GetResponse("", config.CheckAddress)
if err != nil {
utils.Sugar.Info("Error while checking,", config.CheckAddress, " , ", err)
success = false
} else {
if rep.StatusCode == http.StatusOK {
utils.Sugar.Debug("Response was: ", rep.Status, "\t", rep.StatusCode)
success = true
} else {
utils.Sugar.Debug("Response was: ", rep.Status)
success = false
}
}
utils.Sugar.Info("Check returns: ", success)
if config.CascadeMode {
utils.Sugar.Info("Current Mode: CascadeMode")
} else {
utils.Sugar.Info("Current Mode: DirectMode")
}
if !config.DisableAutoChangeMode {
config = ChangeMode(success, config)
} else {
utils.Sugar.Info("Automatic Change Mode is disabled")
}
return config
}
func ChangeMode(success bool, config *Yaml) *Yaml {
if len(config.ProxyURL) == 0 {
utils.Sugar.Error("ProxyURL was not set so staying in DirectMode")
config.CascadeMode = false
return config
}
if (!success && config.CascadeMode && config.OnlineCheck) ||
(!success && CurrentServer == nil && config.OnlineCheck) {
// switch to direct mode
utils.Sugar.Warn("switch to: DirectMode")
config.CascadeMode = false
return config
} else if (success && !config.CascadeMode && config.OnlineCheck) ||
(success && CurrentServer == nil && config.OnlineCheck) {
// switch to cascade mode
utils.Sugar.Warn("switch to: CascadeMode")
config.CascadeMode = true
return config
}
if (success && config.CascadeMode) || (success && CurrentServer == nil) {
// switch to direct mode
utils.Sugar.Warn("switch to: DirectMode")
config.CascadeMode = false
return config
//go Config.DirectFunction()
} else if (!success && !config.CascadeMode) || (!success && CurrentServer == nil) {
// switch to cascade mode
utils.Sugar.Warn("switch to: CascadeMode")
config.CascadeMode = true
return config
//go Config.CascadeFunction()
}
return config
}