// Token: 0x06000047 RID: 71 RVA: 0x00003728 File Offset: 0x00001928
        private void RemoveExpiredEntries(object state)
        {
            TokenBucketMap <KeyT> .tracer.TraceDebug(0L, "Timer delegate invoked.");

            lock (this.data)
            {
                if (this.cleanupTimer == null)
                {
                    TokenBucketMap <KeyT> .tracer.TraceDebug(0L, "Leaving immediately because TokenBucketMap is stopping.");

                    return;
                }
                DateTime    utcNow = DateTime.UtcNow;
                List <KeyT> list   = new List <KeyT>(this.data.Count / 4);
                foreach (KeyValuePair <KeyT, DailyTokenBucket> keyValuePair in this.data)
                {
                    if (keyValuePair.Value.IsExpired(utcNow))
                    {
                        ThrottlingServiceLog.LogTokenExpiry(keyValuePair.Key, keyValuePair.Value);
                        list.Add(keyValuePair.Key);
                    }
                }
                TokenBucketMap <KeyT> .tracer.TraceDebug <int, int>(0L, "Found {0} expired entries out of {1}; removing them.", list.Count, this.data.Count);

                foreach (KeyT key in list)
                {
                    this.data.Remove(key);
                }
            }
            TokenBucketMap <KeyT> .tracer.TraceDebug(0L, "Finished removing expired entries.");
        }
Beispiel #2
0
        // Token: 0x06000003 RID: 3 RVA: 0x0000215C File Offset: 0x0000035C
        public bool ObtainTokens <T>(ObtainTokensRequest <T> request, DateTime currentTime)
        {
            int requestedTokenCount = request.RequestedTokenCount;
            int totalTokenCount     = request.TotalTokenCount;

            if (totalTokenCount < 1)
            {
                throw new ArgumentOutOfRangeException("totalTokenCount", totalTokenCount, "totalTokenCount should be greater than 0");
            }
            if (requestedTokenCount < 1 || requestedTokenCount > totalTokenCount)
            {
                string message = string.Format(CultureInfo.InvariantCulture, "requestedCount should be greater than 0 and less or equal to totalCount of {0}", new object[]
                {
                    totalTokenCount
                });
                throw new ArgumentOutOfRangeException("requestedCount", requestedTokenCount, message);
            }
            this.totalCount = totalTokenCount;
            if (this.IsExpired(currentTime))
            {
                ThrottlingServiceLog.LogTokenExpiry(request.MailboxGuid, this);
                this.timestamp   = currentTime;
                this.issuedCount = 0;
            }
            bool result = false;

            if (this.issuedCount + requestedTokenCount <= this.totalCount)
            {
                this.issuedCount += requestedTokenCount;
                result            = true;
            }
            ThrottlingServiceLog.LogObtainTokens <T>(request, this, result);
            return(result);
        }
        // Token: 0x0600003D RID: 61 RVA: 0x0000333C File Offset: 0x0000153C
        internal static void LogThrottlingBypassed <T>(ObtainTokensRequest <T> request)
        {
            if (!ThrottlingServiceLog.enabled)
            {
                return;
            }
            LogRowFormatter logRowFormatter = new LogRowFormatter(ThrottlingServiceLog.throttlingServiceLogSchema);

            ThrottlingServiceLog.PopulateRequestParmeters <T>(logRowFormatter, request);
            logRowFormatter[10] = "Throttling is bypassed.";
            logRowFormatter[1]  = ThrottlingServiceLog.ThrottlingEventId.BYPASS;
            ThrottlingServiceLog.log.Append(logRowFormatter, 0);
        }
