Ejemplo n.º 1
0
def test_ResultSuccess(time_mock):
    t = 2000
    time_mock.side_effect = monotonic_time(start=t)
    fp1 = 'A' * 40
    fp2 = 'Z' * 40
    circ = [fp1, fp2]
    dest_url = 'http://example.com/sbws.bin'
    scanner_nick = 'sbwsscanner'
    nick = 'Mooooooo'
    relay_ip = '169.254.100.1'
    relay = Result.Relay(fp1, nick, relay_ip)
    rtts = [5, 25]
    downloads = [{'duration': 4, 'amount': 40}]
    r1 = ResultSuccess(rtts, downloads, relay, circ, dest_url, scanner_nick)
    r2 = ResultSuccess(rtts,
                       downloads,
                       relay,
                       circ,
                       dest_url,
                       scanner_nick,
                       t=t)
    assert r1.downloads == downloads
    assert r1.rtts == rtts
    assert r1.nickname == nick
    assert r1.time == t
    assert r1.fingerprint == fp1
    assert r1.scanner == scanner_nick
    assert r1.type == _ResultType.Success
    assert r1.address == relay_ip
    assert r1.circ == circ
    assert r1.dest_url == dest_url
    assert r1.version == RESULT_VERSION
    assert str(r1) == str(r2)
Ejemplo n.º 2
0
def test_ResultSuccess_from_dict(time_mock):
    t = 2000
    time_mock.side_effect = monotonic_time(start=t)
    fp1 = 'A' * 40
    fp2 = 'Z' * 40
    circ = [fp1, fp2]
    dest_url = 'http://example.com/sbws.bin'
    scanner_nick = 'sbwsscanner'
    nick = 'Mooooooo'
    relay_ip = '169.254.100.1'
    relay = Result.Relay(fp1, nick, relay_ip)
    rtts = [5, 25]
    downloads = [{'duration': 4, 'amount': 40}]
    r1 = ResultSuccess(rtts, downloads, relay, circ, dest_url, scanner_nick)
    d = {
        'rtts': rtts,
        'downloads': downloads,
        'fingerprint': fp1,
        'nickname': nick,
        'address': relay_ip,
        'circ': circ,
        'dest_url': dest_url,
        'scanner': scanner_nick,
        'version': RESULT_VERSION,
        'type': _ResultType.Success,
        'time': t,
    }
    r2 = Result.from_dict(d)
    assert isinstance(r1, ResultSuccess)
    assert isinstance(r2, ResultSuccess)
    assert str(r1) == str(r2)
Ejemplo n.º 3
0
def dotsbws_success_result(empty_dotsbws_datadir):
    '''
    Creates an ~/.sbws with a single fresh ResultSuccess in it
    '''
    fp1 = 'A' * 40
    fp2 = 'B' * 40
    circ = [fp1, fp2]
    nick = 'CowSayWhat'
    relay_ip = '169.254.100.1'
    server_ip = '169.254.100.2'
    scanner_nick = 'SBWSscanner'
    rtts = [4.242]
    downloads = [{'duration': 4, 'amount': 40 * 1024}]
    t = time.time()
    relay = Result.Relay(fp1, nick, relay_ip)
    result = ResultSuccess(rtts,
                           downloads,
                           relay,
                           circ,
                           server_ip,
                           scanner_nick,
                           t=t)
    args = _PseudoArguments(directory=empty_dotsbws_datadir.name)
    conf = get_config(args)
    dd = conf['paths']['datadir']
    write_result_to_datadir(result, dd)
    return empty_dotsbws_datadir
Ejemplo n.º 4
0
def add_two_fresh_results(dname, t):
    r1 = ResultError(Result.Relay('DEADBEEF1111', 'CowSayWhat', '127.0.0.1'),
                     ['DEADBEEF1111', 'BEADDEEF2222'],
                     '127.0.1.1',
                     'SBWSscanner',
                     t=t)
    r2 = ResultSuccess([1, 2, 3], [{
        'amount': 100,
        'duration': 1
    }],
                       Result.Relay('DEADBEEF1111', 'CowSayWhat', '127.0.0.1'),
                       ['DEADBEEF1111', 'BEADDEEF2222'],
                       '127.0.1.1',
                       'SBWSscanner',
                       t=t)
    dd = os.path.join(str(dname), 'datadir')
    os.makedirs(dd)
    write_result_to_datadir(r1, dd)
    write_result_to_datadir(r2, dd)
