changeset 4b84673adb24 in /home/hg/repos/gajim-plugins

author: lovetox <[email protected]>
branches: 
details:gajim-plugins?cmd=changeset;node=4b84673adb24
description: Refactor missing key logic & change log levels

diffstat:

 omemo/__init__.py    |  55 +++++++++++++++++----------------------------------
 omemo/omemo/state.py |  34 +++++--------------------------
 omemo/ui.py          |   8 +++---
 omemo/xmpp.py        |   2 +-
 4 files changed, 29 insertions(+), 70 deletions(-)

diffs (194 lines):

diff -r 14142266761a -r 4b84673adb24 omemo/__init__.py
--- a/omemo/__init__.py Sat Jul 16 09:06:16 2016 +0200
+++ b/omemo/__init__.py Thu Jun 23 23:17:09 2016 +0200
@@ -327,19 +327,17 @@
         else:
             log.warn(account_name + " => No devices for " + contact_jid)
 
-    def are_keys_missing(self, account_name, contact_jid):
-        """ Used by the ui to set the state of the PreKeyButton. """
-
-        my_jid = gajim.get_jid_from_account(account_name)
-        state = self.get_omemo_state(account_name)
-        result = 0
-        result += len(state.devices_without_sessions(str(contact_jid)))
-        result += len(state.own_devices_without_sessions(my_jid))
-        if result > 0:
-            log.info(account_name + " => Missing keys for " + contact_jid + ": 
" +
-                     str(result))
-            log.info('Query keys now ...')
-            self.query_prekey(account_name, contact_jid)
+    def are_keys_missing(self, account, contact_jid):
+        """ Check DB if keys are missing and query them """
+        state = self.get_omemo_state(account)
+        devices_without_session = state \
+            .devices_without_sessions(contact_jid)
+        if devices_without_session:
+            for device_id in devices_without_session:
+                self.fetch_device_bundle_information(account,
+                                                     state,
+                                                     contact_jid,
+                                                     device_id)
 
     @log_calls('OmemoPlugin')
     def handle_iq_received(self, event):
@@ -354,23 +352,6 @@
                 del iq_ids_to_callbacks[id_]
 
     @log_calls('OmemoPlugin')
-    def query_prekey(self, account_name, contact_jid):
-        """ Calls OmemoPlugin.fetch_device_bundle_information() for each own or
-            recipient device key missing.
-        """
-        account = account_name
-        state = self.get_omemo_state(account)
-        to_jid = contact_jid
-        my_jid = gajim.get_jid_from_account(account)
-        for device_id in state.devices_without_sessions(to_jid):
-            self.fetch_device_bundle_information(account, state, to_jid,
-                                                 device_id)
-
-        for device_id in state.own_devices_without_sessions(my_jid):
-            self.fetch_device_bundle_information(account, state, my_jid,
-                                                 device_id)
-
-    @log_calls('OmemoPlugin')
     def fetch_device_bundle_information(self, account_name, state, jid,
                                         device_id):
         """ Fetch bundle information for specified jid, key, and create axolotl
@@ -387,8 +368,8 @@
             device_id : int
                 The device_id for which we are missing an axolotl session
         """
-        log.debug(account_name + '=> Fetch bundle device ' + str(device_id) +
-                  '#' + jid)
+        log.info(account_name + ' => Fetch bundle device ' + str(device_id) +
+                 '#' + jid)
         iq = BundleInformationQuery(jid, device_id)
         iq_id = str(iq.getAttr('id'))
         iq_ids_to_callbacks[iq_id] = \
@@ -437,7 +418,7 @@
             return
 
         if state.build_session(recipient_id, device_id, bundle_dict):
-            log.info(recipient_id + ' => session created')
+            log.info(account_name + ' => session created for: ' + recipient_id)
             # Warn User about new Fingerprints in DB if Chat Window is Open
             if account_name in self.ui_list and \
                     recipient_id in self.ui_list[account_name]:
@@ -466,7 +447,7 @@
         iq = BundleInformationAnnouncement(state.bundle, state.own_device_id)
         gajim.connections[account].connection.send(iq)
         id_ = str(iq.getAttr("id"))
-        log.debug(account + " => Announcing OMEMO support via PEP")
+        log.info(account + " => Announcing OMEMO support via PEP")
         iq_ids_to_callbacks[id_] = lambda stanza: \
             self.handle_announcement_result(account, stanza)
 
@@ -487,9 +468,9 @@
         my_jid = gajim.get_jid_from_account(account)
         iq = DevicelistQuery(my_jid)
         if successful(stanza):
