ser:服务端接收大量无效数据时踢出客户端。
This commit is contained in:
@@ -30,10 +30,10 @@ int main(int argc, char* argv[])
|
||||
|
||||
frelayGUI w;
|
||||
|
||||
QFile file(":/QtTheme/theme/Flat/Light/Blue/Pink.qss");
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
a.setStyleSheet(file.readAll());
|
||||
}
|
||||
// QFile file(":/QtTheme/theme/Flat/Light/Blue/Pink.qss");
|
||||
// if (file.open(QFile::ReadOnly)) {
|
||||
// a.setStyleSheet(file.readAll());
|
||||
// }
|
||||
|
||||
QObject::connect(&a, &SingleApplication::instanceStarted, &w, [&w]() {
|
||||
w.showNormal();
|
||||
|
||||
@@ -13,6 +13,8 @@ constexpr quint32 CHUNK_BUF_SIZE = 1 * 1024 * 512;
|
||||
constexpr quint32 FLOW_BACK_MULTIPLE = 50;
|
||||
// 阻塞等级放大倍率
|
||||
constexpr quint32 BLOCK_LEVEL_MULTIPLE = 5;
|
||||
// 允许最大的无效数据包大小
|
||||
constexpr quint32 MAX_INVALID_PACKET_SIZE = CHUNK_BUF_SIZE * 5;
|
||||
|
||||
// It is specified here that the first 30 contents (inclusive) are
|
||||
// used for communication with the server.
|
||||
|
||||
@@ -103,6 +103,12 @@ void Server::onReadyRead()
|
||||
}
|
||||
|
||||
if (client) {
|
||||
if (client->buffer.size() > MAX_INVALID_PACKET_SIZE) {
|
||||
auto mg = QString("Client %1 buffer size exceeded, XXXXX...").arg(client->id);
|
||||
qWarning() << mg;
|
||||
socket->disconnectFromHost();
|
||||
return;
|
||||
}
|
||||
client->buffer.append(socket->readAll());
|
||||
processClientData(client);
|
||||
}
|
||||
@@ -143,7 +149,7 @@ bool Server::sendWithFlowCheck(QTcpSocket* fsoc, QTcpSocket* tsoc, QSharedPointe
|
||||
if (flowBackCount_[fsoc->property("clientId").toString()] > FLOW_BACK_MULTIPLE) {
|
||||
auto level = getBlockLevel(tsoc);
|
||||
flowLimit(fsoc, level);
|
||||
//qDebug() << "Flow back count exceeded, block level:" << level;
|
||||
// qDebug() << "Flow back count exceeded, block level:" << level;
|
||||
}
|
||||
flowBackCount_[fsoc->property("clientId").toString()]++;
|
||||
return sendData(tsoc, frame);
|
||||
|
||||
Reference in New Issue
Block a user