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

lay groundwork for EntryNodes and ExitNodes


svn:r805
parent 9358381d
......@@ -766,7 +766,7 @@ int circuit_send_next_onion_skin(circuit_t *circ) {
* circuit that one is ready. */
connection_ap_attach_pending();
return 0;
} else if (r<0 || !router) {
} else if (r<0) {
log_fn(LOG_WARN,"Unable to extend circuit path.");
return -1;
}
......
......@@ -161,6 +161,8 @@ static void config_assign(or_options_t *options, struct config_line *list) {
config_compare(list, "DirBindAddress", CONFIG_TYPE_STRING, &options->DirBindAddress) ||
config_compare(list, "DirFetchPostPeriod",CONFIG_TYPE_INT, &options->DirFetchPostPeriod) ||
config_compare(list, "ExitNodes", CONFIG_TYPE_STRING, &options->ExitNodes) ||
config_compare(list, "EntryNodes", CONFIG_TYPE_STRING, &options->EntryNodes) ||
config_compare(list, "ExitPolicy", CONFIG_TYPE_STRING, &options->ExitPolicy) ||
config_compare(list, "Group", CONFIG_TYPE_STRING, &options->Group) ||
......@@ -210,17 +212,18 @@ static void config_assign(or_options_t *options, struct config_line *list) {
void print_usage(void) {
printf("tor -f <torrc> [args]\n"
"-d <file>\t\tDebug file\n"
"-e <policy>\t\tExit policy\n"
"-l <level>\t\tLog level\n"
"-m <max>\t\tMax number of connections\n"
"-l <level>\t\tLog level\n"
"-t <bandwidth>\t\tTotal bandwidth\n"
"-r <file>\t\tList of known routers\n");
printf("\nClient options:\n"
"-e \"nick1 nick2 ...\"\t\tExit nodes\n"
"-s <IP>\t\t\tPort to bind to for Socks\n"
);
/* split things up to be ANSI compliant */
printf("-n <nick>\t\tNickname of router\n"
printf("\nServer options:\n"
"-n <nick>\t\tNickname of router\n"
"-o <port>\t\tOR port to bind to\n"
"-p <file>\t\tPID file\n"
"-r <file>\t\tRouter config file\n"
"-t <bandwidth>\t\tTotal bandwidth\n"
);
}
......@@ -233,6 +236,8 @@ void free_options(or_options_t *options) {
tor_free(options->Nickname);
tor_free(options->Address);
tor_free(options->PidFile);
tor_free(options->ExitNodes);
tor_free(options->EntryNodes);
tor_free(options->ExitPolicy);
tor_free(options->SocksBindAddress);
tor_free(options->ORBindAddress);
......@@ -245,6 +250,8 @@ void init_options(or_options_t *options) {
/* give reasonable values for each option. Defaults to zero. */
memset(options,0,sizeof(or_options_t));
options->LogLevel = tor_strdup("info");
options->ExitNodes = tor_strdup("");
options->EntryNodes = tor_strdup("");
options->ExitPolicy = tor_strdup("reject 127.0.0.1:*");
options->SocksBindAddress = tor_strdup("127.0.0.1");
options->ORBindAddress = tor_strdup("0.0.0.0");
......
......@@ -157,6 +157,36 @@ int onionskin_answer(circuit_t *circ, unsigned char *payload, unsigned char *key
return 0;
}
char **parse_nickname_list(char *list, int *num) {
char **out;
char *start,*end;
int i;
while(isspace(*list)) list++;
i=0, start = list;
while(*start) {
while(*start && !isspace(*start)) start++;
i++;
while(isspace(*start)) start++;
}
out = tor_malloc(i * sizeof(char *));
i=0, start=list;
while(*start) {
end=start; while(*end && !isspace(*end)) end++;
out[i] = tor_malloc(MAX_NICKNAME_LEN);
strncpy(out[i],start,end-start);
out[i][end-start] = 0; /* null terminate it */
i++;
while(isspace(*end)) end++;
start = end;
}
*num = i;
return out;
}
/* uses a weighted coin with weight cw to choose a route length */
static int chooselen(double cw) {
int len = 2;
......@@ -254,10 +284,11 @@ int onion_extend_cpath(crypt_path_t **head_ptr, int path_len, routerinfo_t **rou
int rarray_len;
int i;
directory_t *dir;
char **nicknames;
int num_nicknames;
assert(head_ptr);
if (router_out)
*router_out = NULL;
assert(router_out);
router_get_directory(&dir);
rarray = dir->routers;
......@@ -275,6 +306,10 @@ int onion_extend_cpath(crypt_path_t **head_ptr, int path_len, routerinfo_t **rou
log_fn(LOG_DEBUG, "Path is %d long; we want %d", cur_len, path_len);
again:
if(cur_len == 0) { /* picking entry node */
}
choice = crypto_pseudo_rand_int(rarray_len);
log_fn(LOG_DEBUG,"Contemplating router %s for hop %d",
rarray[choice]->nickname, cur_len);
......@@ -318,8 +353,7 @@ int onion_extend_cpath(crypt_path_t **head_ptr, int path_len, routerinfo_t **rou
log_fn(LOG_DEBUG, "Extended circuit path with %s for hop %d",
rarray[choice]->nickname, cur_len);
if (router_out)
*router_out = rarray[choice];
*router_out = rarray[choice];
return 0;
}
......
......@@ -432,6 +432,8 @@ typedef struct {
char *Nickname;
char *Address;
char *PidFile;
char *ExitNodes;
char *EntryNodes;
char *ExitPolicy;
char *SocksBindAddress;
char *ORBindAddress;
......@@ -693,6 +695,8 @@ void onion_pending_remove(circuit_t *circ);
int onionskin_answer(circuit_t *circ, unsigned char *payload, unsigned char *keys);
char **parse_nickname_list(char *start, int *num);
int onion_extend_cpath(crypt_path_t **head_ptr, int path_len, routerinfo_t **router_out);
int onion_skin_create(crypto_pk_env_t *router_key,
......
......@@ -29,9 +29,6 @@ typedef struct directory_token directory_token_t;
/* static function prototypes */
void routerlist_free(routerinfo_t *list);
static char *eat_whitespace(char *s);
static char *eat_whitespace_no_nl(char *s);
static char *find_whitespace(char *s);
static int router_add_exit_policy_from_string(routerinfo_t *router, char *s);
static int router_add_exit_policy(routerinfo_t *router,
directory_token_t *tok);
......@@ -428,40 +425,6 @@ router_get_next_token(char **s, directory_token_t *tok) {
#define router_get_next_token _router_get_next_token
#endif
/* return the first char of s that is not whitespace and not a comment */
static char *eat_whitespace(char *s) {
assert(s);
while(isspace(*s) || *s == '#') {
while(isspace(*s))
s++;
if(*s == '#') { /* read to a \n or \0 */
while(*s && *s != '\n')
s++;
if(!*s)
return s;
}
}
return s;
}
static char *eat_whitespace_no_nl(char *s) {
while(*s == ' ' || *s == '\t')
++s;
return s;
}
/* return the first char of s that is whitespace or '#' or '\0 */
static char *find_whitespace(char *s) {
assert(s);
while(*s && !isspace(*s) && *s != '#')
s++;
return s;
}
int router_get_list_from_string(char *s)
{
if (router_get_list_from_string_impl(&s, &directory, -1, NULL)) {
......
......@@ -464,6 +464,21 @@ test_util() {
test_eq((time_t) 1076393695UL, tor_timegm(&a_time));
}
void test_onion() {
char **names;
int i,num;
names = parse_nickname_list(" foo bar baz quux ", &num);
test_eq(num,4);
test_streq(names[0],"foo");
test_streq(names[1],"bar");
test_streq(names[2],"baz");
test_streq(names[3],"quux");
for(i=0;i<num;i++)
tor_free(names[i]);
tor_free(names);
}
void
test_onion_handshake() {
/* client-side */
......@@ -693,6 +708,7 @@ main(int c, char**v){
puts("\n========================= Util ============================");
test_util();
puts("\n========================= Onion Skins =====================");
test_onion();
test_onion_handshake();
puts("\n========================= Directory Formats ===============");
test_dir_format();
......
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