Projects STRLCPY prox5 Commits 28805017
🤬
  • ■ ■ ■ ■ ■ ■
    .gitignore
    1 1  .idea/
    2 2  *.txt
    3 3  *.list
     4 +*.swp
     5 +*.save
    4 6   
  • ■ ■ ■ ■ ■ ■
    debug.go
    skipped 90 lines
    91 91   }
    92 92  }
    93 93   
     94 +func (pe *ProxyEngine) msgUnableToReach(socksString string) {
     95 + buf := copABuffer.Get().(*strings.Builder)
     96 + buf.WriteString("unable to reach [redacted] with ")
     97 + buf.WriteString(socksString)
     98 + buf.WriteString(", cycling...")
     99 + pe.dbgPrint(buf)
     100 +}
     101 + 
     102 +func (pe *ProxyEngine) msgUsingProxy(socksString string) {
     103 + buf := copABuffer.Get().(*strings.Builder)
     104 + buf.WriteString("MysteryDialer using socks: ")
     105 + buf.WriteString(socksString)
     106 + pe.dbgPrint(buf)
     107 +}
     108 + 
     109 +func (pe *ProxyEngine) msgFailedMiddleware(socksString string) {
     110 + buf := copABuffer.Get().(*strings.Builder)
     111 + buf.WriteString("failed middleware check, ")
     112 + buf.WriteString(socksString)
     113 + buf.WriteString(", cycling...")
     114 + pe.dbgPrint(buf)
     115 +}
     116 + 
     117 +func (pe *ProxyEngine) msgTry(socksString string) {
     118 + buf := copABuffer.Get().(*strings.Builder)
     119 + buf.WriteString("try dial with: ")
     120 + buf.WriteString(socksString)
     121 + pe.dbgPrint(buf)
     122 +}
     123 + 
     124 +func (pe *ProxyEngine) msgCantGetLock(socksString string, putback bool) {
     125 + buf := copABuffer.Get().(*strings.Builder)
     126 + buf.WriteString("can't get lock for ")
     127 + buf.WriteString(socksString)
     128 + if putback {
     129 + buf.WriteString(", putting back in queue")
     130 + }
     131 + pe.dbgPrint(buf)
     132 +}
     133 + 
     134 +func (pe *ProxyEngine) msgGotLock(socksString string) {
     135 + buf := copABuffer.Get().(*strings.Builder)
     136 + buf.WriteString("got lock for ")
     137 + buf.WriteString(socksString)
     138 + pe.dbgPrint(buf)
     139 +}
     140 + 
     141 +func (pe *ProxyEngine) msgChecked(sock *Proxy, success bool) {
     142 + buf := copABuffer.Get().(*strings.Builder)
     143 + if success {
     144 + buf.WriteString("verified ")
     145 + buf.WriteString(sock.Endpoint)
     146 + buf.WriteString(" as SOCKS")
     147 + buf.WriteString(getProtoStr(sock.proto))
     148 + pe.dbgPrint(buf)
     149 + return
     150 + }
     151 + buf.WriteString("failed to verify: ")
     152 + buf.WriteString(sock.Endpoint)
     153 + pe.dbgPrint(buf)
     154 +}
     155 + 
     156 +func (pe *ProxyEngine) msgBadProxRate(sock *Proxy) {
     157 + buf := copABuffer.Get().(*strings.Builder)
     158 + buf.WriteString("badProx ratelimited: ")
     159 + buf.WriteString(sock.Endpoint)
     160 + pe.dbgPrint(buf)
     161 +}
     162 + 
  • ■ ■ ■ ■ ■ ■
    defs.go
    skipped 157 lines
    158 158   }
    159 159   
    160 160   stats := []int64{pe.stats.Valid4, pe.stats.Valid4a, pe.stats.Valid5, pe.stats.ValidHTTP, pe.stats.Dispensed}
    161  - for _, st := range stats {
    162  - atomic.StoreInt64(&st, 0)
     161 + for i := range stats {
     162 + atomic.StoreInt64(&stats[i], 0)
    163 163   }
    164 164   
    165 165   chans := []*chan *Proxy{&pe.Valids.SOCKS5, &pe.Valids.SOCKS4, &pe.Valids.SOCKS4a, &pe.Valids.HTTP, &pe.Pending}
    skipped 75 lines
  • ■ ■ ■ ■ ■
    dispense.go
    skipped 68 lines
    69 69  // GetAnySOCKS retrieves any version SOCKS proxy as a Proxy type
    70 70  // Will block if one is not available!
    71 71  // StateNew/Temporary: Pass a true boolean to this to also receive HTTP proxies.
    72  -func (pe *ProxyEngine) GetAnySOCKS(AcceptHTTP bool) *Proxy {
     72 +func (pe *ProxyEngine) GetAnySOCKS(acceptHTTP bool) *Proxy {
    73 73   defer pe.stats.dispense()
    74 74   for {
    75 75   var sock *Proxy
    skipped 5 lines
    81 81   case sock = <-pe.Valids.SOCKS5:
    82 82   break
    83 83   default:
    84  - if !AcceptHTTP {
    85  - time.Sleep(500 * time.Millisecond)
     84 + if !acceptHTTP {
    86 85   continue
    87 86   }
    88 87   if httptun, htok := pe.GetHTTPTunnel(); htok {
    skipped 47 lines
  • ■ ■ ■ ■ ■
    getters.go
    skipped 140 lines
    141 141   return pe.swampopt.dialerBailout
    142 142  }
    143 143   
    144  -// TODO: More docs
     144 +// TODO: Document middleware concept
     145 + 
    145 146  func (pe *ProxyEngine) GetDispenseMiddleware() func(*Proxy) (*Proxy, bool) {
    146 147   pe.mu.RLock()
    147 148   defer pe.mu.RUnlock()
    skipped 3 lines
  • ■ ■ ■ ■ ■
    list_management.go
    skipped 43 lines
    44 44   return fmt.Sprintf("%s:%s@%s", split6[0], split6[1], combo.String()), true
    45 45  }
    46 46   
    47  -func (pe *ProxyEngine) filter(in string) (filtered string, ok bool) {
     47 +func (pe *ProxyEngine) filter(in string) (filtered string, ok bool) { //nolint:cyclop
    48 48   if !strings.Contains(in, ":") {
    49 49   return in, false
    50 50   }
    skipped 35 lines
    86 86  }
    87 87   
    88 88  // LoadProxyTXT loads proxies from a given seed file and feeds them to the mapBuilder to be later queued automatically for validation.
    89  -// Expects the following formats:
     89 +// Expects one of the following formats for each line:
    90 90  // * 127.0.0.1:1080
    91 91  // * 127.0.0.1:1080:user:pass
    92 92  // * yeet.com:1080
    skipped 23 lines
    116 116   return pe.LoadMultiLineString(sockstr)
    117 117  }
    118 118   
    119  -// LoadSingleProxy loads a SOCKS proxy into our map. Uses the format: 127.0.0.1:1080 (host:port).
     119 +// LoadSingleProxy loads a SOCKS proxy into our map.
     120 +// Expects one of the following formats:
     121 +// * 127.0.0.1:1080
     122 +// * 127.0.0.1:1080:user:pass
     123 +// * yeet.com:1080
     124 +// * yeet.com:1080:user:pass
     125 +// * [fe80::2ef0:5dff:fe7f:c299]:1080
     126 +// * [fe80::2ef0:5dff:fe7f:c299]:1080:user:pass
    120 127  func (pe *ProxyEngine) LoadSingleProxy(sock string) (ok bool) {
    121 128   if sock, ok = pe.filter(sock); !ok {
    122 129   return
    skipped 13 lines
    136 143   }
    137 144  }
    138 145   
    139  -// LoadMultiLineString loads a multiine string object with one (host:port) SOCKS proxy per line.
     146 +// LoadMultiLineString loads a multiine string object with proxy per line.
     147 +// Expects one of the following formats for each line:
     148 +// * 127.0.0.1:1080
     149 +// * 127.0.0.1:1080:user:pass
     150 +// * yeet.com:1080
     151 +// * yeet.com:1080:user:pass
     152 +// * [fe80::2ef0:5dff:fe7f:c299]:1080
     153 +// * [fe80::2ef0:5dff:fe7f:c299]:1080:user:pass
    140 154  func (pe *ProxyEngine) LoadMultiLineString(socks string) int {
    141 155   var count int
    142 156   scan := bufio.NewScanner(strings.NewReader(socks))
    skipped 14 lines
  • ■ ■ ■ ■ ■ ■
    mystery_dialer.go
    skipped 31 lines
    32 32  // DialTimeout is a simple stub adapter to implement a net.Dialer with a timeout.
    33 33  func (pe *ProxyEngine) DialTimeout(network, addr string, timeout time.Duration) (net.Conn, error) {
    34 34   ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(timeout))
    35  - go func() {
     35 + go func() { // this is a goroutine that calls cancel() upon the deadline expiring to avoid context leaks
     36 + <-ctx.Done()
     37 + cancel()
     38 + }()
     39 + return pe.MysteryDialer(ctx, network, addr)
     40 +}
     41 + 
     42 +func (pe *ProxyEngine) addTimeout(socksString string) string {
     43 + tout := copABuffer.Get().(*strings.Builder)
     44 + tout.WriteString(socksString)
     45 + tout.WriteString("?timeout=")
     46 + tout.WriteString(pe.GetServerTimeoutStr())
     47 + tout.WriteRune('s')
     48 + socksString = tout.String()
     49 + discardBuffer(tout)
     50 + return socksString
     51 +}
     52 + 
     53 +func (pe *ProxyEngine) popSockAndLockIt(ctx context.Context) (*Proxy, error) {
     54 + sock := pe.GetAnySOCKS(false)
     55 + socksString := sock.String()
     56 + select {
     57 + case <-ctx.Done():
     58 + return nil, fmt.Errorf("context done: %w", ctx.Err())
     59 + default:
     60 + if atomic.CompareAndSwapUint32(&sock.lock, stateUnlocked, stateLocked) {
     61 + pe.msgGotLock(socksString)
     62 + return sock, nil
     63 + }
    36 64   select {
    37  - case <-ctx.Done():
    38  - cancel()
     65 + case pe.Pending <- sock:
     66 + pe.msgCantGetLock(socksString, true)
     67 + return nil, nil
     68 + default:
     69 + pe.msgCantGetLock(socksString, false)
     70 + return nil, nil
    39 71   }
    40  - }()
    41  - return pe.MysteryDialer(ctx, network, addr)
     72 + }
    42 73  }
    43 74   
    44 75  // MysteryDialer is a dialer function that will use a different proxy for every request.
    skipped 10 lines
    55 86   return nil, fmt.Errorf("giving up after %d tries", max)
    56 87   }
    57 88   if err := ctx.Err(); err != nil {
    58  - return nil, fmt.Errorf("context error: %v", err)
     89 + return nil, fmt.Errorf("context error: %w", err)
    59 90   }
    60 91   var sock *Proxy
    61  - popSockAndLockIt:
    62 92   for {
    63  - sock = pe.GetAnySOCKS(false)
    64  - socksString = sock.String()
    65  - select {
    66  - case <-ctx.Done():
    67  - return nil, fmt.Errorf("context done: %v", ctx.Err())
    68  - default:
    69  - buf := copABuffer.Get().(*strings.Builder)
    70  - if atomic.CompareAndSwapUint32(&sock.lock, stateUnlocked, stateLocked) {
    71  - buf.WriteString("got lock for ")
    72  - buf.WriteString(socksString)
    73  - break popSockAndLockIt
    74  - }
    75  - select {
    76  - case pe.Pending <- sock:
    77  - buf.WriteString("can't get lock, putting back ")
    78  - buf.WriteString(socksString)
    79  - pe.dbgPrint(buf)
    80  - continue
    81  - default:
    82  - buf.WriteString("can't get lock, can't put back ")
    83  - buf.WriteString(socksString)
    84  - continue
    85  - }
     93 + var err error
     94 + sock, err = pe.popSockAndLockIt(ctx)
     95 + if err != nil {
     96 + return nil, err
     97 + }
     98 + if sock != nil {
     99 + break
    86 100   }
    87 101   }
    88  - buf := copABuffer.Get().(*strings.Builder)
    89  - buf.WriteString("try dial with: ")
    90  - buf.WriteString(sock.Endpoint)
    91  - pe.dbgPrint(buf)
    92 102   if pe.GetServerTimeoutStr() != "-1" {
    93  - tout := copABuffer.Get().(*strings.Builder)
    94  - tout.WriteString("?timeout=")
    95  - tout.WriteString(pe.GetServerTimeoutStr())
    96  - tout.WriteRune('s')
     103 + socksString = pe.addTimeout(socksString)
    97 104   }
    98 105   var ok bool
    99 106   if sock, ok = pe.dispenseMiddleware(sock); !ok {
    100  - buf := copABuffer.Get().(*strings.Builder)
    101  - buf.WriteString("failed middleware check, ")
    102  - buf.WriteString(sock.String())
    103  - buf.WriteString(", cycling...")
    104  - pe.dbgPrint(buf)
     107 + pe.msgFailedMiddleware(socksString)
    105 108   continue
    106 109   }
     110 + pe.msgTry(socksString)
    107 111   atomic.StoreUint32(&sock.lock, stateUnlocked)
    108 112   dialSocks := socks.Dial(socksString)
    109 113   conn, err := dialSocks(network, addr)
    110 114   if err != nil {
    111 115   count++
    112  - buf := copABuffer.Get().(*strings.Builder)
    113  - buf.WriteString("unable to reach [redacted] with ")
    114  - buf.WriteString(socksString)
    115  - buf.WriteString(", cycling...")
    116  - pe.dbgPrint(buf)
     116 + pe.msgUnableToReach(socksString)
    117 117   continue
    118 118   }
    119  - buf = copABuffer.Get().(*strings.Builder)
    120  - buf.WriteString("MysteryDialer using socks: ")
    121  - buf.WriteString(socksString)
    122  - pe.dbgPrint(buf)
     119 + pe.msgUsingProxy(socksString)
    123 120   return conn, nil
    124 121   }
    125 122  }
    skipped 1 lines
  • ■ ■ ■ ■ ■
    socks5_server.go
    skipped 1 lines
    2 2   
    3 3  import (
    4 4   "fmt"
     5 + "strings"
     6 + 
    5 7   "git.tcp.direct/kayos/go-socks5"
    6  - "strings"
    7 8  )
    8 9   
    9 10  type socksLogger struct {
    skipped 48 lines
  • ■ ■ ■ ■ ■ ■
    validator_engine.go
    skipped 25 lines
    26 26   headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
    27 27   headers["Accept-Language"] = "en-US,en;q=0.5"
    28 28   headers["'Accept-Encoding'"] = "gzip, deflate, br"
    29  - headers["Connection"] = "keep-alive"
     29 + // headers["Connection"] = "keep-alive"
    30 30   for header, value := range headers {
    31 31   req.Header.Set(header, value)
    32 32   }
    33 33   var client = &http.Client{}
    34 34   var transporter = &http.Transport{
    35 35   DisableKeepAlives: true,
    36  - TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
     36 + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //nolint:gosec
    37 37   TLSHandshakeTimeout: pe.swampopt.validationTimeout,
    38 38   }
    39 39   
    skipped 26 lines
    66 66   }
    67 67   
    68 68   if sock.proto != ProtoHTTP {
    69  - transport.Dial = dialSocks
     69 + transport.Dial = dialSocks //nolint:staticcheck
    70 70   client.Transport = transport
    71 71   return
    72 72   }
    skipped 75 lines
    148 148   atomic.StoreUint32(&sock.lock, stateLocked)
    149 149   defer atomic.StoreUint32(&sock.lock, stateUnlocked)
    150 150   
    151  - s := sock.parent
    152  - if s.useProx.Check(sock) {
     151 + pe := sock.parent
     152 + if pe.useProx.Check(sock) {
    153 153   // s.dbgPrint("useProx ratelimited: " + sock.Endpoint )
    154 154   return
    155 155   }
    156 156   
    157 157   // determined as bad, won't try again until it expires from that cache
    158  - if s.badProx.Peek(sock) {
    159  - buf := copABuffer.Get().(*strings.Builder)
    160  - buf.WriteString("badProx ratelimited: ")
    161  - buf.WriteString(sock.Endpoint)
    162  - s.dbgPrint(buf)
     158 + if pe.badProx.Peek(sock) {
     159 + pe.msgBadProxRate(sock)
    163 160   return
    164 161   }
    165 162   
    skipped 2 lines
    168 165   // try to use the proxy with all 3 SOCKS versions
    169 166   for proto := range protoMap {
    170 167   select {
    171  - case <-s.ctx.Done():
     168 + case <-pe.ctx.Done():
    172 169   return
    173 170   default:
    174 171   sock.proto = proto
    175  - if err := s.singleProxyCheck(sock); err != nil {
     172 + if err := pe.singleProxyCheck(sock); err != nil {
    176 173   // if the proxy is no good, we continue on to the next.
    177 174   continue
    178 175   }
    skipped 3 lines
    182 179   
    183 180   switch sock.proto {
    184 181   case ProtoSOCKS4, ProtoSOCKS4a, ProtoSOCKS5, ProtoHTTP:
    185  - buf := copABuffer.Get().(*strings.Builder)
    186  - buf.WriteString("verified ")
    187  - buf.WriteString(sock.Endpoint)
    188  - buf.WriteString(" as SOCKS")
    189  - buf.WriteString(getProtoStr(sock.proto))
    190  - s.dbgPrint(buf)
    191  - break
     182 + pe.msgChecked(sock, true)
    192 183   default:
    193  - buf := copABuffer.Get().(*strings.Builder)
    194  - buf.WriteString("failed to verify: ")
    195  - buf.WriteString(sock.Endpoint)
    196  - s.dbgPrint(buf)
     184 + pe.msgChecked(sock, false)
    197 185   sock.bad()
    198  - s.badProx.Check(sock)
     186 + pe.badProx.Check(sock)
    199 187   return
    200 188   }
    201 189   
    202 190   sock.good()
    203  - s.tally(sock)
     191 + pe.tally(sock)
    204 192  }
    205 193   
    206 194  func (pe *ProxyEngine) tally(sock *Proxy) {
    skipped 18 lines
Please wait...
Page is in error, reload to recover