Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Core
Tor
Commits
d7ccb6a3
Commit
d7ccb6a3
authored
11 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Plain Diff
Merge branch 'bug8978_rebase_2'
Conflicts: src/test/test_pt.c
parents
b551988e
e02b6b99
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/or/transports.c
+35
-7
35 additions, 7 deletions
src/or/transports.c
src/or/transports.h
+6
-0
6 additions, 0 deletions
src/or/transports.h
src/test/test_pt.c
+63
-0
63 additions, 0 deletions
src/test/test_pt.c
with
104 additions
and
7 deletions
src/or/transports.c
+
35
−
7
View file @
d7ccb6a3
...
...
@@ -134,7 +134,8 @@ static smartlist_t *transport_list = NULL;
SOCKS version <b>socks_ver</b>. */
static
transport_t
*
transport_new
(
const
tor_addr_t
*
addr
,
uint16_t
port
,
const
char
*
name
,
int
socks_ver
)
const
char
*
name
,
int
socks_ver
,
const
char
*
extra_info_args
)
{
transport_t
*
t
=
tor_malloc_zero
(
sizeof
(
transport_t
));
...
...
@@ -142,6 +143,8 @@ transport_new(const tor_addr_t *addr, uint16_t port,
t
->
port
=
port
;
t
->
name
=
tor_strdup
(
name
);
t
->
socks_version
=
socks_ver
;
if
(
extra_info_args
)
t
->
extra_info_args
=
tor_strdup
(
extra_info_args
);
return
t
;
}
...
...
@@ -154,6 +157,7 @@ transport_free(transport_t *transport)
return
;
tor_free
(
transport
->
name
);
tor_free
(
transport
->
extra_info_args
);
tor_free
(
transport
);
}
...
...
@@ -321,7 +325,7 @@ int
transport_add_from_config
(
const
tor_addr_t
*
addr
,
uint16_t
port
,
const
char
*
name
,
int
socks_ver
)
{
transport_t
*
t
=
transport_new
(
addr
,
port
,
name
,
socks_ver
);
transport_t
*
t
=
transport_new
(
addr
,
port
,
name
,
socks_ver
,
NULL
);
int
r
=
transport_add
(
t
);
...
...
@@ -938,7 +942,7 @@ parse_smethod_line(const char *line, managed_proxy_t *mp)
smartlist_t
*
items
=
NULL
;
char
*
method_name
=
NULL
;
char
*
args_string
=
NULL
;
char
*
addrport
=
NULL
;
tor_addr_t
tor_addr
;
char
*
address
=
NULL
;
...
...
@@ -955,6 +959,9 @@ parse_smethod_line(const char *line, managed_proxy_t *mp)
goto
err
;
}
/* Example of legit SMETHOD line:
SMETHOD obfs2 0.0.0.0:25612 ARGS:secret=supersekrit,key=superkey */
tor_assert
(
!
strcmp
(
smartlist_get
(
items
,
0
),
PROTO_SMETHOD
));
method_name
=
smartlist_get
(
items
,
1
);
...
...
@@ -982,7 +989,19 @@ parse_smethod_line(const char *line, managed_proxy_t *mp)
goto
err
;
}
transport
=
transport_new
(
&
tor_addr
,
port
,
method_name
,
PROXY_NONE
);
if
(
smartlist_len
(
items
)
>
3
)
{
/* Seems like there are also some [options] in the SMETHOD line.
Let's see if we can parse them. */
char
*
options_string
=
smartlist_get
(
items
,
3
);
log_debug
(
LD_CONFIG
,
"Got options_string: %s"
,
options_string
);
if
(
!
strcmpstart
(
options_string
,
"ARGS:"
))
{
args_string
=
options_string
+
strlen
(
"ARGS:"
);
log_debug
(
LD_CONFIG
,
"Got ARGS: %s"
,
args_string
);
}
}
transport
=
transport_new
(
&
tor_addr
,
port
,
method_name
,
PROXY_NONE
,
args_string
);
if
(
!
transport
)
goto
err
;
...
...
@@ -1074,7 +1093,7 @@ parse_cmethod_line(const char *line, managed_proxy_t *mp)
goto
err
;
}
transport
=
transport_new
(
&
tor_addr
,
port
,
method_name
,
socks_ver
);
transport
=
transport_new
(
&
tor_addr
,
port
,
method_name
,
socks_ver
,
NULL
);
if
(
!
transport
)
goto
err
;
...
...
@@ -1436,6 +1455,8 @@ pt_get_extra_info_descriptor_string(void)
tor_assert
(
mp
->
transports
);
SMARTLIST_FOREACH_BEGIN
(
mp
->
transports
,
const
transport_t
*
,
t
)
{
char
*
transport_args
=
NULL
;
/* If the transport proxy returned "0.0.0.0" as its address, and
* we know our external IP address, use it. Otherwise, use the
* returned address. */
...
...
@@ -1451,9 +1472,16 @@ pt_get_extra_info_descriptor_string(void)
addrport
=
fmt_addrport
(
&
t
->
addr
,
t
->
port
);
}
/* If this transport has any arguments with it, prepend a space
to them so that we can add them to the transport line. */
if
(
t
->
extra_info_args
)
tor_asprintf
(
&
transport_args
,
" %s"
,
t
->
extra_info_args
);
smartlist_add_asprintf
(
string_chunks
,
"transport %s %s"
,
t
->
name
,
addrport
);
"transport %s %s%s"
,
t
->
name
,
addrport
,
transport_args
?
transport_args
:
""
);
tor_free
(
transport_args
);
}
SMARTLIST_FOREACH_END
(
t
);
}
SMARTLIST_FOREACH_END
(
mp
);
...
...
This diff is collapsed.
Click to expand it.
src/or/transports.h
+
6
−
0
View file @
d7ccb6a3
...
...
@@ -25,6 +25,9 @@ typedef struct transport_t {
/** Boolean: We are re-parsing our transport list, and we are going to remove
* this one if we don't find it in the list of configured transports. */
unsigned
marked_for_removal
:
1
;
/** Arguments for this transport that must be written to the
extra-info descriptor. */
char
*
extra_info_args
;
}
transport_t
;
void
mark_transport_list
(
void
);
...
...
@@ -117,6 +120,9 @@ STATIC void managed_proxy_destroy(managed_proxy_t *mp,
STATIC
managed_proxy_t
*
managed_proxy_create
(
const
smartlist_t
*
transport_list
,
char
**
proxy_argv
,
int
is_server
);
STATIC
managed_proxy_t
*
managed_proxy_create
(
const
smartlist_t
*
transport_list
,
char
**
proxy_argv
,
int
is_server
);
#endif
#endif
...
...
This diff is collapsed.
Click to expand it.
src/test/test_pt.c
+
63
−
0
View file @
d7ccb6a3
...
...
@@ -93,6 +93,22 @@ test_pt_parsing(void)
reset_mp
(
mp
);
/* Include some arguments. Good ones. */
strlcpy
(
line
,
"SMETHOD trebuchet 127.0.0.1:9999 ARGS:counterweight=3,sling=snappy"
,
sizeof
(
line
));
test_assert
(
parse_smethod_line
(
line
,
mp
)
==
0
);
tt_int_op
(
1
,
==
,
smartlist_len
(
mp
->
transports
));
{
const
transport_t
*
transport
=
smartlist_get
(
mp
->
transports
,
0
);
tt_assert
(
transport
);
tt_str_op
(
transport
->
name
,
==
,
"trebuchet"
);
tt_int_op
(
transport
->
port
,
==
,
9999
);
tt_str_op
(
fmt_addr
(
&
transport
->
addr
),
==
,
"127.0.0.1"
);
tt_str_op
(
transport
->
extra_info_args
,
==
,
"counterweight=3,sling=snappy"
);
}
reset_mp
(
mp
);
/* unsupported version */
strlcpy
(
line
,
"VERSION 666"
,
sizeof
(
line
));
test_assert
(
parse_version
(
line
,
mp
)
<
0
);
...
...
@@ -207,6 +223,51 @@ test_pt_protocol(void)
tor_free
(
mp
);
}
static
void
test_pt_get_extrainfo_string
(
void
*
arg
)
{
managed_proxy_t
*
mp1
=
NULL
,
*
mp2
=
NULL
;
char
**
argv1
,
**
argv2
;
smartlist_t
*
t1
=
smartlist_new
(),
*
t2
=
smartlist_new
();
int
r
;
char
*
s
=
NULL
;
(
void
)
arg
;
argv1
=
tor_malloc_zero
(
sizeof
(
char
*
)
*
3
);
argv1
[
0
]
=
tor_strdup
(
"ewige"
);
argv1
[
1
]
=
tor_strdup
(
"Blumenkraft"
);
argv1
[
2
]
=
NULL
;
argv2
=
tor_malloc_zero
(
sizeof
(
char
*
)
*
4
);
argv2
[
0
]
=
tor_strdup
(
"und"
);
argv2
[
1
]
=
tor_strdup
(
"ewige"
);
argv2
[
2
]
=
tor_strdup
(
"Schlangenkraft"
);
argv2
[
3
]
=
NULL
;
mp1
=
managed_proxy_create
(
t1
,
argv1
,
1
);
mp2
=
managed_proxy_create
(
t2
,
argv2
,
1
);
r
=
parse_smethod_line
(
"SMETHOD hagbard 127.0.0.1:5555"
,
mp1
);
tt_int_op
(
r
,
==
,
0
);
r
=
parse_smethod_line
(
"SMETHOD celine 127.0.0.1:1723 ARGS:card=no-enemy"
,
mp2
);
tt_int_op
(
r
,
==
,
0
);
/* Force these proxies to look "completed" or they won't generate output. */
mp1
->
conf_state
=
mp2
->
conf_state
=
PT_PROTO_COMPLETED
;
s
=
pt_get_extra_info_descriptor_string
();
tt_assert
(
s
);
tt_str_op
(
s
,
==
,
"transport hagbard 127.0.0.1:5555
\n
"
"transport celine 127.0.0.1:1723 card=no-enemy
\n
"
);
done:
/* XXXX clean up better */
smartlist_free
(
t1
);
smartlist_free
(
t2
);
tor_free
(
s
);
}
#define PT_LEGACY(name) \
{ #name, legacy_test_helper, 0, &legacy_setup, test_pt_ ## name }
...
...
@@ -215,6 +276,8 @@ struct testcase_t pt_tests[] = {
PT_LEGACY
(
protocol
),
{
"get_transport_options"
,
test_pt_get_transport_options
,
TT_FORK
,
NULL
,
NULL
},
{
"get_extrainfo_string"
,
test_pt_get_extrainfo_string
,
TT_FORK
,
NULL
,
NULL
},
END_OF_TESTCASES
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment