2022-05-23 01:05:50 +00:00
|
|
|
package prox5
|
2021-09-13 09:37:59 +00:00
|
|
|
|
2021-09-13 16:32:07 +00:00
|
|
|
import (
|
|
|
|
"time"
|
2022-08-28 13:12:48 +00:00
|
|
|
|
|
|
|
"git.tcp.direct/kayos/prox5/logger"
|
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
|
2022-10-16 10:53:04 +00:00
|
|
|
func (p5 *ProxyEngine) AddUserAgents(uagents []string) {
|
2022-09-22 23:48:08 +00:00
|
|
|
p5.mu.Lock()
|
2022-10-16 10:53:04 +00:00
|
|
|
p5.opt.userAgents = append(p5.opt.userAgents, uagents...)
|
2022-09-29 06:20:53 +00:00
|
|
|
p5.mu.Unlock()
|
2021-09-13 09:37:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetUserAgents sets the list of useragents we randomly choose from during proxied requests
|
2022-10-16 10:53:04 +00:00
|
|
|
func (p5 *ProxyEngine) SetUserAgents(uagents []string) {
|
2022-09-22 23:48:08 +00:00
|
|
|
p5.mu.Lock()
|
2022-10-16 10:53:04 +00:00
|
|
|
p5.opt.userAgents = uagents
|
2022-09-29 06:20:53 +00:00
|
|
|
p5.mu.Unlock()
|
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)
|
2022-10-16 10:53:04 +00:00
|
|
|
func (p5 *ProxyEngine) SetCheckEndpoints(newendpoints []string) {
|
2022-09-22 23:48:08 +00:00
|
|
|
p5.mu.Lock()
|
2022-10-16 10:53:04 +00:00
|
|
|
p5.opt.checkEndpoints = newendpoints
|
2022-09-29 06:20:53 +00:00
|
|
|
p5.mu.Unlock()
|
2021-09-13 15:36:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddCheckEndpoints appends entries to the running list of whatismyip style endpoitns for validation. (must return only the WAN IP)
|
2022-10-16 10:53:04 +00:00
|
|
|
func (p5 *ProxyEngine) AddCheckEndpoints(endpoints []string) {
|
2022-09-22 23:48:08 +00:00
|
|
|
p5.mu.Lock()
|
2022-10-16 10:53:04 +00:00
|
|
|
p5.opt.checkEndpoints = append(p5.opt.checkEndpoints, endpoints...)
|
2022-09-29 06:20:53 +00:00
|
|
|
p5.mu.Unlock()
|
2021-09-13 15:36:30 +00:00
|
|
|
}
|
|
|
|
|
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.
|
2022-10-16 10:53:04 +00:00
|
|
|
func (p5 *ProxyEngine) SetStaleTime(newtime time.Duration) {
|
|
|
|
p5.opt.Lock()
|
|
|
|
p5.opt.stale = newtime
|
|
|
|
p5.opt.Unlock()
|
2021-09-13 16:32:07 +00:00
|
|
|
}
|
|
|
|
|
2021-09-24 19:07:56 +00:00
|
|
|
// SetValidationTimeout sets the validationTimeout option.
|
2022-10-16 10:53:04 +00:00
|
|
|
func (p5 *ProxyEngine) SetValidationTimeout(timeout time.Duration) {
|
|
|
|
p5.opt.Lock()
|
|
|
|
p5.opt.validationTimeout = timeout
|
|
|
|
p5.opt.Unlock()
|
2021-09-13 17:40:23 +00:00
|
|
|
}
|
|
|
|
|
2021-10-27 16:46:09 +00:00
|
|
|
// SetServerTimeout sets the serverTimeout option.
|
2022-12-27 12:58:10 +00:00
|
|
|
// * serverTimeout defines the timeout for outgoing connections made with the mysteryDialer.
|
|
|
|
// * To disable timeout on outgoing mysteryDialer connections, set this to time.Duration(0).
|
2022-10-16 10:53:04 +00:00
|
|
|
func (p5 *ProxyEngine) SetServerTimeout(timeout time.Duration) {
|
|
|
|
p5.opt.Lock()
|
|
|
|
p5.opt.serverTimeout = timeout
|
|
|
|
p5.opt.Unlock()
|
2021-10-27 16:46:09 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 01:39:19 +00:00
|
|
|
// SetMaxWorkers set the maximum workers for proxy checking.
|
2022-10-16 10:53:04 +00:00
|
|
|
func (p5 *ProxyEngine) SetMaxWorkers(num int) {
|
2022-09-22 23:48:08 +00:00
|
|
|
p5.pool.Tune(num)
|
2022-12-05 01:39:19 +00:00
|
|
|
p5.scaler.SetBaseline(num)
|
2021-09-13 10:08:04 +00:00
|
|
|
}
|
2021-09-20 07:05:21 +00:00
|
|
|
|
2021-10-27 02:51:14 +00:00
|
|
|
// EnableRecycling enables recycling used proxies back into the pending channel for revalidation after dispensed.
|
2022-10-16 10:53:04 +00:00
|
|
|
func (p5 *ProxyEngine) EnableRecycling() {
|
|
|
|
p5.opt.Lock()
|
|
|
|
p5.opt.recycle = true
|
|
|
|
p5.opt.Unlock()
|
2021-09-24 21:06:08 +00:00
|
|
|
}
|
|
|
|
|
2021-10-27 02:51:14 +00:00
|
|
|
// DisableRecycling disables recycling used proxies back into the pending channel for revalidation after dispensed.
|
2022-10-16 10:53:04 +00:00
|
|
|
func (p5 *ProxyEngine) DisableRecycling() {
|
|
|
|
p5.opt.Lock()
|
|
|
|
p5.opt.recycle = false
|
|
|
|
p5.opt.Unlock()
|
2021-09-20 07:05:21 +00:00
|
|
|
}
|
2021-09-20 08:49:06 +00:00
|
|
|
|
2021-10-27 03:08:23 +00:00
|
|
|
// SetRemoveAfter sets the removeafter policy, the amount of times a recycled proxy is marked as bad before it is removed entirely.
|
2022-08-28 13:12:48 +00:00
|
|
|
// - Default is 10
|
|
|
|
// - To disable deleting entirely, set this value to -1
|
|
|
|
// - Only applies when recycling is enabled
|
2022-10-16 10:53:04 +00:00
|
|
|
func (p5 *ProxyEngine) SetRemoveAfter(timesfailed int) {
|
|
|
|
p5.opt.Lock()
|
|
|
|
p5.opt.removeafter = timesfailed
|
|
|
|
p5.opt.Unlock()
|
2021-09-28 06:25:00 +00:00
|
|
|
}
|
|
|
|
|
2022-12-27 12:55:03 +00:00
|
|
|
// SetDialerBailout sets the amount of times the mysteryDialer will dial out and fail before it bails out.
|
2022-08-28 13:12:48 +00:00
|
|
|
// - The dialer will attempt to redial a destination with a different proxy a specified amount of times before it gives up
|
2022-10-16 10:53:04 +00:00
|
|
|
func (p5 *ProxyEngine) SetDialerBailout(dialattempts int) {
|
|
|
|
p5.opt.Lock()
|
|
|
|
p5.opt.dialerBailout = dialattempts
|
|
|
|
p5.opt.Unlock()
|
2022-05-23 01:20:40 +00:00
|
|
|
}
|
|
|
|
|
2022-12-27 12:55:03 +00:00
|
|
|
// SetDispenseMiddleware will add a function that sits within the dialing process of the mysteryDialer and anyhing using it.
|
2022-05-23 01:20:40 +00:00
|
|
|
// 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.
|
2022-10-16 10:53:04 +00:00
|
|
|
func (p5 *ProxyEngine) SetDispenseMiddleware(f func(*Proxy) (*Proxy, bool)) {
|
2022-09-22 23:48:08 +00:00
|
|
|
p5.mu.Lock()
|
|
|
|
p5.dispenseMiddleware = f
|
2022-09-29 06:20:53 +00:00
|
|
|
p5.mu.Unlock()
|
2021-09-20 08:49:06 +00:00
|
|
|
}
|
2022-08-28 13:12:48 +00:00
|
|
|
|
2022-10-16 10:53:04 +00:00
|
|
|
// SetDebugLogger sets the debug logger for the ProxyEngine. See the Logger interface for implementation details.
|
|
|
|
func (p5 *ProxyEngine) SetDebugLogger(l logger.Logger) {
|
2022-08-28 13:12:48 +00:00
|
|
|
debugHardLock.Lock()
|
2022-09-22 23:48:08 +00:00
|
|
|
p5.mu.Lock()
|
|
|
|
p5.DebugLogger = l
|
|
|
|
p5.mu.Unlock()
|
2022-08-28 13:12:48 +00:00
|
|
|
debugHardLock.Unlock()
|
|
|
|
}
|
|
|
|
|
2022-12-05 01:39:19 +00:00
|
|
|
// EnableAutoScaler enables the autoscaler.
|
|
|
|
// This will automatically scale up the number of workers based on the threshold of dial attempts versus validated proxies.
|
2022-10-16 12:56:40 +00:00
|
|
|
func (p5 *ProxyEngine) EnableAutoScaler() {
|
|
|
|
p5.scaler.Enable()
|
|
|
|
}
|
|
|
|
|
2022-12-05 01:39:19 +00:00
|
|
|
// DisableAutoScaler disables the autoscaler.
|
2022-10-16 12:56:40 +00:00
|
|
|
func (p5 *ProxyEngine) DisableAutoScaler() {
|
|
|
|
p5.scaler.Disable()
|
|
|
|
}
|
|
|
|
|
2022-12-05 01:39:19 +00:00
|
|
|
// SetAutoScalerMaxScale sets the relative maximum amount that the autoscaler will scale up.
|
|
|
|
func (p5 *ProxyEngine) SetAutoScalerMaxScale(max int) {
|
|
|
|
p5.scaler.SetMax(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)
|
|
|
|
}
|
|
|
|
|
2022-10-16 12:56:40 +00:00
|
|
|
func (p5 *ProxyEngine) EnableDebugRedaction() {
|
|
|
|
p5.opt.Lock()
|
|
|
|
p5.opt.redact = true
|
|
|
|
p5.opt.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p5 *ProxyEngine) DisableDebugRedaction() {
|
2022-10-16 10:53:04 +00:00
|
|
|
p5.opt.Lock()
|
2022-10-16 12:56:40 +00:00
|
|
|
p5.opt.redact = false
|
2022-10-16 10:53:04 +00:00
|
|
|
p5.opt.Unlock()
|
2022-08-28 13:12:48 +00:00
|
|
|
}
|
2022-10-16 12:56:40 +00:00
|
|
|
|
|
|
|
/*func (p5 *ProxyEngine) EnableListShuffle() {
|
|
|
|
p5.opt.Lock()
|
|
|
|
p5.opt.shuffle = true
|
|
|
|
p5.opt.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p5 *ProxyEngine) DisableListShuffle() {
|
|
|
|
p5.opt.Lock()
|
|
|
|
p5.opt.shuffle = false
|
|
|
|
p5.opt.Unlock()
|
|
|
|
}*/
|