[Pkg-privacy-commits] [obfsproxy] 98/353: Be able to parse IPv6 addresses.

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:01:45 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository obfsproxy.

commit 89e61d3db2c24cbf2351ca17b8c49f9059eb2e11
Author: George Kadianakis <desnacked at riseup.net>
Date:   Tue Jan 15 16:24:56 2013 +0200

    Be able to parse IPv6 addresses.
    
    Rely on pyptlib to do the parsing.
---
 obfsproxy/common/heartbeat.py         | 24 ++++++++++++++++++++++--
 obfsproxy/network/extended_orport.py  |  2 +-
 obfsproxy/network/launch_transport.py |  5 +----
 obfsproxy/transports/base.py          | 17 ++++++++---------
 4 files changed, 32 insertions(+), 16 deletions(-)

diff --git a/obfsproxy/common/heartbeat.py b/obfsproxy/common/heartbeat.py
index 2e2243e..e7aa624 100644
--- a/obfsproxy/common/heartbeat.py
+++ b/obfsproxy/common/heartbeat.py
@@ -1,12 +1,32 @@
 """heartbeat code"""
 
 import datetime
-import socket # for socket.inet_aton()
+import socket # for socket.inet_pton()
 
 import obfsproxy.common.log as logging
 
 log = logging.get_obfslogger()
 
+def get_integer_from_ip_str(ip_str):
+    """
+    Given an IP address in string format in <b>ip_str</b>, return its
+    integer representation.
+
+    Throws ValueError if the IP address string was invalid.
+    """
+    try:
+        return socket.inet_pton(socket.AF_INET, ip_str)
+    except socket.error:
+        pass
+
+    try:
+        return socket.inet_pton(socket.AF_INET6, ip_str)
+    except socket.error:
+        pass
+
+    # Down here, both inet_pton()s failed.
+    raise ValueError("Invalid IP address string")
+
 class Heartbeat(object):
     """
     Represents obfsproxy's heartbeat.
@@ -35,7 +55,7 @@ class Heartbeat(object):
         See if 'ip_str' has connected to obfsproxy before. If not, add
         it to the list of unique IPs.
         """
-        ip = socket.inet_aton(ip_str)
+        ip = get_integer_from_ip_str(ip_str)
         if ip not in self.unique_ips:
             self.unique_ips.add(ip)
 
diff --git a/obfsproxy/network/extended_orport.py b/obfsproxy/network/extended_orport.py
index a80c9dd..1f37f60 100644
--- a/obfsproxy/network/extended_orport.py
+++ b/obfsproxy/network/extended_orport.py
@@ -321,7 +321,7 @@ class ExtORPortClientFactory(network.StaticDestinationClientFactory):
 class ExtORPortServerFactory(network.StaticDestinationClientFactory):
     def __init__(self, ext_or_addrport, ext_or_cookie_file, transport_class):
         self.ext_or_host = ext_or_addrport[0]
-        self.ext_or_port = int(ext_or_addrport[1])
+        self.ext_or_port = ext_or_addrport[1]
         self.cookie_file = ext_or_cookie_file
 
         self.transport_class = transport_class
diff --git a/obfsproxy/network/launch_transport.py b/obfsproxy/network/launch_transport.py
index e04901a..dde7b75 100644
--- a/obfsproxy/network/launch_transport.py
+++ b/obfsproxy/network/launch_transport.py
@@ -40,9 +40,6 @@ def launch_transport_listener(transport, bindaddr, role, remote_addrport, ext_or
         assert(remote_addrport)
         factory = network.StaticDestinationServerFactory(remote_addrport, role, transport_class)
 
-    if role == 'server':
-        addrport = reactor.listenTCP(listen_port, factory)
-    else:
-        addrport = reactor.listenTCP(listen_port, factory, interface=listen_host)
+    addrport = reactor.listenTCP(listen_port, factory, interface=listen_host)
 
     return (addrport.getHost().host, addrport.getHost().port)
diff --git a/obfsproxy/transports/base.py b/obfsproxy/transports/base.py
index b0a7bc7..acb6598 100644
--- a/obfsproxy/transports/base.py
+++ b/obfsproxy/transports/base.py
@@ -1,7 +1,10 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 
+import pyptlib.util
+
 import obfsproxy.common.log as logging
+
 import argparse
 
 log = logging.get_obfslogger()
@@ -12,17 +15,13 @@ This module contains BaseTransport, a pluggable transport skeleton class.
 
 def addrport(string):
     """
-    Receive '<addr>:<port>' and return [<addr>,<port>].
+    Receive '<addr>:<port>' and return (<addr>,<port>).
     Used during argparse CLI parsing.
     """
-
-    addrport = string.split(':')
-
-    if (len(addrport) != 2):
-        msg = "'%s' is not in <addr>:<port> format" % string
-        raise argparse.ArgumentTypeError(msg)
-
-    return addrport
+    try:
+        return pyptlib.util.parse_addr_spec(string)
+    except ValueError, err:
+        raise argparse.ArgumentTypeError(err)
 
 class BaseTransport:
     """

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/obfsproxy.git



More information about the Pkg-privacy-commits mailing list