Merge branch 'merge1' into 'master'

Merge1

See merge request mserneels/ppf!7
This commit is contained in:
mserneels
2019-01-06 22:45:50 +00:00
3 changed files with 30 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ threads = 10
timeout = 15
submit_after = 200
use_ssl = false
debug = false
[proxyfind]
search = true

View File

@@ -20,6 +20,8 @@ def load():
timeout = parser.getint('watcherd', 'timeout')
submit_after = parser.getint('watcherd', 'submit_after')
use_ssl = parser.getboolean('watcherd', 'use_ssl')
global watchd_debug
watchd_debug = parser.getboolean('watcherd', 'debug')
# allow overriding select items from the commandline
import argparse

View File

@@ -42,6 +42,9 @@ class WorkerJob():
sock.send('%s\n' % random.choice(['NICK', 'USER', 'JOIN', 'MODE', 'PART', 'INVITE', 'KNOCK', 'WHOIS', 'WHO', 'NOTICE', 'PRIVMSG', 'PING', 'QUIT']))
return sock, proto, duration, torhost, srv, 0
except rocksock.RocksockException as e:
if config.watchd_debug:
_log("proxy failed: %s://%s: %s"%(proto, self.proxy, e.get_errormessage()), 'debug')
et = e.get_errortype()
err = e.get_error()
fp = e.get_failedproxy()
@@ -85,7 +88,9 @@ class WorkerJob():
self.failcount = 0
self.success_count = self.success_count + 1
self.total_duration += int(duration*1000)
_log('%s://%s; c: %s; d: %.2f sec(s); tor: %s; srv: %s; recv: %s' % (proto, self.proxy, match, duration, tor, srv, recv), 'xxxxx')
cstats = "" if match == 'unknown' else ' c: %s;'%match
torstats = "" if len(config.torhosts)==1 else ' tor: %s;'%tor
_log('%s://%s;%s d: %.2f sec(s);%s; srv: %s; recv: %s' % (proto, self.proxy, cstats, duration, torstats, srv, recv), 'xxxxx')
except KeyboardInterrupt as e:
raise e
except:
@@ -117,18 +122,37 @@ class WorkerThread():
self.thread = threading.Thread(target=self.workloop)
self.thread.start()
def workloop(self):
def try_div(a, b):
if b != 0: return a/float(b)
return 0
success_count = 0
job_count = 0
duration_total = 0
duration_success_total = 0
while True:
if len(self.workqueue):
job = self.workqueue.pop()
nao = time.time()
job.run()
spent = time.time() - nao
if job.failcount == 0:
duration_success_total += spent
success_count += 1
job_count += 1
duration_total += spent
self.workdone.append(job)
elif not self.thread:
break
if self.done.is_set(): break
time.sleep(0.01)
if self.thread:
sys.stdout.write('%s/%s\tthread terminated\r' % (time.strftime('%H:%M:%S', time.gmtime()), self.id))
sys.stdout.flush()
succ_rate = try_div(success_count, job_count)*100
avg_succ_t = try_div(duration_success_total, success_count)
avg_fail_t = try_div(duration_total-duration_success_total, job_count-success_count)
avg_t = try_div(duration_total, job_count)
_log("terminated, %d/%d (%.2f%%), avg.time S/F/T %.2f, %.2f, %.2f" \
% (success_count, job_count, succ_rate, avg_succ_t, avg_fail_t, avg_t) \
, self.id)
class Proxywatchd():