-
Notifications
You must be signed in to change notification settings - Fork 1
/
abstractconnection_p.h
106 lines (97 loc) · 2.96 KB
/
abstractconnection_p.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/****************************************************************************
**
** Ireen — cross-platform OSCAR protocol library
**
** Copyright © 2012 Ruslan Nigmatullin <[email protected]>
** Alexey Prokhin <[email protected]>
**
*****************************************************************************
**
** $IREEN_BEGIN_LICENSE$
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as
** published by the Free Software Foundation, either version 3
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with this program. If not, see http://www.gnu.org/licenses/.
** $IREEN_END_LICENSE$
**
****************************************************************************/
#ifndef IREEN_CONNECTION_P_H
#define IREEN_CONNECTION_P_H
#include "abstractconnection.h"
#include "snac.h"
#include <QTimer>
#include <QDateTime>
#include <QQueue>
namespace Ireen {
#define MINIMIZE_RATE_MEMORY_USAGE 1
class ConnectionRate: public QObject
{
Q_OBJECT
public:
ConnectionRate(const SNAC &sn, AbstractConnection *conn);
virtual ~ConnectionRate() {}
void update(const SNAC &sn);
quint16 groupId() { return m_groupId; }
void send(const SNAC &snac, bool priority);
bool isEmpty() { return m_windowSize <= 1; }
bool testRate(bool priority);
bool startTimeout();
protected:
void timerEvent(QTimerEvent *event);
private:
void sendNextPackets();
quint32 getTimeDiff(const QDateTime &dateTime);
private:
quint16 m_groupId;
quint32 m_windowSize;
quint32 m_clearLevel;
quint32 m_currentLevel;
quint32 m_maxLevel;
quint32 m_lastTimeDiff;
#if !MINIMIZE_RATE_MEMORY_USAGE
quint32 m_alertLevel;
quint32 m_limitLevel;
quint32 m_disconnectLevel;
quint8 m_currentState;
#endif
QDateTime m_time;
QQueue<SNAC> m_lowPriorityQueue;
QQueue<SNAC> m_highPriorityQueue;
QBasicTimer m_timer;
quint32 m_defaultPriority;
AbstractConnection *m_conn;
};
class AbstractConnectionPrivate
{
public:
inline quint16 seqNum() { return seqnum++; }
inline quint32 nextId() { return id++; }
Socket *socket;
FLAP flap;
QMultiMap<quint32, SNACHandler*> handlers;
quint16 seqnum;
quint32 id;
ClientInfo clientInfo;
QHostAddress ext_ip;
QList<quint16> services;
QHash<quint16, ConnectionRate*> rates;
QHash<quint32, ConnectionRate*> ratesHash;
AbstractConnection::ConnectionError error;
QString errorStr;
AbstractConnection::State state;
QSet<SNACInfo> initSnacs; // Snacs that are allowed when initializing connection
QTimer aliveTimer;
private:
friend class AbstractConnection;
void init(AbstractConnection *q);
};
} // namespace Ireen
#endif //IREEN_CONNECTION_P_H