diff --git a/FunctionalClientTest/maindialog.cpp b/FunctionalClientTest/maindialog.cpp index 6dfaae3c6486a08f47ac066cdcefc441019d3aa0..414a124472ad34787423757a5188cb3c788f9a0a 100644 --- a/FunctionalClientTest/maindialog.cpp +++ b/FunctionalClientTest/maindialog.cpp @@ -136,6 +136,7 @@ void MainDialog::timerEvent(QTimerEvent * evt) EXAMPLE_HEARTBEATING * pMsg = (EXAMPLE_HEARTBEATING *)ptr; pMsg->Mark = 0xBEBE; pMsg->tmStamp = time(0)&0x00ffff; + pMsg->source_id = 0; //3/10 possibility to send a data block to server client->SendData(array); @@ -178,7 +179,7 @@ void MainDialog::on_pushButton_clientLogin_clicked() pMsg->data_length = nMsgLen; - pApp->header.MsgType = 0x3000; + pApp->header.MsgType = 0x0001; pApp->MsgUnion.msg_ClientLoginReq.user_id = userID; @@ -300,7 +301,7 @@ void MainDialog::on_pushButton_clientLogout_clicked() pMsg->data_length = nMsgLen; - pApp->header.MsgType = 0x3001; + pApp->header.MsgType = 0x1002; pApp->MsgUnion.msg_ClientLogoutReq.UserName[0] = 0; @@ -443,20 +444,28 @@ int MainDialog::deal_current_message_block() (ptr))+sizeof(EXAMPLE_TRANS_MSG)-1 ); - if (pApp->header.MsgType==0x3800) + if (pApp->header.MsgType==0x7FFE) { if (pApp->MsgUnion.msg_ClientLoginRsp.DoneCode==0) { m_bLogedIn = true; QMessageBox::information(this,tr("Succeed!"),tr("Log in succeed!")); } + else if (pApp->MsgUnion.msg_ClientLoginRsp.DoneCode==1) + { + m_bLogedIn = true; + QMessageBox::information(this,tr("Succeed!"),tr("But you can connect to another idle svr:%1:%2!") + .arg((const char *)pApp->MsgUnion.msg_ClientLoginRsp.Address_Redirect) + .arg(pApp->MsgUnion.msg_ClientLoginRsp.port_Redirect) + ); + } else - QMessageBox::information(this,tr("Failed!"),tr("Log in Failed!")); + QMessageBox::information(this,tr("Failed!"),tr("Log in failed!")); displayMessage(tr("Res = %1") - .arg(pApp->MsgUnion.msg_ClientLoginRsp.DoneCode) - ); + .arg(pApp->MsgUnion.msg_ClientLoginRsp.DoneCode) + ); } - else if (pApp->header.MsgType==0x1803) + else if (pApp->header.MsgType==0x7FFC) { if (pApp->MsgUnion.msg_UploadUserListRsp.DoneCode==0) QMessageBox::information(this,tr("Succeed!"),tr("upload succeed!")); @@ -467,7 +476,7 @@ int MainDialog::deal_current_message_block() ); } - else if (pApp->header.MsgType==0x1804) + else if (pApp->header.MsgType==0x7FFB) { if (pApp->MsgUnion.msg_DownloadUserListRsp.DoneCode==0) { @@ -486,7 +495,7 @@ int MainDialog::deal_current_message_block() ); } - else if (pApp->header.MsgType==0x3801) + else if (pApp->header.MsgType==0x7FFD) { if (pApp->MsgUnion.msg_ClientLogoutRsp.DoneCode==0) QMessageBox::information(this,tr("Succeed!"),tr("log out succeed!")); diff --git a/QTcpClientTest/qghtcpclient.cpp b/QTcpClientTest/qghtcpclient.cpp index 841fd7750c0ca23bd2e58faec4f0ef2bed67dbc7..dc4ed80eb29a284a2085880d4a58398a0ab2cf5a 100644 --- a/QTcpClientTest/qghtcpclient.cpp +++ b/QTcpClientTest/qghtcpclient.cpp @@ -1,16 +1,130 @@ #include "qghtcpclient.h" #include - -QGHTcpClient::QGHTcpClient(QObject *parent,int nPayLoad) +#include +#include +QGHSslClient::QGHSslClient(QObject *parent,int nPayLoad) : QSslSocket(parent), m_nPayLoad(nPayLoad) { assert(m_nPayLoad>=256 && m_nPayLoad<=16*1024*1024); connect(this, SIGNAL(bytesWritten(qint64)), this, SLOT(some_data_sended(qint64))); + m_uuid = 0; +} + +QGHSslClient::~QGHSslClient() +{ } +quint32 QGHSslClient::uuid() +{ + return m_uuid; +} +void QGHSslClient::geneGlobalUUID(const QString & globalUuidFile) +{ + QFile file(globalUuidFile); + int ctp = 0; + while (file.open(QIODevice::ReadWrite)==false) + { + ctp++; + if (ctp>=100) + { + this->disconnectFromHost(); + return ; + } + QThread::currentThread()->sleep(20); + } + file.seek(0); + quint32 oldUUID =1; + if (file.size()>=sizeof(oldUUID)) + file.read((char *)&oldUUID,sizeof(oldUUID)); + oldUUID ++; + this->m_uuid = oldUUID; + file.seek(0); + file.write((char *)&oldUUID,sizeof(oldUUID)); + file.flush(); + file.close(); + +} + +void QGHSslClient::some_data_sended(qint64 wsended) +{ + while (m_buffer_sending.empty()==false) + { + QByteArray & arraySending = *m_buffer_sending.begin(); + qint64 & currentOffset = *m_buffer_sending_offset.begin(); + qint64 nTotalBytes = arraySending.size(); + assert(nTotalBytes>=currentOffset); + qint64 nBytesWritten = write(arraySending.constData()+currentOffset,qMin((int)(nTotalBytes-currentOffset),m_nPayLoad)); + currentOffset += nBytesWritten; + if (currentOffset>=nTotalBytes) + { + m_buffer_sending.pop_front(); + m_buffer_sending_offset.pop_front(); + } + else + break; + } +} +void QGHSslClient::SendData(QByteArray dtarray) +{ + if (dtarray.size()) + { + if (m_buffer_sending.empty()==true) + { + qint64 bytesWritten = write(dtarray.constData(),qMin(dtarray.size(),m_nPayLoad)); + if (bytesWritten < dtarray.size()) + { + m_buffer_sending.push_back(dtarray); + m_buffer_sending_offset.push_back(bytesWritten); + } + } + else + { + m_buffer_sending.push_back(dtarray); + m_buffer_sending_offset.push_back(0); + } + } +} +QGHTcpClient::QGHTcpClient(QObject *parent,int nPayLoad) + : QTcpSocket(parent), + m_nPayLoad(nPayLoad) + +{ + assert(m_nPayLoad>=256 && m_nPayLoad<=16*1024*1024); + connect(this, SIGNAL(bytesWritten(qint64)), this, SLOT(some_data_sended(qint64))); + m_uuid = 0; +} +quint32 QGHTcpClient::uuid() +{ + return m_uuid; +} +void QGHTcpClient::geneGlobalUUID(const QString & globalUuidFile) +{ + QFile file(globalUuidFile); + int ctp = 0; + while (file.open(QIODevice::ReadWrite)==false) + { + ctp++; + if (ctp>=100) + { + this->disconnectFromHost(); + return ; + } + QThread::currentThread()->sleep(20); + } + file.seek(0); + quint32 oldUUID =1; + if (file.size()>=sizeof(oldUUID)) + file.read((char *)&oldUUID,sizeof(oldUUID)); + oldUUID ++; + this->m_uuid = oldUUID; + file.seek(0); + file.write((char *)&oldUUID,sizeof(oldUUID)); + file.flush(); + file.close(); +} QGHTcpClient::~QGHTcpClient() { diff --git a/QTcpClientTest/qghtcpclient.h b/QTcpClientTest/qghtcpclient.h index 7d3fa194e4dcd37661cfafdcc62943567ab24920..79547d26ebbbf1984172ae146849740b47c0132c 100644 --- a/QTcpClientTest/qghtcpclient.h +++ b/QTcpClientTest/qghtcpclient.h @@ -3,16 +3,39 @@ #include #include -class QGHTcpClient : public QSslSocket +class QGHSslClient : public QSslSocket +{ + Q_OBJECT + +public: + QGHSslClient(QObject *parent,int nPayLoad = 4096); + ~QGHSslClient(); + quint32 uuid(); + void geneGlobalUUID(const QString & globalUuidFile); +private: + + quint32 m_uuid; + int m_nPayLoad; + QList m_buffer_sending; + QList m_buffer_sending_offset; +public slots: + void some_data_sended(qint64); + void SendData(QByteArray dtarray); + +}; + +class QGHTcpClient : public QTcpSocket { Q_OBJECT public: QGHTcpClient(QObject *parent,int nPayLoad = 4096); ~QGHTcpClient(); - + quint32 uuid(); + void geneGlobalUUID(const QString & globalUuidFile); private: - int m_nPayLoad; + + quint32 m_uuid; int m_nPayLoad; QList m_buffer_sending; QList m_buffer_sending_offset; public slots: diff --git a/QTcpClientTest/qtcpclienttest.cpp b/QTcpClientTest/qtcpclienttest.cpp index 64f9f439e190cae3f351eac177c1745398c2637c..d1884b33db4f280f2b15671bdb956a12be9159ce 100644 --- a/QTcpClientTest/qtcpclienttest.cpp +++ b/QTcpClientTest/qtcpclienttest.cpp @@ -1,6 +1,7 @@ #include "qtcpclienttest.h" #include #include +#include #include "../ZoomPipeline_FuncSvr/smartlink/st_message.h" using namespace ExampleServer; QTcpClientTest::QTcpClientTest(QWidget *parent, Qt::WindowFlags flags) @@ -15,7 +16,11 @@ QTcpClientTest::QTcpClientTest(QWidget *parent, Qt::WindowFlags flags) ui.lcdNumber->display(settings.value("clientNum","32").toInt()); ui.horizontalSlider->setValue(settings.value("Payload","2048").toInt()); ui.label_load->setText(QString("Payload = %1").arg(settings.value("Payload","2048").toInt())); + ui.checkBox_SSL->setChecked(settings.value("SSL",false).toBool()); + ui.lineEdit_globalFile->setText(settings.value("globalFile","/zpserver_syn.debug").toString()); ui.listView_msg->setModel(&model); + m_maxUUID = 2; + m_minUUID = 0xffffffff; } QTcpClientTest::~QTcpClientTest() @@ -34,58 +39,121 @@ void QTcpClientTest::on_action_Connect_triggered(bool bConn) settings.setValue("port",ui.lineEdit_Port->text()); settings.setValue("clientNum",ui.dial->value()); settings.setValue("Payload",ui.horizontalSlider->value()); + settings.setValue("SSL",ui.checkBox_SSL->isChecked()); + settings.setValue("globalFile",ui.lineEdit_globalFile->text()); if (bConn==true) { nTimer = startTimer(100); + ui.dockWidget->setEnabled(false); } else + { killTimer(nTimer); + ui.dockWidget->setEnabled(true); + QList listObj = m_clients.keys(); + foreach(QTcpSocket * sock,listObj) + sock->disconnectFromHost(); + + } } void QTcpClientTest::on_client_trasferred(qint64 dtw) { - QGHTcpClient * pSock = qobject_cast(sender()); + if (dtw <= sizeof(EXAMPLE_HEARTBEATING)) + return; + QTcpSocket * pSock = qobject_cast(sender()); if (pSock) { - displayMessage(QString("client %1 Transferrd %2 bytes.").arg((quintptr)pSock).arg(dtw)); + QGHSslClient * pSockSsl = qobject_cast(sender()); + QGHTcpClient * pSockTcp = qobject_cast(sender()); + if (pSockSsl) + displayMessage(QString("client %1 Transferrd %2 bytes.").arg(pSockSsl->uuid()).arg(dtw)); + else if (pSockTcp) + displayMessage(QString("client %1 Transferrd %2 bytes.").arg(pSockTcp->uuid()).arg(dtw)); } } void QTcpClientTest::on_client_connected() { - QGHTcpClient * pSock = qobject_cast(sender()); - if (pSock) + QGHSslClient * pSockSsl = qobject_cast(sender()); + QGHTcpClient * pSockTcp = qobject_cast(sender()); + + if (pSockSsl) + { + pSockSsl->geneGlobalUUID(ui.lineEdit_globalFile->text()); + if (pSockSsl->uuid()>m_maxUUID) + m_maxUUID = pSockSsl->uuid(); + if (pSockSsl->uuid()uuid(); + + displayMessage(QString("client %1 connected.").arg(pSockSsl->uuid())); + QByteArray array(sizeof(EXAMPLE_HEARTBEATING),0); + char * ptr = array.data(); + EXAMPLE_HEARTBEATING * pMsg = (EXAMPLE_HEARTBEATING *)ptr; + pMsg->Mark = 0xBEBE; + pMsg->source_id = pSockSsl->uuid(); + pMsg->tmStamp = 0; + (pSockSsl)->SendData(array); + } + else if (pSockTcp) { - displayMessage(QString("client %1 connected.").arg((quintptr)pSock)); + pSockTcp->geneGlobalUUID(ui.lineEdit_globalFile->text()); + if (pSockTcp->uuid()>m_maxUUID) + m_maxUUID = pSockTcp->uuid(); + if (pSockTcp->uuid()uuid(); + + displayMessage(QString("client %1 connected.").arg(pSockTcp->uuid())); QByteArray array(sizeof(EXAMPLE_HEARTBEATING),0); char * ptr = array.data(); EXAMPLE_HEARTBEATING * pMsg = (EXAMPLE_HEARTBEATING *)ptr; pMsg->Mark = 0xBEBE; + pMsg->source_id = pSockTcp->uuid(); pMsg->tmStamp = 0; - (pSock)->SendData(array); + (pSockTcp)->SendData(array); } } void QTcpClientTest::on_client_disconnected() { - QGHTcpClient * pSock = qobject_cast(sender()); - if (pSock) + QGHSslClient * pSockSsl = qobject_cast(sender()); + QGHTcpClient * pSockTcp = qobject_cast(sender()); + if (pSockSsl) + { + displayMessage(QString("client %1 disconnected.").arg(pSockSsl->uuid())); + //disconnect the signal immediately so that the system resource could be freed. + disconnect(pSockSsl, SIGNAL(readyRead()),this, SLOT(new_data_recieved())); + disconnect(pSockSsl, SIGNAL(encrypted()),this, SLOT(on_client_connected())); + disconnect(pSockSsl, SIGNAL(disconnected()),this,SLOT(on_client_disconnected())); + disconnect(pSockSsl, SIGNAL(error(QAbstractSocket::SocketError)),this, SLOT(displayError(QAbstractSocket::SocketError))); + disconnect(pSockSsl, SIGNAL(bytesWritten(qint64)), this, SLOT(on_client_trasferred(qint64))); + m_clients.remove(pSockSsl); + pSockSsl->deleteLater(); + } + else if (pSockTcp) { - displayMessage(QString("client %1 disconnected.").arg((quintptr)pSock)); + displayMessage(QString("client %1 disconnected.").arg(pSockTcp->uuid())); //disconnect the signal immediately so that the system resource could be freed. - disconnect(pSock, SIGNAL(readyRead()),this, SLOT(new_data_recieved())); - disconnect(pSock, SIGNAL(connected()),this, SLOT(on_client_connected())); - disconnect(pSock, SIGNAL(disconnected()),this,SLOT(on_client_disconnected())); - disconnect(pSock, SIGNAL(error(QAbstractSocket::SocketError)),this, SLOT(displayError(QAbstractSocket::SocketError))); - disconnect(pSock, SIGNAL(bytesWritten(qint64)), this, SLOT(on_client_trasferred(qint64))); - m_clients.remove(pSock); - pSock->deleteLater(); + disconnect(pSockTcp, SIGNAL(readyRead()),this, SLOT(new_data_recieved())); + disconnect(pSockTcp, SIGNAL(connected()),this, SLOT(on_client_connected())); + disconnect(pSockTcp, SIGNAL(disconnected()),this,SLOT(on_client_disconnected())); + disconnect(pSockTcp, SIGNAL(error(QAbstractSocket::SocketError)),this, SLOT(displayError(QAbstractSocket::SocketError))); + disconnect(pSockTcp, SIGNAL(bytesWritten(qint64)), this, SLOT(on_client_trasferred(qint64))); + m_clients.remove(pSockTcp); + pSockTcp->deleteLater(); } } void QTcpClientTest::displayError(QAbstractSocket::SocketError /*err*/) { - QGHTcpClient * sock = qobject_cast (sender()); + QTcpSocket * sock = qobject_cast (sender()); if (sock) - displayMessage(QString("client %1 error msg:").arg((quintptr)sock)+sock->errorString()); + { + QGHSslClient * pSockSsl = qobject_cast(sock); + QGHTcpClient * pSockTcp = qobject_cast(sock); + if (pSockSsl) + displayMessage(QString("client %1 error msg:").arg(pSockSsl->uuid())+sock->errorString()); + else if (pSockTcp) + displayMessage(QString("client %1 error msg:").arg(pSockTcp->uuid())+sock->errorString()); + } } void QTcpClientTest::new_data_recieved() { @@ -93,8 +161,16 @@ void QTcpClientTest::new_data_recieved() if (pSock) { QByteArray array =pSock->readAll(); + if (array.size() <= sizeof(EXAMPLE_HEARTBEATING)) + return; //in this example, we just do nothing but to display the byte size. - displayMessage(QString("client %1 Recieved %2 bytes.").arg((quintptr)pSock).arg(array.size())); + QGHSslClient * pSockSsl = qobject_cast(pSock); + QGHTcpClient * pSockTcp = qobject_cast(pSock); + if (pSockSsl) + displayMessage(QString("client %1 Recieved %2 bytes.").arg(pSockSsl->uuid()).arg(array.size())); + else if (pSockTcp) + displayMessage(QString("client %1 Recieved %2 bytes.").arg(pSockTcp->uuid()).arg(array.size())); + } } @@ -105,43 +181,65 @@ void QTcpClientTest::timerEvent(QTimerEvent * evt) { int nTotalClients = ui.dial->value(); int nPayload = ui.horizontalSlider->value(); - QList listObj = m_clients.keys(); + QList listObj = m_clients.keys(); nCount++; if (nCount % 100 == 0) { //send heart-beating - foreach(QGHTcpClient * pSock,listObj) + foreach(QTcpSocket * pSock,listObj) { + quint32 uuid = 0; + QGHSslClient * pSockSsl = qobject_cast(pSock); + QGHTcpClient * pSockTcp = qobject_cast(pSock); + if (pSockSsl) + uuid = pSockSsl->uuid(); + else if (pSockTcp) + uuid = pSockTcp->uuid(); + else + continue; + QByteArray array(sizeof(EXAMPLE_HEARTBEATING),0); char * ptr = array.data(); EXAMPLE_HEARTBEATING * pMsg = (EXAMPLE_HEARTBEATING *)ptr; pMsg->Mark = 0xBEBE; + pMsg->source_id = uuid; pMsg->tmStamp = 0; - (pSock)->SendData(array); + if (pSockSsl) + pSockSsl->SendData(array); + else if (pSockTcp) + pSockTcp->SendData(array); } } - foreach(QGHTcpClient * sock,listObj) + foreach(QTcpSocket * sock,listObj) { - QGHTcpClient * sockDestin = listObj.at(rand() % listObj.size()); - - - if (rand()%1000<5) { + quint32 uuid = 0; + QGHSslClient * pSockSsl = qobject_cast(sock); + QGHTcpClient * pSockTcp = qobject_cast(sock); + if (pSockSsl) + uuid = pSockSsl->uuid(); + else if (pSockTcp) + uuid = pSockTcp->uuid(); + else + continue; quint16 nMsgLen = qrand()%(32)+nPayload-32-sizeof(EXAMPLE_TRANS_MSG); QByteArray array(sizeof(EXAMPLE_TRANS_MSG) + nMsgLen - 1,0); char * ptr = array.data(); EXAMPLE_TRANS_MSG * pMsg = (EXAMPLE_TRANS_MSG *)ptr; pMsg->Mark = 0x55AA; - pMsg->source_id = (quint32)((quint64)(sock) & 0xffffffff ); + pMsg->source_id = uuid; - pMsg->destin_id = (quint32)((quint64)(sockDestin) & 0xffffffff );; + pMsg->destin_id = getRadomUUIDDestin(); pMsg->data_length = nMsgLen; for (int i=0;idata[i] = '0' + i%10; - //3/10 possibility to send a data block to server - sock->SendData(array); + + if (pSockSsl) + pSockSsl->SendData(array); + else if (pSockTcp) + pSockTcp->SendData(array); } } // @@ -152,27 +250,39 @@ void QTcpClientTest::timerEvent(QTimerEvent * evt) if (m_clients.size()>nTotalClients) { int nDel = m_clients.size()-nTotalClients; - QList listObj = m_clients.keys(); + QList listObj = m_clients.keys(); for (int i=0;iabort(); } } - QGHTcpClient * client = new QGHTcpClient(this,ui.horizontalSlider->value()); - //client->connectToHost(ui.lineEdit_ip->text(),ui.lineEdit_Port->text().toUShort()); - m_clients[client] = QDateTime::currentDateTime(); - connect(client, SIGNAL(readyRead()),this, SLOT(new_data_recieved())); - //connect(client, SIGNAL(connected()),this, SLOT(on_client_connected())); - connect(client, SIGNAL(disconnected()),this,SLOT(on_client_disconnected())); - connect(client, SIGNAL(error(QAbstractSocket::SocketError)),this, SLOT(displayError(QAbstractSocket::SocketError))); - connect(client, SIGNAL(bytesWritten(qint64)), this, SLOT(on_client_trasferred(qint64))); - connect(client, SIGNAL(encrypted()), this, SLOT(on_client_connected())); - QString strCerPath = QCoreApplication::applicationDirPath() + "/ca_cert.pem"; - QList lstCas = QSslCertificate::fromPath(strCerPath); - client->setCaCertificates(lstCas); - //debug - //client->setPeerVerifyMode(QSslSocket::VerifyNone); - client->connectToHostEncrypted(ui.lineEdit_ip->text(),ui.lineEdit_Port->text().toUShort()); + if (ui.checkBox_SSL->isChecked()==true) + { + QGHSslClient * client = new QGHSslClient(this,ui.horizontalSlider->value()); + //client->connectToHost(ui.lineEdit_ip->text(),ui.lineEdit_Port->text().toUShort()); + m_clients[client] = QDateTime::currentDateTime(); + connect(client, SIGNAL(readyRead()),this, SLOT(new_data_recieved())); + //connect(client, SIGNAL(connected()),this, SLOT(on_client_connected())); + connect(client, SIGNAL(disconnected()),this,SLOT(on_client_disconnected())); + connect(client, SIGNAL(error(QAbstractSocket::SocketError)),this, SLOT(displayError(QAbstractSocket::SocketError))); + connect(client, SIGNAL(bytesWritten(qint64)), this, SLOT(on_client_trasferred(qint64))); + connect(client, SIGNAL(encrypted()), this, SLOT(on_client_connected())); + QString strCerPath = QCoreApplication::applicationDirPath() + "/ca_cert.pem"; + QList lstCas = QSslCertificate::fromPath(strCerPath); + client->setCaCertificates(lstCas); + client->connectToHostEncrypted(ui.lineEdit_ip->text(),ui.lineEdit_Port->text().toUShort()); + } + else + { + QGHTcpClient * client = new QGHTcpClient(this,ui.horizontalSlider->value()); + m_clients[client] = QDateTime::currentDateTime(); + connect(client, SIGNAL(readyRead()),this, SLOT(new_data_recieved())); + connect(client, SIGNAL(connected()),this, SLOT(on_client_connected())); + connect(client, SIGNAL(disconnected()),this,SLOT(on_client_disconnected())); + connect(client, SIGNAL(error(QAbstractSocket::SocketError)),this, SLOT(displayError(QAbstractSocket::SocketError))); + connect(client, SIGNAL(bytesWritten(qint64)), this, SLOT(on_client_trasferred(qint64))); + client->connectToHost(ui.lineEdit_ip->text(),ui.lineEdit_Port->text().toUShort()); + } } } } @@ -182,3 +292,18 @@ void QTcpClientTest::displayMessage(const QString &str) while (model.rowCount()>=256) model.removeRow(model.rowCount()-1); } +quint32 QTcpClientTest::getRadomUUIDDestin() +{ + int nTotalClients = ui.dial->value(); + int nMinID = m_maxUUID - m_minUUID < nTotalClients ? m_minUUID:m_maxUUID - nTotalClients; + int nSpan = (m_maxUUID - nMinID + 1); + int nChoose = rand() % nSpan; + + return nMinID + nChoose ; +} +void QTcpClientTest::on_toolButton_brFile_clicked() +{ + QString file = QFileDialog::getOpenFileName(this,tr("Open UUID global Syn File")); + if (file.length()>0) + ui.lineEdit_globalFile->setText(file); +} diff --git a/QTcpClientTest/qtcpclienttest.h b/QTcpClientTest/qtcpclienttest.h index 11bfaac14749f0528d6d868e835c84171fa4396b..87a88cb556b1a506785b82eb775a21fc81c8e4e7 100644 --- a/QTcpClientTest/qtcpclienttest.h +++ b/QTcpClientTest/qtcpclienttest.h @@ -17,13 +17,17 @@ public: ~QTcpClientTest(); virtual void timerEvent(QTimerEvent * evt); private: + quint32 m_maxUUID; + quint32 m_minUUID; + quint32 getRadomUUIDDestin(); Ui::QTcpClientTestClass ui; - QMap m_clients; + QMap m_clients; int nTimer; QStandardItemModel model; public slots: void on_horizontalSlider_valueChanged(int); void on_action_Connect_triggered(bool); + void on_toolButton_brFile_clicked(); void new_data_recieved(); void on_client_trasferred(qint64); void on_client_connected(); diff --git a/QTcpClientTest/qtcpclienttest.ui b/QTcpClientTest/qtcpclienttest.ui index 709ae935d851e73c1bed0429a2c8e062a9f0d13e..ee9135ecb025c1464e841fa78039557d2bdb395b 100644 --- a/QTcpClientTest/qtcpclienttest.ui +++ b/QTcpClientTest/qtcpclienttest.ui @@ -6,15 +6,15 @@ 0 0 - 600 - 400 + 647 + 482 QTcpClientTest - + @@ -38,8 +38,8 @@ 0 0 - 600 - 23 + 647 + 19 @@ -105,6 +105,34 @@ + + + + SSL(Need Certs) + + + + + + + Global UUID file + + + + + + + + + + + + ... + + + + + @@ -219,7 +247,7 @@ actionExit - activated() + triggered() QTcpClientTestClass close() diff --git a/ZoomPipeline_FuncSvr/cluster/cross_svr_messages.h b/ZoomPipeline_FuncSvr/cluster/cross_svr_messages.h index 9e4d4c2c23669fa75f323ba0b3f338f4e2787be0..5edbbc9575126ff687af31245a0d11d71b7b01bc 100644 --- a/ZoomPipeline_FuncSvr/cluster/cross_svr_messages.h +++ b/ZoomPipeline_FuncSvr/cluster/cross_svr_messages.h @@ -20,13 +20,17 @@ namespace ZP_Cluster{ struct tag_CSM_BasicInfo{ __UINT8_TYPE__ name [64]; - __UINT8_TYPE__ Address[64]; - __UINT16_TYPE__ port; + __UINT8_TYPE__ Address_LAN[64]; + __UINT16_TYPE__ port_LAN; + __UINT8_TYPE__ Address_Pub[64]; + __UINT16_TYPE__ port_Pub; } basicInfo; //msgType 0x01 struct tag_CSM_Broadcast{ __UINT8_TYPE__ name [64]; - __UINT8_TYPE__ Address[64]; - __UINT16_TYPE__ port; + __UINT8_TYPE__ Address_LAN[64]; + __UINT16_TYPE__ port_LAN; + __UINT8_TYPE__ Address_Pub[64]; + __UINT16_TYPE__ port_Pub; }broadcastMsg[1];//msgType 0x02 } payload; @@ -49,13 +53,17 @@ namespace ZP_Cluster{ } heartBeating; struct tag_CSM_BasicInfo{ unsigned __int8 name [64]; - unsigned __int8 Address[64]; - unsigned __int16 port; + unsigned __int8 Address_LAN[64]; + unsigned __int16 port_LAN; + unsigned __int8 Address_Pub[64]; + unsigned __int16 port_Pub; } basicInfo; struct tag_CSM_Broadcast{ unsigned __int8 name [64]; - unsigned __int8 Address[64]; - unsigned __int16 port; + unsigned __int8 Address_LAN[64]; + unsigned __int16 port_LAN; + unsigned __int8 Address_Pub[64]; + unsigned __int16 port_Pub; } broadcastMsg[1]; } payload; } CROSS_SVR_MSG; diff --git a/ZoomPipeline_FuncSvr/cluster/zp_clusternode.cpp b/ZoomPipeline_FuncSvr/cluster/zp_clusternode.cpp index 941d30714b92f40a4a47fef883f20757806827d6..6537a48f0f35f7ec485a44f5097efc7625c70aea 100644 --- a/ZoomPipeline_FuncSvr/cluster/zp_clusternode.cpp +++ b/ZoomPipeline_FuncSvr/cluster/zp_clusternode.cpp @@ -9,7 +9,7 @@ namespace ZP_Cluster{ { m_currentReadOffset = 0; m_currentMessageSize = 0; - m_nPortPublish = 0; + m_nPortLAN = m_nPortPub = 0; m_last_Report = QDateTime::currentDateTime(); m_nRemoteClientNums = 0; } @@ -26,14 +26,24 @@ namespace ZP_Cluster{ { return m_strTermName; } - QHostAddress zp_ClusterNode::addrPublish() + QHostAddress zp_ClusterNode::addrLAN() { - return m_addrPublish; + return m_addrLAN; } - int zp_ClusterNode::portPublish() + int zp_ClusterNode::portLAN() { - return m_nPortPublish; + return m_nPortLAN; } + + QHostAddress zp_ClusterNode::addrPub() + { + return m_addrPub; + } + int zp_ClusterNode::portPub() + { + return m_nPortPub; + } + QObject * zp_ClusterNode::sock() { return m_pSock; @@ -210,10 +220,11 @@ namespace ZP_Cluster{ } break; case 0x01://basicInfo, when connection established, this message should be used - if (m_currentBlock.length()>=64) - emit evt_Message(this,"Debug:" + m_currentBlock.toHex().left(64) + "..." + m_currentBlock.toHex().right(64)); - else - emit evt_Message(this,"Debug:" + m_currentBlock.toHex()); +// UnComment code below, will generate debug output. +// if (m_currentBlock.length()>=64) +// emit evt_Message(this,"Debug:" + m_currentBlock.toHex().left(64) + "..." + m_currentBlock.toHex().right(64)); +// else +// emit evt_Message(this,"Debug:" + m_currentBlock.toHex()); if (bytesLeft==0) { @@ -221,8 +232,10 @@ namespace ZP_Cluster{ if (strName != m_pTerm->name()) { this->m_strTermName = strName; - m_nPortPublish = pMsg->payload.basicInfo.port; - m_addrPublish = QHostAddress((const char *)pMsg->payload.basicInfo.Address); + m_nPortLAN = pMsg->payload.basicInfo.port_LAN; + m_addrLAN = QHostAddress((const char *)pMsg->payload.basicInfo.Address_LAN); + m_nPortPub = pMsg->payload.basicInfo.port_Pub; + m_addrPub = QHostAddress((const char *)pMsg->payload.basicInfo.Address_Pub); if (false==m_pTerm->regisitNewServer(this)) { this->m_strTermName.clear(); @@ -243,10 +256,11 @@ namespace ZP_Cluster{ } break; case 0x02: //Server - broadcast messages - if (m_currentBlock.length()>=64) - emit evt_Message(this,"Debug:" + m_currentBlock.toHex().left(64) + "..." + m_currentBlock.toHex().right(64)); - else - emit evt_Message(this,"Debug:" + m_currentBlock.toHex()); +// UnComment code below, will generate debug output. +// if (m_currentBlock.length()>=64) +// emit evt_Message(this,"Debug:" + m_currentBlock.toHex().left(64) + "..." + m_currentBlock.toHex().right(64)); +// else +// emit evt_Message(this,"Debug:" + m_currentBlock.toHex()); if (bytesLeft==0) { @@ -256,8 +270,8 @@ namespace ZP_Cluster{ QString strName ((const char *)pMsg->payload.broadcastMsg[i].name); if (strName != m_pTerm->name() && m_pTerm->SvrNodeFromName(strName)==NULL) { - QHostAddress addrToConnectTo((const char *)pMsg->payload.broadcastMsg[i].Address); - quint16 PortToConnectTo = pMsg->payload.broadcastMsg[i].port; + QHostAddress addrToConnectTo((const char *)pMsg->payload.broadcastMsg[i].Address_LAN); + quint16 PortToConnectTo = pMsg->payload.broadcastMsg[i].port_LAN; //because cross-connection is not good, we just want the low Addr:port connect to max Addr:Port. //Connect to New Servers if (strName > m_pTerm->name()) @@ -269,10 +283,11 @@ namespace ZP_Cluster{ } break; case 0x03: - if (m_currentBlock.length()>=64) - emit evt_Message(this,"Debug:" + m_currentBlock.toHex().left(64) + "..." + m_currentBlock.toHex().right(64)); - else - emit evt_Message(this,"Debug:" + m_currentBlock.toHex()); + // UnComment code below, will generate debug output. +// if (m_currentBlock.length()>=64) +// emit evt_Message(this,"Debug:" + m_currentBlock.toHex().left(64) + "..." + m_currentBlock.toHex().right(64)); +// else +// emit evt_Message(this,"Debug:" + m_currentBlock.toHex()); if (m_currentMessageSize==m_currentBlock.size()) { @@ -324,11 +339,17 @@ namespace ZP_Cluster{ strncpy((char *)(pMsg->payload.basicInfo.name), m_pTerm->name().toStdString().c_str(), sizeof(pMsg->payload.basicInfo.name)-1); - strncpy((char *)(pMsg->payload.basicInfo.Address), - m_pTerm->publishAddr().toString().toStdString().c_str(), - sizeof(pMsg->payload.basicInfo.Address)-1); + strncpy((char *)(pMsg->payload.basicInfo.Address_LAN), + m_pTerm->LANAddr().toString().toStdString().c_str(), + sizeof(pMsg->payload.basicInfo.Address_LAN)-1); + + pMsg->payload.basicInfo.port_LAN = m_pTerm->LANPort(); + + strncpy((char *)(pMsg->payload.basicInfo.Address_Pub), + m_pTerm->PublishAddr().toString().toStdString().c_str(), + sizeof(pMsg->payload.basicInfo.Address_Pub)-1); - pMsg->payload.basicInfo.port = m_pTerm->publishPort(); + pMsg->payload.basicInfo.port_Pub = m_pTerm->PublishPort(); emit evt_SendDataToClient(sock(),array); diff --git a/ZoomPipeline_FuncSvr/cluster/zp_clusternode.h b/ZoomPipeline_FuncSvr/cluster/zp_clusternode.h index 755d322797d70596ee1ebe8cee1a5f910aeb0b83..4ba82c8a636b81ac60a68895cdbd6c5e6e27ed63 100644 --- a/ZoomPipeline_FuncSvr/cluster/zp_clusternode.h +++ b/ZoomPipeline_FuncSvr/cluster/zp_clusternode.h @@ -39,8 +39,10 @@ namespace ZP_Cluster{ public: QString termName(); - QHostAddress addrPublish(); - int portPublish() ; + QHostAddress addrLAN(); + int portLAN() ; + QHostAddress addrPub(); + int portPub() ; QObject * sock() ; //!Messages @@ -53,9 +55,10 @@ namespace ZP_Cluster{ QObject * m_pSock; //the data members. QString m_strTermName; //the Terminal's name - QHostAddress m_addrPublish; //The publish address for other terms to connect to - int m_nPortPublish; //The publish port for other terms to connect to - + QHostAddress m_addrLAN; //The LAN address for other terms to connect to + int m_nPortLAN; //The LAN port for other terms to connect to + QHostAddress m_addrPub; //The Publish address for clients to connect to + int m_nPortPub; //The Publish port for clients to connect to //Data Process //The raw data queue and its mutex QList m_list_RawData; diff --git a/ZoomPipeline_FuncSvr/cluster/zp_clusterterm.cpp b/ZoomPipeline_FuncSvr/cluster/zp_clusterterm.cpp index a049c5fcd4ed815d30e2c252d7cf8c291bbb0e80..2b2126c84456594fcb0a83e97f88cdfc86e91c8f 100644 --- a/ZoomPipeline_FuncSvr/cluster/zp_clusterterm.cpp +++ b/ZoomPipeline_FuncSvr/cluster/zp_clusterterm.cpp @@ -17,7 +17,7 @@ namespace ZP_Cluster{ connect(m_pClusterNet,&ZPNetwork::zp_net_Engine::evt_ClientDisconnected, this,&zp_ClusterTerm::on_evt_ClientDisconnected,Qt::QueuedConnection); connect(m_pClusterNet,&ZPNetwork::zp_net_Engine::evt_NewClientConnected, this,&zp_ClusterTerm::on_evt_NewClientConnected,Qt::QueuedConnection); //connect(m_pClusterNet,&ZPNetwork::zp_net_Engine::evt_ClientEncrypted, this,&zp_ClusterTerm::on_evt_ClientEncrypted); - m_nPortPublish = 0; + m_nPortLAN = m_nPortPub = 0; m_nHeartBeatingTime = 20; m_factory = std::bind(&zp_ClusterTerm::default_factory,this,_1,_2,_3); } @@ -64,9 +64,38 @@ namespace ZP_Cluster{ m_factory = fac; } - int zp_ClusterTerm::publishPort(){ + int zp_ClusterTerm::LANPort(){ - return m_nPortPublish; + return m_nPortLAN; + } + QHostAddress zp_ClusterTerm::LANAddr() + { + return m_addrLAN; + } + QHostAddress zp_ClusterTerm::setLANAddr(QHostAddress addr) + { + return m_addrLAN = addr; + } + int zp_ClusterTerm::setLANPort(int port) + { + return m_nPortLAN = port; + } + + int zp_ClusterTerm::PublishPort(){ + + return m_nPortPub; + } + QHostAddress zp_ClusterTerm::PublishAddr() + { + return m_addrPub; + } + QHostAddress zp_ClusterTerm::setPublishAddr(QHostAddress addr) + { + return m_addrPub = addr; + } + int zp_ClusterTerm::setPublishPort(int port) + { + return m_nPortPub = port; } ZPNetwork::zp_net_Engine * zp_ClusterTerm::netEng() { @@ -84,18 +113,6 @@ namespace ZP_Cluster{ { return m_strTermName; } - QHostAddress zp_ClusterTerm::publishAddr() - { - return m_addrPublish; - } - QHostAddress zp_ClusterTerm::setPublishAddr(QHostAddress addr) - { - return m_addrPublish = addr; - } - int zp_ClusterTerm::setPublishPort(int port) - { - return m_nPortPublish = port; - } int zp_ClusterTerm::heartBeatingThrdHold() { return m_nHeartBeatingTime; @@ -130,25 +147,46 @@ namespace ZP_Cluster{ m_hash_mutex.unlock(); return lst; } - QHostAddress zp_ClusterTerm::SvrAddr(const QString & name) + QHostAddress zp_ClusterTerm::SvrLANAddr(const QString & name) { QHostAddress addr; m_hash_mutex.lock(); if (m_hash_Name2node.contains(name)) - addr = m_hash_Name2node[name]->addrPublish(); + addr = m_hash_Name2node[name]->addrLAN(); m_hash_mutex.unlock(); return addr; } - int zp_ClusterTerm::SvrPort(const QString & name) + int zp_ClusterTerm::SvrLANPort(const QString & name) { int port = 0; m_hash_mutex.lock(); if (m_hash_Name2node.contains(name)) - port = m_hash_Name2node[name]->portPublish(); + port = m_hash_Name2node[name]->portLAN(); m_hash_mutex.unlock(); return port; } + QHostAddress zp_ClusterTerm::SvrPubAddr(const QString & name) + { + QHostAddress addr; + m_hash_mutex.lock(); + if (m_hash_Name2node.contains(name)) + addr = m_hash_Name2node[name]->addrPub(); + m_hash_mutex.unlock(); + return addr; + } + + int zp_ClusterTerm::SvrPubPort(const QString & name) + { + int port = 0; + m_hash_mutex.lock(); + if (m_hash_Name2node.contains(name)) + port = m_hash_Name2node[name]->portPub(); + m_hash_mutex.unlock(); + return port; + } + + quint32 zp_ClusterTerm::remoteClientNums(const QString & name) { quint32 res = 0; @@ -392,20 +430,29 @@ namespace ZP_Cluster{ strncpy((char *)pMsg->payload.broadcastMsg[ct].name, pNode->termName().toStdString().c_str(), sizeof(pMsg->payload.broadcastMsg[ct].name)-1); - strncpy((char *)pMsg->payload.broadcastMsg[ct].Address, - pNode->addrPublish().toString().toStdString().c_str(), - sizeof(pMsg->payload.broadcastMsg[ct].Address)-1); - pMsg->payload.broadcastMsg[ct].port = pNode->portPublish(); + strncpy((char *)pMsg->payload.broadcastMsg[ct].Address_LAN, + pNode->addrLAN().toString().toStdString().c_str(), + sizeof(pMsg->payload.broadcastMsg[ct].Address_LAN)-1); + pMsg->payload.broadcastMsg[ct].port_LAN = pNode->portLAN(); + strncpy((char *)pMsg->payload.broadcastMsg[ct].Address_Pub, + pNode->addrPub().toString().toStdString().c_str(), + sizeof(pMsg->payload.broadcastMsg[ct].Address_Pub)-1); + pMsg->payload.broadcastMsg[ct].port_Pub = pNode->portPub(); + ++ct; } m_hash_mutex.unlock(); strncpy((char *)pMsg->payload.broadcastMsg[ct].name, this->name().toStdString().c_str(), sizeof(pMsg->payload.broadcastMsg[ct].name)-1); - strncpy((char *)pMsg->payload.broadcastMsg[ct].Address, - this->publishAddr().toString().toStdString().c_str(), - sizeof(pMsg->payload.broadcastMsg[ct].Address)-1); - pMsg->payload.broadcastMsg[ct].port = this->publishPort(); + strncpy((char *)pMsg->payload.broadcastMsg[ct].Address_LAN, + this->LANAddr().toString().toStdString().c_str(), + sizeof(pMsg->payload.broadcastMsg[ct].Address_LAN)-1); + pMsg->payload.broadcastMsg[ct].port_LAN = this->LANPort(); + strncpy((char *)pMsg->payload.broadcastMsg[ct].Address_Pub, + this->PublishAddr().toString().toStdString().c_str(), + sizeof(pMsg->payload.broadcastMsg[ct].Address_Pub)-1); + pMsg->payload.broadcastMsg[ct].port_Pub = this->PublishPort(); m_hash_mutex.lock(); QList sockkeys = m_hash_Name2node.keys(); //Msgs @@ -449,4 +496,46 @@ namespace ZP_Cluster{ netEng()->SendDataToClient(m_hash_Name2node[svrName]->sock(),array); m_hash_mutex.unlock(); } + + QString zp_ClusterTerm::minPayloadServer(quint8 bufAddresses[/*64*/],quint16 * pnPort) + { + QString serverName = this->name(); + strncpy((char *)bufAddresses + ,this->PublishAddr().toString().toStdString().c_str() + ,64); + *pnPort = this->PublishPort(); + m_hash_mutex.lock(); + QList keys = m_hash_Name2node.keys(); + int nsz = keys.size(); + if (nsz==0) + { + m_hash_mutex.unlock(); + return serverName; + } + //Msgs + int nMinVal = this->m_nClientNums; + zp_ClusterNode * pMinNode = 0; + int ct = 0; + foreach (QString key,keys) + { + zp_ClusterNode * pNode = m_hash_Name2node[key]; + if (pNode->clientNums() < nMinVal ) + { + nMinVal = pNode->clientNums(); + pMinNode = pNode; + } + ++ct; + } + if (pMinNode) + { + strncpy((char *)bufAddresses + ,pMinNode->addrPub().toString().toStdString().c_str() + ,64); + *pnPort = pMinNode->portPub(); + serverName = pMinNode->termName(); + } + m_hash_mutex.unlock(); + return serverName; + } + } diff --git a/ZoomPipeline_FuncSvr/cluster/zp_clusterterm.h b/ZoomPipeline_FuncSvr/cluster/zp_clusterterm.h index db3387afafa3046449f113647de7dfbf0da35baf..f17e2ce2e47f853cda50ab7ba8a9f3bb10ef1d5e 100644 --- a/ZoomPipeline_FuncSvr/cluster/zp_clusterterm.h +++ b/ZoomPipeline_FuncSvr/cluster/zp_clusterterm.h @@ -37,13 +37,43 @@ namespace ZP_Cluster{ ZPTaskEngine::zp_pipeline * taskEng(); bool canExit(); + //Server Group Mapping + public: + zp_ClusterNode * SvrNodeFromName(const QString &); + zp_ClusterNode * SvrNodeFromSocket(QObject *); + QStringList SvrNames(); + quint32 remoteClientNums(const QString & name); + + QHostAddress SvrLANAddr(const QString & name); + int SvrLANPort(const QString & name); + QHostAddress SvrPubAddr(const QString & name); + int SvrPubPort(const QString & name); + + + //Client Num set, for cross-svr balance + void setClientNums(quint32 nnum); + quint32 clientNums(); + //Propties + public: //properties. QString setName(const QString & s); QString name(); - QHostAddress publishAddr(); - int publishPort(); + + //LAN Address, for other servers + QHostAddress LANAddr(); + int LANPort(); + QHostAddress setLANAddr(QHostAddress addr); + int setLANPort(int port); + + //Publish Address, for clients. + QHostAddress PublishAddr(); + int PublishPort(); QHostAddress setPublishAddr(QHostAddress addr); int setPublishPort(int port); + + //Re-Direct Test. + QString minPayloadServer(quint8 bufAddresses[/*64*/],quint16 * pnPort); + int heartBeatingThrdHold() ; void setHeartBeatingThrd(const int n); bool regisitNewServer(zp_ClusterNode *); @@ -63,8 +93,10 @@ namespace ZP_Cluster{ int m_nHeartBeatingTime; quint32 m_nClientNums; //the clients this server now connected. QString m_strTermName;//the Terminal's name - QHostAddress m_addrPublish; //The publish address for other terms to connect to - int m_nPortPublish;//The publish port for other terms to connect to + QHostAddress m_addrLAN; //The LAN address for other server-terms to connect to + int m_nPortLAN;//The LAN port for other server-terms to connect to + QHostAddress m_addrPub; //The Publish address for clients to connect to + int m_nPortPub;//The Publish port for clients to connect to ZPNetwork::zp_net_Engine * m_pClusterNet; ZPTaskEngine::zp_pipeline * m_pClusterEng; //This list hold dead nodes that still in task queue,avoiding crash @@ -73,18 +105,6 @@ namespace ZP_Cluster{ QMutex m_hash_mutex; QMap m_hash_Name2node; QMap m_hash_sock2node; - //Server Group Mapping - public: - zp_ClusterNode * SvrNodeFromName(const QString &); - zp_ClusterNode * SvrNodeFromSocket(QObject *); - QStringList SvrNames(); - QHostAddress SvrAddr(const QString & name); - int SvrPort(const QString & name); - quint32 remoteClientNums(const QString & name); - //Client Num set, for cross-svr balance - void setClientNums(quint32 nnum); - quint32 clientNums(); - signals: void evt_Message(QObject * ,const QString &); diff --git a/ZoomPipeline_FuncSvr/network/zp_nettransthread.cpp b/ZoomPipeline_FuncSvr/network/zp_nettransthread.cpp index 7b1ac1847f9295b4d0455803d2ab820ce4181b5e..b76e2a7b2678cc71ed27f85f07fbea474a138abd 100644 --- a/ZoomPipeline_FuncSvr/network/zp_nettransthread.cpp +++ b/ZoomPipeline_FuncSvr/network/zp_nettransthread.cpp @@ -6,6 +6,14 @@ #include #include #include "zp_net_threadpool.h" +#include +//Trans st +QMutex g_mutex_sta; +quint64 g_bytesRecieved = 0; +quint64 g_bytesSent = 0; +quint64 g_secRecieved = 0; +quint64 g_secSent = 0; + namespace ZPNetwork{ zp_netTransThread::zp_netTransThread(zp_net_Engine *pThreadPool,int nPayLoad,QObject *parent) : QObject(parent) @@ -237,7 +245,15 @@ namespace ZPNetwork{ { QTcpSocket * pSock = qobject_cast(sender()); if (pSock) - emit evt_Data_recieved(pSock,pSock->readAll()); + { + QByteArray array = pSock->readAll(); + int sz = array.size(); + g_mutex_sta.lock(); + g_bytesRecieved +=sz; + g_secRecieved += sz; + g_mutex_sta.unlock(); + emit evt_Data_recieved(pSock,array); + } } /** * @brief this slot will be called when internal socket successfully @@ -248,6 +264,10 @@ namespace ZPNetwork{ */ void zp_netTransThread::some_data_sended(qint64 wsended) { + g_mutex_sta.lock(); + g_bytesSent +=wsended; + g_secSent += wsended; + g_mutex_sta.unlock(); QTcpSocket * pSock = qobject_cast(sender()); if (pSock) { diff --git a/ZoomPipeline_FuncSvr/smartlink/st_client_table.cpp b/ZoomPipeline_FuncSvr/smartlink/st_client_table.cpp index 690f1fb6c486ea69665b6f14e10ac41a427e854b..3802ac000f0926d66f79049e4b5ce8148b6f2693 100644 --- a/ZoomPipeline_FuncSvr/smartlink/st_client_table.cpp +++ b/ZoomPipeline_FuncSvr/smartlink/st_client_table.cpp @@ -18,7 +18,9 @@ namespace ExampleServer{ ,m_pTaskEngine(taskeng) ,m_pDatabaseRes(pDb) ,m_pCluster(pCluster) + ,m_nBalanceMax(1024) { + m_nHeartBeatingDeadThrd = 180; connect (m_pThreadEngine,&ZPNetwork::zp_net_Engine::evt_NewClientConnected,this,&st_client_table::on_evt_NewClientConnected,Qt::QueuedConnection); connect (m_pThreadEngine,&ZPNetwork::zp_net_Engine::evt_ClientEncrypted,this,&st_client_table::on_evt_ClientEncrypted,Qt::QueuedConnection); @@ -36,6 +38,16 @@ namespace ExampleServer{ _1,_2,_3) ); } + void st_client_table::setBalanceMax(int nmax) + { + m_nBalanceMax = nmax; + } + + int st_client_table::balanceMax() + { + return m_nBalanceMax; + } + int st_client_table::heartBeatingThrd() { @@ -332,7 +344,7 @@ namespace ExampleServer{ } } m_hash_mutex.unlock(); - emit evt_Message(this,tr("Recieved remote user-data to uuid:%1,DATA:%2").arg(uuid).arg(QString("HEX")+QString(msg.toHex()))); + //emit evt_Message(this,tr("Recieved remote user-data to uuid:%1,DATA:%2").arg(uuid).arg(QString("HEX")+QString(msg.toHex()))); return bres; } @@ -424,5 +436,16 @@ namespace ExampleServer{ m_mutex_cross_svr_map.unlock(); return svr; } + + bool st_client_table::NeedRedirect(quint8 bufAddresses[/*64*/],quint16 * pnPort) + { + if (m_pCluster->clientNums()minPayloadServer(bufAddresses,pnPort); + if (strServerName==m_pCluster->name()) + return false; + return true; + } + } diff --git a/ZoomPipeline_FuncSvr/smartlink/st_client_table.h b/ZoomPipeline_FuncSvr/smartlink/st_client_table.h index 17e9c9f801bebc5d661f13c6dc722e83ca737adf..082a1911a25702e4ec624c2bd4b56b6e37903d8c 100644 --- a/ZoomPipeline_FuncSvr/smartlink/st_client_table.h +++ b/ZoomPipeline_FuncSvr/smartlink/st_client_table.h @@ -56,6 +56,12 @@ namespace ExampleServer{ //Server Name find QString cross_svr_find_uuid(quint32 uuid); + //Cluster Global Balance + bool NeedRedirect(quint8 bufAddresses[/*64*/],quint16 * pnPort); + + void setBalanceMax(int nmax); + int balanceMax(); + protected: //This list hold dead nodes that still in task queue,avoiding crash QList m_nodeToBeDel; @@ -81,6 +87,9 @@ namespace ExampleServer{ QString m_strDBName_event; QString m_largeFileFolder; + //Cluster max balance value, when clients exceeds this val, balance will happen. + int m_nBalanceMax; + //cluster Nodes Map std::unordered_map m_hash_remoteClient2SvrName; QMutex m_mutex_cross_svr_map; diff --git a/ZoomPipeline_FuncSvr/smartlink/st_clientnode_app_imp.cpp b/ZoomPipeline_FuncSvr/smartlink/st_clientnode_app_imp.cpp index 1fb12c67ecb1bbf11d6ff78bc0932848c0fbaf8b..57365f9bacdce7217255db9420c0976c44e51ef7 100644 --- a/ZoomPipeline_FuncSvr/smartlink/st_clientnode_app_imp.cpp +++ b/ZoomPipeline_FuncSvr/smartlink/st_clientnode_app_imp.cpp @@ -41,7 +41,7 @@ namespace ExampleServer{ pMsg->data_length = nMsgLen; - pApp->header.MsgType = 0x3800; + pApp->header.MsgType = 0x7FFE; stMsg_ClientLoginRsp & reply = pApp->MsgUnion.msg_ClientLoginRsp; @@ -80,6 +80,11 @@ namespace ExampleServer{ { reply.DoneCode = 3; } + //Cluster-Balance. + if (m_pClientTable->NeedRedirect(reply.Address_Redirect,&reply.port_Redirect)) + { + reply.DoneCode = 1; + } } // else // strcpy(reply.TextInfo,"UserID Is Invalid.Accunt locked by svr"); @@ -111,7 +116,7 @@ namespace ExampleServer{ - return reply.DoneCode==0?true:false; + return reply.DoneCode==3?false:true; } bool st_clientNodeAppLayer::Box2Svr_UploadUserTable() { @@ -146,7 +151,7 @@ namespace ExampleServer{ pMsg->data_length = nMsgLen; - pApp->header.MsgType = 0x1803; + pApp->header.MsgType = 0x7FFC; stMsg_UploadUserListRsp & reply = pApp->MsgUnion.msg_UploadUserListRsp; @@ -209,7 +214,7 @@ namespace ExampleServer{ pMsg->data_length = nMsgLen; - pApp->header.MsgType = 0x1804; + pApp->header.MsgType = 0x7FFB; stMsg_DownloadUserListRsp & reply = pApp->MsgUnion.msg_DownloadUserListRsp; @@ -257,7 +262,7 @@ namespace ExampleServer{ pMsg->data_length = nMsgLen; - pApp->header.MsgType = 0x3801; + pApp->header.MsgType = 0x7FFD; stMsg_ClientLogoutRsp & reply = pApp->MsgUnion.msg_ClientLogoutRsp; diff --git a/ZoomPipeline_FuncSvr/smartlink/st_clientnode_applayer.cpp b/ZoomPipeline_FuncSvr/smartlink/st_clientnode_applayer.cpp index b3f0104d91e8a9b09422b77aa7dbf4d62422f07d..4a0a99a28eb9ad7655ce4610c9cc795261838d15 100644 --- a/ZoomPipeline_FuncSvr/smartlink/st_clientnode_applayer.cpp +++ b/ZoomPipeline_FuncSvr/smartlink/st_clientnode_applayer.cpp @@ -94,11 +94,11 @@ namespace ExampleServer{ int st_clientNodeAppLayer::deal_current_message_block() { //then , Start deal to-server messages - //Server - deal messages - if (m_currentBlock.length()>=64) - emit evt_Message(this,"Debug:" + m_currentBlock.toHex().left(64) + "..." + m_currentBlock.toHex().right(64)); - else - emit evt_Message(this,"Debug:" + m_currentBlock.toHex()); + //Uncomment these codes to enable debug msg dump. +// if (m_currentBlock.length()>=64) +// emit evt_Message(this,"Debug:" + m_currentBlock.toHex().left(64) + "..." + m_currentBlock.toHex().right(64)); +// else +// emit evt_Message(this,"Debug:" + m_currentBlock.toHex()); if (m_currentHeader.destin_id==0x00000001) { if (this->m_bLoggedIn==false || this->m_bUUIDRecieved==false) @@ -188,7 +188,7 @@ namespace ExampleServer{ //qDebug()<0) // message is not complete, return return true; @@ -267,7 +267,7 @@ namespace ExampleServer{ else res = this->Box2Svr_DownloadUserTable(); break; - case 0x3001: + case 0x1002: if (bytesLeft()>0) // message is not complete, return return true; diff --git a/ZoomPipeline_FuncSvr/smartlink/st_clientnode_applayer.h b/ZoomPipeline_FuncSvr/smartlink/st_clientnode_applayer.h index 3ab1d7623d60fac2eccbe026d0438fade8ecba7f..044682dbfb9ed7af9200b17a59bf953fd63daf12 100644 --- a/ZoomPipeline_FuncSvr/smartlink/st_clientnode_applayer.h +++ b/ZoomPipeline_FuncSvr/smartlink/st_clientnode_applayer.h @@ -22,15 +22,15 @@ namespace ExampleServer{ int deal_current_message_block(); //!Message Dealers, imp in st_clientnode_msgdeal.cpp bool Deal_ToServer_Handshakes(); - //0x3000<->0x3800 msg, stMsg_ClientLoginReq + //0x0001<->0x7FFE msg, stMsg_ClientLoginReq bool LoginClient(); //!Deal node2Svr Msgs bool Deal_Node2Svr_Msgs(); - //0x1003 - 0x1803 + //0x1003 - 0x7FFC bool Box2Svr_UploadUserTable(); - //0x1004 - 0x1804 + //0x1004 - 0x7FFB bool Box2Svr_DownloadUserTable(); - //0x3001 - 0x3801 + //0x1002 - 0x7FFD bool ClientLogout(); //data items protected: diff --git a/ZoomPipeline_FuncSvr/smartlink/st_clientnode_basetrans.cpp b/ZoomPipeline_FuncSvr/smartlink/st_clientnode_basetrans.cpp index 67484efa5284eeb0cf4b2f3b73fe43f6e7bb3955..57c0d364ff17776820d307c831bdc7479e90efff 100644 --- a/ZoomPipeline_FuncSvr/smartlink/st_clientnode_basetrans.cpp +++ b/ZoomPipeline_FuncSvr/smartlink/st_clientnode_basetrans.cpp @@ -137,6 +137,19 @@ namespace ExampleServer{ continue; //Send back emit evt_SendDataToClient(this->sock(),m_currentBlock); + //Try to Get UUID Immediately + if (m_bUUIDRecieved==false) + { + EXAMPLE_HEARTBEATING * pHbMsg = (EXAMPLE_HEARTBEATING *)(ptrCurrData); + if (bIsValidUserId(pHbMsg->source_id)) + { + m_bUUIDRecieved = true; + m_uuid = pHbMsg->source_id; + //regisit client node to hash-table; + m_pClientTable->regisitClientUUID(this); + } + } + //This Message is Over. Start a new one. m_currentMessageSize = 0; m_currentBlock = QByteArray(); @@ -243,12 +256,21 @@ namespace ExampleServer{ if (!( bIsValidUserId(m_currentHeader.source_id) || (m_currentHeader.source_id==0xffffffff) - )) + ) + ) { emit evt_Message(this,tr("Client ID is invalid! Close client immediatly.")); m_currentBlock = QByteArray(); emit evt_close_client(this->sock()); } + if (bIsValidUserId(m_currentHeader.source_id)==true && + m_uuid != m_currentHeader.source_id) + { + emit evt_Message(this,tr("Client ID Changed in Runtime! Close client immediatly.")); + m_currentBlock = QByteArray(); + emit evt_close_client(this->sock()); + } + } diff --git a/ZoomPipeline_FuncSvr/smartlink/st_message.h b/ZoomPipeline_FuncSvr/smartlink/st_message.h index 3c7decf7e3a1780494797d7bea27531811e3d716..d51643ed2e09f4ebf4568c4b6d0e8533ef98f616 100644 --- a/ZoomPipeline_FuncSvr/smartlink/st_message.h +++ b/ZoomPipeline_FuncSvr/smartlink/st_message.h @@ -21,6 +21,7 @@ namespace ExampleServer{ typedef struct tag_example_heartBeating { __UINT16_TYPE__ Mark; //Always be 0xBeBe + __UINT32_TYPE__ source_id ; //0xffffffff means from server __UINT16_TYPE__ tmStamp; } EXAMPLE_HEARTBEATING; #endif @@ -36,6 +37,7 @@ namespace ExampleServer{ typedef struct tag_example_heartBeating { unsigned __int16 Mark; //Always be 0xBeBe + unsigned __int32 source_id ; //0xffffffff means from server unsigned __int16 tmStamp; } EXAMPLE_HEARTBEATING; #endif diff --git a/ZoomPipeline_FuncSvr/smartlink/st_msg_applayer.h b/ZoomPipeline_FuncSvr/smartlink/st_msg_applayer.h index 3671eca268ff86c35f59ebd9e7fbce33950cb509..fce993d5233cde0a673b8de44a3b990c34315bb6 100644 --- a/ZoomPipeline_FuncSvr/smartlink/st_msg_applayer.h +++ b/ZoomPipeline_FuncSvr/smartlink/st_msg_applayer.h @@ -9,19 +9,31 @@ namespace ExampleServer{ #include //User Login request - //SMARTLINK_MSG_APP::MsgType = 0x3000 + //SMARTLINK_MSG_APP::MsgType = 0x0001 typedef struct tag_stMsg_ClientLoginReq{ __UINT32_TYPE__ user_id; char Passwd[1]; }stMsg_ClientLoginReq; //User Log response - //SMARTLINK_MSG_APP::MsgType = 0x3800 + //SMARTLINK_MSG_APP::MsgType = 0x7FFE typedef struct tag_stMsg_ClientLoginRsp{ __UINT8_TYPE__ DoneCode; __UINT32_TYPE__ UserID; + __UINT8_TYPE__ Address_Redirect[64];// for server-cluster balance, may be this login should be re-direct to another address + __UINT16_TYPE__ port_Redirect; // and a port num. } stMsg_ClientLoginRsp; + //0x1002 + typedef struct tag_stMsg_ClientLogoutReq{ + char UserName[1];//max 32 + }stMsg_ClientLogoutReq; + + //0x7FFD + typedef struct tag_stMsg_ClientLogoutRsp{ + __UINT8_TYPE__ DoneCode; + }stMsg_ClientLogoutRsp; + //UploadUserListReq,0x1003 typedef struct tag_stMsg_UploadUserListReq{ @@ -30,7 +42,7 @@ namespace ExampleServer{ }stMsg_UploadUserListReq; //User Log response - //SMARTLINK_MSG_APP::MsgType = 0x1803 + //SMARTLINK_MSG_APP::MsgType = 0x7FFC typedef struct tag_stMsg_UploadUserListRsp{ __UINT8_TYPE__ DoneCode; } stMsg_UploadUserListRsp; @@ -40,7 +52,7 @@ namespace ExampleServer{ } stMsg_DownloadUserListReq; - //SMARTLINK_MSG_APP::MsgType = 0x1804 + //SMARTLINK_MSG_APP::MsgType = 0x7FFB typedef struct tag_stMsg_DownloadUserListRsp{ __UINT8_TYPE__ DoneCode; __UINT16_TYPE__ UserNum; @@ -48,15 +60,7 @@ namespace ExampleServer{ } stMsg_DownloadUserListRsp; - //0x3001 - typedef struct tag_stMsg_ClientLogoutReq{ - char UserName[1];//max 32 - }stMsg_ClientLogoutReq; - //0x3801 - typedef struct tag_stMsg_ClientLogoutRsp{ - __UINT8_TYPE__ DoneCode; - }stMsg_ClientLogoutRsp; typedef struct tag_example_app_layer{ struct tag_app_layer_header{ @@ -80,19 +84,30 @@ namespace ExampleServer{ #if defined(_MSC_VER) //User Login request - //SMARTLINK_MSG_APP::MsgType = 0x3000 + //SMARTLINK_MSG_APP::MsgType = 0x0001 typedef struct tag_stMsg_ClientLoginReq{ unsigned __int32 user_id; char Passwd[1]; }stMsg_ClientLoginReq; //User Log response - //SMARTLINK_MSG_APP::MsgType = 0x3800 + //SMARTLINK_MSG_APP::MsgType = 0x7FFE typedef struct tag_stMsg_ClientLoginRsp{ - unsigned __int8 DoneCode; + unsigned __int8 DoneCode; //0- successful, 1-redirect, 3-failed. unsigned __int32 UserID; + unsigned __int8 Address_Redirect[64];// for server-cluster balance, may be this login should be re-direct to another address + unsigned __int16 port_Redirect; // and a port num. } stMsg_ClientLoginRsp; + //0x1002 + typedef struct tag_stMsg_ClientLogoutReq{ + char UserName[1];//max 32 + }stMsg_ClientLogoutReq; + + //0x7FFD + typedef struct tag_stMsg_ClientLogoutRsp{ + unsigned __int8 DoneCode; + }stMsg_ClientLogoutRsp; //UploadUserListReq,0x1003 typedef struct tag_stMsg_UploadUserListReq{ @@ -101,7 +116,7 @@ namespace ExampleServer{ }stMsg_UploadUserListReq; //User Log response - //SMARTLINK_MSG_APP::MsgType = 0x1803 + //SMARTLINK_MSG_APP::MsgType = 0x7FFC typedef struct tag_stMsg_UploadUserListRsp{ unsigned __int8 DoneCode; //char TextInfo[64]; @@ -113,22 +128,13 @@ namespace ExampleServer{ } stMsg_DownloadUserListReq; - //SMARTLINK_MSG_APP::MsgType = 0x1804 + //SMARTLINK_MSG_APP::MsgType = 0x7FFB typedef struct tag_stMsg_DownloadUserListRsp{ unsigned __int8 DoneCode; unsigned __int16 UserNum; unsigned __int32 pUserIDList[1]; } stMsg_DownloadUserListRsp; - //0x3001 - typedef struct tag_stMsg_ClientLogoutReq{ - char UserName[1];//max 32 - }stMsg_ClientLogoutReq; - - //0x3801 - typedef struct tag_stMsg_ClientLogoutRsp{ - unsigned __int8 DoneCode; - }stMsg_ClientLogoutRsp; typedef struct tag_example_app_layer{ diff --git a/ZoomPipeline_FuncSvr/zpmainframe.cpp b/ZoomPipeline_FuncSvr/zpmainframe.cpp index abcc5908f060ce7cfe2ba7dfe77b190dca414689..011fd6896b0e454c737aeb8b5364aefac2f25d49 100644 --- a/ZoomPipeline_FuncSvr/zpmainframe.cpp +++ b/ZoomPipeline_FuncSvr/zpmainframe.cpp @@ -14,9 +14,16 @@ using namespace ZPNetwork; using namespace ZPTaskEngine; using namespace ZP_Cluster; -ZPMainFrame::ZPMainFrame(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::ZPMainFrame) + +extern quint64 g_bytesRecieved; +extern quint64 g_bytesSent; +extern quint64 g_secRecieved; +extern quint64 g_secSent; + + +ZPMainFrame::ZPMainFrame(QWidget *parent) + :QMainWindow(parent) + ,ui(new Ui::ZPMainFrame) { m_currentConffile = QCoreApplication::applicationFilePath()+".ini"; ui->setupUi(this); @@ -142,12 +149,16 @@ void ZPMainFrame::initUI() ui->comboBox_db_type->setModel(pCombo); - m_pModelCluster= new QStandardItemModel(0,4,this); + m_pModelCluster= new QStandardItemModel(0,6,this); m_pModelCluster->setHeaderData(0,Qt::Horizontal,tr("Name")); - m_pModelCluster->setHeaderData(1,Qt::Horizontal,tr("Address")); - m_pModelCluster->setHeaderData(2,Qt::Horizontal,tr("Port")); + m_pModelCluster->setHeaderData(1,Qt::Horizontal,tr("LAN_Address")); + m_pModelCluster->setHeaderData(2,Qt::Horizontal,tr("LAN_Port")); m_pModelCluster->setHeaderData(3,Qt::Horizontal,tr("Clients")); + m_pModelCluster->setHeaderData(4,Qt::Horizontal,tr("Pub_Address")); + m_pModelCluster->setHeaderData(5,Qt::Horizontal,tr("Pub_Port")); ui->tableView_activeTerms->setModel(m_pModelCluster); + m_pStatusLabel = new QLabel(this); + this->statusBar()->addWidget(m_pStatusLabel); } void ZPMainFrame::on_evt_MessageNetwork(QObject * psource,const QString & strMsg) @@ -267,12 +278,17 @@ void ZPMainFrame::timerEvent(QTimerEvent * e) } //Cluster---------------------------- - str_msg += tr("Cluster Group Paras:\n"); - str_msg += tr("\tTerminal %1 : %2, published Address: %3:%4\n") + str_msg += tr("Cluster Paras:\n"); + str_msg += tr("\tTerminal %1 : %2\n\t\tLAN Address: %3:%4\n\t\t Publish: %5:%6\n\t\tbalance max clients=%7\n") .arg(m_pClusterTerm->name()) .arg(!m_pClusterTerm->netEng()->ListenerNames().empty()) - .arg(m_pClusterTerm->publishAddr().toString()) - .arg(m_pClusterTerm->publishPort()); + .arg(m_pClusterTerm->LANAddr().toString()) + .arg(m_pClusterTerm->LANPort()) + .arg(m_pClusterTerm->PublishAddr().toString()) + .arg(m_pClusterTerm->PublishPort()) + .arg(m_clientTable->balanceMax()) + ; + nClientThreads = m_pClusterTerm->netEng()->TransThreadNum(); str_msg += "\t"+tr("Trans Threads: %1\n").arg(nClientThreads); for (int i=0;iinsertRow(nInserted); m_pModelCluster->setData(m_pModelCluster->index(nInserted,0),this->m_pClusterTerm->name()); - m_pModelCluster->setData(m_pModelCluster->index(nInserted,1),m_pClusterTerm->publishAddr().toString()); - m_pModelCluster->setData(m_pModelCluster->index(nInserted,2),m_pClusterTerm->publishPort()); + m_pModelCluster->setData(m_pModelCluster->index(nInserted,1),m_pClusterTerm->LANAddr().toString()); + m_pModelCluster->setData(m_pModelCluster->index(nInserted,2),m_pClusterTerm->LANPort()); m_pModelCluster->setData(m_pModelCluster->index(nInserted,3),m_pClusterTerm->clientNums()); + m_pModelCluster->setData(m_pModelCluster->index(nInserted,4),m_pClusterTerm->PublishAddr().toString()); + m_pModelCluster->setData(m_pModelCluster->index(nInserted,5),m_pClusterTerm->PublishPort()); + ++nInserted; foreach (QString strNodeName,lstCluster) { m_pModelCluster->insertRow(nInserted); m_pModelCluster->setData(m_pModelCluster->index(nInserted,0),strNodeName); - m_pModelCluster->setData(m_pModelCluster->index(nInserted,1),m_pClusterTerm->SvrAddr(strNodeName).toString()); - m_pModelCluster->setData(m_pModelCluster->index(nInserted,2),m_pClusterTerm->SvrPort(strNodeName)); + m_pModelCluster->setData(m_pModelCluster->index(nInserted,1),m_pClusterTerm->SvrLANAddr(strNodeName).toString()); + m_pModelCluster->setData(m_pModelCluster->index(nInserted,2),m_pClusterTerm->SvrLANPort(strNodeName)); m_pModelCluster->setData(m_pModelCluster->index(nInserted,3),m_pClusterTerm->remoteClientNums(strNodeName)); + m_pModelCluster->setData(m_pModelCluster->index(nInserted,4),m_pClusterTerm->SvrPubAddr(strNodeName).toString()); + m_pModelCluster->setData(m_pModelCluster->index(nInserted,5),m_pClusterTerm->SvrPubPort(strNodeName)); ++nInserted; } + QString str = QDateTime::currentDateTime().toString(); + str += tr(" Rec %1B(%3 kbps) Sent %2B(%4 kbps)") + .arg(g_bytesRecieved) + .arg(g_bytesSent) + .arg(g_secRecieved*8/1024/2) + .arg(g_secSent*8/1024/2) + ; + g_secRecieved = g_secSent = 0; + m_pStatusLabel->setText(str); } else if (e->timerId()==m_nTimerCheck) { @@ -325,7 +355,6 @@ void ZPMainFrame::timerEvent(QTimerEvent * e) m_pClusterTerm->KickDeadClients(); m_nTimerCheck = startTimer(5000); } - } void ZPMainFrame::on_action_Start_Stop_triggered(bool setordel) { @@ -451,11 +480,14 @@ void ZPMainFrame::forkServer(const QString & config_file) QString strSL_LargetFolder = settings.value("Smartlink/SL_LargetFolder","NUL").toString(); m_clientTable->setLargeFileFolder(strSL_LargetFolder); - + int nmaxBalance = settings.value("Smartlink/nmaxBalance","1024").toInt(); + m_clientTable->setBalanceMax(nmaxBalance); //clusters QString strClusterTermAddr = settings.value("Cluster/strClusterTermAddr","0.0.0.0").toString(); QString strClusterTermPort = settings.value("Cluster/strClusterTermPort","25600").toString(); QString strClusterPubName = settings.value("Cluster/strClusterPubName","Term 001").toString(); + QString strClusterLANAddr = settings.value("Cluster/strClusterLANAddr","127.0.0.1").toString(); + QString strClusterLANPort = settings.value("Cluster/strClusterLANPort","25600").toString(); QString strClusterPubAddr = settings.value("Cluster/strClusterPubAddr","192.168.1.111").toString(); QString strClusterPubPort = settings.value("Cluster/strClusterPubPort","25600").toString(); int nClusterTransThreads = settings.value("Cluster/nClusterTransThreads","4").toInt(); @@ -471,6 +503,8 @@ void ZPMainFrame::forkServer(const QString & config_file) this->m_pClusterTerm->netEng()->AddClientTransThreads(nClusterTransThreads,false); this->m_pClusterTerm->taskEng()->addThreads(nClusterWorkingThreads); this->m_pClusterTerm->setName(strClusterPubName); + this->m_pClusterTerm->setLANAddr(QHostAddress(strClusterLANAddr)); + this->m_pClusterTerm->setLANPort(strClusterLANPort.toInt()); this->m_pClusterTerm->setPublishAddr(QHostAddress(strClusterPubAddr)); this->m_pClusterTerm->setPublishPort(strClusterPubPort.toInt()); this->m_pClusterTerm->StartListen(QHostAddress(strClusterTermAddr),strClusterTermPort.toInt()); @@ -577,8 +611,8 @@ void ZPMainFrame::LoadSettings(const QString & config_file) QString strSLDB_mainEvent = settings.value("Smartlink/SLDB_mainEvt","EMPTY").toString(); ui->lineEdit_SL_DB_ME->setText(strSLDB_mainEvent); - QString strSL_LargetFolder = settings.value("Smartlink/SL_LargetFolder","NUL").toString(); - ui->lineEdit_SL_LargetFolder->setText(strSL_LargetFolder); + int nmaxBalance = settings.value("Smartlink/nmaxBalance","1024").toInt(); + ui->spinBox_cluster_max_payload->setValue(nmaxBalance); //Cluster QString strClusterTermAddr = settings.value("Cluster/strClusterTermAddr","0.0.0.0").toString(); @@ -587,10 +621,17 @@ void ZPMainFrame::LoadSettings(const QString & config_file) ui->lineEdit_cluster_term_port->setText(strClusterTermPort); QString strClusterPubName = settings.value("Cluster/strClusterPubName","Term 001").toString(); ui->lineEdit_cluster_pub_name->setText(strClusterPubName); + QString strClusterLANAddr = settings.value("Cluster/strClusterLANAddr","127.0.0.1").toString(); + ui->lineEdit_cluster_LAN_Addr->setText(strClusterLANAddr); + QString strClusterLANPort = settings.value("Cluster/strClusterLANPort","25600").toString(); + ui->lineEdit_cluster_LAN_Port->setText(strClusterLANPort); + QString strClusterPubAddr = settings.value("Cluster/strClusterPubAddr","192.168.1.111").toString(); ui->lineEdit_cluster_pub_Addr->setText(strClusterPubAddr); QString strClusterPubPort = settings.value("Cluster/strClusterPubPort","25600").toString(); ui->lineEdit_cluster_pub_Port->setText(strClusterPubPort); + + int nClusterTransThreads = settings.value("Cluster/nClusterTransThreads","4").toInt(); ui->horizontalSlider_cluster_transThreads->setValue(nClusterTransThreads); int nClusterWorkingThreads = settings.value("Cluster/nClusterWorkingThreads","4").toInt(); @@ -665,13 +706,16 @@ void ZPMainFrame::SaveSettings(const QString & config_file) settings.setValue("Smartlink/SLDB_useracc",strSLDB_useracc); QString strSLDB_mainEvent = ui->lineEdit_SL_DB_ME->text(); settings.setValue("Smartlink/SLDB_mainEvt",strSLDB_mainEvent); - QString strSL_LargetFolder = ui->lineEdit_SL_LargetFolder->text(); - settings.setValue("Smartlink/SL_LargetFolder",strSL_LargetFolder); + int nmaxBalance = ui->spinBox_cluster_max_payload->value(); + settings.setValue("Smartlink/nmaxBalance",nmaxBalance); + //Cluster settings.setValue("Cluster/strClusterTermAddr",ui->lineEdit_cluster_term_addr->text()); settings.setValue("Cluster/strClusterTermPort",ui->lineEdit_cluster_term_port->text()); settings.setValue("Cluster/strClusterPubName", ui->lineEdit_cluster_pub_name->text()); + settings.setValue("Cluster/strClusterLANAddr",ui->lineEdit_cluster_LAN_Addr->text()); + settings.setValue("Cluster/strClusterLANPort",ui->lineEdit_cluster_LAN_Port->text()); settings.setValue("Cluster/strClusterPubAddr",ui->lineEdit_cluster_pub_Addr->text()); settings.setValue("Cluster/strClusterPubPort",ui->lineEdit_cluster_pub_Port->text()); settings.setValue("Cluster/nClusterTransThreads",ui->horizontalSlider_cluster_transThreads->value()); diff --git a/ZoomPipeline_FuncSvr/zpmainframe.h b/ZoomPipeline_FuncSvr/zpmainframe.h index 83883df16288c11665a11c6951dad3d584ae2cb3..aff131da73cad1e2226394094d4bbed05fe6b08b 100644 --- a/ZoomPipeline_FuncSvr/zpmainframe.h +++ b/ZoomPipeline_FuncSvr/zpmainframe.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include "network/zp_net_threadpool.h" @@ -47,6 +48,7 @@ protected: private: Ui::ZPMainFrame *ui; + QLabel * m_pStatusLabel; ZPNetwork::zp_net_Engine * m_netEngine; ZPTaskEngine::zp_pipeline * m_taskEngine; ExampleServer::st_client_table * m_clientTable; diff --git a/ZoomPipeline_FuncSvr/zpmainframe.ui b/ZoomPipeline_FuncSvr/zpmainframe.ui index 53e6ccd8122885b8291fce15edc0dad9f94234e7..07b7b5a761c348bb0d4760c7bd8d1586dd9476e9 100644 --- a/ZoomPipeline_FuncSvr/zpmainframe.ui +++ b/ZoomPipeline_FuncSvr/zpmainframe.ui @@ -525,6 +525,16 @@ + + + + Publish Name + + + + + + @@ -545,6 +555,19 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -637,22 +660,22 @@ - Publish Address + LAN Address - + - Publish Port + LAN Port - + @@ -667,19 +690,36 @@ + + + + &Save + + + - + - Publish Name + Publish Address - + + + + + + Publish Port + + + + + @@ -694,13 +734,6 @@ - - - - &Save - - - @@ -718,7 +751,7 @@ :/icons/Resources/Alienware (27).png:/icons/Resources/Alienware (27).png - Smartlink + Example Server @@ -800,19 +833,32 @@ - Large data root folder + Cluster balance max payload - + + + 1 + + + 16384 + + - - - ... + + + Qt::Horizontal - + + + 40 + 20 + + + @@ -949,7 +995,7 @@ 0 0 640 - 21 + 19