Skip to content
This repository was archived by the owner on Mar 4, 2023. It is now read-only.

Commit 8506072

Browse files
committed
add optional IP logging to server
disabled by default
1 parent 553f295 commit 8506072

File tree

6 files changed

+35
-26
lines changed

6 files changed

+35
-26
lines changed

src/datasync/datatypestore.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ void DataTypeStore<TType, TKey>::evalDataChanged(int metaTypeId, const QString &
306306
emit dataChanged(key, QVariant::fromValue(_store->load<TType>(key)));
307307
}
308308
} catch(QException &e) {
309-
qWarning(QLoggingCategory{qUtf8Printable(QStringLiteral("qtdatasync.%1.DataTypeStore"))}) << "Failed to loaded changed data with error" << e.what(); //TODO arg setup name
309+
qWarning(QLoggingCategory{qUtf8Printable(QStringLiteral("qtdatasync.%1.DataTypeStore").arg(setupName()))})
310+
<< "Failed to loaded changed data with error" << e.what();
310311
}
311312
}
312313

@@ -439,7 +440,8 @@ void CachingDataTypeStore<TType, TKey>::evalDataChanged(int metaTypeId, const QS
439440
}
440441
}
441442
} catch(QException &e) {
442-
qWarning(QLoggingCategory{qUtf8Printable(QStringLiteral("qtdatasync.%1.CachingDataTypeStore"))}) << "Failed to loaded changed data with error" << e.what(); //TODO arg setup name
443+
qWarning(QLoggingCategory{qUtf8Printable(QStringLiteral("qtdatasync.%1.CachingDataTypeStore").arg(setupName()))})
444+
<< "Failed to loaded changed data with error" << e.what();
443445
}
444446
}
445447

@@ -599,7 +601,8 @@ void CachingDataTypeStore<TType*, TKey>::evalDataChanged(int metaTypeId, const Q
599601
}
600602
}
601603
} catch(QException &e) {
602-
qWarning(QLoggingCategory{qUtf8Printable(QStringLiteral("qtdatasync.%1.CachingDataTypeStore"))}) << "Failed to loaded changed data with error" << e.what(); //TODO arg setup name
604+
qWarning(QLoggingCategory{qUtf8Printable(QStringLiteral("qtdatasync.%1.CachingDataTypeStore").arg(setupName()))})
605+
<< "Failed to loaded changed data with error" << e.what();
603606
}
604607
}
605608

tests/auto/datasync/TestAppServer/qdsapp.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[general]
2+
logIpAddress=true
3+
14
[server]
25
host=localhost
36
port=14242

tests/auto/datasync/TestEventCursor/tst_eventcursor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void TestEventCursor::testAdvanceSkip()
180180
ObjectKey key;
181181
bool wasRemoved;
182182
std::tie(index, key, wasRemoved) = dataList.takeFirst();
183-
//TODO c++17: auto[index, key, wasRemoved] = dataList.takeFirst();
183+
//NOTE c++17: auto[index, key, wasRemoved] = dataList.takeFirst();
184184

185185
QCOMPARE(cursor->index(), index);
186186
QCOMPARE(cursor->key(), key);
@@ -220,7 +220,7 @@ void TestEventCursor::testScanLog()
220220
ObjectKey key;
221221
bool wasRemoved;
222222
std::tie(index, key, wasRemoved) = dataList.takeFirst();
223-
//TODO c++17: auto[index, key, wasRemoved] = dataList.takeFirst();
223+
//NOTE c++17: auto[index, key, wasRemoved] = dataList.takeFirst();
224224

225225
QCOMPARE(scanCursor, cursor);
226226
QCOMPARE(scanCursor->index(), index);

tools/appserver/client.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,16 @@ QThreadStorage<Client::Rng> Client::rngPool;
7777

7878
Client::Client(DatabaseController *database, QWebSocket *websocket, QObject *parent) :
7979
QObject(parent),
80-
_catStr(),
81-
_logCat(new QLoggingCategory("client.unknown")),
8280
_database(database),
8381
_socket(websocket),
84-
_idleTimer(nullptr),
85-
_uploadLimit(10),
86-
_downLimit(20),
87-
_downThreshold(10),
88-
_queue(new SingleTaskQueue(qService->threadPool(), this)),
89-
_state(Authenticating),
90-
_deviceId(),
91-
_loginNonce(),
92-
_cachedChanges(0),
93-
_activeDownloads()
82+
_queue(new SingleTaskQueue(qService->threadPool(), this))
9483
{
9584
_socket->setParent(this);
9685

86+
_logIp = qService->configuration()->value(QStringLiteral("logIpAddress"), _logIp).toBool();
87+
_catStr = catBaseStr() + "unknown";
88+
_logCat.reset(new QLoggingCategory(_catStr.constData()));
89+
9790
connect(_socket, &QWebSocket::disconnected,
9891
this, &Client::closeClient);
9992
connect(_socket, &QWebSocket::binaryMessageReceived,
@@ -328,6 +321,13 @@ void Client::run(const function<void ()> &fn)
328321
});
329322
}
330323

324+
QByteArray Client::catBaseStr() const
325+
{
326+
return _logIp ?
327+
QByteArray{"client.[" + _socket->peerAddress().toString().toUtf8() + "]."} :
328+
QByteArray{"client."};
329+
}
330+
331331
const QLoggingCategory &Client::logFn() const
332332
{
333333
return *_logCat;
@@ -395,7 +395,7 @@ void Client::onRegister(const RegisterMessage &message, QDataStream &stream)
395395
throw ClientErrorException(ErrorMessage::AuthenticationError);
396396
}
397397

398-
_catStr = "client." + _deviceId.toByteArray();
398+
_catStr = catBaseStr() + _deviceId.toByteArray();
399399
_logCat.reset(new QLoggingCategory(_catStr.constData()));
400400

401401
qDebug() << "Created new device and user accounts";
@@ -424,7 +424,7 @@ void Client::onLogin(const LoginMessage &message, QDataStream &stream)
424424
}
425425

426426
_deviceId = message.deviceId;
427-
_catStr = "client." + _deviceId.toByteArray();
427+
_catStr = catBaseStr() + _deviceId.toByteArray();
428428
_logCat.reset(new QLoggingCategory(_catStr.constData()));
429429

430430
_database->updateLogin(_deviceId, message.deviceName);
@@ -463,7 +463,7 @@ void Client::onAccess(const AccessMessage &message, QDataStream &stream)
463463
_deviceId = QUuid::createUuid(); //not stored yet!!!
464464
_cachedAccessRequest = message;
465465
//_cachedFingerPrint done inside of try/catch block
466-
_catStr = "client." + _deviceId.toByteArray();
466+
_catStr = catBaseStr() + _deviceId.toByteArray();
467467
_logCat.reset(new QLoggingCategory(_catStr.constData()));
468468

469469
qDebug() << "New Devices requested account access from" << message.partnerId;

tools/appserver/client.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,27 @@ private Q_SLOTS:
9494
QWebSocket *_socket; //must only be accessed from the main thread
9595

9696
// "constant" members, that wont change after the constructor
97-
QTimer *_idleTimer;
98-
quint32 _uploadLimit;
99-
quint32 _downLimit;
100-
quint32 _downThreshold;
97+
QTimer *_idleTimer = nullptr;
98+
quint32 _uploadLimit = 10;
99+
quint32 _downLimit = 20;
100+
quint32 _downThreshold = 10;
101+
bool _logIp = false;
101102

102103
// thread safe task queue, ensures only 1 task per client is run at the same time
103104
SingleTaskQueue *_queue;
104105

105106
//following members must only be accessed from within a task (to ensure thread safety)
106-
State _state;
107+
State _state = Authenticating;
107108
QUuid _deviceId;
108109
QByteArray _loginNonce;
109-
quint32 _cachedChanges;
110+
quint32 _cachedChanges = 0;
110111
QList<quint64> _activeDownloads;
111112
//cached:
112113
QtDataSync::AccessMessage _cachedAccessRequest;
113114
QByteArray _cachedFingerPrint;
114115

115116
void run(const std::function<void()> &fn);
117+
QByteArray catBaseStr() const;
116118
const QLoggingCategory &logFn() const;
117119

118120
template<typename TMessage>

tools/appserver/qdsapp.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ cleanup/auto=
77
quota/limit=
88
quota/force=
99
loglevel=
10+
logIpAddress=
1011

1112
[server]
1213
name=

0 commit comments

Comments
 (0)