2025-06-17 11:48:13 +08:00
|
|
|
#ifndef PROTOCOL_H
|
2025-06-13 23:14:57 +08:00
|
|
|
#define PROTOCOL_H
|
|
|
|
|
|
|
|
|
|
#include <QByteArray>
|
2025-06-25 10:54:04 +08:00
|
|
|
#include <QMetaType>
|
2025-06-13 23:14:57 +08:00
|
|
|
#include <QSharedPointer>
|
|
|
|
|
#include <QString>
|
2025-06-25 10:54:04 +08:00
|
|
|
#include <functional>
|
2025-06-13 23:14:57 +08:00
|
|
|
|
2025-11-09 11:53:59 +08:00
|
|
|
// 一帧包大小
|
|
|
|
|
constexpr quint32 CHUNK_BUF_SIZE = 1 * 1024 * 512;
|
|
|
|
|
// 流量背压倍率
|
|
|
|
|
constexpr quint32 FLOW_BACK_MULTIPLE = 50;
|
|
|
|
|
// 阻塞等级放大倍率
|
|
|
|
|
constexpr quint32 BLOCK_LEVEL_MULTIPLE = 5;
|
2025-11-15 17:26:09 +08:00
|
|
|
// 允许最大的无效数据包大小
|
|
|
|
|
constexpr quint32 MAX_INVALID_PACKET_SIZE = CHUNK_BUF_SIZE * 5;
|
2025-06-17 11:48:13 +08:00
|
|
|
|
2025-06-13 23:14:57 +08:00
|
|
|
// It is specified here that the first 30 contents (inclusive) are
|
|
|
|
|
// used for communication with the server.
|
|
|
|
|
// Contents beyond 30 are only forwarded.
|
|
|
|
|
enum FrameBufferType : uint16_t {
|
2025-06-17 16:42:39 +08:00
|
|
|
FBT_NONE = 0,
|
2025-06-25 17:06:30 +08:00
|
|
|
FBT_SER_MSG_HEARTBEAT,
|
2025-06-17 16:42:39 +08:00
|
|
|
FBT_SER_MSG_ASKCLIENTS,
|
2025-06-13 23:14:57 +08:00
|
|
|
FBT_SER_MSG_YOURID,
|
|
|
|
|
FBT_SER_MSG_RESPONSE,
|
|
|
|
|
FBT_SER_MSG_FORWARD_FAILED,
|
2025-06-25 17:06:30 +08:00
|
|
|
FBT_SER_MSG_JUDGE_OTHER_ALIVE,
|
|
|
|
|
FBT_SER_MSG_OFFLINE,
|
2025-11-09 11:53:59 +08:00
|
|
|
FBT_SER_FLOW_LIMIT,
|
2025-06-13 23:14:57 +08:00
|
|
|
FBT_CLI_BIN_FILEDATA = 31,
|
|
|
|
|
FBT_CLI_MSG_COMMUNICATE,
|
|
|
|
|
FBT_CLI_ASK_DIRFILE,
|
|
|
|
|
FBT_CLI_ANS_DIRFILE,
|
|
|
|
|
FBT_CLI_ASK_HOME,
|
2025-06-16 20:06:49 +08:00
|
|
|
FBT_CLI_ANS_HOME,
|
|
|
|
|
FBT_CLI_REQ_SEND,
|
2025-06-17 16:42:39 +08:00
|
|
|
FBT_CLI_CAN_SEND,
|
|
|
|
|
FBT_CLI_CANOT_SEND,
|
|
|
|
|
FBT_CLI_REQ_DOWN,
|
|
|
|
|
FBT_CLI_CAN_DOWN,
|
|
|
|
|
FBT_CLI_CANOT_DOWN,
|
|
|
|
|
FBT_CLI_FILE_BUFFER,
|
2025-06-17 11:48:13 +08:00
|
|
|
FBT_CLI_TRANS_DONE,
|
2025-06-20 09:45:39 +08:00
|
|
|
FBT_CLI_TRANS_FAILED,
|
2025-11-09 14:26:39 +08:00
|
|
|
FBT_CLI_TRANS_INTERRUPT,
|
2025-11-05 10:57:40 +08:00
|
|
|
FBT_CLI_FILE_INFO,
|
|
|
|
|
FBT_MSGINFO_ASK,
|
|
|
|
|
FBT_MSGINFO_ANSWER
|
2025-06-13 23:14:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct FrameBuffer {
|
|
|
|
|
QByteArray data;
|
|
|
|
|
QString fid;
|
|
|
|
|
QString tid;
|
2025-06-17 16:42:39 +08:00
|
|
|
FrameBufferType type = FBT_NONE;
|
2025-06-19 11:59:32 +08:00
|
|
|
bool sendRet;
|
2025-06-13 23:14:57 +08:00
|
|
|
};
|
|
|
|
|
|
2025-11-09 11:53:59 +08:00
|
|
|
// 拥堵等级,越高越堵
|
|
|
|
|
enum BlockLevel {
|
|
|
|
|
BL_LEVEL_NORMAL = 0,
|
|
|
|
|
BL_LEVEL_1 = 1,
|
|
|
|
|
BL_LEVEL_2 = 3,
|
|
|
|
|
BL_LEVEL_3 = 5,
|
|
|
|
|
BL_LEVEL_4 = 10,
|
|
|
|
|
BL_LEVEL_5 = 20,
|
|
|
|
|
BL_LEVEL_6 = 50,
|
|
|
|
|
BL_LEVEL_7 = 100,
|
|
|
|
|
BL_LEVEL_8 = 1000
|
|
|
|
|
};
|
|
|
|
|
|
2025-06-13 23:14:57 +08:00
|
|
|
class Protocol
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Protocol();
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
static QSharedPointer<FrameBuffer> ParseBuffer(QByteArray& buffer);
|
|
|
|
|
static QByteArray PackBuffer(const QSharedPointer<FrameBuffer>& frame);
|
|
|
|
|
};
|
|
|
|
|
|
2025-11-06 23:12:13 +08:00
|
|
|
enum FileCheckState {
|
|
|
|
|
FCS_NORMAL = 0,
|
|
|
|
|
FCS_DIR_NOT_EXIST,
|
2025-11-08 21:51:42 +08:00
|
|
|
FCS_FILE_NOT_EXIST,
|
|
|
|
|
FCS_FILE_EXIST
|
2025-11-06 23:12:13 +08:00
|
|
|
};
|
2025-11-05 23:09:37 +08:00
|
|
|
|
|
|
|
|
// 字符串标识
|
|
|
|
|
#define STRMSG_AC_CHECK_FILE_EXIST "requestCheckFileExist"
|
|
|
|
|
#define STRMSG_AC_ANSWER_FILE_EXIST "answerCheckFileExist"
|
2025-11-16 20:26:08 +08:00
|
|
|
#define STRMSG_AC_DEL_FILEDIR "requestDelFileDir"
|
|
|
|
|
#define STRMSG_AC_ANSWER_DEL_FILEDIR "answerDelFileDir"
|
2025-11-05 23:09:37 +08:00
|
|
|
#define STRMSG_AC_RENAME_FILEDIR "requestRenameFileDir"
|
2025-11-16 19:23:59 +08:00
|
|
|
#define STRMSG_AC_ANSWER_RENAME_FILEDIR "answerRenameFileDir"
|
2025-11-05 23:09:37 +08:00
|
|
|
#define STRMSG_AC_NEW_DIR "requestNewDir"
|
|
|
|
|
#define STRMSG_AC_ANSWER_NEW_DIR "answerNewDir"
|
|
|
|
|
#define STRMSG_AC_ASK_FILEINFO "requestFileInfo"
|
|
|
|
|
#define STRMSG_AC_ANSWER_FILEINFO "answerFileInfo"
|
2025-11-06 23:12:13 +08:00
|
|
|
#define STRMSG_AC_UP "upAction"
|
|
|
|
|
#define STRMSG_AC_DOWN "downAction"
|
2025-11-05 23:09:37 +08:00
|
|
|
|
|
|
|
|
#define STRMSG_ST_FILEEXIT "fileExist"
|
|
|
|
|
#define STRMSG_ST_FILENOEXIT "fileNotExist"
|
|
|
|
|
#define STRMSG_ST_DIREXIT "dirExist"
|
|
|
|
|
#define STRMSG_ST_DIRNOEXIT "dirNotExist"
|
|
|
|
|
|
2025-11-16 19:23:59 +08:00
|
|
|
#define STR_FILE "File"
|
|
|
|
|
#define STR_DIR "Dir"
|
|
|
|
|
#define STR_NONE "None"
|
|
|
|
|
|
2025-11-05 23:09:37 +08:00
|
|
|
#endif // PROTOCOL_H
|