[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] outline what bob does to initialize his hidden services



Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or

Modified Files:
	circuit.c main.c or.h rendservice.c router.c 
Log Message:
outline what bob does to initialize his hidden services

let circuit_launch_new return the circ it just made


Index: circuit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuit.c,v
retrieving revision 1.163
retrieving revision 1.164
diff -u -d -r1.163 -r1.164
--- circuit.c	1 Apr 2004 01:57:21 -0000	1.163
+++ circuit.c	1 Apr 2004 03:23:27 -0000	1.164
@@ -15,7 +15,7 @@
 
 static void circuit_is_ready(circuit_t *circ);
 static void circuit_failed(circuit_t *circ);
-static int circuit_establish_circuit(uint8_t purpose);
+static circuit_t *circuit_establish_circuit(uint8_t purpose);
 
 unsigned long stats_n_relay_cells_relayed = 0;
 unsigned long stats_n_relay_cells_delivered = 0;
@@ -1051,21 +1051,19 @@
  */
 static int n_circuit_failures = 0;
 
-/* Return -1 if you aren't going to try to make a circuit, 0 if you did try. */
-int circuit_launch_new(uint8_t purpose) {
+/* Launch a new circuit and return a pointer to it. Return NULL if you failed. */
+circuit_t *circuit_launch_new(uint8_t purpose) {
 
   if(!(options.SocksPort||options.RunTesting)) /* no need for circuits. */
-    return -1;
+    return NULL;
 
   if(n_circuit_failures > 5) { /* too many failed circs in a row. don't try. */
 //    log_fn(LOG_INFO,"%d failures so far, not trying.",n_circuit_failures);
-    return -1;
+    return NULL;
   }
 
   /* try a circ. if it fails, circuit_mark_for_close will increment n_circuit_failures */
-  circuit_establish_circuit(purpose);
-
-  return 0;
+  return circuit_establish_circuit(purpose);
 }
 
 void circuit_increment_failure_count(void) {
@@ -1077,7 +1075,7 @@
   n_circuit_failures = 0;
 }
 
-static int circuit_establish_circuit(uint8_t purpose) {
+static circuit_t *circuit_establish_circuit(uint8_t purpose) {
   routerinfo_t *firsthop;
   connection_t *n_conn;
   circuit_t *circ;
@@ -1090,14 +1088,14 @@
   if (! circ->build_state) {
     log_fn(LOG_INFO,"Generating cpath length failed.");
     circuit_mark_for_close(circ);
-    return -1;
+    return NULL;
   }
 
   onion_extend_cpath(&circ->cpath, circ->build_state, &firsthop);
   if(!circ->cpath) {
     log_fn(LOG_INFO,"Generating first cpath hop failed.");
     circuit_mark_for_close(circ);
-    return -1;
+    return NULL;
   }
 
   /* now see if we're already connected to the first OR in 'route' */
@@ -1111,7 +1109,7 @@
     if(options.ORPort) { /* we would be connected if he were up. and he's not. */
       log_fn(LOG_INFO,"Route's firsthop isn't connected.");
       circuit_mark_for_close(circ);
-      return -1;
+      return NULL;
     }
 
     if(!n_conn) { /* launch the connection */
@@ -1119,14 +1117,15 @@
       if(!n_conn) { /* connect failed, forget the whole thing */
         log_fn(LOG_INFO,"connect to firsthop failed. Closing.");
         circuit_mark_for_close(circ);
-        return -1;
+        return NULL;
       }
     }
 
     log_fn(LOG_DEBUG,"connecting in progress (or finished). Good.");
-    return 0; /* return success. The onion/circuit/etc will be taken care of automatically
-               * (may already have been) whenever n_conn reaches OR_CONN_STATE_OPEN.
-               */
+    /* return success. The onion/circuit/etc will be taken care of automatically
+     * (may already have been) whenever n_conn reaches OR_CONN_STATE_OPEN.
+     */
+    return circ;
   } else { /* it (or a twin) is already open. use it. */
     circ->n_addr = n_conn->addr;
     circ->n_port = n_conn->port;
@@ -1135,10 +1134,10 @@
     if(circuit_send_next_onion_skin(circ) < 0) {
       log_fn(LOG_INFO,"circuit_send_next_onion_skin failed.");
       circuit_mark_for_close(circ);
-      return -1;
+      return NULL;
     }
   }
-  return 0;
+  return circ;
 }
 
 /* find circuits that are waiting on me, if any, and get them to send the onion */

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.218
retrieving revision 1.219
diff -u -d -r1.218 -r1.219
--- main.c	1 Apr 2004 01:57:22 -0000	1.218
+++ main.c	1 Apr 2004 03:23:28 -0000	1.219
@@ -281,9 +281,12 @@
 
   log_fn(LOG_INFO, "We now have a directory.");
 
+  /* just for testing */
   directory_initiate_command(router_pick_directory_server(),
                              DIR_PURPOSE_FETCH_HIDSERV, "foo", 3);
 
+  rend_services_init(); /* get bob to initialize all his hidden services */
+
 }
 
 /* Perform regular maintenance tasks for a single connection.  This
@@ -332,7 +335,7 @@
     /* it's time to fetch a new directory and/or post our descriptor */
     if(options.ORPort) {
       router_rebuild_descriptor();
-      router_upload_desc_to_dirservers();
+      router_upload_dir_desc_to_dirservers();
     }
     if(!options.DirPort) {
       /* NOTE directory servers do not currently fetch directories.
@@ -574,7 +577,7 @@
 
   if(options.ORPort) {
     cpu_init(); /* launch cpuworkers. Need to do this *after* we've read the onion key. */
-    router_upload_desc_to_dirservers(); /* upload our descriptor to all dirservers */
+    router_upload_dir_desc_to_dirservers(); /* upload our descriptor to all dirservers */
   }
 
   /* start up the necessary connections based on which ports are

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.272
retrieving revision 1.273
diff -u -d -r1.272 -r1.273
--- or.h	1 Apr 2004 02:41:41 -0000	1.272
+++ or.h	1 Apr 2004 03:23:28 -0000	1.273
@@ -689,7 +689,7 @@
 void circuit_dump_by_conn(connection_t *conn, int severity);
 
 void circuit_expire_unused_circuits(void);
-int circuit_launch_new(uint8_t purpose);
+circuit_t *circuit_launch_new(uint8_t purpose);
 void circuit_increment_failure_count(void);
 void circuit_reset_failure_count(void);
 void circuit_n_conn_open(connection_t *or_conn);
@@ -929,7 +929,8 @@
 crypto_pk_env_t *init_key_from_file(const char *fname);
 
 void router_retry_connections(void);
-void router_upload_desc_to_dirservers(void);
+void router_upload_dir_desc_to_dirservers(void);
+void router_post_to_dirservers(uint8_t purpose, const char *payload, int payload_len);
 int router_compare_to_my_exit_policy(connection_t *conn);
 const char *router_get_my_descriptor(void);
 int router_rebuild_descriptor(void);
@@ -1018,6 +1019,7 @@
 
 int rend_config_services(or_options_t *options);
 int rend_service_init_keys(void);
+int rend_services_init(void);
 
 #endif
 

Index: rendservice.c
===================================================================
RCS file: /home/or/cvsroot/src/or/rendservice.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rendservice.c	31 Mar 2004 21:54:56 -0000	1.1
+++ rendservice.c	1 Apr 2004 03:23:28 -0000	1.2
@@ -229,3 +229,39 @@
   }
   return 0;
 }
+
+
+#define NUM_INTRO_POINTS 3
+int rend_services_init(void) {
+  int i;
+  routerinfo_t *router;
+  routerlist_t *rl;
+  circuit_t *circ;
+
+  router_get_routerlist(&rl);
+
+  //for each of bob's services,
+
+    /* The directory is now here. Pick three ORs as intro points. */
+    for (i=0;i<rl->n_routers;i++) {
+      router = rl->routers[i];
+      //...
+      // maybe built a smartlist of all of them, then pick at random
+      // until you have three? or something smarter.
+    }
+
+    /* build a service descriptor out of them, and tuck it away
+     * somewhere so we don't lose it */
+
+    /* post it to the dirservers */
+    //call router_post_to_dirservers(DIR_PURPOSE_UPLOAD_HIDSERV, desc, desc_len);
+
+    // for each intro point,
+    {
+      circ = circuit_launch_new(CIRCUIT_PURPOSE_S_ESTABLISH_INTRO);
+      // tell circ which hidden service this is about
+    }
+
+    // anything else?
+}
+

