Пример #1
0
def connection_times():
    durations = list(
        session.execute(
            "select extract(second from connected_after) from connects"))
    df = DataFrame(durations, columns=['Connection time (s)'])
    plot = df.plot(kind='hist')
    save_plot(plot, 'connection_times')
Пример #2
0
def address_types():
    ip_only_1 = session.execute(
        "select count(*) from nodes_1_channel where total_ip > 0 and total_addresses=total_ip"
    ).scalar()
    ip_only_5_10 = session.execute(
        "select count(*) from nodes_5_10_channels where total_ip > 0 and total_addresses=total_ip"
    ).scalar()
    ip_only_best_connected = session.execute(
        "select count(*) from nodes_best_connected where total_ip > 0 and total_addresses=total_ip"
    ).scalar()

    tor_only_1 = session.execute(
        "select count(*) from nodes_1_channel where total_tor > 0 and total_addresses=total_tor"
    ).scalar()
    tor_only_5_10 = session.execute(
        "select count(*) from nodes_5_10_channels where total_tor > 0 and total_addresses=total_tor"
    ).scalar()
    tor_only_best_connected = session.execute(
        "select count(*) from nodes_best_connected where total_tor > 0 and total_addresses=total_tor"
    ).scalar()

    both_1 = session.execute(
        "select count(*) from nodes_1_channel where total_tor > 0 and total_ip > 0"
    ).scalar()
    both_5_10 = session.execute(
        "select count(*) from nodes_5_10_channels where total_tor > 0 and total_ip > 0"
    ).scalar()
    both_best_connected = session.execute(
        "select count(*) from nodes_best_connected where total_tor > 0 and total_ip > 0"
    ).scalar()

    node_types = np.array([
        'Nodes with 1 channel', 'Nodes with 5-10 channels',
        'Nodes with higest number\n of channels in the network'
    ])
    ip_only = np.array([ip_only_1, ip_only_5_10, ip_only_best_connected])
    tor_only = np.array([tor_only_1, tor_only_5_10, tor_only_best_connected])
    both = np.array([both_1, both_5_10, both_best_connected])

    total_1 = ip_only_1 + tor_only_1 + both_1
    total_5_10 = ip_only_5_10 + tor_only_5_10 + both_5_10
    total_best = ip_only_best_connected + tor_only_best_connected + both_best_connected
    total = [total_1, total_5_10, total_best]

    proportion_ip = np.true_divide(ip_only, total) * 100
    proportion_tor = np.true_divide(tor_only, total) * 100
    proportion_both = np.true_divide(both, total) * 100

    df = DataFrame([proportion_ip, proportion_tor,
                    proportion_both]).transpose()
    df.index = node_types
    df.columns = [
        'IP addresses only', 'Onion addresses only', 'Both kinds of addresses'
    ]

    print(df)
    plot = df.plot(kind='bar', stacked=True)

    save_plot(plot, 'address_types.png', tilt_x_labels=True)
Пример #3
0
def attempts_hist():
    avgs = session.execute(
        "select amount_usd, round(avg(attempts), 2) from payments where success=True group by amount_usd order by amount_usd asc"
    )
    df = DataFrame(avgs)
    df[[1]] = df[[1]].astype(float)
    df[[1]] -= 1  # Display retries instead of attempts
    df.columns = ['', 'Average number of retires before success']
    df.index = ['USD 0.01', 'USD 1.00', 'USD 10.00']
    plot = df.plot(kind='bar')
    print(df)
    save_plot(plot, 'avg_attempts', tilt_x_labels=True)
