QtDataSync  4.2.0
A simple offline-first synchronisation framework, to synchronize data of Qt applications between devices
Public Types | Public Member Functions | Static Public Member Functions | Properties | List of all members
QtDataSync::Setup Class Reference

The class to setup and create datasync instances. More...

#include <setup.h>

Public Types

enum  SyncPolicy { PreferChanged, PreferDeleted }
 Defines the possible policies on how to treat merge conflicts between change and delete. More...
 
enum  SignatureScheme { RSA_PSS_SHA3_512, ECDSA_ECP_SHA3_512, ECNR_ECP_SHA3_512 }
 The signature schemes supported for Setup::signatureScheme. More...
 
enum  EncryptionScheme { RSA_OAEP_SHA3_512, ECIES_ECP_SHA3_512 }
 The encryption schemes supported for Setup::encryptionScheme. More...
 
enum  CipherScheme {
  AES_EAX, AES_GCM, TWOFISH_EAX, TWOFISH_GCM,
  SERPENT_EAX, SERPENT_GCM, IDEA_EAX
}
 The symmetric cipher schemes supported for Setup::cipherScheme. More...
 
enum  EllipticCurve {
  secp112r1, secp128r1, secp160r1, secp192r1,
  secp224r1, secp256r1, secp384r1, secp521r1,
  brainpoolP160r1, brainpoolP192r1, brainpoolP224r1, brainpoolP256r1,
  brainpoolP320r1, brainpoolP384r1, brainpoolP512r1, secp112r2,
  secp128r2, secp160r2, secp160k1, secp192k1,
  secp224k1, secp256k1
}
 Elliptic curves supported as key parameter for Setup::signatureKeyParam and Setup::encryptionKeyParam in case an ECC scheme is used.
 
enum  EventMode { EventMode::Unchanged, EventMode::Enabled, EventMode::Disabled }
 Possible values for the event logging mode change. More...
 
using FatalErrorHandler = std::function< void(QString, QString, const QMessageLogContext &)>
 Typedef of an error handler function. See Setup::fatalErrorHandler.
 

Public Member Functions

 Setup (Setup &&other) noexcept
 Move constructor.
 
Setupoperator= (Setup &&other) noexcept
 Move assignment operator.
 
QString localDir () const
 READ accessor for Setup::localDir.
 
QUrl remoteObjectHost () const
 READ accessor for Setup::remoteObjectHost.
 
QJsonSerializerserializer () const
 READ accessor for Setup::serializer.
 
ConflictResolverconflictResolver () const
 READ accessor for Setup::conflictResolver.
 
FatalErrorHandler fatalErrorHandler () const
 READ accessor for Setup::fatalErrorHandler.
 
int cacheSize () const
 READ accessor for Setup::cacheSize.
 
bool persistDeletedVersion () const
 READ accessor for Setup::persistDeletedVersion.
 
SyncPolicy syncPolicy () const
 READ accessor for Setup::syncPolicy.
 
QSslConfiguration sslConfiguration () const
 READ accessor for Setup::sslConfiguration.
 
RemoteConfig remoteConfiguration () const
 READ accessor for Setup::remoteConfiguration.
 
QString keyStoreProvider () const
 READ accessor for Setup::keyStoreProvider.
 
SignatureScheme signatureScheme () const
 READ accessor for Setup::signatureScheme.
 
QVariant signatureKeyParam () const
 READ accessor for Setup::signatureKeyParam.
 
EncryptionScheme encryptionScheme () const
 READ accessor for Setup::encryptionScheme.
 
QVariant encryptionKeyParam () const
 READ accessor for Setup::encryptionKeyParam.
 
CipherScheme cipherScheme () const
 READ accessor for Setup::cipherScheme.
 
qint32 cipherKeySize () const
 READ accessor for Setup::cipherKeySize.
 
EventMode eventLoggingMode () const
 READ accessor for Setup::eventLoggingMode.
 
SetupsetLocalDir (QString localDir)
 WRITE accessor for Setup::localDir.
 
SetupsetRemoteObjectHost (QUrl remoteObjectHost)
 WRITE accessor for Setup::remoteObjectHost.
 
SetupsetSerializer (QJsonSerializer *serializer)
 WRITE accessor for Setup::serializer.
 
SetupsetConflictResolver (ConflictResolver *conflictResolver)
 WRITE accessor for Setup::conflictResolver.
 
SetupsetFatalErrorHandler (const FatalErrorHandler &fatalErrorHandler)
 WRITE accessor for Setup::fatalErrorHandler.
 
SetupsetCacheSize (int cacheSize)
 WRITE accessor for Setup::cacheSize.
 
SetupsetPersistDeletedVersion (bool persistDeletedVersion)
 WRITE accessor for Setup::persistDeletedVersion.
 
SetupsetSyncPolicy (SyncPolicy syncPolicy)
 WRITE accessor for Setup::syncPolicy.
 
SetupsetSslConfiguration (QSslConfiguration sslConfiguration)
 WRITE accessor for Setup::sslConfiguration.
 
SetupsetRemoteConfiguration (RemoteConfig remoteConfiguration)
 WRITE accessor for Setup::remoteConfiguration.
 