Index: router.c
===================================================================
RCS file: /home/or/cvsroot/src/or/router.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- router.c	31 Mar 2004 22:02:13 -0000	1.18
+++ router.c	1 Apr 2004 03:23:28 -0000	1.19
@@ -236,26 +236,30 @@
   }
 }
 
-void router_upload_desc_to_dirservers(void) {
-  int i;
-  routerinfo_t *router;
-  routerlist_t *rl;
+void router_upload_dir_desc_to_dirservers(void) {
   const char *s;
 
-  router_get_routerlist(&rl);
-  if(!rl)
-    return;
-
   s = router_get_my_descriptor();
   if (!s) {
     log_fn(LOG_WARN, "No descriptor; skipping upload");
     return;
   }
+  router_post_to_dirservers(DIR_PURPOSE_UPLOAD_DIR, s, strlen(s));
+}
+
+void router_post_to_dirservers(uint8_t purpose, const char *payload, int payload_len) {
+  int i;
+  routerinfo_t *router;
+  routerlist_t *rl;
+
+  router_get_routerlist(&rl);
+  if(!rl)
+    return;
 
   for(i=0;i<rl->n_routers;i++) {
     router = rl->routers[i];
     if(router->dir_port > 0)
-      directory_initiate_command(router, DIR_PURPOSE_UPLOAD_DIR, s, strlen(s));
+      directory_initiate_command(router, purpose, payload, payload_len);
   }
 }