fix major bug where all proxies were stale

This commit is contained in:
kayos@tcp.direct 2021-09-13 09:01:19 -07:00
parent 39fe5714f6
commit 39c93cf73a
4 changed files with 34 additions and 12 deletions

@ -32,7 +32,7 @@ type Swamp struct {
}
var (
defaultStaleTime = time.Duration(1) * time.Hour
defaultStaleTime = 1 * time.Hour
defWorkers = 100
defaultChecks = []string{"https://wtfismyip.com/text", "https://myexternalip.com/raw", "https://ipinfo.io/ip"}
)

@ -25,6 +25,23 @@ func init() {
println(err.Error())
os.Exit(1)
}
println("[USAGE] q: quit | d: debug | a: socks4 | b: socks4a | c: socks5")
}
func get(ver string) {
switch ver {
case "4":
println("retrieving SOCKS4...")
println(swamp.Socks4Str())
case "4a":
println("retrieving SOCKS4a...")
println(swamp.Socks4aStr())
case "5":
println("retrieving SOCKS5...")
println(swamp.Socks5Str())
}
}
func main() {
@ -49,6 +66,12 @@ func main() {
println("enabling debug")
swamp.EnableDebug()
}
case "a":
go get("4")
case "b":
go get("4a")
case "c":
go get("5")
case "q":
quit <- true
default:

@ -1,6 +1,9 @@
package pxndscvm
import "time"
import (
"fmt"
"time"
)
// Socks5Str gets a SOCKS5 proxy that we have fully verified (dialed and then retrieved our IP address from a what-is-my-ip endpoint.
func (s *Swamp) Socks5Str() string {
@ -68,18 +71,12 @@ func (s *Swamp) GetAnySOCKS() Proxy {
}
func (s *Swamp) stillGood(candidate Proxy) bool {
switch {
// if since its been validated it's ended up failing so much that its on our bad list then skip it
case badProx.Peek(candidate):
fallthrough
// if we've been checking or using this too often recently then skip it
case useProx.Check(candidate):
fallthrough
case time.Since(candidate.Verified) > s.swampopt.Stale:
if time.Since(candidate.Verified) > s.swampopt.Stale {
s.dbgPrint("proxy stale: " + candidate.Endpoint)
fmt.Println("time since: ", time.Since(candidate.Verified))
return false
default:
return true
}
return true
}
// RandomUserAgent retrieves a random user agent from our list in string form

@ -222,6 +222,8 @@ func (s *Swamp) tossUp() {
continue
}
p.Verified = time.Now()
switch p.Proto {
case "4":
s.Stats.v4()