SetupsetKeyStoreProvider (QString keyStoreProvider)
 WRITE accessor for Setup::keyStoreProvider.
 
SetupsetSignatureScheme (SignatureScheme signatureScheme)
 WRITE accessor for Setup::signatureScheme.
 
SetupsetSignatureKeyParam (QVariant signatureKeyParam)
 WRITE accessor for Setup::signatureKeyParam.
 
SetupsetEncryptionScheme (EncryptionScheme encryptionScheme)
 WRITE accessor for Setup::encryptionScheme.
 
SetupsetEncryptionKeyParam (QVariant encryptionKeyParam)
 WRITE accessor for Setup::encryptionKeyParam.
 
SetupsetCipherScheme (CipherScheme cipherScheme)
 WRITE accessor for Setup::cipherScheme.
 
SetupsetCipherKeySize (qint32 cipherKeySize)
 WRITE accessor for Setup::cipherKeySize.
 
SetupsetEventLoggingMode (EventMode eventLoggingMode)
 WRITE accessor for Setup::eventLoggingMode.
 
SetupresetLocalDir ()
 RESET accessor for Setup::localDir.
 
SetupresetRemoteObjectHost ()
 RESET accessor for Setup::remoteObjectHost.
 
SetupresetSerializer ()
 RESET accessor for Setup::serializer.
 
SetupresetConflictResolver ()
 RESET accessor for Setup::conflictResolver.
 
SetupresetFatalErrorHandler ()
 RESET accessor for Setup::fatalErrorHandler.
 
SetupresetCacheSize ()
 RESET accessor for Setup::cacheSize.
 
SetupresetPersistDeletedVersion ()
 RESET accessor for Setup::persistDeletedVersion.
 
SetupresetSyncPolicy ()
 RESET accessor for Setup::syncPolicy.
 
SetupresetSslConfiguration ()
 RESET accessor for Setup::sslConfiguration.
 
SetupresetRemoteConfiguration ()
 RESET accessor for Setup::remoteConfiguration.
 
SetupresetKeyStoreProvider ()
 RESET accessor for Setup::keyStoreProvider.
 
SetupresetSignatureScheme ()
 RESET accessor for Setup::signatureScheme.
 
SetupresetSignatureKeyParam ()
 RESET accessor for Setup::signatureKeyParam.
 
SetupresetEncryptionScheme ()
 RESET accessor for Setup::encryptionScheme.
 
SetupresetEncryptionKeyParam ()
 RESET accessor for Setup::encryptionKeyParam.
 
SetupresetCipherScheme ()
 RESET accessor for Setup::cipherScheme.
 
SetupresetCipherKeySize ()
 RESET accessor for Setup::cipherKeySize.
 
SetupresetEventLoggingMode ()
 RESET accessor for Setup::resetEventLoggingMode.
 
SetupsetAccount (const QJsonObject &importData, bool keepData=false, bool allowFailure=false)
 Sets an account to be imported on creation of the instance. More...
 
SetupsetAccount (const QByteArray &importData, bool keepData=false, bool allowFailure=false)
 Sets an account to be imported on creation of the instance. More...
 
SetupsetAccountTrusted (const QJsonObject &importData, const QString &password, bool keepData=false, bool allowFailure=false)
 Sets an account to be imported on creation of the instance. More...
 
SetupsetAccountTrusted (const QByteArray &importData, const QString &password, bool keepData=false, bool allowFailure=false)
 Sets an account to be imported on creation of the instance. More...
 
void create (const QString &name=DefaultSetup)
 Creates a datasync instance from this setup with the given name. More...
 
bool createPassive (const QString &name=DefaultSetup, int timeout=30000)
 Creates a passive setup with the given name that connects to the primary datasync instance. More...
 

Static Public Member Functions

static bool exists (const QString &name=DefaultSetup)
 Checks if a setup for the given name does already exist. More...
 
static void setCleanupTimeout (unsigned long timeout)
 Sets the maximum timeout for shutting down setups. More...
 
static void removeSetup (const QString &name, bool waitForFinished=false)
 Stops the datasync instance and removes it. More...
 
static QStringList keystoreProviders ()
 Returns a list of all keystore providers defined via the plugins. More...
 
static QStringList availableKeystores ()
 Returns a list of all keystore providers that are actually available for use. More...
 
static bool keystoreAvailable (const QString &provider)
 Checks if the given keystore provider is available. More...
 
static QString defaultKeystoreProvider ()
 Returns the default provider to be used based on the current platform and the available providers. More...
 
static KeyStoreloadKeystore (QObject *parent=nullptr, const QString &setupName=DefaultSetup)
 Create and load akeystore instance from the default provider. More...
 
static KeyStoreloadKeystore (const QString &provider, QObject *parent=nullptr, const QString &setupName=DefaultSetup)
 Create and load akeystore instance from the given provider. More...
 

Properties

QString localDir
 The local storage directoy used by the instance. More...
 
QUrl remoteObjectHost
 The url to be used to host the remote object sources, and to connect to to acquire the replicas. More...
 
QJsonSerializer serializer
 The serializer to be used to serialize and deserialize data to and from the store. More...
 
