QcNetworkClient Class
Joins a network game (decisions E-251, E-252, E-872): connects over TLS to the address, checks the server's certificate against the pin in the known servers (pins it at the first connection), logs in with the credentials and hands over the session once the server welcomed the player. More...
| Header: | #include <clientcore/network/QcNetworkClient.h> |
| Inherits: | QObject |
Public Types
| struct | Request |
| enum class | Pinning { Check, DisabledForTests } |
| enum class | Stage { Idle, Connecting, LoggingIn } |
Public Functions
| QcNetworkClient(const QcNetworkClient &) | |
| QcNetworkClient(QcNetworkClient &&) | |
| void | cancel() |
| void | join(const QcNetworkClient::Request &request) |
| QByteArray | serverFingerprint() const |
| QcNetworkClient::Stage | stage() const |
| std::unique_ptr<QcClientSession> | takeSession() |
| QcNetworkClient & | operator=(QcNetworkClient &&) |
| QcNetworkClient & | operator=(const QcNetworkClient &) |
Signals
| void | certificateChanged(const QString &address) |
| void | failed(const QcJoinFailure &failure, const QcMsg::Disconnect &refusal) |
| void | joined() |
| void | stageChanged(QcNetworkClient::Stage stage) |
Detailed Description
Every join ends with exactly one of joined() and failed(); cancel() ends it silently. Lives in the GUI thread like the session it makes. A session that ticks on its own thread (decision E-560) gets that thread from here: the connector runs in it, so the TLS socket is made, used and closed in that one thread and never changes threads (decision E-872); the outcome comes back through a QcMailbox, the pin is checked here before anything is sent.
Member Type Documentation
enum class QcNetworkClient::Pinning
Whether the server's certificate is checked against its pin.
Only tests that do not test the pinning turn it off; every program checks.
| Constant | Value | Description |
|---|---|---|
QcNetworkClient::Pinning::Check | 0 | checked (every program) |
QcNetworkClient::Pinning::DisabledForTests | 1 | not checked (tests of other things) |
enum class QcNetworkClient::Stage
How far the join is.
| Constant | Value | Description |
|---|---|---|
QcNetworkClient::Stage::Idle | 0 | no join running |
QcNetworkClient::Stage::Connecting | 1 | making the TLS connection |
QcNetworkClient::Stage::LoggingIn | 2 | connected, logging in until the server welcomes the player |
Member Function Documentation
[delete] QcNetworkClient::QcNetworkClient(const QcNetworkClient &)
Copy-constructs an instance of QcNetworkClient. This function is deleted.
[delete] QcNetworkClient::QcNetworkClient(QcNetworkClient &&)
Move-constructs an instance of QcNetworkClient. This function is deleted.
void QcNetworkClient::cancel()
Ends the join silently; neither joined() nor failed() follows.
[signal] void QcNetworkClient::certificateChanged(const QString &address)
Just before failed(): the server showed another certificate than the one pinned for address; the join was refused before anything was sent.
[signal] void QcNetworkClient::failed(const QcJoinFailure &failure, const QcMsg::Disconnect &refusal)
Emitted with the failure that ended the join (decision E-964): the step that failed (connection, certificate, login), the addresses tried and a translated reason and hint; refusal is the server's Disconnect (with its translation key) when it sent one.
void QcNetworkClient::join(const QcNetworkClient::Request &request)
Starts joining as request says; a join still running is cancelled first.
[signal] void QcNetworkClient::joined()
The server welcomed the player; takeSession() hands over the session.
QByteArray QcNetworkClient::serverFingerprint() const
Returns the SHA-256 of the certificate of the server of the last join (QcTlsFingerprint), once connected.
QcNetworkClient::Stage QcNetworkClient::stage() const
Returns how far the join is.
[signal] void QcNetworkClient::stageChanged(QcNetworkClient::Stage stage)
The join reached stage.
std::unique_ptr<QcClientSession> QcNetworkClient::takeSession()
Returns the session after joined(): logged in, loading the world, ticking. The caller takes it over; null before and once taken.
[delete] QcNetworkClient &QcNetworkClient::operator=(QcNetworkClient &&)
Move-assigns other to this QcNetworkClient instance. This function is deleted.
[delete] QcNetworkClient &QcNetworkClient::operator=(const QcNetworkClient &)
Copy-assigns other to this QcNetworkClient instance. This function is deleted.