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
Mike Perry
Tor
Commits
d113b75d
Commit
d113b75d
authored
Feb 13, 2006
by
Roger Dingledine
Browse files
more log conversions.
whee. svn:r6003
parent
36484f87
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
src/or/config.c
View file @
d113b75d
This diff is collapsed.
Click to expand it.
src/or/connection.c
View file @
d113b75d
This diff is collapsed.
Click to expand it.
src/or/connection_edge.c
View file @
d113b75d
This diff is collapsed.
Click to expand it.
src/or/connection_or.c
View file @
d113b75d
...
...
@@ -137,7 +137,7 @@ cell_unpack(cell_t *dest, const char *src)
int
connection_or_reached_eof
(
connection_t
*
conn
)
{
info
(
LD_OR
,
"OR connection reached EOF. Closing."
);
log_
info
(
LD_OR
,
"OR connection reached EOF. Closing."
);
connection_mark_for_close
(
conn
);
return
0
;
}
...
...
@@ -160,28 +160,29 @@ connection_or_read_proxy_response(connection_t *conn)
&
headers
,
MAX_HEADERS_SIZE
,
NULL
,
NULL
,
10000
,
0
))
{
case
-
1
:
/* overflow */
warn
(
LD_PROTOCOL
,
"Your https proxy sent back an oversized response. "
"
Closing."
);
log_
warn
(
LD_PROTOCOL
,
"Your https proxy sent back an oversized response.
Closing."
);
return
-
1
;
case
0
:
info
(
LD_OR
,
"https proxy response not all here yet. Waiting."
);
log_
info
(
LD_OR
,
"https proxy response not all here yet. Waiting."
);
return
0
;
/* case 1, fall through */
}
if
(
parse_http_response
(
headers
,
&
status_code
,
&
date_header
,
&
compression
,
&
reason
)
<
0
)
{
warn
(
LD_OR
,
"Unparseable headers from proxy (connecting to '%s'). Closing."
,
conn
->
address
);
log_warn
(
LD_OR
,
"Unparseable headers from proxy (connecting to '%s'). Closing."
,
conn
->
address
);
tor_free
(
headers
);
return
-
1
;
}
if
(
!
reason
)
reason
=
tor_strdup
(
"[no reason given]"
);
if
(
status_code
==
200
)
{
info
(
LD_OR
,
"HTTPS connect to '%s' successful! (200
\"
%s
\"
) Starting TLS."
,
conn
->
address
,
reason
);
log_
info
(
LD_OR
,
"HTTPS connect to '%s' successful! (200
\"
%s
\"
) Starting TLS."
,
conn
->
address
,
reason
);
tor_free
(
reason
);
if
(
connection_tls_start_handshake
(
conn
,
0
)
<
0
)
{
/* TLS handshaking error of some kind. */
...
...
@@ -192,10 +193,10 @@ connection_or_read_proxy_response(connection_t *conn)
return
0
;
}
/* else, bad news on the status code */
warn
(
LD_OR
,
"The https proxy sent back an unexpected status code %d (
\"
%s
\"
). "
"Closing."
,
status_code
,
reason
);
log_
warn
(
LD_OR
,
"The https proxy sent back an unexpected status code %d (
\"
%s
\"
). "
"Closing."
,
status_code
,
reason
);
tor_free
(
reason
);
connection_mark_for_close
(
conn
);
return
-
1
;
...
...
@@ -240,7 +241,7 @@ connection_or_finished_flushing(connection_t *conn)
switch
(
conn
->
state
)
{
case
OR_CONN_STATE_PROXY_FLUSHING
:
debug
(
LD_OR
,
"finished sending CONNECT to proxy."
);
log_
debug
(
LD_OR
,
"finished sending CONNECT to proxy."
);
conn
->
state
=
OR_CONN_STATE_PROXY_READING
;
connection_stop_writing
(
conn
);
break
;
...
...
@@ -248,7 +249,7 @@ connection_or_finished_flushing(connection_t *conn)
connection_stop_writing
(
conn
);
break
;
default:
err
(
LD_BUG
,
"BUG: called in unexpected state %d."
,
conn
->
state
);
log_
err
(
LD_BUG
,
"BUG: called in unexpected state %d."
,
conn
->
state
);
tor_fragile_assert
();
return
-
1
;
}
...
...
@@ -264,8 +265,8 @@ connection_or_finished_connecting(connection_t *conn)
tor_assert
(
conn
->
type
==
CONN_TYPE_OR
);
tor_assert
(
conn
->
state
==
OR_CONN_STATE_CONNECTING
);
debug
(
LD_OR
,
"OR connect() to router at %s:%u finished."
,
conn
->
address
,
conn
->
port
);
log_
debug
(
LD_OR
,
"OR connect() to router at %s:%u finished."
,
conn
->
address
,
conn
->
port
);
if
(
get_options
()
->
HttpsProxy
)
{
char
buf
[
1024
];
...
...
@@ -280,7 +281,7 @@ connection_or_finished_connecting(connection_t *conn)
if
(
authenticator
)
{
base64_authenticator
=
alloc_http_authenticator
(
authenticator
);
if
(
!
base64_authenticator
)
warn
(
LD_OR
,
"Encoding https authenticator failed"
);
log_
warn
(
LD_OR
,
"Encoding https authenticator failed"
);
}
if
(
base64_authenticator
)
{
tor_snprintf
(
buf
,
sizeof
(
buf
),
"CONNECT %s:%d HTTP/1.1
\r\n
"
...
...
@@ -428,7 +429,7 @@ connection_or_connect(uint32_t addr, uint16_t port, const char *id_digest)
if
(
server_mode
(
options
)
&&
(
me
=
router_get_my_routerinfo
())
&&
router_digest_is_me
(
id_digest
))
{
info
(
LD_PROTOCOL
,
"Client asked me to connect to myself. Refusing."
);
log_
info
(
LD_PROTOCOL
,
"Client asked me to connect to myself. Refusing."
);
return
NULL
;
}
...
...
@@ -486,11 +487,11 @@ connection_tls_start_handshake(connection_t *conn, int receiving)
conn
->
state
=
OR_CONN_STATE_HANDSHAKING
;
conn
->
tls
=
tor_tls_new
(
conn
->
s
,
receiving
,
0
);
if
(
!
conn
->
tls
)
{
warn
(
LD_BUG
,
"tor_tls_new failed. Closing."
);
log_
warn
(
LD_BUG
,
"tor_tls_new failed. Closing."
);
return
-
1
;
}
connection_start_reading
(
conn
);
debug
(
LD_OR
,
"starting TLS handshake on fd %d"
,
conn
->
s
);
log_
debug
(
LD_OR
,
"starting TLS handshake on fd %d"
,
conn
->
s
);
if
(
connection_tls_continue_handshake
(
conn
)
<
0
)
{
return
-
1
;
}
...
...
@@ -509,16 +510,16 @@ connection_tls_continue_handshake(connection_t *conn)
switch
(
tor_tls_handshake
(
conn
->
tls
))
{
case
TOR_TLS_ERROR
:
case
TOR_TLS_CLOSE
:
info
(
LD_OR
,
"tls error. breaking connection."
);
log_
info
(
LD_OR
,
"tls error. breaking connection."
);
return
-
1
;
case
TOR_TLS_DONE
:
return
connection_tls_finish_handshake
(
conn
);
case
TOR_TLS_WANTWRITE
:
connection_start_writing
(
conn
);
debug
(
LD_OR
,
"wanted write"
);
log_
debug
(
LD_OR
,
"wanted write"
);
return
0
;
case
TOR_TLS_WANTREAD
:
/* handshaking conns are *always* reading */
debug
(
LD_OR
,
"wanted read"
);
log_
debug
(
LD_OR
,
"wanted read"
);
return
0
;
}
return
0
;
...
...
@@ -570,7 +571,7 @@ connection_or_check_valid_handshake(connection_t *conn, char *digest_rcvd)
check_no_tls_errors
();
if
(
!
tor_tls_peer_has_cert
(
conn
->
tls
))
{
info
(
LD_PROTOCOL
,
"Peer didn't send a cert! Closing."
);
log_
info
(
LD_PROTOCOL
,
"Peer didn't send a cert! Closing."
);
return
-
1
;
}
check_no_tls_errors
();
...
...
@@ -581,8 +582,8 @@ connection_or_check_valid_handshake(connection_t *conn, char *digest_rcvd)
return
-
1
;
}
check_no_tls_errors
();
debug
(
LD_OR
,
"Other side (%s:%d) claims to be router '%s'"
,
conn
->
address
,
conn
->
port
,
nickname
);
log_
debug
(
LD_OR
,
"Other side (%s:%d) claims to be router '%s'"
,
conn
->
address
,
conn
->
port
,
nickname
);
if
(
tor_tls_verify
(
severity
,
conn
->
tls
,
&
identity_rcvd
)
<
0
)
{
log_fn
(
severity
,
LD_OR
,
"Other side, which claims to be router '%s' (%s:%d),"
...
...
@@ -591,7 +592,7 @@ connection_or_check_valid_handshake(connection_t *conn, char *digest_rcvd)
return
-
1
;
}
check_no_tls_errors
();
debug
(
LD_OR
,
"The router's cert is valid."
);
log_
debug
(
LD_OR
,
"The router's cert is valid."
);
crypto_pk_get_digest
(
identity_rcvd
,
digest_rcvd
);
if
(
crypto_pk_cmp_keys
(
get_identity_key
(),
identity_rcvd
)
<
0
)
{
...
...
@@ -661,7 +662,7 @@ connection_tls_finish_handshake(connection_t *conn)
char
digest_rcvd
[
DIGEST_LEN
];
int
started_here
=
connection_or_nonopen_was_started_here
(
conn
);
debug
(
LD_OR
,
"tls handshake done. verifying."
);
log_
debug
(
LD_OR
,
"tls handshake done. verifying."
);
if
(
connection_or_check_valid_handshake
(
conn
,
digest_rcvd
)
<
0
)
return
-
1
;
...
...
@@ -669,8 +670,9 @@ connection_tls_finish_handshake(connection_t *conn)
#if 0
connection_t *c;
if ((c=connection_or_get_by_identity_digest(digest_rcvd))) {
debug(LD_OR,"Router '%s' is already connected on fd %d. Dropping fd %d.",
c->nickname, c->s, conn->s);
log_debug(LD_OR,
"Router '%s' is already connected on fd %d. Dropping fd %d.",
c->nickname, c->s, conn->s);
return -1;
}
#endif
...
...
@@ -730,9 +732,9 @@ connection_or_write_cell_to_buf(const cell_t *cell, connection_t *conn)
if
(
connection_handle_write
(
conn
)
<
0
)
{
if
(
!
conn
->
marked_for_close
)
{
/* this connection is broken. remove it. */
warn
(
LD_BUG
,
"Bug: unhandled error on write for OR conn (fd %d); removing"
,
conn
->
s
);
log_
warn
(
LD_BUG
,
"Bug: unhandled error on write for OR conn (fd %d); removing"
,
conn
->
s
);
tor_fragile_assert
();
conn
->
has_sent_end
=
1
;
/* don't cry wolf about duplicate close */
/* XXX do we need a close-immediate here, so we don't try to flush? */
...
...
@@ -761,9 +763,10 @@ connection_or_process_cells_from_inbuf(connection_t *conn)
cell_t
cell
;
loop:
debug
(
LD_OR
,
"%d: starting, inbuf_datalen %d (%d pending in tls object)."
,
conn
->
s
,(
int
)
buf_datalen
(
conn
->
inbuf
),
tor_tls_get_pending_bytes
(
conn
->
tls
));
log_debug
(
LD_OR
,
"%d: starting, inbuf_datalen %d (%d pending in tls object)."
,
conn
->
s
,(
int
)
buf_datalen
(
conn
->
inbuf
),
tor_tls_get_pending_bytes
(
conn
->
tls
));
if
(
buf_datalen
(
conn
->
inbuf
)
<
CELL_NETWORK_SIZE
)
/* whole response
available? */
return
0
;
/* not yet */
...
...
@@ -797,7 +800,7 @@ connection_or_send_destroy(uint16_t circ_id, connection_t *conn, int reason)
cell
.
circ_id
=
circ_id
;
cell
.
command
=
CELL_DESTROY
;
cell
.
payload
[
0
]
=
(
uint8_t
)
reason
;
debug
(
LD_OR
,
"Sending destroy (circID %d)."
,
circ_id
);
log_
debug
(
LD_OR
,
"Sending destroy (circID %d)."
,
circ_id
);
connection_or_write_cell_to_buf
(
&
cell
,
conn
);
return
0
;
}
...
...
src/or/control.c
View file @
d113b75d
...
...
@@ -700,7 +700,7 @@ control_setconf_helper(connection_t *conn, uint32_t len, char *body,
*
outp
=
'\0'
;
if
(
config_get_lines
(
config
,
&
lines
)
<
0
)
{
warn
(
LD_CONTROL
,
"Controller gave us config lines we can't parse."
);
log_
warn
(
LD_CONTROL
,
"Controller gave us config lines we can't parse."
);
connection_write_str_to_buf
(
"551 Couldn't parse configuration
\r\n
"
,
conn
);
tor_free
(
config
);
...
...
@@ -709,7 +709,7 @@ control_setconf_helper(connection_t *conn, uint32_t len, char *body,
tor_free
(
config
);
}
else
{
if
(
config_get_lines
(
body
,
&
lines
)
<
0
)
{
warn
(
LD_CONTROL
,
"Controller gave us config lines we can't parse."
);
log_
warn
(
LD_CONTROL
,
"Controller gave us config lines we can't parse."
);
send_control0_error
(
conn
,
ERR_SYNTAX
,
"Couldn't parse configuration"
);
return
0
;
}
...
...
@@ -718,7 +718,8 @@ control_setconf_helper(connection_t *conn, uint32_t len, char *body,
if
((
r
=
options_trial_assign
(
lines
,
use_defaults
,
clear_first
))
<
0
)
{
int
v0_err
;
const
char
*
msg
;
warn
(
LD_CONTROL
,
"Controller gave us config lines that didn't validate."
);
log_warn
(
LD_CONTROL
,
"Controller gave us config lines that didn't validate."
);
switch
(
r
)
{
case
-
1
:
v0_err
=
ERR_UNRECOGNIZED_CONFIG_KEY
;
...
...
@@ -1024,7 +1025,8 @@ handle_control_authenticate(connection_t *conn, uint32_t len, const char *body)
char
expected
[
S2K_SPECIFIER_LEN
+
DIGEST_LEN
];
char
received
[
DIGEST_LEN
];
if
(
decode_hashed_password
(
expected
,
options
->
HashedControlPassword
)
<
0
)
{
warn
(
LD_CONTROL
,
"Couldn't decode HashedControlPassword: invalid base16"
);
log_warn
(
LD_CONTROL
,
"Couldn't decode HashedControlPassword: invalid base16"
);
goto
err
;
}
secret_to_key
(
received
,
DIGEST_LEN
,
password
,
password_len
,
expected
);
...
...
@@ -1052,7 +1054,7 @@ handle_control_authenticate(connection_t *conn, uint32_t len, const char *body)
}
return
0
;
ok:
info
(
LD_CONTROL
,
"Authenticated control connection (%d)"
,
conn
->
s
);
log_
info
(
LD_CONTROL
,
"Authenticated control connection (%d)"
,
conn
->
s
);
send_control_done
(
conn
);
if
(
STATE_IS_V0
(
conn
->
state
))
conn
->
state
=
CONTROL_CONN_STATE_OPEN_V0
;
...
...
@@ -1168,18 +1170,20 @@ handle_control_mapaddress(connection_t *conn, uint32_t len, const char *body)
const
char
*
from
=
smartlist_get
(
elts
,
0
);
const
char
*
to
=
smartlist_get
(
elts
,
1
);
if
(
!
is_plausible_address
(
from
))
{
warn
(
LD_CONTROL
,
"Skipping invalid argument '%s' in MapAddress msg"
,
log_warn
(
LD_CONTROL
,
"Skipping invalid argument '%s' in MapAddress msg"
,
from
);
}
else
if
(
!
is_plausible_address
(
to
))
{
warn
(
LD_CONTROL
,
"Skipping invalid argument '%s' in MapAddress msg"
,
to
);
log_warn
(
LD_CONTROL
,
"Skipping invalid argument '%s' in MapAddress msg"
,
to
);
}
else
if
(
!
strcmp
(
from
,
"."
)
||
!
strcmp
(
from
,
"0.0.0.0"
))
{
const
char
*
address
=
addressmap_register_virtual_address
(
!
strcmp
(
from
,
"."
)
?
RESOLVED_TYPE_HOSTNAME
:
RESOLVED_TYPE_IPV4
,
tor_strdup
(
to
));
if
(
!
address
)
{
warn
(
LD_CONTROL
,
"Unable to allocate address for '%s' in MapAddress msg"
,
safe_str
(
line
));
log_
warn
(
LD_CONTROL
,
"Unable to allocate address for '%s' in MapAddress msg"
,
safe_str
(
line
));
}
else
{
size_t
anslen
=
strlen
(
address
)
+
strlen
(
to
)
+
8
;
char
*
ans
=
tor_malloc
(
anslen
);
...
...
@@ -1201,7 +1205,8 @@ handle_control_mapaddress(connection_t *conn, uint32_t len, const char *body)
}
}
}
else
{
warn
(
LD_CONTROL
,
"Skipping MapAddress line with wrong number of items."
);
log_warn
(
LD_CONTROL
,
"Skipping MapAddress line with wrong number of items."
);
}
SMARTLIST_FOREACH
(
elts
,
char
*
,
cp
,
tor_free
(
cp
));
smartlist_clear
(
elts
);
...
...
@@ -1375,8 +1380,8 @@ handle_getinfo_helper(const char *question, char **answer)
case
AP_CONN_STATE_OPEN
:
state
=
"SUCCEEDED"
;
break
;
default:
warn
(
LD_BUG
,
"Asked for stream in unknown state %d"
,
conns
[
i
]
->
state
);
log_
warn
(
LD_BUG
,
"Asked for stream in unknown state %d"
,
conns
[
i
]
->
state
);
continue
;
}
circ
=
circuit_get_by_edge_conn
(
conns
[
i
]);
...
...
@@ -1645,8 +1650,8 @@ handle_control_extendcircuit(connection_t *conn, uint32_t len,
if
(
circ
->
state
==
CIRCUIT_STATE_OPEN
)
{
circuit_set_state
(
circ
,
CIRCUIT_STATE_BUILDING
);
if
(
circuit_send_next_onion_skin
(
circ
)
<
0
)
{
info
(
LD_CONTROL
,
"send_next_onion_skin failed; circuit marked for closing."
);
log_
info
(
LD_CONTROL
,
"send_next_onion_skin failed; circuit marked for closing."
);
circuit_mark_for_close
(
circ
,
END_CIRC_AT_ORIGIN
);
if
(
v0
)
send_control0_error
(
conn
,
ERR_INTERNAL
,
"couldn't send onion skin"
);
...
...
@@ -1977,8 +1982,8 @@ handle_control_closecircuit(connection_t *conn, uint32_t len,
if
(
!
strcasecmp
(
smartlist_get
(
args
,
i
),
"IfUnused"
))
safe
=
1
;
else
info
(
LD_CONTROL
,
"Skipping unknown option %s"
,
(
char
*
)
smartlist_get
(
args
,
i
));
log_
info
(
LD_CONTROL
,
"Skipping unknown option %s"
,
(
char
*
)
smartlist_get
(
args
,
i
));
}
}
SMARTLIST_FOREACH
(
args
,
char
*
,
cp
,
tor_free
(
cp
));
...
...
@@ -2006,7 +2011,7 @@ handle_control_fragments(connection_t *conn, uint16_t command_type,
{
if
(
command_type
==
CONTROL0_CMD_FRAGMENTHEADER
)
{
if
(
conn
->
incoming_cmd
)
{
warn
(
LD_CONTROL
,
"Dropping incomplete fragmented command"
);
log_
warn
(
LD_CONTROL
,
"Dropping incomplete fragmented command"
);
tor_free
(
conn
->
incoming_cmd
);
}
if
(
body_len
<
6
)
{
...
...
@@ -2058,7 +2063,7 @@ connection_control_reached_eof(connection_t *conn)
tor_assert
(
conn
);
tor_assert
(
conn
->
type
==
CONN_TYPE_CONTROL
);
info
(
LD_CONTROL
,
"Control connection reached EOF. Closing."
);
log_
info
(
LD_CONTROL
,
"Control connection reached EOF. Closing."
);
connection_mark_for_close
(
conn
);
return
0
;
}
...
...
@@ -2223,13 +2228,14 @@ connection_control_process_inbuf_v0(connection_t *conn)
{
case
-
2
:
tor_free
(
body
);
info
(
LD_CONTROL
,
"Detected v1 control protocol on connection (fd %d)"
,
conn
->
s
);
log_info
(
LD_CONTROL
,
"Detected v1 control protocol on connection (fd %d)"
,
conn
->
s
);
conn
->
state
=
CONTROL_CONN_STATE_NEEDAUTH_V1
;
return
connection_control_process_inbuf_v1
(
conn
);
case
-
1
:
tor_free
(
body
);
warn
(
LD_CONTROL
,
"Error in control command. Failing."
);
log_
warn
(
LD_CONTROL
,
"Error in control command. Failing."
);
return
-
1
;
case
0
:
/* Control command not all here yet. Wait. */
...
...
@@ -2245,8 +2251,8 @@ connection_control_process_inbuf_v0(connection_t *conn)
* commands will be considered. */
if
(
conn
->
state
==
CONTROL_CONN_STATE_NEEDAUTH_V0
&&
command_type
!=
CONTROL0_CMD_AUTHENTICATE
)
{
info
(
LD_CONTROL
,
"Rejecting '%s' command; authentication needed."
,
control_cmd_to_string
(
command_type
));
log_
info
(
LD_CONTROL
,
"Rejecting '%s' command; authentication needed."
,
control_cmd_to_string
(
command_type
));
send_control0_error
(
conn
,
ERR_UNAUTHORIZED
,
"Authentication required"
);
tor_free
(
body
);
goto
again
;
...
...
@@ -2265,7 +2271,7 @@ connection_control_process_inbuf_v0(connection_t *conn)
body
=
conn
->
incoming_cmd
;
conn
->
incoming_cmd
=
NULL
;
}
else
if
(
conn
->
incoming_cmd
)
{
warn
(
LD_CONTROL
,
"Dropping incomplete fragmented command"
);
log_
warn
(
LD_CONTROL
,
"Dropping incomplete fragmented command"
);
tor_free
(
conn
->
incoming_cmd
);
}
...
...
@@ -2333,18 +2339,19 @@ connection_control_process_inbuf_v0(connection_t *conn)
case
CONTROL0_CMD_CONFVALUE
:
case
CONTROL0_CMD_EVENT
:
case
CONTROL0_CMD_INFOVALUE
:
warn
(
LD_CONTROL
,
"Received client-only '%s' command; ignoring."
,
control_cmd_to_string
(
command_type
));
log_
warn
(
LD_CONTROL
,
"Received client-only '%s' command; ignoring."
,
control_cmd_to_string
(
command_type
));
send_control0_error
(
conn
,
ERR_UNRECOGNIZED_TYPE
,
"Command type only valid from server to tor client"
);
break
;
case
CONTROL0_CMD_FRAGMENTHEADER
:
case
CONTROL0_CMD_FRAGMENT
:
warn
(
LD_CONTROL
,
"Recieved command fragment out of order; ignoring."
);
log_warn
(
LD_CONTROL
,
"Recieved command fragment out of order; ignoring."
);
send_control0_error
(
conn
,
ERR_SYNTAX
,
"Bad fragmentation on command."
);
default:
warn
(
LD_CONTROL
,
"Received unrecognized command type %d; ignoring."
,
(
int
)
command_type
);
log_
warn
(
LD_CONTROL
,
"Received unrecognized command type %d; ignoring."
,
(
int
)
command_type
);
send_control0_error
(
conn
,
ERR_UNRECOGNIZED_TYPE
,
"Unrecognized command type"
);
break
;
...
...
@@ -2399,7 +2406,7 @@ control_event_circuit_status(circuit_t *circ, circuit_status_event_t tp)
case
CIRC_EVENT_FAILED
:
status
=
"FAILED"
;
break
;
case
CIRC_EVENT_CLOSED
:
status
=
"CLOSED"
;
break
;
default:
warn
(
LD_BUG
,
"Unrecognized status code %d"
,
(
int
)
tp
);
log_
warn
(
LD_BUG
,
"Unrecognized status code %d"
,
(
int
)
tp
);
return
0
;
}
send_control1_event
(
EVENT_CIRCUIT_STATUS
,
...
...
@@ -2472,7 +2479,7 @@ control_event_stream_status(connection_t *conn, stream_status_event_t tp)
case
STREAM_EVENT_NEW_RESOLVE
:
status
=
"NEWRESOLVE"
;
break
;
case
STREAM_EVENT_FAILED_RETRIABLE
:
status
=
"DETACHED"
;
break
;
default:
warn
(
LD_BUG
,
"Unrecognized status code %d"
,
(
int
)
tp
);
log_
warn
(
LD_BUG
,
"Unrecognized status code %d"
,
(
int
)
tp
);
return
0
;
}
circ
=
circuit_get_by_edge_conn
(
conn
);
...
...
@@ -2514,7 +2521,7 @@ control_event_or_conn_status(connection_t *conn,or_conn_status_event_t tp)
case
OR_CONN_EVENT_FAILED
:
status
=
"FAILED"
;
break
;
case
OR_CONN_EVENT_CLOSED
:
status
=
"CLOSED"
;
break
;
default:
warn
(
LD_BUG
,
"Unrecognized status code %d"
,
(
int
)
tp
);
log_
warn
(
LD_BUG
,
"Unrecognized status code %d"
,
(
int
)
tp
);
return
0
;
}
send_control1_event
(
EVENT_OR_CONN_STATUS
,
...
...
@@ -2731,7 +2738,7 @@ init_cookie_authentication(int enabled)
authentication_cookie_is_set
=
1
;
if
(
write_bytes_to_file
(
fname
,
authentication_cookie
,
AUTHENTICATION_COOKIE_LEN
,
1
))
{
warn
(
LD_FS
,
"Error writing authentication cookie."
);
log_
warn
(
LD_FS
,
"Error writing authentication cookie."
);
return
-
1
;
}
...
...
src/or/cpuworker.c
View file @
d113b75d
...
...
@@ -85,7 +85,8 @@ tag_unpack(const char *tag, uint32_t *addr, uint16_t *port, uint16_t *circ_id)
in
.
s_addr
=
htonl
(
*
addr
);
tor_inet_ntoa
(
&
in
,
addrbuf
,
sizeof
(
addrbuf
));
debug
(
LD_OR
,
"onion was from %s:%d, circ_id %d."
,
addrbuf
,
*
port
,
*
circ_id
);
log_debug
(
LD_OR
,
"onion was from %s:%d, circ_id %d."
,
addrbuf
,
*
port
,
*
circ_id
);
}
/** Called when the onion key has changed and we need to spawn new
...
...
@@ -111,12 +112,12 @@ cpuworkers_rotate(void)
int
connection_cpu_reached_eof
(
connection_t
*
conn
)
{
warn
(
LD_GENERAL
,
"Read eof. Worker died unexpectedly."
);
log_
warn
(
LD_GENERAL
,
"Read eof. Worker died unexpectedly."
);
if
(
conn
->
state
!=
CPUWORKER_STATE_IDLE
)
{
/* 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. */
warn
(
LD_GENERAL
,
"...and it left a circuit queued; abandoning circ."
);
log_
warn
(
LD_GENERAL
,
"...and it left a circuit queued; abandoning circ."
);
num_cpuworkers_busy
--
;
}
num_cpuworkers
--
;
...
...
@@ -166,8 +167,9 @@ connection_cpu_process_inbuf(connection_t *conn)
circ
=
circuit_get_by_circid_orconn
(
circ_id
,
p_conn
);
if
(
success
==
0
)
{
debug
(
LD_OR
,
"decoding onionskin failed. (Old key or bad software.) Closing."
);
log_debug
(
LD_OR
,
"decoding onionskin failed. "
"(Old key or bad software.) Closing."
);
if
(
circ
)
circuit_mark_for_close
(
circ
,
END_CIRC_REASON_TORPROTOCOL
);
goto
done_processing
;
...
...
@@ -178,17 +180,17 @@ connection_cpu_process_inbuf(connection_t *conn)
* why our tag doesn't include a pointer to the circ, because we'd
* never know if it's still valid.
*/
debug
(
LD_OR
,
"processed onion for a circ that's gone. Dropping."
);
log_
debug
(
LD_OR
,
"processed onion for a circ that's gone. Dropping."
);
goto
done_processing
;
}
tor_assert
(
circ
->
p_conn
);
if
(
onionskin_answer
(
circ
,
CELL_CREATED
,
buf
+
TAG_LEN
,
buf
+
TAG_LEN
+
ONIONSKIN_REPLY_LEN
)
<
0
)
{
warn
(
LD_OR
,
"onionskin_answer failed. Closing."
);
log_
warn
(
LD_OR
,
"onionskin_answer failed. Closing."
);
circuit_mark_for_close
(
circ
,
END_CIRC_REASON_INTERNAL
);
goto
done_processing
;
}
debug
(
LD_OR
,
"onionskin_answer succeeded. Yay."
);
log_
debug
(
LD_OR
,
"onionskin_answer succeeded. Yay."
);
}
else
{
tor_assert
(
0
);
/* don't ask me to do handshakes yet */
}
...
...
@@ -254,26 +256,28 @@ cpuworker_main(void *data)
if
((
r
=
recv
(
fd
,
&
question_type
,
1
,
0
))
!=
1
)
{
// log_fn(LOG_ERR,"read type failed. Exiting.");
if
(
r
==
0
)
{
info
(
LD_OR
,
"CPU worker exiting because Tor process closed connection "
"(either rotated keys or died)."
);
log_info
(
LD_OR
,
"CPU worker exiting because Tor process closed connection "
"(either rotated keys or died)."
);
}
else
{
info
(
LD_OR
,
"CPU worker editing because of error on connection to Tor "
"process."
);
info
(
LD_OR
,
"(Error on %d was %s)"
,
fd
,
tor_socket_strerror
(
tor_socket_errno
(
fd
)));
log_info
(
LD_OR
,
"CPU worker editing because of error on connection to Tor "
"process."
);
log_info
(
LD_OR
,
"(Error on %d was %s)"
,
fd
,
tor_socket_strerror
(
tor_socket_errno
(
fd
)));
}
goto
end
;
}
tor_assert
(
question_type
==
CPUWORKER_TASK_ONION
);
if
(
read_all
(
fd
,
tag
,
TAG_LEN
,
1
)
!=
TAG_LEN
)
{
err
(
LD_BUG
,
"read tag failed. Exiting."
);
log_
err
(
LD_BUG
,
"read tag failed. Exiting."
);
goto
end
;
}
if
(
read_all
(
fd
,
question
,
ONIONSKIN_CHALLENGE_LEN
,
1
)
!=
ONIONSKIN_CHALLENGE_LEN
)
{
err
(
LD_BUG
,
"read question failed. Exiting."
);
log_
err
(
LD_BUG
,
"read question failed. Exiting."
);
goto
end
;
}
...
...
@@ -281,21 +285,21 @@ cpuworker_main(void *data)
if
(
onion_skin_server_handshake
(
question
,
onion_key
,
last_onion_key
,
reply_to_proxy
,
keys
,
CPATH_KEY_MATERIAL_LEN
)
<
0
)
{
/* failure */
debug
(
LD_OR
,
"onion_skin_server_handshake failed."
);
log_
debug
(
LD_OR
,
"onion_skin_server_handshake failed."
);
memset
(
buf
,
0
,
LEN_ONION_RESPONSE
);
/* send all zeros for failure */
}
else
{
/* success */
debug
(
LD_OR
,
"onion_skin_server_handshake succeeded."
);
log_
debug
(
LD_OR
,
"onion_skin_server_handshake succeeded."
);
buf
[
0
]
=
1
;
/* 1 means success */
memcpy
(
buf
+
1
,
tag
,
TAG_LEN
);
memcpy
(
buf
+
1
+
TAG_LEN
,
reply_to_proxy
,
ONIONSKIN_REPLY_LEN
);
memcpy
(
buf
+
1
+
TAG_LEN
+
ONIONSKIN_REPLY_LEN
,
keys
,
CPATH_KEY_MATERIAL_LEN
);
}
if
(
write_all
(
fd
,
buf
,
LEN_ONION_RESPONSE
,
1
)
!=
LEN_ONION_RESPONSE
)
{
err
(
LD_BUG
,
"writing response buf failed. Exiting."
);
log_
err
(
LD_BUG
,
"writing response buf failed. Exiting."
);
goto
end
;
}
debug
(
LD_OR
,
"finished writing response."
);
log_
debug
(
LD_OR
,
"finished writing response."
);
}
}
end:
...
...
@@ -321,15 +325,15 @@ spawn_cpuworker(void)
fdarray
=
tor_malloc
(
sizeof
(
int
)
*
2
);
if
((
err
=
tor_socketpair
(
AF_UNIX
,
SOCK_STREAM
,
0
,
fdarray
))
<
0
)
{
warn
(
LD_NET
,
"Couldn't construct socketpair: %s"
,
tor_socket_strerror
(
-
err
));
log_
warn
(
LD_NET
,
"Couldn't construct socketpair: %s"
,
tor_socket_strerror
(
-
err
));
tor_free
(
fdarray
);
return
-
1
;
}
fd
=
fdarray
[
0
];
spawn_func
(
cpuworker_main
,
(
void
*
)
fdarray
);
debug
(
LD_OR
,
"just spawned a cpu worker."
);
log_
debug
(
LD_OR
,
"just spawned a cpu worker."
);
#ifndef TOR_IS_MULTITHREADED
tor_close_socket
(
fdarray
[
1
]);
/* don't need the worker's side of the pipe */
tor_free
(
fdarray
);
...
...
@@ -344,7 +348,7 @@ spawn_cpuworker(void)
conn
->
address
=
tor_strdup
(
"localhost"
);
if
(
connection_add
(
conn
)
<
0
)
{
/* no space, forget it */
warn
(
LD_NET
,
"connection_add failed. Giving up."
);
log_
warn
(
LD_NET
,
"connection_add failed. Giving up."
);
connection_free
(
conn
);
/* this closes fd */
return
-
1
;
}
...
...
@@ -370,7 +374,7 @@ spawn_enough_cpuworkers(void)
while
(
num_cpuworkers
<
num_cpuworkers_needed
)
{
if
(
spawn_cpuworker
()
<
0
)
{
warn
(
LD_GENERAL
,
"Spawn failed. Will try again later."
);
log_
warn
(
LD_GENERAL
,
"Spawn failed. Will try again later."
);
return
;
}
num_cpuworkers
++
;
...
...
@@ -391,7 +395,7 @@ process_pending_task(connection_t *cpuworker)
if
(
!
circ
)
return
;
if
(
assign_to_cpuworker
(
cpuworker
,
CPUWORKER_TASK_ONION
,
circ
)
<
0
)
warn
(
LD_OR
,
"assign_to_cpuworker failed. Ignoring."
);
log_
warn
(
LD_OR
,
"assign_to_cpuworker failed. Ignoring."
);
}
#define CPUWORKER_BUSY_TIMEOUT 3600
/* seconds */
...
...
@@ -415,8 +419,8 @@ cull_wedged_cpuworkers(void)
conn
->
type
==
CONN_TYPE_CPUWORKER
&&
conn
->
state
==
CPUWORKER_STATE_BUSY_ONION
&&
conn
->
timestamp_lastwritten
+
CPUWORKER_BUSY_TIMEOUT
<
now
)
{
notice
(
LD_BUG
,
"Bug: closing wedged cpuworker. Can somebody find the bug?"
);
log_
notice
(
LD_BUG
,
"Bug: closing wedged cpuworker. Can somebody find the bug?"
);
num_cpuworkers_busy
--
;
num_cpuworkers
--
;
connection_mark_for_close
(
conn
);
...
...
@@ -447,7 +451,7 @@ assign_to_cpuworker(connection_t *cpuworker, uint8_t question_type,
tor_assert
(
circ
->
onionskin
);
if
(
num_cpuworkers_busy
==
num_cpuworkers
)
{
debug
(
LD_OR
,
"No idle cpuworkers. Queuing."
);