summaryrefslogtreecommitdiff
path: root/src/or/routerlist.c
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2004-12-05 07:10:08 +0000
committerRoger Dingledine <arma@torproject.org>2004-12-05 07:10:08 +0000
commitef6c9d18e799e5b02505ba73bbf36bfe92ce5a8b (patch)
tree24e864902bc7196fb3e2ca1a39fc7463c2582d1c /src/or/routerlist.c
parent32e74d352500dc228a1de5d5bc97e219897ef09b (diff)
downloadtor-ef6c9d18e799e5b02505ba73bbf36bfe92ce5a8b.tar.gz
tor-ef6c9d18e799e5b02505ba73bbf36bfe92ce5a8b.zip
New circuit building strategy: keep a list of ports that we've used in the past 6 hours, and always try to have 2 circuits open or on the way
that will handle each such port. (We can extend this to include addresses if exit policies shift to require that.) Seed us with port 80 so web browsers won't complain that Tor is "slow to start up". This was necessary because our old circuit building strategy just involved counting circuits, and as time went by we would build up a big pile of circuits that had peculiar exit policies (e.g. only exit to 9001-9100) which would take up space in the circuit pile but never get used. Fix router_compare_addr_to_addr_policy: it was not treating a port of * as always matching, so we were picking reject *:* nodes as exit nodes too. If you haven't used a clean circuit in an hour, throw it away, just to be on the safe side. This means after 6 hours a totally unused Tor client will have no circuits open. svn:r3078
Diffstat (limited to 'src/or/routerlist.c')
-rw-r--r--src/or/routerlist.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 9a364d4898..5abca8c149 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -936,10 +936,11 @@ router_resolve_routerlist(routerlist_t *rl)
/** Decide whether a given addr:port is definitely accepted, definitely
* rejected, or neither by a given policy. If <b>addr</b> is 0, we
- * don't know the IP of the target address.
+ * don't know the IP of the target address. If <b>port</b> is 0, we
+ * don't know the port of the target address.
*
- * Returns -1 for "rejected", 0 for "accepted", 1 for "maybe" (since IP is
- * unknown).
+ * Returns -1 for "rejected", 0 for "accepted", 1 for "maybe" (since IP or
+ * port is unknown).
*/
int router_compare_addr_to_addr_policy(uint32_t addr, uint16_t port,
addr_policy_t *policy)
@@ -948,7 +949,6 @@ int router_compare_addr_to_addr_policy(uint32_t addr, uint16_t port,
int maybe_accept = 0;
int match = 0;
int maybe = 0;
- struct in_addr in;
addr_policy_t *tmpe;
for (tmpe=policy; tmpe; tmpe=tmpe->next) {
@@ -956,7 +956,8 @@ int router_compare_addr_to_addr_policy(uint32_t addr, uint16_t port,
maybe = 0;
if (!addr) {
/* Address is unknown. */
- if (port >= tmpe->prt_min && port <= tmpe->prt_max) {
+ if ((port >= tmpe->prt_min && port <= tmpe->prt_max) ||
+ (!port && tmpe->prt_min<=1 && tmpe->prt_max>=65535)) {
/* The port definitely matches. */
if (tmpe->msk == 0) {
match = 1;
@@ -965,10 +966,6 @@ int router_compare_addr_to_addr_policy(uint32_t addr, uint16_t port,
}
} else if (!port) {
/* The port maybe matches. */
- /* XXX Nick: it looks port 0 only means something special for resolve
- * commands, which can currently be handled by any exit node.
- * Should we treat those specially elsewhere?
- */
maybe = 1;
}
} else {
@@ -989,9 +986,10 @@ int router_compare_addr_to_addr_policy(uint32_t addr, uint16_t port,
maybe_accept = 1;
}
if (match) {
- in.s_addr = htonl(addr);
- log_fn(LOG_DEBUG,"Address %s:%d matches policy '%s'",
- inet_ntoa(in), port, tmpe->string);
+// struct in_addr in;
+// in.s_addr = htonl(addr);
+// log_fn(LOG_DEBUG,"Address %s:%d matches policy '%s'",
+// inet_ntoa(in), port, tmpe->string);
if (tmpe->policy_type == ADDR_POLICY_ACCEPT) {
/* If we already hit a clause that might trigger a 'reject', than we
* can't be sure of this certain 'accept'.*/
@@ -1024,7 +1022,7 @@ int router_exit_policy_all_routers_reject(uint32_t addr, uint16_t port) {
/** Return true iff <b>router</b> does not permit exit streams.
*/
int router_exit_policy_rejects_all(routerinfo_t *router) {
- return router_compare_addr_to_addr_policy(0, 1, router->exit_policy)
+ return router_compare_addr_to_addr_policy(0, 0, router->exit_policy)
== ADDR_POLICY_REJECTED;
}