-            log.debug(account + ' => Publishing bundle was successful')
+            log.info(account + ' => Publishing bundle was successful')
             gajim.connections[account].connection.send(iq)
-            log.debug(account + ' => Querry own Devicelist')
+            log.info(account + ' => Querry own Devicelist')
             id_ = str(iq.getAttr("id"))
             iq_ids_to_callbacks[id_] = lambda stanza: \
                 self.handle_devicelist_result(account, stanza)
@@ -512,7 +493,7 @@
         state = self.get_omemo_state(account)
 
         if successful(stanza):
-            log.debug(account + ' => Devicelistquery was successful')
+            log.info(account + ' => Devicelistquery was successful')
             devices_list = unpack_device_list_update(stanza, account)
             if len(devices_list) == 0:
                 return False
diff -r 14142266761a -r 4b84673adb24 omemo/omemo/state.py
--- a/omemo/omemo/state.py      Sat Jul 16 09:06:16 2016 +0200
+++ b/omemo/omemo/state.py      Thu Jun 23 23:17:09 2016 +0200
@@ -65,10 +65,10 @@
             else:
                 self.add_own_device(device_id)
 
-        log.debug(self.own_jid + ': Roster devices after boot:' +
-                  str(self.device_ids))
-        log.debug(self.own_jid + ': Own devices after boot:' +
-                  str(self.own_devices))
+        log.info(self.own_jid + ': Roster devices after boot:' +
+                 str(self.device_ids))
+        log.info(self.own_jid + ': Own devices after boot:' +
+                 str(self.own_devices))
 
     def build_session(self, recipient_id, device_id, bundle_dict):
         sessionBuilder = SessionBuilder(self.store, self.store, self.store,
@@ -308,30 +308,8 @@
                            for dev in known_devices
                            if not self.store.containsSession(jid, dev)]
         if missing_devices:
-            log.debug('Missing device sessions: ' + str(
-                      missing_devices))
-        return missing_devices
-
-    def own_devices_without_sessions(self, own_jid):
-        """ List own device_ids which have no axolotl session.
-
-            Parameters
-            ----------
-            own_jid : string
-                Workaround for missing own jid in OmemoState
-
-            Returns
-            -------
-            [int]
-                A list of device_ids
-        """
-        known_devices = set(self.own_devices) - {self.own_device_id}
-        missing_devices = [dev
-                           for dev in known_devices
-                           if not self.store.containsSession(own_jid, dev)]
-        if missing_devices:
-            log.debug('Missing device sessions: ' + str(
-                missing_devices))
+            log.info(self.account + ' => Missing device sessions for ' +
+                     jid + ': ' + str(missing_devices))
         return missing_devices
 
     def get_session_cipher(self, jid, device_id):
diff -r 14142266761a -r 4b84673adb24 omemo/ui.py
--- a/omemo/ui.py       Sat Jul 16 09:06:16 2016 +0200
+++ b/omemo/ui.py       Thu Jun 23 23:17:09 2016 +0200
@@ -60,15 +60,15 @@
     def on_click(self, widget):
         enabled = self.get_active()
         if enabled:
-            log.info(self.contact.account.name + ' => Enable OMEMO for ' +
-                     self.contact.jid)
+            log.debug(self.contact.account.name + ' => Enable OMEMO for ' +
+                      self.contact.jid)
             self.plugin.omemo_enable_for(self.contact)
             self.ui.WarnIfUndecidedFingerprints()
             self.chat_control.print_conversation_line(
                 u'OMEMO encryption enabled ', 'status', '', None)
         else:
-            log.info(self.contact.account.name + ' => Disable OMEMO for ' +
-                     self.contact.jid)
+            log.debug(self.contact.account.name + ' => Disable OMEMO for ' +
+                      self.contact.jid)
             self.plugin.omemo_disable_for(self.contact)
             self.ui.refreshAuthLockSymbol()
             self.chat_control.print_conversation_line(
diff -r 14142266761a -r 4b84673adb24 omemo/xmpp.py
--- a/omemo/xmpp.py     Sat Jul 16 09:06:16 2016 +0200
+++ b/omemo/xmpp.py     Thu Jun 23 23:17:09 2016 +0200
@@ -326,7 +326,7 @@
 def decode_data(node):
     """ Fetch the data from specified node and b64decode it. """
     data = node.getData()
-    log.debug(data)
+
     if not data:
         log.warn("No node data")
         return
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to