changeset 15091:9cdc8bb39cf2

[gaim-migrate @ 17876] First stab at attempting to keep track of our rate limiting average committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sat, 02 Dec 2006 10:43:06 +0000
parents 033e1604cf63
children 525607f86cce
files libgaim/protocols/oscar/family_oservice.c libgaim/protocols/oscar/flap_connection.c libgaim/protocols/oscar/oscar.h
diffstat 3 files changed, 40 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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;
--- 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);
 }
--- 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);