[or-cvs] If we are an authoritative dirserver, check out the fingerp...
Nick Mathewson
nickm at seul.org
Tue Sep 28 22:24:58 UTC 2004
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv19310/src/or
Modified Files:
connection_or.c dirserv.c or.h
Log Message:
If we are an authoritative dirserver, check out the fingerprint list when setting connection nicknames
Index: connection_or.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_or.c,v
retrieving revision 1.126
retrieving revision 1.127
diff -u -d -r1.126 -r1.127
--- connection_or.c 27 Sep 2004 06:00:43 -0000 1.126
+++ connection_or.c 28 Sep 2004 22:24:56 -0000 1.127
@@ -120,6 +120,7 @@
{
routerinfo_t *r;
struct in_addr in;
+ const char *n;
r = router_get_by_digest(id_digest);
if (r) {
connection_or_init_conn_from_router(conn,r);
@@ -130,9 +131,16 @@
/* This next part isn't really right, but it's good enough for now. */
conn->receiver_bucket = conn->bandwidth = options.BandwidthBurst;
memcpy(conn->identity_digest, id_digest, DIGEST_LEN);
- conn->nickname = tor_malloc(HEX_DIGEST_LEN+1);
- base16_encode(conn->nickname, HEX_DIGEST_LEN+1,
- conn->identity_digest, DIGEST_LEN);
+ /* If we're an authoritative directory server, we may know a
+ * nickname for this router. */
+ n = dirserv_get_nickname_by_digest(id_digest);
+ if (n) {
+ conn->nickname = tor_strdup(n);
+ } else {
+ conn->nickname = tor_malloc(HEX_DIGEST_LEN+1);
+ base16_encode(conn->nickname, HEX_DIGEST_LEN+1,
+ conn->identity_digest, DIGEST_LEN);
+ }
tor_free(conn->address);
in.s_addr = htonl(addr);
conn->address = tor_strdup(inet_ntoa(in));
Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dirserv.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -d -r1.82 -r1.83
--- dirserv.c 27 Sep 2004 07:28:48 -0000 1.82
+++ dirserv.c 28 Sep 2004 22:24:56 -0000 1.83
@@ -23,6 +23,7 @@
static int list_running_servers(char **nicknames_out);
static void directory_remove_unrecognized(void);
static int dirserv_regenerate_directory(void);
+static void encode_digest_to_fingerprint(char *fp, const char *digest);
/************** Fingerprint handling code ************/
@@ -181,17 +182,32 @@
}
}
-/** Return true iff any router named <b>nickname</b> with <b>digest</b>
- * is in the verified fingerprint list. */
-static int
-router_nickname_is_approved(const char *nickname, const char *digest)
+/** If we are an authoritative directory, and the list of approved
+ * servers contains one whose identity key digest is <b>digest</b>,
+ * return that router's nickname. Otherwise return NULL. */
+const char *dirserv_get_nickname_by_digest(const char *digest)
{
- int i,j;
- fingerprint_entry_t *ent;
char fp[FINGERPRINT_LEN+1];
- char hexdigest[HEX_DIGEST_LEN+1];
if (!fingerprint_list)
- return 0;
+ return NULL;
+ tor_assert(digest);
+ encode_digest_to_fingerprint(fp, digest);
+
+ SMARTLIST_FOREACH(fingerprint_list, fingerprint_entry_t*, ent,
+ { if (!strcasecmp(fp, ent->fingerprint))
+ return ent->nickname; } );
+ return NULL;
+}
+
+/** Set fp to contain the hex encoding of <b>digest</b>, with every 4
+ * hex digits separated by a space. The digest must be DIGEST_LEN bytes long;
+ * fp must have FINGERPRINT_LEN+1 bytes free. */
+static void encode_digest_to_fingerprint(char *fp, const char *digest)
+{
+ char hexdigest[HEX_DIGEST_LEN+1];
+ int i,j;
+
+ tor_assert(fp&&digest);
base16_encode(hexdigest, sizeof(hexdigest), digest, DIGEST_LEN);
for (i=j=0;j<HEX_DIGEST_LEN;++i,++j) {
@@ -200,15 +216,20 @@
fp[++i]=' ';
}
fp[i]='\0';
+}
- for (i=0;i<smartlist_len(fingerprint_list);++i) {
- ent = smartlist_get(fingerprint_list, i);
- if (!strcasecmp(nickname,ent->nickname) &&
- !strcasecmp(fp,ent->fingerprint)) {
- return 1;
- }
- }
- return 0;
+/** Return true iff any router named <b>nickname</b> with <b>digest</b>
+ * is in the verified fingerprint list. */
+static int
+router_nickname_is_approved(const char *nickname, const char *digest)
+{
+ const char *n;
+
+ n = dirserv_get_nickname_by_digest(digest);
+ if (n && !strcasecmp(n,nickname))
+ return 1;
+ else
+ return 0;
}
/** Clear the current fingerprint list. */
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.420
retrieving revision 1.421
diff -u -d -r1.420 -r1.421
--- or.h 27 Sep 2004 06:57:16 -0000 1.420
+++ or.h 28 Sep 2004 22:24:56 -0000 1.421
@@ -1177,6 +1177,7 @@
int dirserv_parse_fingerprint_file(const char *fname);
int dirserv_router_fingerprint_is_known(const routerinfo_t *router);
void dirserv_free_fingerprint_list();
+const char *dirserv_get_nickname_by_digest(const char *digest);
int dirserv_add_descriptor(const char **desc);
int dirserv_load_from_directory_string(const char *dir);
void dirserv_free_descriptors();
More information about the tor-commits
mailing list