Skip to content

Commit 8e07692

Browse files
committed
Aborted data should not be passed to recv function
append_paylaod is no longer needed.
1 parent c26ff8d commit 8e07692

File tree

10 files changed

+15
-28
lines changed

10 files changed

+15
-28
lines changed

docs/config.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ In this page, we will look at the config file of trojan. Trojan uses [`JSON`](ht
1616
"password": [
1717
"password1"
1818
],
19-
"append_payload": true,
2019
"log_level": 1,
2120
"ssl": {
2221
"verify": true,
@@ -47,7 +46,6 @@ In this page, we will look at the config file of trojan. Trojan uses [`JSON`](ht
4746
- `remote_addr`: server address (hostname)
4847
- `remote_port`: server port
4948
- `password`: password used for verification (only the first password in the array will be used)
50-
- `append_payload`: whether to append the first packet to trojan request. It can reduce length patterns of sessions, but may cause stability issues, in which case set it to `false`. For example, if you are running trojan server and trojan client on the same machine, you should set this option to `false`, because there is a race condition at the time the client receives its first packet.
5149
- `log_level`: how much log to dump. 0: ALL; 1: INFO; 2: WARN; 3: ERROR; 4: FATAL; 5: OFF.
5250
- `ssl`: `SSL` specific configurations
5351
- `verify`: whether to verify `SSL` certificate **STRONGLY RECOMMENDED**
@@ -81,7 +79,6 @@ This forward config is for port forwarding. Everything is the same as the client
8179
"password": [
8280
"password1"
8381
],
84-
"append_payload": true,
8582
"udp_timeout": 60,
8683
"log_level": 1,
8784
"ssl": {

examples/client.json-example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"password": [
88
"password1"
99
],
10-
"append_payload": true,
1110
"log_level": 1,
1211
"ssl": {
1312
"verify": true,

examples/forward.json-example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"password": [
1010
"password1"
1111
],
12-
"append_payload": true,
1312
"udp_timeout": 60,
1413
"log_level": 1,
1514
"ssl": {

src/clientsession.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ void ClientSession::start() {
6060
void ClientSession::in_async_read() {
6161
auto self = shared_from_this();
6262
in_socket.async_read_some(boost::asio::buffer(in_read_buf, MAX_LENGTH), [this, self](const boost::system::error_code error, size_t length) {
63-
if (error && error != boost::asio::error::operation_aborted) {
63+
if (error == boost::asio::error::operation_aborted) {
64+
return;
65+
}
66+
if (error) {
6467
destroy();
6568
return;
6669
}
@@ -106,7 +109,10 @@ void ClientSession::out_async_write(const string &data) {
106109
void ClientSession::udp_async_read() {
107110
auto self = shared_from_this();
108111
udp_socket.async_receive_from(boost::asio::buffer(udp_read_buf, MAX_LENGTH), udp_recv_endpoint, [this, self](const boost::system::error_code error, size_t length) {
109-
if (error && error != boost::asio::error::operation_aborted) {
112+
if (error == boost::asio::error::operation_aborted) {
113+
return;
114+
}
115+
if (error) {
110116
destroy();
111117
return;
112118
}
@@ -211,17 +217,9 @@ void ClientSession::in_sent() {
211217
}
212218
case REQUEST: {
213219
status = CONNECT;
220+
in_async_read();
214221
if (is_udp) {
215-
in_async_read();
216-
}
217-
if (config.append_payload) {
218-
if (is_udp) {
219-
udp_async_read();
220-
} else {
221-
in_async_read();
222-
}
223-
} else {
224-
first_packet_recv = true;
222+
udp_async_read();
225223
}
226224
auto self = shared_from_this();
227225
resolver.async_resolve(config.remote_addr, to_string(config.remote_port), [this, self](const boost::system::error_code error, tcp::resolver::results_type results) {

src/config.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ void Config::populate(const ptree &tree) {
5959
string p = item.second.get_value<string>();
6060
password[SHA224(p)] = p;
6161
}
62-
append_payload = tree.get("append_payload", true);
6362
udp_timeout = tree.get("udp_timeout", 60);
6463
log_level = static_cast<Log::Level>(tree.get("log_level", 1));
6564
ssl.verify = tree.get("ssl.verify", true);

src/config.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class Config {
3939
std::string target_addr;
4040
uint16_t target_port;
4141
std::map<std::string, std::string> password;
42-
bool append_payload;
4342
int udp_timeout;
4443
Log::Level log_level;
4544
class SSLConfig {

src/forwardsession.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ void ForwardSession::start() {
5454
}
5555
}
5656
out_write_buf = TrojanRequest::generate(config.password.cbegin()->first, config.target_addr, config.target_port, true);
57-
if (config.append_payload) {
58-
in_async_read();
59-
} else {
60-
first_packet_recv = true;
61-
}
57+
in_async_read();
6258
Log::log_with_endpoint(in_endpoint, "forwarding to " + config.target_addr + ':' + to_string(config.target_port) + " via " + config.remote_addr + ':' + to_string(config.remote_port), Log::INFO);
6359
auto self = shared_from_this();
6460
resolver.async_resolve(config.remote_addr, to_string(config.remote_port), [this, self](const boost::system::error_code error, tcp::resolver::results_type results) {
@@ -123,7 +119,10 @@ void ForwardSession::start() {
123119
void ForwardSession::in_async_read() {
124120
auto self = shared_from_this();
125121
in_socket.async_read_some(boost::asio::buffer(in_read_buf, MAX_LENGTH), [this, self](const boost::system::error_code error, size_t length) {
126-
if (error && error != boost::asio::error::operation_aborted) {
122+
if (error == boost::asio::error::operation_aborted) {
123+
return;
124+
}
125+
if (error) {
127126
destroy();
128127
return;
129128
}

tests/LinuxSmokeTest/client.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"password": [
88
"linux-smoke-test-password"
99
],
10-
"append_payload": false,
1110
"log_level": 0,
1211
"ssl": {
1312
"verify": true,

tests/LinuxSmokeTest/fake-client.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"password": [
88
"wrong-password"
99
],
10-
"append_payload": false,
1110
"log_level": 0,
1211
"ssl": {
1312
"verify": true,

tests/LinuxSmokeTest/forward.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"password": [
1010
"linux-smoke-test-password"
1111
],
12-
"append_payload": false,
1312
"udp_timeout": 60,
1413
"log_level": 0,
1514
"ssl": {

0 commit comments

Comments
 (0)