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)
void LanDeviceLink::dataReceived()
{
QByteArray data = mSocket->readAll();
//qDebug() << "LanDeviceLink dataReceived" << data;
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()) {
QByteArray package = mSocket->readLine();
//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);
//qDebug() << "LanDeviceLink dataReceived" << data;
if (decrypted.hasPayloadTransferInfo()) {
qDebug() << "HasPayloadTransferInfo";
DownloadJob* job = new DownloadJob(mSocket->peerAddress(), decrypted.payloadTransferInfo());
job->start();
decrypted.setPayload(job->getPayload(), decrypted.payloadSize());
}
NetworkPackage unserialized(QString::null);
NetworkPackage::unserialize(package, &unserialized);
if (unserialized.isEncrypted()) {
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()) {
qWarning() << "Ignoring unencrypted payload";
continue;
}
Q_EMIT receivedPackage(decrypted);
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) {
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