Skip to content
Snippets Groups Projects
Unverified Commit 3d99eb64 authored by Bensong Liu's avatar Bensong Liu
Browse files

bug fix

parent f7009f0d
No related branches found
No related tags found
No related merge requests found
...@@ -16,8 +16,14 @@ constexpr size_t DGRAM_BUFFER_SIZE = 20480; ...@@ -16,8 +16,14 @@ constexpr size_t DGRAM_BUFFER_SIZE = 20480;
// to the real openvpn server. // to the real openvpn server.
constexpr size_t SERVER_ENCRYPT_CONNECTION_TIMEOUT_SECONDS = 60; constexpr size_t SERVER_ENCRYPT_CONNECTION_TIMEOUT_SECONDS = 60;
#include <random>
// MAGIC PORT NUMBER! Warning! Used for Inbound - Outbound IPC talking. Windows wepoll doesn't support PIPE, so I have to use this. // MAGIC PORT NUMBER! Warning! Used for Inbound - Outbound IPC talking. Windows wepoll doesn't support PIPE, so I have to use this.
constexpr uint16_t TCP_TMP_PORT_NUMBER = 50999; uint16_t get_tmp_tcp_port_number() {
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_int_distribution<int> dist(40000, 60000);
return dist(mt);
}
#endif #endif
...@@ -44,7 +44,7 @@ namespace Filters { ...@@ -44,7 +44,7 @@ namespace Filters {
// Usually the decrypt/decode/de-obfs function. // Usually the decrypt/decode/de-obfs function.
virtual string convertBackward(string binaryDatagram) override { virtual string convertBackward(string binaryDatagram) override {
for (auto iter = chainedFilters.rbegin(); iter != chainedFilters.rend(); ++iter) { for (auto iter = chainedFilters.rbegin(); iter != chainedFilters.rend(); ++iter) {
binaryDatagram = (*iter)->convertForward(binaryDatagram); binaryDatagram = (*iter)->convertBackward(binaryDatagram);
} }
return binaryDatagram; return binaryDatagram;
} }
......
...@@ -21,7 +21,7 @@ namespace Filters { ...@@ -21,7 +21,7 @@ namespace Filters {
virtual string convertForward(string datagram) override { virtual string convertForward(string datagram) override {
auto curr_key_digit = 0; auto curr_key_digit = 0;
for (auto offset = 0; offset < datagram.size(); ++offset) { for (auto offset = 0; offset < datagram.size(); ++offset) {
datagram[0] ^= key[curr_key_digit++]; datagram[offset] ^= key[curr_key_digit++];
} }
return datagram; return datagram;
} }
......
...@@ -79,12 +79,14 @@ inline auto mkpipe() { ...@@ -79,12 +79,14 @@ inline auto mkpipe() {
inline auto mk_tcp_pipe() { inline auto mk_tcp_pipe() {
sockfd_t connfd_cli_side, connfd_srv_side; sockfd_t connfd_cli_side, connfd_srv_side;
auto listenfd = rlib::quick_listen("::1", TCP_TMP_PORT_NUMBER); auto tmp_port = get_tmp_tcp_port_number();
auto listenfd = rlib::quick_listen("::1", tmp_port); // We have no UnixSocket on Windows.
auto serverThread = std::thread([&] { auto serverThread = std::thread([&] {
connfd_srv_side = rlib::quick_accept(listenfd); connfd_srv_side = rlib::quick_accept(listenfd);
}); });
connfd_cli_side = rlib::quick_connect("::1", TCP_TMP_PORT_NUMBER); connfd_cli_side = rlib::quick_connect("::1", tmp_port);
serverThread.join(); serverThread.join();
rlib::sockIO::close_ex(listenfd);
return std::make_pair(connfd_cli_side, connfd_srv_side); return std::make_pair(connfd_cli_side, connfd_srv_side);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment