Update package to packet

This commit is contained in:
Simon Stürz 2022-03-09 17:09:12 +01:00
parent 5d5f433b4f
commit 816111ddc7
7 changed files with 23 additions and 23 deletions

View File

@ -127,22 +127,22 @@ void ProxyClient::resetTimer()
QList<QByteArray> ProxyClient::processData(const QByteArray &data) QList<QByteArray> ProxyClient::processData(const QByteArray &data)
{ {
QList<QByteArray> packages; QList<QByteArray> packets;
// Handle packet fragmentation // Handle packet fragmentation
m_dataBuffer.append(data); m_dataBuffer.append(data);
int splitIndex = m_dataBuffer.indexOf("}\n{"); int splitIndex = m_dataBuffer.indexOf("}\n{");
while (splitIndex > -1) { while (splitIndex > -1) {
packages.append(m_dataBuffer.left(splitIndex + 1)); packets.append(m_dataBuffer.left(splitIndex + 1));
m_dataBuffer = m_dataBuffer.right(m_dataBuffer.length() - splitIndex - 2); m_dataBuffer = m_dataBuffer.right(m_dataBuffer.length() - splitIndex - 2);
splitIndex = m_dataBuffer.indexOf("}\n{"); splitIndex = m_dataBuffer.indexOf("}\n{");
} }
if (m_dataBuffer.trimmed().endsWith("}")) { if (m_dataBuffer.trimmed().endsWith("}")) {
packages.append(m_dataBuffer); packets.append(m_dataBuffer);
m_dataBuffer.clear(); m_dataBuffer.clear();
} }
return packages; return packets;
} }
QDebug operator<<(QDebug debug, ProxyClient *proxyClient) QDebug operator<<(QDebug debug, ProxyClient *proxyClient)

View File

