def spawn_acceptor(): ''' Starts the TCP accept thread and spins as connections are brought up. ''' Waldo.tcp_accept(Pong, HOST, PORT) while True: pass
def spawn_acceptor(): ''' Starts the TCP accept thread and spins as connections are brought up. ''' Waldo.tcp_accept(InnerPong, HOST, PORT_INNER, throw_func) while True: pass
def run_chatter_a(): # runs in accept mode global quit Waldo.tcp_accept(ChatterA, HOSTNAME, PORT, display_msg, connected_callback=listen_for_user_input) while True: if quit: break time.sleep(SLEEP_TIME)
def run_server(): ''' Runs the multi-connection chat server. ''' global server server = Waldo.no_partner_create(Server, display_msg) print server Waldo.tcp_accept(ClientHandler, HOSTNAME, PORT, server, display_msg) while True: time.sleep(SLEEP_TIME)
def run_test(): ''' Tests Waldo's ability to detect an application exception on the partner endpoint mid-sequence and propagate that exception back to the root endpoint for handling. Returns true if the exception is caught and handled, and false otherwise. ''' Waldo.tcp_accept(Pong,HOST,PORT) connector = Waldo.tcp_connect(Ping,HOST,PORT) return connector.testPropagateException()
def run_test(): ''' Tests Waldo's ability to detect an application exception on the partner endpoint mid-sequence and propagate that exception back to the root endpoint for handling. Returns true if the exception is caught and handled, and false otherwise. ''' Waldo.tcp_accept(Pong, HOST, PORT) connector = Waldo.tcp_connect(Ping, HOST, PORT) return connector.testPropagateException()
def run_test(): ''' Tests Waldo's ability to propagate an exception back through a sequence within an endpoint call. Returns true if the exception is caught and handled, and false otherwise. ''' Waldo.tcp_accept(Pong,HOST,PORT) connector = Waldo.tcp_connect(Ping,HOST,PORT) catcher = Waldo.no_partner_create(Catcher) catcher.addEndpoint(connector) return catcher.testCatchApplicationExceptionFromSequence()
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
def run_test(): Waldo.tcp_accept(Pt2, HOST, PORT, connected_callback=pt2_connected) pt1 = Waldo.tcp_connect(Pt1, HOST, PORT,createList); pt2 = pt2_wait_queue.get() returned_list = pt1.start_seq() time.sleep(1) list_to_return.append('wo') if returned_list != list_to_return: return False return True
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
def run_test(): ''' Tests Waldo's capability of propagating an exception back through nested sequences. Here we have two pairs of endpoints: (a,b), (c,d). Endpoint a begins a sequence with b, which makes and endpoint call to c, which initiates a sequence with d, which raises an exception. Returns true if the exception is propagated back to the root of the event and handled and false otherwise. ''' Waldo.tcp_accept(InnerPong, HOST, PORT_INNER, throw_func) inner_ping = Waldo.tcp_connect(InnerPing, HOST, PORT_INNER) Waldo.tcp_accept(OuterPong, HOST, PORT_OUTER, inner_ping) outer_ping = Waldo.tcp_connect(OuterPing, HOST, PORT_OUTER) return outer_ping.testNestedSequencePropagation()
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
def run_test(): accept_stoppable = Waldo.tcp_accept( SideA, SIDEA_HOST, SIDEA_PORT, connected_callback=sidea_connected) sideb = Waldo.tcp_connect( SideB,SIDEA_HOST,SIDEA_PORT) sidea = sidea_wait_queue.get() sidea.add_stop_listener(sidea_stop_listener) sideb.add_stop_listener(sideb_stop_listener_1) sideb.add_stop_listener(sideb_stop_listener_2) listener_id = sideb.add_stop_listener(sideb_stop_listener_2) sideb.remove_stop_listener(listener_id) sideb.remove_stop_listener(listener_id) sidea.do_nothing() sideb.do_nothing() sidea.stop() time.sleep(1) if sidea_stop_counter != 1: return False if sideb_stop_counter != 3: return False return True
def run_test(): accept_stoppable = Waldo.tcp_accept( SideA, SIDEA_HOST, SIDEA_PORT, connected_callback=sidea_connected) sideb = Waldo.tcp_connect( SideB,SIDEA_HOST,SIDEA_PORT) sidea = sidea_wait_queue.get() sidea.do_nothing() sideb.do_nothing() sidea.stop() time.sleep(1) # ensure that stop fires on single host. try: sidea.do_nothing() return False except Waldo.StoppedException as inst: pass # ensure that the other side also sees the stop. try: sideb.do_nothing() return False except Waldo.StoppedException as inst: pass return True
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
def run_test(): ''' Tests Waldo's ability to propagate an ApplicationException back through an endpoint call on the remote partner in a sequence. The exception should be passed back to the root endpoint which initiates the sequence. Returns true if the exception is caught and handled, and false otherwise. ''' thrower = Waldo.no_partner_create(Pong,None) catcher_partner = Waldo.tcp_accept(Pong,HOST,PORT,thrower) catcher = Waldo.tcp_connect(Ping,HOST,PORT) return catcher.testExceptionPropagation()
def run_anagram_server(): anagram_server = Waldo.no_partner_create(AnagramServer) Waldo.tcp_accept(PlayerHelper, HOSTNAME, ANAGRAM_PORT, anagram_server) load_solutions() while True: print 'Waiting for players....' while anagram_server.get_player_count() <= 0: time.sleep(0.1) print 'Player entered. Game will begin in 10 seconds.' set_solutions(anagram_server) anagram_server.broadcastWaitingMessage('Game will begin in %d seconds. Type "/ready" to join.\n' %ANAGRAM_WAITTIME) for i in range(ANAGRAM_WAITTIME): if (i == ANAGRAM_WAITTIME/2): anagram_server.broadcastMessage('Game will begin in %d seconds\n' %i) time.sleep(1) print 'Game has begun!' anagram_server.start_game() time.sleep(20)#Change to GAMETIME after testing anagram_server.end_game() time.sleep(ANAGRAM_WAITTIME/2) anagram_server.restart_server()
def run_test(): ''' Tests Waldo's capability of propagating a network exception back through a sequence. Here we have two pairs of endpoints: (a,b), (c,d). Endpoint a begins a sequence with b, which makes and endpoint call to c, which initiates a sequence with d. Endpoint d is in a separate process which is manually terminated mid-sequence, thus a network exception should be detected by c and propagated back to a. Returns true if the exception is propagated back to the root of the event and handled and false otherwise. ''' global acceptor_proc Waldo.set_default_heartbeat_period(1) Waldo.set_default_partner_timeout(2) acceptor_proc.start() time.sleep(SLEEP_TIME) # make sure process is ready for tcp_connect inner_ping = Waldo.tcp_connect(InnerPing, HOST, PORT_INNER) Waldo.tcp_accept(OuterPong, HOST, PORT_OUTER, inner_ping) outer_ping = Waldo.tcp_connect(OuterPing, HOST, PORT_OUTER) result = outer_ping.testNestedSequencePropagation() acceptor_proc.terminate() return result
def run_test(): original_sidea_num = 13 original_sideb_num = 135.1 accept_stoppable = Waldo.tcp_accept( SideA, SIDEA_HOST, SIDEA_PORT,original_sidea_num, connected_callback=sidea_connected) sideb = Waldo.tcp_connect( SideB,SIDEA_HOST,SIDEA_PORT,original_sideb_num) sidea = sidea_wait_queue.get() # check if each initialized correctly if sidea.get_other_val() != original_sideb_num: print '\nErr: symmetric did not initialize correctly' return False if sideb.get_other_val() != original_sidea_num: print '\nErr: symmetric did not initialize correctly' return False sidea_num = 39 sideb_num = 41 # write endpoint number to each side sidea.set_other_val(sideb_num) sideb.set_other_val(sidea_num) if sidea.get_other_val() != sideb_num: print '\nErr: symmetric did not set other side correctly' return False if sideb.get_other_val() != sidea_num: print '\nErr: symmetric did not set other side correctly' return False accept_stoppable.stop() return True
def run_test(): accept_stoppable = Waldo.tcp_accept( Modifier, MODIFIER_HOST, MODIFIER_PORT, connected_callback=modifier_connected) data_reader = Waldo.tcp_connect( DataReader,MODIFIER_HOST,MODIFIER_PORT) modifier = modifier_wait_queue.get() # check peered value is initialized properly if modifier.read_peered_num() != 22: print '\nErr: incorrect modifier initial val of peered num' return False if data_reader.read_peered_num() != 22: print '\nErr: incorrect data reader initial val of peered num' return False # check modifier can increment if modifier.increment_peered_num() != 23: print '\nErr: incorrect modifier return from peered num increment' return False # check modifier sees increment if modifier.read_peered_num() != 23: print '\nErr: incorrect modifier return from peered num read' return False # check data reader sees increment if data_reader.read_peered_num() != 23: print '\nErr: incorrect data reader return from peered num read' return False accept_stoppable.stop() return True
def tell(): """Accepts incoming requests for retrieve list.""" Waldo.tcp_accept(EndpointB, HOSTNAME, PORT, retrieve_list, connected_callback=cb) time.sleep(WAIT_TIME)
f = open('serverLog', 'a') n = 1 def display_msg(endpoint, msg): ''' Called when a client sends a message to the server. Misleading function name: display_msg doesn't actually display a msg. ''' global f global n global startTime if(msg == str(numMessages - 1)): f.write(str(n) + ' ') n += 1 f.write(str(time.time() - startTime) + '\n') Waldo.tcp_accept(Server, HOSTNAME, PORT, display_msg) print 'Server is up and running.' for i in range(1, 17): numClients = i for k in range(0, i): subprocess.Popen("python client.py " + str(i)) #wait for endpoints to die... time.sleep(timeout * numClients) numKilled = 0
solution = [] elif line.startswith('--'): anagram = line[2:].upper() else: solution.append(line.upper()) def set_solutions(anagram_server): anagram = random.choice([key for key in solution_set]) solutions = solution_set[anagram] anagram_server.set_solution(anagram, solutions) if __name__ == '__main__': anagram_server = Waldo.no_partner_create(AnagramServer) print 'GameServer created!' Waldo.tcp_accept(PlayerHelper, HOSTNAME, 6767, anagram_server) load_solutions() while True: print 'Waiting for players....' while anagram_server.get_player_count() <= 0: time.sleep(0.1) print 'Player entered. Game will begin in 10 seconds.' set_solutions(anagram_server) anagram_server.broadcastWaitingMessage('Game will begin in %d seconds. Type "/ready" to join.\n' %WAITTIME) for i in range(WAITTIME): if (i == WAITTIME/2): anagram_server.broadcastMessage('Game will begin in %d seconds' %i) time.sleep(1) print 'Game has begun!' anagram_server.start_game() time.sleep(20)
numClients = 0 #The server.py now manages the client files too. This improves coordination #while still leaving multiprocessing features. if(len(sys.argv) >= 2): rewrite = sys.argv[1] else: rewrite = raw_input('Overwrite logs? (Input y/n): ') if(rewrite in ['y', 'Y']): f = open('clientLog', 'w') f.close() f = open('serverLog', 'w') else: f = open('serverLog', 'a') n = 1 Waldo.tcp_accept(Server, HOSTNAME, PORT) print 'Server is up and running.' for i in range(1, 2): numClients = i for k in range(0, i): subprocess.Popen(["python","client.py",str(i)]) #wait for endpoints to die... time.sleep(timeout * numClients) numKilled = 0
import sys sys.path.append("../..") from waldo.lib import Waldo from emitted import Pong import time def pong_connected(endpoint): print '\nPong endpoint is connected!\n' Waldo.tcp_accept( Pong, 'localhost',6767, connected_callback=pong_connected) print 'Server is running. Better go catch it!' while True: pass
def display_msg(endpoint, msg): """ Called when a client sends a message to the server. Misleading function name: display_msg doesn't actually display a msg. """ global f global n global startTime if msg == str(numMessages - 1): f.write(str(n) + " ") n += 1 f.write(str(time.time() - startTime) + "\n") Waldo.tcp_accept(Server, HOSTNAME, PORT, connected_callback=connected) print "Server is up and running." for i in range(1, 2): numClients = i for k in range(0, i): subprocess.Popen(["python", "client.py", str(i)]) # wait for endpoints to die... while numKilled < numClients: time.sleep(1) numKilled = 0
REFRESH = 0.1 def connected(endpoint): endpoint.changeMSGS(msgs) while True: time.sleep(REFRESH) endpoint.service_signal() endpoint.receiveStatus(count) def display_msg(endpoint, msg): if msg != "": print (msg) msgs.append(msg) endpoint.changeMSGS(msgs) # I think I should make updating a separate function def vote(endpoint, gameNum, enter): if gameNum >= 0: increment = -1 if enter: increment = 1 count[int(gameNum)] += increment Waldo.tcp_accept(Server, HOSTNAME, PORT, display_msg, vote, connected_callback=connected) print "Server is up and running." while True: pass