[tor-commits] [flashproxy/master] Style and output changes in forward_ports.

dcf at torproject.org dcf at torproject.org
Mon Jul 1 07:25:40 UTC 2013


commit 7bc60e7c01b36ea888c67347e3ce3ec24e6444b3
Author: David Fifield <david at bamsoftware.com>
Date:   Sun Jun 30 23:53:25 2013 -0700

    Style and output changes in forward_ports.
---
 flashproxy-client |   20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/flashproxy-client b/flashproxy-client
index e65a0a0..008bd95 100755
--- a/flashproxy-client
+++ b/flashproxy-client
@@ -130,26 +130,28 @@ def safe_str(s):
         return s
 
 def forward_ports(pairs):
+    """Attempt to forward all given pairs (external, internal) pairs of ports
+    using port_forwarding_helper."""
     script_path = os.path.join(get_script_dir(), "tor-fw-helper")
     command = [script_path]
+    basename = os.path.basename(command[0])
     for external, internal in pairs:
         command += ["-p", "%d:%d" % (external, internal)]
     try:
-        log(u"Attempting NAT traversal for ports " + " ".join(["%d:%d" % p for p in pairs]))
+        log(u"Running port forwarding command: %s" % " ".join(command))
         p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         stdout, stderr = p.communicate()
     except OSError, e:
-        log(u"Error opening tor-fw-helper.")
+        log(u"Error running %s: %s" % (basename, str(e)))
         return False
+    for line in stdout.splitlines():
+        log(u"%s: %s" % (basename, line))
+    for line in stderr.splitlines():
+        log(u"%s: %s" % (basename, line))
     if p.returncode != 0:
-        log("tor-fw-helper exited with status %d." % p.returncode)
+        log("%s exited with status %d." % (basename, p.returncode))
         return False
-    line = stdout.split()
-    if len(line) >= 5 and line[4] == "SUCCESS":
-        log(u"NAT traversal succeeded.")
-        return True
-    log(u"NAT traversal failed.")
-    return False
+    return True
 
 log_lock = threading.Lock()
 def log(msg):





More information about the tor-commits mailing list