-
Notifications
You must be signed in to change notification settings - Fork 6
/
setters.go
212 lines (183 loc) · 7.25 KB
/
setters.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package prox5
import (
"time"
"git.tcp.direct/kayos/prox5/logger"
)
// AddUserAgents appends to the list of useragents we randomly choose from during proxied requests
func (p5 *ProxyEngine) AddUserAgents(uagents []string) {
p5.mu.Lock()
p5.opt.userAgents = append(p5.opt.userAgents, uagents...)
p5.mu.Unlock()
p5.DebugLogger.Printf("added %d useragents to cycle through for proxy validation", len(uagents))
}
// SetUserAgents sets the list of useragents we randomly choose from during proxied requests
func (p5 *ProxyEngine) SetUserAgents(uagents []string) {
p5.mu.Lock()
p5.opt.userAgents = uagents
p5.mu.Unlock()
p5.DebugLogger.Printf("set %d useragents to cycle through for proxy validation", len(uagents))
}
// SetCheckEndpoints replaces the running list of whatismyip style endpoitns for validation. (must return only the WAN IP)
func (p5 *ProxyEngine) SetCheckEndpoints(newendpoints []string) {
p5.mu.Lock()
p5.opt.checkEndpoints = newendpoints
p5.mu.Unlock()
p5.DebugLogger.Printf("set %d check endpoints for proxy validations", len(newendpoints))
}
// AddCheckEndpoints appends entries to the running list of whatismyip style endpoitns for validation. (must return only the WAN IP)
func (p5 *ProxyEngine) AddCheckEndpoints(endpoints []string) {
p5.mu.Lock()
p5.opt.checkEndpoints = append(p5.opt.checkEndpoints, endpoints...)
p5.mu.Unlock()
p5.DebugLogger.Printf("added %d check endpoints for proxy validations", len(endpoints))
}
// SetStaleTime replaces the duration of time after which a proxy will be considered "stale". stale proxies will be skipped upon retrieval.
func (p5 *ProxyEngine) SetStaleTime(newtime time.Duration) {
p5.opt.Lock()
p5.opt.stale = newtime
p5.opt.Unlock()
p5.DebugLogger.Printf("prox5 stale time set to %s", newtime)
}
// SetValidationTimeout sets the validationTimeout option.
func (p5 *ProxyEngine) SetValidationTimeout(timeout time.Duration) {
p5.opt.Lock()
p5.opt.validationTimeout = timeout
p5.opt.Unlock()
p5.DebugLogger.Printf("prox5 validation timeout set to %s", timeout)
}
// SetServerTimeout sets the serverTimeout option.
// * serverTimeout defines the timeout for outgoing connections made with the mysteryDialer.
// * To disable timeout on outgoing mysteryDialer connections, set this to time.Duration(0).
func (p5 *ProxyEngine) SetServerTimeout(timeout time.Duration) {
p5.opt.Lock()
p5.opt.serverTimeout = timeout
p5.opt.Unlock()
p5.DebugLogger.Printf("prox5 server timeout set to %s", timeout)
}
// SetMaxWorkers set the maximum workers for proxy checking.
func (p5 *ProxyEngine) SetMaxWorkers(num int) {
if p5.isEmpty() && num < 2 {
p5.DebugLogger.
Printf("prox5 cannot set max workers to %d, minimum is 2 until we have some valid proxies", num)
num = 2
}
p5.pool.Tune(num)
p5.scaler.SetBaseline(num)
}
// EnableRecycling enables recycling used proxies back into the pending channel for revalidation after dispensed.
func (p5 *ProxyEngine) EnableRecycling() {
p5.opt.Lock()
p5.opt.recycle = true
p5.opt.Unlock()
p5.DebugLogger.Printf("prox5 recycling enabled")
}
// DisableRecycling disables recycling used proxies back into the pending channel for revalidation after dispensed.
func (p5 *ProxyEngine) DisableRecycling() {
p5.opt.Lock()
p5.opt.recycle = false
p5.opt.Unlock()
p5.DebugLogger.Printf("prox5 recycling disabled")
}
// SetRemoveAfter sets the removeafter policy, the amount of times a recycled proxy is marked as bad before it is removed entirely.
// - Default is 10
// - To disable deleting entirely, set this value to -1
// - Only applies when recycling is enabled
func (p5 *ProxyEngine) SetRemoveAfter(timesfailed int) {
p5.opt.Lock()
p5.opt.removeafter = timesfailed
p5.opt.Unlock()
p5.DebugLogger.Printf("prox5 removeafter policy set to %d", timesfailed)
}
// SetDialerBailout sets the amount of times the mysteryDialer will dial out and fail before it bails out.
// - The dialer will attempt to redial a destination with a different proxy a specified amount of times before it gives up
func (p5 *ProxyEngine) SetDialerBailout(dialattempts int) {
p5.opt.Lock()
p5.opt.dialerBailout = dialattempts
p5.opt.Unlock()
p5.DebugLogger.Printf("prox5 dialer bailout set to %d", dialattempts)
}
// SetDispenseMiddleware will add a function that sits within the dialing process of the mysteryDialer and anyhing using it.
// This means this function will be called mid-dial during connections. Return true to approve proxy, false to skip it.
// Take care modiying the proxy in-flight as it is a pointer.
func (p5 *ProxyEngine) SetDispenseMiddleware(f func(*Proxy) (*Proxy, bool)) {
p5.mu.Lock()
p5.dispenseMiddleware = f
p5.mu.Unlock()
p5.DebugLogger.Printf("prox5 dispense middleware set")
}
// SetDebugLogger sets the debug logger for the ProxyEngine. See the Logger interface for implementation details.
//
// Deprecated: use SetLogger instead. This will be removed in a future version.
func (p5 *ProxyEngine) SetDebugLogger(l logger.Logger) {
p5.SetLogger(l)
}
// SetLogger sets the debug logger for the ProxyEngine. See the Logger interface for implementation details.
func (p5 *ProxyEngine) SetLogger(l logger.Logger) {
debugHardLock.Lock()
p5.mu.Lock()
p5.DebugLogger = l
p5.mu.Unlock()
debugHardLock.Unlock()
p5.DebugLogger.Printf("prox5 debug logger set")
}
func (p5 *ProxyEngine) SetAndEnableDebugLogger(l logger.Logger) {
p5.SetLogger(l)
p5.EnableDebug()
}
// EnableAutoScaler enables the autoscaler.
// This will automatically scale up the number of workers based on the threshold of dial attempts versus validated proxies.
func (p5 *ProxyEngine) EnableAutoScaler() {
p5.scaler.Enable()
p5.DebugLogger.Printf("prox5 autoscaler enabled")
}
// DisableAutoScaler disables the autoscaler.
func (p5 *ProxyEngine) DisableAutoScaler() {
p5.scaler.Disable()
p5.DebugLogger.Printf("prox5 autoscaler disabled")
}
// SetAutoScalerMaxScale sets the relative maximum amount that the autoscaler will scale up.
func (p5 *ProxyEngine) SetAutoScalerMaxScale(max int) {
p5.scaler.SetMax(max)
p5.DebugLogger.Printf("prox5 autoscaler max scale set to %d", max)
}
// SetAutoScalerThreshold sets the threshold of validated proxies versus dials that will trigger the autoscaler.
func (p5 *ProxyEngine) SetAutoScalerThreshold(threshold int) {
p5.scaler.SetThreshold(threshold)
p5.DebugLogger.Printf("prox5 autoscaler threshold set to %d", threshold)
}
func (p5 *ProxyEngine) EnableDebugRedaction() {
p5.opt.Lock()
p5.opt.redact = true
p5.opt.Unlock()
p5.DebugLogger.Printf("[redacted]")
}
func (p5 *ProxyEngine) DisableDebugRedaction() {
p5.opt.Lock()
p5.opt.redact = false
p5.opt.Unlock()
p5.DebugLogger.Printf("prox5 redaction disabled")
}
func (p5 *ProxyEngine) EnableRecyclerShuffling() {
p5.opt.Lock()
p5.opt.shuffle = true
p5.opt.Unlock()
p5.DebugLogger.Printf("prox5 recycler shuffling enabled")
}
func (p5 *ProxyEngine) DisableRecyclerShuffling() {
p5.opt.Lock()
p5.opt.shuffle = false
p5.opt.Unlock()
p5.DebugLogger.Printf("prox5 recycler shuffling disabled")
}
func (p5 *ProxyEngine) EnableHTTPClientTLSVerification() {
p5.opt.Lock()
p5.opt.tlsVerify = true
p5.opt.Unlock()
p5.DebugLogger.Printf("prox5 HTTP client TLS verification enabled")
}
func (p5 *ProxyEngine) DisableHTTPClientTLSVerification() {
p5.opt.Lock()
p5.opt.tlsVerify = false
p5.opt.Unlock()
p5.DebugLogger.Printf("prox5 HTTP client TLS verification disabled")
}