QtDataSync::ConflictResolver conflictResolver
 An optional conflict resolver to handle merge conflicts. More...
 
FatalErrorHandler fatalErrorHandler
 An alternative handler for fatal errors. More...
 
int cacheSize
 The size of the internal database cache, in bytes. More...
 
bool persistDeletedVersion
 Specify whether deleted datasets should persist. More...
 
SyncPolicy syncPolicy
 The policiy for how to handle conflicts. More...
 
QSslConfiguration sslConfiguration
 The ssl configuration to be used to connect to the remote. More...
 
QtDataSync::RemoteConfig remoteConfiguration
 The configuration to be used to connect to the remote. More...
 
QString keyStoreProvider
 The name of the preferred keystore provider. More...
 
SignatureScheme signatureScheme
 The algorithmic scheme to be used for new signature keys. More...
 
QVariant signatureKeyParam
 The generation parameter for the signature key. More...
 
EncryptionScheme encryptionScheme
 The algorithmic scheme to be used for new encryption keys. More...
 
QVariant encryptionKeyParam
 The generation parameter for the encryption key. More...
 
CipherScheme cipherScheme
 The algorithmic scheme to be used for new secret exchange keys (which are symmetric) More...
 
qint32 cipherKeySize
 The size in bytes for the secret exchange key (which is symmetric) More...
 
EventMode eventLoggingMode
 The logging mode for database change events. More...
 

Detailed Description

The class to setup and create datasync instances.

The Setup class is what you need for configuration. Before you can use datasync, you always have to create at least one instance by using this setup. For most applications, it's sufficient to simply use the default constructed setup and set the remote configuration. However, if you want to use custom implementations or change the way specific components behave, the setup is where to do so. Once all the configuration part has been done, you can call create() (or createPassive()) to create the instance.

See also
Setup::create, Setup::createPassive, Setup::removeSetup, Defaults

Definition at line 59 of file setup.h.

Member Enumeration Documentation

◆ CipherScheme

The symmetric cipher schemes supported for Setup::cipherScheme.

Enumerator
AES_EAX 

AES operating in EAX authenticated encryption mode.

AES_GCM 

AES operating in GCM authenticated encryption mode.

TWOFISH_EAX 

Twofish operating in EAX authenticated encryption mode.

TWOFISH_GCM 

Twofish operating in GCM authenticated encryption mode.

SERPENT_EAX 

Serpent operating in EAX authenticated encryption mode.

SERPENT_GCM 

Serpent operating in GCM authenticated encryption mode.

IDEA_EAX 

IDEA operating in EAX authenticated encryption mode.

Definition at line 128 of file setup.h.

◆ EncryptionScheme

The encryption schemes supported for Setup::encryptionScheme.

Enumerator
RSA_OAEP_SHA3_512 

RSA in OAEP mode with Sha3 hash of 512 bits.

ECIES_ECP_SHA3_512 

ECIES on prime curves with Sha3 hash of 512 bits (Requires at least crypto++ 6.0)

Definition at line 121 of file setup.h.

◆ EventMode

Possible values for the event logging mode change.

Enumerator
Unchanged 

Keep as is. If it was previously enabled, it stays enabled. Same goes for the disabled state.

Enabled 

Enable event logging, regardless of the previous state.

Disabled 

Disable event logging, regardless of the previous state.

Definition at line 170 of file setup.h.

◆ SignatureScheme

The signature schemes supported for Setup::signatureScheme.

Enumerator
RSA_PSS_SHA3_512 

RSA in PSS mode with Sha3 hash of 512 bits.

ECDSA_ECP_SHA3_512 

ECDSA on prime curves with Sha3 hash of 512 bits.

ECNR_ECP_SHA3_512 

ECNR on prime curves with Sha3 hash of 512 bits.

Definition at line 113 of file setup.h.

◆ SyncPolicy

Defines the possible policies on how to treat merge conflicts between change and delete.

Enumerator
PreferChanged 

Keep the changed entry.

PreferDeleted 

< Discard the change and keep the entry deleted

Definition at line 106 of file setup.h.

Member Function Documentation

◆ availableKeystores()

QtDataSync::Setup::availableKeystores ( )
static

Returns a list of all keystore providers that are actually available for use.

Returns
All providers the are currently usable

This list contains only the providers that can currently access the keystore and thus are usable. For a list of all existing providers, use keystoreProviders()

Note
If you only want to check if a specific provider is available, it is more efficient to use keystoreAvailable(), as this method will perform the same for all existing keystores.
See also
Setup::keystoreProviders, Setup::keystoreAvailable

◆ create()

QtDataSync::Setup::create ( const QString name = DefaultSetup)

Creates a datasync instance from this setup with the given name.

Parameters
nameThe unique name of the setup to be created
Exceptions
SetupExistsExceptionIf a datasync instance with the same name already exists
SetupLockedExceptionIf the local directory is already locked by another instance

This method creates and starts a new datasync instance from the configuration of the setup. It will automatically launch the new thread and initialize it. This is done asynchronously, but you don't need to wait for it. After this method returned, you can use the instance as you please, with i.e. DataStore, SyncManager, etc.

