[gnome-keysign: 18/65] bluetooth: refactor to a more clear structure



commit 70230973ee1bddce9f24ef134ad88f1fa9e0b461
Author: RyuzakiKK <aasonykk gmail com>
Date:   Thu Aug 17 12:09:17 2017 +0200

    bluetooth: refactor to a more clear structure
    
    stop_receive has been removed because it was redundant. The comment
    about the port release is no more relevant because now we call accept()
    only when we are sure that there is a connection, so we don't need to
    stop a connection attempt anymore.

 keysign/bluetoothoffer.py | 9 ++-------
 keysign/offer.py          | 4 ++--
 tests/test_bluetooth.py   | 2 +-
 3 files changed, 5 insertions(+), 10 deletions(-)
---
diff --git a/keysign/bluetoothoffer.py b/keysign/bluetoothoffer.py
index 59978e9..7f32d2f 100644
--- a/keysign/bluetoothoffer.py
+++ b/keysign/bluetoothoffer.py
@@ -69,7 +69,7 @@ class BluetoothOffer:
 
         returnValue((success, message))
 
-    def generate_code(self):
+    def allocate_code(self):
         try:
             code = get_local_bt_address().upper()
         except dbus.exceptions.DBusException as e:
@@ -86,11 +86,6 @@ class BluetoothOffer:
         return code, bt_data
 
     def stop(self):
-        self.stopped = True
-
-    def stop_receive(self):
-        # FIXME right now it seems that even after stop()
-        # the used port is not released
         log.debug("Stopping bt receive")
         self.stopped = True
         if self.server_socket:
@@ -119,7 +114,7 @@ def main(args):
     key = get_usable_keys(pattern=args[0])[0]
 
     offer = BluetoothOffer(key)
-    code, _ = offer.generate_code()
+    code, _ = offer.allocate_code()
     offer.start().addCallback(_received)
     print("Offering key: {}".format(key))
     print("Discovery info: {}".format(code))
diff --git a/keysign/offer.py b/keysign/offer.py
index 5b92902..cba712a 100644
--- a/keysign/offer.py
+++ b/keysign/offer.py
@@ -19,7 +19,7 @@ class Offer:
         a_info = self.a_offer.start()
         code, a_data = a_info
         self.bt_offer = BluetoothOffer(self.key)
-        _, self.b_data = self.bt_offer.generate_code()
+        _, self.b_data = self.bt_offer.allocate_code()
         discovery_data = a_data + ";" + self.b_data
         # As design when we use both avahi and wormhole we only display
         # the wormhole code
@@ -46,7 +46,7 @@ class Offer:
 
     def stop_bt(self):
         if self.bt_offer:
-            self.bt_offer.stop_receive()
+            self.bt_offer.stop()
             self.bt_offer = None
 
     def stop(self):
diff --git a/tests/test_bluetooth.py b/tests/test_bluetooth.py
index 9728fc9..82ee4e4 100644
--- a/tests/test_bluetooth.py
+++ b/tests/test_bluetooth.py
@@ -45,7 +45,7 @@ def test_bt():
     hmac = mac_generate(key.fingerprint.encode('ascii'), file_key_data)
     # Start offering the key
     offer = BluetoothOffer(key)
-    info = yield offer.generate_code()
+    info = yield offer.allocate_code()
     code, _ = info
     offer.start()
     receive = BluetoothReceive()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]