From 2f3741f7a3f14ba5f7cd55ddeaa993086f434c97 Mon Sep 17 00:00:00 2001 From: Nick Daly Date: Tue, 27 Mar 2012 17:27:53 -0500 Subject: [PATCH] Added (untested) proxying; load default settings sensibly. --- ugly_hacks/santiago/simple_santiago.py | 60 +++++++++++++++++--------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/ugly_hacks/santiago/simple_santiago.py b/ugly_hacks/santiago/simple_santiago.py index baa2c6c68..7433394ff 100644 --- a/ugly_hacks/santiago/simple_santiago.py +++ b/ugly_hacks/santiago/simple_santiago.py @@ -267,7 +267,7 @@ class SimpleSantiago(object): """ request = DefaultDict(lambda: None) - for k,v in kwargs.iteritems(): + for k, v in kwargs.iteritems(): request[k] = v return request @@ -295,7 +295,7 @@ class SimpleSantiago(object): return if not self.am_i(host): - self.proxy() + self.proxy(to, host, client, service, reply_to) else: self.learn_service(client, "santiago", reply_to) @@ -303,13 +303,17 @@ class SimpleSantiago(object): service, self.get_host_locations(client, service), self.get_host_locations(client, "santiago")) - def proxy(self): + def proxy(self, to, host, client, service, reply_to): """Pass off a request to another Santiago. - TODO: complete. + Attempt to contact the other Santiago and ask it to reply both to the + original host as well as me. """ - pass + self.request(self.me, to, host, client, + service, reply_to) + self.request(self.me, to, host, client, + service, self.get_client_locations(host, "santiago")) def handle_reply(self, from_, to, host, client, service, locations, reply_to): @@ -358,29 +362,45 @@ class SimpleSantiago(object): if __name__ == "__main__": # FIXME: convert this to the withsqlite setup. - for datum in ("listeners", "senders", "hosting", "consuming"): - locals()[datum] = load_data("b", datum) - # Dummy Settings: - # - # https_port = 8090 - # cert = "/tmp/santiagoTest/santiagoTest1.crt" - # listeners = { "https": { "socket_port": https_port, - # "ssl_certificate": cert, - # "ssl_private_key": cert }, } - # senders = { "https": { "host": tor_proxy, - # "port": tor_proxy_port} } - # hosting = { "a": { "santiago": set( ["https://localhost:8090"] )}, - # "b": { "santiago": set( ["https://localhost:8090"] )}} - # consuming = { "santiago": { "b": set( ["https://localhost:8090"] ), - # "a": set( ["someAddress.onion"] )}} + # load listeners + try: + listeners = load_data("b", "listeners") + except IOError: + https_port = 8090 + cert = "/tmp/santiagoTest/santiagoTest1.crt" + listeners = { "https": { "socket_port": https_port, + "ssl_certificate": cert, + "ssl_private_key": cert }, } + # load senders + try: + senders = load_data("b", "senders") + except IOError: + tor_proxy = "localhost" + tor_proxy_port = 8118 + senders = { "https": { "host": tor_proxy, + "port": tor_proxy_port} } + # load hosting + try: + hosting = load_data("b", "hosting") + except IOError: + hosting = { "a": { "santiago": set( ["https://localhost:8090"] )}, + "b": { "santiago": set( ["https://localhost:8090"] )}} + # load consuming + try: + consuming = load_data("b", "consuming") + except IOError: + consuming = { "santiago": { "b": set( ["https://localhost:8090"] ), + "a": set( ["someAddress.onion"] )}} + # load the Santiago santiago_b = SimpleSantiago(listeners, senders, hosting, consuming, "b") # TODO: integrate multiple servers: # http://docs.cherrypy.org/dev/refman/process/servers.html + # Start the application. # cherrypy.Application( cherrypy.quickstart( santiago_b, '/')