Attention
If you get a SetupLockedException, it's propably because two instances of your application have started, and try to use the same local storage directory. You can either make your application a single instance app (See QSingleInstance), use different local dirs per instance. Or make use of passive setups.
Warning
After this method, you must not access any other of the setups methods. Consider it deleted. Not following this will propably crash your application.
See also
Setup::createPassive, Setup::removeSetup

◆ createPassive()

QtDataSync::Setup::createPassive ( const QString name = DefaultSetup,
int  timeout = 30000 
)

Creates a passive setup with the given name that connects to the primary datasync instance.

Parameters
nameThe unique name of the setup to be created
timeoutAn optional timeout to wait for the setup to connect to the active instance
Returns
true if the setup could connect to the active setup, false if not
Exceptions
SetupExistsExceptionIf a datasync instance with the same name already exists

The passive setup differs from the active one greatly. It does not create a datasync instance, but instead tries to connect to an active one. This means, you typically have one process that uses a normal (active) setup, and one or more other processes, that connect to it by using a passive setup. If the setup fails to connect within the timeout, false is returned.

The behaviour also depends on the timeout. Possible values:

  • < 0: Wait until the connection is ready, infinitely
  • > 0: Wait until the connection is ready, or at most timeout milliseconds.
  • = 0: Only create the internal instances and let the initialize, do not wait for a connection
Attention
In order for the passive setup to connect to the primary one, it must be able to connect to the remote object host. This means that Setup::remoteObjectHost must be accessible from the passive setup. Passive setups are typically used in a multi process context, which means you will have to use a local or tcp url on both, the active and the passive setups.

After beeing created, the passive setup can be used just like a normal setup, as long as it did successfully connect to the active one. Classes like the SyncManager and AccountManager will simply connect to the active instance. The DataStore classes access data directly, but use the active instance for communicating changes. This means data changes will still be atomic, but the corresponding change signals take a while to be delivered (the must go through the active instance due to technical reasons)

Note
If the method returns false you can still use the setup. This only means that no active instance was found, which makes the Manager classes do nothing, and prevents the store classes from emitting any change signals. Accessing the stores however is still possible, and no data is lost. However, since the change signals are not working, most applications will not work correctly without having an active setup available. So no crashes or fatal errors. It is recommended to show an error to the user and gracefully exit in such cases.
See also
Setup::create, Setup::removeSetup, Setup::remoteObjectHost

◆ defaultKeystoreProvider()

QtDataSync::Setup::defaultKeystoreProvider ( )
static

Returns the default provider to be used based on the current platform and the available providers.

Returns
The default provider to be used, limited to the ones actually available

Internally, the method has a list of all providers for each platform. It will check for all of these they are available and return the first one that actually is. If no provider is found, the plain provider is returned, even if it is not available. The list is sorted as follows:

  1. The provider in the QTDATASYNC_KEYSTORE environment variable
  2. Windows only: Windows credential store
  3. Apple only: Keychain
  4. Secret Service
  5. KWallet
  6. Plain
See also
Setup::keystoreProviders, Setup::availableKeystores

◆ exists()

QtDataSync::Setup::exists ( const QString name = DefaultSetup)
static

Checks if a setup for the given name does already exist.

Parameters
nameThe name of the setup to check for
Returns
true if a setup already exists for that name, false if not
See also
Setup::create, SetupExistsException

◆ keystoreAvailable()

QtDataSync::Setup::keystoreAvailable ( const QString provider)
static

Checks if the given keystore provider is available.

Parameters
providerThe name of the keystore type to be checked
Returns
true if the provider exists and is usable, false if not

A useable provider is one that can access it's keystore and thus be used. If order to find out whether a provider exists, use keystoreProviders().

Internally, the plugin gets temporarily loaded in order to check if the keystore is accessible. This may take a moment to complete, depending on the keystore beeing used.

See also
Setup::keystoreProviders, Setup::availableKeystores

◆ keystoreProviders()

QtDataSync::Setup::keystoreProviders ( )
static

Returns a list of all keystore providers defined via the plugins.

Returns
All providers possible via the plugins

The list contains all providers of all found plugins. In order to obtain a list of providers that are actually currently usable (available), use availableKeystores()

See also
Setup::availableKeystores, Setup::keystoreAvailable

◆ loadKeystore() [1/2]

QtDataSync::Setup::loadKeystore ( QObject parent = nullptr,
const QString setupName = DefaultSetup 
)
static

Create and load akeystore instance from the default provider.

Parameters
parentThe parent object to set as the keystores parent
setupNameThe name of the setup to create the keystore for
Returns
A newly created KeyStore instance or nullptr if the keystore does not exist
Exceptions
SetupDoesNotExistExceptionIf the setup specified by setupName does not exist (yet)
QExceptionIf something went wrong while loading the plugin

This method simply creates a keystore instance. This can be useful if you want to use a keystore outside of datasync to store your own secrets there.

Note
The keystore still requires a valid and running datasync instance, as it is needed for logging etc. This is only due to how the keystore is designed, as external access was originally not planned, and may change in the future.
See also
KeyStore, Setup::keystoreProviders, Setup::defaultKeystoreProvider

