private RPCConnectionMetering.RuntimeData GetRuntimedData(uint serviceID, uint methodID)
        {
            uint num = serviceID * 1000u + methodID;

            RPCConnectionMetering.RuntimeData runtimeData = this.m_data.GetRuntimeData(num);
            if (runtimeData == null)
            {
                runtimeData = new RPCConnectionMetering.RuntimeData();
                this.m_data.RuntimeData[num] = runtimeData;
                RPCConnectionMetering.StaticData staticData = null;
                foreach (KeyValuePair <string, RPCConnectionMetering.StaticData> keyValuePair in this.m_data.MethodDefaults)
                {
                    if (keyValuePair.Value.ServiceId == serviceID && keyValuePair.Value.MethodId == methodID)
                    {
                        staticData = keyValuePair.Value;
                        break;
                    }
                }
                if (staticData == null)
                {
                    foreach (KeyValuePair <string, RPCConnectionMetering.StaticData> keyValuePair2 in this.m_data.ServiceDefaults)
                    {
                        if (keyValuePair2.Value.ServiceId == serviceID)
                        {
                            staticData = keyValuePair2.Value;
                            break;
                        }
                    }
                }
                if (staticData == null && this.m_data.GlobalDefault != null)
                {
                    staticData = this.m_data.GlobalDefault;
                }
                if (staticData == null)
                {
                    this.m_log.LogDebug("Always allowing ServiceId={0} MethodId={1}", new object[]
                    {
                        serviceID,
                        methodID
                    });
                    runtimeData.AlwaysAllow = true;
                    return(runtimeData);
                }
                runtimeData.StaticData = staticData;
                if (staticData.RateLimitCount == 0u)
                {
                    runtimeData.AlwaysDeny = true;
                }
                else if (staticData.RateLimitSeconds == 0u)
                {
                    runtimeData.FiniteCallsLeft = staticData.RateLimitCount;
                }
                else
                {
                    runtimeData.Tracker = new RPCConnectionMetering.CallTracker(staticData.RateLimitCount, staticData.RateLimitSeconds);
                }
            }
            return(runtimeData);
        }
        private void InitializeInternalState(RPCMeterConfig config, ServiceCollectionHelper serviceHelper)
        {
            List <string> list        = new List <string>();
            List <string> list2       = new List <string>();
            int           methodCount = config.MethodCount;

            for (int i = 0; i < methodCount; i++)
            {
                RPCMethodConfig rpcmethodConfig             = config.Method[i];
                RPCConnectionMetering.StaticData staticData = new RPCConnectionMetering.StaticData();
                staticData.FromProtocol(rpcmethodConfig);
                if (!rpcmethodConfig.HasServiceName)
                {
                    if (this.m_data.GlobalDefault == null)
                    {
                        this.m_data.GlobalDefault = staticData;
                        this.m_log.LogDebug("Adding global default {0}", new object[]
                        {
                            staticData
                        });
                    }
                    else
                    {
                        this.m_log.LogWarning("Static data has two defaults, ignoring additional ones.");
                    }
                }
                else
                {
                    string            serviceName           = rpcmethodConfig.ServiceName;
                    ServiceDescriptor importedServiceByName = serviceHelper.GetImportedServiceByName(serviceName);
                    if (importedServiceByName == null)
                    {
                        if (!list2.Contains(serviceName))
                        {
                            this.m_log.LogDebug("Ignoring not imported service {0}", new object[]
                            {
                                serviceName
                            });
                            list2.Add(serviceName);
                        }
                    }
                    else
                    {
                        staticData.ServiceId = importedServiceByName.Id;
                        if (rpcmethodConfig.HasMethodName)
                        {
                            string           methodName             = rpcmethodConfig.MethodName;
                            string           text                   = string.Format("{0}.{1}", serviceName, methodName);
                            MethodDescriptor methodDescriptorByName = importedServiceByName.GetMethodDescriptorByName(text);
                            if (methodDescriptorByName == null)
                            {
                                this.m_log.LogDebug("Configuration specifies an unused method {0}, ignoring.", new object[]
                                {
                                    methodName
                                });
                                goto IL_231;
                            }
                            if (this.m_data.MethodDefaults.ContainsKey(text))
                            {
                                this.m_log.LogWarning("Default for method {0} already exists, ignoring extras.", new object[]
                                {
                                    text
                                });
                                goto IL_231;
                            }
                            staticData.MethodId = methodDescriptorByName.Id;
                            this.m_data.MethodDefaults[text] = staticData;
                            this.m_log.LogDebug("Adding Method default {0}", new object[]
                            {
                                staticData
                            });
                        }
                        else
                        {
                            if (this.m_data.ServiceDefaults.ContainsKey(serviceName))
                            {
                                this.m_log.LogWarning("Default for service {0} already exists, ignoring extras.", new object[]
                                {
                                    serviceName
                                });
                                goto IL_231;
                            }
                            this.m_data.ServiceDefaults[serviceName] = staticData;
                            this.m_log.LogDebug("Adding Service default {0}", new object[]
                            {
                                staticData
                            });
                        }
                        list.Add(serviceName);
                    }
                }
                IL_231 :;
            }
            foreach (KeyValuePair <uint, ServiceDescriptor> keyValuePair in serviceHelper.ImportedServices)
            {
                if (!list.Contains(keyValuePair.Value.Name) && this.m_data.GlobalDefault == null)
                {
                    this.m_log.LogDebug("Configuration for service {0} was not found and will not be metered.", new object[]
                    {
                        keyValuePair.Value.Name
                    });
                }
            }
        }
        private void InitializeInternalState(RPCMeterConfig config, ServiceCollectionHelper serviceHelper)
        {
            string        serviceName;
            string        str;
            List <string> strs        = new List <string>();
            List <string> strs1       = new List <string>();
            int           methodCount = config.MethodCount;

            for (int i = 0; i < methodCount; i++)
            {
                RPCMethodConfig item = config.Method[i];
                RPCConnectionMetering.StaticData staticDatum = new RPCConnectionMetering.StaticData();
                staticDatum.FromProtocol(item);
                if (item.HasServiceName)
                {
                    serviceName = item.ServiceName;
                    ServiceDescriptor importedServiceByName = serviceHelper.GetImportedServiceByName(serviceName);
                    if (importedServiceByName != null)
                    {
                        staticDatum.ServiceId = importedServiceByName.Id;
                        if (!item.HasMethodName)
                        {
                            if (this.m_data.ServiceDefaults.ContainsKey(serviceName))
                            {
                                goto Label1;
                            }
                            this.m_data.ServiceDefaults[serviceName] = staticDatum;
                            this.m_log.LogDebug("Adding Service default {0}", new object[] { staticDatum });
                        }
                        else
                        {
                            string methodName = item.MethodName;
                            str = string.Format("{0}.{1}", serviceName, methodName);
                            MethodDescriptor methodDescriptorByName = importedServiceByName.GetMethodDescriptorByName(str);
                            if (methodDescriptorByName != null)
                            {
                                if (this.m_data.MethodDefaults.ContainsKey(str))
                                {
                                    goto Label2;
                                }
                                staticDatum.MethodId            = methodDescriptorByName.Id;
                                this.m_data.MethodDefaults[str] = staticDatum;
                                this.m_log.LogDebug("Adding Method default {0}", new object[] { staticDatum });
                            }
                            else
                            {
                                this.m_log.LogDebug("Configuration specifies an unused method {0}, ignoring.", new object[] { methodName });
                                goto Label0;
                            }
                        }
                        strs.Add(serviceName);
                    }
                    else if (!strs1.Contains(serviceName))
                    {
                        this.m_log.LogDebug("Ignoring not imported service {0}", new object[] { serviceName });
                        strs1.Add(serviceName);
                    }
                }
                else if (this.m_data.GlobalDefault != null)
                {
                    this.m_log.LogWarning("Static data has two defaults, ignoring additional ones.");
                }
                else
                {
                    this.m_data.GlobalDefault = staticDatum;
                    this.m_log.LogDebug("Adding global default {0}", new object[] { staticDatum });
                }
Label0:
            }
            foreach (KeyValuePair <uint, ServiceDescriptor> importedService in serviceHelper.ImportedServices)
            {
                if (strs.Contains(importedService.Value.Name) || this.m_data.GlobalDefault != null)
                {
                    continue;
                }
                this.m_log.LogDebug("Configuration for service {0} was not found and will not be metered.", new object[] { importedService.Value.Name });
            }
            return;

Label1:
            BattleNetLogSource mLog = this.m_log;

            mLog.LogWarning("Default for service {0} already exists, ignoring extras.", new object[] { serviceName });
            goto Label0;
Label2:
            BattleNetLogSource battleNetLogSource = this.m_log;

            battleNetLogSource.LogWarning("Default for method {0} already exists, ignoring extras.", new object[] { str });
            goto Label0;
        }
