prox5/setters.go

120 lines
4.1 KiB
Go
Raw Normal View History

2022-05-23 01:05:50 +00:00
package prox5
import (
"time"
"git.tcp.direct/kayos/prox5/logger"
)
// AddUserAgents appends to the list of useragents we randomly choose from during proxied requests
2022-09-22 23:48:08 +00:00
func (p5 *Swamp) AddUserAgents(uagents []string) {
p5.mu.Lock()
defer p5.mu.Unlock()
p5.swampopt.userAgents = append(p5.swampopt.userAgents, uagents...)
}
// SetUserAgents sets the list of useragents we randomly choose from during proxied requests
2022-09-22 23:48:08 +00:00
func (p5 *Swamp) SetUserAgents(uagents []string) {
p5.mu.Lock()
defer p5.mu.Unlock()
p5.swampopt.userAgents = uagents
}
// SetCheckEndpoints replaces the running list of whatismyip style endpoitns for validation. (must return only the WAN IP)
2022-09-22 23:48:08 +00:00
func (p5 *Swamp) SetCheckEndpoints(newendpoints []string) {
p5.mu.Lock()
defer p5.mu.Unlock()
p5.swampopt.checkEndpoints = newendpoints
}
// AddCheckEndpoints appends entries to the running list of whatismyip style endpoitns for validation. (must return only the WAN IP)
2022-09-22 23:48:08 +00:00
func (p5 *Swamp) AddCheckEndpoints(endpoints []string) {
p5.mu.Lock()
defer p5.mu.Unlock()
p5.swampopt.checkEndpoints = append(p5.swampopt.checkEndpoints, endpoints...)
}
// SetStaleTime replaces the duration of time after which a proxy will be considered "stale". stale proxies will be skipped upon retrieval.
2022-09-22 23:48:08 +00:00
func (p5 *Swamp) SetStaleTime(newtime time.Duration) {
p5.swampopt.Lock()
defer p5.swampopt.Unlock()
p5.swampopt.stale = newtime
}
2021-09-24 19:07:56 +00:00
// SetValidationTimeout sets the validationTimeout option.
2022-09-22 23:48:08 +00:00
func (p5 *Swamp) SetValidationTimeout(timeout time.Duration) {
p5.swampopt.Lock()
defer p5.swampopt.Unlock()
p5.swampopt.validationTimeout = timeout
}
// SetServerTimeout sets the serverTimeout option.
2021-10-28 15:51: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-09-22 23:48:08 +00:00
func (p5 *Swamp) SetServerTimeout(timeout time.Duration) {
p5.swampopt.Lock()
defer p5.swampopt.Unlock()
p5.swampopt.serverTimeout = timeout
}
2021-09-20 08:49:06 +00:00
// SetMaxWorkers set the maximum workers for proxy checking and clears the current proxy map and worker pool jobs.
2022-09-22 23:48:08 +00:00
func (p5 *Swamp) SetMaxWorkers(num int) {
p5.pool.Tune(num)
}
2021-10-27 02:51:14 +00:00
// EnableRecycling enables recycling used proxies back into the pending channel for revalidation after dispensed.
2022-09-22 23:48:08 +00:00
func (p5 *Swamp) EnableRecycling() {
p5.swampopt.Lock()
defer p5.swampopt.Unlock()
p5.swampopt.recycle = true
}
2021-10-27 02:51:14 +00:00
// DisableRecycling disables recycling used proxies back into the pending channel for revalidation after dispensed.
2022-09-22 23:48:08 +00:00
func (p5 *Swamp) DisableRecycling() {
p5.swampopt.Lock()
defer p5.swampopt.Unlock()
p5.swampopt.recycle = false
}
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.
// - Default is 10
// - To disable deleting entirely, set this value to -1
// - Only applies when recycling is enabled
2022-09-22 23:48:08 +00:00
func (p5 *Swamp) SetRemoveAfter(timesfailed int) {
p5.swampopt.Lock()
defer p5.swampopt.Unlock()
p5.swampopt.removeafter = timesfailed
2021-09-28 06:25:00 +00:00
}
// SetDialerBailout sets the amount of times the MysteryDialer will dial out and fail before it bails out.
// - The dialer will attempt to redial a destination with a different proxy a specified amount of times before it gives up
2022-09-22 23:48:08 +00:00
func (p5 *Swamp) SetDialerBailout(dialattempts int) {
p5.swampopt.Lock()
defer p5.swampopt.Unlock()
p5.swampopt.dialerBailout = dialattempts
}
// SetDispenseMiddleware will add a function that sits within the dialing process of the MysteryDialer and anyhing using it.
// 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-09-22 23:48:08 +00:00
func (p5 *Swamp) SetDispenseMiddleware(f func(*Proxy) (*Proxy, bool)) {
p5.mu.Lock()
defer p5.mu.Unlock()
p5.dispenseMiddleware = f
2021-09-20 08:49:06 +00:00
}
2022-09-22 23:28:28 +00:00
// SetDebugLogger sets the debug logger for the Swamp. See the Logger interface for implementation details.
2022-09-22 23:48:08 +00:00
func (p5 *Swamp) SetDebugLogger(l logger.Logger) {
debugHardLock.Lock()
2022-09-22 23:48:08 +00:00
p5.mu.Lock()
p5.DebugLogger = l
p5.mu.Unlock()
debugHardLock.Unlock()
}
2022-09-22 23:48:08 +00:00
func (p5 *Swamp) SetShuffle(shuffle bool) {
p5.mu.Lock()
defer p5.mu.Unlock()
p5.swampopt.shuffle = shuffle
}