Beispiel #4
0
 // Token: 0x06000031 RID: 49 RVA: 0x00002F48 File Offset: 0x00001148
 protected override void OnStopInternal()
 {
     ThrottlingService.StartStopBreadcrumbs.Drop("Stopping Throttling Service", new object[0]);
     ThrottlingService.tracer.TraceDebug(0L, "Stopping Throttling Service");
     ThrottlingServiceLog.Stop();
     if (this.rpcServer != null)
     {
         this.rpcServer.Stop();
         this.rpcServer = null;
     }
     ThrottlingService.tracer.TraceDebug(0L, "Throttling Service stopped successfully");
     ThrottlingService.StartStopBreadcrumbs.Drop("Throttling Service stopped successfully", new object[0]);
 }
        // Token: 0x06000029 RID: 41 RVA: 0x00002B18 File Offset: 0x00000D18
        private bool ObtainTokens(Guid mailboxGuid, RequestedAction requestedAction, int requestedTokenCount, int totalTokenCount, string clientHostName, string clientProcessName, string clientType)
        {
            ThrottlingService.Tracer.TraceDebug(0L, "ObtainTokens() request: mailboxGuid=<{0}>; requestedAction={1}; requestedTokenCount={2}; totalTokenCount={3}", new object[]
            {
                mailboxGuid,
                requestedAction,
                requestedTokenCount,
                totalTokenCount
            });
            ObtainTokensRequest <Guid> request = new ObtainTokensRequest <Guid>(mailboxGuid, requestedTokenCount, totalTokenCount, requestedAction, clientHostName, clientProcessName, clientType);
            bool flag;

            if (totalTokenCount < 1 || requestedTokenCount < 1 || requestedTokenCount > totalTokenCount)
            {
                ThrottlingService.Tracer.TraceError(0L, "ObtainSubmissionTokens(): invalid arguments supplied");
                flag = false;
            }
            else if (requestedAction == RequestedAction.UserMailSubmission)
            {
                flag = this.userSubmissionTokens.ObtainTokens(request);
            }
            else if (requestedAction == RequestedAction.MailboxRuleMailSubmission)
            {
                flag = this.mailboxRuleSubmissionTokens.ObtainTokens(request);
            }
            else
            {
                ThrottlingServiceLog.LogThrottlingBypassed <Guid>(request);
                ThrottlingService.Tracer.TraceDebug <RequestedAction>(0L, "Action {1} is not supported, therefor is allowed by default", requestedAction);
                flag = true;
            }
            if (flag)
            {
                ThrottlingService.Tracer.TraceDebug(0L, "ObtainTokens(): request allowed");
            }
            else
            {
                ThrottlingService.EventLogger.LogEvent(ThrottlingServiceEventLogConstants.Tuple_MailboxThrottled, mailboxGuid.ToString(), new object[]
                {
                    mailboxGuid,
                    clientHostName,
                    requestedAction,
                    requestedTokenCount,
                    totalTokenCount,
                    clientType,
                    clientProcessName
                });
                ThrottlingService.Tracer.TraceDebug(0L, "ObtainTokens(): request denied");
            }
            return(flag);
        }
Beispiel #6
0
        // Token: 0x06000030 RID: 48 RVA: 0x00002E90 File Offset: 0x00001090
        protected override void OnStartInternal(string[] args)
        {
            TimeSpan startupTimeout = TimeSpan.FromMinutes(6.0);

            base.ExRequestAdditionalTime((int)startupTimeout.TotalMilliseconds);
            ThrottlingService.StartStopBreadcrumbs.Drop("Starting Throttling Service", new object[0]);
            ThrottlingService.tracer.TraceDebug(0L, "Starting Throttling Service");
            if (ThrottlingAppConfig.LoggingEnabled && ThrottlingAppConfig.LogPath != null)
            {
                ThrottlingServiceLog.Start();
            }
            if (!ThrottlingRpcServerImpl.TryCreateInstance(startupTimeout, out this.rpcServer))
            {
                ThrottlingService.StartStopBreadcrumbs.Drop("Failed to start Throttling Service, exiting", new object[0]);
                Environment.Exit(1);
            }
            ThrottlingService.tracer.TraceDebug(0L, "Throttling Service started successfully");
            ThrottlingService.StartStopBreadcrumbs.Drop("Throttling Service started successfully", new object[0]);
            ThrottlingServiceLog.LogServiceStart();
        }
        // Token: 0x0600003A RID: 58 RVA: 0x00003260 File Offset: 0x00001460
        public static void LogObtainTokens <T>(ObtainTokensRequest <T> request, object tokenInfo, bool result)
        {
            if (!ThrottlingServiceLog.enabled)
            {
                return;
            }
            LogRowFormatter logRowFormatter = new LogRowFormatter(ThrottlingServiceLog.throttlingServiceLogSchema);

            ThrottlingServiceLog.PopulateRequestParmeters <T>(logRowFormatter, request);
            logRowFormatter[9]  = result;
            logRowFormatter[10] = tokenInfo;
            if (result)
            {
                logRowFormatter[1] = ThrottlingServiceLog.ThrottlingEventId.APPROVE;
            }
            else
            {
                logRowFormatter[1] = ThrottlingServiceLog.ThrottlingEventId.DENY;
            }
            ThrottlingServiceLog.log.Append(logRowFormatter, 0);
        }