[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [flashproxy/master] make fac.py in flashproxy-common not soft-implicit-depends on facilitator-reg
commit def182a2501070fa5dfcb9793fe977c58b0861ae
Author: Ximin Luo <infinity0@xxxxxxx>
Date: Thu Nov 21 18:57:23 2013 +0000
make fac.py in flashproxy-common not soft-implicit-depends on facilitator-reg
- to do this, we turn put_reg_base64 into a generic run-a-program function
- also push the pad-base64 behaviour directly into facilitator-reg
- fix earlier oversight, and document the fact that facilitator-reg is used
---
facilitator/doc/facilitator-design.txt | 4 ++--
facilitator/facilitator-email-poller | 2 +-
facilitator/facilitator-reg | 7 ++++++-
facilitator/facilitator.cgi | 2 +-
flashproxy/fac.py | 14 ++++----------
5 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/facilitator/doc/facilitator-design.txt b/facilitator/doc/facilitator-design.txt
index 20f9c0a..19d5d47 100644
--- a/facilitator/doc/facilitator-design.txt
+++ b/facilitator/doc/facilitator-design.txt
@@ -5,8 +5,8 @@ pass them to the backend. There are three supported helper rendezvous
methods: HTTP, email, and appspot.
facilitator-reg is a simple program that forwards its standard input to
-a locally running facilitator-reg-daemon process. It is not used by the
-other components, but is useful for debugging and test purposes.
+a locally running facilitator-reg-daemon process. It is used by other
+components as a utility, but is also useful for debugging and testing.
facilitator-reg-daemon accepts connections containing encrypted client
registrations and forwards them to the facilitator. It exists as a
diff --git a/facilitator/facilitator-email-poller b/facilitator/facilitator-email-poller
index 9c35df1..8a5c972 100755
--- a/facilitator/facilitator-email-poller
+++ b/facilitator/facilitator-email-poller
@@ -265,7 +265,7 @@ def message_ok(msg):
def handle_message(msg):
try:
- if fac.put_reg_base64(msg.get_payload()):
+ if fac.put_reg_proc(["facilitator-reg"], msg.get_payload()):
log(u"registered client")
else:
log(u"failed to register client")
diff --git a/facilitator/facilitator-reg b/facilitator/facilitator-reg
index 5346dcc..3a3d196 100755
--- a/facilitator/facilitator-reg
+++ b/facilitator/facilitator-reg
@@ -48,11 +48,16 @@ def main():
s = socket.socket(addrinfo[0], addrinfo[1], addrinfo[2])
s.connect(addrinfo[4])
+ sent = 0
while True:
data = sys.stdin.read(1024)
if data == "":
+ mod = sent % 4
+ if mod != 0:
+ s.sendall((4 - mod) * "=")
break
- s.send(data)
+ s.sendall(data)
+ sent += len(data)
s.shutdown(socket.SHUT_WR)
data = s.recv(1024)
diff --git a/facilitator/facilitator.cgi b/facilitator/facilitator.cgi
index addcaf4..10f4b19 100755
--- a/facilitator/facilitator.cgi
+++ b/facilitator/facilitator.cgi
@@ -23,7 +23,7 @@ def exit_error(status):
def send_url_reg(reg):
# Translate from url-safe base64 alphabet to the standard alphabet.
reg = reg.replace('-', '+').replace('_', '/')
- return fac.put_reg_base64(reg)
+ return fac.put_reg_proc(["facilitator-reg"], reg)
method = os.environ.get("REQUEST_METHOD")
remote_addr = (os.environ.get("REMOTE_ADDR"), None)
diff --git a/flashproxy/fac.py b/flashproxy/fac.py
index 0686f54..25c1f84 100644
--- a/flashproxy/fac.py
+++ b/flashproxy/fac.py
@@ -211,14 +211,8 @@ def get_reg(facilitator_addr, proxy_addr, proxy_transport_list):
else:
raise ValueError("Facilitator response was not \"OK\"")
-def put_reg_base64(b64):
- """Attempt to add a registration by running a facilitator-reg program
- locally."""
- # Padding is optional, but the python base64 functions can't
- # handle lack of padding. Add it here. Assumes correct encoding.
- mod = len(b64) % 4
- if mod != 0:
- b64 += (4 - mod) * "="
- p = subprocess.Popen(["facilitator-reg"], stdin=subprocess.PIPE)
- stdout, stderr = p.communicate(b64)
+def put_reg_proc(args, data):
+ """Attempt to add a registration by running a program."""
+ p = subprocess.Popen(args, stdin=subprocess.PIPE)
+ stdout, stderr = p.communicate(data)
return p.returncode == 0
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits