ssl: Use QSslSocket directly to avoid redundant qobject_casts
[quassel.git] / src / core / metricsserver.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2020 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #pragma once
22
23 #include <QHash>
24 #include <QObject>
25 #include <QString>
26 #include <QTcpServer>
27
28 #include "coreidentity.h"
29
30 class MetricsServer : public QObject
31 {
32     Q_OBJECT
33
34 public:
35     explicit MetricsServer(QObject* parent = nullptr);
36
37     bool startListening();
38     void stopListening(const QString& msg);
39
40     void addLoginAttempt(UserId user, bool successful);
41     void addLoginAttempt(const QString& user, bool successful);
42
43     void addSession(UserId user, const QString& name);
44     void removeSession(UserId user);
45
46     void addClient(UserId user);
47     void removeClient(UserId user);
48
49     void addNetwork(UserId user);
50     void removeNetwork(UserId user);
51
52     void transmitDataNetwork(UserId user, uint64_t size);
53     void receiveDataNetwork(UserId user, uint64_t size);
54
55     void messageQueue(UserId user, uint64_t size);
56
57     void setCertificateExpires(QDateTime expires);
58
59 private slots:
60     void incomingConnection();
61     void respond();
62
63 private:
64     QTcpServer _server, _v6server;
65
66     QHash<UserId, uint64_t> _loginAttempts{};
67     QHash<UserId, uint64_t> _successfulLogins{};
68
69     QHash<UserId, QString> _sessions{};
70
71     QHash<UserId, int32_t> _clientSessions{};
72     QHash<UserId, int32_t> _networkSessions{};
73
74     QHash<UserId, uint64_t> _networkDataTransmit{};
75     QHash<UserId, uint64_t> _networkDataReceive{};
76
77     QHash<UserId, uint64_t> _messageQueue{};
78
79     QDateTime _certificateExpires{};
80 };