-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgetters.go
147 lines (124 loc) · 3.98 KB
/
getters.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
package prox5
import (
"strconv"
"sync/atomic"
"time"
"git.tcp.direct/kayos/common/entropy"
)
// GetStatistics returns all Statistics atomics.
func (p5 *ProxyEngine) GetStatistics() Statistics {
p5.mu.RLock()
defer p5.mu.RUnlock()
return p5.stats
}
// RandomUserAgent retrieves a random user agent from our list in string form.
func (p5 *ProxyEngine) RandomUserAgent() string {
p5.mu.RLock()
defer p5.mu.RUnlock()
return entropy.RandomStrChoice(p5.opt.userAgents)
}
// GetRandomEndpoint returns a random whatismyip style endpoint from our ProxyEngine's options
func (p5 *ProxyEngine) GetRandomEndpoint() string {
p5.mu.RLock()
defer p5.mu.RUnlock()
return entropy.RandomStrChoice(p5.opt.checkEndpoints)
}
// GetStaleTime returns the duration of time after which a proxy will be considered "stale".
func (p5 *ProxyEngine) GetStaleTime() time.Duration {
p5.opt.RLock()
defer p5.opt.RUnlock()
return p5.opt.stale
}
// GetValidationTimeout returns the current value of validationTimeout.
func (p5 *ProxyEngine) GetValidationTimeout() time.Duration {
p5.opt.RLock()
defer p5.opt.RUnlock()
return p5.opt.validationTimeout
}
// GetValidationTimeoutStr returns the current value of validationTimeout (in seconds string).
func (p5 *ProxyEngine) GetValidationTimeoutStr() string {
p5.opt.RLock()
defer p5.opt.RUnlock()
timeout := p5.opt.validationTimeout
return strconv.Itoa(int(timeout / time.Second))
}
// GetServerTimeout returns the current value of serverTimeout.
func (p5 *ProxyEngine) GetServerTimeout() time.Duration {
p5.opt.RLock()
defer p5.opt.RUnlock()
return p5.opt.serverTimeout
}
// GetServerTimeoutStr returns the current value of serverTimeout (in seconds string).
func (p5 *ProxyEngine) GetServerTimeoutStr() string {
p5.opt.RLock()
defer p5.opt.RUnlock()
timeout := p5.opt.serverTimeout
if timeout == time.Duration(0) {
return "-1"
}
return strconv.Itoa(int(timeout / time.Second))
}
// GetMaxWorkers returns maximum amount of workers that validate proxies concurrently. Note this is read-only during runtime.
func (p5 *ProxyEngine) GetMaxWorkers() int {
return p5.pool.Cap()
}
// IsRunning returns true if our background goroutines defined in daemons.go are currently operational
func (p5 *ProxyEngine) IsRunning() bool {
return atomic.LoadUint32(&p5.Status) == 0
}
// GetRecyclingStatus retrieves the current recycling status, see EnableRecycling.
func (p5 *ProxyEngine) GetRecyclingStatus() bool {
p5.opt.RLock()
defer p5.opt.RUnlock()
return p5.opt.recycle
}
// GetWorkers retrieves pond worker Statistics:
// - return MaxWorkers, RunningWorkers, IdleWorkers
func (p5 *ProxyEngine) GetWorkers() (maxWorkers, runningWorkers, idleWorkers int) {
p5.mu.RLock()
defer p5.mu.RUnlock()
return p5.pool.Cap(), p5.pool.Running(), p5.pool.Free()
}
// GetRemoveAfter retrieves the removeafter policy, the amount of times a recycled proxy is marked as bad until it is removed entirely.
// - returns -1 if recycling is disabled.
func (p5 *ProxyEngine) GetRemoveAfter() int {
p5.mu.RLock()
defer p5.mu.RUnlock()
if !p5.opt.recycle {
return -1
}
return p5.opt.removeafter
}
// GetDialerBailout retrieves the dialer bailout policy. See SetDialerBailout for more info.
func (p5 *ProxyEngine) GetDialerBailout() int {
p5.mu.RLock()
defer p5.mu.RUnlock()
return p5.opt.dialerBailout
}
// TODO: Document middleware concept
func (p5 *ProxyEngine) GetDispenseMiddleware() func(*Proxy) (*Proxy, bool) {
p5.mu.RLock()
defer p5.mu.RUnlock()
return p5.dispenseMiddleware
}
func (p5 *ProxyEngine) GetRecyclerShuffleStatus() bool {
p5.mu.RLock()
defer p5.mu.RUnlock()
return p5.opt.shuffle
}
func (p5 *ProxyEngine) GetAutoScalerStatus() bool {
return p5.scaler.IsOn()
}
func (p5 *ProxyEngine) GetAutoScalerStateString() string {
return p5.scaler.StateString()
}
func (p5 *ProxyEngine) GetDebugRedactStatus() bool {
p5.mu.RLock()
defer p5.mu.RUnlock()
return p5.opt.redact
}
func (p5 *ProxyEngine) GetHTTPTLSVerificationStatus() bool {
p5.mu.RLock()
defer p5.mu.RUnlock()
return p5.opt.tlsVerify
}