/// <summary> /// Send a data packet to the rate class that will send it /// </summary> /// <param name="dp">A <see cref="DataPacket"/> object</param> public static void DispatchToRateClass(DataPacket dp) { if (dp.ParentConnection == null) { dp.ParentConnection = dp.ParentSession.Connections.GetByFamily( dp.SNAC.FamilyServiceID); if (dp.ParentConnection == null || dp.ParentConnection.ReadyForData == false) { dp.ParentSession.Connections.AddDelayedPacket(dp.SNAC.FamilyServiceID, dp); return; } } int key = (int)(dp.SNAC.FamilyServiceID << 16) | dp.SNAC.FamilySubtypeID; RateClass rc = dp.ParentSession.RateClasses[key]; if (rc != null) { rc.Enqueue(dp); } else { dp.ParentConnection.SendFLAP(dp.Data.GetBytes()); } }
/// <summary> /// Creates a new RateClassManager /// </summary> public RateClassManager(Session parent) { // Initialize RateClass tables for (int i = 0; i < 5; i++) { _classes[i] = new RateClass(parent, i + 1); } }
/// <summary> /// Processes the list of rate limitations -- SNAC(01,07) /// </summary> /// <param name="dp">A <see cref="DataPacket"/> object containing SNAC(01,07)</param> public static void ProcessRateLimitations(DataPacket dp) { Session sess = dp.ParentSession; ushort num_classes = dp.Data.ReadUshort(); Hashtable rcs = new Hashtable(); ushort[] classes = new ushort[num_classes]; RateClassManager rcm = sess.RateClasses; // Get the rate class attributes out of the SNAC for (int i = 0; i < num_classes; i++) { ushort id = dp.Data.ReadUshort(); RateClass rc = sess.RateClasses.GetByID(id); rc.WindowSize = dp.Data.ReadUint(); rc.ClearLevel = dp.Data.ReadUint(); rc.AlertLevel = dp.Data.ReadUint(); rc.LimitLevel = dp.Data.ReadUint(); rc.DisconnectLevel = dp.Data.ReadUint(); rc.CurrentLevel = dp.Data.ReadUint(); rc.MaxLevel = dp.Data.ReadUint(); if (dp.ParentSession.Families.GetFamilyVersion(0x0001) >= 3) { rc.LastTime = dp.Data.ReadUint(); rc.CurrentState = dp.Data.ReadByte(); } sess.RateClasses.SetByID(id, rc); rc.StartLimitedTransmission(); classes[i] = id; } // Register rates with the session's ConnectionList for (int i = 0; i < num_classes; i++) { ushort id = dp.Data.ReadUshort(); ushort num_pairs = dp.Data.ReadUshort(); for (int j = 0; j < num_pairs; j++) { ushort family = dp.Data.ReadUshort(); ushort subtype = dp.Data.ReadUshort(); rcm.SetRateClassKey(family, subtype, id); } } AcknowledgeRateLimitations(dp, classes); }
/// <summary> /// Sets a <see cref="RateClass"/> object by its ID number /// </summary> /// <param name="Id">A rate class ID number, 1 - 5</param> /// <param name="rc">A <see cref="RateClass"/> object</param> public void SetByID(int Id, RateClass rc) { _classes[Id - 1] = rc; }