[tor-commits] [flashproxy/master] Move find_client_addr to fac.py.
infinity0 at torproject.org
infinity0 at torproject.org
Mon Oct 28 14:47:41 UTC 2013
commit b7c3727f60420c65fcba6d7c870080887fac7840
Author: David Fifield <david at bamsoftware.com>
Date: Thu Oct 17 02:18:21 2013 -0700
Move find_client_addr to fac.py.
This is going to be used in common by facilitator-reg-daemon and
facilitator.cgi (the two front-end interfaces to the facilitator that
exist).
Currently we're cheating a bit and using cgi.FieldStorage to parse the
POST body in facilitator.cgi, which happens to work because of the
common URL syntax.
---
facilitator/fac.py | 16 ++++++++++++++++
facilitator/facilitator-reg-daemon | 18 +-----------------
2 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/facilitator/fac.py b/facilitator/fac.py
index 5e917d6..58db4cf 100644
--- a/facilitator/fac.py
+++ b/facilitator/fac.py
@@ -5,6 +5,7 @@ import socket
import stat
import subprocess
import pwd
+import urlparse
from collections import namedtuple
# Return true iff the given fd is readable, writable, and executable only by its
@@ -147,6 +148,21 @@ def format_addr(addr):
raise ValueError("host and port may not both be None")
return u"%s%s" % (host_str, port_str)
+def find_client_addr(body):
+ """Find and parse the first client line of the form
+ client=...
+ Returns None if no client line was found."""
+ for line in body.splitlines():
+ try:
+ qs = urlparse.parse_qs(line, keep_blank_values=True, strict_parsing=True)
+ except ValueError:
+ continue
+ client_specs = qs["client"]
+ if len(client_specs) != 1:
+ continue
+ return parse_addr_spec(client_specs[0])
+ return None
+
class Transport(namedtuple("Transport", "inner outer")):
@classmethod
diff --git a/facilitator/facilitator-reg-daemon b/facilitator/facilitator-reg-daemon
index 0eef4b4..77a6bc8 100755
--- a/facilitator/facilitator-reg-daemon
+++ b/facilitator/facilitator-reg-daemon
@@ -7,7 +7,6 @@ import socket
import sys
import threading
import time
-import urlparse
import fac
@@ -77,21 +76,6 @@ def log(msg):
finally:
log_lock.release()
-def find_client_addr(body):
- """Find and parse the first client line of the form
- client=...
- Returns None if no client line was found."""
- for line in body.splitlines():
- try:
- qs = urlparse.parse_qs(line, keep_blank_values=True, strict_parsing=True)
- except ValueError:
- continue
- client_specs = qs["client"]
- if len(client_specs) != 1:
- continue
- return fac.parse_addr_spec(client_specs[0])
- return None
-
class Handler(SocketServer.StreamRequestHandler):
def __init__(self, *args, **kwargs):
self.deadline = time.time() + CLIENT_TIMEOUT
@@ -123,7 +107,7 @@ class Handler(SocketServer.StreamRequestHandler):
try:
ciphertext = b64_ciphertext.decode("base64")
plaintext = rsa.private_decrypt(ciphertext, RSA.pkcs1_oaep_padding)
- client_addr = find_client_addr(plaintext)
+ client_addr = fac.find_client_addr(plaintext)
log(u"registering %s" % safe_str(fac.format_addr(client_addr)))
if fac.put_reg(FACILITATOR_ADDR, client_addr, "websocket"):
print >> self.wfile, "OK"
More information about the tor-commits
mailing list