Commit c92b4682 authored by Matt Traudt's avatar Matt Traudt
Browse files


GH: closes #135
parent f0d7e3a4
......@@ -11,7 +11,6 @@ from ..lib.destination import DestinationList
# from ..util.simpleauth import authenticate_to_server
# from ..util.sockio import (make_socket, close_socket)
from sbws.globals import (fail_hard, is_initted)
from sbws.globals import MIN_REQ_BYTES, MAX_REQ_BYTES
import sbws.util.stem as stem_utils
from stem.control import EventType
from argparse import ArgumentDefaultsHelpFormatter
......@@ -167,7 +166,7 @@ def measure_bandwidth_to_server(session, conf, dest, content_length):
'duration': data, 'amount': expected_amount})
expected_amount = _next_expected_amount(
expected_amount, data, download_times)
expected_amount, data, download_times, min_dl, max_dl)
return results
......@@ -266,7 +265,8 @@ def _should_keep_result(did_request_maximum, result_time, download_times):
return False
def _next_expected_amount(expected_amount, result_time, download_times):
def _next_expected_amount(expected_amount, result_time, download_times,
min_dl, max_dl):
if result_time < download_times['toofast']:
# Way too fast, greatly increase the amount we ask for
expected_amount = int(expected_amount * 5)
......@@ -277,8 +277,8 @@ def _next_expected_amount(expected_amount, result_time, download_times):
expected_amount = int(
expected_amount * download_times['target'] / result_time)
# Make sure we don't request too much or too little
expected_amount = max(MIN_REQ_BYTES, expected_amount)
expected_amount = min(MAX_REQ_BYTES, expected_amount)
expected_amount = max(min_dl, expected_amount)
expected_amount = min(max_dl, expected_amount)
return expected_amount
......@@ -12,20 +12,6 @@ PKG_DIR = os.path.abspath(os.path.dirname(__file__))
SOCKET_TIMEOUT = 60 # seconds
# Minimum and maximum number of bytes a scanner is allowed to request from a
# server. If these are changed, a WIRE_VERSION bump is required, which also
# happens to require an sbws major version bump.
# Note for smart people and people who pull out Wireshark: Even if the scanner
# requests 1 byte, that request and the 1 byte response will each be carried
# over the Internet in 514 byte Tor cells. Theoretically we could bump the
# minimum request size up to ~498 bytes, but I see no reason why we should.
# Trying to hit the maximum cell size just makes sbws server send more, us read
# more, and it runs the risk of standards changing underneath us and sbws
# suddenly creating more than one cell.
MAX_REQ_BYTES = 1 * 1024 * 1024 * 1024 # 1 GiB
# This is a dictionary of torrc options we always want to set when launching
# Tor and that do not depend on any runtime configuration
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment