diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2023-06-14 18:48:19 +0200 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2023-07-17 16:49:16 +0000 |
commit | 226d06402b0fe8e95d6261c788df61f0af91b2f9 (patch) | |
tree | 718855e747859edc70788929917d606a0aa25cf4 /examples/network/network-chat/client.h | |
parent | 5651be517a9f25798a051f7dd7548d40381148df (diff) |
Network-chat: Fix remote peer making multiple connections
The system was just treating IP (and optionally port) as a unique
identifier, so if a peer had multiple possible paths to a client they
would connect multiple times.
This fixes that by generating using QUuid in each client.
We then use this during broadcast, replacing the username we
sent before (which was not used), and as part of the greeting.
The greeting now is more complex, since we need to send both
username and the ID.
Change-Id: I6c6c2ffd5198406aad48445a68dd6aab36de69c0
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'examples/network/network-chat/client.h')
-rw-r--r-- | examples/network/network-chat/client.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/examples/network/network-chat/client.h b/examples/network/network-chat/client.h index 55abd84c9e..2ce6afe826 100644 --- a/examples/network/network-chat/client.h +++ b/examples/network/network-chat/client.h @@ -21,7 +21,7 @@ public: void sendMessage(const QString &message); QString nickName() const; - bool hasConnection(const QHostAddress &senderIp, int senderPort = -1) const; + bool hasConnection(const QByteArray &peerUniqueId) const; signals: void newMessage(const QString &from, const QString &message); @@ -39,7 +39,7 @@ private: PeerManager *peerManager; Server server; - QMultiHash<QHostAddress, Connection *> peers; + QMultiHash<QByteArray, Connection *> peers; }; #endif |