Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
David Goulet
Tor
Commits
22727b4e
Commit
22727b4e
authored
Nov 28, 2004
by
Roger Dingledine
Browse files
wrong is ok, and right is fine, but in between is apparently
totally unacceptable to me. svn:r3005
parent
f7c6ad06
Changes
20
Hide whitespace changes
Inline
Side-by-side
src/common/container.h
View file @
22727b4e
...
...
@@ -61,7 +61,7 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join,
int var ## _sl_idx, var ## _sl_len=smartlist_len(sl); \
type var; \
for (var ## _sl_idx = 0; var ## _sl_idx < var ## _sl_len; \
++var ## _sl_idx) {
\
++var ## _sl_idx) { \
var = smartlist_get((sl),var ## _sl_idx); \
cmd; \
} } while (0)
...
...
src/common/log.c
View file @
22727b4e
...
...
@@ -105,7 +105,7 @@ static int log_tor_version(logfile_t *lf, int reset)
tor_snprintf
(
buf
+
n
,
sizeof
(
buf
)
-
n
,
"Tor %s opening %slog file.
\n
"
,
VERSION
,
is_new
?
"new "
:
""
);
if
(
fputs
(
buf
,
lf
->
file
)
==
EOF
||
fflush
(
lf
->
file
)
==
EOF
)
/* error */
fflush
(
lf
->
file
)
==
EOF
)
/* error */
return
-
1
;
/* failed */
return
0
;
}
...
...
@@ -189,7 +189,7 @@ logv(int severity, const char *funcname, const char *format, va_list ap)
continue
;
}
if
(
fputs
(
buf
,
lf
->
file
)
==
EOF
||
fflush
(
lf
->
file
)
==
EOF
)
{
/* error */
fflush
(
lf
->
file
)
==
EOF
)
{
/* error */
/* don't log the error! Blow away this log entry and continue. */
logfile_t
*
victim
=
lf
;
lf
=
victim
->
next
;
...
...
src/common/util.c
View file @
22727b4e
...
...
@@ -1208,7 +1208,7 @@ parse_addr_and_port_range(const char *s, uint32_t *addr_out,
}
else
{
endptr
=
NULL
;
*
port_min_out
=
(
uint16_t
)
tor_parse_long
(
port
,
10
,
1
,
65535
,
NULL
,
&
endptr
);
NULL
,
&
endptr
);
if
(
*
endptr
==
'-'
)
{
port
=
endptr
+
1
;
endptr
=
NULL
;
...
...
src/or/buffers.c
View file @
22727b4e
...
...
@@ -490,7 +490,7 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) {
return
0
;
/* not yet */
req
->
command
=
(
unsigned
char
)
*
(
buf
->
mem
+
1
);
if
(
req
->
command
!=
SOCKS_COMMAND_CONNECT
&&
req
->
command
!=
SOCKS_COMMAND_RESOLVE
)
{
req
->
command
!=
SOCKS_COMMAND_RESOLVE
)
{
/* not a connect or resolve? we don't support it. */
log_fn
(
LOG_WARN
,
"socks5: command %d not recognized. Rejecting."
,
req
->
command
);
...
...
@@ -548,7 +548,7 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) {
req
->
command
=
(
unsigned
char
)
*
(
buf
->
mem
+
1
);
if
(
req
->
command
!=
SOCKS_COMMAND_CONNECT
&&
req
->
command
!=
SOCKS_COMMAND_RESOLVE
)
{
req
->
command
!=
SOCKS_COMMAND_RESOLVE
)
{
/* not a connect or resolve? we don't support it. */
log_fn
(
LOG_WARN
,
"socks4: command %d not recognized. Rejecting."
,
req
->
command
);
...
...
src/or/circuitbuild.c
View file @
22727b4e
...
...
@@ -281,7 +281,7 @@ circuit_t *circuit_establish_circuit(uint8_t purpose,
}
if
(
onion_extend_cpath
(
&
circ
->
cpath
,
circ
->
build_state
,
&
firsthop
)
<
0
||
!
CIRCUIT_IS_ORIGIN
(
circ
))
{
!
CIRCUIT_IS_ORIGIN
(
circ
))
{
log_fn
(
LOG_INFO
,
"Generating first cpath hop failed."
);
circuit_mark_for_close
(
circ
);
return
NULL
;
...
...
@@ -345,9 +345,9 @@ void circuit_n_conn_done(connection_t *or_conn, int status) {
if
(
circ
->
marked_for_close
)
continue
;
if
(
!
circ
->
n_conn
&&
circ
->
n_addr
==
or_conn
->
addr
&&
circ
->
n_port
==
or_conn
->
port
&&
!
memcmp
(
or_conn
->
identity_digest
,
circ
->
n_conn_id_digest
,
DIGEST_LEN
))
{
circ
->
n_addr
==
or_conn
->
addr
&&
circ
->
n_port
==
or_conn
->
port
&&
!
memcmp
(
or_conn
->
identity_digest
,
circ
->
n_conn_id_digest
,
DIGEST_LEN
))
{
tor_assert
(
circ
->
state
==
CIRCUIT_STATE_OR_WAIT
);
if
(
!
status
)
{
/* or_conn failed; close circ */
log_fn
(
LOG_INFO
,
"or_conn failed. Closing circ."
);
...
...
@@ -434,8 +434,8 @@ int circuit_send_next_onion_skin(circuit_t *circ) {
}
if
(
onion_skin_create
(
router
->
onion_pkey
,
&
(
circ
->
cpath
->
handshake_state
),
payload
)
<
0
)
{
&
(
circ
->
cpath
->
handshake_state
),
payload
)
<
0
)
{
log_fn
(
LOG_WARN
,
"onion_skin_create (first hop) failed."
);
return
-
1
;
}
...
...
@@ -486,7 +486,7 @@ int circuit_send_next_onion_skin(circuit_t *circ) {
/* send it to hop->prev, because it will transfer
* it to a create cell and then send to hop */
if
(
connection_edge_send_command
(
NULL
,
circ
,
RELAY_COMMAND_EXTEND
,
payload
,
payload_len
,
hop
->
prev
)
<
0
)
payload
,
payload_len
,
hop
->
prev
)
<
0
)
return
0
;
/* circuit is closed */
hop
->
state
=
CPATH_STATE_AWAITING_KEYS
;
...
...
@@ -607,7 +607,7 @@ int circuit_init_cpath_crypto(crypt_path_t *cpath, char *key_data, int reverse)
return
-
1
;
}
if
(
!
(
cpath
->
b_crypto
=
crypto_create_init_cipher
(
key_data
+
(
2
*
DIGEST_LEN
)
+
CIPHER_KEY_LEN
,
0
)))
{
crypto_create_init_cipher
(
key_data
+
(
2
*
DIGEST_LEN
)
+
CIPHER_KEY_LEN
,
0
)))
{
log
(
LOG_WARN
,
"backward cipher initialization failed."
);
return
-
1
;
}
...
...
@@ -651,7 +651,7 @@ int circuit_finish_handshake(circuit_t *circ, char *reply) {
tor_assert
(
hop
->
state
==
CPATH_STATE_AWAITING_KEYS
);
if
(
onion_skin_client_handshake
(
hop
->
handshake_state
,
reply
,
keys
,
DIGEST_LEN
*
2
+
CIPHER_KEY_LEN
*
2
)
<
0
)
{
DIGEST_LEN
*
2
+
CIPHER_KEY_LEN
*
2
)
<
0
)
{
log_fn
(
LOG_WARN
,
"onion_skin_client_handshake failed."
);
return
-
1
;
}
...
...
@@ -879,7 +879,7 @@ static routerinfo_t *choose_good_exit_server_general(routerlist_t *dir)
continue
;
/* skip routers that are known to be down */
}
if
(
!
router
->
is_verified
&&
(
!
(
options
->
_AllowUnverified
&
ALLOW_UNVERIFIED_EXIT
)
||
(
!
(
options
->
_AllowUnverified
&
ALLOW_UNVERIFIED_EXIT
)
||
router_is_unreliable_router
(
router
,
1
,
1
)))
{
/* if it's unverified, and either we don't want it or it's unsuitable */
n_supported
[
i
]
=
-
1
;
...
...
@@ -894,7 +894,7 @@ static routerinfo_t *choose_good_exit_server_general(routerlist_t *dir)
continue
;
/* skip routers that reject all */
}
if
(
smartlist_len
(
preferredentries
)
==
1
&&
router
==
(
routerinfo_t
*
)
smartlist_get
(
preferredentries
,
0
))
{
router
==
(
routerinfo_t
*
)
smartlist_get
(
preferredentries
,
0
))
{
n_supported
[
i
]
=
-
1
;
log_fn
(
LOG_DEBUG
,
"Skipping node %s (index %d) -- it's our only preferred entry node."
,
router
->
nickname
,
i
);
continue
;
...
...
src/or/circuitlist.c
View file @
22727b4e
...
...
@@ -317,10 +317,12 @@ circuit_get_youngest_clean_open(uint8_t purpose) {
circuit_t
*
youngest
=
NULL
;
for
(
circ
=
global_circuitlist
;
circ
;
circ
=
circ
->
next
)
{
if
(
CIRCUIT_IS_ORIGIN
(
circ
)
&&
circ
->
state
==
CIRCUIT_STATE_OPEN
&&
!
circ
->
marked_for_close
&&
circ
->
purpose
==
purpose
&&
!
circ
->
timestamp_dirty
&&
(
!
youngest
||
youngest
->
timestamp_created
<
circ
->
timestamp_created
))
if
(
CIRCUIT_IS_ORIGIN
(
circ
)
&&
circ
->
state
==
CIRCUIT_STATE_OPEN
&&
!
circ
->
marked_for_close
&&
circ
->
purpose
==
purpose
&&
!
circ
->
timestamp_dirty
&&
(
!
youngest
||
youngest
->
timestamp_created
<
circ
->
timestamp_created
))
youngest
=
circ
;
}
return
youngest
;
...
...
src/or/circuituse.c
View file @
22727b4e
...
...
@@ -89,7 +89,7 @@ static int circuit_is_acceptable(circuit_t *circ,
}
}
else
{
/* not general */
if
(
rend_cmp_service_ids
(
conn
->
rend_query
,
circ
->
rend_query
)
&&
(
circ
->
rend_query
[
0
]
||
purpose
!=
CIRCUIT_PURPOSE_C_REND_JOINED
))
{
(
circ
->
rend_query
[
0
]
||
purpose
!=
CIRCUIT_PURPOSE_C_REND_JOINED
))
{
/* this circ is not for this conn, and it's not suitable
* for cannibalizing either */
return
0
;
...
...
@@ -111,11 +111,11 @@ static int circuit_is_better(circuit_t *a, circuit_t *b, uint8_t purpose)
*/
if
(
b
->
timestamp_dirty
)
{
if
(
a
->
timestamp_dirty
&&
a
->
timestamp_dirty
>
b
->
timestamp_dirty
)
a
->
timestamp_dirty
>
b
->
timestamp_dirty
)
return
1
;
}
else
{
if
(
a
->
timestamp_dirty
||
a
->
timestamp_created
>
b
->
timestamp_created
)
a
->
timestamp_created
>
b
->
timestamp_created
)
return
1
;
}
break
;
...
...
@@ -199,7 +199,7 @@ void circuit_expire_building(time_t now) {
/* some debug logs, to help track bugs */
if
(
victim
->
purpose
>=
CIRCUIT_PURPOSE_C_INTRODUCING
&&
victim
->
purpose
<=
CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED
)
{
victim
->
purpose
<=
CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED
)
{
if
(
!
victim
->
timestamp_dirty
)
log_fn
(
LOG_DEBUG
,
"Considering %sopen purp %d to %s (circid %d). (clean)."
,
victim
->
state
==
CIRCUIT_STATE_OPEN
?
""
:
"non"
,
...
...
@@ -216,25 +216,25 @@ void circuit_expire_building(time_t now) {
/* if circ is !open, or if it's open but purpose is a non-finished
* intro or rend, then mark it for close */
if
(
victim
->
state
!=
CIRCUIT_STATE_OPEN
||
victim
->
purpose
==
CIRCUIT_PURPOSE_C_ESTABLISH_REND
||
victim
->
purpose
==
CIRCUIT_PURPOSE_C_INTRODUCING
||
victim
->
purpose
==
CIRCUIT_PURPOSE_S_ESTABLISH_INTRO
||
/* it's a rend_ready circ, but it's already picked a query */
(
victim
->
purpose
==
CIRCUIT_PURPOSE_C_REND_READY
&&
victim
->
rend_query
[
0
])
||
/* c_rend_ready circs measure age since timestamp_dirty,
* because that's set when they switch purposes
*/
/* rend and intro circs become dirty each time they
* make an introduction attempt. so timestamp_dirty
* will reflect the time since the last attempt.
*/
((
victim
->
purpose
==
CIRCUIT_PURPOSE_C_REND_READY
||
victim
->
purpose
==
CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED
||
victim
->
purpose
==
CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT
)
&&
victim
->
timestamp_dirty
+
MIN_SECONDS_BEFORE_EXPIRING_CIRC
>
now
))
{
victim
->
purpose
==
CIRCUIT_PURPOSE_C_ESTABLISH_REND
||
victim
->
purpose
==
CIRCUIT_PURPOSE_C_INTRODUCING
||
victim
->
purpose
==
CIRCUIT_PURPOSE_S_ESTABLISH_INTRO
||
/* it's a rend_ready circ, but it's already picked a query */
(
victim
->
purpose
==
CIRCUIT_PURPOSE_C_REND_READY
&&
victim
->
rend_query
[
0
])
||
/* c_rend_ready circs measure age since timestamp_dirty,
* because that's set when they switch purposes
*/
/* rend and intro circs become dirty each time they
* make an introduction attempt. so timestamp_dirty
* will reflect the time since the last attempt.
*/
((
victim
->
purpose
==
CIRCUIT_PURPOSE_C_REND_READY
||
victim
->
purpose
==
CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED
||
victim
->
purpose
==
CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT
)
&&
victim
->
timestamp_dirty
+
MIN_SECONDS_BEFORE_EXPIRING_CIRC
>
now
))
{
if
(
victim
->
n_conn
)
log_fn
(
LOG_INFO
,
"Abandoning circ %s:%d:%d (state %d:%s, purpose %d)"
,
victim
->
n_conn
->
address
,
victim
->
n_port
,
victim
->
n_circ_id
,
...
...
@@ -264,10 +264,12 @@ int circuit_stream_is_being_handled(connection_t *conn) {
time_t
now
=
time
(
NULL
);
for
(
circ
=
global_circuitlist
;
circ
;
circ
=
circ
->
next
)
{
if
(
CIRCUIT_IS_ORIGIN
(
circ
)
&&
circ
->
state
!=
CIRCUIT_STATE_OPEN
&&
!
circ
->
marked_for_close
&&
circ
->
purpose
==
CIRCUIT_PURPOSE_C_GENERAL
&&
(
!
circ
->
timestamp_dirty
||
circ
->
timestamp_dirty
+
get_options
()
->
NewCircuitPeriod
<
now
))
{
if
(
CIRCUIT_IS_ORIGIN
(
circ
)
&&
circ
->
state
!=
CIRCUIT_STATE_OPEN
&&
!
circ
->
marked_for_close
&&
circ
->
purpose
==
CIRCUIT_PURPOSE_C_GENERAL
&&
(
!
circ
->
timestamp_dirty
||
circ
->
timestamp_dirty
+
get_options
()
->
NewCircuitPeriod
<
now
))
{
exitrouter
=
router_get_by_digest
(
circ
->
build_state
->
chosen_exit_digest
);
if
(
exitrouter
&&
connection_ap_can_use_exit
(
conn
,
exitrouter
))
if
(
++
num
>=
MIN_CIRCUITS_HANDLING_STREAM
)
...
...
@@ -305,8 +307,9 @@ void circuit_build_needed_circs(time_t now) {
client_dns_clean
();
circuit_expire_old_circuits
();
if
(
get_options
()
->
RunTesting
&&
circ
&&
circ
->
timestamp_created
+
TESTING_CIRCUIT_INTERVAL
<
now
)
{
if
(
get_options
()
->
RunTesting
&&
circ
&&
circ
->
timestamp_created
+
TESTING_CIRCUIT_INTERVAL
<
now
)
{
log_fn
(
LOG_INFO
,
"Creating a new testing circuit."
);
circuit_launch_by_identity
(
CIRCUIT_PURPOSE_C_GENERAL
,
NULL
);
}
...
...
@@ -320,7 +323,7 @@ void circuit_build_needed_circs(time_t now) {
/* if there's no open circ, and less than 5 are on the way,
* go ahead and try another. */
if
(
!
circ
&&
circuit_count_building
(
CIRCUIT_PURPOSE_C_GENERAL
)
<
CIRCUIT_MIN_BUILDING_GENERAL
)
{
<
CIRCUIT_MIN_BUILDING_GENERAL
)
{
circuit_launch_by_identity
(
CIRCUIT_PURPOSE_C_GENERAL
,
NULL
);
}
...
...
@@ -720,7 +723,7 @@ circuit_get_open_circ_or_launch(connection_t *conn,
tor_free
(
exitname
);
if
(
circ
&&
(
desired_circuit_purpose
!=
CIRCUIT_PURPOSE_C_GENERAL
)
)
{
desired_circuit_purpose
!=
CIRCUIT_PURPOSE_C_GENERAL
)
{
/* then write the service_id into circ */
strlcpy
(
circ
->
rend_query
,
conn
->
rend_query
,
sizeof
(
circ
->
rend_query
));
}
...
...
src/or/connection.c
View file @
22727b4e
...
...
@@ -713,11 +713,11 @@ static void connection_consider_empty_buckets(connection_t *conn) {
return
;
}
if
(
connection_speaks_cells
(
conn
)
&&
conn
->
state
==
OR_CONN_STATE_OPEN
&&
conn
->
receiver_bucket
==
0
)
{
log_fn
(
LOG_DEBUG
,
"receiver bucket exhausted. Pausing."
);
conn
->
wants_to_read
=
1
;
connection_stop_reading
(
conn
);
conn
->
state
==
OR_CONN_STATE_OPEN
&&
conn
->
receiver_bucket
==
0
)
{
log_fn
(
LOG_DEBUG
,
"receiver bucket exhausted. Pausing."
);
conn
->
wants_to_read
=
1
;
connection_stop_reading
(
conn
);
}
}
...
...
@@ -757,12 +757,12 @@ void connection_bucket_refill(struct timeval *now) {
}
if
(
conn
->
wants_to_read
==
1
/* it's marked to turn reading back on now */
&&
global_read_bucket
>
0
/* and we're allowed to read */
&&
global_write_bucket
>
0
/* and we're allowed to write (XXXX,
* not the best place to check this.) */
&&
(
!
connection_speaks_cells
(
conn
)
||
conn
->
state
!=
OR_CONN_STATE_OPEN
||
conn
->
receiver_bucket
>
0
))
{
&&
global_read_bucket
>
0
/* and we're allowed to read */
&&
global_write_bucket
>
0
/* and we're allowed to write (XXXX,
* not the best place to check this.) */
&&
(
!
connection_speaks_cells
(
conn
)
||
conn
->
state
!=
OR_CONN_STATE_OPEN
||
conn
->
receiver_bucket
>
0
))
{
/* and either a non-cell conn or a cell conn with non-empty bucket */
log_fn
(
LOG_DEBUG
,
"waking up conn (fd %d)"
,
conn
->
s
);
conn
->
wants_to_read
=
0
;
...
...
@@ -839,7 +839,7 @@ loop_again:
/* XXX I suspect pollerr may make Windows not get to this point. :( */
router_mark_as_down
(
conn
->
identity_digest
);
if
(
conn
->
purpose
==
DIR_PURPOSE_FETCH_DIR
&&
!
all_trusted_directory_servers_down
())
{
!
all_trusted_directory_servers_down
())
{
log_fn
(
LOG_INFO
,
"Giving up on dirserver %s; trying another."
,
conn
->
address
);
directory_get_from_dirserver
(
DIR_PURPOSE_FETCH_DIR
,
NULL
);
}
...
...
@@ -1117,7 +1117,7 @@ connection_t *connection_exact_get_by_addr_port(uint32_t addr, uint16_t port) {
for
(
i
=
0
;
i
<
n
;
i
++
)
{
conn
=
carray
[
i
];
if
(
conn
->
addr
==
addr
&&
conn
->
port
==
port
&&
!
conn
->
marked_for_close
&&
(
!
best
||
best
->
timestamp_created
<
conn
->
timestamp_created
))
(
!
best
||
best
->
timestamp_created
<
conn
->
timestamp_created
))
best
=
conn
;
}
return
best
;
...
...
@@ -1134,9 +1134,9 @@ connection_t *connection_get_by_identity_digest(const char *digest, int type)
conn
=
carray
[
i
];
if
(
conn
->
type
!=
type
)
continue
;
if
(
!
memcmp
(
conn
->
identity_digest
,
digest
,
DIGEST_LEN
)
&&
!
conn
->
marked_for_close
&&
(
!
best
||
best
->
timestamp_created
<
conn
->
timestamp_created
))
if
(
!
memcmp
(
conn
->
identity_digest
,
digest
,
DIGEST_LEN
)
&&
!
conn
->
marked_for_close
&&
(
!
best
||
best
->
timestamp_created
<
conn
->
timestamp_created
))
best
=
conn
;
}
return
best
;
...
...
@@ -1207,8 +1207,8 @@ connection_t *connection_get_by_type_rendquery(int type, const char *rendquery)
for
(
i
=
0
;
i
<
n
;
i
++
)
{
conn
=
carray
[
i
];
if
(
conn
->
type
==
type
&&
!
conn
->
marked_for_close
&&
!
rend_cmp_service_ids
(
rendquery
,
conn
->
rend_query
))
!
conn
->
marked_for_close
&&
!
rend_cmp_service_ids
(
rendquery
,
conn
->
rend_query
))
return
conn
;
}
return
NULL
;
...
...
@@ -1217,9 +1217,9 @@ connection_t *connection_get_by_type_rendquery(int type, const char *rendquery)
/** Return 1 if <b>conn</b> is a listener conn, else return 0. */
int
connection_is_listener
(
connection_t
*
conn
)
{
if
(
conn
->
type
==
CONN_TYPE_OR_LISTENER
||
conn
->
type
==
CONN_TYPE_AP_LISTENER
||
conn
->
type
==
CONN_TYPE_DIR_LISTENER
||
conn
->
type
==
CONN_TYPE_CONTROL_LISTENER
)
conn
->
type
==
CONN_TYPE_AP_LISTENER
||
conn
->
type
==
CONN_TYPE_DIR_LISTENER
||
conn
->
type
==
CONN_TYPE_CONTROL_LISTENER
)
return
1
;
return
0
;
}
...
...
@@ -1234,9 +1234,9 @@ int connection_state_is_open(connection_t *conn) {
return
0
;
if
((
conn
->
type
==
CONN_TYPE_OR
&&
conn
->
state
==
OR_CONN_STATE_OPEN
)
||
(
conn
->
type
==
CONN_TYPE_AP
&&
conn
->
state
==
AP_CONN_STATE_OPEN
)
||
(
conn
->
type
==
CONN_TYPE_EXIT
&&
conn
->
state
==
EXIT_CONN_STATE_OPEN
)
||
(
conn
->
type
==
CONN_TYPE_CONTROL
&&
conn
->
state
==
CONTROL_CONN_STATE_OPEN
))
(
conn
->
type
==
CONN_TYPE_AP
&&
conn
->
state
==
AP_CONN_STATE_OPEN
)
||
(
conn
->
type
==
CONN_TYPE_EXIT
&&
conn
->
state
==
EXIT_CONN_STATE_OPEN
)
||
(
conn
->
type
==
CONN_TYPE_CONTROL
&&
conn
->
state
==
CONTROL_CONN_STATE_OPEN
))
return
1
;
return
0
;
...
...
src/or/connection_edge.c
View file @
22727b4e
...
...
@@ -213,12 +213,12 @@ int connection_edge_finished_connecting(connection_t *conn)
/* deliver a 'connected' relay cell back through the circuit. */
if
(
connection_edge_is_rendezvous_stream
(
conn
))
{
if
(
connection_edge_send_command
(
conn
,
circuit_get_by_conn
(
conn
),
RELAY_COMMAND_CONNECTED
,
NULL
,
0
,
conn
->
cpath_layer
)
<
0
)
RELAY_COMMAND_CONNECTED
,
NULL
,
0
,
conn
->
cpath_layer
)
<
0
)
return
0
;
/* circuit is closed, don't continue */
}
else
{
*
(
uint32_t
*
)
connected_payload
=
htonl
(
conn
->
addr
);
if
(
connection_edge_send_command
(
conn
,
circuit_get_by_conn
(
conn
),
RELAY_COMMAND_CONNECTED
,
connected_payload
,
4
,
conn
->
cpath_layer
)
<
0
)
RELAY_COMMAND_CONNECTED
,
connected_payload
,
4
,
conn
->
cpath_layer
)
<
0
)
return
0
;
/* circuit is closed, don't continue */
}
tor_assert
(
conn
->
package_window
>
0
);
...
...
@@ -515,7 +515,7 @@ int connection_ap_handshake_send_begin(connection_t *ap_conn, circuit_t *circ)
log_fn
(
LOG_DEBUG
,
"Sending relay cell to begin stream %d."
,
ap_conn
->
stream_id
);
if
(
connection_edge_send_command
(
ap_conn
,
circ
,
RELAY_COMMAND_BEGIN
,
payload
,
payload_len
,
ap_conn
->
cpath_layer
)
<
0
)
payload
,
payload_len
,
ap_conn
->
cpath_layer
)
<
0
)
return
-
1
;
/* circuit is closed, don't continue */
ap_conn
->
package_window
=
STREAMWINDOW_START
;
...
...
@@ -1000,8 +1000,8 @@ int connection_ap_can_use_exit(connection_t *conn, routerinfo_t *exit)
return
tor_version_as_new_as
(
exit
->
platform
,
"0.0.9pre1"
);
}
addr
=
client_dns_lookup_entry
(
conn
->
socks_request
->
address
);
if
(
router_compare_addr_to_addr_policy
(
addr
,
conn
->
socks_request
->
port
,
exit
->
exit_policy
)
<
0
)
if
(
router_compare_addr_to_addr_policy
(
addr
,
conn
->
socks_request
->
port
,
exit
->
exit_policy
)
<
0
)
return
0
;
return
1
;
}
...
...
src/or/connection_or.c
View file @
22727b4e
...
...
@@ -208,7 +208,7 @@ connection_t *connection_or_connect(uint32_t addr, uint16_t port,
tor_assert
(
id_digest
);
if
(
server_mode
(
get_options
())
&&
(
me
=
router_get_my_routerinfo
())
&&
!
memcmp
(
me
->
identity_digest
,
id_digest
,
DIGEST_LEN
))
{
!
memcmp
(
me
->
identity_digest
,
id_digest
,
DIGEST_LEN
))
{
log_fn
(
LOG_WARN
,
"Request to connect to myself! Failing."
);
return
NULL
;
}
...
...
@@ -385,8 +385,8 @@ connection_tls_finish_handshake(connection_t *conn) {
router
=
router_get_by_nickname
(
nickname
);
if
(
router
&&
/* we know this nickname */
router
->
is_verified
&&
/* make sure it's the right guy */
memcmp
(
digest_rcvd
,
router
->
identity_digest
,
DIGEST_LEN
)
!=
0
)
{
router
->
is_verified
&&
/* make sure it's the right guy */
memcmp
(
digest_rcvd
,
router
->
identity_digest
,
DIGEST_LEN
)
!=
0
)
{
log_fn
(
LOG_WARN
,
"Identity key not as expected for router claiming to be '%s' (%s:%d) "
,
nickname
,
conn
->
address
,
conn
->
port
);
return
-
1
;
}
...
...
@@ -455,7 +455,7 @@ void connection_or_write_cell_to_buf(const cell_t *cell, connection_t *conn) {
* during periods of high load we won't read the entire megabyte from
* input before pushing any data out. */
if (conn->outbuf_flushlen-CELL_NETWORK_SIZE < MIN_TLS_FLUSHLEN &&
conn->outbuf_flushlen >= MIN_TLS_FLUSHLEN) {
conn->outbuf_flushlen >= MIN_TLS_FLUSHLEN) {
int extra = conn->outbuf_flushlen - MIN_TLS_FLUSHLEN;
conn->outbuf_flushlen = MIN_TLS_FLUSHLEN;
if (connection_handle_write(conn) < 0) {
...
...
src/or/cpuworker.c
View file @
22727b4e
...
...
@@ -235,7 +235,7 @@ static int cpuworker_main(void *data) {
if
(
question_type
==
CPUWORKER_TASK_ONION
)
{
if
(
onion_skin_server_handshake
(
question
,
onion_key
,
last_onion_key
,
reply_to_proxy
,
keys
,
40
+
32
)
<
0
)
{
reply_to_proxy
,
keys
,
40
+
32
)
<
0
)
{
/* failure */
log_fn
(
LOG_WARN
,
"onion_skin_server_handshake failed."
);
memset
(
buf
,
0
,
LEN_ONION_RESPONSE
);
/* send all zeros for failure */
...
...
src/or/directory.c
View file @
22727b4e
...
...
@@ -277,14 +277,14 @@ directory_initiate_command(const char *address, uint32_t addr,
conn
->
state
=
DIR_CONN_STATE_CONNECTING
;
if
(
purpose
==
DIR_PURPOSE_FETCH_DIR
||
purpose
==
DIR_PURPOSE_UPLOAD_DIR
||
purpose
==
DIR_PURPOSE_FETCH_RUNNING_LIST
)
{
purpose
==
DIR_PURPOSE_UPLOAD_DIR
||
purpose
==
DIR_PURPOSE_FETCH_RUNNING_LIST
)
{
/* then we want to connect directly */
switch
(
connection_connect
(
conn
,
conn
->
address
,
addr
,
dir_port
))
{
case
-
1
:
router_mark_as_down
(
conn
->
identity_digest
);
/* don't try him again */
if
(
purpose
==
DIR_PURPOSE_FETCH_DIR
&&
!
all_trusted_directory_servers_down
())
{
!
all_trusted_directory_servers_down
())
{
log_fn
(
LOG_INFO
,
"Giving up on dirserver '%s'; trying another."
,
conn
->
address
);
directory_get_from_dirserver
(
purpose
,
NULL
);
}
...
...
@@ -475,8 +475,8 @@ parse_http_response(const char *headers, int *code, time_t *date,
while
(
isspace
((
int
)
*
headers
))
headers
++
;
/* tolerate leading whitespace */
if
(
sscanf
(
headers
,
"HTTP/1.%d %d"
,
&
n1
,
&
n2
)
<
2
||
(
n1
!=
0
&&
n1
!=
1
)
||
(
n2
<
100
||
n2
>=
600
))
{
(
n1
!=
0
&&
n1
!=
1
)
||
(
n2
<
100
||
n2
>=
600
))
{
log_fn
(
LOG_WARN
,
"Failed to parse header '%s'"
,
headers
);
return
-
1
;
}
...
...
@@ -538,8 +538,8 @@ connection_dir_client_reached_eof(connection_t *conn)
int
compression
;
switch
(
fetch_from_buf_http
(
conn
->
inbuf
,
&
headers
,
MAX_HEADERS_SIZE
,
&
body
,
&
body_len
,
MAX_DIR_SIZE
))
{
&
headers
,
MAX_HEADERS_SIZE
,
&
body
,
&
body_len
,
MAX_DIR_SIZE
))
{
case
-
1
:
/* overflow */
log_fn
(
LOG_WARN
,
"'fetch' response too large. Failing."
);
return
-
1
;
...
...
@@ -550,7 +550,7 @@ connection_dir_client_reached_eof(connection_t *conn)
}
if
(
parse_http_response
(
headers
,
&
status_code
,
&
date_header
,
&
compression
)
<
0
)
{
&
compression
)
<
0
)
{
log_fn
(
LOG_WARN
,
"Unparseable headers. Closing."
);
tor_free
(
body
);
tor_free
(
headers
);
return
-
1
;
...
...
@@ -782,7 +782,7 @@ directory_handle_command_get(connection_t *conn, char *headers,
}
if
(
!
strcmp
(
url
,
"/tor/running-routers"
)
||
!
strcmp
(
url
,
"/tor/running-routers.z"
))
{
/* running-routers fetch */
!
strcmp
(
url
,
"/tor/running-routers.z"
))
{
/* running-routers fetch */
int
deflated
=
!
strcmp
(
url
,
"/tor/dir.z"
);
tor_free
(
url
);
if
(
!
authdir_mode
(
get_options
()))
{
...
...
@@ -926,8 +926,8 @@ static int directory_handle_command(connection_t *conn) {
tor_assert
(
conn
->
type
==
CONN_TYPE_DIR
);
switch
(
fetch_from_buf_http
(
conn
->
inbuf
,
&
headers
,
MAX_HEADERS_SIZE
,
&
body
,
&
body_len
,
MAX_BODY_SIZE
))
{
&
headers
,
MAX_HEADERS_SIZE
,
&
body
,
&
body_len
,
MAX_BODY_SIZE
))
{
case
-
1
:
/* overflow */
log_fn
(
LOG_WARN
,
"Invalid input. Closing."
);
return
-
1
;
...
...
src/or/dirserv.c
View file @
22727b4e
...
...
@@ -114,7 +114,7 @@ dirserv_parse_fingerprint_file(const char *fname)
continue
;
}
if
(
strlen
(
fingerprint
)
!=
FINGERPRINT_LEN
||
!
crypto_pk_check_fingerprint_syntax
(
fingerprint
))
{
!
crypto_pk_check_fingerprint_syntax
(
fingerprint
))
{
log_fn
(
LOG_WARN
,
"Invalid fingerprint (nickname '%s', fingerprint %s). Skipping."
,
nickname
,
fingerprint
);
continue
;
...
...
src/or/dns.c
View file @
22727b4e
...
...
@@ -353,8 +353,8 @@ void assert_connection_edge_not_dns_pending(connection_t *conn) {
SPLAY_FOREACH
(
resolve
,
cache_tree
,
&
cache_root
)
{
for
(
pend
=
resolve
->
pending_connections
;
pend
;
pend
=
pend
->
next
)
{
pend
;
pend
=
pend
->
next
)
{
tor_assert
(
pend
->
conn
!=
conn
);
}
}
...
...
@@ -368,8 +368,8 @@ void assert_all_pending_dns_resolves_ok(void) {
SPLAY_FOREACH
(
resolve
,
cache_tree
,
&
cache_root
)
{
for
(
pend
=
resolve
->
pending_connections
;
pend
;
pend
=
pend
->
next
)
{
pend
;
pend
=
pend
->
next
)
{
assert_connection_ok
(
pend
->
conn
,
0
);
tor_assert
(
pend
->
conn
->
s
==
-
1
);
tor_assert
(
!
connection_in_array
(
pend
->
conn
));
...
...
src/or/main.c
View file @
22727b4e
...
...
@@ -252,7 +252,7 @@ static void conn_read(int i) {
* should be a &&.
*/
if
(
!
connection_is_reading
(
conn
)
||
!
connection_has_pending_tls_data
(
conn
))
!
connection_has_pending_tls_data
(
conn
))
return
;
/* this conn should not read */
log_fn
(
LOG_DEBUG
,
"socket %d wants to read."
,
conn
->
s
);
...
...
@@ -263,15 +263,15 @@ static void conn_read(int i) {
if
(
/* XXX does POLLHUP also mean it's definitely broken? */
#ifdef MS_WINDOWS
(
poll_array
[
i
].
revents
&
POLLERR
)
||
(
poll_array
[
i
].
revents
&
POLLERR
)
||
#endif
connection_handle_read
(
conn
)
<
0
)
{
if
(
!
conn
->
marked_for_close
)
{
/* this connection is broken. remove it */
log_fn
(
LOG_WARN
,
"Unhandled error on read for %s connection (fd %d); removing"
,
CONN_TYPE_TO_STRING
(
conn
->
type
),
conn
->
s
);
connection_mark_for_close
(
conn
);
}
connection_handle_read
(
conn
)
<
0
)
{
if
(
!
conn
->
marked_for_close
)
{
/* this connection is broken. remove it */
log_fn
(
LOG_WARN
,
"Unhandled error on read for %s connection (fd %d); removing"
,
CONN_TYPE_TO_STRING
(
conn
->
type
),
conn
->
s
);
connection_mark_for_close
(
conn
);
}
}
assert_connection_ok
(
conn
,
time
(
NULL
));
assert_all_pending_dns_resolves_ok
();
...
...
@@ -411,8 +411,8 @@ static void run_connection_housekeeping(int i, time_t now) {
/* Expire any directory connections that haven't sent anything for 5 min */
if
(
conn
->
type
==
CONN_TYPE_DIR
&&
!
conn
->
marked_for_close
&&
conn
->
timestamp_lastwritten
+
5
*
60
<
now
)
{
!
conn
->
marked_for_close
&&
conn
->
timestamp_lastwritten
+
5
*
60
<
now
)
{
log_fn
(
LOG_INFO
,
"Expiring wedged directory conn (fd %d, purpose %d)"
,
conn
->
s
,
conn
->
purpose
);
connection_mark_for_close
(
conn
);
return
;
...
...
@@ -421,12 +421,12 @@ static void run_connection_housekeeping(int i, time_t now) {
/* If we haven't written to an OR connection for a while, then either nuke
the connection or send a keepalive, depending. */
if
(
connection_speaks_cells
(
conn
)
&&
now
>=
conn
->
timestamp_lastwritten
+
options
->
KeepalivePeriod
)
{
now
>=
conn
->
timestamp_lastwritten
+
options
->
KeepalivePeriod
)
{
routerinfo_t
*
router
=
router_get_by_digest
(
conn
->
identity_digest
);
if
((
!
connection_state_is_open
(
conn
))
||
(
we_are_hibernating
()
&&
!
circuit_get_by_conn
(
conn
))
||
(
!
clique_mode
(
options
)
&&
!
circuit_get_by_conn
(
conn
)
&&
(
!
router
||
!
server_mode
(
options
)
||
!
router_is_clique_mode
(
router
))))
{
(
we_are_hibernating
()
&&
!
circuit_get_by_conn
(
conn
))
||
(
!
clique_mode
(
options
)
&&
!
circuit_get_by_conn
(
conn
)
&&
(
!
router
||
!
server_mode
(
options
)
||
!
router_is_clique_mode
(
router
))))
{
/* our handshake has expired; we're hibernating;
* or we have no circuits and we're both either OPs or normal ORs,
* then kill it. */
...
...
@@ -727,7 +727,7 @@ static int prepare_for_poll(void) {
for
(
i
=
0
;
i
<
nfds
;
i
++
)
{
conn
=
connection_array
[
i
];
if
(
connection_has_pending_tls_data
(
conn
)
&&
connection_is_reading
(
conn
))
{
connection_is_reading
(
conn
))
{