| skipped 159 lines |
160 | 160 | | var protoMap = map[ProxyProtocol]string{ |
161 | 161 | | ProtoSOCKS4: "4", ProtoSOCKS4a: "4a", |
162 | 162 | | ProtoSOCKS5: "5", ProtoHTTP: "http", |
163 | | - | ProtoSOCKS5h: "5h", |
| 163 | + | ProtoSOCKS5h: "5h", protoNULL: "null", |
164 | 164 | | } |
165 | 165 | | |
166 | 166 | | func getProtoStr(protocol ProxyProtocol) string { |
| skipped 4 lines |
171 | 171 | | } |
172 | 172 | | |
173 | 173 | | func (sock *Proxy) validate() { |
174 | | - | atomic.StoreUint32(&sock.lock, stateLocked) |
| 174 | + | if !atomic.CompareAndSwapUint32(&sock.lock, stateUnlocked, stateLocked) { |
| 175 | + | return |
| 176 | + | } |
175 | 177 | | defer atomic.StoreUint32(&sock.lock, stateUnlocked) |
176 | 178 | | |
177 | 179 | | pe := sock.parent |
| skipped 10 lines |
188 | 190 | | |
189 | 191 | | // TODO: consider giving the option for verbose logging of this stuff? |
190 | 192 | | |
191 | | - | // try to use the proxy with all 3 SOCKS versions |
192 | | - | for proto := range protoMap { |
193 | | - | select { |
194 | | - | case <-pe.ctx.Done(): |
195 | | - | return |
196 | | - | default: |
197 | | - | sock.proto = proto |
198 | | - | if err := pe.singleProxyCheck(sock); err != nil { |
199 | | - | // if the proxy is no good, we continue on to the next. |
200 | | - | continue |
| 193 | + | if sock.timesValidated == 0 || sock.proto == protoNULL { |
| 194 | + | // try to use the proxy with all 3 SOCKS versions |
| 195 | + | for proto := range protoMap { |
| 196 | + | select { |
| 197 | + | case <-pe.ctx.Done(): |
| 198 | + | return |
| 199 | + | default: |
| 200 | + | sock.proto = proto |
| 201 | + | if err := pe.singleProxyCheck(sock); err != nil { |
| 202 | + | // if the proxy is no good, we continue on to the next. |
| 203 | + | continue |
| 204 | + | } |
| 205 | + | break |
201 | 206 | | } |
202 | | - | break |
| 207 | + | } |
| 208 | + | } else { |
| 209 | + | if err := pe.singleProxyCheck(sock); err != nil { |
| 210 | + | sock.bad() |
| 211 | + | pe.badProx.Check(sock) |
| 212 | + | return |
203 | 213 | | } |
204 | 214 | | } |
205 | 215 | | |
| skipped 33 lines |