Browse Source

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.
reviewable/pr6465/r11
Anthony Bilinski 3 years ago
parent
commit
08fdd3a2c7
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 7
      doc/user_manual_en.md
  2. 34
      src/net/bootstrapnodeupdater.cpp
  3. 7
      src/persistence/paths.cpp
  4. 1
      src/persistence/paths.h

7
doc/user_manual_en.md

@ -463,9 +463,10 @@ information.
## Bootstrap Nodes ## Bootstrap Nodes
qTox uses bootstrap nodes to find its way in to the DHT. The list of nodes is 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 stored in `~/.config/tox/` on Linux, `%APPDATA%\Roaming\tox` on Windows, and
`~/.config/tox/` on Linux, `%APPDATA%\Roaming\tox` on Windows, and `~/Library/Application Support/Tox` on macOS. `bootstrapNodes.example.json`
`~/Library/Application Support/Tox` on macOS. stores the default list. If a new list is placed at `bootstrapNodes.json`, it
will be used instead.
## Avoiding Censorship ## Avoiding Censorship

34
src/net/bootstrapnodeupdater.cpp

@ -201,6 +201,19 @@ QByteArray serialize(QList<DhtServer> nodes)
QJsonDocument doc{rootObj}; QJsonDocument doc{rootObj};
return doc.toJson(QJsonDocument::Indented); 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 } // namespace
/** /**
@ -211,25 +224,18 @@ BootstrapNodeUpdater::BootstrapNodeUpdater(const QNetworkProxy& proxy, Paths& _p
: proxy{proxy} : proxy{proxy}
, paths{_paths} , paths{_paths}
, QObject{parent} , QObject{parent}
{} {
createExampleBootstrapNodesFile(_paths);
}
QList<DhtServer> BootstrapNodeUpdater::getBootstrapnodes() const QList<DhtServer> BootstrapNodeUpdater::getBootstrapnodes() const
{ {
auto userFilePath = paths.getUserNodesFilePath(); auto userFilePath = paths.getUserNodesFilePath();
if (!QFile(userFilePath).exists()) { if (QFile::exists(userFilePath)) {
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();
}
return loadNodesFile(userFilePath); return loadNodesFile(userFilePath);
} else {
return loadNodesFile(builtinNodesFile);
}
} }
void BootstrapNodeUpdater::requestBootstrapNodes() void BootstrapNodeUpdater::requestBootstrapNodes()

7
src/persistence/paths.cpp

@ -365,6 +365,13 @@ QString Paths::getAppCacheDirPath() const
#endif #endif
} }
QString Paths::getExampleNodesFilePath() const
{
QDir dir(getSettingsDirPath());
constexpr static char nodesFileName[] = "bootstrapNodes.example.json";
return dir.filePath(nodesFileName);
}
QString Paths::getUserNodesFilePath() const QString Paths::getUserNodesFilePath() const
{ {
QDir dir(getSettingsDirPath()); QDir dir(getSettingsDirPath());

1
src/persistence/paths.h

@ -51,6 +51,7 @@ public:
QString getSettingsDirPath() const; QString getSettingsDirPath() const;
QString getAppDataDirPath() const; QString getAppDataDirPath() const;
QString getAppCacheDirPath() const; QString getAppCacheDirPath() const;
QString getExampleNodesFilePath() const;
QString getUserNodesFilePath() const; QString getUserNodesFilePath() const;
#endif #endif

Loading…
Cancel
Save