New: SOCKS5 Server timeout independant of Valid. timeout

This commit is contained in:
kayos@tcp.direct 2021-10-27 09:46:09 -07:00
parent c0389996a2
commit dc757d433b
Signed by: kayos
GPG Key ID: 4B841471B4BEE979
5 changed files with 24 additions and 6 deletions

View File

@ -92,6 +92,7 @@ func defOpt() *swampOptions {
sm.recycle.Store(true)
sm.debug.Store(false)
sm.validationTimeout.Store(time.Duration(12) * time.Second)
sm.serverTimeout.Store(time.Duration(360) * time.Second)
sm.dialerBailout.Store(defBailout)
sm.stale.Store(defaultStaleTime)
@ -143,6 +144,9 @@ type swampOptions struct {
// This will apply for both the initial quick check (dial), and the second check (HTTP GET).
validationTimeout atomic.Value
// serverTimeout defines the timeout for outgoing connections made with the MysteryDialer.
serverTimeout atomic.Value
dialerBailout atomic.Value
// recycle determines whether or not we recycle proxies pack into the pending channel after we dispense them

View File

@ -40,12 +40,23 @@ func (s *Swamp) GetValidationTimeout() time.Duration {
return s.swampopt.validationTimeout.Load().(time.Duration)
}
// GetTimeoutSecondsStr returns the current value of validationTimeout (in seconds string).
func (s *Swamp) GetTimeoutSecondsStr() string {
// GetValidationTimeoutStr returns the current value of validationTimeout (in seconds string).
func (s *Swamp) GetValidationTimeoutStr() string {
timeout := s.swampopt.validationTimeout.Load().(time.Duration)
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)
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()

View File

@ -47,13 +47,12 @@ func (s *Swamp) MysteryDialer(ctx context.Context, network, addr string) (net.Co
}
s.dbgPrint("dialer trying: " + sock.Endpoint + "...")
socksString = fmt.Sprintf("socks%s://%s?timeout=%ss", sock.GetProto(), sock.Endpoint, s.GetTimeoutSecondsStr())
socksString = fmt.Sprintf("socks%s://%s?timeout=%ss", sock.GetProto(), sock.Endpoint, s.GetServerTimeoutStr())
atomic.StoreUint32(&sock.lock, stateUnlocked)
dialSocks := socks.Dial(socksString)
if conn, err = dialSocks(network, addr); err != nil {
count++
s.dbgPrint(ylw + "unable to reach [redacted] with " + socksString + ", cycling..." + rst)
continue
}
break

View File

@ -42,6 +42,11 @@ func (s *Swamp) SetValidationTimeout(timeout time.Duration) {
s.swampopt.validationTimeout.Store(timeout)
}
// SetServerTimeout sets the serverTimeout option.
func (s *Swamp) SetServerTimeout(timeout time.Duration) {
s.swampopt.serverTimeout.Store(timeout)
}
// SetMaxWorkers set the maximum workers for proxy checking and clears the current proxy map and worker pool jobs.
func (s *Swamp) SetMaxWorkers(num int) {
s.pool.Tune(num)

View File

@ -32,13 +32,12 @@ func (s socksCreds) Valid(username, password string) bool {
// listen is standard Go listen string, e.g: "127.0.0.1:1080".
// username and password are used for authenticatig to the SOCKS5 server.
func (s *Swamp) StartSOCKS5Server(listen, username, password string) error {
s.socks5ServerAuth = socksCreds{username: username, password: password}
conf := &socks5.Config{
Dial: s.MysteryDialer,
Credentials: s.socks5ServerAuth,
Logger: s.socksServerLogger,
Dial: s.MysteryDialer,
}
s.dbgPrint("listening for SOCKS5 connections on " + listen)