Commits

Cédric Bonhomme  committed 8cc2f80

Added test if the client is registered with the public key to the authentication agent.

  • Participants
  • Parent commits ab93c67

Comments (0)

Files changed (4)

File source/authenticationAgent.py

                     pass
 
                 elif command[0] == "addinterlocutor":
-                    pubkey = xmlParser.get_pub_key(command[1])
-                    ontology = xmlParser.get_ontology(command[1])
+                    pubkey = str(xmlParser.get_pub_key(command[1]))
+                    ontology = str(xmlParser.get_ontology(command[1]))
 
                     self.myAgent.outgoing_message = "newinterlocutor:" + command[1] + \
                                             ":" + ontology + ":" + pubkey

File source/configurations/clients_informations.xml

-<?xml version="1.0" ?><clients><client><name>alice</name><password>e66115848130d33984df50f6db4f18606e528884</password><ontology>ontoAlice</ontology><pubkey>10469561507669980205845878878482661147242531840462528970116508189514511474321-22774868557631724240972266067314576135755966918326659069859326136887363208409</pubkey></client><client><name>bob</name><password>e4dc6e7ed857107161e5876f93d2e05dff5cffdc</password><ontology>ontoBob</ontology><pubkey>1549967412529426729313949458268948672226951152424232244187603267034164784789-2739559867477094853848905282988657412068718710053779621246269884544479491523</pubkey></client></clients>

File source/simpleGui.py

     def __create_right_panel(self):
         """
         """
-        self.connection_info = Label(self.master, text = "No discussion", \
+        self.connection_info = Label(self.master, text = "No interlocutor", \
                 padx = 10, pady = 10, justify = LEFT, **labelTextStyle)
         self.connection_info.grid(row = 1, column = 4, sticky = W)
 
-
     def connect_to_tux(self):
         """Launch the connection with Tux Droid.
 
-        Called in a new thread.
+        Called in a new thread at gui launch.
         """
         try:
             self.tuxy = tuxdroid.Tux() # blocking instruction
-        except NameError, e:
-            pass
+        except NameError:
+            pass       # already managed at 'tuxdroid' import
         except Exception, e:
-            print e
+            print e # exceptions coming from tuxdroid module
             self.tuxy = None
 
     def signin(self):
         username_entry = Entry(msg)
         username_entry.grid(row = 0, column = 1, pady = 2)
         username_entry.insert(0, self.name.lower())
+        username_entry.configure(state=DISABLED)
         username_entry.focus_set()
 
         Label(msg, text='Password : ').grid(row = 1, column = 0)
 
     def block_sender(self, event = None):
         """
+        Block the selected client.
         """
         client = None
         try:
                 self.client_agent.blocked_sender.append(client)
             else:
                 self.client_agent.blocked_sender.remove(client)
-                print self.client_agent.blocked_sender
 
     def connect_to_client(self, event = None, client = None):
         """
 
     def add_client(self, client, ontology, pubkey):
         """
-        The method is called by clienAgent when the authentication agent
-        has given the requested informations about the new
-        interlocutor.
+        The method is called by the client agent when the
+        authentication agent has given the requested informations
+        about the new interlocutor.
         """
-        # add the new interlocutor to the dic of interlocutors
+        if ontology == 'None' and pubkey == 'None':
+            self.show_info(client + ' is not registered.\n' + \
+                'You would not be able to communicate with ' + client + '.')
+            return
+
+        # Construct the RSA key of the new interlocutor
         rsa_interlocutor = rsa.RSA(nb_bits = 128)
         rsa_interlocutor.b = int(pubkey.split('-')[0])
         rsa_interlocutor.n = int(pubkey.split('-')[1])
 
+        # Add the interlocutor with its ontology and RSA public KEY
         self.client_agent.receiver[client] = (ontology, \
                                                     rsa_interlocutor)
-        # update the connection info label
+        # Update the connection info label
         self.update_connection_info_label()
 
-
     def update_connection_info_label(self):
         """
         Update the label wich contains the
         list of current interlocutors.
         """
         if self.client_agent.receiver:
-            connection_info = "Connected with:\n"
+            if len(self.client_agent.receiver) == 1:
+                connection_info = "Interlocutor:\n"
+            else:
+                connection_info = "Interlocutors:\n"
             for a_client in self.client_agent.receiver.keys()[:-1]:
                 connection_info += " - " + a_client + ";\n"
             connection_info += " - " + self.client_agent.receiver.keys()[-1] + "."
             self.connection_info.configure(text=connection_info)
         else:
-            self.connection_info.configure(text="No discussion")
+            self.connection_info.configure(text="No interlocutor")
 
     def send_message(self):
         """
                                 ' would like to chat with you.\n' + \
                                 'Add this person to the conversation ?') :
 
+                # Try to connect to the new client. This step will
+                # success if the client is already registered.
                 self.connect_to_client(client = name)
-                self.update_conversation_zone(dec_message)
+
+                # If the new client is not registered to the
+                # authentication agent.
+                if name in self.client_agent.receiver.keys():
+                    self.update_conversation_zone(dec_message)
 
     def update_conversation_zone(self, msg):
         """

File source/spade/user_db.xml

Binary file modified.