mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 22:03:31 +01:00
r14101@tombo: nickm | 2008-02-10 13:24:27 -0500
Merge connection_or_act_on_netinfo into command.c; remove some fields from or_handshake_state(). svn:r13458
This commit is contained in:
parent
8a7c4e6b62
commit
a4db22f675
@ -503,6 +503,9 @@ command_process_netinfo_cell(cell_t *cell, or_connection_t *conn)
|
|||||||
uint8_t n_other_addrs;
|
uint8_t n_other_addrs;
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
|
|
||||||
|
long apparent_skew = 0;
|
||||||
|
uint32_t my_apparent_addr = 0;
|
||||||
|
|
||||||
if (conn->link_proto < 2) {
|
if (conn->link_proto < 2) {
|
||||||
log_fn(LOG_PROTOCOL_WARN, LD_OR,
|
log_fn(LOG_PROTOCOL_WARN, LD_OR,
|
||||||
"Received a NETINFO cell on %s connection; dropping.",
|
"Received a NETINFO cell on %s connection; dropping.",
|
||||||
@ -516,15 +519,10 @@ command_process_netinfo_cell(cell_t *cell, or_connection_t *conn)
|
|||||||
}
|
}
|
||||||
tor_assert(conn->handshake_state &&
|
tor_assert(conn->handshake_state &&
|
||||||
conn->handshake_state->received_versions);
|
conn->handshake_state->received_versions);
|
||||||
if (conn->handshake_state->received_netinfo) {
|
|
||||||
log_fn(LOG_PROTOCOL_WARN, LD_OR,
|
|
||||||
"Received a duplicate NETINFO cell; dropping.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/* Decode the cell. */
|
/* Decode the cell. */
|
||||||
timestamp = ntohl(get_uint32(cell->payload));
|
timestamp = ntohl(get_uint32(cell->payload));
|
||||||
if (abs(now - conn->handshake_state->sent_versions_at) < 180) {
|
if (abs(now - conn->handshake_state->sent_versions_at) < 180) {
|
||||||
conn->handshake_state->apparent_skew = now - timestamp;
|
apparent_skew = now - timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
my_addr_type = (uint8_t) cell->payload[4];
|
my_addr_type = (uint8_t) cell->payload[4];
|
||||||
@ -538,7 +536,7 @@ command_process_netinfo_cell(cell_t *cell, or_connection_t *conn)
|
|||||||
connection_mark_for_close(TO_CONN(conn));
|
connection_mark_for_close(TO_CONN(conn));
|
||||||
return;
|
return;
|
||||||
} else if (my_addr_type == RESOLVED_TYPE_IPV4 && my_addr_len == 4) {
|
} else if (my_addr_type == RESOLVED_TYPE_IPV4 && my_addr_len == 4) {
|
||||||
conn->handshake_state->my_apparent_addr = ntohl(get_uint32(my_addr_ptr));
|
my_apparent_addr = ntohl(get_uint32(my_addr_ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
n_other_addrs = (uint8_t) *cp++;
|
n_other_addrs = (uint8_t) *cp++;
|
||||||
@ -556,7 +554,7 @@ command_process_netinfo_cell(cell_t *cell, or_connection_t *conn)
|
|||||||
if (other_addr_type == RESOLVED_TYPE_IPV4 && other_addr_len == 4) {
|
if (other_addr_type == RESOLVED_TYPE_IPV4 && other_addr_len == 4) {
|
||||||
uint32_t addr = ntohl(get_uint32(cp));
|
uint32_t addr = ntohl(get_uint32(cp));
|
||||||
if (addr == conn->real_addr) {
|
if (addr == conn->real_addr) {
|
||||||
conn->handshake_state->apparently_canonical = 1;
|
conn->is_canonical = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -564,17 +562,33 @@ command_process_netinfo_cell(cell_t *cell, or_connection_t *conn)
|
|||||||
--n_other_addrs;
|
--n_other_addrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
conn->handshake_state->received_netinfo = 1;
|
/* Act on apparent skew. */
|
||||||
|
/** Warn when we get a netinfo skew with at least this value. */
|
||||||
if (conn->handshake_state->apparently_canonical) {
|
#define NETINFO_NOTICE_SKEW 3600
|
||||||
conn->is_canonical = 1;
|
if (abs(apparent_skew) > NETINFO_NOTICE_SKEW &&
|
||||||
|
router_get_by_digest(conn->identity_digest)) {
|
||||||
|
char dbuf[64];
|
||||||
|
/*XXXX020 not always warn!*/
|
||||||
|
format_time_interval(dbuf, sizeof(dbuf), apparent_skew);
|
||||||
|
log_fn(LOG_WARN, LD_HTTP, "Received NETINFO cell with skewed time from "
|
||||||
|
"server at %s:%d. It seems that our clock is %s by %s, or "
|
||||||
|
"that theirs is %s. Tor requires an accurate clock to work: "
|
||||||
|
"please check your time and date settings.",
|
||||||
|
conn->_base.address, (int)conn->_base.port,
|
||||||
|
apparent_skew>0 ? "ahead" : "behind", dbuf,
|
||||||
|
apparent_skew>0 ? "behind" : "ahead");
|
||||||
|
control_event_general_status(LOG_WARN,
|
||||||
|
"CLOCK_SKEW SKEW=%ld SOURCE=OR:%s:%d",
|
||||||
|
apparent_skew, conn->_base.address, conn->_base.port);
|
||||||
}
|
}
|
||||||
if (connection_or_act_on_netinfo(conn)<0 ||
|
|
||||||
connection_or_set_state_open(conn)<0)
|
|
||||||
connection_mark_for_close(TO_CONN(conn));
|
|
||||||
|
|
||||||
log_info(LD_OR, "Got good NETINFO cell from %s",
|
/*XXX020 maybe act on my_apparent_addr */
|
||||||
safe_str(conn->_base.address));
|
|
||||||
|
if (connection_or_set_state_open(conn)<0)
|
||||||
|
connection_mark_for_close(TO_CONN(conn));
|
||||||
|
else
|
||||||
|
log_info(LD_OR, "Got good NETINFO cell from %s",
|
||||||
|
safe_str(conn->_base.address));
|
||||||
assert_connection_ok(TO_CONN(conn),time(NULL));
|
assert_connection_ok(TO_CONN(conn),time(NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1085,42 +1085,3 @@ connection_or_send_netinfo(or_connection_t *conn)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** DOCDOC Called when we're done authenticating; act on stuff we
|
|
||||||
* learned in netinfo. */
|
|
||||||
int
|
|
||||||
connection_or_act_on_netinfo(or_connection_t *conn)
|
|
||||||
{
|
|
||||||
long delta;
|
|
||||||
/*XXXX020 merge this into handle_netinfo.*/
|
|
||||||
if (!conn->handshake_state)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
tor_assert(conn->handshake_state->received_versions != 0);
|
|
||||||
|
|
||||||
delta = conn->handshake_state->apparent_skew;
|
|
||||||
/** Warn when we get a netinfo skew with at least this value. */
|
|
||||||
#define NETINFO_NOTICE_SKEW 3600
|
|
||||||
if (abs(delta) > NETINFO_NOTICE_SKEW &&
|
|
||||||
router_get_by_digest(conn->identity_digest)) {
|
|
||||||
char dbuf[64];
|
|
||||||
/*XXXX020 not always warn!*/
|
|
||||||
format_time_interval(dbuf, sizeof(dbuf), delta);
|
|
||||||
log_fn(LOG_WARN, LD_HTTP, "Received NETINFO cell with skewed time from "
|
|
||||||
"server at %s:%d. It seems that our clock is %s by %s, or "
|
|
||||||
"that theirs is %s. Tor requires an accurate clock to work: "
|
|
||||||
"please check your time and date settings.",
|
|
||||||
conn->_base.address, (int)conn->_base.port,
|
|
||||||
delta>0 ? "ahead" : "behind", dbuf,
|
|
||||||
delta>0 ? "behind" : "ahead");
|
|
||||||
control_event_general_status(LOG_WARN,
|
|
||||||
"CLOCK_SKEW SKEW=%ld SOURCE=OR:%s:%d",
|
|
||||||
delta, conn->_base.address, conn->_base.port);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (conn->handshake_state->apparently_canonical)
|
|
||||||
conn->is_canonical = 1;
|
|
||||||
|
|
||||||
/* XXX020 possibly, learn my address from my_apparent_addr */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -893,11 +893,6 @@ typedef struct or_handshake_state_t {
|
|||||||
unsigned int started_here : 1;
|
unsigned int started_here : 1;
|
||||||
unsigned int received_versions : 1;
|
unsigned int received_versions : 1;
|
||||||
|
|
||||||
/* from netinfo: XXXX020 totally useless. */
|
|
||||||
unsigned int received_netinfo : 1;
|
|
||||||
long apparent_skew;
|
|
||||||
uint32_t my_apparent_addr;
|
|
||||||
unsigned int apparently_canonical;
|
|
||||||
} or_handshake_state_t;
|
} or_handshake_state_t;
|
||||||
|
|
||||||
/** Subtype of connection_t for an "OR connection" -- that is, one that speaks
|
/** Subtype of connection_t for an "OR connection" -- that is, one that speaks
|
||||||
@ -2870,7 +2865,6 @@ void cell_pack(packed_cell_t *dest, const cell_t *src);
|
|||||||
void var_cell_pack_header(const var_cell_t *cell, char *hdr_out);
|
void var_cell_pack_header(const var_cell_t *cell, char *hdr_out);
|
||||||
var_cell_t *var_cell_new(uint16_t payload_len);
|
var_cell_t *var_cell_new(uint16_t payload_len);
|
||||||
void var_cell_free(var_cell_t *cell);
|
void var_cell_free(var_cell_t *cell);
|
||||||
int connection_or_act_on_netinfo(or_connection_t *conn);
|
|
||||||
|
|
||||||
/********************************* control.c ***************************/
|
/********************************* control.c ***************************/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user