[or-cvs] teach alice to recognize y.onion addresses
Roger Dingledine
arma at seul.org
Thu Apr 1 19:39:13 UTC 2004
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or
Modified Files:
rendcommon.c
Log Message:
teach alice to recognize y.onion addresses
Index: rendcommon.c
===================================================================
RCS file: /home/or/cvsroot/src/or/rendcommon.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- rendcommon.c 1 Apr 2004 02:41:41 -0000 1.4
+++ rendcommon.c 1 Apr 2004 19:39:11 -0000 1.5
@@ -177,12 +177,27 @@
}
}
+/* return 1 if query is a valid service id, else return 0. */
+int rend_valid_service_id(char *query) {
+ if(strlen(query) != REND_SERVICE_ID_LEN)
+ return 0;
+
+ /* XXXX also check for bad chars. */
+ return 1;
+}
+
+/* 'query' is a base-32'ed service id. If it's malformed, return -1.
+ * Else look it up.
+ * If it is found, point *desc to it, and write its length into
+ * *desc_len, and return 1.
+ * If it is not found, return 0.
+ */
int rend_cache_lookup(char *query, const char **desc, int *desc_len)
{
rend_cache_entry_t *e;
assert(rend_cache);
- if (strlen(query) != REND_SERVICE_ID_LEN)
- return -1; /* XXXX also check for bad chars. */
+ if (!rend_valid_service_id(query))
+ return -1;
e = (rend_cache_entry_t*) strmap_get_lc(rend_cache, query);
if (!e)
return 0;
@@ -191,6 +206,9 @@
return 1;
}
+/* Calculate desc's service id, and store it.
+ * Return -1 if it's malformed or otherwise rejected, else return 0.
+ */
int rend_cache_store(char *desc, int desc_len)
{
rend_cache_entry_t *e;
@@ -251,8 +269,17 @@
* Else return -1 and change nothing.
*/
int rend_parse_rendezvous_address(char *address) {
+ char *s;
+ s = strchr(address,'.');
+ if(!s) return -1; /* no dot */
+ if(strcmp(s+1,"onion")) return -1; /* not .onion */
+ *s = 0; /* null terminate it */
+ if(rend_valid_service_id(address))
+ return 0; /* success */
+ /* otherwise, return to previous state and return -1 */
+ *s = '.';
return -1;
}
More information about the tor-commits
mailing list