2022-05-23 01:05:50 +00:00
|
|
|
package prox5
|
2021-09-13 09:37:59 +00:00
|
|
|
|
2021-09-13 17:55:51 +00:00
|
|
|
import (
|
2022-12-27 12:59:23 +00:00
|
|
|
"sync/atomic"
|
2021-09-13 17:55:51 +00:00
|
|
|
"time"
|
|
|
|
)
|
2021-09-13 09:37:59 +00:00
|
|
|
|
2022-10-16 10:53:04 +00:00
|
|
|
// Statistics is used to encapsulate various proxy engine stats
|
2022-10-16 07:38:49 +00:00
|
|
|
type Statistics struct {
|
2021-09-13 11:26:18 +00:00
|
|
|
// Valid4 is the amount of SOCKS4 proxies validated
|
2023-12-05 21:52:32 +00:00
|
|
|
Valid4 *atomic.Int64
|
2021-09-13 11:26:18 +00:00
|
|
|
// Valid4a is the amount of SOCKS4a proxies validated
|
2023-12-05 21:52:32 +00:00
|
|
|
Valid4a *atomic.Int64
|
2021-09-13 11:26:18 +00:00
|
|
|
// Valid5 is the amount of SOCKS5 proxies validated
|
2023-12-05 21:52:32 +00:00
|
|
|
Valid5 *atomic.Int64
|
2021-09-23 16:06:49 +00:00
|
|
|
// ValidHTTP is the amount of HTTP proxies validated
|
2023-12-05 21:52:32 +00:00
|
|
|
ValidHTTP *atomic.Int64
|
2021-09-13 11:26:18 +00:00
|
|
|
// Dispensed is a simple ticker to keep track of proxies dispensed via our getters
|
2023-12-05 21:52:32 +00:00
|
|
|
Dispensed *atomic.Int64
|
2021-09-18 04:54:42 +00:00
|
|
|
// Stale is the amount of proxies that failed our stale policy upon dispensing
|
2023-12-05 21:52:32 +00:00
|
|
|
Stale *atomic.Int64
|
2021-09-23 07:38:00 +00:00
|
|
|
// Checked is the amount of proxies we've checked.
|
2023-12-05 21:52:32 +00:00
|
|
|
Checked *atomic.Int64
|
2021-09-14 02:47:16 +00:00
|
|
|
// birthday represents the time we started checking proxies with this pool
|
2023-12-05 21:52:32 +00:00
|
|
|
birthday *atomic.Pointer[time.Time]
|
2022-12-27 15:25:10 +00:00
|
|
|
|
2023-12-05 21:52:32 +00:00
|
|
|
badAccounted *atomic.Int64
|
|
|
|
accountingLastDone *atomic.Pointer[time.Time]
|
2021-09-13 09:37:59 +00:00
|
|
|
}
|
|
|
|
|
2022-10-16 07:38:49 +00:00
|
|
|
func (stats *Statistics) dispense() {
|
2023-12-05 21:52:32 +00:00
|
|
|
stats.Dispensed.Add(1)
|
2021-09-13 11:26:18 +00:00
|
|
|
}
|
|
|
|
|
2022-10-16 07:38:49 +00:00
|
|
|
func (stats *Statistics) stale() {
|
2023-12-05 21:52:32 +00:00
|
|
|
stats.Stale.Add(1)
|
2021-09-18 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
2022-10-16 07:38:49 +00:00
|
|
|
func (stats *Statistics) v4() {
|
2023-12-05 21:52:32 +00:00
|
|
|
stats.Valid4.Add(1)
|
2021-09-13 09:37:59 +00:00
|
|
|
}
|
|
|
|
|
2022-10-16 07:38:49 +00:00
|
|
|
func (stats *Statistics) v4a() {
|
2023-12-05 21:52:32 +00:00
|
|
|
stats.Valid4a.Add(1)
|
2021-09-13 09:37:59 +00:00
|
|
|
}
|
|
|
|
|
2022-10-16 07:38:49 +00:00
|
|
|
func (stats *Statistics) v5() {
|
2023-12-05 21:52:32 +00:00
|
|
|
stats.Valid5.Add(1)
|
2021-09-13 09:37:59 +00:00
|
|
|
}
|
2021-09-13 17:55:51 +00:00
|
|
|
|
2022-10-16 07:38:49 +00:00
|
|
|
func (stats *Statistics) http() {
|
2023-12-05 21:52:32 +00:00
|
|
|
stats.ValidHTTP.Add(1)
|
2021-09-23 16:06:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-25 08:21:41 +00:00
|
|
|
// GetTotalValidated retrieves our grand total validated proxy count.
|
2023-12-05 21:52:32 +00:00
|
|
|
func (p5 *ProxyEngine) GetTotalValidated() int64 {
|
2022-09-22 23:48:08 +00:00
|
|
|
stats := p5.GetStatistics()
|
2023-09-07 07:05:19 +00:00
|
|
|
|
|
|
|
total := int64(0)
|
2023-12-05 21:52:32 +00:00
|
|
|
for _, val := range []*atomic.Int64{stats.Valid4a, stats.Valid4, stats.Valid5, stats.ValidHTTP} {
|
|
|
|
total += val.Load()
|
2023-09-07 07:05:19 +00:00
|
|
|
}
|
2023-12-05 21:52:32 +00:00
|
|
|
return total
|
2022-12-27 12:59:23 +00:00
|
|
|
}
|
|
|
|
|
2022-12-27 15:25:10 +00:00
|
|
|
func (p5 *ProxyEngine) GetTotalBad() int64 {
|
2023-01-01 00:40:32 +00:00
|
|
|
p5.badProx.Patrons.DeleteExpired()
|
2022-12-27 15:25:10 +00:00
|
|
|
return int64(p5.badProx.Patrons.ItemCount())
|
2021-11-25 08:21:41 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 17:55:51 +00:00
|
|
|
// GetUptime returns the total lifetime duration of our pool.
|
2022-10-16 07:38:49 +00:00
|
|
|
func (stats *Statistics) GetUptime() time.Duration {
|
2023-12-05 21:52:32 +00:00
|
|
|
return time.Since(*stats.birthday.Load())
|
2021-09-13 17:55:51 +00:00
|
|
|
}
|