mirror of
https://github.com/ChronosX88/Influence-cjdns.git
synced 2024-11-23 15:42:18 +00:00
Changed "action" to check the availability of a peer
This commit is contained in:
parent
8b75f7c5e1
commit
65ab05979d
@ -5,8 +5,8 @@ Handler::Handler()
|
|||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
|
|
||||||
handlers = {
|
handlers = {
|
||||||
{"createSession", std::bind(&Handler::createSession, this, _1)},
|
{"checkPeer", std::bind(&Handler::createSession, this, _1)},
|
||||||
{"createSessionSuccess", std::bind(&Handler::createSessionSuccessMethod, this, _1)}
|
{"checkPeerSuccess", std::bind(&Handler::checkPeerSuccessMethod, this, _1)}
|
||||||
};
|
};
|
||||||
network = new Network();
|
network = new Network();
|
||||||
connect(network, &Network::json_received, this, &Handler::handle);
|
connect(network, &Network::json_received, this, &Handler::handle);
|
||||||
@ -23,12 +23,12 @@ void Handler::createSession(QJsonObject jsonReceived)
|
|||||||
{
|
{
|
||||||
QJsonObject jsonSend;
|
QJsonObject jsonSend;
|
||||||
jsonSend["peerID"] = my_ipv6;
|
jsonSend["peerID"] = my_ipv6;
|
||||||
jsonSend["action"] = "createSessionSuccess";
|
jsonSend["action"] = "checkPeerSuccess";
|
||||||
QString peerReceiver = jsonReceived["peerID"].toString();
|
QString peerReceiver = jsonReceived["peerID"].toString();
|
||||||
network->sendDatagram(jsonSend, peerReceiver);
|
network->sendDatagram(jsonSend, peerReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Handler::createSessionSuccessMethod(QJsonObject jsonReceived)
|
void Handler::createSessionSuccessMethod(QJsonObject jsonReceived)
|
||||||
{
|
{
|
||||||
emit createSessionSuccess();
|
emit checkPeerSuccess();
|
||||||
}
|
}
|
||||||
|
@ -12,12 +12,12 @@ class Handler : public QObject
|
|||||||
public:
|
public:
|
||||||
Handler();
|
Handler();
|
||||||
signals:
|
signals:
|
||||||
void createSessionSuccess();
|
void checkPeerSuccess();
|
||||||
private:
|
private:
|
||||||
Network *network;
|
Network *network;
|
||||||
void createSession(QJsonObject jsonReceived);
|
void createSession(QJsonObject jsonReceived);
|
||||||
std::map<QString, std::function<void(QJsonObject)>> handlers;
|
std::map<QString, std::function<void(QJsonObject)>> handlers;
|
||||||
void createSessionSuccessMethod(QJsonObject jsonReceived);
|
void checkPeerSuccessMethod(QJsonObject jsonReceived);
|
||||||
private slots:
|
private slots:
|
||||||
void handle(QJsonObject jsonReceived);
|
void handle(QJsonObject jsonReceived);
|
||||||
};
|
};
|
||||||
|
@ -10,7 +10,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
handler = new Handler();
|
handler = new Handler();
|
||||||
timer = new QTimer();
|
timer = new QTimer();
|
||||||
connect(timer, SIGNAL(timeout()), this, SLOT(slotTimerAlarm()));
|
connect(timer, SIGNAL(timeout()), this, SLOT(slotTimerAlarm()));
|
||||||
connect(handler, &Handler::createSessionSuccess, this, &MainWindow::peerReceiverConnected);
|
connect(handler, &Handler::checkPeerSuccessSuccess, this, &MainWindow::peerReceiverAvailable);
|
||||||
ui->myIP->setText(my_ipv6);
|
ui->myIP->setText(my_ipv6);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ void MainWindow::on_connectToPeer_clicked()
|
|||||||
ui->connectToPeer->setText("Ожидание...");
|
ui->connectToPeer->setText("Ожидание...");
|
||||||
QJsonObject j;
|
QJsonObject j;
|
||||||
j["peerID"] = my_ipv6;
|
j["peerID"] = my_ipv6;
|
||||||
j["action"] = "createSession";
|
j["action"] = "checkPeer";
|
||||||
QString s = ui->peerID->text();
|
QString s = ui->peerID->text();
|
||||||
network->sendDatagram(j, s);
|
network->sendDatagram(j, s);
|
||||||
timer->start(10000);
|
timer->start(10000);
|
||||||
@ -48,7 +48,7 @@ void MainWindow::slotTimerAlarm()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::peerReceiverConnected()
|
void MainWindow::peerReceiverAvailable()
|
||||||
{
|
{
|
||||||
receive = true;
|
receive = true;
|
||||||
int ret = QMessageBox::information(this,QObject::tr("Info"),tr("Peer Available!"));
|
int ret = QMessageBox::information(this,QObject::tr("Info"),tr("Peer Available!"));
|
||||||
|
@ -20,7 +20,7 @@ class MainWindow : public QMainWindow
|
|||||||
explicit MainWindow(QWidget *parent = 0);
|
explicit MainWindow(QWidget *parent = 0);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
public slots:
|
public slots:
|
||||||
void peerReceiverConnected();
|
void peerReceiverAvailable();
|
||||||
private slots:
|
private slots:
|
||||||
void on_connectToPeer_clicked();
|
void on_connectToPeer_clicked();
|
||||||
void slotTimerAlarm();
|
void slotTimerAlarm();
|
||||||
|
Loading…
Reference in New Issue
Block a user