Exemplo n.º 1
0
        public bool TryGet(Guid database, IRequestContext requestContext, out BackEndServer backEndServer)
        {
            if (requestContext == null)
            {
                throw new ArgumentNullException("requestContext");
            }
            backEndServer = null;
            PerfCounters.HttpProxyCacheCountersInstance.BackEndServerLocalCacheHitsRateBase.Increment();
            PerfCounters.HttpProxyCacheCountersInstance.BackEndServerOverallCacheHitsRateBase.Increment();
            PerfCounters.IncrementMovingPercentagePerformanceCounterBase(PerfCounters.HttpProxyCacheCountersInstance.MovingPercentageBackEndServerLocalCacheHitsRate);
            PerfCounters.IncrementMovingPercentagePerformanceCounterBase(PerfCounters.HttpProxyCacheCountersInstance.MovingPercentageBackEndServerOverallCacheHitsRate);
            MailboxServerCacheEntry mailboxServerCacheEntry = null;
            bool flag  = false;
            bool flag2 = this.serversCache.TryGetValue(database, out mailboxServerCacheEntry);

            if (flag2)
            {
                if (MailboxServerCache.IsE14ServerStale(mailboxServerCacheEntry))
                {
                    this.Remove(database, requestContext);
                    return(false);
                }
                backEndServer = mailboxServerCacheEntry.BackEndServer;
                PerfCounters.HttpProxyCacheCountersInstance.BackEndServerLocalCacheHitsRate.Increment();
                PerfCounters.UpdateMovingPercentagePerformanceCounter(PerfCounters.HttpProxyCacheCountersInstance.MovingPercentageBackEndServerLocalCacheHitsRate);
                if (mailboxServerCacheEntry.IsDueForRefresh(MailboxServerCache.GetRefreshInterval(backEndServer)))
                {
                    flag = true;
                }
            }
            if (HttpProxySettings.MailboxServerLocatorSharedCacheEnabled.Value && (!flag2 || flag))
            {
                MailboxServerCacheEntry sharedCacheEntry = null;
                long   latency  = 0L;
                string diagInfo = null;
                bool   latency2 = LatencyTracker.GetLatency <bool>(() => this.sharedCacheClient.TryGet <MailboxServerCacheEntry>(database.ToString(), requestContext.ActivityId, out sharedCacheEntry, out diagInfo), out latency);
                requestContext.LogSharedCacheCall(latency, diagInfo);
                if (latency2 && (!flag2 || sharedCacheEntry.LastRefreshTime > mailboxServerCacheEntry.LastRefreshTime))
                {
                    this.Add(database, sharedCacheEntry, requestContext, false);
                    mailboxServerCacheEntry = sharedCacheEntry;
                    flag2 = true;
                }
            }
            if (flag2)
            {
                backEndServer = mailboxServerCacheEntry.BackEndServer;
                PerfCounters.HttpProxyCacheCountersInstance.BackEndServerOverallCacheHitsRate.Increment();
                PerfCounters.UpdateMovingPercentagePerformanceCounter(PerfCounters.HttpProxyCacheCountersInstance.MovingPercentageBackEndServerOverallCacheHitsRate);
                if (!this.LazyRefreshDisabled && mailboxServerCacheEntry.IsDueForRefresh(MailboxServerCache.GetRefreshInterval(mailboxServerCacheEntry.BackEndServer)))
                {
                    if (MailboxServerCache.BackgroundServerRefreshEnabled.Value)
                    {
                        this.RegisterRefresh(new DatabaseWithForest(database, mailboxServerCacheEntry.ResourceForest, requestContext.ActivityId));
                    }
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(requestContext.Logger, "ServerLocatorRefresh", database);

                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(requestContext.Logger, "RefreshingCacheEntry", mailboxServerCacheEntry.ToString());
                }
            }
            return(flag2);
        }
Exemplo n.º 2
0
        public void Add(Guid database, BackEndServer server, string resourceForestFqdn, bool isSourceCachedData, Guid initiatingRequestId)
        {
            MailboxServerCacheEntry entry = new MailboxServerCacheEntry(server, resourceForestFqdn, DateTime.UtcNow, isSourceCachedData);

            this.Add(database, entry, initiatingRequestId, null, true);
        }
