2022-05-23 01:05:50 +00:00
|
|
|
package prox5
|
2021-09-12 02:59:05 +00:00
|
|
|
|
2022-05-30 10:42:18 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
)
|
2021-09-18 03:47:11 +00:00
|
|
|
|
2021-09-23 07:38:00 +00:00
|
|
|
// SwampStatus represents the current state of our Swamp.
|
|
|
|
type SwampStatus uint32
|
|
|
|
|
|
|
|
const (
|
|
|
|
// Running means the proxy pool is currently taking in proxys and validating them, and is available to dispense proxies.
|
|
|
|
Running SwampStatus = iota
|
|
|
|
// Paused means the proxy pool has been with Swamp.Pause() and may be resumed with Swamp.Resume()
|
|
|
|
Paused
|
|
|
|
// New means the proxy pool has never been started.
|
|
|
|
New
|
|
|
|
)
|
|
|
|
|
2021-09-21 12:24:30 +00:00
|
|
|
// Start starts our proxy pool operations. Trying to start a running Swamp will return an error.
|
2021-09-18 03:47:11 +00:00
|
|
|
func (s *Swamp) Start() error {
|
2021-10-23 17:25:28 +00:00
|
|
|
if s.Status.Load().(SwampStatus) != New {
|
2022-05-30 10:42:18 +00:00
|
|
|
return s.Resume()
|
2021-09-18 03:47:11 +00:00
|
|
|
}
|
2022-05-30 10:42:18 +00:00
|
|
|
s.startDaemons()
|
2021-09-20 01:23:18 +00:00
|
|
|
return nil
|
2021-09-14 07:35:04 +00:00
|
|
|
}
|
2021-09-15 05:09:43 +00:00
|
|
|
|
2021-09-13 19:18:18 +00:00
|
|
|
/*
|
|
|
|
Pause will cease the creation of any new proxy validation operations.
|
|
|
|
* You will be able to start the proxy pool again with Swamp.Resume(), it will have the same Statistics, options, and ratelimits.
|
|
|
|
* During pause you are still able to dispense proxies.
|
|
|
|
* Options may be changed and proxy lists may be loaded when paused.
|
|
|
|
* Pausing an already paused Swamp is a nonop.
|
|
|
|
*/
|
2021-09-20 12:29:28 +00:00
|
|
|
func (s *Swamp) Pause() error {
|
2021-10-23 17:25:28 +00:00
|
|
|
if !s.IsRunning() {
|
|
|
|
return errors.New("not running")
|
2021-09-13 19:16:26 +00:00
|
|
|
}
|
2021-10-23 14:26:23 +00:00
|
|
|
|
|
|
|
s.dbgPrint("pausing...")
|
|
|
|
|
2022-05-30 10:42:18 +00:00
|
|
|
s.quit()
|
2021-09-23 07:38:00 +00:00
|
|
|
|
2021-10-23 17:25:28 +00:00
|
|
|
s.Status.Store(Paused)
|
2021-09-20 12:29:28 +00:00
|
|
|
return nil
|
2021-09-13 19:08:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-30 10:42:18 +00:00
|
|
|
func (s *Swamp) startDaemons() {
|
2021-10-23 17:25:28 +00:00
|
|
|
go s.mapBuilder()
|
|
|
|
<-s.conductor
|
2022-05-30 10:42:18 +00:00
|
|
|
s.svcUp()
|
2021-10-23 17:25:28 +00:00
|
|
|
go s.jobSpawner()
|
|
|
|
|
|
|
|
for {
|
|
|
|
if s.IsRunning() {
|
|
|
|
s.Status.Store(Running)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-23 14:26:23 +00:00
|
|
|
// Resume will resume pause proxy pool operations, attempting to resume a running Swamp is returns an error.
|
2021-09-18 03:47:11 +00:00
|
|
|
func (s *Swamp) Resume() error {
|
2021-10-23 17:25:28 +00:00
|
|
|
if s.IsRunning() {
|
2022-05-30 10:42:18 +00:00
|
|
|
return errors.New("already running")
|
2021-09-13 19:16:26 +00:00
|
|
|
}
|
2022-05-30 10:42:18 +00:00
|
|
|
s.ctx, s.quit = context.WithCancel(context.Background())
|
|
|
|
s.startDaemons()
|
2021-09-18 03:47:11 +00:00
|
|
|
return nil
|
2021-09-13 19:08:41 +00:00
|
|
|
}
|