-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial audit logging, for review. #1006
base: master
Are you sure you want to change the base?
Changes from 4 commits
5d43fad
2fd3fb2
4707910
998616f
45a629d
4692b7e
b43bf9f
177a12d
d2a319b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// | ||
// EntitiesAuditLogging.cpp | ||
// libraries/entities/src | ||
// | ||
// Created by Kalila L on Feb 5 2021. | ||
// Copyright 2021 Vircadia contributors. | ||
// | ||
// Distributed under the Apache License, Version 2.0. | ||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | ||
// | ||
|
||
#include "EntitiesAuditLogging.h" | ||
|
||
#include <QJsonObject> | ||
#include <QTimer> | ||
|
||
Q_LOGGING_CATEGORY(entities_audit, "vircadia.entities.audit"); | ||
|
||
QJsonObject auditLogAddBuffer; | ||
QJsonObject auditLogEditBuffer; | ||
digisomni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
QTimer* auditLogProcessorTimer; | ||
digisomni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
void EntitiesAuditLogging::processAuditLogBuffers() { | ||
if (!auditLogAddBuffer.isEmpty()) { | ||
QJsonObject objectToOutput; | ||
objectToOutput.insert("add", auditLogAddBuffer); | ||
qCDebug(entities_audit) << objectToOutput; | ||
auditLogAddBuffer = QJsonObject(); | ||
} | ||
if (!auditLogEditBuffer.isEmpty()) { | ||
QJsonObject objectToOutput; | ||
objectToOutput.insert("edit", auditLogEditBuffer); | ||
qCDebug(entities_audit) << objectToOutput; | ||
auditLogEditBuffer = QJsonObject(); | ||
} | ||
} | ||
|
||
void EntitiesAuditLogging::startAuditLogProcessor() { | ||
auditLogProcessorTimer = new QTimer(this); | ||
digisomni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
connect(auditLogProcessorTimer, &QTimer::timeout, this, &EntitiesAuditLogging::processAuditLogBuffers); | ||
auditLogProcessorTimer->start(_auditEditLoggingInterval); | ||
} | ||
|
||
void EntitiesAuditLogging::stopAuditLogProcessor() { | ||
auditLogProcessorTimer->stop(); | ||
} | ||
|
||
bool EntitiesAuditLogging::isProcessorRunning() { | ||
if (!auditLogProcessorTimer) { | ||
digisomni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return false; | ||
} else { | ||
return true; | ||
} | ||
} | ||
|
||
void EntitiesAuditLogging::processAddEntityPacket(const QString& sender, const QString& entityID, const QString& entityType) { | ||
QJsonValue findExisting = auditLogAddBuffer.take(sender); | ||
if (!findExisting.isUndefined()) { | ||
QJsonObject existingObject = findExisting.toObject(); | ||
if (!existingObject.contains(entityID)) { | ||
existingObject.insert(entityID, entityType); | ||
} | ||
auditLogAddBuffer.insert(sender, existingObject); | ||
} else { | ||
QJsonObject newEntry{ { entityID, entityType } }; | ||
auditLogAddBuffer.insert(sender, newEntry); | ||
} | ||
} | ||
|
||
void EntitiesAuditLogging::processEditEntityPacket(const QString& sender, const QString& entityID) { | ||
QJsonValue findExisting = auditLogEditBuffer.take(sender); | ||
if (!findExisting.isUndefined()) { | ||
QJsonObject existingObject = findExisting.toObject(); | ||
if (!existingObject.contains(entityID)) { | ||
existingObject.insert(entityID, 1); | ||
} else { | ||
existingObject[entityID] = existingObject[entityID].toInt() + 1; | ||
} | ||
auditLogEditBuffer.insert(sender, existingObject); | ||
} else { | ||
QJsonObject newEntry{ { entityID, 1 } }; | ||
auditLogEditBuffer.insert(sender, newEntry); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing CR at EOF. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// EntitiesAuditLogging.h | ||
// libraries/entities/src | ||
// | ||
// Created by Kalila L on Feb 5 2021. | ||
// Copyright 2021 Vircadia contributors. | ||
// | ||
// Distributed under the Apache License, Version 2.0. | ||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | ||
// | ||
|
||
#ifndef vircadia_EntitiesAuditLogging_h | ||
#define vircadia_EntitiesAuditLogging_h | ||
|
||
#include <QLoggingCategory> | ||
|
||
Q_DECLARE_LOGGING_CATEGORY(entities_audit); | ||
|
||
class EntitiesAuditLogging : public QObject { | ||
Q_OBJECT | ||
public: | ||
bool isProcessorRunning(); | ||
void startAuditLogProcessor(); | ||
void stopAuditLogProcessor(); | ||
void setAuditEditLoggingInterval(float interval) { _auditEditLoggingInterval = interval; }; | ||
void processAddEntityPacket(const QString& sender, const QString& entityID, const QString& entityType); | ||
void processEditEntityPacket(const QString& sender, const QString& entityID); | ||
|
||
private: | ||
void processAuditLogBuffers(); | ||
|
||
float _auditEditLoggingInterval; | ||
}; | ||
|
||
#endif // vircadia_EntitiesAuditLogging_h |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,6 +14,6 @@ | |||||
|
||||||
#include <QLoggingCategory> | ||||||
|
||||||
Q_DECLARE_LOGGING_CATEGORY(entities) | ||||||
Q_DECLARE_LOGGING_CATEGORY(entities); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
#endif // hifi_EntitiesLogging_h |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -37,6 +37,7 @@ | |||||
#include "UpdateEntityOperator.h" | ||||||
#include "QVariantGLM.h" | ||||||
#include "EntitiesLogging.h" | ||||||
#include "EntitiesAuditLogging.h" | ||||||
#include "RecurseOctreeToMapOperator.h" | ||||||
#include "RecurseOctreeToJSONOperator.h" | ||||||
#include "LogHandler.h" | ||||||
|
@@ -45,6 +46,7 @@ | |||||
|
||||||
static const quint64 DELETED_ENTITIES_EXTRA_USECS_TO_CONSIDER = USECS_PER_MSEC * 50; | ||||||
const float EntityTree::DEFAULT_MAX_TMP_ENTITY_LIFETIME = 60 * 60; // 1 hour | ||||||
const float EntityTree::DEFAULT_AUDIT_EDIT_INTERVAL = 10000; // 10 seconds | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These names are unfortunately long. |
||||||
static const QString DOMAIN_UNLIMITED = "domainUnlimited"; | ||||||
|
||||||
EntityTree::EntityTree(bool shouldReaverage) : | ||||||
|
@@ -1795,6 +1797,10 @@ void EntityTree::processChallengeOwnershipPacket(ReceivedMessage& message, const | |||||
} | ||||||
} | ||||||
|
||||||
void EntityTree::setAuditEditLoggingInterval(float interval) { | ||||||
entitiesAuditLogProcessor.setAuditEditLoggingInterval(interval); | ||||||
} | ||||||
|
||||||
// NOTE: Caller must lock the tree before calling this. | ||||||
int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned char* editData, int maxLength, | ||||||
const SharedNodePointer& senderNode) { | ||||||
|
@@ -1803,6 +1809,10 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c | |||||
return 0; | ||||||
} | ||||||
|
||||||
if (wantAuditEditLogging() && !entitiesAuditLogProcessor.isProcessorRunning()) { | ||||||
entitiesAuditLogProcessor.startAuditLogProcessor(); | ||||||
} | ||||||
|
||||||
int processedBytes = 0; | ||||||
bool isAdd = false; | ||||||
bool isClone = false; | ||||||
|
@@ -1829,6 +1839,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c | |||||
quint64 startFilter = 0, endFilter = 0; | ||||||
quint64 startLogging = 0, endLogging = 0; | ||||||
|
||||||
|
||||||
bool suppressDisallowedClientScript = false; | ||||||
bool suppressDisallowedServerScript = false; | ||||||
bool suppressDisallowedPrivateUserData = false; | ||||||
|
@@ -2003,6 +2014,10 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c | |||||
qCDebug(entities) << "User [" << senderNode->getUUID() << "] editing entity. ID:" << entityItemID; | ||||||
qCDebug(entities) << " properties:" << properties; | ||||||
} | ||||||
if (wantAuditEditLogging()) { | ||||||
entitiesAuditLogProcessor.processEditEntityPacket(senderNode->getPublicSocket().toString(), | ||||||
entityItemID.toString()); | ||||||
Comment on lines
+2025
to
+2026
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indenting seems a bit arbitrary. |
||||||
} | ||||||
if (wantTerseEditLogging()) { | ||||||
QList<QString> changedProperties = properties.listChangedProperties(); | ||||||
fixupTerseEditLogging(properties, changedProperties); | ||||||
|
@@ -2082,6 +2097,11 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c | |||||
<< newEntity->getEntityItemID(); | ||||||
qCDebug(entities) << " properties:" << properties; | ||||||
} | ||||||
if (wantAuditEditLogging()) { | ||||||
entitiesAuditLogProcessor.processAddEntityPacket(senderNode->getPublicSocket().toString(), | ||||||
entityItemID.toString(), | ||||||
EntityTypes::getEntityTypeName(properties.getType())); | ||||||
Comment on lines
+2108
to
+2110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indenting seems a bit arbitrary. |
||||||
} | ||||||
if (wantTerseEditLogging()) { | ||||||
QList<QString> changedProperties = properties.listChangedProperties(); | ||||||
fixupTerseEditLogging(properties, changedProperties); | ||||||
|
@@ -2105,7 +2125,6 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c | |||||
} | ||||||
} | ||||||
|
||||||
|
||||||
_totalDecodeTime += endDecode - startDecode; | ||||||
_totalLookupTime += endLookup - startLookup; | ||||||
_totalUpdateTime += endUpdate - startUpdate; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.