+void ClientSyncer::setWarningsHandler(const char *slot) {
+ resetWarningsHandler();
+ connect(this, SIGNAL(handleIgnoreWarnings(bool)), this, slot);
+}
+
+void ClientSyncer::resetWarningsHandler() {
+ disconnect(this, SIGNAL(handleIgnoreWarnings(bool)), this, 0);
+}
+
+void ClientSyncer::resetConnection() {
+ if(_socket) {
+ disconnect(_socket, 0, this, 0);
+ _socket->deleteLater();
+ _socket = 0;
+ }
+ _blockSize = 0;
+
+ coreConnectionInfo.clear();
+ _coreMsgBuffer.clear();
+
+ netsToSync.clear();
+ numNetsToSync = 0;
+}
+
+#ifdef HAVE_SSL
+void ClientSyncer::ignoreSslWarnings(bool permanently) {
+ QSslSocket *sock = qobject_cast<QSslSocket *>(_socket);
+ if(sock) {
+ // ensure that a proper state is displayed and no longer a warning
+ emit socketStateChanged(sock->state());
+ }
+ if(permanently) {
+ if(!sock)
+ qWarning() << Q_FUNC_INFO << "unable to save cert digest! Socket is either a nullptr or not a QSslSocket";
+ else
+ KnownHostsSettings().saveKnownHost(sock);
+ }
+ emit connectionMsg(_coreMsgBuffer["CoreInfo"].toString());
+ connectionReady();
+}
+
+void ClientSyncer::sslSocketEncrypted() {
+ QSslSocket *socket = qobject_cast<QSslSocket *>(sender());
+ Q_ASSERT(socket);
+
+ // if there were sslErrors we already had extensive error handling
+ // no need to check for a digest change again.
+ if(!socket->sslErrors().isEmpty())
+ return;
+
+ QByteArray knownDigest = KnownHostsSettings().knownDigest(socket);
+ if(knownDigest == socket->peerCertificate().digest()) {
+ connectionReady();
+ return;
+ }
+
+ QStringList warnings;
+ if(!knownDigest.isEmpty()) {
+ warnings << tr("Cert Digest changed! was: %1").arg(QString(prettyDigest(knownDigest)));
+ }
+
+ setWarningsHandler(SLOT(ignoreSslWarnings(bool)));
+ emit connectionWarnings(warnings);
+}
+