◆ loadKeystore() [2/2]

QtDataSync::Setup::loadKeystore ( const QString provider,
QObject parent = nullptr,
const QString setupName = DefaultSetup 
)
static

Create and load akeystore instance from the given provider.

Parameters
providerThe keystore provider to create a keystore for
parentThe parent object to set as the keystores parent
setupNameThe name of the setup to create the keystore for
Returns
A newly created KeyStore instance or nullptr if the keystore does not exist
Exceptions
SetupDoesNotExistExceptionIf the setup specified by setupName does not exist (yet)
QExceptionIf something went wrong while loading the plugin

This method simply creates a keystore instance. This can be useful if you want to use a keystore outside of datasync to store your own secrets there.

Note
The keystore still requires a valid and running datasync instance, as it is needed for logging etc. This is only due to how the keystore is designed, as external access was originally not planned, and may change in the future.
See also
KeyStore, Setup::keystoreProviders, Setup::defaultKeystoreProvider

◆ removeSetup()

QtDataSync::Setup::removeSetup ( const QString name,
bool  waitForFinished = false 
)
static

Stops the datasync instance and removes it.

Parameters
nameThe name of the setup to be removed
waitForFinishedIf set to true, the method will wait until finished

Removing a setup stops the instances and delets it. This happens asynchronously and gracefully in the background. However, you cannot register another setup with the same name until the previous one has been deleted.

If you wait for the method to finish, the cleanup timeout will be used to terminate if the instance does not finish in time. This is not the case if you don't wait. Please note that waiting is blocking, and thus not recommended to use for GUI apps.

See also
Setup::setCleanupTimeout

◆ setAccount() [1/2]

QtDataSync::Setup::setAccount ( const QJsonObject importData,
bool  keepData = false,
bool  allowFailure = false 
)

Sets an account to be imported on creation of the instance.

Parameters
importDataThe account data to be imported
keepDataSpecify whether the stored data should be preserved
allowFailureSpecify how a failure to import the account should be treated

This method is basically a shortcut to import an account on creation - which is faster and much more efficient than first creating a new account and then delete it again to import an existing one. Internally, the same things will happen as with AccountManager::importAccount (or AccountManager::importAccountTrusted).

Whats special is that since there is no account manager to handle a failure, there are two way to handle that. If allowFailure is false (the default), failing to import the data will trigger a fatal error. If it is set to true, the error is only printed and a new account is created instead, so that the engine can continue running.

See also
Setup::setAccount, Setup::setAccountTrusted, AccountManager::importAccount, AccountManager::importAccountTrusted,

◆ setAccount() [2/2]

Setup& QtDataSync::Setup::setAccount ( const QByteArray importData,
bool  keepData = false,
bool  allowFailure = false 
)

Sets an account to be imported on creation of the instance.

Parameters
importDataThe account data to be imported
keepDataSpecify whether the stored data should be preserved
allowFailureSpecify how a failure to import the account should be treated

This method is basically a shortcut to import an account on creation - which is faster and much more efficient than first creating a new account and then delete it again to import an existing one. Internally, the same things will happen as with AccountManager::importAccount (or AccountManager::importAccountTrusted).

Whats special is that since there is no account manager to handle a failure, there are two way to handle that. If allowFailure is false (the default), failing to import the data will trigger a fatal error. If it is set to true, the error is only printed and a new account is created instead, so that the engine can continue running.

See also
Setup::setAccount, Setup::setAccountTrusted, AccountManager::importAccount, AccountManager::importAccountTrusted,

◆ setAccountTrusted() [1/2]

QtDataSync::Setup::setAccountTrusted ( const QJsonObject importData,
const QString password,
bool  keepData = false,
bool  allowFailure = false 
)

Sets an account to be imported on creation of the instance.

Parameters
passwordThe password used to decrypt the imported data with. Must be the same as used for the export
importDataThe account data to be imported
keepDataSpecify whether the stored data should be preserved
allowFailureSpecify how a failure to import the account should be treated

This method is basically a shortcut to import an account on creation - which is faster and much more efficient than first creating a new account and then delete it again to import an existing one. Internally, the same things will happen as with AccountManager::importAccount (or AccountManager::importAccountTrusted).

Whats special is that since there is no account manager to handle a failure, there are two way to handle that. If allowFailure is false (the default), failing to import the data will trigger a fatal error. If it is set to true, the error is only printed and a new account is created instead, so that the engine can continue running.

See also
Setup::setAccount, Setup::setAccountTrusted, AccountManager::importAccount, AccountManager::importAccountTrusted,

◆ setAccountTrusted() [2/2]

Setup& QtDataSync::Setup::setAccountTrusted ( const QByteArray importData,
const QString password,
bool  keepData = false,
bool  allowFailure = false 
)

Sets an account to be imported on creation of the instance.

Parameters
passwordThe password used to decrypt the imported data with. Must be the same as used for the export
importDataThe account data to be imported
keepDataSpecify whether the stored data should be preserved
allowFailureSpecify how a failure to import the account should be treated

This method is basically a shortcut to import an account on creation - which is faster and much more efficient than first creating a new account and then delete it again to import an existing one. Internally, the same things will happen as with AccountManager::importAccount (or AccountManager::importAccountTrusted).

