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

[tor-commits] [bridgedb/master] Change Dist.uniformMap() to return IPv4 /16s, not /24s.



commit a1d5c24322402d13de02b4e6f9943352b79bfba2
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date:   Tue Mar 31 01:51:10 2015 +0000

    Change Dist.uniformMap() to return IPv4 /16s, not /24s.
    
    See https://trac.torproject.org/projects/tor/ticket/4771#comment:23
    
     * FIXES part of #4771.
---
 lib/bridgedb/Dist.py |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/bridgedb/Dist.py b/lib/bridgedb/Dist.py
index cd91d62..466db84 100644
--- a/lib/bridgedb/Dist.py
+++ b/lib/bridgedb/Dist.py
@@ -48,14 +48,14 @@ class EmailRequestedKey(Exception):
 
 def uniformMap(ip):
     """Map an IP to an arbitrary 'area' string, such that any two IPv4
-    addresses in the same ``/24`` subnet, or any two IPv6 addresses in the
+    addresses in the same ``/16`` subnet, or any two IPv6 addresses in the
     same ``/64`` subnet, get the same string.
 
     >>> from bridgedb import Dist
     >>> Dist.uniformMap('1.2.3.4')
-    '1.2.3.0/24'
-    >>> Dist.uniformMap('1.2.3.154')
-    '1.2.3.0/24'
+    '1.2.0.0/16'
+    >>> Dist.uniformMap('1.2.211.154')
+    '1.2.0.0/16'
     >>> Dist.uniformMap('2001:f::bc1:b13:2808')
     '2001:f::/64'
     >>> Dist.uniformMap('2a00:c98:2030:a020:2::42')
@@ -75,8 +75,8 @@ def uniformMap(ip):
         subnet = str(ipaddr.IPv6Network(truncated + "::/64"))
         return subnet
     else:
-        truncated = '.'.join(address.exploded.split('.')[:3])
-        subnet = str(ipaddr.IPv4Network(truncated + '.0/24'))
+        truncated = '.'.join(address.exploded.split('.')[:2])
+        subnet = str(ipaddr.IPv4Network(truncated + '.0.0/16'))
         return subnet
 
 def getNumBridgesPerAnswer(ring, max_bridges_per_answer=3):



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits