From d982925593dbb724e4c8ebeb4f945c2184f11831 Mon Sep 17 00:00:00 2001 From: Roger Dingledine Date: Tue, 2 Jul 2002 09:36:58 +0000 Subject: Integrated onion proxy into or/ The 'or' process can now be told (by the global_role variable) what roles this server should play -- connect to all ORs, listen for ORs, listen for OPs, listen for APs, or any combination. * everything in /src/op/ is now obsolete. * connection_ap.c now handles all interactions with application proxies * "port" is now or_port, op_port, ap_port. But routers are still always referenced (say, in conn_get_by_addr_port()) by addr / or_port. We should make routers.c actually read these new ports (currently I've kludged it so op_port = or_port+10, ap_port=or_port+20) * circuits currently know if they're at the beginning of the path because circ->cpath is set. They use this instead for crypts (both ways), if it's set. * I still obey the "send a 0 back to the AP when you're ready" protocol, but I think we should phase it out. I can simply not read from the AP socket until I'm ready. I need to do a lot of cleanup work here, but the code appears to work, so now's a good time for a checkin. svn:r22 --- src/or/main.c | 80 ++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 28 deletions(-) (limited to 'src/or/main.c') diff --git a/src/or/main.c b/src/or/main.c index 2cac0819c..543b1ea3f 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -8,20 +8,24 @@ static char *args = "hf:e:n:l:"; int loglevel = LOG_DEBUG; +int global_role = ROLE_OR_LISTEN | ROLE_OR_CONNECT_ALL | ROLE_OP_LISTEN | ROLE_AP_LISTEN; +/* FIXME defaulting to all roles for now. should make it a config option though */ + /* valid config file options */ config_opt_t options[] = { {"RouterFile", CONFIG_TYPE_STRING, {0}, 0}, {"PrivateKeyFile", CONFIG_TYPE_STRING, {0}, 0}, - {"EntryPort", CONFIG_TYPE_INT, {0}, 0}, - {"NetworkPort", CONFIG_TYPE_INT, {0}, 0}, + {"APPort", CONFIG_TYPE_INT, {0}, 0}, + {"OPPort", CONFIG_TYPE_INT, {0}, 0}, + {"ORPort", CONFIG_TYPE_INT, {0}, 0}, + {"CoinWeight", CONFIG_TYPE_DOUBLE, {0}, 0}, {"MaxConn", CONFIG_TYPE_INT, {0}, 0}, - {"MaxConnTimeout", CONFIG_TYPE_INT, {0}, 0}, {"TrafficShaping", CONFIG_TYPE_INT, {0}, 0}, {0} }; enum opts { - RouterFile=0, PrivateKeyFile, EntryPort, NetworkPort, MaxConn, MaxConnTimeout, TrafficShaping + RouterFile=0, PrivateKeyFile, APPort, OPPort, ORPort, CoinWeight, MaxConn, TrafficShaping }; connection_t *connection_array[MAXCONNECTIONS] = @@ -138,7 +142,7 @@ routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port) { for(i=0;iaddr == addr) && (router->port == port)) + if ((router->addr == addr) && (router->or_port == port)) return router; } @@ -146,6 +150,24 @@ routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port) { } +routerinfo_t *router_get_first_in_route(unsigned int *route, size_t routelen) { + return router_array[route[routelen-1]]; +} + +/* a wrapper around new_route. put all these in routers.c perhaps? */ +unsigned int *router_new_route(size_t *rlen) { + return new_route(options[CoinWeight].r.d, router_array,rarray_len, rlen); +} + +/* a wrapper around create_onion */ +unsigned char *router_create_onion(unsigned int *route, size_t routelen, size_t *lenp, crypt_path_t **cpathp) { + return create_onion(router_array,rarray_len,route,routelen,lenp,cpathp); +} + +connection_t *connect_to_router_as_op(routerinfo_t *router) { + return connection_connect_to_router_as_op(router, prkey, options[ORPort].r.i); +} + void connection_watch_events(connection_t *conn, short events) { assert(conn && conn->poll_index < nfds); @@ -167,6 +189,8 @@ void check_conn_read(int i) { retval = connection_op_handle_listener_read(conn); } else if (conn->type == CONN_TYPE_OR_LISTENER) { retval = connection_or_handle_listener_read(conn); + } else if (conn->type == CONN_TYPE_AP_LISTENER) { + retval = connection_ap_handle_listener_read(conn); } else { /* else it's an OP, OR, or exit */ retval = connection_read_to_buf(conn); @@ -228,7 +252,10 @@ void check_conn_marked(int i) { assert(conn); if(conn->marked_for_close) { log(LOG_DEBUG,"check_conn_marked(): Cleaning up connection."); - connection_flush_buf(conn); /* flush it first */ + if(conn->s >= 0) { /* might be an incomplete exit connection */ + /* FIXME there's got to be a better way to check for this -- and make other checks? */ + connection_flush_buf(conn); /* flush it first */ + } connection_remove(conn); connection_free(conn); if(i