Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
udp-forwarder-ex
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Recolic
udp-forwarder-ex
Commits
9a740f04
There was an error fetching the commit references. Please try again later.
Unverified
Commit
9a740f04
authored
4 years ago
by
Bensong Liu
Browse files
Options
Downloads
Patches
Plain Diff
add reverse filter
parent
221ccbe3
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/filters/base.hpp
+25
-2
25 additions, 2 deletions
src/filters/base.hpp
src/forwarder.hpp
+19
-13
19 additions, 13 deletions
src/forwarder.hpp
src/main.cc
+1
-1
1 addition, 1 deletion
src/main.cc
with
45 additions
and
16 deletions
src/filters/base.hpp
+
25
−
2
View file @
9a740f04
...
...
@@ -30,7 +30,7 @@ namespace Filters {
};
struct
ChainedFilters
:
public
BaseFilter
{
ChainedFilters
(
const
std
::
list
<
Filters
::
BaseFilter
*>&
chainedFilters
)
explicit
ChainedFilters
(
const
std
::
list
<
Filters
::
BaseFilter
*>&
chainedFilters
)
:
chainedFilters
(
chainedFilters
)
{}
// Usually the encrypt/encode/obfs function.
...
...
@@ -42,7 +42,7 @@ namespace Filters {
}
// Usually the decrypt/decode/de-obfs function.
virtual
string
convertBackward
(
string
binaryDatagram
)
{
virtual
string
convertBackward
(
string
binaryDatagram
)
override
{
for
(
auto
iter
=
chainedFilters
.
rbegin
();
iter
!=
chainedFilters
.
rend
();
++
iter
)
{
binaryDatagram
=
(
*
iter
)
->
convertForward
(
binaryDatagram
);
}
...
...
@@ -51,6 +51,29 @@ namespace Filters {
const
std
::
list
<
Filters
::
BaseFilter
*>&
chainedFilters
;
};
struct
ReversedFilter
:
public
BaseFilter
{
explicit
ReversedFilter
(
BaseFilter
*
real
,
bool
I_should_delete
=
false
)
:
real
(
real
),
I_should_delete
(
I_should_delete
)
{}
virtual
~
ReversedFilter
()
{
if
(
I_should_delete
)
delete
real
;
}
// Usually the encrypt/encode/obfs function.
virtual
string
convertForward
(
string
binaryDatagram
)
override
{
return
real
->
convertBackward
(
binaryDatagram
);
}
// Usually the decrypt/decode/de-obfs function.
virtual
string
convertBackward
(
string
binaryDatagram
)
override
{
return
real
->
convertForward
(
binaryDatagram
);
}
bool
I_should_delete
=
false
;
BaseFilter
*
real
;
};
}
#endif
...
...
This diff is collapsed.
Click to expand it.
src/forwarder.hpp
+
19
−
13
View file @
9a740f04
...
...
@@ -14,6 +14,23 @@
using
std
::
string
;
// This function parse the FilterConfig string for you. Register implemented modules here!
inline
Filters
::
BaseFilter
*
CreateFilterFromConfig
(
rlib
::
string
filterConfig
)
{
Filters
::
BaseFilter
*
newFilter
=
nullptr
;
if
(
filterConfig
.
starts_with
(
"aes@"
))
newFilter
=
new
Filters
::
AESFilter
();
else
if
(
filterConfig
.
starts_with
(
"xor@"
))
newFilter
=
new
Filters
::
XorFilter
();
// these filters were not deleted. just a note.
else
if
(
filterConfig
.
starts_with
(
"reverse@"
))
{
auto
newFilterConfig
=
filterConfig
.
substr
(
8
);
newFilter
=
new
Filters
::
ReversedFilter
(
CreateFilterFromConfig
(
newFilterConfig
),
true
);
}
else
throw
std
::
invalid_argument
(
"Unknown filter in filterConfig item: "
+
filterConfig
);
newFilter
->
loadConfig
(
filterConfig
);
return
newFilter
;
}
class
Forwarder
{
public:
...
...
@@ -36,19 +53,8 @@ public:
std
::
list
<
Filters
::
BaseFilter
*>
chainedFilters
;
for
(
auto
&&
filterConfig
:
filterConfigs
)
{
Filters
::
BaseFilter
*
newFilter
=
nullptr
;
if
(
filterConfig
.
starts_with
(
"aes"
))
newFilter
=
new
Filters
::
AESFilter
();
else
if
(
filterConfig
.
starts_with
(
"xor"
))
newFilter
=
new
Filters
::
XorFilter
();
// these filters were not deleted. just a note.
else
throw
std
::
invalid_argument
(
"Unknown filter in filterConfig item: "
+
filterConfig
);
newFilter
->
loadConfig
(
filterConfig
);
chainedFilters
.
push_back
(
newFilter
);
}
for
(
auto
&&
filterConfig
:
filterConfigs
)
chainedFilters
.
push_back
(
CreateFilterFromConfig
(
filterConfig
));
ptrFilter
=
new
Filters
::
ChainedFilters
(
chainedFilters
);
}
...
...
This diff is collapsed.
Click to expand it.
src/main.cc
+
1
−
1
View file @
9a740f04
...
...
@@ -26,7 +26,7 @@ int real_main(int argc, char **argv) {
rlog
.
info
(
" '$method@$params', available methods: "
);
rlog
.
info
(
" 'plain@$addr@$port', 'misc@$addr@$portRange@$psk'"
);
rlog
.
info
(
"There could be multiple --filter, but they MUST be in correct order. "
);
rlog
.
info
(
"available filters: 'aes@$password' , 'xor@$password'"
);
rlog
.
info
(
"available filters: 'aes@$password' , 'xor@$password'
, 'reverse@$otherFilter'
"
);
return
0
;
}
auto
inboundConfig
=
args
.
getValueArg
(
"-i"
);
...
...
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