summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-03-11 21:39:39 +0000
committerNick Mathewson <nickm@torproject.org>2005-03-11 21:39:39 +0000
commit777d3dde0c828a67d52419feb5a8d0587d63dbc1 (patch)
tree8c44e5d85e68a8f5b3a402031ff14a52884d497d /src
parentb17bb918ac3360ac3a050bfb8f4215a1a17554dd (diff)
downloadtor-777d3dde0c828a67d52419feb5a8d0587d63dbc1.tar.gz
tor-777d3dde0c828a67d52419feb5a8d0587d63dbc1.zip
Get address map resetting implemented.
svn:r3745
Diffstat (limited to 'src')
-rw-r--r--src/or/config.c1
-rw-r--r--src/or/connection_edge.c55
-rw-r--r--src/or/main.c1
-rw-r--r--src/or/or.h2
4 files changed, 35 insertions, 24 deletions
diff --git a/src/or/config.c b/src/or/config.c
index 204a477f67..1f4e0ffa9e 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -1823,6 +1823,7 @@ config_register_addressmaps(or_options_t *options) {
struct config_line_t *opt;
char *from, *to;
+ addressmap_clear_configured();
elts = smartlist_create();
for (opt = options->AddressMap; opt; opt = opt->next) {
smartlist_split_string(elts, opt->value, NULL,
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 87487b3181..420047e826 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -435,29 +435,26 @@ addressmap_ent_remove(const char *addr, addressmap_entry_t *ent)
addressmap_ent_free(ent);
}
-/** A helper function for addressmap_clean() below. If ent is too old,
- * then remove it from the tree and return NULL, else return ent.
- */
-static void *
-_addressmap_remove_if_expired(const char *addr,
- addressmap_entry_t *ent,
- time_t *nowp) {
- if (ent->expires > 1 && ent->expires < *nowp) {
- log(LOG_INFO, "Addressmap: expiring remap (%s to %s)",
- addr, ent->new_address);
- addressmap_ent_remove(addr,ent);
- return NULL;
- } else {
- return ent;
- }
+/** Remove all entries from the addressmap that were set via the
+ * configuration file or the command line. */
+void
+addressmap_clear_configured(void)
+{
+ addressmap_get_mappings(NULL, 0, 0);
+}
+
+/** Remove all entries from the addressmap that are set to expire, ever. */
+void
+addressmap_clear_transient(void)
+{
+ addressmap_get_mappings(NULL, 2, TIME_MAX);
}
/** Clean out entries from the addressmap cache that were
* added long enough ago that they are no longer valid.
*/
void addressmap_clean(time_t now) {
- strmap_foreach(addressmap,
- (strmap_foreach_fn)_addressmap_remove_if_expired, &now);
+ addressmap_get_mappings(NULL, 2, now);
}
/** Free all the elements in the addressmap, and free the addressmap
@@ -708,7 +705,11 @@ address_is_invalid_destination(const char *address) {
return 0;
}
-/* DOCDOC */
+/* Iterate over all address mapings which have exipry times between
+ * min_expires and max_expires, inclusive. If sl is provided, add an
+ * "old-addr new-addr" string to sl for each mapping. If sl is NULL,
+ * remove the mappings.
+ */
void
addressmap_get_mappings(smartlist_t *sl, time_t min_expires, time_t max_expires)
{
@@ -717,17 +718,23 @@ addressmap_get_mappings(smartlist_t *sl, time_t min_expires, time_t max_expires)
void *_val;
addressmap_entry_t *val;
- tor_assert(sl);
-
for (iter = strmap_iter_init(addressmap); !strmap_iter_done(iter);
iter = strmap_iter_next(addressmap,iter)) {
strmap_iter_get(iter, &key, &_val);
val = _val;
if (val->expires >= min_expires && val->expires <= max_expires) {
- size_t len = strlen(key)+strlen(val->new_address)+2;
- char *line = tor_malloc(len);
- tor_snprintf(line, len, "%s %s", key, val->new_address);
- smartlist_add(sl, line);
+ if (sl) {
+ size_t len = strlen(key)+strlen(val->new_address)+2;
+ char *line = tor_malloc(len);
+ tor_snprintf(line, len, "%s %s", key, val->new_address);
+ smartlist_add(sl, line);
+ iter = strmap_iter_next(addressmap,iter);
+ } else {
+ addressmap_ent_remove(key, val);
+ iter = strmap_iter_next_rmv(addressmap,iter);
+ }
+ } else {
+ iter = strmap_iter_next(addressmap,iter);
}
}
}
diff --git a/src/or/main.c b/src/or/main.c
index 83bd105301..0c9eacf8c4 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -892,6 +892,7 @@ static int do_hup(void) {
if (accounting_is_enabled(options))
accounting_record_bandwidth_usage(time(NULL));
+ addressmap_clear_transient();
/* first, reload config variables, in case they've changed */
/* no need to provide argc/v, they've been cached inside init_from_config */
if (init_from_config(0, NULL) < 0) {
diff --git a/src/or/or.h b/src/or/or.h
index 8137cf8145..f14632eb0d 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1312,6 +1312,8 @@ void connection_ap_attach_pending(void);
void addressmap_init(void);
void addressmap_clean(time_t now);
+void addressmap_clear_configured(void);
+void addressmap_clear_transient(void);
void addressmap_free_all(void);
void addressmap_rewrite(char *address, size_t maxlen);
int addressmap_already_mapped(const char *address);