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
ZerXes
Tor
Commits
e4127e4d
Commit
e4127e4d
authored
Oct 21, 2003
by
Roger Dingledine
Browse files
move closer to being able to reload config on HUP
rename APPort to SocksPort introduce new tor_free() macro svn:r642
parent
80d428b2
Changes
10
Show whitespace changes
Inline
Side-by-side
src/or/circuit.c
View file @
e4127e4d
...
...
@@ -481,7 +481,7 @@ void circuit_close(circuit_t *circ) {
circuit_t
*
youngest
=
NULL
;
assert
(
circ
);
if
(
options
.
AP
Port
)
{
if
(
options
.
Socks
Port
)
{
youngest
=
circuit_get_newest_open
();
log_fn
(
LOG_DEBUG
,
"youngest %d, circ %d."
,(
int
)
youngest
,
(
int
)
circ
);
}
...
...
@@ -496,7 +496,7 @@ void circuit_close(circuit_t *circ) {
for
(
conn
=
circ
->
p_streams
;
conn
;
conn
=
conn
->
next_stream
)
{
connection_send_destroy
(
circ
->
p_aci
,
conn
);
}
if
(
options
.
AP
Port
&&
youngest
==
circ
)
{
/* check this after we've sent the destroys, to reduce races */
if
(
options
.
Socks
Port
&&
youngest
==
circ
)
{
/* check this after we've sent the destroys, to reduce races */
/* our current circuit just died. Launch another one pronto. */
log_fn
(
LOG_INFO
,
"Youngest circuit dying. Launching a replacement."
);
circuit_launch_new
(
1
);
...
...
@@ -616,7 +616,7 @@ void circuit_expire_unused_circuits(void) {
void
circuit_launch_new
(
int
failure_status
)
{
static
int
failures
=
0
;
if
(
!
options
.
AP
Port
)
/* we're not an application proxy. no need for circuits. */
if
(
!
options
.
Socks
Port
)
/* we're not an application proxy. no need for circuits. */
return
;
if
(
failure_status
==
-
1
)
{
/* I was called because a circuit succeeded */
...
...
src/or/config.c
View file @
e4127e4d
...
...
@@ -131,6 +131,7 @@ static int config_compare(struct config_line *c, char *key, int type, void *arg)
*
(
int
*
)
arg
=
i
;
break
;
case
CONFIG_TYPE_STRING
:
tor_free
(
*
(
char
**
)
arg
);
*
(
char
**
)
arg
=
tor_strdup
(
c
->
value
);
break
;
case
CONFIG_TYPE_DOUBLE
:
...
...
@@ -159,10 +160,12 @@ static void config_assign(or_options_t *options, struct config_line *list) {
config_compare
(
list
,
"Nickname"
,
CONFIG_TYPE_STRING
,
&
options
->
Nickname
)
||
config_compare
(
list
,
"Address"
,
CONFIG_TYPE_STRING
,
&
options
->
Address
)
||
config_compare
(
list
,
"ExitPolicy"
,
CONFIG_TYPE_STRING
,
&
options
->
ExitPolicy
)
||
config_compare
(
list
,
"SocksBindAddress"
,
CONFIG_TYPE_STRING
,
&
options
->
SocksBindAddress
)
||
config_compare
(
list
,
"ORBindAddress"
,
CONFIG_TYPE_STRING
,
&
options
->
ORBindAddress
)
||
/* int options */
config_compare
(
list
,
"MaxConn"
,
CONFIG_TYPE_INT
,
&
options
->
MaxConn
)
||
config_compare
(
list
,
"
AP
Port"
,
CONFIG_TYPE_INT
,
&
options
->
AP
Port
)
||
config_compare
(
list
,
"
Socks
Port"
,
CONFIG_TYPE_INT
,
&
options
->
Socks
Port
)
||
config_compare
(
list
,
"ORPort"
,
CONFIG_TYPE_INT
,
&
options
->
ORPort
)
||
config_compare
(
list
,
"DirPort"
,
CONFIG_TYPE_INT
,
&
options
->
DirPort
)
||
config_compare
(
list
,
"DirFetchPostPeriod"
,
CONFIG_TYPE_INT
,
&
options
->
DirFetchPostPeriod
)
||
...
...
@@ -195,20 +198,27 @@ void print_usage(void) {
}
/* return 0 if success, <0 if failure. */
int
getconfig
(
int
argc
,
char
**
argv
,
or_options_t
*
options
)
{
struct
config_line
*
cl
;
FILE
*
cf
;
char
*
fname
;
int
i
;
int
result
=
0
;
void
free_options
(
or_options_t
*
options
)
{
tor_free
(
options
->
LogLevel
);
tor_free
(
options
->
LogFile
);
tor_free
(
options
->
DebugLogFile
);
tor_free
(
options
->
DataDirectory
);
tor_free
(
options
->
RouterFile
);
tor_free
(
options
->
Nickname
);
tor_free
(
options
->
Address
);
tor_free
(
options
->
PidFile
);
tor_free
(
options
->
ExitPolicy
);
}
void
init_options
(
or_options_t
*
options
)
{
/* give reasonable values for each option. Defaults to zero. */
memset
(
options
,
0
,
sizeof
(
or_options_t
));
options
->
LogLevel
=
"info"
;
options
->
ExitPolicy
=
"reject 127.0.0.1:*,reject 18.244.0.188:25,accept *:*"
;
options
->
LogLevel
=
tor_strdup
(
"info"
);
options
->
ExitPolicy
=
tor_strdup
(
"reject 127.0.0.1:*,reject 18.244.0.188:25,accept *:*"
);
options
->
SocksBindAddress
=
tor_strdup
(
"127.0.0.1"
);
options
->
ORBindAddress
=
tor_strdup
(
"0.0.0.0"
);
options
->
loglevel
=
LOG_INFO
;
options
->
PidFile
=
"tor.pid"
;
options
->
PidFile
=
tor_strdup
(
"tor.pid"
)
;
options
->
DataDirectory
=
NULL
;
options
->
CoinWeight
=
0
.
1
;
options
->
MaxConn
=
900
;
...
...
@@ -218,6 +228,17 @@ int getconfig(int argc, char **argv, or_options_t *options) {
options
->
NewCircuitPeriod
=
60
;
/* once a minute */
options
->
TotalBandwidth
=
800000
;
/* at most 800kB/s total sustained incoming */
options
->
NumCpus
=
1
;
}
/* return 0 if success, <0 if failure. */
int
getconfig
(
int
argc
,
char
**
argv
,
or_options_t
*
options
)
{
struct
config_line
*
cl
;
FILE
*
cf
;
char
*
fname
;
int
i
;
int
result
=
0
;
init_options
(
options
);
if
(
argc
>
1
&&
(
!
strcmp
(
argv
[
1
],
"-h"
)
||
!
strcmp
(
argv
[
1
],
"--help"
)))
{
print_usage
();
...
...
@@ -295,8 +316,8 @@ int getconfig(int argc, char **argv, or_options_t *options) {
result
=
-
1
;
}
if
(
options
->
AP
Port
<
0
)
{
log
(
LOG_WARN
,
"
AP
Port option can't be negative."
);
if
(
options
->
Socks
Port
<
0
)
{
log
(
LOG_WARN
,
"
Socks
Port option can't be negative."
);
result
=
-
1
;
}
...
...
@@ -305,7 +326,7 @@ int getconfig(int argc, char **argv, or_options_t *options) {
result
=
-
1
;
}
if
(
options
->
AP
Port
>
1
&&
if
(
options
->
Socks
Port
>
1
&&
(
options
->
CoinWeight
<
0
.
0
||
options
->
CoinWeight
>=
1
.
0
))
{
log
(
LOG_WARN
,
"CoinWeight option must be >=0.0 and <1.0."
);
result
=
-
1
;
...
...
src/or/connection.c
View file @
e4127e4d
...
...
@@ -100,8 +100,7 @@ void connection_free(connection_t *conn) {
buf_free
(
conn
->
inbuf
);
buf_free
(
conn
->
outbuf
);
}
if
(
conn
->
address
)
free
(
conn
->
address
);
tor_free
(
conn
->
address
);
if
(
connection_speaks_cells
(
conn
))
{
directory_set_dirty
();
...
...
@@ -115,8 +114,7 @@ void connection_free(connection_t *conn) {
crypto_free_pk_env
(
conn
->
link_pkey
);
if
(
conn
->
identity_pkey
)
crypto_free_pk_env
(
conn
->
identity_pkey
);
if
(
conn
->
nickname
)
free
(
conn
->
nickname
);
tor_free
(
conn
->
nickname
);
if
(
conn
->
s
>=
0
)
{
log_fn
(
LOG_INFO
,
"closing fd %d."
,
conn
->
s
);
...
...
src/or/connection_or.c
View file @
e4127e4d
...
...
@@ -85,8 +85,7 @@ void connection_or_init_conn_from_router(connection_t *conn, routerinfo_t *route
conn
->
link_pkey
=
crypto_pk_dup_key
(
router
->
link_pkey
);
conn
->
identity_pkey
=
crypto_pk_dup_key
(
router
->
identity_pkey
);
conn
->
nickname
=
tor_strdup
(
router
->
nickname
);
if
(
conn
->
address
)
free
(
conn
->
address
);
tor_free
(
conn
->
address
);
conn
->
address
=
tor_strdup
(
router
->
address
);
}
...
...
src/or/dirserv.c
View file @
e4127e4d
...
...
@@ -165,10 +165,8 @@ static int n_descriptors = 0;
static
void
free_descriptor_entry
(
descriptor_entry_t
*
desc
)
{
if
(
desc
->
descriptor
)
free
(
desc
->
descriptor
);
if
(
desc
->
nickname
)
free
(
desc
->
nickname
);
tor_free
(
desc
->
descriptor
);
tor_free
(
desc
->
nickname
);
free
(
desc
);
}
...
...
@@ -218,7 +216,7 @@ dirserv_add_descriptor(const char **desc)
log
(
LOG_WARN
,
"Couldn't parse descriptor"
);
goto
err
;
}
free
(
desc_tmp
);
desc_tmp
=
NULL
;
tor_
free
(
desc_tmp
);
/* Okay. Now check whether the fingerprint is recognized. */
if
(
!
dirserv_router_fingerprint_is_known
(
ri
))
{
log
(
LOG_WARN
,
"Identity is unrecognized for descriptor"
);
...
...
@@ -238,7 +236,7 @@ dirserv_add_descriptor(const char **desc)
/* We already have a newer descriptor */
log_fn
(
LOG_INFO
,
"We already have a newer desc for nickname %s. Not adding."
,
ri
->
nickname
);
/* This isn't really an error; return. */
if
(
desc_tmp
)
free
(
desc_tmp
);
tor_
free
(
desc_tmp
);
if
(
ri
)
routerinfo_free
(
ri
);
*
desc
=
end
;
return
0
;
...
...
@@ -263,8 +261,7 @@ dirserv_add_descriptor(const char **desc)
routerinfo_free
(
ri
);
return
0
;
err:
if
(
desc_tmp
)
free
(
desc_tmp
);
tor_free
(
desc_tmp
);
if
(
ri
)
routerinfo_free
(
ri
);
...
...
@@ -417,8 +414,7 @@ size_t dirserv_get_directory(const char **directory)
free
(
new_directory
);
return
0
;
}
if
(
the_directory
)
free
(
the_directory
);
tor_free
(
the_directory
);
the_directory
=
new_directory
;
the_directory_len
=
strlen
(
the_directory
);
log_fn
(
LOG_INFO
,
"New directory (size %d):
\n
%s"
,
the_directory_len
,
...
...
src/or/main.c
View file @
e4127e4d
...
...
@@ -337,7 +337,7 @@ static void run_scheduled_events(time_t now) {
/* 2. Every NewCircuitPeriod seconds, we expire old circuits and make a
* new one as needed.
*/
if
(
options
.
AP
Port
&&
time_to_new_circuit
<
now
)
{
if
(
options
.
Socks
Port
&&
time_to_new_circuit
<
now
)
{
circuit_expire_unused_circuits
();
circuit_launch_new
(
-
1
);
/* tell it to forget about previous failures */
circ
=
circuit_get_newest_open
();
...
...
@@ -595,7 +595,7 @@ static int do_main_loop(void) {
* and start the listeners.
*/
retry_all_connections
((
uint16_t
)
options
.
ORPort
,
(
uint16_t
)
options
.
AP
Port
,
(
uint16_t
)
options
.
Socks
Port
,
(
uint16_t
)
options
.
DirPort
);
for
(;;)
{
...
...
src/or/onion.c
View file @
e4127e4d
...
...
@@ -222,7 +222,7 @@ static unsigned int *new_route(double cw, routerinfo_t **rarray, int rarray_len,
for
(
i
=
0
;
i
<*
routelen
;
i
++
)
{
// log_fn(LOG_DEBUG,"Choosing hop %u.",i);
if
(
CRYPTO_PSEUDO_RAND_INT
(
choice
))
{
free
(
(
void
*
)
route
);
free
(
route
);
return
NULL
;
}
...
...
@@ -432,7 +432,7 @@ onion_skin_create(crypto_pk_env_t *dest_router_key,
return
0
;
err:
if
(
pubkey
)
free
(
pubkey
);
tor_
free
(
pubkey
);
if
(
dh
)
crypto_dh_free
(
dh
);
if
(
cipher
)
crypto_free_cipher_env
(
cipher
);
return
-
1
;
...
...
src/or/or.h
View file @
e4127e4d
...
...
@@ -335,7 +335,7 @@ typedef struct {
uint32_t
addr
;
/* all host order */
uint16_t
or_port
;
uint16_t
ap
_port
;
uint16_t
socks
_port
;
uint16_t
dir_port
;
time_t
published_on
;
...
...
@@ -426,9 +426,11 @@ typedef struct {
char
*
Address
;
char
*
PidFile
;
char
*
ExitPolicy
;
char
*
SocksBindAddress
;
char
*
ORBindAddress
;
double
CoinWeight
;
int
ORPort
;
int
AP
Port
;
int
Socks
Port
;
int
DirPort
;
int
MaxConn
;
int
OnionRouter
;
...
...
src/or/routers.c
View file @
e4127e4d
...
...
@@ -144,10 +144,8 @@ void routerinfo_free(routerinfo_t *router)
if
(
!
router
)
return
;
if
(
router
->
address
)
free
(
router
->
address
);
if
(
router
->
nickname
)
free
(
router
->
nickname
);
tor_free
(
router
->
address
);
tor_free
(
router
->
nickname
);
if
(
router
->
onion_pkey
)
crypto_free_pk_env
(
router
->
onion_pkey
);
if
(
router
->
link_pkey
)
...
...
@@ -157,9 +155,9 @@ void routerinfo_free(routerinfo_t *router)
while
(
router
->
exit_policy
)
{
e
=
router
->
exit_policy
;
router
->
exit_policy
=
e
->
next
;
if
(
e
->
string
)
free
(
e
->
string
);
if
(
e
->
address
)
free
(
e
->
address
);
if
(
e
->
port
)
free
(
e
->
port
);
tor_
free
(
e
->
string
);
tor_
free
(
e
->
address
);
tor_
free
(
e
->
port
);
free
(
e
);
}
free
(
router
);
...
...
@@ -170,10 +168,8 @@ void directory_free(directory_t *dir)
int
i
;
for
(
i
=
0
;
i
<
dir
->
n_routers
;
++
i
)
routerinfo_free
(
dir
->
routers
[
i
]);
if
(
dir
->
routers
)
free
(
dir
->
routers
);
if
(
dir
->
software_versions
)
free
(
dir
->
software_versions
);
tor_free
(
dir
->
routers
);
tor_free
(
dir
->
software_versions
);
free
(
dir
);
}
...
...
@@ -825,8 +821,8 @@ routerinfo_t *router_get_entry_from_string(char**s) {
goto
err
;
}
/* Router->
ap
_port */
router
->
ap
_port
=
atoi
(
ARGS
[
3
]);
/* Router->
socks
_port */
router
->
socks
_port
=
atoi
(
ARGS
[
3
]);
/* Router->dir_port */
router
->
dir_port
=
atoi
(
ARGS
[
4
]);
...
...
@@ -838,8 +834,8 @@ routerinfo_t *router_get_entry_from_string(char**s) {
goto
err
;
}
log_fn
(
LOG_DEBUG
,
"or_port %d,
ap
_port %d, dir_port %d, bandwidth %d."
,
router
->
or_port
,
router
->
ap
_port
,
router
->
dir_port
,
router
->
bandwidth
);
log_fn
(
LOG_DEBUG
,
"or_port %d,
socks
_port %d, dir_port %d, bandwidth %d."
,
router
->
or_port
,
router
->
socks
_port
,
router
->
dir_port
,
router
->
bandwidth
);
/* XXX Later, require platform before published. */
NEXT_TOKEN
();
...
...
@@ -1039,12 +1035,9 @@ static int router_add_exit_policy(routerinfo_t *router,
policy_read_failed:
assert
(
newe
->
string
);
log_fn
(
LOG_WARN
,
"Couldn't parse line '%s'. Dropping"
,
newe
->
string
);
if
(
newe
->
string
)
free
(
newe
->
string
);
if
(
newe
->
address
)
free
(
newe
->
address
);
if
(
newe
->
port
)
free
(
newe
->
port
);
tor_free
(
newe
->
string
);
tor_free
(
newe
->
address
);
tor_free
(
newe
->
port
);
free
(
newe
);
return
-
1
;
}
...
...
@@ -1121,7 +1114,7 @@ int router_rebuild_descriptor(void) {
ri
->
nickname
=
tor_strdup
(
options
.
Nickname
);
/* No need to set addr. */
ri
->
or_port
=
options
.
ORPort
;
ri
->
ap
_port
=
options
.
AP
Port
;
ri
->
socks
_port
=
options
.
Socks
Port
;
ri
->
dir_port
=
options
.
DirPort
;
ri
->
published_on
=
time
(
NULL
);
ri
->
onion_pkey
=
crypto_pk_dup_key
(
get_onion_key
());
...
...
@@ -1202,7 +1195,7 @@ int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
router
->
nickname
,
router
->
address
,
router
->
or_port
,
router
->
ap
_port
,
router
->
socks
_port
,
router
->
dir_port
,
router
->
bandwidth
,
platform
,
...
...
src/or/test.c
View file @
e4127e4d
...
...
@@ -517,7 +517,7 @@ test_dir_format()
r1
.
addr
=
0xc0a80001u
;
/* 192.168.0.1 */
r1
.
published_on
=
0
;
r1
.
or_port
=
9000
;
r1
.
ap
_port
=
9002
;
r1
.
socks
_port
=
9002
;
r1
.
dir_port
=
9003
;
r1
.
onion_pkey
=
pk1
;
r1
.
identity_pkey
=
pk2
;
...
...
@@ -539,7 +539,7 @@ test_dir_format()
r2
.
addr
=
0x0a030201u
;
/* 10.3.2.1 */
r2
.
published_on
=
5
;
r2
.
or_port
=
9005
;
r2
.
ap
_port
=
0
;
r2
.
socks
_port
=
0
;
r2
.
dir_port
=
0
;
r2
.
onion_pkey
=
pk2
;
r2
.
identity_pkey
=
pk1
;
...
...
@@ -580,7 +580,7 @@ test_dir_format()
test_assert
(
rp1
);
test_streq
(
rp1
->
address
,
r1
.
address
);
test_eq
(
rp1
->
or_port
,
r1
.
or_port
);
test_eq
(
rp1
->
ap
_port
,
r1
.
ap
_port
);
test_eq
(
rp1
->
socks
_port
,
r1
.
socks
_port
);
test_eq
(
rp1
->
dir_port
,
r1
.
dir_port
);
test_eq
(
rp1
->
bandwidth
,
r1
.
bandwidth
);
test_assert
(
crypto_pk_cmp_keys
(
rp1
->
onion_pkey
,
pk1
)
==
0
);
...
...
@@ -603,7 +603,7 @@ test_dir_format()
test_assert(rp2);
test_streq(rp2->address, r2.address);
test_eq(rp2->or_port, r2.or_port);
test_eq(rp2->
ap
_port, r2.
ap
_port);
test_eq(rp2->
socks
_port, r2.
socks
_port);
test_eq(rp2->dir_port, r2.dir_port);
test_eq(rp2->bandwidth, r2.bandwidth);
test_assert(crypto_pk_cmp_keys(rp2->onion_pkey, pk2) == 0);
...
...
@@ -636,14 +636,14 @@ test_dir_format()
test_eq(2, dir2->n_routers);
#endif
if
(
pk1_str
)
free
(
pk1_str
);
if
(
pk2_str
)
free
(
pk2_str
);
tor_
free
(
pk1_str
);
tor_
free
(
pk2_str
);
if
(
pk1
)
crypto_free_pk_env
(
pk1
);
if
(
pk2
)
crypto_free_pk_env
(
pk2
);
if
(
rp1
)
routerinfo_free
(
rp1
);
if
(
rp2
)
routerinfo_free
(
rp2
);
if
(
dir1
)
free
(
dir1
);
/* And more !*/
if
(
dir1
)
free
(
dir2
);
/* And more !*/
tor_
free
(
dir1
);
/* And more !*/
tor_
free
(
dir2
);
/* And more !*/
/* make sure compare_recommended_versions() works */
test_eq
(
0
,
compare_recommended_versions
(
"abc"
,
"abc"
));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment