-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrate_limits.html
312 lines (277 loc) · 10.1 KB
/
rate_limits.html
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<html>
<head>
<title>Rate-limits description</title>
<style type="text/css">
body {background-color: white; font-size: 13px;}
td {font-size: 16px;}
.corr {color:red;}
</style>
</head>
<body bgcolor=white>
<table width=640 bgcolor=darkblue cellSpacing=0 cellPadding=0 border=0><tr><td>
<table width=100% cellSpacing=2 cellPadding=0 border=0><tr><td bgcolor=#4040FF>
<table width=100% cellSpacing=0 cellPadding=0 border=0>
<tr>
<td><b><font color="white"> Rate-limits </font></b></td>
<td width=40% align=right><b><font color="white"> </font></b></td>
</tr>
</table>
</td></tr>
</table>
</td></tr></table>
<br>
<table width=640 cellSpacing=0 cellPadding=0 border=0>
<tr>
<td>
<table width=640 bgcolor=darkblue cellSpacing=0 cellPadding=0 border=0><tr><td>
<table width=100% cellSpacing=2 cellPadding=0 border=0><tr><td bgcolor=#E9E9E9 >
<table width=100% cellSpacing=0 cellPadding=0 border=0>
<tr><td width=5> </td>
<td><br>
Rate limits is a way to control client->server data flow. This is done
by calculating rate level on every client snac. If client rate goes above alert
server send warning, if it goes above limit server send warning and drop
snacs from client, if it goes above disconnect level client disconnected from
server and can't connect again for some time.<br>
At some point in the logon sequence the client should send
<a href="snac_01_06.html">SNAC(01,06)</a> which is the "rate request" packet.
In reply, the server will send the "rate response"
<a href="snac_01_07.html">SNAC(01,07)</a> which contain rate limit parameters
formatted as follows:
<br><br>
First comes a word value telling you how many rate classes there are.
Then for each class you get a structure like this:<br><br>
<table width=100% cellSpacing=0 cellPadding=0 align=center border=0>
<tr><td width=20></td><td>
<table width=400 bgcolor=darkgreen cellSpacing=0 cellPadding=0 border=0><tr><td>
<table width=100% cellSpacing=2 cellPadding=0 border=0><tr><td bgcolor=#FAFAFA>
<table width=400 cellSpacing=0 cellPadding=0 align=center border=0>
<tr>
<td width=28%> xx xx</td>
<td width=5> </td>
<td>word</td>
<td width=5> </td>
<td width=55%>Rate class ID</td>
</tr>
</table>
</td></tr>
<tr><td bgcolor=#FAFAFA>
<table width=400 cellSpacing=0 cellPadding=0 align=center border=0>
<tr>
<td> xx xx xx xx</td>
<td width=5> </td>
<td>dword</td>
<td width=5> </td>
<td width=55%>Window size</td>
</tr>
<tr>
<td> xx xx xx xx</td>
<td width=5> </td>
<td>dword</td>
<td width=5> </td>
<td width=55%>Clear level</td>
</tr>
<tr>
<td> xx xx xx xx</td>
<td width=5> </td>
<td>dword</td>
<td width=5> </td>
<td width=55%>Alert level</td>
</tr>
<tr>
<td> xx xx xx xx</td>
<td width=5> </td>
<td>dword</td>
<td width=5> </td>
<td width=55%>Limit level</td>
</tr>
<tr>
<td> xx xx xx xx</td>
<td width=5> </td>
<td>dword</td>
<td width=5> </td>
<td width=55%>Disconnect level</td>
</tr>
<tr>
<td> xx xx xx xx</td>
<td width=5> </td>
<td>dword</td>
<td width=5> </td>
<td width=55%>Current level</td>
</tr>
<tr>
<td> xx xx xx xx</td>
<td width=5> </td>
<td>dword</td>
<td width=5> </td>
<td width=55%>Max level</td>
</tr>
<tr>
<td> xx xx xx xx</td>
<td width=5> </td>
<td>dword</td>
<td width=5> </td>
<td width=55%>Last time;</td>
</tr>
<tr>
<td> xx</td>
<td width=5> </td>
<td>byte</td>
<td width=5> </td>
<td width=55%>Current state;</td>
</tr>
</table>
</td></tr>
</table>
</td></tr></table>
</td></tr>
</table>
<br>
And after those you get another set of structures (one for each class)
like this:<br><br>
<table width=100% cellSpacing=0 cellPadding=0 align=center border=0>
<tr><td width=20></td>
<td>
<table width=400 bgcolor=darkgreen cellSpacing=0 cellPadding=0 border=0><tr><td>
<table width=100% cellSpacing=2 cellPadding=0 border=0><tr><td bgcolor=#fafafa >
<table width=400 cellSpacing=0 cellPadding=0 align=center border=0>
<tr>
<td width=28%> xx xx</td>
<td width=5> </td>
<td>word</td>
<td width=5> </td>
<td width=55%>rate group id</td>
</tr>
<tr>
<td width=28%> xx xx</td>
<td width=5> </td>
<td>word</td>
<td width=5> </td>
<td width=55%>count of pairs in group</td>
</tr>
</table>
</td></tr>
<tr><td bgcolor=#fafafa >
<table width=400 cellSpacing=0 cellPadding=0 align=center border=0>
<tr>
<td> xx xx xx xx</td>
<td width=5> </td>
<td>dword</td>
<td width=5> </td>
<td width=55%>family/subtype pair #1</td>
</tr>
<tr>
<td> ....</td>
<td width=5> </td>
<td>....</td>
<td width=5> </td>
<td width=55%>....</td>
</tr>
<tr>
<td> xx xx xx xx</td>
<td width=5> </td>
<td>dword</td>
<td width=5> </td>
<td width=55%>family/subtype pair #n</td>
</tr>
</table>
</td></tr>
</table>
</td></tr></table>
</td></tr>
</table>
<br>
The rest of the structure is just <font color=red>count</font> word pairs, a SNAC family and SNAC
subtype for each SNAC that will use the rate information from this class.<br>
If the number of classes received is zero you should not reply. If it is
greater than zero, then you should reply with <a href="snac_01_08.html">
SNAC(01,08)</a> - "rate acknowledge" which is just a list of words with
the Class ID of each class you received.<br>
Now for some more explanations about the protocol. For each rate class, ICQ
can be in one of three states: <font color=blue>"limited"</font> (state 1), in
which no data is sent; <font color=blue>"alert"</font> (state 2), which is when
you're sending too fast, but you aren't yet limited; and <font color=blue>"clear"
</font> (state 3), when everything is cool. Every time a packet is sent (assuming
you aren't being "limited"), ICQ updates a "Last Time" value to keep track of
the last sent time (as with the state value, there is a separate time for each
rate class).<br>
It also looks up the time since the previous packet was sent and uses that
to keep a running average of time between packets (I refer to this as the
rate level). This level is calculated using a window size which specifies
how many of the previous times to take into account, as follows:<br><br>
<font color=blue>
NewLevel = (Window - 1)/Window * OldLevel + 1/Window * CurrentTimeDiff
</font><br><br>
There is also a Maximum Level at which this value will be capped. This formula
is for both server and client because they both should calculate current level.
You can check if your calculations is ok - just send <a href="snac_01_06.html">
SNAC(01,06)</a> in the middle of a session and compare server value from
<a href="snac_01_07.html">SNAC(01,07)</a> with yours.<br>
Once the new level has been calculated, ICQ updates your state as follows:
if your level is less than the Limit Level your state will be set to 1
("limited"); if it's greater than the Limit Level, but less than the Alert
Level, your state will be set to 2 ("alert"); if it's greater than the Alert
Level your state will be 3 ("clear"). If your state was already set to 1,
the calculation is slightly different. It only compares your level against
the Clear Level value - if it's greater than that, your state becomes 3
("clear"), otherwise it remains at 1 ("limited"). And one more thing - icq
often receive SNAC(01,07) with state=114 - this is ok, this mean that you
not limited.<br>
Incidentally, this calculation happens before your packet is actually sent, so
if your state changes to "limited" at this point, the packet won't be sent.
If your state is not "clear", ICQ will also start a timer for some time in
the future (the actual duration is rather complicated so I won't go into
that now) so that your state can be recalculated, giving you a chance to get
back to "clear".<br>
Now that you know the basic protocol, some of the SNAC parameters will make
more sense. The Window Size is the Window mentioned in calculating the
running average time between packets (the level). The Clear, Alert and Limit
Levels are used in calculating the rate state. Disconnect level is the level
at which the ICQ server will disconnect you so it doesn't used by the client.
The Current level is what the level is initially set to you when SNAC 1/07 is
received. The Max Level is what the level is capped at when calculating the
running average.<br><br>
The Last Time is a duration in milliseconds which is used to set the initial
value of the last sent time (the time is set to the specified duration into
the past, i.e. 1000 milliseconds means 1 second ago). The Start State
specifies the initial rate state, and although the state is immediately
recalculated, the current state does effect that calculation (as explained
above).<br><br>
</td>
<td width=5></td></tr>
</table>
</td></tr></table>
</td></tr></table>
</td></tr></table>
<br>
<table width=640 bgcolor=darkgray cellSpacing=0 cellPadding=0 border=0><tr><td>
<table width=100% cellSpacing=2 cellPadding=0 border=0><tr><td bgcolor=#E9E9E9 ><table width=100% cellSpacing=0 cellPadding=0 border=0>
<tr><td align=center valign=middle><b><font color=black size=2>
<a href="index.html" target="_top">Main</a> |
<a href="basic.html" target="_top">Basic</a> |
<a href="login.html" target="_top">Login</a> |
<a href="families.html" target="_top">Snaclist</a> |
<a href="sequences.html" target="_top">Sequences</a> |
<a href="lists.html" target="_top">Misc</a> |
<a href="changes.html" target="_top">Changes</a> |
<a href="credits.html" target="_top">Credits</a> |
<a href="terms.html" target="_top">Terms</a>
</font></b></td></tr></table>
</td></tr></table>
</td></tr></table>
<!--#include virtual="_bottom.htxt" -->
</body>
</html>