prox5/getters.go

149 lines
4.0 KiB
Go
Raw Normal View History

2022-05-23 01:05:50 +00:00
package prox5
2021-09-13 08:30:49 +00:00
import (
"strconv"
"sync/atomic"
"time"
"git.tcp.direct/kayos/common/entropy"
)
2022-10-16 07:38:49 +00:00
// GetStatistics returns all current Statistics.
2021-10-27 15:46:15 +00:00
// * This is a pointer, do not modify it!
2022-10-16 10:53:04 +00:00
func (p5 *ProxyEngine) GetStatistics() *Statistics {
2022-09-29 06:20:53 +00:00
p5.mu.RLock()
defer p5.mu.RUnlock()
2022-09-22 23:48:08 +00:00
return p5.stats
2021-10-27 15:46:15 +00:00
}
// RandomUserAgent retrieves a random user agent from our list in string form.
2022-10-16 10:53:04 +00:00
func (p5 *ProxyEngine) RandomUserAgent() string {
2022-09-22 23:48:08 +00:00
p5.mu.RLock()
defer p5.mu.RUnlock()
2022-10-16 10:53:04 +00:00
return entropy.RandomStrChoice(p5.opt.userAgents)
}
2022-10-16 10:53:04 +00:00
// GetRandomEndpoint returns a random whatismyip style endpoint from our ProxyEngine's options
func (p5 *ProxyEngine) GetRandomEndpoint() string {
2022-09-22 23:48:08 +00:00
p5.mu.RLock()
defer p5.mu.RUnlock()
2022-10-16 10:53:04 +00:00
return entropy.RandomStrChoice(p5.opt.checkEndpoints)
}
// GetStaleTime returns the duration of time after which a proxy will be considered "stale".
2022-10-16 10:53:04 +00:00
func (p5 *ProxyEngine) GetStaleTime() time.Duration {
p5.opt.RLock()
defer p5.opt.RUnlock()
return p5.opt.stale
}
// GetValidationTimeout returns the current value of validationTimeout.
2022-10-16 10:53:04 +00:00
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).
2022-10-16 10:53:04 +00:00
func (p5 *ProxyEngine) GetValidationTimeoutStr() string {
p5.opt.RLock()
defer p5.opt.RUnlock()
timeout := p5.opt.validationTimeout
2021-09-28 06:25:00 +00:00
return strconv.Itoa(int(timeout / time.Second))
}
// GetServerTimeout returns the current value of serverTimeout.
2022-10-16 10:53:04 +00:00
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).
2022-10-16 10:53:04 +00:00
func (p5 *ProxyEngine) GetServerTimeoutStr() string {
p5.opt.RLock()
defer p5.opt.RUnlock()
timeout := p5.opt.serverTimeout
2021-10-28 15:51:10 +00:00
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.
2022-10-16 10:53:04 +00:00
func (p5 *ProxyEngine) GetMaxWorkers() int {
2022-09-22 23:48:08 +00:00
return p5.pool.Cap()
}
2021-09-20 01:23:18 +00:00
// IsRunning returns true if our background goroutines defined in daemons.go are currently operational
2022-10-16 10:53:04 +00:00
func (p5 *ProxyEngine) IsRunning() bool {
2022-09-29 04:26:10 +00:00
return atomic.LoadUint32(&p5.Status) == 0
2021-09-20 01:23:18 +00:00
}
// GetRecyclingStatus retrieves the current recycling status, see EnableRecycling.
2022-10-16 10:53:04 +00:00
func (p5 *ProxyEngine) GetRecyclingStatus() bool {
p5.opt.RLock()
defer p5.opt.RUnlock()
return p5.opt.recycle
}
2022-10-16 07:38:49 +00:00
// GetWorkers retrieves pond worker Statistics:
// - return MaxWorkers, RunningWorkers, IdleWorkers
2022-10-16 10:53:04 +00:00
func (p5 *ProxyEngine) GetWorkers() (maxWorkers, runningWorkers, idleWorkers int) {
2022-09-22 23:48:08 +00:00
p5.mu.RLock()
defer p5.mu.RUnlock()
return p5.pool.Cap(), p5.pool.Running(), p5.pool.Free()
}
2021-09-20 08:49:06 +00:00
// 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.
2022-10-16 10:53:04 +00:00
func (p5 *ProxyEngine) GetRemoveAfter() int {
2022-09-22 23:48:08 +00:00
p5.mu.RLock()
defer p5.mu.RUnlock()
2022-10-16 10:53:04 +00:00
if !p5.opt.recycle {
2021-09-20 08:49:06 +00:00
return -1
}
2022-10-16 10:53:04 +00:00
return p5.opt.removeafter
2021-09-20 08:49:06 +00:00
}
2021-09-28 06:25:00 +00:00
// GetDialerBailout retrieves the dialer bailout policy. See SetDialerBailout for more info.
2022-10-16 10:53:04 +00:00
func (p5 *ProxyEngine) GetDialerBailout() int {
2022-09-22 23:48:08 +00:00
p5.mu.RLock()
defer p5.mu.RUnlock()
2022-10-16 10:53:04 +00:00
return p5.opt.dialerBailout
}
2022-07-25 07:14:26 +00:00
// TODO: Document middleware concept
2022-10-16 10:53:04 +00:00
func (p5 *ProxyEngine) GetDispenseMiddleware() func(*Proxy) (*Proxy, bool) {
2022-09-22 23:48:08 +00:00
p5.mu.RLock()
defer p5.mu.RUnlock()
return p5.dispenseMiddleware
2021-09-28 06:25:00 +00:00
}
2023-01-31 09:21:29 +00:00
func (p5 *ProxyEngine) GetRecyclerShuffleStatus() bool {
2022-09-22 23:48:08 +00:00
p5.mu.RLock()
defer p5.mu.RUnlock()
2022-10-16 10:53:04 +00:00
return p5.opt.shuffle
2023-01-31 09:21:29 +00:00
}
2022-10-16 12:56:40 +00:00
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
}
2023-01-31 09:21:29 +00:00
func (p5 *ProxyEngine) GetHTTPTLSVerificationStatus() bool {
p5.mu.RLock()
defer p5.mu.RUnlock()
return p5.opt.tlsVerify
}