Commit 3bee35c8 authored by aagbsn's avatar aagbsn
Browse files

4297 - ipv6 uniformMap

Adds an ipv6-comptabile uniform mapper.
parent ee4d719b
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -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,6 +21,9 @@ def uniformMap(ip):
    >>> uniformMap('1.2.3.4')
    '1.2.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):