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
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