comparison libpurple/protocols/oscar/flap_connection.c @ 28490:45583f271c02

oscar: Update the rate calculations based on OSCAR docs. Another patch from Aman "tmm1" Gupta. committer: Paul Aurich <paul@darkrain42.org>
author aman@tmm1.net
date Tue, 03 Nov 2009 05:53:06 +0000
parents bff61dad9a6b
children 4575d8daba12
comparison
equal deleted inserted replaced
28489:05fd23db0a68 28490:45583f271c02
129 */ 129 */
130 static guint32 130 static guint32
131 rateclass_get_new_current(FlapConnection *conn, struct rateclass *rateclass, struct timeval *now) 131 rateclass_get_new_current(FlapConnection *conn, struct rateclass *rateclass, struct timeval *now)
132 { 132 {
133 unsigned long timediff; /* In milliseconds */ 133 unsigned long timediff; /* In milliseconds */
134 guint32 current;
134 135
135 timediff = (now->tv_sec - rateclass->last.tv_sec) * 1000 + (now->tv_usec - rateclass->last.tv_usec) / 1000; 136 timediff = (now->tv_sec - rateclass->last.tv_sec) * 1000 + (now->tv_usec - rateclass->last.tv_usec) / 1000;
136 137 current = ((rateclass->current * (rateclass->windowsize - 1)) + timediff) / rateclass->windowsize;
137 /* This formula is taken from the joscar API docs. Preesh. */ 138
138 return MIN(((rateclass->current * (rateclass->windowsize - 1)) + timediff) / rateclass->windowsize, rateclass->max); 139 /* This formula is taken from http://dev.aol.com/aim/oscar/#RATELIMIT */
140 return MIN(current, rateclass->max);
139 } 141 }
140 142
141 /* 143 /*
142 * Attempt to send the contents of a given queue 144 * Attempt to send the contents of a given queue
143 * 145 *
159 { 161 {
160 guint32 new_current; 162 guint32 new_current;
161 163
162 new_current = rateclass_get_new_current(conn, rateclass, &now); 164 new_current = rateclass_get_new_current(conn, rateclass, &now);
163 165
164 /* (Add 100ms padding to account for inaccuracies in the calculation) */ 166 if (rateclass->dropping_snacs || new_current <= rateclass->alert)
165 if (new_current < rateclass->alert + 100)
166 /* Not ready to send this SNAC yet--keep waiting. */ 167 /* Not ready to send this SNAC yet--keep waiting. */
167 return FALSE; 168 return FALSE;
168 169
169 rateclass->current = new_current; 170 rateclass->current = new_current;
170 rateclass->last.tv_sec = now.tv_sec; 171 rateclass->last.tv_sec = now.tv_sec;
243 guint32 new_current; 244 guint32 new_current;
244 245
245 gettimeofday(&now, NULL); 246 gettimeofday(&now, NULL);
246 new_current = rateclass_get_new_current(conn, rateclass, &now); 247 new_current = rateclass_get_new_current(conn, rateclass, &now);
247 248
248 /* (Add 100ms padding to account for inaccuracies in the calculation) */ 249 if (rateclass->dropping_snacs || new_current <= rateclass->alert)
249 if (new_current < rateclass->alert + 100)
250 { 250 {
251 purple_debug_info("oscar", "Current rate for conn %p would be %u, but we alert at %u; enqueueing\n", conn, new_current, (rateclass->alert + 100)); 251 purple_debug_info("oscar", "Current rate for conn %p would be %u, but we alert at %u; enqueueing\n", conn, new_current, rateclass->alert);
252 252
253 enqueue = TRUE; 253 enqueue = TRUE;
254 } 254 }
255 else 255 else
256 { 256 {