예제 #1
0
        public override void ConnectClients()
        {
            base.ConnectClients();

            Assert.AreEqual(XmppState.Connected, this.client1.State);
            Assert.AreEqual(XmppState.Connected, this.client2.State);

            this.receptor = new XmppEventReceptor(this.client2);
            this.sink     = new XmppEventSink("XMPP Event Sink", this.client1, this.client2.FullJID, true);

            Log.Register(this.sink);
        }
예제 #2
0
        public override void DisposeClients()
        {
            if (this.sink != null)
            {
                Log.Unregister(this.sink);
                this.sink.Dispose();
                this.sink = null;
            }

            if (this.receptor != null)
            {
                this.receptor.Dispose();
                this.receptor = null;
            }

            base.DisposeClients();
        }
예제 #3
0
        private void DestroyXmppClient()
        {
            this.reconnectTimer?.Dispose();
            this.reconnectTimer = null;
            this.contracts.DestroyClients();
            if (!(this.xmppClient is null))
            {
                this.xmppClient.OnError           -= XmppClient_Error;
                this.xmppClient.OnConnectionError -= XmppClient_ConnectionError;
                this.xmppClient.OnStateChanged    -= XmppClient_StateChanged;
                this.OnConnectionStateChanged(new ConnectionStateChangedEventArgs(XmppState.Offline, this.userInitiatedLogInOrOut));
                if (!(this.xmppEventSink is null))
                {
                    this.logService.RemoveListener(this.xmppEventSink);
                    this.xmppEventSink.Dispose();
                    this.xmppEventSink = null;
                }

                this.xmppClient.Dispose();
            }
            this.xmppClient = null;
        }
예제 #4
0
        private static void DisposeClient()
        {
            minuteTimer?.Dispose();
            minuteTimer = null;

            contracts?.Dispose();
            contracts = null;

            fileUpload?.Dispose();
            fileUpload = null;

#if DEBUG
            if (!(xmppEventSink is null))
            {
                Log.Unregister(xmppEventSink);

                xmppEventSink.Dispose();
                xmppEventSink = null;
            }
#endif
            xmpp?.Dispose();
            xmpp = null;
        }
예제 #5
0
        private async Task CreateXmppClient(bool CanCreateKeys)
        {
            this.xmppThread = this.startupProfiler?.CreateThread("XMPP", ProfilerThreadType.StateMachine);
            this.xmppThread?.Start();
            this.xmppThread?.Idle();

            if (isCreatingClient)
            {
                return;
            }

            try
            {
                isCreatingClient = true;

                if (!(this.xmppClient is null))
                {
                    DestroyXmppClient();
                }
                if (this.xmppClient is null ||
                    this.domainName != this.tagProfile.Domain ||
                    this.accountName != this.tagProfile.Account ||
                    this.passwordHash != this.tagProfile.PasswordHash ||
                    this.passwordHashMethod != this.tagProfile.PasswordHashMethod)
                {
                    this.domainName         = this.tagProfile.Domain;
                    this.accountName        = this.tagProfile.Account;
                    this.passwordHash       = this.tagProfile.PasswordHash;
                    this.passwordHashMethod = this.tagProfile.PasswordHashMethod;

                    (string hostName, int portNumber, bool isIpAddress) = await this.networkService.LookupXmppHostnameAndPort(domainName);

                    this.xmppClient = new XmppClient(hostName, portNumber, accountName, passwordHash, passwordHashMethod, Constants.LanguageCodes.Default, appAssembly, this.sniffer)
                    {
                        TrustServer      = !isIpAddress,
                        AllowCramMD5     = false,
                        AllowDigestMD5   = false,
                        AllowPlain       = false,
                        AllowEncryption  = true,
                        AllowScramSHA1   = true,
                        AllowScramSHA256 = true
                    };

                    this.xmppClient.RequestRosterOnStartup = false;
                    this.xmppClient.OnStateChanged        += XmppClient_StateChanged;
                    this.xmppClient.OnConnectionError     += XmppClient_ConnectionError;
                    this.xmppClient.OnError += XmppClient_Error;
                    this.xmppEventSink       = new XmppEventSink("XMPP Event Sink", this.xmppClient, this.tagProfile.LogJid, false);

                    if (!string.IsNullOrWhiteSpace(this.tagProfile.LegalJid))
                    {
                        await this.contracts.CreateClients(CanCreateKeys);
                    }

                    this.IsLoggedOut = false;
                    this.xmppClient.Connect(isIpAddress ? string.Empty : domainName);

                    bool connectSucceeded = false;
                    // Await connected state during registration or user initiated log in, but not otherwise.
                    if (!this.tagProfile.IsCompleteOrWaitingForValidation() || this.userInitiatedLogInOrOut)
                    {
                        connectSucceeded = await this.WaitForConnectedState(Constants.Timeouts.XmppConnect);
                    }
                    // This saves startup time for registered users with a complete profile
                    if (this.tagProfile.IsComplete())
                    {
                        connectSucceeded = true;
                    }

                    if (!connectSucceeded)
                    {
                        this.logService.LogWarning("Connect to XMPP server '{0}' failed for account '{1}' with the specified timeout of {2} ms",
                                                   this.domainName,
                                                   this.accountName,
                                                   (int)Constants.Timeouts.XmppConnect.TotalMilliseconds);
                    }

                    this.RecreateReconnectTimer();
                }
            }
            finally
            {
                isCreatingClient = false;
            }
        }