Commits

ced...@debian  committed e1bc77e

Changed authenticationAgent: communication with clientAgent. Bug fixes

  • Participants
  • Parent commits 3b4c464

Comments (0)

Files changed (4)

File source/authenticationAgent.py

                         answer = self.myAgent.SendMessage()
                         self.myAgent.addBehaviour(answer, None)
 
+                elif command[0] == "addinterlocutor":
+                    pubkey = xmlParser.get_pub_key(command[1])
+                    ontology = xmlParser.get_ontology(command[1])
+
+                    self.myAgent.outgoing_message = "newinterlocutor:" + command[1] + \
+                                            ":" + ontology + ":" + pubkey
+                    self.myAgent.receiver = self.msg.getSender().getName().split('@')[0]
+
+                    # send the message with a OneShotBehaviour
+                    self.myAgent.addBehaviour(self.myAgent.SendMessage(), None)
+
+
+
     class SendMessage(spade.Behaviour.OneShotBehaviour):
         """
         This behaviour is in charge of sending message.

File source/clientAgent.py

                 if command[0] == "logged":
                     print "Logging in !"
 
+                elif command[0] == "newinterlocutor":
+                    print command
+                    self.myAgent.gui.add_client(command[1], command[2], command[3])
+
     class SendMessageToAuthenticator(spade.Behaviour.OneShotBehaviour):
         """
         """
             for receiver_agent in self.myAgent.receiver.keys():
 
                 # First, form the receiver AID
-                print receiver_agent
                 receiver = self.myAgent.search_agent_into_df( \
                                     service_name = receiver_agent)[0].getAID()
 

File source/configurations/clients_informations.xml

-<?xml version="1.0" ?><clients><client><name>bob</name><password>test</password><ontology>ontoBob</ontology><pubkey>42</pubkey></client><client><name>alice</name><password>tes1</password><ontology>ontoAlice</ontology><pubkey>42</pubkey></client></clients>
+<?xml version="1.0" ?><clients><client><name>bob</name><password>test1</password><ontology>ontoBob</ontology><pubkey>42</pubkey></client><client><name>alice</name><password>test3</password><ontology>ontoAlice</ontology><pubkey>42</pubkey></client></clients>

File source/simpleGui.py

             if password1 == password2:
                 # set the outgoing message
                 self.client_agent.outgoing_message = "signin:" + \
-                                            self.name.lower + \
+                                            self.name.lower() + \
                                             ":" + password1 + \
                                             ":" + self.ontology + \
                                             ":" + self.pubkey
                 # send the message with a OneShotBehaviour
                 self.client_agent.addBehaviour(self.client_agent.SendMessageToAuthenticator(), None)
 
+                msg.destroy()
+
         msg = Toplevel(self.master)
         msg.title('Signin')
         msg.resizable(height = False, width = False)
             except IndexError:
                 pass
         if client not in self.client_agent.receiver.keys():
-            pubkey = xmlParser.get_pub_key(client)
-            ontology = xmlParser.get_ontology(client)
+            # if client is not already an interlocutor
+            # Ask for information to the authenticationAgent
+            # set the outgoing message
+            self.client_agent.outgoing_message = "addinterlocutor:" + client
 
-            self.client_agent.receiver[client] = (ontology, \
-                                                    pubkey)
+            # send the answer to the authentication agent
+            self.client_agent.addBehaviour(self.client_agent.SendMessageToAuthenticator(), None)
+
 
             self.client_agent.gui = self
             self.client_agent.ontology = self.ontology
-            self.update_connection_info_label()
+
             #tkMessageBox.showinfo('Information', 'Connected with ' + client)
         else:
             #tkMessageBox.showinfo('Information', 'Already connected with ' + client)
             del self.client_agent.receiver[client]
             self.update_connection_info_label()
 
+    def add_client(self, client, ontology, pubkey):
+        """
+        The method is called when the authentication agent
+        has given the requested informations about the new
+        interlocutor.
+        """
+        # add the new interlocutor to the list of interlocutors
+        self.client_agent.receiver[client] = (ontology, \
+                                                    pubkey)
+        # 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"