From 226d06402b0fe8e95d6261c788df61f0af91b2f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Wed, 14 Jun 2023 18:48:19 +0200 Subject: 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 Reviewed-by: Timur Pocheptsov --- examples/network/network-chat/client.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/network/network-chat/client.h') 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 peers; + QMultiHash peers; }; #endif -- cgit v1.2.3