Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions src/common/data/channel_async.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,6 @@ class ChannelAsync {

co_await timer.async_wait(boost::asio::use_awaitable);

// while (!mutex_.try_lock()) {
// if (std::chrono::steady_clock::now() - start >
// std::chrono::seconds(3)) {
// spdlog::error("Session::send: failed to acquire lock within
// timeout"); co_return false;
// }
// std::this_thread::yield(); // Yield to avoid busy waiting
// }

co_return;
}

Expand Down
30 changes: 30 additions & 0 deletions src/common/network/ip_address.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ class IPv4Address : public IPAddress<boost::asio::ip::address> {
return *this;
}

IPv4Address& operator=(const std::string& ip) {
*this = IPv4Address(ip);
return *this;
}

static IPv4Address Create(const std::string& ip) { return IPv4Address(ip); }

static IPv4Address Create(const boost::asio::ip::address& ip_addr) {
Expand Down Expand Up @@ -203,6 +208,11 @@ class IPv6Address : public IPAddress<boost::asio::ip::address> {
return *this;
}

IPv6Address& operator=(const std::string& ip) {
*this = IPv6Address(ip);
return *this;
}

static IPv6Address Create(const std::string& ip) { return IPv6Address(ip); }

static IPv6Address Create(const boost::asio::ip::address& ip_addr) {
Expand Down Expand Up @@ -315,6 +325,16 @@ class IPv4Address : public IPAddress<pcpp::IPv4Address> {
return *this;
}

IPv4Address& operator=(const pcpp::IPv4Address& other) {
*this = IPv4Address(other);
return *this;
}

IPv4Address& operator=(const std::string& ip) {
*this = IPv4Address(ip);
return *this;
}

static IPv4Address Create(std::string ip) {
return IPv4Address(std::move(ip));
}
Expand Down Expand Up @@ -365,6 +385,16 @@ class IPv6Address : public IPAddress<pcpp::IPv6Address> {
return *this;
}

IPv6Address& operator=(const pcpp::IPv6Address& other) {
*this = IPv6Address(other);
return *this;
}

IPv6Address& operator=(const std::string& ip) {
*this = IPv6Address(ip);
return *this;
}

static IPv6Address Create(std::string ip) {
return IPv6Address(std::move(ip));
}
Expand Down
13 changes: 13 additions & 0 deletions src/common/network/ip_packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,10 @@ class IPPacket {
parsed_packet_ = pcpp::Packet(&raw_packet_, false);
if (pcpp::LINKTYPE_IPV4 == ip_type) {
ipv4_layer_ = parsed_packet_.getLayerOfType<pcpp::IPv4Layer>();
ipv4_ = ipv4_layer_->getDstIPv4Address();
} else if (pcpp::LINKTYPE_IPV6 == ip_type) {
ipv6_layer_ = parsed_packet_.getLayerOfType<pcpp::IPv6Layer>();
ipv6_ = ipv6_layer_->getDstIPv6Address();
}
} catch (const std::exception& e) {
SPDLOG_WARN(
Expand Down Expand Up @@ -197,6 +199,14 @@ class IPPacket {
}
}

fptn::common::network::IPv4Address DstIPv4Address() const noexcept {
return ipv4_;
}

fptn::common::network::IPv6Address DstIPv6Address() const noexcept {
return ipv6_;
}

void SetClientId(fptn::ClientID client_id) noexcept {
client_id_ = client_id;
}
Expand Down Expand Up @@ -391,6 +401,9 @@ class IPPacket {

pcpp::IPv4Layer* ipv4_layer_ = nullptr;
pcpp::IPv6Layer* ipv6_layer_ = nullptr;

fptn::common::network::IPv4Address ipv4_;
fptn::common::network::IPv6Address ipv6_;
};

using IPPacketPtr = std::unique_ptr<IPPacket>;
Expand Down
14 changes: 12 additions & 2 deletions src/common/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ Distributed under the MIT License (https://opensource.org/licenses/MIT)
#include <boost/locale.hpp>

namespace fptn::common::utils {
inline std::string GenerateRandomString(int length) {
inline std::string GenerateRandomString(const int length) {
const std::string characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

std::mt19937 gen{std::random_device {}()};
std::mt19937 gen{std::random_device{}()};
std::uniform_int_distribution<std::size_t> dist(0, characters.size() - 1);

std::string result;
Expand Down Expand Up @@ -77,4 +77,14 @@ inline std::string ToLowerCase(const std::string& str) {
return str;
}

inline std::string FilterDigitsOnly(const std::string& input) {
std::string result;
result.reserve(input.size());

std::ranges::copy_if(input, std::back_inserter(result),
[](const unsigned char c) { return std::isdigit(c); });

return result;
}

} // namespace fptn::common::utils
23 changes: 23 additions & 0 deletions src/common/utils/uuid4.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*=============================================================================
Copyright (c) 2024-2026 Stas Skokov

Distributed under the MIT License (https://opensource.org/licenses/MIT)
=============================================================================*/

#pragma once

#include <string>

#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>

namespace fptn::common::utils {

inline std::string GenerateUUID4() {
boost::uuids::random_generator generator;
const boost::uuids::uuid uuid = generator();
return boost::uuids::to_string(uuid);
}

} // namespace fptn::common::utils
4 changes: 0 additions & 4 deletions src/fptn-client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ add_executable(
fptn-client-cli.cpp
vpn/vpn_client.h
vpn/vpn_client.cpp
vpn/http/client.h
vpn/http/client.cpp
routing/route_manager.h
routing/route_manager.cpp
config/config_file.cpp
Expand Down Expand Up @@ -124,8 +122,6 @@ WarningsAsErrors: ''
fptn-client-gui.cpp
vpn/vpn_client.h
vpn/vpn_client.cpp
vpn/http/client.h
vpn/http/client.cpp
routing/route_manager.h
routing/route_manager.cpp
config/config_file.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/fptn-client/config/config_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ using fptn::utils::speed_estimator::ServerInfo;
namespace fptn::config {

ConfigFile::ConfigFile(std::string sni,
fptn::protocol::https::CensorshipStrategy censorship_strategy)
fptn::protocol::https::HttpsInitConnectionStrategy censorship_strategy)
: sni_(std::move(sni)),
censorship_strategy_(censorship_strategy),
version_(0) {} // NOLINT(whitespace/indent_namespace)

ConfigFile::ConfigFile(std::string token,
std::string sni,
fptn::protocol::https::CensorshipStrategy censorship_strategy)
fptn::protocol::https::HttpsInitConnectionStrategy censorship_strategy)
: token_(std::move(token)),
sni_(std::move(sni)),
censorship_strategy_(censorship_strategy),
Expand Down
7 changes: 3 additions & 4 deletions src/fptn-client/config/config_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ Distributed under the MIT License (https://opensource.org/licenses/MIT)

#include "fptn-client/utils/speed_estimator/server_info.h"
#include "fptn-client/utils/speed_estimator/speed_estimator.h"
#include "fptn-protocol-lib/https/censorship_strategy.h"

namespace fptn::config {
class ConfigFile final {
public:
explicit ConfigFile(std::string sni,
fptn::protocol::https::CensorshipStrategy censorship_strategy);
fptn::protocol::https::HttpsInitConnectionStrategy censorship_strategy);
explicit ConfigFile(std::string token,
std::string sni,
fptn::protocol::https::CensorshipStrategy censorship_strategy);
fptn::protocol::https::HttpsInitConnectionStrategy censorship_strategy);

bool Parse();
fptn::utils::speed_estimator::ServerInfo FindFastestServer(
Expand All @@ -48,7 +47,7 @@ class ConfigFile final {
private:
const std::string token_;
const std::string sni_;
const fptn::protocol::https::CensorshipStrategy censorship_strategy_;
const fptn::protocol::https::HttpsInitConnectionStrategy censorship_strategy_;

int version_;
std::string service_name_;
Expand Down
37 changes: 24 additions & 13 deletions src/fptn-client/fptn-client-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Distributed under the MIT License (https://opensource.org/licenses/MIT)
#include "common/network/net_interface.h"

#include "config/config_file.h"
#include "fptn-protocol-lib/connection/connection_manager_builder/connection_manager_builder.h"
#include "fptn-protocol-lib/https/obfuscator/methods/detector.h"
#include "fptn-protocol-lib/time/time_provider.h"
#include "plugins/blacklist/domain_blacklist.h"
Expand Down Expand Up @@ -224,14 +225,14 @@ int main(int argc, char* argv[]) {
}

const auto bypass_method = args.get<std::string>("--bypass-method");
fptn::protocol::https::CensorshipStrategy censorship_strategy =
fptn::protocol::https::CensorshipStrategy::kSni;
fptn::protocol::https::HttpsInitConnectionStrategy censorship_strategy =
fptn::protocol::https::HttpsInitConnectionStrategy::kSni;
if (bypass_method == "obfuscation") {
censorship_strategy =
fptn::protocol::https::CensorshipStrategy::kTlsObfuscator;
fptn::protocol::https::HttpsInitConnectionStrategy::kTlsObfuscator;
} else if (bypass_method == "sni-reality") {
censorship_strategy =
fptn::protocol::https::CensorshipStrategy::kSniRealityMode;
fptn::protocol::https::HttpsInitConnectionStrategy::kSniRealityMode;
}

/* parse network lists */
Expand Down Expand Up @@ -314,17 +315,28 @@ int main(int argc, char* argv[]) {
split_domains_str, blacklist_domains_str);

/* auth & dns */
auto http_client = std::make_unique<fptn::vpn::http::Client>(server_ip,
selected_server.port, tun_interface_address_ipv4,
tun_interface_address_ipv6, sni, selected_server.md5_fingerprint,
censorship_strategy);
const auto strategy = fptn::protocol::connection::strategies::
ConnectionStrategy::kLongTermConnection;
auto connection_manager =
fptn::protocol::connection::ConnectionManagerBuilder()
.SetConnectionStrategyType(strategy)
.SetServer(server_ip, selected_server.port)
.SetTunInterface(
tun_interface_address_ipv4, tun_interface_address_ipv6)
.SetSNI(sni)
.SetServerFingerprint(selected_server.md5_fingerprint)
.SetCensorshipStrategy(censorship_strategy)
.SetMaxReconnections(5)
.SetConnectionTimeout(10000)
.Build();

const bool status =
http_client->Login(config.GetUsername(), config.GetPassword());
connection_manager->Login(config.GetUsername(), config.GetPassword());
if (!status) {
SPDLOG_ERROR("The username or password you entered is incorrect");
return EXIT_FAILURE;
}
const auto [dnsServerIPv4, dnsServerIPv6] = http_client->GetDns();
const auto [dnsServerIPv4, dnsServerIPv6] = connection_manager->GetDns();
if (dnsServerIPv4.IsEmpty() || dnsServerIPv6.IsEmpty()) {
SPDLOG_ERROR("DNS server error! Check your connection!");
return EXIT_FAILURE;
Expand Down Expand Up @@ -364,9 +376,8 @@ int main(int argc, char* argv[]) {
}

/* vpn client */
fptn::vpn::VpnClient vpn_client(std::move(http_client),
std::move(virtual_network_interface), dnsServerIPv4, dnsServerIPv6,
std::move(client_plugins));
fptn::vpn::VpnClient vpn_client(std::move(connection_manager),
std::move(virtual_network_interface), std::move(client_plugins));
vpn_client.Start();

// Wait for the WebSocket tunnel to establish
Expand Down
8 changes: 4 additions & 4 deletions src/fptn-client/fptn-client-gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ int main(int argc, char* argv[]) {

// Setup signal handler
#if defined(__APPLE__) || defined(__linux__)
std::signal(SIGINT, SignalHandler);
std::signal(SIGHUP, SignalHandler);
std::signal(SIGTERM, SignalHandler);
std::signal(SIGQUIT, SignalHandler);
::signal(SIGINT, SignalHandler);
::signal(SIGHUP, SignalHandler);
::signal(SIGTERM, SignalHandler);
::signal(SIGQUIT, SignalHandler);
#if __linux__
std::signal(SIGPWR, SignalHandler);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ void SniAutoscanDialog::WorkerThread(int thread_id) {
constexpr int kHandshakeTimeout = 2;
fptn::protocol::https::ApiClient client(server.host.toStdString(),
server.port, sni, server.md5_fingerprint.toStdString(),
protocol::https::CensorshipStrategy::kSni);
protocol::https::HttpsInitConnectionStrategy::kSni);

handshake_ok = client.TestHandshake(kHandshakeTimeout);
if (handshake_ok) {
Expand Down
Loading
Loading