# HG changeset patch # User Mark Doliner # Date 1165056186 0 # Node ID 9cdc8bb39cf2c4d940e14ff6e35919176ba1ecac # Parent 033e1604cf631ff8fa9df8ccf9f0dd6072d6321d [gaim-migrate @ 17876] First stab at attempting to keep track of our rate limiting average committer: Tailor Script diff -r 033e1604cf63 -r 9cdc8bb39cf2 libgaim/protocols/oscar/family_oservice.c --- a/libgaim/protocols/oscar/family_oservice.c Sat Dec 02 10:17:13 2006 +0000 +++ b/libgaim/protocols/oscar/family_oservice.c Sat Dec 02 10:43:06 2006 +0000 @@ -266,10 +266,10 @@ rateclass_find(GSList *rateclasses, guint16 id) { GSList *tmp; - struct rateclass *rateclass; for (tmp = rateclasses; tmp != NULL; tmp = tmp->next) { + struct rateclass *rateclass; rateclass = tmp->data; if (rateclass->classid == id) return rateclass; diff -r 033e1604cf63 -r 9cdc8bb39cf2 libgaim/protocols/oscar/flap_connection.c --- a/libgaim/protocols/oscar/flap_connection.c Sat Dec 02 10:17:13 2006 +0000 +++ b/libgaim/protocols/oscar/flap_connection.c Sat Dec 02 10:43:06 2006 +0000 @@ -72,6 +72,42 @@ flap_connection_send(conn, frame); } +static void +update_rate_class(FlapConnection *conn, guint16 family, guint16 subtype) +{ + GSList *tmp1, *tmp2; + + for (tmp1 = conn->rateclasses; tmp1 != NULL; tmp1 = tmp1->next) + { + struct rateclass *rateclass; + rateclass = tmp1->data; + + for (tmp2 = rateclass->members; tmp2 != NULL; tmp2 = tmp2->next) + { + struct snacpair *snacpair; + snacpair = tmp2->data; + if ((snacpair->group == family) && (snacpair->subtype == subtype)) + { + /* + * We've found the rateclass for this SNAC family and + * subtype! Update our "current" average by calculating + * a rolling average. This is pretty shoddy. We should + * really keep track of the times when the last last + * windowsize messages that were sent and just calculate + * the REAL average. + */ + time_t now; + now = time(NULL); + /* This formula is taken from the joscar API docs. */ + rateclass->current = MIN(((rateclass->current * (rateclass->windowsize - 1)) + (now - rateclass->last)) / rateclass->windowsize, rateclass->max); + rateclass->last = now; + return; + } + } + } +} + + /** * This sends a channel 2 FLAP containing a SNAC. The SNAC family and * subtype are looked up in the rate info for this connection, and if @@ -96,6 +132,7 @@ } /* TODO: Outgoing message throttling */ + update_rate_class(conn, family, subtype); flap_connection_send(conn, frame); } diff -r 033e1604cf63 -r 9cdc8bb39cf2 libgaim/protocols/oscar/oscar.h --- a/libgaim/protocols/oscar/oscar.h Sat Dec 02 10:17:13 2006 +0000 +++ b/libgaim/protocols/oscar/oscar.h Sat Dec 02 10:43:06 2006 +0000 @@ -1577,6 +1577,8 @@ guint8 unknown[5]; /* only present in versions >= 3 */ GSList *members; /* Contains node of struct snacpair */ /* TODO: Maybe use a GHashTable for members */ + + time_t last; /**< The time when we last sent a SNAC of this rate class. */ }; int aim_cachecookie(OscarData *od, IcbmCookie *cookie);