Finish implementing GETINFO; make it easy to query address maps.

svn:r3732
This commit is contained in:
Nick Mathewson 2005-03-03 06:37:54 +00:00
parent f90ccf5648
commit c185825585
6 changed files with 77 additions and 15 deletions

View File

@ -181,6 +181,7 @@ AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(long long) AC_CHECK_SIZEOF(long long)
AC_CHECK_SIZEOF(__int64) AC_CHECK_SIZEOF(__int64)
AC_CHECK_SIZEOF(void *) AC_CHECK_SIZEOF(void *)
AC_CHECK_SIZEOF(time_t)
# We want to make sure that we _don't_ have a cell_t defined, like IRIX does. # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.

View File

@ -49,20 +49,20 @@ R o Reset uptime when IP changes.
Functionality Functionality
N . Implement pending controller features. N . Implement pending controller features.
o Stubs for new functions. o Stubs for new functions.
. GETINFO o GETINFO
o Version o Version
o Descriptor list o Descriptor list
o Individual descriptors o Individual descriptors
o Need to remember descriptors for all routers. o Need to remember descriptors for all routers.
o Replace everything else that remembers serverdescs with o Replace everything else that remembers serverdescs with
routerinfo. routerinfo.
- List of address mappings o List of address mappings
o POSTDESCRIPTOR o POSTDESCRIPTOR
. MAPADDRESS o MAPADDRESS
o Map A->B. o Map A->B.
o Map DontCare->B. o Map DontCare->B.
o Reuse mappings when asked to map DontCare->B for the same B. o Reuse mappings when asked to map DontCare->B for the same B.
- But only when the DontCare is of the same type. :/ o But only when the DontCare is of the same type. :/
o Way to handle overlong messages o Way to handle overlong messages
o Specify fragmented format o Specify fragmented format
o Implement fragmented format o Implement fragmented format
@ -70,8 +70,9 @@ N . Implement pending controller features.
o Better stream IDs o Better stream IDs
o Stream status changed: "new" state. o Stream status changed: "new" state.
- EXTENDCIRCUIT <depends on revised circ selection stuff.> - EXTENDCIRCUIT <depends on revised circ selection stuff.>
- ATTACHSTREAM - ATTACHSTREAM
- Make streams have an 'unattached and unattachable' state. - Make streams have an 'unattached and not-automatically-attachable'
state.
- Add support to put new streams into this state rather than try to - Add support to put new streams into this state rather than try to
attach them automatically. ("Hidden" config option.) attach them automatically. ("Hidden" config option.)
- Time out never-attached streams. - Time out never-attached streams.

View File

@ -235,6 +235,16 @@ typedef uint32_t uintptr_t;
#endif #endif
#endif #endif
#ifndef TIME_MAX
#if (SIZEOF_TIME_T == 4)
#define TIME_MAX ((time_t)UINT32_MAX)
#elif (SIZEOF_TIME_T == 8)
#define TIME_MAX ((time_t)UINT64_MAX)
#else
#error "Can't define TIME_MAX"
#endif
#endif
/* Any size_t larger than this amount is likely to be an underflow. */ /* Any size_t larger than this amount is likely to be an underflow. */
#define SIZE_T_CEILING (sizeof(char)<<(sizeof(size_t)*8 - 1)) #define SIZE_T_CEILING (sizeof(char)<<(sizeof(size_t)*8 - 1))

View File

