Better logging of what's going on

This commit is contained in:
Albert Vaca 2016-03-07 16:01:44 -08:00
parent 8f9fde8f40
commit ff9775e1c9
3 changed files with 21 additions and 12 deletions

View file

@ -78,7 +78,7 @@ void LanLinkProvider::onStart()
bool success = mUdpServer->bind(bindAddress, port, QUdpSocket::ShareAddress); bool success = mUdpServer->bind(bindAddress, port, QUdpSocket::ShareAddress);
Q_ASSERT(success); Q_ASSERT(success);
qDebug() << "onStart"; qCDebug(KDECONNECT_CORE) << "onStart";
mTcpPort = port; mTcpPort = port;
while (!mServer->listen(bindAddress, mTcpPort)) { while (!mServer->listen(bindAddress, mTcpPort)) {
@ -95,7 +95,7 @@ void LanLinkProvider::onStart()
void LanLinkProvider::onStop() void LanLinkProvider::onStop()
{ {
qDebug() << "onStop"; qCDebug(KDECONNECT_CORE) << "onStop";
mUdpServer->close(); mUdpServer->close();
mServer->close(); mServer->close();
} }
@ -135,7 +135,7 @@ void LanLinkProvider::newUdpConnection() //udpBroadcastReceived
NetworkPackage* receivedPackage = new NetworkPackage(""); NetworkPackage* receivedPackage = new NetworkPackage("");
bool success = NetworkPackage::unserialize(datagram, receivedPackage); bool success = NetworkPackage::unserialize(datagram, receivedPackage);
//qDebug() << "udp connection from " << receivedPackage->; //qCDebug(KDECONNECT_CORE) << "udp connection from " << receivedPackage->;
qCDebug(KDECONNECT_CORE) << "Datagram " << datagram.data() ; qCDebug(KDECONNECT_CORE) << "Datagram " << datagram.data() ;
@ -219,14 +219,15 @@ void LanLinkProvider::connected()
QString certString = KdeConnectConfig::instance()->getDeviceProperty(deviceId, "certificate", QString()); QString certString = KdeConnectConfig::instance()->getDeviceProperty(deviceId, "certificate", QString());
if (!certString.isEmpty()) { if (!certString.isEmpty()) {
qDebug() << "Device trusted"; qCDebug(KDECONNECT_CORE) << "Device trusted";
socket->addCaCertificate(QSslCertificate(certString.toLatin1())); socket->addCaCertificate(QSslCertificate(certString.toLatin1()));
socket->setPeerVerifyMode(QSslSocket::VerifyPeer); socket->setPeerVerifyMode(QSslSocket::VerifyPeer);
connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>))); connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>)));
} else { } else {
qDebug() << "Device untrusted"; qCDebug(KDECONNECT_CORE) << "Device untrusted";
// Do not care about ssl errors here, socket will not be closed due to errors because of query peer // Do not care about ssl errors here, socket will not be closed due to errors because of query peer
socket->setPeerVerifyMode(QSslSocket::QueryPeer); socket->setPeerVerifyMode(QSslSocket::QueryPeer);
connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrorsLogButIgnore(QList<QSslError>)));
} }
qCDebug(KDECONNECT_CORE) << "Starting server ssl"; qCDebug(KDECONNECT_CORE) << "Starting server ssl";
connect(socket, SIGNAL(encrypted()), this, SLOT(encrypted())); connect(socket, SIGNAL(encrypted()), this, SLOT(encrypted()));
@ -252,8 +253,7 @@ void LanLinkProvider::connected()
void LanLinkProvider::encrypted() void LanLinkProvider::encrypted()
{ {
qCDebug(KDECONNECT_CORE) << "Socket succesfully stablished an SSL connection";
qCDebug(KDECONNECT_CORE) << "Socket encrypted";
QSslSocket* socket = qobject_cast<QSslSocket*>(sender()); QSslSocket* socket = qobject_cast<QSslSocket*>(sender());
if (!socket) return; if (!socket) return;
@ -306,7 +306,12 @@ void LanLinkProvider::sslErrors(const QList<QSslError>& errors)
// Socket disconnects itself on ssl error and will be deleted by deleteLater slot, no need to delete manually // Socket disconnects itself on ssl error and will be deleted by deleteLater slot, no need to delete manually
} }
void LanLinkProvider::sslErrorsLogButIgnore(const QList<QSslError>& errors)
{
foreach(const QSslError &error, errors) {
qCDebug(KDECONNECT_CORE) << "SSL Error (ignoring):" << error.errorString();
}
}
//I'm the new device and this is the answer to my UDP identity package (no data received yet) //I'm the new device and this is the answer to my UDP identity package (no data received yet)
void LanLinkProvider::newConnection() void LanLinkProvider::newConnection()
@ -362,15 +367,16 @@ void LanLinkProvider::dataReceived()
socket->setPeerVerifyName(deviceId); socket->setPeerVerifyName(deviceId);
if (isDeviceTrusted) { if (isDeviceTrusted) {
qDebug() << "Device trusted"; qCDebug(KDECONNECT_CORE) << "Device trusted";
QString certString = KdeConnectConfig::instance()->getDeviceProperty(deviceId, "certificate", QString()); QString certString = KdeConnectConfig::instance()->getDeviceProperty(deviceId, "certificate", QString());
socket->addCaCertificate(QSslCertificate(certString.toLatin1())); socket->addCaCertificate(QSslCertificate(certString.toLatin1()));
socket->setPeerVerifyMode(QSslSocket::VerifyPeer); socket->setPeerVerifyMode(QSslSocket::VerifyPeer);
connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>))); connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>)));
} else { } else {
qDebug() << "Device untrusted"; qCDebug(KDECONNECT_CORE) << "Device untrusted";
// Do not care about ssl errors here, socket will not be closed due to errors because of query peer // Do not care about ssl errors here, socket will not be closed due to errors because of query peer
socket->setPeerVerifyMode(QSslSocket::QueryPeer); socket->setPeerVerifyMode(QSslSocket::QueryPeer);
connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrorsLogButIgnore(QList<QSslError>)));
} }
qCDebug(KDECONNECT_CORE) << "Starting client ssl"; qCDebug(KDECONNECT_CORE) << "Starting client ssl";
connect(socket, SIGNAL(encrypted()), this, SLOT(encrypted())); connect(socket, SIGNAL(encrypted()), this, SLOT(encrypted()));
@ -409,7 +415,7 @@ void LanLinkProvider::configureSocket(QSslSocket* socket)
// Configure for ssl // Configure for ssl
socket->setLocalCertificate(KdeConnectConfig::instance()->certificate()); socket->setLocalCertificate(KdeConnectConfig::instance()->certificate());
socket->setPrivateKey(KdeConnectConfig::instance()->privateKeyPath()); socket->setPrivateKey(KdeConnectConfig::instance()->privateKeyPath());
socket->setProtocol(QSsl::TlsV1_0); socket->setProtocol(QSsl::AnyProtocol);
#ifdef TCP_KEEPIDLE #ifdef TCP_KEEPIDLE
// time to start sending keepalive packets (seconds) // time to start sending keepalive packets (seconds)
@ -462,7 +468,7 @@ LanPairingHandler* LanLinkProvider::createPairingHandler(DeviceLink* link)
LanPairingHandler* ph = mPairingHandlers.value(link->deviceId()); LanPairingHandler* ph = mPairingHandlers.value(link->deviceId());
if (!ph) { if (!ph) {
ph = new LanPairingHandler(link); ph = new LanPairingHandler(link);
qDebug() << "creating pairing handler for" << link->deviceId(); qCDebug(KDECONNECT_CORE) << "creating pairing handler for" << link->deviceId();
connect (ph, &LanPairingHandler::pairingError, link, &DeviceLink::pairingError); connect (ph, &LanPairingHandler::pairingError, link, &DeviceLink::pairingError);
mPairingHandlers[link->deviceId()] = ph; mPairingHandlers[link->deviceId()] = ph;
} }

View file

@ -62,6 +62,7 @@ private Q_SLOTS:
void dataReceived(); void dataReceived();
void deviceLinkDestroyed(QObject* destroyedDeviceLink); void deviceLinkDestroyed(QObject* destroyedDeviceLink);
void sslErrors(const QList<QSslError>& errors); void sslErrors(const QList<QSslError>& errors);
void sslErrorsLogButIgnore(const QList<QSslError>& errors);
private: private:
static void configureSocket(QSslSocket* socket); static void configureSocket(QSslSocket* socket);

View file

@ -113,6 +113,8 @@ void NotificationsDbusInterface::addNotification(Notification* noti)
removeNotification(internalId); removeNotification(internalId);
} }
qCDebug(KDECONNECT_PLUGIN_NOTIFICATION) << "addNotification" << internalId;
connect(noti, &Notification::dismissRequested, connect(noti, &Notification::dismissRequested,
this, &NotificationsDbusInterface::dismissRequested); this, &NotificationsDbusInterface::dismissRequested);