Skip to content

Commit

Permalink
MAX_FAILURE_RATIO in /etc/sdwdate.d/30_default.conf
Browse files Browse the repository at this point in the history
  • Loading branch information
troubadoour committed Oct 23, 2015
1 parent d442166 commit 8c028f1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
10 changes: 8 additions & 2 deletions etc/sdwdate.d/30_default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
## Copyright (C) 2012 - 2014 Patrick Schleizer <adrelanos@riseup.net>
## See the file COPYING for copying conditions.

## Please use "/etc/sdwdate.d/50_user" for your custom
## Please use "/etc/sdwdate.d/50_user.conf" for your custom
## configuration, which will override the defaults found here.
## When sdwdate is updated, this file may be overwritten.

## Proxy settings for non anonymous distributions.
## Uncomment for standard tor configuration (no stream isolation).
#PROXY_IP=127.0.0.1
#PROXY_PORT=9050
#PROXY_PORT=9053

## Allowed percentage of url failures common to every pool.
## If sdwdate frequently stops with "Maximum allowed number of failures" error,
## create a file "/etc/sdwdate.d/50_user.conf" overriding MAX_FAILURE_RATIO
## with a higher figure.
MAX_FAILURE_RATIO=0.34

## pool syntax
## "url.onion[:port]#comment"
Expand Down
23 changes: 20 additions & 3 deletions usr/bin/sdwdate
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import sys
import logging
import signal
import os
import glob
import time
from datetime import datetime
import random
Expand Down Expand Up @@ -39,22 +40,38 @@ class Pool:
self.url, self.comment = read_pools(pool, 'production')
self.url_random = []
self.already_picked_index = []
allowed_failure_ratio = 0.34
self.invalid_urls = 0
self.allowed_failures = int(len(self.url) * allowed_failure_ratio)
self.done = False

@property
def url_range(self):
return len(self.url)

@property
def allowed_failures(self):
if os.path.exists('/etc/sdwdate.d/'):
files = sorted(glob.glob('/etc/sdwdate.d/*'))
for f in files:
with open(f) as conf:
lines = conf.readlines()
for line in lines:
if line.startswith('MAX_FAILURE_RATIO'):
failure_ratio = re.search(r'=(.*)', line).group(1)
return int(len(self.url) * float(failure_ratio))
else:
return int(len(self.url) * 0.34)
return int(len(self.url) * 0.34)



class Sdwdate:
def __init__(self):
self.iteration = 0
self.number_of_pools = 3

self.pools = [Pool(pool) for pool in range(self.number_of_pools)]
## Could get it here to prevent reading the file in sdwdate_loop for each Unreachable url.
#self.allowed_failures = [Pool(pool).allowed_failures for pool in range(self.number_of_pools)]
self.urls = []
self.url_random = []
self.valid_urls = []
Expand Down Expand Up @@ -548,7 +565,7 @@ if __name__ == "__main__":

f = open(sdwdate.success_path, 'w')
f.close()
sleep_time = 0.2 #randint(60, 180)
sleep_time = randint(60, 180)
log_level = 'info'

elif status == 'error':
Expand Down
4 changes: 2 additions & 2 deletions usr/share/translations/sdwdate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ sdwdate:
general_proxy_error: '<b>General Proxy Error.</b> Is Tor running?'
general_timeout_error: '<b>General Timeout Error.</b> Internet connection might be down'

max_pool_failures_1: '<b>Maximum number of allowed failures</b> reached in pool '
max_pool_failures_1: '<b>Maximum allowed number of failures</b> reached in pool '
max_pool_failures_2: '. Giving up.<br> If the problem occurs too frequently, please report it.<br>
You may increase MAX_FAILURE_RATIO in /etc/sdwdate.d/30_default.conf.'
You may increase MAX_FAILURE_RATIO (see /etc/sdwdate.d/30_default.conf).'

0 comments on commit 8c028f1

Please sign in to comment.