/// <summary> /// Loads one specific XMPPAccount and subscribes to all its events. /// </summary> /// <param name="account">The account which should get loaded.</param> /// <returns>Returns a new XMPPClient instance.</returns> private XMPPClient LoadAccount(XMPPAccount account) { XMPPClient client = new XMPPClient(account); client.connection.TCP_CONNECTION.disableConnectionTimeout = Settings.getSettingBoolean(SettingsConsts.DEBUG_DISABLE_TCP_TIMEOUT); client.connection.TCP_CONNECTION.disableTlsUpgradeTimeout = Settings.getSettingBoolean(SettingsConsts.DEBUG_DISABLE_TLS_TIMEOUT); // Enable OMEMO: OmemoStore signalProtocolStore = new OmemoStore(account); // Generate OMEMO keys if necessary: if (!account.omemoKeysGenerated) { account.generateOmemoKeys(); AccountDBManager.INSTANCE.setAccount(account, true, false); } client.enableOmemo(signalProtocolStore); // Sometimes the DB fails and only stores less than 100 OMEMO pre keys. // So if we detect an issue with that generate a new batch of OMEMO pre keys and announce the new ones. if (account.OMEMO_PRE_KEYS.Count < 100) { Logger.Warn("Only " + account.OMEMO_PRE_KEYS.Count + " found. Generating a new set."); account.OMEMO_PRE_KEYS.Clear(); account.OMEMO_PRE_KEYS.AddRange(CryptoUtils.generateOmemoPreKeys()); account.omemoBundleInfoAnnounced = false; AccountDBManager.INSTANCE.setAccount(account, true, false); } return(client); }
/// <summary> /// Loads one specific XMPPAccount and subscribes to all its events. /// </summary> /// <param name="acc">The account which should get loaded.</param> /// <returns></returns> private XMPPClient loadAccount(XMPPAccount acc) { XMPPClient c = new XMPPClient(acc); c.connection.TCP_CONNECTION.disableConnectionTimeout = Settings.getSettingBoolean(SettingsConsts.DEBUG_DISABLE_TCP_TIMEOUT); c.connection.TCP_CONNECTION.disableTlsUpgradeTimeout = Settings.getSettingBoolean(SettingsConsts.DEBUG_DISABLE_TLS_TIMEOUT); // Enable OMEMO: OmemoStore signalProtocolStore = new OmemoStore(acc); // Generate OMEMO keys if necessary: if (!acc.omemoKeysGenerated) { acc.generateOmemoKeys(); AccountDBManager.INSTANCE.setAccount(acc, true, false); } c.enableOmemo(signalProtocolStore); // Sometimes the DB fails and only stores less than 100 OMEMO pre keys. // So if we detect an issue with that generate a new batch of OMEMO pre keys and announce the new ones. if (acc.OMEMO_PRE_KEYS.Count < 100) { Logger.Warn("Only " + acc.OMEMO_PRE_KEYS.Count + " found. Generating a new set."); acc.OMEMO_PRE_KEYS.Clear(); acc.OMEMO_PRE_KEYS.AddRange(CryptoUtils.generateOmemoPreKeys()); acc.omemoBundleInfoAnnounced = false; AccountDBManager.INSTANCE.setAccount(acc, true, false); } // Ensure no event gets bound multiple times: unsubscribeFromEvents(c); c.NewChatMessage += C_NewChatMessage; c.NewRoosterMessage += C_NewRoosterMessage; c.NewPresence += C_NewPresence; // Requesting roster if connected c.ConnectionStateChanged += C_ConnectionStateChanged; c.MessageSend += C_MessageSend; c.NewBookmarksResultMessage += C_NewBookmarksResultMessage; c.NewDeliveryReceipt += C_NewDeliveryReceipt; c.getXMPPAccount().PropertyChanged += ConnectionHandler_PropertyChanged; c.OmemoSessionBuildError += C_OmemoSessionBuildError; return(c); }