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

lay groundwork for EntryNodes and ExitNodes


svn:r805
parent 9358381d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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;
    }
+13 −6
Original line number Diff line number Diff line
@@ -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");
+38 −4
Original line number Diff line number Diff line
@@ -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,7 +353,6 @@ 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];
  return 0;
}
+4 −0
Original line number Diff line number Diff line
@@ -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,
+0 −37
Original line number Diff line number Diff line
@@ -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)) {
Loading