2021-09-13 09:37:59 +00:00
|
|
|
package pxndscvm
|
|
|
|
|
2021-09-13 16:32:07 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
2021-09-20 07:16:20 +00:00
|
|
|
"fmt"
|
2021-09-13 16:32:07 +00:00
|
|
|
"time"
|
2021-09-20 07:16:20 +00:00
|
|
|
|
|
|
|
"github.com/alitto/pond"
|
2021-09-13 16:32:07 +00:00
|
|
|
)
|
2021-09-13 10:08:04 +00:00
|
|
|
|
2021-09-13 09:37:59 +00:00
|
|
|
// AddUserAgents appends to the list of useragents we randomly choose from during proxied requests
|
|
|
|
func (s *Swamp) AddUserAgents(uagents []string) {
|
|
|
|
// mutex lock so that RLock during proxy checking will block while we change this value
|
|
|
|
s.mu.Lock()
|
|
|
|
defer s.mu.Unlock()
|
2021-09-18 13:47:19 +00:00
|
|
|
s.swampopt.userAgents = append(s.swampopt.userAgents, uagents...)
|
2021-09-13 09:37:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetUserAgents sets the list of useragents we randomly choose from during proxied requests
|
|
|
|
func (s *Swamp) SetUserAgents(uagents []string) {
|
|
|
|
s.mu.Lock()
|
|
|
|
defer s.mu.Unlock()
|
2021-09-18 13:47:19 +00:00
|
|
|
s.swampopt.userAgents = append(s.swampopt.userAgents, uagents...)
|
2021-09-13 09:37:59 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 15:36:30 +00:00
|
|
|
// SetCheckEndpoints replaces the running list of whatismyip style endpoitns for validation. (must return only the WAN IP)
|
|
|
|
func (s *Swamp) SetCheckEndpoints(newendpoints []string) {
|
|
|
|
s.mu.Lock()
|
|
|
|
defer s.mu.Unlock()
|
|
|
|
s.swampopt.CheckEndpoints = newendpoints
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddCheckEndpoints appends entries to the running list of whatismyip style endpoitns for validation. (must return only the WAN IP)
|
|
|
|
func (s *Swamp) AddCheckEndpoints(newendpoints []string) {
|
|
|
|
s.mu.Lock()
|
|
|
|
defer s.mu.Unlock()
|
|
|
|
s.swampopt.CheckEndpoints = append(s.swampopt.CheckEndpoints, newendpoints...)
|
|
|
|
}
|
|
|
|
|
2021-09-13 16:32:07 +00:00
|
|
|
// SetStaleTime replaces the duration of time after which a proxy will be considered "stale". stale proxies will be skipped upon retrieval.
|
|
|
|
func (s *Swamp) SetStaleTime(newtime time.Duration) {
|
|
|
|
s.mu.Lock()
|
|
|
|
defer s.mu.Unlock()
|
2021-09-18 13:47:19 +00:00
|
|
|
s.swampopt.stale = newtime
|
2021-09-13 16:32:07 +00:00
|
|
|
}
|
|
|
|
|
2021-09-18 13:47:19 +00:00
|
|
|
// SetValidationTimeout sets the validationTimeout option (in seconds).
|
2021-09-13 17:40:23 +00:00
|
|
|
func (s *Swamp) SetValidationTimeout(newtimeout int) {
|
|
|
|
s.mu.Lock()
|
|
|
|
defer s.mu.Unlock()
|
2021-09-18 13:47:19 +00:00
|
|
|
s.swampopt.validationTimeout = newtimeout
|
2021-09-13 17:40:23 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 15:17:20 +00:00
|
|
|
// SetMaxWorkers set the maximum workers for proxy checking, this must be set before calling LoadProxyTXT for the first time.
|
2021-09-13 10:08:04 +00:00
|
|
|
func (s *Swamp) SetMaxWorkers(num int) error {
|
2021-09-18 12:38:09 +00:00
|
|
|
if s.Status == Running {
|
|
|
|
return errors.New("can't change max workers during proxypool operation, try pausing first")
|
2021-09-13 10:08:04 +00:00
|
|
|
}
|
2021-09-20 07:16:20 +00:00
|
|
|
s.pool.Stop()
|
2021-09-18 13:47:19 +00:00
|
|
|
s.swampopt.maxWorkers = num
|
2021-09-20 07:16:20 +00:00
|
|
|
s.pool = pond.New(s.swampopt.maxWorkers, 1000000, pond.PanicHandler(func(p interface{}) {
|
|
|
|
fmt.Println("WORKER PANIC! ", p)
|
|
|
|
}))
|
2021-09-13 10:08:04 +00:00
|
|
|
return nil
|
|
|
|
}
|
2021-09-20 07:05:21 +00:00
|
|
|
|
|
|
|
// EnableRecycling toggles recycling used proxies back into the pending channel for revalidation after dispensed.
|
|
|
|
func (s *Swamp) EnableRecycling(choice bool) {
|
|
|
|
s.mu.Lock()
|
|
|
|
defer s.mu.Unlock()
|
|
|
|
s.swampopt.recycle = choice
|
|
|
|
}
|