Commit 9af0bc34 authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

LanDeviceLink now uses readLine instead of readAll

parent fc45b643
...@@ -81,48 +81,37 @@ bool LanDeviceLink::sendPackage(NetworkPackage& np) ...@@ -81,48 +81,37 @@ bool LanDeviceLink::sendPackage(NetworkPackage& np)
void LanDeviceLink::dataReceived() void LanDeviceLink::dataReceived()
{ {
QByteArray data = mSocket->readAll();
//qDebug() << "LanDeviceLink dataReceived" << data; QByteArray package = mSocket->readLine();
QList<QByteArray> packages = data.split('\n');
Q_FOREACH(const QByteArray& package, packages) {
if (package.length() < 3) {
continue;
}
NetworkPackage unserialized(QString::null);
NetworkPackage::unserialize(package, &unserialized);
if (unserialized.isEncrypted()) {
//mPrivateKey should always be set when device link is added to device, no null-checking done here //qDebug() << "LanDeviceLink dataReceived" << data;
NetworkPackage decrypted(QString::null);
unserialized.decrypt(mPrivateKey, &decrypted);
if (decrypted.hasPayloadTransferInfo()) { NetworkPackage unserialized(QString::null);
qDebug() << "HasPayloadTransferInfo"; NetworkPackage::unserialize(package, &unserialized);
DownloadJob* job = new DownloadJob(mSocket->peerAddress(), decrypted.payloadTransferInfo()); if (unserialized.isEncrypted()) {
job->start();
decrypted.setPayload(job->getPayload(), decrypted.payloadSize());
}
Q_EMIT receivedPackage(decrypted); //mPrivateKey should always be set when device link is added to device, no null-checking done here
NetworkPackage decrypted(QString::null);
unserialized.decrypt(mPrivateKey, &decrypted);
} else { if (decrypted.hasPayloadTransferInfo()) {
qDebug() << "HasPayloadTransferInfo";
DownloadJob* job = new DownloadJob(mSocket->peerAddress(), decrypted.payloadTransferInfo());
job->start();
decrypted.setPayload(job->getPayload(), decrypted.payloadSize());
}
if (unserialized.hasPayloadTransferInfo()) { Q_EMIT receivedPackage(decrypted);
qWarning() << "Ignoring unencrypted payload";
continue;
}
Q_EMIT receivedPackage(unserialized); } else {
if (unserialized.hasPayloadTransferInfo()) {
qWarning() << "Ignoring unencrypted payload";
} }
} Q_EMIT receivedPackage(unserialized);
//qDebug() << "MOAR BYTES" << mSocket->bytesAvailable() << packages.length(); }
if (mSocket->bytesAvailable() > 0) { if (mSocket->bytesAvailable() > 0) {
QMetaObject::invokeMethod(this, "dataReceived", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "dataReceived", Qt::QueuedConnection);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment