aboutsummaryrefslogtreecommitdiff
path: root/src/or/nodelist.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2010-09-29 15:00:41 -0400
committerNick Mathewson <nickm@torproject.org>2010-10-01 18:14:27 -0400
commit26e897420e07611e0b2c10b28202c388eea4bd6b (patch)
treefa4b00945e82f2f030cf19bb186c5899834e535a /src/or/nodelist.h
parent6dd7f85bc7fa9887736feb7604e76d7226d03ca5 (diff)
downloadtor-26e897420e07611e0b2c10b28202c388eea4bd6b.tar
tor-26e897420e07611e0b2c10b28202c388eea4bd6b.tar.gz
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and microdesc_t. It should try to present a consistent interface to all of them. There should be a node_t for a server whenever there is * A routerinfo_t for it in the routerlist * A routerstatus_t in the current_consensus. (note that a microdesc_t alone isn't enough to make a node_t exist, since microdescriptors aren't usable on their own.) There are three ways to get a node_t right now: looking it up by ID, looking it up by nickname, and iterating over the whole list of microdescriptors. All (or nearly all) functions that are supposed to return "a router" -- especially those used in building connections and circuits -- should return a node_t, not a routerinfo_t or a routerstatus_t. A node_t should hold all the *mutable* flags about a node. This patch moves the is_foo flags from routerinfo_t into node_t. The flags in routerstatus_t remain, but they get set from the consensus and should not change. Some other highlights of this patch are: * Looking up routerinfo and routerstatus by nickname is now unified and based on the "look up a node by nickname" function. This tries to look only at the values from current consensus, and not get confused by the routerinfo_t->is_named flag, which could get set for other weird reasons. This changes the behavior of how authorities (when acting as clients) deal with nodes that have been listed by nickname. * I tried not to artificially increase the size of the diff here by moving functions around. As a result, some functions that now operate on nodes are now in the wrong file -- they should get moved to nodelist.c once this refactoring settles down. This moving should happen as part of a patch that moves functions AND NOTHING ELSE. * Some old code is now left around inside #if 0/1 blocks, and should get removed once I've verified that I don't want it sitting around to see how we used to do things. There are still some unimplemented functions: these are flagged with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the implementation here, piece by piece. I wish this patch could have been smaller, but there did not seem to be any piece of it that was independent from the rest. Moving flags forces many functions that once returned routerinfo_t * to return node_t *, which forces their friends to change, and so on.
Diffstat (limited to 'src/or/nodelist.h')
-rw-r--r--src/or/nodelist.h39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/or/nodelist.h b/src/or/nodelist.h
index 6a77ba683..3dceb7573 100644
--- a/src/or/nodelist.h
+++ b/src/or/nodelist.h
@@ -12,7 +12,8 @@
#ifndef _TOR_NODELIST_H
#define _TOR_NODELIST_H
-node_t *node_get_by_id(const char *identity_digest);
+node_t *node_get_mutable_by_id(const char *identity_digest);
+const node_t *node_get_by_id(const char *identity_digest);
node_t *nodelist_add_routerinfo(routerinfo_t *ri);
node_t *nodelist_add_microdesc(microdesc_t *md);
void nodelist_set_consensus(networkstatus_t *ns);
@@ -24,5 +25,41 @@ void nodelist_purge(void);
void nodelist_free_all(void);
void nodelist_assert_ok(void);
+const node_t *node_get_by_nickname(const char *nickname, int warn_if_unnamed);
+void node_get_verbose_nickname(const node_t *node,
+ char *verbose_name_out);
+int node_is_named(const node_t *node);
+int node_is_dir(const node_t *node);
+int node_has_descriptor(const node_t *node);
+int node_get_purpose(const node_t *node);
+#define node_is_bridge(node) \
+ (node_get_purpose((node)) == ROUTER_PURPOSE_BRIDGE)
+int node_is_me(const node_t *node);
+int node_exit_policy_rejects_all(const node_t *node);
+int node_get_addr(const node_t *node, tor_addr_t *addr_out);
+uint32_t node_get_addr_ipv4h(const node_t *node);
+int node_allows_single_hop_exits(const node_t *node);
+uint16_t node_get_orport(const node_t *node);
+const char *node_get_nickname(const node_t *node);
+const char *node_get_platform(const node_t *node);
+void node_get_address_string(const node_t *node, char *cp, size_t len);
+long node_get_declared_uptime(const node_t *node);
+time_t node_get_published_on(const node_t *node);
+
+smartlist_t *nodelist_get_list(void);
+
+/* XXXX These need to move out of routerlist.c */
+void nodelist_refresh_countries(void);
+void node_set_country(node_t *node);
+void nodelist_add_node_family(smartlist_t *nodes, const node_t *node);
+int nodes_in_same_family(const node_t *node1, const node_t *node2);
+
+/* This means: implement this code or function or thing, nick! */
+#define UNIMPLEMENTED_NODELIST() \
+ while (unimplemented_nodelist_truth) { \
+ tor_assert(0); \
+ }
+extern int unimplemented_nodelist_truth;
+
#endif