def run(self): names.append(self.getName()) transmitter_socket = socket.socket() transmitter_socket = SDPTPTC.fail_repeat_connector( transmitter_socket, self.address, self.port, self.receiver_identity) commands.append("#{0}".format(self.receiver_identity)) while True: while len(instructions) != 0: if instructions[0][0].startswith('#{0}'.format( self.receiver_identity)): split_instruction = (instructions.pop(0)[0]).split(' ', 1) message = SDPTPTC.encode( self.key, (identity + ': ' + split_instruction[1])) transmitter_socket.send(message.encode())
def run(self): transmitter_socket = socket.socket() transmitter_socket = SDPTPTC.fail_repeat_connector( transmitter_socket, self.address, self.port, self.receiver_identity) connection_live = True connections.append([self.address, self.receiver_identity]) update_list.append([self.getName(), False]) index = update_list.index([self.getName(), False]) connection_update() while connection_live: try: if update_list[index][1]: print("Updating {0} @ {1}".format(self.receiver_identity, self.address)) transmitter_socket.send(connections_transmission.encode()) update_list[index][1] = False except socket.error: print("Closing") connections[index] = ["", ""] update_list[index] = ["", False] connection_update() connection_live = False print("Closed") time.sleep(15)
def server_connector(): request = socket.socket() request = SDPTPTC.fail_repeat_connector(request, server_address, 6112, "Addressing Server") receiver_port = int((request.recv(128)).decode()) request.send(identity.encode()) request.shutdown(socket.SHUT_RDWR) request.close() addressing_receiver_thread = AddressingReceiver(receiver_port) addressing_receiver_thread.start()
def conversation_starter(recipient, receiver_address, receiver_port, sender_port, sender_identity, key): if recipient: receiver_address = receiver_address[0] elif not recipient: request = socket.socket() request = SDPTPTC.fail_repeat_connector(request, receiver_address, sender_port, sender_identity) sender_port = ports.get() request.send((str(sender_port) + ' ' + identity).encode()) receiver_port = int((request.recv(128)).decode()) key = SDPTPTC.key_generation_client(request) key = SDPTPTC.create_key(key) request.shutdown(socket.SHUT_RDWR) request.close() transmitter_thread = Transmitter(receiver_address, receiver_port, sender_identity, key) receiver_thread = Receiver(sender_port, key) transmitter_thread.start() receiver_thread.start()
def run(self): receiver_socket = socket.socket() receiver_socket.bind((home_address, self.port)) receiver_socket.listen(5) while True: transmitter_socket, transmitter_address = receiver_socket.accept() while True: message = transmitter_socket.recv(4096).decode() if message != '': print((SDPTPTC.decode(self.key, message) + '\t' + str(time.ctime())))
def run(self): while running: request_handler_socket = socket.socket() request_sender_socket, request_sender_address = SDPTPTC.socket_binder( request_handler_socket, 5112, server_address) port = ports.get() request_sender_socket.send(str(port).encode()) request_sender_information = request_sender_socket.recv( 128).decode() request_sender_port = int(request_sender_information[0:4]) request_sender_identity = request_sender_information[5:] numerical_key = SDPTPTC.key_generation_server( request_sender_socket) key = SDPTPTC.create_key(numerical_key) request_sender_socket.shutdown(socket.SHUT_RDWR) request_handler_socket.close() request_sender_socket.close() conversation_starter(True, request_sender_address, request_sender_port, port, request_sender_identity, key)
def run(self): while running: # Lock all threads which read from instructions instruction = input() if instruction[:3] in commands: if instruction.startswith('##C'): instructions.append([instruction]) input_barrier.wait() elif instruction.startswith('##S'): instructions.append([instruction]) input_barrier.wait() elif instruction.startswith('##T'): SDPTPTC.table_printer(connections) elif instruction.startswith('##H'): SDPTPTC.help_command() elif instruction.startswith('##I'): SDPTPTC.who_am_i(identity, home_address, server_address) elif instruction.startswith('##F'): length = len(instructions) for index in range(length): instructions.pop(index) print("Instruction buffer cleared of {0} instructions". format(length)) elif instruction.startswith('#'): instructions.append([instruction])
def initialisation(): global s_g_primes s_g_primes = SDPTPTC.s_g_prime_generator() global home_address home_address = SDPTPTC.get_local_address() global ports ports = queue.Queue() for port in range(6113, 7112): ports.put(port) global connections connections = [] global running running = True global update_list update_list = [] global connections_transmission connections_transmission = ""
def run(self): while running: request_handler_socket = socket.socket() request_sender_socket, request_sender_address = SDPTPTC.socket_binder( request_handler_socket, 6112, home_address) port = ports.get() request_sender_socket.send(str(port).encode()) request_sender_identity = request_sender_socket.recv(128).decode() request_sender_socket.shutdown(socket.SHUT_RDWR) request_handler_socket.close() request_sender_socket.close() conversation_starter(True, request_sender_address, port, request_sender_identity)
def initialisation(): global instructions instructions = [] global identity identity = input("Please input identity") global home_address home_address = SDPTPTC.get_local_address() global running running = True global conditional conditional = threading.Condition() global ports ports = queue.Queue() for port in range(5113, 6112): ports.put(port) global names names = [] global input_barrier input_barrier = threading.Barrier(2) global commands commands = ['##C', '##H', '##I', '##S', '##T', '##F'] global connections connections = [] global server_address server_address = input("Input addressing server address") if server_address == "0": server_address = home_address