blob: f2d7396ef7bce5f60347c8a44eb3ebb58efaf305 (
plain)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/*
rateclass.h - Oscar Rate Limiting Implementation
Copyright (c) 2004 by Tom Linsky <twl6@po.cwru.edu>
Copyright (c) 2004 by Matt Rogers <mattr@k
Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
*************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
*************************************************************************
*/
#ifndef RATECLASS_H
#define RATECLASS_H
#include "oscartypes.h"
#include <tqobject.h>
#include <tqvaluelist.h>
#include <tqdatetime.h>
#include <tqpair.h>
const int RATE_SAFETY_TIME = 50;
struct SnacPair
{
int family;
int subtype;
};
class Transfer;
class RateClass : public TQObject
{
Q_OBJECT
public:
RateClass( TQObject* parent = 0 );
~RateClass();
/** Accessor for classid */
Oscar::WORD id() const;
/** Sets rate information */
void setRateInfo( Oscar::RateInfo newRateInfo );
/** Add a SNAC to the rate class */
void addMember( const Oscar::SNAC& s );
/** Adds rate class members */
void addMember( Oscar::WORD family, Oscar::WORD subtype );
/** Tells whether the passed snac is a member of this rate class */
bool isMember( const Oscar::SNAC& s ) const;
/**
* Tells whether the passed family and subtype combo is a member
* of this rate class
*/
bool isMember( Oscar::WORD family, Oscar::WORD subtype ) const;
/** Add a packet to the queue */
void enqueue( Transfer* );
/** Takes a packet off the front of the queue */
void dequeue();
/** Check if the queue is empty */
bool queueIsEmpty() const;
/**
* Calulate the time until we can send again
* Uses the first packet on the queue to determine the time since that's
* the packet that will get sent.
* \return the time in milliseconds that we need to wait
*/
int timeToNextSend();
/**
* Calulate the time until we get to initial level
* \return the time in milliseconds that we need to wait
*/
int timeToInitialLevel();
/**
* Calculates a new rate level and updates the rate class' current level
* to match
*/
void updateRateInfo();
/**
* Dump the current packet queue. These packets will not be sent. Used
* on disconnection
*/
void dumpQueue();
signals:
/** Tell the rate class manager we're ready to send */
void dataReady( Transfer* );
private:
/** Calculate our new rate level */
Oscar::DWORD calcNewLevel( int timeDifference ) const;
/** sets up the timer for the transfer just added to the queue */
void setupTimer();
private slots:
/**
* Send the packet. Basically emits dataReady for the first transfer
*/
void slotSend();
private:
Oscar::RateInfo m_rateInfo;
TQValueList<SnacPair> m_members;
TQValueList<Transfer*> m_packetQueue;
TQTime m_packetTimer;
// we are waiting for the TQTimer::singleShot() to send
bool m_waitingToSend;
};
#endif
|