mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 13:13:44 +01:00
initial patches on patches
svn:r814
This commit is contained in:
parent
8a17d9e5d3
commit
fe856406be
@ -430,7 +430,7 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) {
|
||||
req->reply[0] = 5; /* socks5 reply */
|
||||
req->reply[1] = 0xFF; /* reject all methods */
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
buf_remove_from_front(buf,2+nummethods);/* remove packet from buf */
|
||||
|
||||
req->replylen = 2; /* 2 bytes of response */
|
||||
@ -461,7 +461,7 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) {
|
||||
strlen(tmpbuf)+1,MAX_SOCKS_ADDR_LEN);
|
||||
return -1;
|
||||
}
|
||||
strcpy(req->addr,tmpbuf);
|
||||
strcpy(req->address,tmpbuf);
|
||||
req->port = ntohs(*(uint16_t*)(buf->mem+8));
|
||||
buf_remove_from_front(buf, 10);
|
||||
return 1;
|
||||
@ -475,8 +475,8 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) {
|
||||
len+1,MAX_SOCKS_ADDR_LEN);
|
||||
return -1;
|
||||
}
|
||||
memcpy(req->addr,buf->mem+5,len);
|
||||
req->addr[len] = 0;
|
||||
memcpy(req->address,buf->mem+5,len);
|
||||
req->address[len] = 0;
|
||||
req->port = ntohs(*(uint16_t*)(buf->mem+5+len));
|
||||
buf_remove_from_front(buf, 5+len+2);
|
||||
return 1;
|
||||
@ -533,7 +533,7 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) {
|
||||
}
|
||||
}
|
||||
log_fn(LOG_DEBUG,"Everything is here. Success.");
|
||||
strcpy(req->addr, socks4_prot == socks4 ? tmpbuf : startaddr);
|
||||
strcpy(req->address, socks4_prot == socks4 ? tmpbuf : startaddr);
|
||||
buf_remove_from_front(buf, next-buf->mem+1); /* next points to the final \0 on inbuf */
|
||||
return 1;
|
||||
|
||||
|
@ -86,6 +86,8 @@ void circuit_free(circuit_t *circ) {
|
||||
crypto_free_cipher_env(circ->n_crypto);
|
||||
if (circ->p_crypto)
|
||||
crypto_free_cipher_env(circ->p_crypto);
|
||||
if(circ->build_state)
|
||||
tor_free(circ->build_state->chosen_exit);
|
||||
tor_free(circ->build_state);
|
||||
circuit_free_cpath(circ->cpath);
|
||||
free(circ);
|
||||
@ -659,7 +661,7 @@ int circuit_establish_circuit(void) {
|
||||
circ = circuit_new(0, NULL); /* sets circ->p_circ_id and circ->p_conn */
|
||||
circ->state = CIRCUIT_STATE_OR_WAIT;
|
||||
circ->build_state = onion_new_cpath_build_state();
|
||||
|
||||
|
||||
if (! circ->build_state) {
|
||||
log_fn(LOG_INFO,"Generating cpath length failed.");
|
||||
circuit_close(circ);
|
||||
|
@ -101,7 +101,7 @@ void connection_edge_end(connection_t *conn, char reason, crypt_path_t *cpath_la
|
||||
payload[0] = reason;
|
||||
if(reason == END_STREAM_REASON_EXITPOLICY) {
|
||||
*(uint32_t *)(payload+1) = htonl(conn->addr);
|
||||
payload_len += 6;
|
||||
payload_len += 4;
|
||||
}
|
||||
|
||||
circ = circuit_get_by_conn(conn);
|
||||
@ -250,12 +250,10 @@ int connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ, connection
|
||||
*(cell->payload+RELAY_HEADER_SIZE) == END_STREAM_REASON_EXITPOLICY) {
|
||||
/* No need to close the connection. We'll hold it open while
|
||||
* we try a new exit node.
|
||||
* cell->payload+RELAY_HEADER_SIZE+1 holds the addr and then
|
||||
* port of the destination. Which is good, because we've
|
||||
* forgotten it.
|
||||
* cell->payload+RELAY_HEADER_SIZE+1 holds the destination addr.
|
||||
*/
|
||||
addr = ntohl(*cell->payload+RELAY_HEADER_SIZE+1);
|
||||
client_dns_set_entry(conn->socks_request->addr, addr);
|
||||
client_dns_set_entry(conn->socks_request->address, addr);
|
||||
conn->state = AP_CONN_STATE_CIRCUIT_WAIT;
|
||||
/* XXX Build another circuit as required */
|
||||
return 0;
|
||||
@ -324,7 +322,7 @@ int connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ, connection
|
||||
log_fn(LOG_INFO,"Connected! Notifying application.");
|
||||
if (cell->length-RELAY_HEADER_SIZE == 4) {
|
||||
addr = htonl(*(uint32_t*)(cell->payload + RELAY_HEADER_SIZE));
|
||||
client_dns_set_entry(conn->socks_request->addr, addr);
|
||||
client_dns_set_entry(conn->socks_request->address, addr);
|
||||
}
|
||||
if(connection_ap_handshake_socks_reply(conn, NULL, 0, 1) < 0) {
|
||||
log_fn(LOG_INFO,"Writing to socks-speaking application failed. Closing.");
|
||||
@ -620,19 +618,18 @@ static void connection_ap_handshake_send_begin(connection_t *ap_conn, circuit_t
|
||||
assert(ap_conn->type == CONN_TYPE_AP);
|
||||
assert(ap_conn->state == AP_CONN_STATE_CIRCUIT_WAIT);
|
||||
assert(ap_conn->socks_request);
|
||||
assert(ap_conn->socks_request->addr);
|
||||
|
||||
crypto_pseudo_rand(STREAM_ID_SIZE, ap_conn->stream_id);
|
||||
/* FIXME check for collisions */
|
||||
|
||||
in.s_addr = client_dns_lookup_entry(ap_conn->socks_request->addr);
|
||||
in.s_addr = client_dns_lookup_entry(ap_conn->socks_request->address);
|
||||
string_addr = in.s_addr ? inet_ntoa(in) : NULL;
|
||||
|
||||
memcpy(payload, ap_conn->stream_id, STREAM_ID_SIZE);
|
||||
payload_len = STREAM_ID_SIZE + 1 +
|
||||
snprintf(payload+STREAM_ID_SIZE,CELL_PAYLOAD_SIZE-RELAY_HEADER_SIZE-STREAM_ID_SIZE,
|
||||
"%s:%d",
|
||||
string_addr ? string_addr : ap_conn->socks_request->addr,
|
||||
string_addr ? string_addr : ap_conn->socks_request->address,
|
||||
ap_conn->socks_request->port);
|
||||
|
||||
log_fn(LOG_DEBUG,"Sending relay cell to begin stream %d.",*(int *)ap_conn->stream_id);
|
||||
@ -786,8 +783,8 @@ void connection_exit_connect(connection_t *conn) {
|
||||
int connection_ap_can_use_exit(connection_t *conn, routerinfo_t *exit)
|
||||
{
|
||||
uint32_t addr;
|
||||
|
||||
addr = client_dns_lookup_entry(conn->socks_request->addr);
|
||||
|
||||
addr = client_dns_lookup_entry(conn->socks_request->address);
|
||||
return router_supports_exit_address(addr, conn->port, exit);
|
||||
}
|
||||
|
||||
@ -896,7 +893,7 @@ static void client_dns_set_entry(const char *address, uint32_t val)
|
||||
}
|
||||
}
|
||||
|
||||
static void client_dns_clean()
|
||||
static void client_dns_clean(void)
|
||||
{
|
||||
struct client_dns_entry **expired_entries;
|
||||
int n_expired_entries = 0;
|
||||
@ -905,8 +902,8 @@ static void client_dns_clean()
|
||||
int i;
|
||||
|
||||
expired_entries = tor_malloc(client_dns_size *
|
||||
sizeof(struct client_dns_entry *));
|
||||
|
||||
sizeof(struct client_dns_entry *));
|
||||
|
||||
now = time(NULL);
|
||||
SPLAY_FOREACH(ent, client_dns_tree, &client_dns_root) {
|
||||
if (ent->expires < now) {
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include "or.h"
|
||||
extern or_options_t options; /* command-line and config-file options */
|
||||
|
||||
#define MAX_CPUWORKERS 17
|
||||
#define MAX_CPUWORKERS 16
|
||||
#define MIN_CPUWORKERS 1
|
||||
|
||||
#define TAG_LEN 8
|
||||
@ -60,10 +60,14 @@ int connection_cpu_process_inbuf(connection_t *conn) {
|
||||
if(conn->inbuf_reached_eof) {
|
||||
log_fn(LOG_WARN,"Read eof. Worker dying.");
|
||||
if(conn->state != CPUWORKER_STATE_IDLE) {
|
||||
/* XXX the circ associated with this cpuworker will wait forever. Oops. */
|
||||
/* the circ associated with this cpuworker will have to wait until
|
||||
* it gets culled in run_connection_housekeeping(), since we have
|
||||
* no way to find out which circ it was. */
|
||||
log_fn(LOG_WARN,"...and leaving a circuit waiting. Oh well.");
|
||||
num_cpuworkers_busy--;
|
||||
}
|
||||
num_cpuworkers--;
|
||||
spawn_enough_cpuworkers(); /* try to regrow. hope we don't end up spinning. */
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -215,7 +219,6 @@ static void spawn_enough_cpuworkers(void) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void process_pending_task(connection_t *cpuworker) {
|
||||
circuit_t *circ;
|
||||
|
||||
@ -233,8 +236,8 @@ static void process_pending_task(connection_t *cpuworker) {
|
||||
/* if cpuworker is defined, assert that he's idle, and use him. else,
|
||||
* look for an idle cpuworker and use him. if none idle, queue task onto
|
||||
* the pending onion list and return.
|
||||
* If question_type is CPUWORKER_TASK_ONION then task is a circ, else
|
||||
* (something else)
|
||||
* If question_type is CPUWORKER_TASK_ONION then task is a circ.
|
||||
* No other question_types are allowed.
|
||||
*/
|
||||
int assign_to_cpuworker(connection_t *cpuworker, unsigned char question_type,
|
||||
void *task) {
|
||||
@ -271,7 +274,7 @@ int assign_to_cpuworker(connection_t *cpuworker, unsigned char question_type,
|
||||
connection_write_to_buf(tag, sizeof(tag), cpuworker);
|
||||
connection_write_to_buf(circ->onionskin, DH_ONIONSKIN_LEN, cpuworker);
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -802,6 +802,9 @@ int tor_main(int argc, char *argv[]) {
|
||||
if(options.OnionRouter) { /* only spawn dns handlers if we're a router */
|
||||
dns_init(); /* initialize the dns resolve tree, and spawn workers */
|
||||
}
|
||||
if(options.SocksPort) {
|
||||
client_dns_init(); /* init the client dns cache */
|
||||
}
|
||||
|
||||
#ifndef MS_WINDOWS /* do signal stuff only on unix */
|
||||
signal (SIGINT, catch); /* catch kills so we can exit cleanly */
|
||||
|
@ -6,16 +6,11 @@
|
||||
|
||||
extern or_options_t options; /* command-line and config-file options */
|
||||
|
||||
struct cpath_build_state_t {
|
||||
int desired_path_len;
|
||||
char *chosen_exit; /* nicknames */
|
||||
};
|
||||
|
||||
static int count_acceptable_routers(routerinfo_t **rarray, int rarray_len);
|
||||
|
||||
int decide_circ_id_type(char *local_nick, char *remote_nick) {
|
||||
int result;
|
||||
|
||||
|
||||
assert(remote_nick);
|
||||
if(!local_nick)
|
||||
return CIRC_ID_TYPE_LOWER;
|
||||
@ -306,8 +301,7 @@ static routerinfo_t *choose_good_exit_server(directory_t *dir)
|
||||
}
|
||||
}
|
||||
}
|
||||
tor_free(n_supported);
|
||||
tor_free(n_maybe_supported);
|
||||
tor_free(n_supported); tor_free(n_maybe_supported);
|
||||
i = crypto_pseudo_rand_int(dir->n_routers);
|
||||
log_fn(LOG_DEBUG, "Chose exit server '%s'", dir->routers[i]->nickname);
|
||||
return dir->routers[i];
|
||||
@ -324,7 +318,6 @@ cpath_build_state_t *onion_new_cpath_build_state(void) {
|
||||
return NULL;
|
||||
info = tor_malloc(sizeof(cpath_build_state_t));
|
||||
info->desired_path_len = r;
|
||||
/* XXX This is leaked */
|
||||
info->chosen_exit = tor_strdup(choose_good_exit_server(dir)->nickname);
|
||||
return info;
|
||||
}
|
||||
@ -413,6 +406,7 @@ int onion_extend_cpath(crypt_path_t **head_ptr, cpath_build_state_t *state, rout
|
||||
} else if (cur_len == state->desired_path_len - 1) { /* Picking last node */
|
||||
log_fn(LOG_DEBUG, "Contemplating last hop: choice already made.");
|
||||
choice = router_get_by_nickname(state->chosen_exit);
|
||||
/* XXX check if null */
|
||||
} else {
|
||||
log_fn(LOG_DEBUG, "Contemplating intermediate hop: random choice.");
|
||||
choice = rarray[crypto_pseudo_rand_int(rarray_len)];
|
||||
|
@ -392,7 +392,10 @@ struct crypt_path_t {
|
||||
|
||||
typedef struct crypt_path_t crypt_path_t;
|
||||
|
||||
typedef struct cpath_build_state_t cpath_build_state_t;
|
||||
typedef struct {
|
||||
int desired_path_len;
|
||||
char *chosen_exit; /* nickname of planned exit node */
|
||||
} cpath_build_state_t;
|
||||
|
||||
/* struct for a path (circuit) through the network */
|
||||
struct circuit_t {
|
||||
@ -470,7 +473,7 @@ struct socks_request_t {
|
||||
char socks_version;
|
||||
int replylen;
|
||||
char reply[MAX_SOCKS_REPLY_LEN];
|
||||
char addr[MAX_SOCKS_ADDR_LEN];
|
||||
char address[MAX_SOCKS_ADDR_LEN];
|
||||
uint16_t port;
|
||||
};
|
||||
|
||||
@ -627,6 +630,8 @@ extern uint64_t stats_n_data_bytes_packaged;
|
||||
extern uint64_t stats_n_data_cells_received;
|
||||
extern uint64_t stats_n_data_bytes_received;
|
||||
|
||||
void client_dns_init(void);
|
||||
|
||||
/********************************* connection_or.c ***************************/
|
||||
|
||||
int connection_or_process_inbuf(connection_t *conn);
|
||||
|
@ -63,7 +63,7 @@ routerinfo_t *router_pick_directory_server(void) {
|
||||
return router;
|
||||
}
|
||||
|
||||
log_fn(LOG_WARN,"No dirservers are up. Giving them all another chance.");
|
||||
log_fn(LOG_INFO,"No dirservers are reachable. Trying them all again.");
|
||||
/* no running dir servers found? go through and mark them all as up,
|
||||
* and we'll cycle through the list again. */
|
||||
for(i=0;i<directory->n_routers;i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user