// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL // KOutNet - One peer's profile banner, exchanged over the pinned TLS channel #pragma once #include #include #include #include #include #include #include namespace koutnet { // The banner half of the peer table, shaped after AvatarExchange: the same // channel writer, seats and per-seat sha dedup, and "data" empty means the // banner went away. The differences are kMsgBanner, the peer-banners // directory and what a landed banner is called. A banner is not a presence // field because it travels authenticated and is deduped by sha. class BannerExchange : public QObject { Q_OBJECT public: // Places one frame on the authenticated channel to a seat; false when there is no channel. using ChannelWriter = std::function; // The current seats - every authenticated peer address worth reaching. using Seats = std::function()>; // Records where a peer's banner landed (NetworkManager keeps it in the peer // info map). Defaults to a no-op. using PeerInfoRecorder = std::function; explicit BannerExchange(ChannelWriter channelWriter, Seats seats, PeerInfoRecorder peerInfoRecorder = {}, QObject *parent = nullptr); // Re-reads the local banner and pushes it to each seat that has not seen // this sha. An empty or unreadable path means "no banner" and is pushed to // seats that still think we have one. Q_INVOKABLE void setBanner(const QString &bannerPath); // A seat's channel just authenticated and has never seen our banner, so push // it now or it stays unadorned until the next change. void onPeerAuthenticated(const QString &address); // A banner frame arrived off a channel. The bytes are parked under the app's // data dir and the local file URL is raised so the UI can repaint. void onFrame(const QString &host, const QJsonObject &msg); Q_SIGNALS: // A peer's banner landed, or went away with an empty source. fromIp is the // chat id the banner belongs to. void peerBanner(QString fromIp, QString bannerSource); private: void sendBannerToPeer(const QString &targetAddress); void broadcastBanner(); ChannelWriter m_channelWriter; Seats m_seats; PeerInfoRecorder m_peerInfoRecorder; // This station's banner: the path, the bytes and their sha-256 hex for dedup. // An empty path (or unreadable file) means no banner. QString m_bannerPath; QByteArray m_bannerData; QString m_bannerSha; // seat -> the sha that seat last received from us, so an unchanged banner // is pushed once per seat instead of on every presence or reconnect. QHash m_lastBannerSent; }; } // namespace koutnet