Persist automatic socket protocols in desktop configuration
This commit is contained in:
1 parent
556f6e0b9e
commit
f3bc5acacc
2 files changed
+18
-1
No files matched your search
@@ -20,7 +20,7 @@ static const QSet<QString> GLOBAL_KEYS = {
|
||||
"my_node_name", "my_private_key", "my_public_key", "my_node_id",
|
||||
"tun_enabled", "tun_ifname", "tun_ip", "mtu",
|
||||
"keepalive_timeout", "keepalive_interval", "keepalive_adaptive", "bbr_max_cwnd",
|
||||
"auto_sockets",
|
||||
"auto_sockets", "auto_socket_protocols",
|
||||
"debug_level", "log_file", "db_path", "db_sync_enabled", "db_sync_ttl",
|
||||
"enable_timestamp", "enable_function_names", "enable_file_lines", "enable_colors",
|
||||
"tun_test_mode"
|
||||
@@ -212,6 +212,7 @@ bool NodeConfig::create(const QString& nodeName, quint16 listenPort) {
|
||||
m_clients.clear();
|
||||
(void)listenPort; /* автосокеты сами создают UDP+TCP на случайных портах */
|
||||
m_autoSockets = true;
|
||||
m_autoSocketProtocols = QStringLiteral("tcp+udp");
|
||||
if (m_dbPath.isEmpty())
|
||||
m_dbPath = "chat_data";
|
||||
if (m_debugFile.isEmpty())
|
||||
@@ -227,6 +228,7 @@ bool NodeConfig::load() {
|
||||
m_clients.clear();
|
||||
m_errors.clear();
|
||||
m_language = QStringLiteral("system");
|
||||
m_autoSocketProtocols = QStringLiteral("tcp+udp");
|
||||
|
||||
QString section, controlIp, controlPort;
|
||||
QTextStream in(&f);
|
||||
@@ -311,6 +313,16 @@ bool NodeConfig::load() {
|
||||
else if (key == "my_public_key") m_pubKey = val;
|
||||
else if (key == "my_private_key") m_privKey = val;
|
||||
else if (key == "auto_sockets") m_autoSockets = (val.compare("yes", Qt::CaseInsensitive) == 0 || val == "1");
|
||||
else if (key == "auto_socket_protocols") {
|
||||
const QString protocols = val.toLower();
|
||||
if (protocols == "tcp" || protocols == "udp" || protocols == "tcp+udp") m_autoSocketProtocols = protocols;
|
||||
else {
|
||||
m_errors.append(QString("line %1: invalid auto_socket_protocols='%2'; expected tcp, udp or tcp+udp")
|
||||
.arg(lineNum).arg(val));
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "auto_socket_protocols='%s' is invalid path=%s line=%d",
|
||||
qPrintable(val), qPrintable(m_path), lineNum);
|
||||
}
|
||||
}
|
||||
} else if (section.startsWith("server:")) {
|
||||
QString srvName = section.mid(7);
|
||||
if (key == "addr") m_servers.append({srvName, val});
|
||||
@@ -366,6 +378,7 @@ bool NodeConfig::saveFull() {
|
||||
if (!m_privKey.isEmpty()) out << "my_private_key=" << m_privKey << "\n";
|
||||
if (!m_pubKey.isEmpty()) out << "my_public_key=" << m_pubKey << "\n";
|
||||
out << "auto_sockets=" << (m_autoSockets ? "yes" : "no") << "\n";
|
||||
out << "auto_socket_protocols=" << m_autoSocketProtocols << "\n";
|
||||
out << "\n";
|
||||
|
||||
for (auto& srv : m_servers) {
|
||||
@@ -441,6 +454,7 @@ bool NodeConfig::save() {
|
||||
config_update_in_lines(lines, "global", "my_private_key", m_privKey, true);
|
||||
config_update_in_lines(lines, "global", "my_public_key", m_pubKey, true);
|
||||
config_update_in_lines(lines, "global", "auto_sockets", m_autoSockets ? "yes" : "no", true);
|
||||
config_update_in_lines(lines, "global", "auto_socket_protocols", m_autoSocketProtocols, true);
|
||||
|
||||
if (!m_controlAddr.isEmpty()) {
|
||||
int sep = m_controlAddr.lastIndexOf(':');
|
||||
|
||||
@@ -44,6 +44,8 @@ public:
|
||||
|
||||
bool autoSockets() const { return m_autoSockets; }
|
||||
void setAutoSockets(bool v) { m_autoSockets = v; }
|
||||
QString autoSocketProtocols() const { return m_autoSocketProtocols; }
|
||||
void setAutoSocketProtocols(const QString& protocols) { m_autoSocketProtocols = protocols; }
|
||||
|
||||
QString filePath() const { return m_path; }
|
||||
|
||||
@@ -75,6 +77,7 @@ private:
|
||||
QList<NodeClient> m_clients;
|
||||
QString m_controlAddr;
|
||||
bool m_autoSockets = true;
|
||||
QString m_autoSocketProtocols = QStringLiteral("tcp+udp"); // протоколы автоматически создаваемых сокетов
|
||||
QString m_dbPath;
|
||||
QString m_debugFile;
|
||||
QString m_debugLevel;
|
||||
|
||||
Reference in new issue
Block a user