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;
|
||||
|
||||
handlers = {
|
||||
{"createSession", std::bind(&Handler::createSession, this, _1)},
|
||||
{"createSessionSuccess", std::bind(&Handler::createSessionSuccessMethod, this, _1)}
|
||||
{"checkPeer", std::bind(&Handler::createSession, this, _1)},
|
||||
{"checkPeerSuccess", std::bind(&Handler::checkPeerSuccessMethod, this, _1)}
|
||||
};
|
||||
network = new Network();
|
||||
connect(network, &Network::json_received, this, &Handler::handle);
|
||||
@ -23,12 +23,12 @@ void Handler::createSession(QJsonObject jsonReceived)
|
||||
{
|
||||
QJsonObject jsonSend;
|
||||
jsonSend["peerID"] = my_ipv6;
|
||||
jsonSend["action"] = "createSessionSuccess";
|
||||
jsonSend["action"] = "checkPeerSuccess";
|
||||
QString peerReceiver = jsonReceived["peerID"].toString();
|
||||
network->sendDatagram(jsonSend, peerReceiver);
|
||||
}
|
||||
|
||||
void Handler::createSessionSuccessMethod(QJsonObject jsonReceived)
|
||||
{
|
||||
emit createSessionSuccess();
|
||||
emit checkPeerSuccess();
|
||||
}
|
||||
|
@ -12,12 +12,12 @@ class Handler : public QObject
|
||||
public:
|
||||
Handler();
|
||||
signals:
|
||||
void createSessionSuccess();
|
||||
void checkPeerSuccess();
|
||||
private:
|
||||
Network *network;
|
||||
void createSession(QJsonObject jsonReceived);
|
||||
std::map<QString, std::function<void(QJsonObject)>> handlers;
|
||||
void createSessionSuccessMethod(QJsonObject jsonReceived);
|
||||
void checkPeerSuccessMethod(QJsonObject jsonReceived);
|
||||
private slots:
|
||||
void handle(QJsonObject jsonReceived);
|
||||
};
|
||||
|
@ -10,7 +10,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
handler = new Handler();
|
||||
timer = new QTimer();
|
||||
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);
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ void MainWindow::on_connectToPeer_clicked()
|
||||
ui->connectToPeer->setText("Ожидание...");
|
||||
QJsonObject j;
|
||||
j["peerID"] = my_ipv6;
|
||||
j["action"] = "createSession";
|
||||
j["action"] = "checkPeer";
|
||||
QString s = ui->peerID->text();
|
||||
network->sendDatagram(j, s);
|
||||
timer->start(10000);
|
||||
@ -48,7 +48,7 @@ void MainWindow::slotTimerAlarm()
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::peerReceiverConnected()
|
||||
void MainWindow::peerReceiverAvailable()
|
||||
{
|
||||
receive = true;
|
||||
int ret = QMessageBox::information(this,QObject::tr("Info"),tr("Peer Available!"));
|
||||
|
@ -20,7 +20,7 @@ class MainWindow : public QMainWindow
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
public slots:
|
||||
void peerReceiverConnected();
|
||||
void peerReceiverAvailable();
|
||||
private slots:
|
||||
void on_connectToPeer_clicked();
|
||||
void slotTimerAlarm();
|
||||
|
Loading…
Reference in New Issue
Block a user