[Telepathy-commits] [telepathy-gabble/master] add BytestreamSIFallback abstract class

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Tue Mar 17 09:43:14 PDT 2009


---
 tests/twisted/bytestream.py |   86 ++++++++++++++++++++++--------------------
 1 files changed, 45 insertions(+), 41 deletions(-)

diff --git a/tests/twisted/bytestream.py b/tests/twisted/bytestream.py
index 9f82660..6fb26eb 100644
--- a/tests/twisted/bytestream.py
+++ b/tests/twisted/bytestream.py
@@ -445,10 +445,8 @@ def parse_ibb_msg_data(message):
     return ibb_data['sid'], binary
 
 ##### SI Fallback (Gabble specific extension) #####
-
-class BytestreamSIFallbackS5CannotConnect(Bytestream):
-    """Try to use SOCKS5 and fallback to IBB because the target can't connect
-    to the receiver."""
+class BytestreamSIFallback(Bytestream):
+    """Abstract class used for all the SI fallback scenarios"""
     def __init__(self, stream, q, sid, initiator, target, initiated):
         Bytestream.__init__(self, stream, q, sid, initiator, target, initiated)
 
@@ -458,8 +456,6 @@ class BytestreamSIFallbackS5CannotConnect(Bytestream):
         self.ibb = BytestreamIBB(stream, q, sid, initiator, target,
             initiated)
 
-        self.used = self.ibb
-
     def create_si_offer(self, profile, to=None):
         iq, si, field = self._create_si_offer(profile, to)
 
@@ -484,33 +480,6 @@ class BytestreamSIFallbackS5CannotConnect(Bytestream):
         assert str(value[0]) == self.socks5.get_ns()
         assert str(value[1]) == self.ibb.get_ns()
 
-    def open_bytestream(self, expected=None):
-        # first propose to peer to connect using SOCKS5
-        # We set an invalid IP so that won't work
-        self.socks5._send_socks5_init([
-            # Not working streamhost
-            (self.initiator, 'invalid.invalid', 12345),
-            ])
-
-        if expected is not None:
-            event, iq_event = self.q.expect_many(expected,
-                EventPattern('stream-iq', iq_type='error', to=self.initiator))
-        else:
-            event = None
-            iq_event = self.q.expect('stream-iq', iq_type='error', to=self.initiator)
-
-        self.socks5.check_error_stanza(iq_event.stanza)
-
-        # socks5 failed, let's try IBB
-        self.ibb.open_bytestream()
-        return event
-
-    def send_data(self, data):
-        self.used.send_data(data)
-
-    def get_data(self):
-        return self.used.get_data()
-
     def create_si_reply(self, iq, to=None):
         result = IQ(self.stream, 'result')
         result['id'] = iq['id']
@@ -530,15 +499,11 @@ class BytestreamSIFallbackS5CannotConnect(Bytestream):
 
         return result, res_si
 
-    def wait_bytestream_open(self):
-        # Gabble tries SOCKS5 first
-        id, mode, sid, hosts = self.socks5._expect_socks5_init()
-
-        # Pretend we can't connect to it
-        self.socks5.send_not_found(id)
+    def send_data(self, data):
+        self.used.send_data(data)
 
-        # Gabble now tries IBB
-        self.ibb.wait_bytestream_open()
+    def get_data(self):
+        return self.used.get_data()
 
     def wait_bytestream_closed(self):
         self.used.wait_bytestream_closed()
@@ -552,3 +517,42 @@ class BytestreamSIFallbackS5CannotConnect(Bytestream):
             '/iq/si[@xmlns="%s"]/si-multiple[@xmlns="%s"]'
             % (ns.SI, ns.SI_MULTIPLE), iq)
         assert si_multiple is not None
+
+class BytestreamSIFallbackS5CannotConnect(BytestreamSIFallback):
+    """Try to use SOCKS5 and fallback to IBB because the target can't connect
+    to the receiver."""
+    def __init__(self, stream, q, sid, initiator, target, initiated):
+        BytestreamSIFallback.__init__(self, stream, q, sid, initiator, target, initiated)
+
+        self.used = self.ibb
+
+    def open_bytestream(self, expected=None):
+        # first propose to peer to connect using SOCKS5
+        # We set an invalid IP so that won't work
+        self.socks5._send_socks5_init([
+            # Not working streamhost
+            (self.initiator, 'invalid.invalid', 12345),
+            ])
+
+        if expected is not None:
+            event, iq_event = self.q.expect_many(expected,
+                EventPattern('stream-iq', iq_type='error', to=self.initiator))
+        else:
+            event = None
+            iq_event = self.q.expect('stream-iq', iq_type='error', to=self.initiator)
+
+        self.socks5.check_error_stanza(iq_event.stanza)
+
+        # socks5 failed, let's try IBB
+        self.ibb.open_bytestream()
+        return event
+
+    def wait_bytestream_open(self):
+        # Gabble tries SOCKS5 first
+        id, mode, sid, hosts = self.socks5._expect_socks5_init()
+
+        # Pretend we can't connect to it
+        self.socks5.send_not_found(id)
+
+        # Gabble now tries IBB
+        self.ibb.wait_bytestream_open()
-- 
1.5.6.5




More information about the telepathy-commits mailing list