[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [bridgedb/develop] Add GeoIP CCs as bridgedb.bridges.BridgeAddressBase.country @property.
commit 38c5f2db3a02fc49584e0d0a166d11efc8314d4a
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date: Wed Feb 18 23:39:07 2015 +0000
Add GeoIP CCs as bridgedb.bridges.BridgeAddressBase.country @property.
This adds a ``country`` @property to Bridges and PluggableTransports,
which, when accessed, determines the two-letter GeoIP country code of
the bridge/PT's ``address`` @property. (Therefore, this doesn't work on
additional ORAddresses currently, but it does work on all other bridge
IP addresses.)
These changes add back in the functionality that Alden S. Page
contributed in the patches for #12872 to the bridgedb.Bridges.Bridge
class, but which had to be removed due to conflicts with the changes for
* ADD a BridgeAddressBase.country @property.
* FIXES part of #12872.
---
lib/bridgedb/bridges.py | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/lib/bridgedb/bridges.py b/lib/bridgedb/bridges.py
index 10e1ffc..b791730 100644
--- a/lib/bridgedb/bridges.py
+++ b/lib/bridgedb/bridges.py
@@ -25,6 +25,7 @@ from Crypto.Util.number import long_to_bytes
import bridgedb.Storage
+from bridgedb import geo
from bridgedb import safelog
from bridgedb import bridgerequest
from bridgedb.crypto import removePKCS1Padding
@@ -141,11 +142,15 @@ class BridgeAddressBase(object):
:type address: ``ipaddr.IPv4Address`` or ``ipaddr.IPv6Address``
:ivar address: The IP address of :class:`Bridge` or one of its
:class:`PluggableTransport`s.
+
+ :type country: str
+ :ivar country: The two-letter GeoIP country code of the :ivar:`address`.
"""
def __init__(self):
self._fingerprint = None
self._address = None
+ self._country = None
@property
def fingerprint(self):
@@ -199,6 +204,18 @@ class BridgeAddressBase(object):
"""Reset this Bridge's address to ``None``."""
self._address = None
+ @property
+ def country(self):
+ """Get the two-letter GeoIP country code for the :ivar:`address`.
+
+ :rtype: str or ``None``
+ :returns: If :ivar:`address` is set, this returns a two-letter country
+ code for the geolocated region that :ivar:`address` is within;
+ otherwise, returns ``None``.
+ """
+ if self.address:
+ return geo.getCountryCode(self.address)
+
class PluggableTransport(BridgeAddressBase):
"""A single instance of a Pluggable Transport (PT) offered by a
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits