// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL // KOutNet - The outgoing file transfer: read, announce, place the chunks. #pragma once #include #include #include #include #include namespace koutnet { // The outgoing half of a file transfer, stood out of NetworkManager: read the // file (or take bytes already in memory), announce it with a file_meta frame, // then place the CBOR byte-string chunk frames that follow. The pinned TLS channel that // carries them is not owned here - it is pushed in as seams, exactly like the // voice transport's pin gate and the avatar exchange's writer, because the peer // table, the channel and the identity belong to the owner. A transfer is one // shot: the channel is ordered, complete and replay-proof, so nothing is // buffered or retransmitted and the receiver's file_ack is only its own // book-keeping closure, not a retry signal. class FileTransferSender : public QObject { Q_OBJECT public: explicit FileTransferSender(QObject *parent = nullptr); // The owner's routing seams. canUseTls says whether the address the file // is for belongs to a live pinned channel (a peer with none is just // unreachable), and place() puts one length-prefixed protocol frame on // that channel. The identity and address lambdas feed the meta frame's // from_id/from_ip and are read fresh on each send: the primary address can // change under a running session, but the receiver answers the file_ack to // the address the meta named. void setRouter(std::function canUseTls, std::function place); void setLocalIdentity(const std::function &ownIdentityId, const std::function &ownAddress); // Reads filePath and sends it; false with a reported error when the file is // missing, the peer has no live channel, or the size is over the transfer // ceiling in FileTransferHandler. bool send(const QString &toIp, const QString &filePath); // The same path for bytes already in memory (tests, drag of a virtual // file): rawBytes must be non-empty for this branch to win. bool sendBytes(const QString &toIp, const QByteArray &rawBytes, const QString &filename); Q_SIGNALS: void errorOccurred(QString message); private: bool placeFrames(const QString &toIp, const QByteArray &data, const QString &filename, const QString &errorLabel); std::function m_canUseTls; std::function m_place; std::function m_ownIdentityId; std::function m_ownAddress; }; } // namespace koutnet