[refactor] use MiniRTC public APIs across clients

This commit is contained in:
dijunkun committed 2026-11-06 23:44:54 +08:00
1 parent 05782bce7c
commit a64a28a5a3
16 files changed
+121 -86

No files matched your search

@@ -13,7 +13,7 @@
#include <stdexcept>
#include <string_view>
#include "direct_address.h"
#include <minirtc.h>
#include "lan_password.h"
#ifdef _WIN32
// Winsock must precede windows.h; the networking headers need its types.
@@ -212,12 +212,14 @@ unsigned ParsePort(const std::string& value) {
return port;
}
bool IsIpAddress(const std::string& value) {
return minirtc::ParseDirectAddress(value).has_value();
char normalized[129]{};
return NormalizeMiniRtcDirectAddress(value.data(), value.size(), normalized, sizeof(normalized)) == 0;
}
std::string NormalizeAddress(const std::string& value) {
const auto address = minirtc::ParseDirectAddress(value);
Require(address.has_value(), "Invalid LAN endpoint");
return minirtc::DirectAddressString(*address);
char normalized[129]{};
Require(NormalizeMiniRtcDirectAddress(value.data(), value.size(), normalized, sizeof(normalized)) == 0,
"Invalid LAN endpoint");
return normalized;
}
std::string FormatEndpoint(const std::string& address, unsigned port) {
return (address.find(':') == std::string::npos ? address
@@ -13,7 +13,7 @@
#include <websocketpp/config/asio_client.hpp>
#include <websocketpp/server.hpp>
#include "direct_address.h"
#include <minirtc.h>
namespace crossdesk::lan {
namespace {
@@ -147,7 +147,11 @@ bool SupportsDualStack() {
std::string SocketAddress(asio::ip::address address) {
if (address.is_v6() && address.to_v6().is_v4_mapped())
address = asio::ip::make_address_v4(asio::ip::v4_mapped, address.to_v6());
return minirtc::DirectAddressString(address);
if (address.is_v4()) return address.to_string();
auto ipv6 = address.to_v6();
const auto scope = ipv6.scope_id();
ipv6.scope_id(0);
return ipv6.to_string() + (scope ? "%" + std::to_string(scope) : "");
}
std::shared_ptr<Context> TlsContext() {
auto context = std::make_shared<Context>(Context::tls);
@@ -323,7 +327,8 @@ struct Transport::Impl {
c->local_address = SocketAddress(local.address());
c->remote_address = SocketAddress(remote.address());
const auto interfaces = LocalIpInterfaces();
if (!minirtc::IsDirectAddressPair(c->local_address, c->remote_address) ||
if (IsMiniRtcDirectAddressPair(c->local_address.data(), c->local_address.size(),
c->remote_address.data(), c->remote_address.size()) != 1 ||
std::none_of(
interfaces.begin(), interfaces.end(),
[&](const auto& i) { return i.address == c->local_address; })) {