Commit ddc2b69a authored by Roger Dingledine's avatar Roger Dingledine
Browse files

onion proxies now work (i think)


svn:r96
parent 5948f143
......@@ -188,37 +188,44 @@ RETURN VALUE: 0 on success, non-zero on error
}
}
if ( options->Role < 0 || options->Role > 15 )
{
log(LOG_ERR,"Role option must be an integer between 0 and 15 (inclusive).");
code = -1;
}
if ( options->RouterFile == NULL )
{
log(LOG_ERR,"RouterFile option required, but not found.");
code = -1;
}
if ( options->PrivateKeyFile == NULL )
if ( ROLE_IS_OR(options->Role) && options->PrivateKeyFile == NULL )
{
log(LOG_ERR,"PrivateKeyFile option required, but not found.");
log(LOG_ERR,"PrivateKeyFile option required for OR, but not found.");
code = -1;
}
if ( options->ORPort < 1 )
if ( (options->Role & ROLE_OR_LISTEN) && options->ORPort < 1 )
{
log(LOG_ERR,"ORPort option required and must be a positive integer value.");
code = -1;
}
if ( options->OPPort < 1 )
if ( (options->Role & ROLE_OP_LISTEN) && options->OPPort < 1 )
{
log(LOG_ERR,"OPPort option required and must be a positive integer value.");
code = -1;
}
if ( options->APPort < 1 )
if ( (options->Role & ROLE_AP_LISTEN) && options->APPort < 1 )
{
log(LOG_ERR,"APPort option required and must be a positive integer value.");
code = -1;
}
if ( options->CoinWeight < 0.0 || options->CoinWeight >= 1.0 )
if ( (options->Role & ROLE_AP_LISTEN) &&
(options->CoinWeight < 0.0 || options->CoinWeight >= 1.0) )
{
log(LOG_ERR,"CoinWeight option must be a value from 0.0 upto 1.0, but not including 1.0.");
code = -1;
......@@ -248,12 +255,6 @@ RETURN VALUE: 0 on success, non-zero on error
code = -1;
}
if ( options->Role < 0 || options->Role > 15 )
{
log(LOG_ERR,"Role option must be an integer between 0 and 15 (inclusive).");
code = -1;
}
return code;
}
......@@ -297,13 +297,13 @@ int retry_all_connections(int role, routerinfo_t **router_array, int rarray_len,
return 0;
}
connection_t *connection_connect_to_router_as_op(routerinfo_t *router, crypto_pk_env_t *prkey, uint16_t local_or_port) {
connection_t *connection_connect_to_router_as_op(routerinfo_t *router, uint16_t local_or_port) {
struct sockaddr_in local; /* local address */
if(learn_local(&local) < 0)
return NULL;
local.sin_port = htons(local_or_port);
return connection_or_connect_as_op(router, prkey, &local);
return connection_or_connect_as_op(router, &local);
}
int connection_read_to_buf(connection_t *conn) {
......@@ -356,7 +356,7 @@ int connection_write_to_buf(char *string, int len, connection_t *conn) {
if(!len)
return 0;
if( (conn->type != CONN_TYPE_OR && conn->type != CONN_TYPE_OR) ||
if( (!connection_speaks_cells(conn)) ||
(!connection_state_is_open(conn)) ||
(options.LinkPadding == 0) ) {
/* connection types other than or and op, or or/op not in 'open' state, should flush immediately */
......@@ -528,8 +528,9 @@ int connection_encrypt_cell(cell_t *cellp, connection_t *conn) {
}
#if 0
printf("Sending: Cell header crypttext: ");
px = (char *)&newcell;
for(x=0;x<8;x++) {
printf("%u ",newheader[x]);
printf("%u ",px[x]);
}
printf("\n");
#endif
......
......@@ -218,21 +218,25 @@ connection_t *connection_or_connect(routerinfo_t *router, crypto_pk_env_t *prkey
*
*/
connection_t *connection_or_connect_as_op(routerinfo_t *router, crypto_pk_env_t *prkey, struct sockaddr_in *local) {
connection_t *connection_or_connect_as_op(routerinfo_t *router, struct sockaddr_in *local) {
connection_t *conn;
int result=0; /* so connection_or_connect() can tell us what happened */
assert(router && prkey && local);
assert(router && local);
if(router->addr == local->sin_addr.s_addr && router->or_port == ntohs(local->sin_port)) {
/* this is me! don't connect to me. */
log(LOG_WARNING,"connection_or_connect_as_op(): You just asked me to connect to myself.");
return NULL;
}
/* this function should never be called if we're already connected to router, but */
/* FIXME we should check here if we're already connected, and return the conn */
/* check first to be sure */
conn = connection_exact_get_by_addr_port(router->addr,router->or_port);
if(conn)
return conn;
conn = connection_or_connect(router, prkey, local, router->op_port, &result);
conn = connection_or_connect(router, NULL, local, router->op_port, &result);
if(!conn)
return NULL;
......@@ -276,6 +280,7 @@ int or_handshake_op_send_keys(connection_t *conn) {
*(uint32_t *)message = htonl(bandwidth);
memcpy((void *)(message + 4), (void *)conn->f_crypto->key, 8);
memcpy((void *)(message + 12), (void *)conn->b_crypto->key, 8);
#if 0
printf("f_session_key: ");
for(x=0;x<8;x++) {
......
......@@ -198,8 +198,9 @@ unsigned char *router_create_onion(unsigned int *route, int routelen, int *len,
/* FIXME can we cut this function out? */
connection_t *connect_to_router_as_op(routerinfo_t *router) {
return connection_connect_to_router_as_op(router, prkey, options.ORPort);
return connection_connect_to_router_as_op(router, options.ORPort);
}
void connection_watch_events(connection_t *conn, short events) {
......@@ -418,16 +419,18 @@ int do_main_loop(void) {
return -1;
}
/* load the private key */
prkey = crypto_new_pk_env(CRYPTO_PK_RSA);
if (!prkey) {
log(LOG_ERR,"Error creating a crypto environment.");
return -1;
}
if (crypto_pk_read_private_key_filename(prkey, options.PrivateKeyFile))
{
log(LOG_ERR,"Error loading private key.");
return -1;
/* load the private key, if we're supposed to have one */
if(ROLE_IS_OR(global_role)) {
prkey = crypto_new_pk_env(CRYPTO_PK_RSA);
if (!prkey) {
log(LOG_ERR,"Error creating a crypto environment.");
return -1;
}
if (crypto_pk_read_private_key_filename(prkey, options.PrivateKeyFile))
{
log(LOG_ERR,"Error loading private key.");
return -1;
}
}
/* start-up the necessary connections based on global_role. This is where we
......
......@@ -4,6 +4,8 @@
#include "or.h"
extern int global_role; /* from main.c */
/********* START VARIABLES **********/
tracked_onion_t *tracked_onions = NULL; /* linked list of tracked onions */
......@@ -109,8 +111,9 @@ unsigned int *new_route(double cw, routerinfo_t **rarray, int rarray_len, int *r
log(LOG_DEBUG,"new_route(): Chosen route length %d.",*routelen);
for(i=0;i<rarray_len;i++) {
log(LOG_DEBUG,"Contemplating whether router %d is any good...",i);
if(!connection_exact_get_by_addr_port(rarray[i]->addr, rarray[i]->or_port)) {
log(LOG_DEBUG,"Contemplating whether router %d is a new option...",i);
if( (global_role & ROLE_OR_CONNECT_ALL) &&
!connection_exact_get_by_addr_port(rarray[i]->addr, rarray[i]->or_port)) {
log(LOG_DEBUG,"Nope, %d is not connected.",i);
goto next_i_loop;
}
......@@ -156,7 +159,7 @@ unsigned int *new_route(double cw, routerinfo_t **rarray, int rarray_len, int *r
log(LOG_DEBUG,"new_route(): Contemplating router %u.",choice);
if(choice == oldchoice ||
(oldchoice < rarray_len && !pkey_cmp(rarray[choice]->pkey, rarray[oldchoice]->pkey)) ||
!connection_twin_get_by_addr_port(rarray[choice]->addr, rarray[choice]->or_port)) {
((global_role & ROLE_OR_CONNECT_ALL) && !connection_twin_get_by_addr_port(rarray[choice]->addr, rarray[choice]->or_port))) {
/* Same router as last choice, or router twin,
* or no routers with that key are connected to us.
* Try again. */
......
......@@ -56,6 +56,8 @@
#define ROLE_OP_LISTEN 4
#define ROLE_AP_LISTEN 8
#define ROLE_IS_OR(role) ((role & ROLE_OR_LISTEN) || (role & ROLE_OR_CONNECT_ALL) || (role & ROLE_OP_LISTEN))
#define CONN_TYPE_OP_LISTENER 1
#define CONN_TYPE_OP 2
#define CONN_TYPE_OR_LISTENER 3
......@@ -413,7 +415,7 @@ int connection_handle_listener_read(connection_t *conn, int new_type, int new_st
/* start all connections that should be up but aren't */
int retry_all_connections(int role, routerinfo_t **router_array, int rarray_len,
crypto_pk_env_t *prkey, uint16_t or_port, uint16_t op_port, uint16_t ap_port);
connection_t *connection_connect_to_router_as_op(routerinfo_t *router, crypto_pk_env_t *prkey, uint16_t local_or_port);
connection_t *connection_connect_to_router_as_op(routerinfo_t *router, uint16_t local_or_port);
int connection_read_to_buf(connection_t *conn);
......@@ -509,7 +511,7 @@ int or_handshake_server_process_nonce(connection_t *conn);
connection_t *connect_to_router_as_or(routerinfo_t *router, crypto_pk_env_t *prkey, struct sockaddr_in *local);
connection_t *connection_or_connect_as_or(routerinfo_t *router, crypto_pk_env_t *prkey, struct sockaddr_in *local);
connection_t *connection_or_connect_as_op(routerinfo_t *router, crypto_pk_env_t *prkey, struct sockaddr_in *local);
connection_t *connection_or_connect_as_op(routerinfo_t *router, struct sockaddr_in *local);
int connection_or_create_listener(crypto_pk_env_t *prkey, struct sockaddr_in *local);
int connection_or_handle_listener_read(connection_t *conn);
......
......@@ -14,6 +14,8 @@
#include "or.h"
extern int global_role; /* from main.c */
/* private function, to determine whether the current entry in the router list is actually us */
static int router_is_me(uint32_t or_address, uint16_t or_listenport, uint16_t my_or_listenport)
{
......@@ -25,6 +27,11 @@ static int router_is_me(uint32_t or_address, uint16_t or_listenport, uint16_t my
char *addr = NULL;
int i = 0;
if(!ROLE_IS_OR(global_role)) {
/* we're not an OR. This obviously isn't us. */
return 0;
}
/* obtain local host information */
if (gethostname(localhostname,512) < 0) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment