Exemple #1
0
func (w *Worker) Work() {
	w.Running = true
	w.stoppedChan = make(chan struct{})
	time.AfterFunc(1*time.Minute, func() {
		w.Timeout()
	})

	go func() {
		checker := 0
		for w.Running {
			if checker%20 == 0 {
				if w.IPList.IsAlmostBlacklisted() {
					w.IPList = ip.NextIPList()
				}

				if w.IsUsersAlmostBlackListed() {
					w.Users = user.GetDummyUsers(100)
				}
			}

			ip := w.IPList.Next()
			user := w.Users[rand.Intn(len(w.Users))]
			for user.InUse() {
				user = w.Users[rand.Intn(len(w.Users))]
			}

			user.Start()
			w.Login(ip, user)

			if !w.Running {
				user.FlagIncomplete()
				ip.FlagIncomplete()
			}

			user.Finish()

			checker++
		}

		w.stoppedChan <- struct{}{}
	}()
}
Exemple #2
0
func New() *Worker {
	latestWorkerID++

	w := &Worker{
		ID:              latestWorkerID,
		TimeoutDuration: DefaultTimeoutDuration,

		IPList: ip.NextIPList(),
		Users:  user.GetDummyUsers(100),

		Debug:    false,
		Running:  false,
		FastFail: true,

		logger: log.New(os.Stdout, "", 0),
	}
	w.logger.SetFlags(log.Ltime)

	jar, _ := cookiejar.New(&cookiejar.Options{})
	w.Transport = &http.Transport{}
	w.Client = &http.Client{
		Transport: w.Transport,
		Jar:       jar,
		CheckRedirect: func(req *http.Request, via []*http.Request) error {
			if len(via) >= 10 {
				return errors.New("stopped after 10 redirects")
			}

			req.Header.Set("User-Agent", via[0].Header.Get("User-Agent"))
			req.Header.Set("X-Forwarded-For", via[0].Header.Get("X-Forwarded-For"))

			return nil
		},
	}

	return w
}