[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [tor-bugs] #12872 [BridgeDB]: Know within which country a bridge is located
#12872: Know within which country a bridge is located
-------------------------+-------------------------------------------------
Reporter: sysrqb | Owner: isis
Type: | Status: closed
enhancement | Milestone:
Priority: blocker | Version:
Component: | Keywords: bridgedb-dist, easy,
BridgeDB | bridgedb-0.3.0, isis2014Q3Q4, isisExB
Resolution: fixed | Parent ID:
Actual Points: |
Points: |
-------------------------+-------------------------------------------------
Changes (by isis):
* keywords: bridgedb-dist, easy, bridgedb-0.2.5, isis2014Q3Q4, isisExB =>
bridgedb-dist, easy, bridgedb-0.3.0, isis2014Q3Q4, isisExB
* status: needs_review => closed
* resolution: => fixed
Comment:
[https://gitweb.torproject.org/user/isis/bridgedb.git/commit/?h=fix/12872
-bridge-geoip_r1&id=dec1d60e13087cd16cc7dd9feec1cd86828d275c Both]
[https://gitweb.torproject.org/user/isis/bridgedb.git/commit/?h=fix/12872
-bridge-geoip_r1&id=4c5c35dca9ec768d8b5db031a9253eb50b3544f7 patches] are
merged! Thanks, pagea!
I had to change a few minor things because of the changes for #9380â
Because the `bridgedb.Bridges.Bridge` class no longer exists now, these
changes:
{{{
diff --git a/lib/bridgedb/Bridges.py b/lib/bridgedb/Bridges.py
index 2439130..4b80f12 100644
--- a/lib/bridgedb/Bridges.py
+++ b/lib/bridgedb/Bridges.py
@@ -22,6 +22,7 @@ import random
import bridgedb.Storage
import bridgedb.Bucket
+import bridgedb.geo
from bridgedb.crypto import getHMACFunc
from bridgedb.parse import addr
@@ -118,6 +119,8 @@ class Bridge(object):
given in the bridge's descriptor, corresponding to desc_digest.
:attr bool verified: Did we receive the descriptor for this bridge
that
was specified in the networkstatus?
+ :attr str countryCode: The two-letter country code of this bridge as
+ reported by GeoIP.
"""
def __init__(self, nickname, ip, orport, fingerprint=None,
id_digest=None,
or_addresses=None, transports=None):
@@ -135,6 +138,7 @@ class Bridge(object):
self.desc_digest = None
self.ei_digest = None
self.verified = False
+ self.countryCode = None
if id_digest is not None:
assert fingerprint is None
@@ -149,6 +153,13 @@ class Bridge(object):
else:
raise TypeError("Bridge with no ID")
+ # Determine the country code of this bridge.
+ self.countryCode = bridgedb.geo.getCountryCode(ip)
+ if self.countryCode is None:
+ logging.debug(" Bridge: Country code not detected. IP: %s" %
ip)
+ else:
+ logging.debug(" Bridge: Country code found: %s" %
self.countryCode)
+
def setDescriptorDigest(self, digest):
"""Set the descriptor digest, specified in the NS."""
self.desc_digest = digest
}}}
[https://gitweb.torproject.org/user/isis/bridgedb.git/commit/?h=fix/12872
-bridge-geoip_r1&id=38c5f2db3a02fc49584e0d0a166d11efc8314d4a have been
refactored] into the `bridgedb.brides.BridgeAddressBase` class, so that
the GeoIP country code can be obtained for both a Bridge's main ORAddress,
as well as any of its Pluggable Transport addresses:
{{{
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
}}}
Additionally, I made a couple
[https://gitweb.torproject.org/user/isis/bridgedb.git/commit/?h=fix/12872
-bridge-geoip_r1&id=e38e1374acb3bf6e21ffafe8b4edfe0003b80d1a tiny]
[https://gitweb.torproject.org/user/isis/bridgedb.git/commit/?h=fix/12872
-bridge-geoip_r1&id=45b092770e776e19189f66a5aa081331a367f7fa fixes] and
added
[https://gitweb.torproject.org/user/isis/bridgedb.git/commit/?h=fix/12872
-bridge-geoip_r1&id=feeb440961f3c8db4cc4e2476ee0373c4f49da94 unittests]
[https://gitweb.torproject.org/user/isis/bridgedb.git/commit/?h=fix/12872
-bridge-geoip_r1&id=fdf4afad33f8759f4154797a4bd37d678ff40daa for]
[https://gitweb.torproject.org/user/isis/bridgedb.git/commit/?h=fix/12872
-bridge-geoip_r1&id=21b9a3916c273e483a58d1101eb3991f65afc00b all] the
relevant code.
--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/12872#comment:16>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online
_______________________________________________
tor-bugs mailing list
tor-bugs@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-bugs