Ejemplo n.º 5
0
def test_resultdump(rd, args, conf_results, controller, router_status,
                    server_descriptor):
    from sbws import settings
    relay = Relay(
        router_status.fingerprint,
        controller,
        ns=router_status,
        desc=server_descriptor,
    )
    relay.increment_relay_recent_priority_list()
    relay.increment_relay_recent_measurement_attempt()
    r = ResultSuccess(
        [],
        2000,
        relay,
        ["A", "B"],
        "http://localhost/bw",
        "scanner_nick",
    )
    # Storing the result with `rd.queue.put` will not store the result to disk
    # because the thread is not spawned with pytest.
    rd.store_result(r)
    results = rd.results_for_relay(relay)
    # It has stored the result
    assert 1 == len(results)
    # The result has the correct attribute
    assert 1 == len(results[0].relay_recent_priority_list)
    # Store a second result for the sme relay
    r = ResultError(
        relay,
        ["A", "B"],
        "http://localhost/bw",
        "scanner_nick",
    )
    rd.store_result(r)
    assert 2 == len(results)
    assert 1 == len(results[1].relay_recent_priority_list)
    settings.set_end_event()
Ejemplo n.º 6
0
def _build_result_for_relay(conf, rl, result_type, relay_nick,
                            timestamp):
    relay = [r for r in rl.relays if r.nickname == relay_nick]
    assert len(relay) == 1
    relay = relay[0]
    other = [r for r in rl.relays if r.nickname != relay_nick][0]
    circ = [relay.fingerprint, other.fingerprint]
    rtts = [0.5, 0.5, 0.5]
    dls = [
        {'amount': 1024, 'duration': 1},
        {'amount': 1024, 'duration': 1},
        {'amount': 1024, 'duration': 1},
    ]
    if result_type == ResultSuccess:
        return ResultSuccess(rtts, dls, relay, circ,
                             conf['destinations.foo']['url'],
                             'test', t=timestamp)

    elif result_type == ResultErrorCircuit:
        return ResultErrorCircuit(relay, circ,
                                  conf['destinations.foo']['url'],
                                  'test', msg='Test error circ message',
                                  t=timestamp)
Ejemplo n.º 7
0
                      NICK1,
                      IP1,
                      ED25519,
                      average_bandwidth=AVG_BW,
                      burst_bandwidth=BUR_BW,
                      observed_bandwidth=OBS_BW,
                      consensus_bandwidth=BW,
                      consensus_bandwidth_is_unmeasured=UNMEASURED,
                      relay_in_recent_consensus_count=2)
RELAY2 = Result.Relay(FP2, NICK2, IP2, ED25519)

RESULT = Result(RELAY1, CIRC12, DEST_URL, SCANNER, t=TIME1)
RESULT_SUCCESS1 = ResultSuccess(RTTS1,
                                DOWNLOADS1,
                                RELAY1,
                                CIRC12,
                                DEST_URL,
                                SCANNER,
                                t=TIME1)
RESULT_SUCCESS2 = ResultSuccess(RTTS2,
                                DOWNLOADS2,
                                RELAY2,
                                CIRC21,
                                DEST_URL,
                                SCANNER,
                                t=TIME2)
RESULT_ERROR_STREAM = ResultErrorStream(RELAY1,
                                        CIRC12,
                                        DEST_URL,
                                        SCANNER,
                                        t=TIME1,
Ejemplo n.º 8
0
def dotsbws_success_result_two_relays(empty_dotsbws_datadir):
    '''
    Creates an ~/.sbws with a a couple of fresh ResultSuccess for a couple or
    relays
    '''
    args = _PseudoArguments(directory=empty_dotsbws_datadir.name)
    conf = get_config(args)
    dd = conf['paths']['datadir']
    fp1 = 'A' * 40
    fp2 = 'C' * 40
    circ = [fp1, fp2]
    nick = 'CowSayWhat1'
    relay_ip = '169.254.100.1'
    server_ip = '169.254.100.3'
    scanner_nick = 'SBWSscanner'
    rtts = [5, 25]
    downloads = [{'duration': 4, 'amount': 40 * 1024}]
    t = time.time()
    relay = Result.Relay(fp1, nick, relay_ip)
    result = ResultSuccess(rtts,
                           downloads,
                           relay,
                           circ,
                           server_ip,
                           scanner_nick,
                           t=t)
    write_result_to_datadir(result, dd)

    rtts = [10, 20]
    downloads = [{'duration': 4, 'amount': 80 * 1024}]
    t = time.time()
    result = ResultSuccess(rtts,
                           downloads,
                           relay,
                           circ,
                           server_ip,
                           scanner_nick,
                           t=t)
    write_result_to_datadir(result, dd)

    fp1 = 'B' * 40
    circ = [fp1, fp2]
    nick = 'CowSayWhat2'
    relay_ip = '169.254.100.2'
    rtts = [50, 250]
    downloads = [{'duration': 4, 'amount': 400 * 1024}]
    t = time.time()
    relay = Result.Relay(fp1, nick, relay_ip)
    result = ResultSuccess(rtts,
                           downloads,
                           relay,
                           circ,
                           server_ip,
                           scanner_nick,
                           t=t)
    write_result_to_datadir(result, dd)

    rtts = [100, 200]
    downloads = [{'duration': 4, 'amount': 800 * 1024}]
    t = time.time()
    result = ResultSuccess(rtts,
                           downloads,
                           relay,
                           circ,
                           server_ip,
                           scanner_nick,
                           t=t)
    write_result_to_datadir(result, dd)

    return empty_dotsbws_datadir