Exemple #1
0
def add_single_dht_node(node_host_port_pair):

    # first: connect to discovery service
    requester = Waldo.tcp_connect(
        Requester,
        conf.COORDINATOR_HOST_PORT_PAIR.host,
        conf.COORDINATOR_HOST_PORT_PAIR.port,
        # the host and port that our new dht node will listen on for
        # connections to other dht nodes.
        node_host_port_pair.host,
        node_host_port_pair.port,
    )

    # request request addresses of other nodes to contact from
    # discovery service, plus register self with discovery service.
    uuid, finger_table, next, prev = requester.register()
    dht_node = Waldo.no_partner_create(
        Node, uuid, util_funcs.distance, util_funcs.hashed_uuid, util_funcs.between, util_funcs.debug_print
    )

    # listen for connections to my node
    def on_connected(sidea_endpoint):
        sidea_endpoint.add_connection_to_node()

    Waldo.tcp_accept(
        NodeSideA,
        node_host_port_pair.host,
        node_host_port_pair.port,
        dht_node,
        node_host_port_pair.host,
        node_host_port_pair.port,
        connected_callback=on_connected,
    )

    # connect to other nodes in my finger table
    for uuid in finger_table.keys():
        # table_entry has form:
        #   host: <text>
        #   port: <number>
        #   valid: <bool>
        #   uuid: <text>
        table_entry = finger_table[uuid]
        host_to_connect_to = table_entry["host"]
        port_to_connect_to = table_entry["port"]

        connection_to_finger_table_node = Waldo.tcp_connect(
            NodeSideB,
            host_to_connect_to,
            port_to_connect_to,
            dht_node,
            node_host_port_pair.host,
            node_host_port_pair.port,
        )

    return dht_node
Exemple #2
0
def start_coordinator():
    math_endpoint = Waldo.math_endpoint_lib()

    coordinator_master = Waldo.no_partner_create(
        CoordinatorMaster, util_funcs.between, util_funcs.rand_uuid, math_endpoint, conf.MAX_NUMBER_FINGER_TABLE_ENTRIES
    )

    # begin listening for connections to coordinator master
    Waldo.tcp_accept(
        Coordinator, conf.COORDINATOR_HOST_PORT_PAIR.host, conf.COORDINATOR_HOST_PORT_PAIR.port, coordinator_master
    )

    return coordinator_master
Exemple #3
0
def run_test():

    uuid = util_funcs.hashed_uuid(None,'some id')
    dht_node = Waldo.no_partner_create(
        Node,uuid,util_funcs.distance,util_funcs.hashed_uuid,
        util_funcs.between, util_funcs.debug_print)

    data_to_add = [
        ('key','data'),
        ('a','ata'),
        ('m','wow')]

    # add the data
    for key,data in data_to_add:
        dht_node.add_data(key,data)

    # test that the added data is still there
    for key,data in data_to_add:
        value, num_hops, exists = dht_node.get_data(key)
        if not exists:
            print '\nErr: data should have existed in dht'
            return False
        if value != data:
            print '\nErr: got incorrect value back for key'
            return False
        
    # test that data not added is not there
    not_added_data_keys = ['woie','dow','mwoe']
    for key in not_added_data_keys:
        value,num_hops,exists = dht_node.get_data(key)
        if exists:
            print '\nErr: should not have received any data from false key'
            return False

    return True
Exemple #4
0
def run_test():

    dhta = create_single_node(HOSTA,PORTA)
    dhtb = create_single_node(HOSTB,PORTB,True)

    # now try to connect the nodes to each other. a connects to b.
    connection = Waldo.tcp_connect(
        NodeSideB,HOSTB,PORTB,dhta, HOSTA, PORTA)

    connection.add_connection_to_node()
    time.sleep(3)

    # connection established between two sides.

    # add several pieces of data
    NUM_DATA_TO_ADD = 10
    for i in range(0, NUM_DATA_TO_ADD):
        dhta.add_data(str(i),str(i))

    # check that the added pieces of data are returned when query
    for i in range(0, NUM_DATA_TO_ADD):
        value, num_hops, found = dhtb.get_data(str(i))
        if not found:
            print '\nError: did not find key expecting'
            return False
        if value != str(i):
            print '\nError: incorrect value'
            return False
        
    return True
Exemple #5
0
def create_single_node(listen_on_host, listen_on_port, should_accept=False):
    uuid = util_funcs.hashed_uuid(None,str(random.random()))
    dht_node = Waldo.no_partner_create(
        Node,uuid,util_funcs.distance,util_funcs.hashed_uuid,
        util_funcs.between,
        util_funcs.debug_print)

    if should_accept:
        def on_connected(endpoint):
            pass
            # print '\nGot into on connected\n'

        # listen for connections to dht node
        Waldo.tcp_accept(
            NodeSideA,
            listen_on_host, listen_on_port,
            dht_node,
            listen_on_host, listen_on_port,
            connected_callback = on_connected)

    return dht_node
def run_test():
    sideA, sideB = (
        Waldo.same_host_create(SideA).same_host_create(SideB))

    
    original_num = 30
    ext_num = Waldo._waldo_classes['WaldoExtNumVariable'](
        'garbage',sideA._host_uuid,False,original_num)


    sideA.load_ext_num(ext_num)


    # sequences + externals
    amt_to_increment = 6
    a,b = sideA.test_seq_arg(amt_to_increment)
    if a != (b + amt_to_increment):
        print '\nErr: incorrect numbers from sequence'
        return False
    
    
        
    return True
#Waldo Quiz 3/6/20

from graphics import *
from random import *
from Waldo import *

#Basics
w = GraphWin("WALDO MAKER 2000",600,600)
waldos = []

#Making two buttons
blue = Waldo(Point(230,300))
blue.setFill('blue')
blue.draw(w)
waldos.append(blue)

yellow = Waldo(Point(350,300))
yellow.setFill('yellow')
yellow.draw(w)
waldos.append(yellow)

#################################################

while True:
    location = w.getMouse()
#Blue button
    if(waldos[0].contains(location)):
        for i in range(0,randint(5,20)):
            red = Waldo(Point(randint(5,580),randint(5,580)))
            red.draw(w)
            waldos.append(red)