@ -356,7 +356,11 @@ void connection_ap_attach_pending(void)
* When an addressmap request is made but one is already registered, * When an addressmap request is made but one is already registered,
* the new one is replaced only if the currently registered one has * the new one is replaced only if the currently registered one has
* no "new_address" (that is, it's in the process of dns resolve), * no "new_address" (that is, it's in the process of dns resolve),
* or if the new one is permanent (expires==0). * or if the new one is permanent (expires==0 or 1).
*
* (We overload the 'expires' field, using "0" for mappings set via
* the configuration file, "1" for mappings set from the control
* interface, and other values for DNS mappings that can expire.)
*/ */
typedef struct { typedef struct {
char *new_address; char *new_address;
@ -438,7 +442,7 @@ static void *
_addressmap_remove_if_expired(const char *addr, _addressmap_remove_if_expired(const char *addr,
addressmap_entry_t *ent, addressmap_entry_t *ent,
time_t *nowp) { time_t *nowp) {
if (ent->expires && ent->expires < *nowp) { if (ent->expires > 1 && ent->expires < *nowp) {
log(LOG_INFO, "Addressmap: expiring remap (%s to %s)", log(LOG_INFO, "Addressmap: expiring remap (%s to %s)",
addr, ent->new_address); addr, ent->new_address);
addressmap_ent_remove(addr,ent); addressmap_ent_remove(addr,ent);
@ -493,7 +497,8 @@ int addressmap_already_mapped(const char *address) {
} }
/** Register a request to map <b>address</b> to <b>new_address</b>, /** Register a request to map <b>address</b> to <b>new_address</b>,
* which will expire on <b>expires</b> (or 0 if never expires). * which will expire on <b>expires</b> (or 0 if never expires from config
* file, 1 if never expires from controller).
* *
* <b>new_address</b> should be a newly dup'ed string, which we'll use or * <b>new_address</b> should be a newly dup'ed string, which we'll use or
* free as appropriate. We will leave address alone. * free as appropriate. We will leave address alone.
@ -505,7 +510,7 @@ void addressmap_register(const char *address, char *new_address, time_t expires)
addressmap_entry_t *ent; addressmap_entry_t *ent;
ent = strmap_get(addressmap, address); ent = strmap_get(addressmap, address);
if (ent && ent->new_address && expires) { if (ent && ent->new_address && expires>1) {
log_fn(LOG_INFO,"Addressmap ('%s' to '%s') not performed, since it's already mapped to '%s'", address, new_address, ent->new_address); log_fn(LOG_INFO,"Addressmap ('%s' to '%s') not performed, since it's already mapped to '%s'", address, new_address, ent->new_address);
tor_free(new_address); tor_free(new_address);
return; return;
@ -688,7 +693,7 @@ addressmap_register_virtual_address(int type, char *new_address)
tor_free(*addrp); tor_free(*addrp);
*addrp = addressmap_get_virtual_address(type); *addrp = addressmap_get_virtual_address(type);
strmap_set(virtaddress_reversemap, new_address, tor_strdup(*addrp)); strmap_set(virtaddress_reversemap, new_address, tor_strdup(*addrp));
addressmap_register(*addrp, new_address, 0); addressmap_register(*addrp, new_address, 1);
return *addrp; return *addrp;
} }
@ -703,6 +708,30 @@ address_is_invalid_destination(const char *address) {
return 0; return 0;
} }
/* DOCDOC */
void
addressmap_get_mappings(smartlist_t *sl, time_t min_expires, time_t max_expires)
{
strmap_iter_t *iter;
const char *key;
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);
}
}
}
/** connection_edge_process_inbuf() found a conn in state /** connection_edge_process_inbuf() found a conn in state
* socks_wait. See if conn->inbuf has the right bytes to proceed with * socks_wait. See if conn->inbuf has the right bytes to proceed with
* the socks handshake. * the socks handshake.

View File

@ -487,7 +487,8 @@ handle_control_mapaddress(connection_t *conn, uint32_t len, const char *body)
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0); SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
SMARTLIST_FOREACH(lines, const char *, line, SMARTLIST_FOREACH(lines, const char *, line,
{ {
smartlist_split_string(elts, body, " ", 0, 2); tor_strlower(line);
smartlist_split_string(elts, line, " ", 0, 2);
if (smartlist_len(elts) == 2) { if (smartlist_len(elts) == 2) {
const char *from = smartlist_get(elts,0); const char *from = smartlist_get(elts,0);
const char *to = smartlist_get(elts,1); const char *to = smartlist_get(elts,1);
@ -510,7 +511,7 @@ handle_control_mapaddress(connection_t *conn, uint32_t len, const char *body)
smartlist_add(reply, ans); smartlist_add(reply, ans);
} }
} else { } else {
addressmap_register(from, tor_strdup(to), 0); addressmap_register(from, tor_strdup(to), 1);
smartlist_add(reply, tor_strdup(line)); smartlist_add(reply, tor_strdup(line));
} }
} else { } else {
@ -559,8 +560,27 @@ handle_getinfo_helper(const char *question)
*cp++ = ','; *cp++ = ',';
}); });
return answer; return answer;
} else if (!strcmp(question, "addr-mappings")) { } else if (!strcmpstart(question, "addr-mappings/")) {
return NULL; /* XXXX */ time_t min_e, max_e;
smartlist_t *mappings;
char *answer;
if (!strcmp(question, "addr-mappings/all")) {
min_e = 0; max_e = TIME_MAX;
} else if (!strcmp(question, "addr-mappings/cache")) {
min_e = 2; max_e = TIME_MAX;
} else if (!strcmp(question, "addr-mappings/config")) {
min_e = 0; max_e = 0;
} else if (!strcmp(question, "addr-mappings/control")) {
min_e = 1; max_e = 1;
} else {
return NULL;
}
mappings = smartlist_create();
addressmap_get_mappings(mappings, min_e, max_e);
answer = smartlist_join_strings(mappings, "\n", 1, NULL);
SMARTLIST_FOREACH(mappings, char *, cp, tor_free(cp));
smartlist_free(mappings);
return answer;
} else { } else {
/* unrecognized key */ /* unrecognized key */
return NULL; return NULL;

View File

@ -1320,6 +1320,7 @@ void addressmap_register(const char *address, char *new_address, time_t expires)
int client_dns_incr_failures(const char *address); int client_dns_incr_failures(const char *address);
void client_dns_set_addressmap(const char *address, uint32_t val, const char *exitname); void client_dns_set_addressmap(const char *address, uint32_t val, const char *exitname);
char *addressmap_register_virtual_address(int type, char *new_address); char *addressmap_register_virtual_address(int type, char *new_address);
void addressmap_get_mappings(smartlist_t *sl, time_t min_expires, time_t max_expires);
void parse_socks_policy(void); void parse_socks_policy(void);
void free_socks_policy(void); void free_socks_policy(void);