mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
feat(core): Store default bootstrap list separate from user list
Allows qTox to tell the difference between a default list that should be upgraded when defaults are changed, ora user list that should never be changed.
This commit is contained in:
parent
2b41a06b55
commit
08fdd3a2c7
|
@ -463,9 +463,10 @@ information.
|
|||
## Bootstrap Nodes
|
||||
|
||||
qTox uses bootstrap nodes to find its way in to the DHT. The list of nodes is
|
||||
stored in `bootstrapNodes.json` and can be found and modified if wanted at
|
||||
`~/.config/tox/` on Linux, `%APPDATA%\Roaming\tox` on Windows, and
|
||||
`~/Library/Application Support/Tox` on macOS.
|
||||
stored in `~/.config/tox/` on Linux, `%APPDATA%\Roaming\tox` on Windows, and
|
||||
`~/Library/Application Support/Tox` on macOS. `bootstrapNodes.example.json`
|
||||
stores the default list. If a new list is placed at `bootstrapNodes.json`, it
|
||||
will be used instead.
|
||||
|
||||
## Avoiding Censorship
|
||||
|
||||
|
|
|
@ -201,6 +201,19 @@ QByteArray serialize(QList<DhtServer> nodes)
|
|||
QJsonDocument doc{rootObj};
|
||||
return doc.toJson(QJsonDocument::Indented);
|
||||
}
|
||||
|
||||
void createExampleBootstrapNodesFile(const Paths& paths)
|
||||
{
|
||||
// deserialize and reserialize instead of just copying to strip out any unnecessary json, making it easier for
|
||||
// users to edit. Overwrite the file on every start to keep it up to date when our internal list updates.
|
||||
auto buildInNodes = loadNodesFile(builtinNodesFile);
|
||||
auto serializedNodes = serialize(buildInNodes);
|
||||
|
||||
QFile outFile(paths.getExampleNodesFilePath());
|
||||
outFile.open(QIODevice::WriteOnly | QIODevice::Text);
|
||||
outFile.write(serializedNodes.data(), serializedNodes.size());
|
||||
outFile.close();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
/**
|
||||
|
@ -211,25 +224,18 @@ BootstrapNodeUpdater::BootstrapNodeUpdater(const QNetworkProxy& proxy, Paths& _p
|
|||
: proxy{proxy}
|
||||
, paths{_paths}
|
||||
, QObject{parent}
|
||||
{}
|
||||
{
|
||||
createExampleBootstrapNodesFile(_paths);
|
||||
}
|
||||
|
||||
QList<DhtServer> BootstrapNodeUpdater::getBootstrapnodes() const
|
||||
{
|
||||
auto userFilePath = paths.getUserNodesFilePath();
|
||||
if (!QFile(userFilePath).exists()) {
|
||||
qInfo() << "Bootstrap node list not found, creating one with default nodes.";
|
||||
// deserialize and reserialize instead of just copying to strip out any unnecessary json, making it easier for
|
||||
// users to edit
|
||||
auto buildInNodes = loadNodesFile(builtinNodesFile);
|
||||
auto serializedNodes = serialize(buildInNodes);
|
||||
|
||||
QFile outFile(userFilePath);
|
||||
outFile.open(QIODevice::WriteOnly | QIODevice::Text);
|
||||
outFile.write(serializedNodes.data(), serializedNodes.size());
|
||||
outFile.close();
|
||||
if (QFile::exists(userFilePath)) {
|
||||
return loadNodesFile(userFilePath);
|
||||
} else {
|
||||
return loadNodesFile(builtinNodesFile);
|
||||
}
|
||||
|
||||
return loadNodesFile(userFilePath);
|
||||
}
|
||||
|
||||
void BootstrapNodeUpdater::requestBootstrapNodes()
|
||||
|
|
|
@ -365,6 +365,13 @@ QString Paths::getAppCacheDirPath() const
|
|||
#endif
|
||||
}
|
||||
|
||||
QString Paths::getExampleNodesFilePath() const
|
||||
{
|
||||
QDir dir(getSettingsDirPath());
|
||||
constexpr static char nodesFileName[] = "bootstrapNodes.example.json";
|
||||
return dir.filePath(nodesFileName);
|
||||
}
|
||||
|
||||
QString Paths::getUserNodesFilePath() const
|
||||
{
|
||||
QDir dir(getSettingsDirPath());
|
||||
|
|
|
@ -51,6 +51,7 @@ public:
|
|||
QString getSettingsDirPath() const;
|
||||
QString getAppDataDirPath() const;
|
||||
QString getAppCacheDirPath() const;
|
||||
QString getExampleNodesFilePath() const;
|
||||
QString getUserNodesFilePath() const;
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user