summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2003-11-12 19:34:34 +0000
committerRoger Dingledine <arma@torproject.org>2003-11-12 19:34:34 +0000
commitf5829aa723fddb9e48f07a8e9830924c1bd8f5fb (patch)
treef0bbbf7cbf9f9346440f233c772fc0d6ced366d5
parent9358381d83d0d27db58c94cf01ab45c16292d378 (diff)
downloadtor-f5829aa723fddb9e48f07a8e9830924c1bd8f5fb.tar.gz
tor-f5829aa723fddb9e48f07a8e9830924c1bd8f5fb.zip
lay groundwork for EntryNodes and ExitNodes
svn:r805
-rw-r--r--src/or/circuit.c2
-rw-r--r--src/or/config.c19
-rw-r--r--src/or/onion.c42
-rw-r--r--src/or/or.h4
-rw-r--r--src/or/routers.c37
-rw-r--r--src/or/test.c16
6 files changed, 72 insertions, 48 deletions
diff --git a/src/or/circuit.c b/src/or/circuit.c
index 51d9cd1442..07456e082f 100644
--- a/src/or/circuit.c
+++ b/src/or/circuit.c
@@ -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;
}
diff --git a/src/or/config.c b/src/or/config.c
index f9518aead8..bef558e89e 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -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");
diff --git a/src/or/onion.c b/src/or/onion.c
index be11d2d339..7c124a5600 100644
--- a/src/or/onion.c
+++ b/src/or/onion.c
@@ -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;
}
diff --git a/src/or/or.h b/src/or/or.h
index 6aa5622e10..f1f9d2515f 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -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,
diff --git a/src/or/routers.c b/src/or/routers.c
index 7c9c787fe6..29effd1da0 100644
--- a/src/or/routers.c
+++ b/src/or/routers.c
@@ -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)) {
diff --git a/src/or/test.c b/src/or/test.c
index a653c179b0..2783232836 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -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();