mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Option to use custom list of bootstrap nodes
False by default, to allow for auto-updates and fix problems with people who can't connect to the DHT due to the old list not being updated and not working
This commit is contained in:
parent
bf8e1101c5
commit
86ca598a48
4
core.cpp
4
core.cpp
|
@ -882,7 +882,8 @@ void Core::saveConfiguration()
|
|||
return;
|
||||
}
|
||||
|
||||
qDebug() << "Core: writing tox_save";
|
||||
qDebug() << "Core: Saving";
|
||||
|
||||
uint32_t fileSize = tox_size(tox);
|
||||
if (fileSize > 0 && fileSize <= INT32_MAX) {
|
||||
uint8_t *data = new uint8_t[fileSize];
|
||||
|
@ -892,7 +893,6 @@ void Core::saveConfiguration()
|
|||
delete[] data;
|
||||
}
|
||||
|
||||
qDebug() << "Core: writing settings";
|
||||
Settings::getInstance().save();
|
||||
}
|
||||
|
||||
|
|
57
settings.cpp
57
settings.cpp
|
@ -30,7 +30,7 @@ const QString Settings::FILENAME = "settings.ini";
|
|||
bool Settings::makeToxPortable{false};
|
||||
|
||||
Settings::Settings() :
|
||||
loaded(false)
|
||||
loaded(false), useCustomDhtList{false}
|
||||
{
|
||||
load();
|
||||
}
|
||||
|
@ -48,8 +48,9 @@ Settings& Settings::getInstance()
|
|||
|
||||
void Settings::load()
|
||||
{
|
||||
if (loaded)
|
||||
if (loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
QFile portableSettings(FILENAME);
|
||||
if (portableSettings.exists())
|
||||
|
@ -71,19 +72,28 @@ void Settings::load()
|
|||
filePath = ":/conf/" + FILENAME;
|
||||
}
|
||||
|
||||
qDebug() << "Settings: Loading from "<<filePath;
|
||||
|
||||
QSettings s(filePath, QSettings::IniFormat);
|
||||
s.beginGroup("DHT Server");
|
||||
int serverListSize = s.beginReadArray("dhtServerList");
|
||||
for (int i = 0; i < serverListSize; i ++) {
|
||||
s.setArrayIndex(i);
|
||||
DhtServer server;
|
||||
server.name = s.value("name").toString();
|
||||
server.userId = s.value("userId").toString();
|
||||
server.address = s.value("address").toString();
|
||||
server.port = s.value("port").toInt();
|
||||
dhtServerList << server;
|
||||
if (s.value("useCustomList").toBool())
|
||||
{
|
||||
useCustomDhtList = true;
|
||||
qDebug() << "Using custom bootstrap nodes list";
|
||||
int serverListSize = s.beginReadArray("dhtServerList");
|
||||
for (int i = 0; i < serverListSize; i ++) {
|
||||
s.setArrayIndex(i);
|
||||
DhtServer server;
|
||||
server.name = s.value("name").toString();
|
||||
server.userId = s.value("userId").toString();
|
||||
server.address = s.value("address").toString();
|
||||
server.port = s.value("port").toInt();
|
||||
dhtServerList << server;
|
||||
}
|
||||
s.endArray();
|
||||
}
|
||||
s.endArray();
|
||||
else
|
||||
useCustomDhtList=false;
|
||||
s.endGroup();
|
||||
|
||||
friendAddresses.clear();
|
||||
|
@ -137,6 +147,26 @@ void Settings::load()
|
|||
if (!SmileyPack::isValid(smileyPack) && !SmileyPack::listSmileyPacks().isEmpty())
|
||||
smileyPack = SmileyPack::listSmileyPacks()[0].second;
|
||||
|
||||
// Read the embedded DHT bootsrap nodes list if needed
|
||||
if (dhtServerList.isEmpty())
|
||||
{
|
||||
qDebug() << "Using embeded bootstrap nodes list";
|
||||
QSettings rcs(":/conf/settings.ini", QSettings::IniFormat);
|
||||
rcs.beginGroup("DHT Server");
|
||||
int serverListSize = rcs.beginReadArray("dhtServerList");
|
||||
for (int i = 0; i < serverListSize; i ++) {
|
||||
rcs.setArrayIndex(i);
|
||||
DhtServer server;
|
||||
server.name = rcs.value("name").toString();
|
||||
server.userId = rcs.value("userId").toString();
|
||||
server.address = rcs.value("address").toString();
|
||||
server.port = rcs.value("port").toInt();
|
||||
dhtServerList << server;
|
||||
}
|
||||
rcs.endArray();
|
||||
rcs.endGroup();
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
|
@ -148,11 +178,14 @@ void Settings::save()
|
|||
|
||||
void Settings::save(QString path)
|
||||
{
|
||||
qDebug() << "Settings: Saving in "<<path;
|
||||
|
||||
QSettings s(path, QSettings::IniFormat);
|
||||
|
||||
s.clear();
|
||||
|
||||
s.beginGroup("DHT Server");
|
||||
s.setValue("useCustomList", useCustomDhtList);
|
||||
s.beginWriteArray("dhtServerList", dhtServerList.size());
|
||||
for (int i = 0; i < dhtServerList.size(); i ++) {
|
||||
s.setArrayIndex(i);
|
||||
|
|
|
@ -142,6 +142,7 @@ private:
|
|||
|
||||
bool loaded;
|
||||
|
||||
bool useCustomDhtList;
|
||||
QList<DhtServer> dhtServerList;
|
||||
int dhtServerId;
|
||||
bool dontShowDhtDialog;
|
||||
|
|
Loading…
Reference in New Issue
Block a user