[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [bridgedb/master] Make the @port property common to both PluggableTransports and Bridges.
commit 63bc3924096d0cde3373e37d85ca1101e2fb438e
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date: Tue Jun 9 00:08:04 2015 +0000
Make the @port property common to both PluggableTransports and Bridges.
Because it seems awkward to require doing type checks in order to know
which port a bridge-like thing is listening on.
That is, previously, we could access PluggableTransport.port and
Bridge.orPort, but *not* Bridge.port. Moving the port @property from
the PluggableTransport class to the BridgeAddressBase class (and
updating the Bridge.orPort @property to point at the port @property)
allows us to access the port property of either one without caring which
type it is.
In addition to allowing us to forego type checks, this allow allows us to
define an interface which essentially says that "a bridge-like thing is a
thing which has a fingerprint, address, and a port", which again allows us to
generalise code to deal with "bridge-like" things, rather than dealing with a
tuple of classes which happen to be considered "bridge-like" at the time of
writing.
* MOVE the port @property from the PluggableTransport class to the
BridgeAddressBase class.
* CHANGE the Bridge.orPort @property to point at the new port
@property.
---
lib/bridgedb/bridges.py | 65 +++++++++++++++++++++++++----------------------
1 file changed, 34 insertions(+), 31 deletions(-)
diff --git a/lib/bridgedb/bridges.py b/lib/bridgedb/bridges.py
index f56b0e7..5093bef 100644
--- a/lib/bridgedb/bridges.py
+++ b/lib/bridgedb/bridges.py
@@ -141,12 +141,17 @@ class BridgeAddressBase(object):
:type country: str
:ivar country: The two-letter GeoIP country code of the :ivar:`address`.
+
+ :type port: int
+ :ivar port: A integer specifying the port which this :class:`Bridge`
+ (or :class:`PluggableTransport`) is listening on.
"""
def __init__(self):
self._fingerprint = None
self._address = None
self._country = None
+ self._port = None
@property
def fingerprint(self):
@@ -242,6 +247,32 @@ class BridgeAddressBase(object):
if self.address:
return geo.getCountryCode(self.address)
+ @property
+ def port(self):
+ """Get the port number which this ``Bridge`` is listening
+ for incoming client connections on.
+
+ :rtype: int or None
+ :returns: The port (as an int), if it is known and valid; otherwise,
+ returns ``None``.
+ """
+ return self._port
+
+ @port.setter
+ def port(self, value):
+ """Store the port number which this ``Bridge`` is listening
+ for incoming client connections on.
+
+ :param int value: The transport's port.
+ """
+ if isinstance(value, int) and (0 <= value <= 65535):
+ self._port = value
+
+ @port.deleter
+ def port(self):
+ """Reset this ``Bridge``'s port to ``None``."""
+ self._port = None
+
class PluggableTransport(BridgeAddressBase):
"""A single instance of a Pluggable Transport (PT) offered by a
@@ -314,7 +345,6 @@ class PluggableTransport(BridgeAddressBase):
:data:`arguments`.
"""
super(PluggableTransport, self).__init__()
- self._port = None
self._methodname = None
self._blockedIn = {}
@@ -438,32 +468,6 @@ class PluggableTransport(BridgeAddressBase):
return False
@property
- def port(self):
- """Get the port number which this ``PluggableTransport`` is listening
- for incoming client connections on.
-
- :rtype: int or None
- :returns: The port (as an int), if it is known and valid; otherwise,
- returns ``None``.
- """
- return self._port
-
- @port.setter
- def port(self, value):
- """Store the port number which this ``PluggableTransport`` is listening
- for incoming client connections on.
-
- :param int value: The transport's port.
- """
- if isinstance(value, int) and (0 <= value <= 65535):
- self._port = value
-
- @port.deleter
- def port(self):
- """Reset this ``PluggableTransport``'s port to ``None``."""
- self._port = None
-
- @property
def methodname(self):
"""Get this :class:`PluggableTransport`'s methodname.
@@ -632,7 +636,7 @@ class BridgeBase(BridgeAddressBase):
:rtype: int
:returns: This Bridge's default ORPort.
"""
- return self._orPort
+ return self.port
@orPort.setter
def orPort(self, value):
@@ -640,13 +644,12 @@ class BridgeBase(BridgeAddressBase):
:param int value: The Bridge's ORPort.
"""
- if isinstance(value, int) and (0 <= value <= 65535):
- self._orPort = value
+ self.port = value
@orPort.deleter
def orPort(self):
"""Reset this Bridge's ORPort."""
- self._orPort = None
+ del self.port
class BridgeBackwardsCompatibility(BridgeBase):
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits