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
f5829aa7
Commit
f5829aa7
authored
Nov 12, 2003
by
Roger Dingledine
Browse files
lay groundwork for EntryNodes and ExitNodes
svn:r805
parent
9358381d
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/or/circuit.c
View file @
f5829aa7
...
...
@@ -766,7 +766,7 @@ int circuit_send_next_onion_skin(circuit_t *circ) {
* circuit that one is ready. */
connection_ap_attach_pending
();
return
0
;
}
else
if
(
r
<
0
||
!
router
)
{
}
else
if
(
r
<
0
)
{
log_fn
(
LOG_WARN
,
"Unable to extend circuit path."
);
return
-
1
;
}
...
...
src/or/config.c
View file @
f5829aa7
...
...
@@ -161,6 +161,8 @@ static void config_assign(or_options_t *options, struct config_line *list) {
config_compare
(
list
,
"DirBindAddress"
,
CONFIG_TYPE_STRING
,
&
options
->
DirBindAddress
)
||
config_compare
(
list
,
"DirFetchPostPeriod"
,
CONFIG_TYPE_INT
,
&
options
->
DirFetchPostPeriod
)
||
config_compare
(
list
,
"ExitNodes"
,
CONFIG_TYPE_STRING
,
&
options
->
ExitNodes
)
||
config_compare
(
list
,
"EntryNodes"
,
CONFIG_TYPE_STRING
,
&
options
->
EntryNodes
)
||
config_compare
(
list
,
"ExitPolicy"
,
CONFIG_TYPE_STRING
,
&
options
->
ExitPolicy
)
||
config_compare
(
list
,
"Group"
,
CONFIG_TYPE_STRING
,
&
options
->
Group
)
||
...
...
@@ -210,17 +212,18 @@ static void config_assign(or_options_t *options, struct config_line *list) {
void
print_usage
(
void
)
{
printf
(
"tor -f <torrc> [args]
\n
"
"-d <file>
\t\t
Debug file
\n
"
"-e <policy>
\t\t
Exit policy
\n
"
"-l <level>
\t\t
Log level
\n
"
"-m <max>
\t\t
Max number of connections
\n
"
"-l <level>
\t\t
Log level
\n
"
"-t <bandwidth>
\t\t
Total bandwidth
\n
"
"-r <file>
\t\t
List of known routers
\n
"
);
printf
(
"
\n
Client options:
\n
"
"-e
\"
nick1 nick2 ...
\"\t\t
Exit nodes
\n
"
"-s <IP>
\t\t\t
Port to bind to for Socks
\n
"
);
/* split things up to be ANSI compliant */
printf
(
"-n <nick>
\t\t
Nickname of router
\n
"
printf
(
"
\n
Server options:
\n
"
"-n <nick>
\t\t
Nickname of router
\n
"
"-o <port>
\t\t
OR port to bind to
\n
"
"-p <file>
\t\t
PID file
\n
"
"-r <file>
\t\t
Router config file
\n
"
"-t <bandwidth>
\t\t
Total bandwidth
\n
"
);
}
...
...
@@ -233,6 +236,8 @@ void free_options(or_options_t *options) {
tor_free
(
options
->
Nickname
);
tor_free
(
options
->
Address
);
tor_free
(
options
->
PidFile
);
tor_free
(
options
->
ExitNodes
);
tor_free
(
options
->
EntryNodes
);
tor_free
(
options
->
ExitPolicy
);
tor_free
(
options
->
SocksBindAddress
);
tor_free
(
options
->
ORBindAddress
);
...
...
@@ -245,6 +250,8 @@ 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
=
tor_strdup
(
"info"
);
options
->
ExitNodes
=
tor_strdup
(
""
);
options
->
EntryNodes
=
tor_strdup
(
""
);
options
->
ExitPolicy
=
tor_strdup
(
"reject 127.0.0.1:*"
);
options
->
SocksBindAddress
=
tor_strdup
(
"127.0.0.1"
);
options
->
ORBindAddress
=
tor_strdup
(
"0.0.0.0"
);
...
...
src/or/onion.c
View file @
f5829aa7
...
...
@@ -157,6 +157,36 @@ int onionskin_answer(circuit_t *circ, unsigned char *payload, unsigned char *key
return
0
;
}
char
**
parse_nickname_list
(
char
*
list
,
int
*
num
)
{
char
**
out
;
char
*
start
,
*
end
;
int
i
;
while
(
isspace
(
*
list
))
list
++
;
i
=
0
,
start
=
list
;
while
(
*
start
)
{
while
(
*
start
&&
!
isspace
(
*
start
))
start
++
;
i
++
;
while
(
isspace
(
*
start
))
start
++
;
}
out
=
tor_malloc
(
i
*
sizeof
(
char
*
));
i
=
0
,
start
=
list
;
while
(
*
start
)
{
end
=
start
;
while
(
*
end
&&
!
isspace
(
*
end
))
end
++
;
out
[
i
]
=
tor_malloc
(
MAX_NICKNAME_LEN
);
strncpy
(
out
[
i
],
start
,
end
-
start
);
out
[
i
][
end
-
start
]
=
0
;
/* null terminate it */
i
++
;
while
(
isspace
(
*
end
))
end
++
;
start
=
end
;
}
*
num
=
i
;
return
out
;
}
/* uses a weighted coin with weight cw to choose a route length */
static
int
chooselen
(
double
cw
)
{
int
len
=
2
;
...
...
@@ -254,10 +284,11 @@ int onion_extend_cpath(crypt_path_t **head_ptr, int path_len, routerinfo_t **rou
int
rarray_len
;
int
i
;
directory_t
*
dir
;
char
**
nicknames
;
int
num_nicknames
;
assert
(
head_ptr
);
if
(
router_out
)
*
router_out
=
NULL
;
assert
(
router_out
);
router_get_directory
(
&
dir
);
rarray
=
dir
->
routers
;
...
...
@@ -275,6 +306,10 @@ int onion_extend_cpath(crypt_path_t **head_ptr, int path_len, routerinfo_t **rou
log_fn
(
LOG_DEBUG
,
"Path is %d long; we want %d"
,
cur_len
,
path_len
);
again:
if
(
cur_len
==
0
)
{
/* picking entry node */
}
choice
=
crypto_pseudo_rand_int
(
rarray_len
);
log_fn
(
LOG_DEBUG
,
"Contemplating router %s for hop %d"
,
rarray
[
choice
]
->
nickname
,
cur_len
);
...
...
@@ -318,8 +353,7 @@ int onion_extend_cpath(crypt_path_t **head_ptr, int path_len, routerinfo_t **rou
log_fn
(
LOG_DEBUG
,
"Extended circuit path with %s for hop %d"
,
rarray
[
choice
]
->
nickname
,
cur_len
);
if
(
router_out
)
*
router_out
=
rarray
[
choice
];
*
router_out
=
rarray
[
choice
];
return
0
;
}
...
...
src/or/or.h
View file @
f5829aa7
...
...
@@ -432,6 +432,8 @@ typedef struct {
char
*
Nickname
;
char
*
Address
;
char
*
PidFile
;
char
*
ExitNodes
;
char
*
EntryNodes
;
char
*
ExitPolicy
;
char
*
SocksBindAddress
;
char
*
ORBindAddress
;
...
...
@@ -693,6 +695,8 @@ void onion_pending_remove(circuit_t *circ);
int
onionskin_answer
(
circuit_t
*
circ
,
unsigned
char
*
payload
,
unsigned
char
*
keys
);
char
**
parse_nickname_list
(
char
*
start
,
int
*
num
);
int
onion_extend_cpath
(
crypt_path_t
**
head_ptr
,
int
path_len
,
routerinfo_t
**
router_out
);
int
onion_skin_create
(
crypto_pk_env_t
*
router_key
,
...
...
src/or/routers.c
View file @
f5829aa7
...
...
@@ -29,9 +29,6 @@ typedef struct directory_token directory_token_t;
/* static function prototypes */
void
routerlist_free
(
routerinfo_t
*
list
);
static
char
*
eat_whitespace
(
char
*
s
);
static
char
*
eat_whitespace_no_nl
(
char
*
s
);
static
char
*
find_whitespace
(
char
*
s
);
static
int
router_add_exit_policy_from_string
(
routerinfo_t
*
router
,
char
*
s
);
static
int
router_add_exit_policy
(
routerinfo_t
*
router
,
directory_token_t
*
tok
);
...
...
@@ -428,40 +425,6 @@ router_get_next_token(char **s, directory_token_t *tok) {
#define router_get_next_token _router_get_next_token
#endif
/* return the first char of s that is not whitespace and not a comment */
static
char
*
eat_whitespace
(
char
*
s
)
{
assert
(
s
);
while
(
isspace
(
*
s
)
||
*
s
==
'#'
)
{
while
(
isspace
(
*
s
))
s
++
;
if
(
*
s
==
'#'
)
{
/* read to a \n or \0 */
while
(
*
s
&&
*
s
!=
'\n'
)
s
++
;
if
(
!*
s
)
return
s
;
}
}
return
s
;
}
static
char
*
eat_whitespace_no_nl
(
char
*
s
)
{
while
(
*
s
==
' '
||
*
s
==
'\t'
)
++
s
;
return
s
;
}
/* return the first char of s that is whitespace or '#' or '\0 */
static
char
*
find_whitespace
(
char
*
s
)
{
assert
(
s
);
while
(
*
s
&&
!
isspace
(
*
s
)
&&
*
s
!=
'#'
)
s
++
;
return
s
;
}
int
router_get_list_from_string
(
char
*
s
)
{
if
(
router_get_list_from_string_impl
(
&
s
,
&
directory
,
-
1
,
NULL
))
{
...
...
src/or/test.c
View file @
f5829aa7
...
...
@@ -464,6 +464,21 @@ test_util() {
test_eq
((
time_t
)
1076393695UL
,
tor_timegm
(
&
a_time
));
}
void
test_onion
()
{
char
**
names
;
int
i
,
num
;
names
=
parse_nickname_list
(
" foo bar baz quux "
,
&
num
);
test_eq
(
num
,
4
);
test_streq
(
names
[
0
],
"foo"
);
test_streq
(
names
[
1
],
"bar"
);
test_streq
(
names
[
2
],
"baz"
);
test_streq
(
names
[
3
],
"quux"
);
for
(
i
=
0
;
i
<
num
;
i
++
)
tor_free
(
names
[
i
]);
tor_free
(
names
);
}
void
test_onion_handshake
()
{
/* client-side */
...
...
@@ -693,6 +708,7 @@ main(int c, char**v){
puts
(
"
\n
========================= Util ============================"
);
test_util
();
puts
(
"
\n
========================= Onion Skins ====================="
);
test_onion
();
test_onion_handshake
();
puts
(
"
\n
========================= Directory Formats ==============="
);
test_dir_format
();
...
...
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