prox5/getters.go

104 lines
3.2 KiB
Go
Raw Normal View History

2021-10-09 17:23:13 +00:00
package Prox5
2021-09-13 08:30:49 +00:00
import (
"strconv"
"time"
)
// GetProto safely retrieves the protocol value of the Proxy.
2021-10-24 20:30:15 +00:00
func (sock *Proxy) GetProto() string {
return sock.Proto.Load().(string)
}
2021-10-27 15:46:15 +00:00
// GetStatistics returns all current statistics.
// * This is a pointer, do not modify it!
func (s *Swamp) GetStatistics() *Statistics {
return s.Stats
}
// RandomUserAgent retrieves a random user agent from our list in string form.
func (s *Swamp) RandomUserAgent() string {
s.mu.RLock()
defer s.mu.RUnlock()
return randStrChoice(s.swampopt.userAgents)
}
// GetRandomEndpoint returns a random whatismyip style endpoint from our Swamp's options
func (s *Swamp) GetRandomEndpoint() string {
s.mu.RLock()
defer s.mu.RUnlock()
return randStrChoice(s.swampopt.checkEndpoints)
}
// GetStaleTime returns the duration of time after which a proxy will be considered "stale".
func (s *Swamp) GetStaleTime() time.Duration {
return s.swampopt.stale.Load().(time.Duration)
}
// GetValidationTimeout returns the current value of validationTimeout.
2021-09-24 19:07:56 +00:00
func (s *Swamp) GetValidationTimeout() time.Duration {
return s.swampopt.validationTimeout.Load().(time.Duration)
}
// GetValidationTimeoutStr returns the current value of validationTimeout (in seconds string).
func (s *Swamp) GetValidationTimeoutStr() string {
timeout := s.swampopt.validationTimeout.Load().(time.Duration)
2021-09-28 06:25:00 +00:00
return strconv.Itoa(int(timeout / time.Second))
}
// GetServerTimeout returns the current value of serverTimeout.
func (s *Swamp) GetServerTimeout() time.Duration {
return s.swampopt.serverTimeout.Load().(time.Duration)
}
// GetServerTimeoutStr returns the current value of serverTimeout (in seconds string).
func (s *Swamp) GetServerTimeoutStr() string {
timeout := s.swampopt.serverTimeout.Load().(time.Duration)
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.
func (s *Swamp) GetMaxWorkers() int {
return s.pool.Cap()
}
2021-09-20 01:23:18 +00:00
// IsRunning returns true if our background goroutines defined in daemons.go are currently operational
func (s *Swamp) IsRunning() bool {
if s.runningdaemons.Load() == nil {
return false
2021-09-20 01:23:18 +00:00
}
return s.runningdaemons.Load().(int) > 0
2021-09-20 01:23:18 +00:00
}
// GetRecyclingStatus retrieves the current recycling status, see EnableRecycling.
func (s *Swamp) GetRecyclingStatus() bool {
return s.swampopt.recycle.Load().(bool)
}
// GetWorkers retrieves pond worker statistics:
// * return MaxWorkers, RunningWorkers, IdleWorkers
2021-10-24 20:30:15 +00:00
func (s *Swamp) GetWorkers() (maxWorkers, runningWorkers, idleWorkers int) {
s.mu.RLock()
defer s.mu.RUnlock()
2021-09-24 19:07:56 +00:00
return s.pool.Cap(), s.pool.Running(), s.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.
func (s *Swamp) GetRemoveAfter() int {
s.mu.RLock()
defer s.mu.RUnlock()
if !s.swampopt.recycle.Load().(bool) {
2021-09-20 08:49:06 +00:00
return -1
}
return s.swampopt.removeafter.Load().(int)
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.
func (s *Swamp) GetDialerBailout() int {
return s.swampopt.dialerBailout.Load().(int)
}