Exemplo n.º 1
0
def get_clients():
    clients = []
    nodes = get_nodes()

    for node in nodes:
        clients.append(RpcClient(node))
    return clients
Exemplo n.º 2
0
def nodes_page():
    """List nodes
    """
    with get_conn() as conn:
        # todo: include search/filter form, GET variables
        nodes = get_nodes(conn)

    return render_template("node_list.html", nodes=nodes)
Exemplo n.º 3
0
async def broadcast(req):
    """Broadcast the request to all running BFTList nodes."""
    nodes = get_nodes()
    tasks = []
    print(
        f"Client {req['client_id']} ==> Broadcasting req " +
        f"{req['operation']['type']} {req['operation']['args']} to all nodes")
    for _, node in nodes.items():
        tasks.append(send_to_node(node, req))
    # wait for request to be sent to all nodes
    await asyncio.gather(*tasks)
    return
Exemplo n.º 4
0
def nodes_json():
    """Serve json data from postgres
    """
    # todo: push getting nodes down into app.node
    # utility method to get NodeCollection.asJSON()
    with get_conn() as conn:
        area_name = request.args.get('area')
        nodes = get_nodes(conn, area=area_name)
        features = [node.as_geojson_feature_dict() for node in nodes]

        geojson = {"type": "FeatureCollection", "features": features}
    return jsonify(geojson)
Exemplo n.º 5
0
async def main():
    args = parser.parse_args()
    nodes = get_nodes()
    n = int(len(nodes) / args.SCALE_FACTOR)
    client_count = int(args.NBR_OF_CLIENTS / n)

    tasks = []
    start_time = time.time()
    for i in range(args.ID * client_count,
                   args.ID * client_count + client_count):
        t = run_client(i, args.OPERATION, args.REQS_PER_CLIENT, nodes)
        tasks.append(t)
    await asyncio.gather(*tasks)
    count = client_count * args.REQS_PER_CLIENT
    end_time = time.time()
    print(f"Process {args.ID} ==> {count} reqs injected by {client_count} " +
          f"clients in {end_time - start_time} s")
Exemplo n.º 6
0
"""Methods related to communication with BFTList nodes."""

# standard
import requests
import time
import asyncio

# local
from node import Node, get_nodes

nodes = get_nodes()


def build_payload(client_id, op, *args):
    """Builds a request object to be sent to all BFTList nodes."""
    return {
        "client_id": client_id,
        "timestamp": int(time.time()),
        "operation": {
            "type": op,
            "args": args
        }
    }


async def send_to_node(node: Node, req):
    """
    Sends the given req as a POST request to a Node.

    Tries to send the request up to 5 times with 1 second interval, will
    quit if 5 failed attempts is reached.
Exemplo n.º 7
0
def get_node_table_from_file(nodes_file):
    nodes = get_nodes(nodes_file)
    return get_node_table_from_list(nodes)