[tor-commits] [bridgedb/master] 4297 - ipv6 uniformMap
aagbsn at torproject.org
aagbsn at torproject.org
Sat Mar 16 23:46:31 UTC 2013
commit 3bee35c8d3977d0645bd57b8fc7bf4ef003538af
Author: aagbsn <aagbsn at extc.org>
Date: Tue Feb 28 13:21:50 2012 -0800
4297 - ipv6 uniformMap
Adds an ipv6-comptabile uniform mapper.
---
lib/bridgedb/Dist.py | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/lib/bridgedb/Dist.py b/lib/bridgedb/Dist.py
index 6a459be..95fe0b5 100644
--- a/lib/bridgedb/Dist.py
+++ b/lib/bridgedb/Dist.py
@@ -12,6 +12,7 @@ import bridgedb.Storage
import logging
import re
import time
+from ipaddr import IPv6Address, IPAddress
def uniformMap(ip):
"""Map an IP to an arbitrary 'area' string, such that any two /24 addresses
@@ -20,7 +21,10 @@ def uniformMap(ip):
>>> uniformMap('1.2.3.4')
'1.2.3'
"""
- return ".".join( ip.split(".")[:3] )
+ if type(IPAddress(ip)) is IPv6Address:
+ return ":".join(IPv6Address(ip).exploded.split(':')[:4])
+ else:
+ return ".".join( ip.split(".")[:3] )
class IPBasedDistributor(bridgedb.Bridges.BridgeHolder):
"""Object that hands out bridges based on the IP address of an incoming
More information about the tor-commits
mailing list