Whats special is that since there is no account manager to handle a failure, there are two way to handle that. If allowFailure is false (the default), failing to import the data will trigger a fatal error. If it is set to true, the error is only printed and a new account is created instead, so that the engine can continue running.

See also
Setup::setAccount, Setup::setAccountTrusted, AccountManager::importAccount, AccountManager::importAccountTrusted,

◆ setCleanupTimeout()

QtDataSync::Setup::setCleanupTimeout ( unsigned long  timeout)
static

Sets the maximum timeout for shutting down setups.

Parameters
timeoutThe new timeout to be used.

When shutting down the application, the datasync instances, which are running on different threads, have to shut down as well. Upon destruction, all instances are told to stop, and then the main thread will block until they are done or a timout is reached. the cleanup timout is the maximum time to wait for each thread to finish. The default value is -1, which means there is no timeout. The app will wait infinitely.

Attention
Typically, you won't notice the delay the instances need. They finish fast, and since all windows etc have already been destroyed at that time, the user won't notice anything. Only use a timeout if absolutely neccessary, since a terminated thread (and thats what happens after a timeout) results in undefined states, and may even corrupt the stored data.
See also
Setup::removeSetup, qAddPostRoutine()

Property Documentation

◆ cacheSize

QtDataSync::Setup::cacheSize
readwrite

The size of the internal database cache, in bytes.

Default: 100_mb

All loaded json data is internally cached to speed up frequent read operations on the same items. This property limits the size in bytes that cache can hold at most. If you set it to 0, the caching gets completly deactivated.

Note
Make shure to not exceed INT_MAX. Negative cache values can lead to undefined behaviour.
Accessors
READcacheSize()
WRITEsetCacheSize()
RESETresetCacheSize()
See also
Defaults::property, Defaults::CacheSize, QtDataSync::KB, QtDataSync::MB, QtDataSync::GB, QtDataSync::literals

Definition at line 75 of file setup.h.

◆ cipherKeySize

QtDataSync::Setup::cipherKeySize
readwrite

The size in bytes for the secret exchange key (which is symmetric)

Default: 0

The size of the key depends on the Setup::cipherScheme. If this property is 0, the maximum key size for each algorithm is used. The following table shows what size limits apply per algorithm. Please note that the key size is independend of the mode of operation, i.e. the keysize for AES applies for both, Setup::AES_EAX and Setup::AES_GCM:

Algorithm Allowed key sizes in bytes, default marked bold
AEX 16, 24, 32
Twofish 16, 24, 32
Serpent 16, 24, 32
IDEA 16
Accessors
READcipherKeySize()
WRITEsetCipherKeySize()
RESETresetCipherKeySize()
See also
Defaults::property, Defaults::SymKeyParam, Setup::cipherScheme

Definition at line 97 of file setup.h.

◆ cipherScheme

QtDataSync::Setup::cipherScheme
readwrite

The algorithmic scheme to be used for new secret exchange keys (which are symmetric)

Default: Setup::AES_EAX

Accessors
READcipherScheme()
WRITEsetCipherScheme()
RESETresetCipherScheme()
See also
Defaults::property, Defaults::SymScheme, Setup::cipherKeySize

Definition at line 95 of file setup.h.

◆ conflictResolver

QtDataSync::Setup::conflictResolver
readwrite

An optional conflict resolver to handle merge conflicts.

Default: nullptr

If you want to use a custom conflict resolver to handle merge conflicts, you can set one for the engine here.

Attention
The resolver is owned by the setup, and later transfered to the engine. When calling the WRITE accessor, the old instance gets deleted first. The one passed via write will become owned by the setup as well. If the setup goes out of scope without beeing created, the resolver gets deleted as well.
Accessors
READconflictResolver()
WRITEsetConflictResolver()
RESETresetConflictResolver()
See also
Defaults::conflictResolver, ConflictResolver

Definition at line 71 of file setup.h.

◆ encryptionKeyParam

QtDataSync::Setup::encryptionKeyParam
readwrite

The generation parameter for the encryption key.

Default: invalid

The type and interpretation of this parameter depend on the Setup::encryptionScheme. If this property is an invalid QVariant, Defaults::defaultParam is used to determine the default key parameter for each type. The following table shows what the key param must be per scheme:

Scheme Type Default value Description
Setup::RSA_OAEP_SHA3_512 int 4096 The size of the RSA key
Setup::ECIES_ECP_SHA3_512 Setup::EllipticCurve Setup::brainpoolP384r1 The elliptic curve and the key size
Accessors
READencryptionKeyParam()
WRITEsetEncryptionKeyParam()
RESETresetEncryptionKeyParam()
See also
Defaults::property, Defaults::CryptKeyParam, Setup::encryptionScheme, Defaults::defaultParam

Definition at line 93 of file setup.h.

◆ encryptionScheme

QtDataSync::Setup::encryptionScheme
readwrite

The algorithmic scheme to be used for new encryption keys.

Default: Setup::RSA_OAEP_SHA3_512