@ -189,7 +189,7 @@ void JsonRpcServer::unregisterHandler(JsonHandler *handler)
m_handlers.remove(handler->name()); m_handlers.remove(handler->name());
} }
void JsonRpcServer::processDataPackage(TransportClient *transportClient, const QByteArray &data) void JsonRpcServer::processDataPacket(TransportClient *transportClient, const QByteArray &data)
{ {
QJsonParseError error; QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error); QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
@ -347,8 +347,8 @@ void JsonRpcServer::processData(TransportClient *transportClient, const QByteArr
qCDebug(dcJsonRpcTraffic()) << "Incoming data from" << transportClient << ": " << qUtf8Printable(data); qCDebug(dcJsonRpcTraffic()) << "Incoming data from" << transportClient << ": " << qUtf8Printable(data);
// Handle package fragmentation // Handle packet fragmentation
QList<QByteArray> packages = transportClient->processData(data); QList<QByteArray> packets = transportClient->processData(data);
// Make sure the buffer size is in range // Make sure the buffer size is in range
if (transportClient->bufferSize() > 1024 * 10) { if (transportClient->bufferSize() > 1024 * 10) {
@ -357,8 +357,8 @@ void JsonRpcServer::processData(TransportClient *transportClient, const QByteArr
return; return;
} }
foreach (const QByteArray &package, packages) { foreach (const QByteArray &packet, packets) {
processDataPackage(transportClient, package); processDataPacket(transportClient, packet);
} }
} }

View File

@ -74,7 +74,7 @@ private slots:
void asyncReplyFinished(); void asyncReplyFinished();
public slots: public slots:
void processDataPackage(TransportClient *transportClient, const QByteArray &data); void processDataPacket(TransportClient *transportClient, const QByteArray &data);
// Client registration for JSON RPC traffic // Client registration for JSON RPC traffic
void registerClient(TransportClient *transportClient); void registerClient(TransportClient *transportClient);

View File

@ -27,11 +27,11 @@ void TunnelProxyClient::setType(Type type)
QList<QByteArray> TunnelProxyClient::processData(const QByteArray &data) QList<QByteArray> TunnelProxyClient::processData(const QByteArray &data)
{ {
QList<QByteArray> packages; QList<QByteArray> packets;
// Parse packages depending on the encoded // Parse packets depending on the encoded
if (m_slipEnabled) { if (m_slipEnabled) {
// Read each byte until we get END byte, then unescape the package // Read each byte until we get END byte, then unescape the packet
for (int i = 0; i < data.length(); i++) { for (int i = 0; i < data.length(); i++) {
quint8 byte = static_cast<quint8>(data.at(i)); quint8 byte = static_cast<quint8>(data.at(i));
if (byte == SlipDataProcessor::ProtocolByteEnd) { if (byte == SlipDataProcessor::ProtocolByteEnd) {
@ -44,7 +44,7 @@ QList<QByteArray> TunnelProxyClient::processData(const QByteArray &data)
qCWarning(dcTunnelProxyServerTraffic()) << "Received inconsistant SLIP encoded message. Ignoring data..."; qCWarning(dcTunnelProxyServerTraffic()) << "Received inconsistant SLIP encoded message. Ignoring data...";
} else { } else {
qCDebug(dcTunnelProxyServerTraffic()) << "Frame received"; qCDebug(dcTunnelProxyServerTraffic()) << "Frame received";
packages.append(m_dataBuffer); packets.append(m_dataBuffer);
m_dataBuffer.clear(); m_dataBuffer.clear();
} }
} else { } else {
@ -56,17 +56,17 @@ QList<QByteArray> TunnelProxyClient::processData(const QByteArray &data)
m_dataBuffer.append(data); m_dataBuffer.append(data);
int splitIndex = m_dataBuffer.indexOf("}\n{"); int splitIndex = m_dataBuffer.indexOf("}\n{");
while (splitIndex > -1) { while (splitIndex > -1) {
packages.append(m_dataBuffer.left(splitIndex + 1)); packets.append(m_dataBuffer.left(splitIndex + 1));
m_dataBuffer = m_dataBuffer.right(m_dataBuffer.length() - splitIndex - 2); m_dataBuffer = m_dataBuffer.right(m_dataBuffer.length() - splitIndex - 2);
splitIndex = m_dataBuffer.indexOf("}\n{"); splitIndex = m_dataBuffer.indexOf("}\n{");
} }
if (m_dataBuffer.trimmed().endsWith("}")) { if (m_dataBuffer.trimmed().endsWith("}")) {
packages.append(m_dataBuffer); packets.append(m_dataBuffer);
m_dataBuffer.clear(); m_dataBuffer.clear();
} }
} }
return packages; return packets;
} }
QDebug operator<<(QDebug debug, TunnelProxyClient *tunnelProxyClient) QDebug operator<<(QDebug debug, TunnelProxyClient *tunnelProxyClient)

View File

@ -350,14 +350,14 @@ void TunnelProxyServer::onClientDataAvailable(const QUuid &clientId, const QByte
// Data coming from a connected server connection // Data coming from a connected server connection
if (tunnelProxyClient->slipEnabled()) { if (tunnelProxyClient->slipEnabled()) {
// Unpack SLIP data, get address, pipe to client or give it to the json rpc server if address 0x0000 // Unpack SLIP data, get address, pipe to client or give it to the json rpc server if address 0x0000
// Handle package fragmentation // Handle packet fragmentation
QList<QByteArray> frames = tunnelProxyClient->processData(data); QList<QByteArray> frames = tunnelProxyClient->processData(data);
foreach (const QByteArray &frameData, frames) { foreach (const QByteArray &frameData, frames) {
SlipDataProcessor::Frame frame = SlipDataProcessor::parseFrame(frameData); SlipDataProcessor::Frame frame = SlipDataProcessor::parseFrame(frameData);
if (frame.socketAddress == 0x0000) { if (frame.socketAddress == 0x0000) {
qCDebug(dcTunnelProxyServerTraffic()) << "Received frame for the JSON server" << tunnelProxyClient; qCDebug(dcTunnelProxyServerTraffic()) << "Received frame for the JSON server" << tunnelProxyClient;
m_jsonRpcServer->processDataPackage(tunnelProxyClient, frame.data); m_jsonRpcServer->processDataPacket(tunnelProxyClient, frame.data);
} else { } else {
// This data seems to be for a client with the given address // This data seems to be for a client with the given address
TunnelProxyServerConnection *serverConnection = m_tunnelProxyServerConnections.value(tunnelProxyClient->uuid()); TunnelProxyServerConnection *serverConnection = m_tunnelProxyServerConnections.value(tunnelProxyClient->uuid());

View File

@ -133,7 +133,7 @@ void JsonRpcClient::sendRequest(const QVariantMap &request, bool slipEnabled)
m_connection->sendData(data); m_connection->sendData(data);
} }
void JsonRpcClient::processDataPackage(const QByteArray &data) void JsonRpcClient::processDataPacket(const QByteArray &data)
{ {
QJsonParseError error; QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error); QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
@ -196,12 +196,12 @@ void JsonRpcClient::processData(const QByteArray &data)
m_dataBuffer.append(data); m_dataBuffer.append(data);
int splitIndex = m_dataBuffer.indexOf("}\n{"); int splitIndex = m_dataBuffer.indexOf("}\n{");
while (splitIndex > -1) { while (splitIndex > -1) {
processDataPackage(m_dataBuffer.left(splitIndex + 1)); processDataPacket(m_dataBuffer.left(splitIndex + 1));
m_dataBuffer = m_dataBuffer.right(m_dataBuffer.length() - splitIndex - 2); m_dataBuffer = m_dataBuffer.right(m_dataBuffer.length() - splitIndex - 2);
splitIndex = m_dataBuffer.indexOf("}\n{"); splitIndex = m_dataBuffer.indexOf("}\n{");
} }
if (m_dataBuffer.trimmed().endsWith("}")) { if (m_dataBuffer.trimmed().endsWith("}")) {
processDataPackage(m_dataBuffer); processDataPacket(m_dataBuffer);
m_dataBuffer.clear(); m_dataBuffer.clear();
} }
} }

View File

@ -68,7 +68,7 @@ private:
QHash<int, JsonReply *> m_replies; QHash<int, JsonReply *> m_replies;
void sendRequest(const QVariantMap &request, bool slipEnabled = false); void sendRequest(const QVariantMap &request, bool slipEnabled = false);
void processDataPackage(const QByteArray &data); void processDataPacket(const QByteArray &data);
signals: signals:
void tunnelEstablished(const QString clientName, const QString &clientUuid); void tunnelEstablished(const QString clientName, const QString &clientUuid);