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
|
2022-05-23 01:20:40 +00:00
|
|
|
Valid4 int64
|
2021-09-13 11:26:18 +00:00
|
|
|
// Valid4a is the amount of SOCKS4a proxies validated
|
2022-05-23 01:20:40 +00:00
|
|
|
Valid4a int64
|
2021-09-13 11:26:18 +00:00
|
|
|
// Valid5 is the amount of SOCKS5 proxies validated
|
2022-05-23 01:20:40 +00:00
|
|
|
Valid5 int64
|
2021-09-23 16:06:49 +00:00
|
|
|
// ValidHTTP is the amount of HTTP proxies validated
|
2022-05-23 01:20:40 +00:00
|
|
|
ValidHTTP int64
|
2021-09-13 11:26:18 +00:00
|
|
|
// Dispensed is a simple ticker to keep track of proxies dispensed via our getters
|
2022-05-23 01:20:40 +00:00
|
|
|
Dispensed int64
|
2021-09-18 04:54:42 +00:00
|
|
|
// Stale is the amount of proxies that failed our stale policy upon dispensing
|
2022-05-23 01:20:40 +00:00
|
|
|
Stale int64
|
2021-09-23 07:38:00 +00:00
|
|
|
// Checked is the amount of proxies we've checked.
|
2022-05-23 01:20:40 +00:00
|
|
|
Checked int64
|
2021-09-14 02:47:16 +00:00
|
|
|
// birthday represents the time we started checking proxies with this pool
|
|
|
|
birthday time.Time
|
2022-12-27 15:25:10 +00:00
|
|
|
|
2023-01-31 09:21:29 +00:00
|
|
|
badAccounted int64
|
|
|
|
accountingLastDone time.Time
|
2021-09-13 09:37:59 +00:00
|
|
|
}
|
|
|
|
|
2022-10-16 07:38:49 +00:00
|
|
|
func (stats *Statistics) dispense() {
|
2022-12-27 12:59:23 +00:00
|
|
|
atomic.AddInt64(&stats.Dispensed, 1)
|
2021-09-13 11:26:18 +00:00
|
|
|
}
|
|
|
|
|
2022-10-16 07:38:49 +00:00
|
|
|
func (stats *Statistics) stale() {
|
2022-12-27 12:59:23 +00:00
|
|
|
atomic.AddInt64(&stats.Stale, 1)
|
2021-09-18 04:54:42 +00:00
|
|
|
}
|
|
|
|
|
2022-10-16 07:38:49 +00:00
|
|
|
func (stats *Statistics) v4() {
|
2022-12-27 12:59:23 +00:00
|
|
|
atomic.AddInt64(&stats.Valid4, 1)
|
2021-09-13 09:37:59 +00:00
|
|
|
}
|
|
|
|
|
2022-10-16 07:38:49 +00:00
|
|
|
func (stats *Statistics) v4a() {
|
2022-12-27 12:59:23 +00:00
|
|
|
atomic.AddInt64(&stats.Valid4a, 1)
|
2021-09-13 09:37:59 +00:00
|
|
|
}
|
|
|
|
|
2022-10-16 07:38:49 +00:00
|
|
|
func (stats *Statistics) v5() {
|
2022-12-27 12:59:23 +00:00
|
|
|
atomic.AddInt64(&stats.Valid5, 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() {
|
2022-12-27 12:59:23 +00:00
|
|
|
atomic.AddInt64(&stats.ValidHTTP, 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.
|
2022-10-16 10:53:04 +00:00
|
|
|
func (p5 *ProxyEngine) GetTotalValidated() int {
|
2022-09-22 23:48:08 +00:00
|
|
|
stats := p5.GetStatistics()
|
2022-12-27 12:59:23 +00:00
|
|
|
return int(atomic.LoadInt64(&stats.Valid4a) + stats.Valid4 + stats.Valid5 + stats.ValidHTTP)
|
|
|
|
}
|
|
|
|
|
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 {
|
2021-09-14 02:47:16 +00:00
|
|
|
return time.Since(stats.birthday)
|
2021-09-13 17:55:51 +00:00
|
|
|
}
|