mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Fix DHT bootstraping
Fixes #1 Fixes bad translation of the DHT nodes' ports to big endian
This commit is contained in:
parent
b62700e6f6
commit
b6b062d8b9
58
core.cpp
58
core.cpp
|
@ -16,8 +16,6 @@
|
|||
|
||||
#include "core.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
|
@ -40,9 +38,12 @@ Core::Core() :
|
|||
saveTimer->start(TOX_SAVE_INTERVAL);
|
||||
fileTimer = new QTimer(this);
|
||||
fileTimer->start(TOX_FILE_INTERVAL);
|
||||
bootstrapTimer = new QTimer(this);
|
||||
bootstrapTimer->start(TOX_BOOTSTRAP_INTERVAL);
|
||||
connect(toxTimer, &QTimer::timeout, this, &Core::process);
|
||||
connect(saveTimer, &QTimer::timeout, this, &Core::saveConfiguration);
|
||||
connect(fileTimer, &QTimer::timeout, this, &Core::fileHeartbeat);
|
||||
connect(bootstrapTimer, &QTimer::timeout, this, &Core::onBootstrapTimer);
|
||||
connect(&Settings::getInstance(), &Settings::dhtServerListChanged, this, &Core::bootstrapDht);
|
||||
}
|
||||
|
||||
|
@ -54,6 +55,12 @@ Core::~Core()
|
|||
}
|
||||
}
|
||||
|
||||
void Core::onBootstrapTimer()
|
||||
{
|
||||
if(!tox_isconnected(tox))
|
||||
bootstrapDht();
|
||||
}
|
||||
|
||||
void Core::onFriendRequest(Tox*/* tox*/, const uint8_t* cUserId, const uint8_t* cMessage, uint16_t cMessageSize, void* core)
|
||||
{
|
||||
emit static_cast<Core*>(core)->friendRequestReceived(CUserId::toString(cUserId), CString::toString(cMessage, cMessageSize));
|
||||
|
@ -346,11 +353,25 @@ void Core::setStatus(Status status)
|
|||
|
||||
void Core::bootstrapDht()
|
||||
{
|
||||
qDebug() << "Core: Bootstraping DHT";
|
||||
const Settings& s = Settings::getInstance();
|
||||
QList<Settings::DhtServer> dhtServerList = s.getDhtServerList();
|
||||
|
||||
for (const Settings::DhtServer& dhtServer : dhtServerList) {
|
||||
tox_bootstrap_from_address(tox, dhtServer.address.toLatin1().data(), 0, qToBigEndian(dhtServer.port), CUserId(dhtServer.userId).data());
|
||||
static int j = 0;
|
||||
int i=0;
|
||||
int listSize = dhtServerList.size();
|
||||
while (i<2)
|
||||
{
|
||||
const Settings::DhtServer& dhtServer = dhtServerList[j % listSize];
|
||||
if (tox_bootstrap_from_address(tox, dhtServer.address.toLatin1().data(),
|
||||
0, qToBigEndian(dhtServer.port), CUserId(dhtServer.userId).data()) == 1)
|
||||
qDebug() << QString("Core: Bootstraping from ")+dhtServer.name+QString(", addr ")+dhtServer.address.toLatin1().data()
|
||||
+QString(", port ")+QString().setNum(qToBigEndian(dhtServer.port));
|
||||
else
|
||||
qDebug() << "Core: Error bootstraping from "+dhtServer.name;
|
||||
|
||||
j++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -362,8 +383,6 @@ void Core::process()
|
|||
fflush(stdout);
|
||||
#endif
|
||||
checkConnection();
|
||||
if (!tox_isconnected(tox))
|
||||
bootstrapDht();
|
||||
toxTimer->start(tox_do_interval(tox));
|
||||
}
|
||||
|
||||
|
@ -412,9 +431,11 @@ void Core::checkConnection()
|
|||
static bool isConnected = false;
|
||||
|
||||
if (tox_isconnected(tox) && !isConnected) {
|
||||
qDebug() << "Core: Connected to DHT";
|
||||
emit connected();
|
||||
isConnected = true;
|
||||
} else if (!tox_isconnected(tox) && isConnected) {
|
||||
qDebug() << "Core: Disconnected to DHT";
|
||||
emit disconnected();
|
||||
isConnected = false;
|
||||
}
|
||||
|
@ -523,8 +544,7 @@ void Core::checkLastOnline(int friendId) {
|
|||
|
||||
void Core::start()
|
||||
{
|
||||
tox = tox_new(0);
|
||||
|
||||
tox = tox_new(1);
|
||||
if (tox == nullptr) {
|
||||
qCritical() << "Core failed to start";
|
||||
emit failedToStart();
|
||||
|
@ -533,6 +553,17 @@ void Core::start()
|
|||
|
||||
loadConfiguration();
|
||||
|
||||
uint8_t friendAddress[TOX_FRIEND_ADDRESS_SIZE];
|
||||
tox_get_address(tox, friendAddress);
|
||||
|
||||
emit friendAddressGenerated(CFriendAddress::toString(friendAddress));
|
||||
|
||||
CString cUsername(Settings::getInstance().getUsername());
|
||||
tox_set_name(tox, cUsername.data(), cUsername.size());
|
||||
|
||||
CString cStatusMessage(Settings::getInstance().getStatusMessage());
|
||||
tox_set_status_message(tox, cStatusMessage.data(), cStatusMessage.size());
|
||||
|
||||
tox_callback_friend_request(tox, onFriendRequest, this);
|
||||
tox_callback_friend_message(tox, onFriendMessage, this);
|
||||
tox_callback_friend_action(tox, onAction, this);
|
||||
|
@ -548,17 +579,6 @@ void Core::start()
|
|||
tox_callback_file_control(tox, onFileControlCallback, this);
|
||||
tox_callback_file_data(tox, onFileDataCallback, this);
|
||||
|
||||
uint8_t friendAddress[TOX_FRIEND_ADDRESS_SIZE];
|
||||
tox_get_address(tox, friendAddress);
|
||||
|
||||
emit friendAddressGenerated(CFriendAddress::toString(friendAddress));
|
||||
|
||||
CString cUsername(Settings::getInstance().getUsername());
|
||||
tox_set_name(tox, cUsername.data(), cUsername.size());
|
||||
|
||||
CString cStatusMessage(Settings::getInstance().getStatusMessage());
|
||||
tox_set_status_message(tox, cStatusMessage.data(), cStatusMessage.size());
|
||||
|
||||
bootstrapDht();
|
||||
|
||||
toxTimer->start(tox_do_interval(tox));
|
||||
|
|
4
core.h
4
core.h
|
@ -32,6 +32,7 @@
|
|||
#define GROUPCHAT_MAX_SIZE 32
|
||||
#define TOX_SAVE_INTERVAL 30*1000
|
||||
#define TOX_FILE_INTERVAL 50
|
||||
#define TOX_BOOTSTRAP_INTERVAL 10*1000
|
||||
|
||||
struct DhtServer
|
||||
{
|
||||
|
@ -95,6 +96,7 @@ private:
|
|||
static void onFileDataCallback(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata);
|
||||
|
||||
void checkConnection();
|
||||
void onBootstrapTimer();
|
||||
|
||||
void loadConfiguration();
|
||||
void saveConfiguration();
|
||||
|
@ -103,7 +105,7 @@ private:
|
|||
void checkLastOnline(int friendId);
|
||||
|
||||
Tox* tox;
|
||||
QTimer *toxTimer, *saveTimer, *fileTimer;
|
||||
QTimer *toxTimer, *saveTimer, *fileTimer, *bootstrapTimer;
|
||||
QList<DhtServer> dhtServerList;
|
||||
int dhtServerId;
|
||||
static QList<ToxFile> fileSendQueue;
|
||||
|
|
|
@ -1,36 +1,36 @@
|
|||
[DHT%20Server]
|
||||
dhtServerList\size=13
|
||||
dhtServerList\1\name=benwaffle
|
||||
dhtServerList\1\userId=8E6667FF967EA30B3DC3DB57A4B533152476E7AAE090158B9C2D9DF58ECC7B78
|
||||
dhtServerList\1\address=192.3.30.132
|
||||
dhtServerList\size=16
|
||||
dhtServerList\1\name=stqism
|
||||
dhtServerList\1\userId=951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F
|
||||
dhtServerList\1\address=192.254.75.98
|
||||
dhtServerList\1\port=33445
|
||||
dhtServerList\2\name=zlacki RU #1
|
||||
dhtServerList\2\userId=D59F99384592DE4C8AB9D534D5197DB90F4755CC9E975ED0C565E18468A1445B
|
||||
dhtServerList\2\address=31.192.105.19
|
||||
dhtServerList\2\name=sonOfRa
|
||||
dhtServerList\2\userId=04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F
|
||||
dhtServerList\2\address=144.76.60.215
|
||||
dhtServerList\2\port=33445
|
||||
dhtServerList\3\name=aitjcize
|
||||
dhtServerList\3\userId=7F9C31FE850E97CEFD4C4591DF93FC757C7C12549DDD55F8EEAECC34FE76C029
|
||||
dhtServerList\3\address=54.199.139.199
|
||||
dhtServerList\3\name=stal
|
||||
dhtServerList\3\userId=A09162D68618E742FFBCA1C2C70385E6679604B2D80EA6E84AD0996A1AC8A074
|
||||
dhtServerList\3\address=23.226.230.47
|
||||
dhtServerList\3\port=33445
|
||||
dhtServerList\4\name=zlacki US
|
||||
dhtServerList\4\userId=9430A83211A7AD1C294711D069D587028CA0B4782FA43CB9B30008247A43C944
|
||||
dhtServerList\4\address=69.42.220.58
|
||||
dhtServerList\4\name=ChauffeR
|
||||
dhtServerList\4\userId=4FD54CFD426A338399767E56FD0F44F5E35FA8C38C8E87C8DC3FEAC0160F8E1
|
||||
dhtServerList\4\address=37.187.20.216
|
||||
dhtServerList\4\port=33445
|
||||
dhtServerList\5\name=platos
|
||||
dhtServerList\5\userId=B24E2FB924AE66D023FE1E42A2EE3B432010206F751A2FFD3E297383ACF1572E
|
||||
dhtServerList\5\address=66.175.223.88
|
||||
dhtServerList\5\name=aitjcize
|
||||
dhtServerList\5\userId=7F9C31FE850E97CEFD4C4591DF93FC757C7C12549DDD55F8EEAECC34FE76C029
|
||||
dhtServerList\5\address=54.199.139.199
|
||||
dhtServerList\5\port=33445
|
||||
dhtServerList\6\name=stqism
|
||||
dhtServerList\6\userId=951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F
|
||||
dhtServerList\6\address=192.254.75.98
|
||||
dhtServerList\6\name=astonex
|
||||
dhtServerList\6\userId=7F31BFC93B8E4016A902144D0B110C3EA97CB7D43F1C4D21BCAE998A7C838821
|
||||
dhtServerList\6\address=109.169.46.133
|
||||
dhtServerList\6\port=33445
|
||||
dhtServerList\7\name=nurupo
|
||||
dhtServerList\7\userId=F404ABAA1C99A9D37D61AB54898F56793E1DEF8BD46B1038B9D822E8460FAB67
|
||||
dhtServerList\7\address=192.210.149.121
|
||||
dhtServerList\7\port=33445
|
||||
dhtServerList\8\name=JmanGuy
|
||||
dhtServerList\8\userId=20C797E098701A848B07D0384222416B0EFB60D08CECB925B860CAEAAB572067
|
||||
dhtServerList\8\address=66.74.15.98
|
||||
dhtServerList\8\name=mousey
|
||||
dhtServerList\8\userId=5EB67C51D3FF5A9D528D242B669036ED2A30F8A60E674C45E7D43010CB2E1331
|
||||
dhtServerList\8\address=37.187.46.132
|
||||
dhtServerList\8\port=33445
|
||||
dhtServerList\9\name=zlacki NL
|
||||
dhtServerList\9\userId=CC2B02636A2ADBC2871D6EC57C5E9589D4FD5E6F98A14743A4B949914CF26D39
|
||||
|
@ -40,16 +40,27 @@ dhtServerList\10\name=zlacki RU #2
|
|||
dhtServerList\10\userId=AE27E1E72ADA3DC423C60EEBACA241456174048BE76A283B41AD32D953182D49
|
||||
dhtServerList\10\address=193.107.16.73
|
||||
dhtServerList\10\port=33445
|
||||
dhtServerList\11\name=stal
|
||||
dhtServerList\11\userId=A09162D68618E742FFBCA1C2C70385E6679604B2D80EA6E84AD0996A1AC8A074
|
||||
dhtServerList\11\address=23.226.230.47
|
||||
dhtServerList\11\name=platos
|
||||
dhtServerList\11\userId=B24E2FB924AE66D023FE1E42A2EE3B432010206F751A2FFD3E297383ACF1572E
|
||||
dhtServerList\11\address=66.175.223.88
|
||||
dhtServerList\11\port=33445
|
||||
dhtServerList\12\name=sonOfRa
|
||||
dhtServerList\12\userId=DDCF277B8B45B0D357D78AA4E201766932DF6CDB7179FC7D5C9F3C2E8E705326
|
||||
dhtServerList\12\address=144.76.60.215
|
||||
dhtServerList\12\name=JmanGuy
|
||||
dhtServerList\12\userId=20C797E098701A848B07D0384222416B0EFB60D08CECB925B860CAEAAB572067
|
||||
dhtServerList\12\address=66.74.15.98
|
||||
dhtServerList\12\port=33445
|
||||
dhtServerList\13\name=anonymous
|
||||
dhtServerList\13\userId=5CD7EB176C19A2FD840406CD56177BB8E75587BB366F7BB3004B19E3EDC04143
|
||||
dhtServerList\13\address=192.184.81.118
|
||||
dhtServerList\13\port=33445
|
||||
|
||||
dhtServerList\14\name=benwaffle
|
||||
dhtServerList\14\userId=8E6667FF967EA30B3DC3DB57A4B533152476E7AAE090158B9C2D9DF58ECC7B78
|
||||
dhtServerList\14\address=192.3.30.132
|
||||
dhtServerList\14\port=33445
|
||||
dhtServerList\15\name=zlacki RU #1
|
||||
dhtServerList\15\userId=D59F99384592DE4C8AB9D534D5197DB90F4755CC9E975ED0C565E18468A1445B
|
||||
dhtServerList\15\address=31.192.105.19
|
||||
dhtServerList\15\port=33445
|
||||
dhtServerList\16\name=zlacki US
|
||||
dhtServerList\16\userId=9430A83211A7AD1C294711D069D587028CA0B4782FA43CB9B30008247A43C944
|
||||
dhtServerList\16\address=69.42.220.58
|
||||
dhtServerList\16\port=33445
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <QFile>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
#include <QDebug>
|
||||
|
||||
const QString Settings::FILENAME = "settings.ini";
|
||||
|
||||
|
@ -52,6 +53,7 @@ void Settings::load()
|
|||
//if no settings file exist -- use the default one
|
||||
QFile file(filePath);
|
||||
if (!file.exists()) {
|
||||
qDebug() << "No settings file found, using defaults";
|
||||
filePath = ":/conf/" + FILENAME;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
QString name;
|
||||
QString userId;
|
||||
QString address;
|
||||
int port;
|
||||
quint16 port;
|
||||
};
|
||||
|
||||
const QList<DhtServer>& getDhtServerList() const;
|
||||
|
|
|
@ -80,8 +80,6 @@ Widget::Widget(QWidget *parent) :
|
|||
coreThread->start();
|
||||
|
||||
friendForm.show(*ui);
|
||||
|
||||
// TODO: For the friendlist just stack friend widgets in a scrollable widget's layout
|
||||
}
|
||||
|
||||
Widget::~Widget()
|
||||
|
@ -128,7 +126,7 @@ void Widget::onDisconnected()
|
|||
void Widget::onFailedToStartCore()
|
||||
{
|
||||
QMessageBox critical(this);
|
||||
critical.setText("Toxcor failed to start, the application will terminate after you close this message.");
|
||||
critical.setText("Toxcore failed to start, the application will terminate after you close this message.");
|
||||
critical.setIcon(QMessageBox::Critical);
|
||||
critical.exec();
|
||||
qApp->quit();
|
||||
|
|
Loading…
Reference in New Issue
Block a user