Пример #4
0
        private RPCConnectionMetering.RuntimeData GetRuntimedData(uint serviceID, uint methodID)
        {
            uint num = serviceID * 1000u + methodID;

            RPCConnectionMetering.RuntimeData runtimeData = this.m_data.GetRuntimeData(num);
            if (runtimeData == null)
            {
                runtimeData = new RPCConnectionMetering.RuntimeData();
                this.m_data.RuntimeData.set_Item(num, runtimeData);
                RPCConnectionMetering.StaticData staticData = null;
                using (Dictionary <string, RPCConnectionMetering.StaticData> .Enumerator enumerator = this.m_data.MethodDefaults.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        KeyValuePair <string, RPCConnectionMetering.StaticData> current = enumerator.get_Current();
                        if (current.get_Value().ServiceId == serviceID && current.get_Value().MethodId == methodID)
                        {
                            staticData = current.get_Value();
                            break;
                        }
                    }
                }
                if (staticData == null)
                {
                    using (Dictionary <string, RPCConnectionMetering.StaticData> .Enumerator enumerator2 = this.m_data.ServiceDefaults.GetEnumerator())
                    {
                        while (enumerator2.MoveNext())
                        {
                            KeyValuePair <string, RPCConnectionMetering.StaticData> current2 = enumerator2.get_Current();
                            if (current2.get_Value().ServiceId == serviceID)
                            {
                                staticData = current2.get_Value();
                                break;
                            }
                        }
                    }
                }
                if (staticData == null && this.m_data.GlobalDefault != null)
                {
                    staticData = this.m_data.GlobalDefault;
                }
                if (staticData == null)
                {
                    this.m_log.LogDebug("Always allowing ServiceId={0} MethodId={1}", new object[]
                    {
                        serviceID,
                        methodID
                    });
                    runtimeData.AlwaysAllow = true;
                    return(runtimeData);
                }
                runtimeData.StaticData = staticData;
                if (staticData.RateLimitCount == 0u)
                {
                    runtimeData.AlwaysDeny = true;
                }
                else if (staticData.RateLimitSeconds == 0u)
                {
                    runtimeData.FiniteCallsLeft = staticData.RateLimitCount;
                }
                else
                {
                    runtimeData.Tracker = new RPCConnectionMetering.CallTracker(staticData.RateLimitCount, staticData.RateLimitSeconds);
                }
            }
            return(runtimeData);
        }