diff options
author | Roger Dingledine <arma@torproject.org> | 2004-04-01 19:39:11 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2004-04-01 19:39:11 +0000 |
commit | f05937355e6b2eb664ebb969b412c791a415cde9 (patch) | |
tree | 32b8b4ee915b060b64451bcd954c2eea8aec1c9b | |
parent | 7993382ba1796130f4dd02ec65267e9a5cced611 (diff) | |
download | tor-f05937355e6b2eb664ebb969b412c791a415cde9.tar tor-f05937355e6b2eb664ebb969b412c791a415cde9.tar.gz |
teach alice to recognize y.onion addresses
svn:r1430
-rw-r--r-- | src/or/rendcommon.c | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c index 220ed31a2..4535defdb 100644 --- a/src/or/rendcommon.c +++ b/src/or/rendcommon.c @@ -177,12 +177,27 @@ void rend_cache_clean(void) } } +/* 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 @@ int rend_cache_lookup(char *query, const char **desc, int *desc_len) 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 @@ int rend_cache_store(char *desc, int desc_len) * 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; } |