Пример #4
0
def connection_successes():
    successes = dict(
        list(
            session.execute(
                "select category, count(*) as successes from connects where success=True group by category"
            )))
    #failure = dict(list(session.execute("select category, count(*) as total from connects where success=False group by category")))

    refused = dict(
        list(
            session.execute(
                "select category, count(*) from connects where connectresult like '%refused%' group by category"
            )))
    no_tor_circuit = dict(
        list(
            session.execute(
                "select category, count(*) from connects where connectresult like '%in progress%' group by category"
            )))
    timeout = dict(
        list(
            session.execute(
                "select category, count(*) from connects where connectresult like '%timed out%' group by category"
            )))
    df_refused = DataFrame(refused.items(),
                           columns=['category', 'Connection refused'])
    df_timeout = DataFrame(timeout.items(), columns=['category', 'Timeout'])
    df_tor = DataFrame(no_tor_circuit.items(),
                       columns=['category', 'Unable to establish Tor circuit'])

    df = DataFrame(successes.items(),
                   columns=['category', 'Connection succeeded'])
    dfe = df.merge(df_refused, how='left').merge(df_timeout, how='left').merge(
        df_refused, how='left').merge(df_tor, how='left')
    dfe = dfe.fillna(0)
    dfe.index = [
        'Nodes with 1 open channel', 'Nodes with 5-10 open channels',
        'Nodes with higest number\n of channels in the network'
    ]

    def normalize(x):
        total = sum(x[1:])
        x[1:] *= 100
        x[1:] /= total
        return x

    df3 = dfe.apply(normalize, axis=1)
    plot = df3.plot(kind='bar', stacked=True, color='gryb')
    save_plot(plot, 'connection_success', tilt_x_labels=True)
Пример #5
0
def success_by_route_length():
    data = session.execute(
        "select route_length, count(case success when True then 1 end)::float/count(*)*100 as success_rate, count(case route_length when route_length then 1 end) as count from payments group by route_length "
        "order by route_length asc")
    data = list(data)
    data = {
        'Hop count': [d['route_length'] for d in data],
        'Success rate, %': [d['success_rate'] for d in data],
        'Number of probes with this route length': [d['count'] for d in data]
    }
    df = DataFrame(data)
    df = df.set_index(['Hop count'])

    plot = df.plot(kind='bar',
                   secondary_y='Number of probes with this route length')
    save_plot(plot, 'success_by_hops')
Пример #6
0
def success_rate_combined():
    total = total_attempts_by_amount()
    attempt1_success = session.execute(
        "select amount_usd, count(*) from payments where success=True and attempts=1 group by amount_usd order by amount_usd asc"
    )
    successes = DataFrame(attempt1_success, index=total.index)[[1]]
    successes /= total / 100
    successes.columns = ['Success on first attempt']

    attemptany_success = session.execute(
        "select amount_usd, count(*) from payments where success=True group by amount_usd order by amount_usd asc"
    )
    successes_retries = DataFrame(attemptany_success, index=total.index)[[1]]
    successes_retries /= total / 100
    successes_retries.columns = ['Success after at most 25 attempts']

    combined = successes.join(successes_retries)
    plot = combined.plot(kind='bar')
    save_plot(plot, 'payment_success_rate', tilt_x_labels=True)

    print(combined)
Пример #7
0
def connection_failure_reasons():

    refused = session.execute(
        "select count(*) from connects where connectresult like '%refused%'"
    ).scalar()
    no_tor_circuit = session.execute(
        "select count(*) from connects where connectresult like '%in progress%'"
    ).scalar()
    timeout = session.execute(
        "select count(*) from connects where connectresult like '%timed out%'"
    ).scalar()
    index = [
        'TCP Connection refused', 'Unable to establish Tor circuit', 'Timeout',
        'Other error'
    ]
    df = DataFrame(
        {'Connection errors': [refused, no_tor_circuit, timeout, 1]},
        index=index)
    plot = df.plot(kind='pie', y='Connection errors', labels=None)
    plot.set_ylabel('')
    save_plot(plot, 'connection_errors')
Пример #8
0
def visible_nodes():
    nodes_over_time = list(
        session.execute(
            "select extract (epoch from delay) as secs, to_char(delay, 'HH24 hrs, MI mnutes, ss secs') as time, total_nodes from gossip_most order by time asc"
        ))
    df = DataFrame(nodes_over_time,
                   columns=['secs', 'Time', 'Nodes in the local network view'])
    df = df.set_index(['secs'])

    def human_readable_interval(x):
        time = x['Time']
        components = time.split(', ')
        nonzero = [c for c in components if not c.startswith('00 ')]
        x['Time'] = ", ".join(nonzero)
        return x

    df = df.apply(human_readable_interval, axis=1)
    df = df.set_index(['Time'])
    print(df)
    plot = df.plot(kind='line', x_compat=True)
    # plot.get_figure().savefig('gossip.png')
    save_plot(plot, 'gossip', tilt_x_labels=60)