Accessors
READencryptionScheme()
WRITEsetEncryptionScheme()
RESETresetEncryptionScheme()
See also
Defaults::property, Defaults::CryptScheme, Setup::encryptionKeyParam

Definition at line 91 of file setup.h.

◆ eventLoggingMode

QtDataSync::Setup::eventLoggingMode
readwrite

The logging mode for database change events.

Default: EventMode::Unchanged

Note
Event though the default value is EventMode::Unchanged, this implicitly means for newly created setups event logging is disabled! If you create a completly new setup and want event logging, you have to set this property to EventMode::Enabled at least once.

Event logging is an optional component of datasync that can be used for reliable, deterministic and ordered handling of change events from any source. The main class to access these events is the EventCursor. This property is used to control the activation of this component.

If disabled, no events are logged at all. This means EventCursor becomes unusable. If enabled, all changes to data (create, change and delete) trigger an event that is permanently stored and can be accessed vua the EventCursor. The Unchanged mode simply means "keep it in whatever state it already is" - this is useful if you don't want to break anything

Attention
Setting this to EventMode::Disabled will immediatly drop all already stored change events! So unless you are certain you don't need these, be careful with that option.
Accessors
READeventLoggingMode()
WRITEsetEventLoggingMode()
RESETresetEventLoggingMode()
REVISION2
See also
Defaults::property, Defaults::EventLoggingMode, QtDataSync::EventCursor, Setup::EventMode

Definition at line 99 of file setup.h.

◆ fatalErrorHandler

QtDataSync::Setup::fatalErrorHandler
readwrite

An alternative handler for fatal errors.

Default: invalid

When a fatal error occurs it is reported to the engine via logFatal (which uses Logger::reportFatalError). Such a fatal error must be handelt immediatly, and this method sets the method to be called in such cases.

It is called on the thread where the error happends, and should be used to react to the error in whatever way. A fatal error will render the datasync instance invalid, leading to the unavoidable abortion of the application. You can set a custom handler in order to custom log the error or perform other operations, but at the end the method should not return. This can be archieved by calling for example std::abort in the end.

The default handler, which is used in case no custom handler is set, calls qFatal to present the error and abort the application.

Semantics of the fatalErrorHandler:

  • Parameter 1: descriptive string of the error
  • Parameter 2: The name of the setup in which the error occured
  • Parameter 3: A const reference to the context where the error occured
  • The method must not return (if it does std::abort is called)
Accessors
READfatalErrorHandler()
WRITEsetFatalErrorHandler()
RESETresetFatalErrorHandler()
See also
logFatal, Logger::reportFatalError, Setup::FatalErrorHandler

Definition at line 73 of file setup.h.

◆ keyStoreProvider

QtDataSync::Setup::keyStoreProvider
readwrite

The name of the preferred keystore provider.

Default: empty

Note
If the provider is an invalid string, the engine uses the default provider, which is decided by Setup::defaultKeystoreProvider

The keystore is used to securely store private keys on the users device. You can use Setup::availableKeystores to find out which keystores are currently available

The following keystores are support via a plugin that is part of the Library:

  • KWallet (KDE only)
  • SecretService (based on the gnome library, works with any keystore that implements it. Currently known:)
    • gnome-keyring
  • Windows Credentials store (Desktop windows only)
  • Android Shared Preferences (Not completly secure, Android only)
  • Apple Keychain (macOs and iOs only)
  • Plain (An unsecure fallback implementation that works on any platform)
Note
Typically the plugin is expected to in the $QT_INSTALL_PLUGINS/keystores folder. If you have the plugins elsewhere, use the PLUGIN_KEYSTORES_PATH environment variable to specify additional paths, seperated by the system path seperator (: on unix, ; on windows)

More keystores can be added by creating a custom KeyStorePlugin

Accessors
READkeyStoreProvider()
WRITEsetKeyStoreProvider()
RESETresetKeyStoreProvider()
See also
Defaults::property, Defaults::KeyStoreProvider, Setup::keystoreProviders, Setup::availableKeystores, KeyStore, KeyStorePlugin

Definition at line 85 of file setup.h.

◆ localDir

QtDataSync::Setup::localDir
readwrite

The local storage directoy used by the instance.

Default: "./qtdatasync/default"

The local directory is the heart of the datasync instance. It's where the actual data, configurations etc. are stored. A datasync instance is identified by it's local directory across multiple processes. There can only be one active (but many passive) instances per storage folder. If you want to make use of multiple setups within an application, they all need their own storage directory

Note
The path is resolved relative to the applications local data folder. See QStandardPaths::AppLocalDataLocation
Accessors
READlocalDir()
WRITEsetLocalDir()
RESETresetLocalDir()
See also
Setup::create, Setup::createPassive, Defaults::storageDir

Definition at line 65 of file setup.h.

◆ persistDeletedVersion

QtDataSync::Setup::persistDeletedVersion
readwrite

Specify whether deleted datasets should persist.

Default: false

Persisting deleted datasets means that even after a dataset has been deleted and all changes synchronized, the information that is was deleted is kept around. This can prevent problems with the synchronisation when keys are reused, as the engine is now able to detect which operation (change or delete) was newer. If not persisting, there is no way to tell if a dataset was deleted or never existed in the first place. In exchange, The database gets filled with deleted entries for every deleted dataset.