Exemplo n.º 3
0
        public void Add(Guid database, BackEndServer server, string resourceForestFqdn, bool isSourceCachedData, IRequestContext requestContext)
        {
            MailboxServerCacheEntry entry = new MailboxServerCacheEntry(server, resourceForestFqdn, DateTime.UtcNow, isSourceCachedData);

            this.Add(database, entry, requestContext.ActivityId, requestContext, true);
        }
Exemplo n.º 4
0
        // Token: 0x060001EA RID: 490 RVA: 0x00009428 File Offset: 0x00007628
        public BackEndServer GetDownLevelClientAccessServer <ServiceType>(AnchorMailbox anchorMailbox, BackEndServer mailboxServer, ClientAccessType clientAccessType, RequestDetailsLogger logger, bool calculateRedirectUrl, out Uri redirectUrl) where ServiceType : HttpService
        {
            if (anchorMailbox == null)
            {
                throw new ArgumentNullException("anchorMailbox");
            }
            if (mailboxServer == null)
            {
                throw new ArgumentNullException("mailboxServer");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            if (!DownLevelServerManager.IsApplicable)
            {
                throw new HttpProxyException(HttpStatusCode.NotFound, 3001, string.Format("{0} does not support down level server proxy.", HttpProxyGlobals.ProtocolType));
            }
            redirectUrl = null;
            if (mailboxServer.Version < Server.E14MinVersion)
            {
                if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(1))
                {
                    ExTraceGlobals.VerboseTracer.TraceDebug <int, int, string>((long)this.GetHashCode(), "[DownLevelServerManager::GetDownLevelClientAccessServer]: Found mailbox server version {0}, which was pre-E14 minimum version {1}, so returning mailbox server FQDN {2}", mailboxServer.Version, Server.E14MinVersion, mailboxServer.Fqdn);
                }
                return(mailboxServer);
            }
            ServiceTopology currentLegacyServiceTopology = ServiceTopology.GetCurrentLegacyServiceTopology("d:\\dbs\\sh\\e16df\\0212_214120_0\\cmd\\1g\\sources\\Dev\\Cafe\\src\\HttpProxy\\DownLevelServerManager\\DownLevelServerManager.cs", "GetDownLevelClientAccessServer", 415);
            Site            site   = currentLegacyServiceTopology.GetSite(mailboxServer.Fqdn, "d:\\dbs\\sh\\e16df\\0212_214120_0\\cmd\\1g\\sources\\Dev\\Cafe\\src\\HttpProxy\\DownLevelServerManager\\DownLevelServerManager.cs", "GetDownLevelClientAccessServer", 416);
            ServiceType     result = this.GetClientAccessServiceInSite <ServiceType>(currentLegacyServiceTopology, anchorMailbox, site, clientAccessType, (ServiceType service) => service.ServerVersionNumber >= Server.E14MinVersion && service.ServerVersionNumber < Server.E15MinVersion, logger);

            if (calculateRedirectUrl && !Utilities.IsPartnerHostedOnly && !CafeConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).NoCrossSiteRedirect.Enabled&& result != null && !string.IsNullOrEmpty(result.ServerFullyQualifiedDomainName) && !HttpProxyGlobals.LocalSite.Member.DistinguishedName.Equals(result.Site.DistinguishedName))
            {
                HttpService httpService = currentLegacyServiceTopology.FindAny <ServiceType>(1, (ServiceType externalService) => externalService != null && externalService.ServerFullyQualifiedDomainName.Equals(result.ServerFullyQualifiedDomainName, StringComparison.OrdinalIgnoreCase), "d:\\dbs\\sh\\e16df\\0212_214120_0\\cmd\\1g\\sources\\Dev\\Cafe\\src\\HttpProxy\\DownLevelServerManager\\DownLevelServerManager.cs", "GetDownLevelClientAccessServer", 441);
                if (httpService != null)
                {
                    redirectUrl = httpService.Url;
                }
            }
            return(new BackEndServer(result.ServerFullyQualifiedDomainName, result.ServerVersionNumber));
        }
Exemplo n.º 5
0
 // Token: 0x0600027B RID: 635 RVA: 0x00003165 File Offset: 0x00001365
 public virtual bool ShouldInvalidate(BackEndServer badTarget)
 {
     return(false);
 }
Exemplo n.º 6
0
        internal async Task Login(AuthResult auth)
        {
            if (!Init.IsCompleted)
            {
                await Init;
            }
            if (auth.Content.Status != "LOGIN")
            {
                throw new ArgumentException("Invalid auth credentials");
            }

            var context = Riot.Services.Service.RegisterObjects();

            rtmp = new RtmpClient(new Uri("rtmps://" + Region.Current.MainServer + ":2099"), context, ObjectEncoding.Amf3);
            rtmp.MessageReceived += Rtmp_MessageReceived;
            rtmp.Disconnected    += Rtmp_Disconnected;
            await rtmp.ConnectAsync();

            chat.Connect(auth);

            LoginSession session = null;

            do
            {
                try {
                    var creds = auth.GetAuthCredentials();
                    creds.ClientVersion = clientVersion;
                    session             = await LoginService.Login(creds);
                } catch (InvocationException x) when(x.RootCause is ClientVersionMismatchException)
                {
                    var inner = (ClientVersionMismatchException)x.RootCause;

                    clientVersion = (string)inner.SubstitutionArguments[1];
                    Log("Patch (DDragon outdated): " + clientVersion);
                }
            } while (session == null);

            string bc = $"bc-{session.AccountSummary.AccountId}";
            string gn = $"gn-{session.AccountSummary.AccountId}";
            string cn = $"cn-{session.AccountSummary.AccountId}";
            await Task.WhenAll(
                rtmp.SubscribeAsync("my-rtmps", "messagingDestination", "bc", bc),
                rtmp.SubscribeAsync("my-rtmps", "messagingDestination", gn, gn),
                rtmp.SubscribeAsync("my-rtmps", "messagingDestination", cn, cn)
                );

            await rtmp.LoginAsync(auth.Username.ToLower(), session.Token);

            string state = await AccountService.GetAccountState();

            if (state != "ENABLED")
            {
                Log(state);
                throw new AuthenticationException("Not Enabled: " + state);
            }

            this.LoginQueue   = auth.Content;
            this.loginSession = session;
            this.Me           = await summoner.Connect(session);

            try {
                Authed?.Invoke(this, EventArgs.Empty);
            } catch (Exception x) {
                Log("Caught exception while dispatching auth: " + x);
            }

            BackEndServer.Async("/kappa/defer/auth", new JSONObject());

            new Thread(HeartBeatLoop)
            {
                IsBackground = true
            }.Start();
        }
Exemplo n.º 7
0
 internal void Exit()
 {
     BackEndServer.Stop();
 }
Exemplo n.º 8
0
 // Token: 0x0600057E RID: 1406 RVA: 0x0001EC50 File Offset: 0x0001CE50
 protected override BackEndServer GetDownLevelClientAccessServer(AnchorMailbox anchorMailbox, BackEndServer backEndServer)
 {
     return(backEndServer);
 }
        // Token: 0x060005B1 RID: 1457 RVA: 0x0001F974 File Offset: 0x0001DB74
        protected override AnchoredRoutingTarget TryDirectTargetCalculation()
        {
            BackEndServer randomDownLevelClientAccessServer = DownLevelServerManager.Instance.GetRandomDownLevelClientAccessServer();

            return(new AnchoredRoutingTarget(new AnonymousAnchorMailbox(this), randomDownLevelClientAccessServer));
        }
Exemplo n.º 10
0
 // Token: 0x060004FE RID: 1278 RVA: 0x00008C7B File Offset: 0x00006E7B
 protected override void RedirectIfNeeded(BackEndServer mailboxServer)
 {
 }
