def test_query(self): ciphertext = self.encryption_scheme.encrypt(self.key, self.message) client_message = protocol.ClientMessage() client_message.query(ciphertext) self.assertIsInstance(client_message, protocol.ClientMessage) self.assertEqual(client_message.message_type.__repr__(), protocol.MessageType("query").__repr__())
def test_move_left(self): ciphertext = self.encryption_scheme.encrypt(self.key, self.message) client_message = protocol.ClientMessage() client_message.move_left(ciphertext) #TODO protocol.ClientMessage().move_left(ciphertext) doesn't work self.assertIsInstance(client_message, protocol.ClientMessage) self.assertEqual(client_message.message_type.__repr__(), protocol.MessageType("move_left").__repr__())
def test_insert(self): ciphertext = self.encryption_scheme.encrypt(self.key, self.message) client_message = protocol.ClientMessage() client_message.insert(ciphertext, None, "left") self.assertIsInstance(client_message, protocol.ClientMessage) self.assertIsNone(client_message.new_ciphertext) self.assertEqual(client_message.insert_direction, "left") self.assertEqual(client_message.message_type.__repr__(), protocol.MessageType("insert").__repr__())
def receive(self, client_message): #print "KEYS: " + str(self.fake_ope_table) self.learner.process_message(client_message) if (client_message.message_type.__repr__() == protocol.MessageType( "move_left").__repr__()): current = self.DCS_hack(client_message) left_child = current.left if left_child: server_message = protocol.ServerMessage( ciphertext=left_child.value, client_message=client_message) else: server_message = protocol.ServerMessage( ciphertext=None, client_message=client_message) elif (client_message.message_type.__repr__() == protocol.MessageType( "move_right").__repr__()): current = self.DCS_hack(client_message) right_child = current.right if right_child: server_message = protocol.ServerMessage( ciphertext=right_child.value, client_message=client_message) else: server_message = protocol.ServerMessage( ciphertext=None, client_message=client_message) elif (client_message.message_type.__repr__() == protocol.MessageType( "get_root").__repr__()): if not self.root: server_message = protocol.ServerMessage( ciphertext=None, client_message=client_message) else: server_message = protocol.ServerMessage( ciphertext=self.root.value, client_message=client_message) elif (client_message.message_type.__repr__() == protocol.MessageType( "insert").__repr__()): new_node = Server.OPE_Node(client_message.new_ciphertext) print "Server insert, new_ciphertext=" + str( client_message.new_ciphertext) # root case if client_message.ciphertext == None: self.root = new_node if client_message.new_ciphertext in self.fake_ope_table.keys(): self.fake_ope_table[client_message.new_ciphertext] += [ self.root ] else: self.fake_ope_table[client_message.new_ciphertext] = [ self.root ] else: node = self.DCS_hack(client_message) new_node.parent = node if (client_message.insert_direction == "left"): node.left = new_node elif (client_message.insert_direction == "right"): node.right = new_node if client_message.new_ciphertext in self.fake_ope_table.keys(): self.fake_ope_table[client_message.new_ciphertext] += [ new_node ] else: self.fake_ope_table[client_message.new_ciphertext] = [ new_node ] # AVL rebalance while (node and node.parent): rebalance(node.parent) node = node.parent self.update_root() server_message = protocol.ServerMessage( ciphertext=client_message.new_ciphertext, client_message=client_message) elif (client_message.message_type.__repr__() == protocol.MessageType( "query").__repr__()): # trivial implementation since there is no data associated with a ciphertext besides itself server_message = protocol.ServerMessage( ciphertext=client_message.ciphertext, client_message=client_message) self.communication_channel.put(server_message) return server_message
def test_get_root(self): client_message = protocol.ClientMessage() client_message.get_root() self.assertIsInstance(client_message, protocol.ClientMessage) self.assertEqual(client_message.message_type.__repr__(), protocol.MessageType("get_root").__repr__())