Rule of thumb: If you frequently reuse keys, set it to true. If you create your keys randomly or chances of a key beeing reused are low, do not persist.

Accessors
READpersistDeletedVersion()
WRITEsetPersistDeletedVersion()
RESETresetPersistDeletedVersion()
See also
Defaults::property, Defaults::PersistDeleted

Definition at line 77 of file setup.h.

◆ remoteConfiguration

QtDataSync::Setup::remoteConfiguration
readwrite

The configuration to be used to connect to the remote.

Default: empty

This part must be set in order to connect to a remote. It is however possible to import the remote configuration instead of using the one provided via this property.

Accessors
READremoteConfiguration()
WRITEsetRemoteConfiguration()
RESETresetRemoteConfiguration()
See also
Defaults::property, Defaults::RemoteConfig, RemoteConfiguration, AccountManager::exportAccount, AccountManager::exportAccountTrusted

Definition at line 83 of file setup.h.

◆ remoteObjectHost

QtDataSync::Setup::remoteObjectHost
readwrite

The url to be used to host the remote object sources, and to connect to to acquire the replicas.

Default: invalid

Note
If the url is invalid when calling create(), the setup generates a default url based of the setups properties. It is: "threaded://qtdatasync/<setupName>/enginenode"

This url is used to create the host node in the engine that provides internal remote object sources, and to create the QRemoteObjectNode instances to connect to this host node and acquire the replicas. This is all happening internally, so you don't not to worry about the how to.

The default url uses the threaded connection, which is only valid within the same process. For more details, and the alternatives, see Threaded remote objects

Accessors
READremoteObjectHost()
WRITEsetRemoteObjectHost()
RESETresetRemoteObjectHost()
See also
Defaults::remoteNode, Defaults::remoteAddress, Threaded remote objects, AccountManager, SyncManager

Definition at line 67 of file setup.h.

◆ serializer

QtDataSync::Setup::serializer
readwrite

The serializer to be used to serialize and deserialize data to and from the store.

Default: A pointer to a valid serializer

You can use this property to customize how the serializer should serialize data and to register converters for custom types.

Attention
The serializer is owned by the setup, and later transfered to the engine. When calling the WRITE or RESET accessors, the old instance gets deleted first. The one passed via write will become owned by the setup as well. If the setup goes out of scope without beeing created, the serializer gets deleted as well.
Accessors
READserializer()
WRITEsetSerializer()
RESETresetSerializer()
See also
Defaults::serializer, QJsonSerializer

Definition at line 69 of file setup.h.

◆ signatureKeyParam

QtDataSync::Setup::signatureKeyParam
readwrite

The generation parameter for the signature key.

Default: invalid

The type and interpretation of this parameter depend on the Setup::signatureScheme. If this property is an invalid QVariant, Defaults::defaultParam is used to determine the default key parameter for each type. The following table shows what the key param must be per scheme:

Scheme Type Default value Description
Setup::RSA_PSS_SHA3_512 int 4096 The size of the RSA key
Setup::ECDSA_ECP_SHA3_512 Setup::EllipticCurve Setup::brainpoolP384r1 The elliptic curve and the key size
Setup::ECNR_ECP_SHA3_512 Setup::EllipticCurve Setup::brainpoolP384r1 The elliptic curve and the key size
Accessors
READsignatureKeyParam()
WRITEsetSignatureKeyParam()
RESETresetSignatureKeyParam()
See also
Defaults::property, Defaults::SignKeyParam, Setup::signatureScheme, Defaults::defaultParam

Definition at line 89 of file setup.h.

◆ signatureScheme

QtDataSync::Setup::signatureScheme
readwrite

The algorithmic scheme to be used for new signature keys.

Default: Setup::RSA_PSS_SHA3_512

Accessors
READsignatureScheme()
WRITEsetSignatureScheme()
RESETresetSignatureScheme()
See also
Defaults::property, Defaults::SignScheme, Setup::signatureKeyParam

Definition at line 87 of file setup.h.

◆ sslConfiguration

QtDataSync::Setup::sslConfiguration
readwrite

The ssl configuration to be used to connect to the remote.

Default: QSslConfiguration::defaultConfiguration()

Is used by the internal websocket server. If you need a configuration different from the one for the application, you can set one via this property

Accessors
READsslConfiguration()
WRITEsetSslConfiguration()
RESETresetSslConfiguration()
See also
Defaults::property, Defaults::SslConfiguration, QSslConfiguration::defaultConfiguration

Definition at line 81 of file setup.h.

◆ syncPolicy

QtDataSync::Setup::syncPolicy
readwrite

The policiy for how to handle conflicts.

Default: Setup::PreferChanged

In case a conflict is detected, and one of the changes is a data change, and one is a deletion, this policy decides which of the two should be kept, and which one gets discarded.

Accessors
READsyncPolicy()
WRITEsetSyncPolicy()
RESETresetSyncPolicy()
See also
Defaults::property, Defaults::ConflictPolicy, Setup::SyncPolicy

Definition at line 79 of file setup.h.


The documentation for this class was generated from the following files: