diff libgaim/protocols/oscar/flap_connection.c @ 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
line wrap: on
line diff
--- 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);
 }