Exemplo n.º 11
0
        protected override BackEndServer GetDownLevelClientAccessServer(AnchorMailbox anchorMailbox, BackEndServer mailboxServer)
        {
            BackEndServer deterministicBackEndServer = HttpProxyBackEndHelper.GetDeterministicBackEndServer <WebServicesService>(mailboxServer, anchorMailbox.ToCookieKey(), this.ClientAccessType);

            ExTraceGlobals.VerboseTracer.TraceDebug <int, BackEndServer, BackEndServer>((long)this.GetHashCode(), "[OWAUserPhotoProxyRequestHandler::GetDownLevelClientAccessServer] Context {0}; Overriding down level target {0} with latest version backend {1}.", base.TraceContext, mailboxServer, deterministicBackEndServer);
            return(deterministicBackEndServer);
        }
Exemplo n.º 12
0
 // Token: 0x060000E2 RID: 226 RVA: 0x0000500A File Offset: 0x0000320A
 public override BackEndCookieEntryBase BuildCookieEntryForTarget(BackEndServer routingTarget, bool proxyToDownLevel, bool useResourceForest, bool organizationAware)
 {
     return(null);
 }
Exemplo n.º 13
0
        protected virtual void CreateGroupsForLocalMailboxes(List <MailboxInfo> localMailboxes)
        {
            Dictionary <Guid, BackEndServer> dictionary = new Dictionary <Guid, BackEndServer>(localMailboxes.Count);

            for (int i = 0; i < localMailboxes.Count; i++)
            {
                Guid key = (localMailboxes[i].Type == MailboxType.Primary) ? localMailboxes[i].MdbGuid : localMailboxes[i].ArchiveDatabase;
                if (!dictionary.ContainsKey(key))
                {
                    dictionary.Add(key, null);
                }
            }
            for (int j = 0; j < localMailboxes.Count; j++)
            {
                Guid guid = (localMailboxes[j].Type == MailboxType.Primary) ? localMailboxes[j].MdbGuid : localMailboxes[j].ArchiveDatabase;
                try
                {
                    BackEndServer backEndServer = null;
                    dictionary.TryGetValue(guid, out backEndServer);
                    if (backEndServer == null)
                    {
                        Factory.Current.MailboxGroupGeneratorTracer.TraceDebug <Guid, Guid>((long)this.GetHashCode(), "Correlation Id:{0}. Retrieving backend servers for database {1} and all the databases in the DAG", this.callerInfo.QueryCorrelationId, guid);
                        int k = EwsEndpointDiscovery.MailboxServerLocatorRetryCount;
                        while (k > 0)
                        {
                            using (MailboxServerLocator mailboxServerLocator = MailboxServerLocator.CreateWithResourceForestFqdn(guid, null))
                            {
                                Stopwatch stopwatch = new Stopwatch();
                                stopwatch.Start();
                                IAsyncResult asyncResult = mailboxServerLocator.BeginGetServer(null, null);
                                bool         flag        = asyncResult.AsyncWaitHandle.WaitOne(EwsEndpointDiscovery.MailboxServerLocatorTimeout);
                                if (flag)
                                {
                                    BackEndServer value = mailboxServerLocator.EndGetServer(asyncResult);
                                    stopwatch.Stop();
                                    Factory.Current.EventLog.LogEvent(InfoWorkerEventLogConstants.Tuple_DiscoveryMailboxServerLocatorTime, null, new object[]
                                    {
                                        this.callerInfo.QueryCorrelationId.ToString(),
                                        guid.ToString(),
                                        stopwatch.ElapsedMilliseconds
                                    });
                                    dictionary[guid] = value;
                                    foreach (KeyValuePair <Guid, BackEndServer> keyValuePair in mailboxServerLocator.AvailabilityGroupServers)
                                    {
                                        if (dictionary.ContainsKey(keyValuePair.Key))
                                        {
                                            Factory.Current.MailboxGroupGeneratorTracer.TraceDebug <Guid, Guid, Guid>((long)this.GetHashCode(), "Correlation Id:{0}. While queried backend for {1}, also retrieved backend for {2}", this.callerInfo.QueryCorrelationId, guid, keyValuePair.Key);
                                            dictionary[keyValuePair.Key] = keyValuePair.Value;
                                        }
                                    }
                                    break;
                                }
                                stopwatch.Stop();
                                Factory.Current.EventLog.LogEvent(InfoWorkerEventLogConstants.Tuple_DiscoveryServerLocatorTimeout, null, new object[]
                                {
                                    guid.ToString(),
                                    this.callerInfo.QueryCorrelationId.ToString(),
                                    EwsEndpointDiscovery.MailboxServerLocatorRetryCount - k + 1
                                });
                                k--;
                            }
                        }
                    }
                    if (dictionary[guid] != null)
                    {
                        this.AddMailboxToGroup(localMailboxes[j], dictionary[guid]);
                    }
                    else
                    {
                        Factory.Current.MailboxGroupGeneratorTracer.TraceDebug <Guid, Guid, SmtpAddress>((long)this.GetHashCode(), "Correlation Id:{0}. Couldn't find the backend for database {1}. So adding an error group for mailbox {2}", this.callerInfo.QueryCorrelationId, guid, localMailboxes[j].PrimarySmtpAddress);
                        this.AddMailboxToGroup(localMailboxes[j], new GroupId(new DatabaseLocationUnavailableException(Strings.DatabaseLocationUnavailable(localMailboxes[j].PrimarySmtpAddress.ToString()))));
                    }
                }
                catch (MailboxServerLocatorException error)
                {
                    Factory.Current.MailboxGroupGeneratorTracer.TraceDebug <Guid, Guid>((long)this.GetHashCode(), "Correlation Id:{0}. Encountered an Exception while querying backend for database {1}", this.callerInfo.QueryCorrelationId, guid);
                    this.AddMailboxToGroup(localMailboxes[j], new GroupId(error));
                }
            }
        }
        // Token: 0x060004B5 RID: 1205 RVA: 0x00019F74 File Offset: 0x00018174
        protected override BackEndServer GetDownLevelClientAccessServer(AnchorMailbox anchorMailbox, BackEndServer mailboxServer)
        {
            if (mailboxServer.Version < Server.E14MinVersion)
            {
                return(this.GetE12TargetServer(mailboxServer));
            }
            Uri           uri = null;
            BackEndServer downLevelClientAccessServer = DownLevelServerManager.Instance.GetDownLevelClientAccessServer <ServiceType>(anchorMailbox, mailboxServer, this.ClientAccessType, base.Logger, HttpProxyGlobals.ProtocolType == 4 || HttpProxyGlobals.ProtocolType == 5 || HttpProxyGlobals.ProtocolType == 1, out uri);

            if (uri != null)
            {
                Uri uri2 = this.UpdateExternalRedirectUrl(uri);
                if (Uri.Compare(uri2, base.ClientRequest.Url, UriComponents.Host, UriFormat.Unescaped, StringComparison.Ordinal) != 0)
                {
                    if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(1))
                    {
                        ExTraceGlobals.VerboseTracer.TraceDebug <string>((long)this.GetHashCode(), "[BEServerCookieProxyRequestHandler::GetDownLevelClientAccessServer]: Stop processing and redirect to {0}.", uri2.ToString());
                    }
                    throw new HttpException(302, uri2.ToString());
                }
            }
            return(downLevelClientAccessServer);
        }
 // Token: 0x060004B7 RID: 1207 RVA: 0x0001A044 File Offset: 0x00018244
 protected virtual BackEndServer GetE12TargetServer(BackEndServer mailboxServer)
 {
     return(MailboxServerCache.Instance.GetRandomE15Server(this));
 }
Exemplo n.º 16
0
        // Token: 0x06000239 RID: 569 RVA: 0x0000B140 File Offset: 0x00009340
        public void Add(Guid database, BackEndServer server, string resourceForestFqdn, long failoverSequenceNumber, IRequestContext requestContext)
        {
            MailboxServerCacheEntry entry = new MailboxServerCacheEntry(server, resourceForestFqdn, failoverSequenceNumber);

            this.Add(database, entry, requestContext);
        }