2019-07-05 07:54:53 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2019-07-08 15:41:34 +00:00
|
|
|
#include "base/bytes.h"
|
2019-07-10 15:03:48 +00:00
|
|
|
#include "base/basic_types.h"
|
2019-07-08 15:41:34 +00:00
|
|
|
|
2019-12-02 13:10:19 +00:00
|
|
|
namespace MTP::details {
|
2019-07-05 07:54:53 +00:00
|
|
|
|
|
|
|
class AbstractSocket : protected QObject {
|
|
|
|
public:
|
|
|
|
static std::unique_ptr<AbstractSocket> Create(
|
|
|
|
not_null<QThread*> thread,
|
|
|
|
const bytes::vector &secret,
|
2021-06-15 12:45:48 +00:00
|
|
|
const QNetworkProxy &proxy,
|
|
|
|
bool protocolForFiles);
|
2019-07-05 07:54:53 +00:00
|
|
|
|
|
|
|
explicit AbstractSocket(not_null<QThread*> thread) {
|
|
|
|
moveToThread(thread);
|
|
|
|
}
|
|
|
|
virtual ~AbstractSocket() = default;
|
|
|
|
|
|
|
|
[[nodiscard]] rpl::producer<> connected() const {
|
|
|
|
return _connected.events();
|
|
|
|
}
|
|
|
|
[[nodiscard]] rpl::producer<> disconnected() const {
|
|
|
|
return _disconnected.events();
|
|
|
|
}
|
|
|
|
[[nodiscard]] rpl::producer<> readyRead() const {
|
|
|
|
return _readyRead.events();
|
|
|
|
}
|
|
|
|
[[nodiscard]] rpl::producer<> error() const {
|
|
|
|
return _error.events();
|
|
|
|
}
|
2019-07-10 15:03:48 +00:00
|
|
|
[[nodiscard]] rpl::producer<> syncTimeRequests() const {
|
|
|
|
return _syncTimeRequests.events();
|
|
|
|
}
|
2019-07-05 07:54:53 +00:00
|
|
|
|
|
|
|
virtual void connectToHost(const QString &address, int port) = 0;
|
2019-07-28 16:00:42 +00:00
|
|
|
[[nodiscard]] virtual bool isGoodStartNonce(bytes::const_span nonce) = 0;
|
2019-07-10 15:03:48 +00:00
|
|
|
virtual void timedOut() = 0;
|
2019-07-05 07:54:53 +00:00
|
|
|
[[nodiscard]] virtual bool isConnected() = 0;
|
2019-07-08 13:56:09 +00:00
|
|
|
[[nodiscard]] virtual bool hasBytesAvailable() = 0;
|
2019-07-08 15:41:34 +00:00
|
|
|
[[nodiscard]] virtual int64 read(bytes::span buffer) = 0;
|
|
|
|
virtual void write(
|
|
|
|
bytes::const_span prefix,
|
|
|
|
bytes::const_span buffer) = 0;
|
2019-07-05 07:54:53 +00:00
|
|
|
|
|
|
|
virtual int32 debugState() = 0;
|
|
|
|
|
|
|
|
protected:
|
2021-06-15 12:45:48 +00:00
|
|
|
static const int kFilesSendBufferSize = 2 * 1024 * 1024;
|
|
|
|
static const int kFilesReceiveBufferSize = 2 * 1024 * 1024;
|
|
|
|
|
2019-07-05 07:54:53 +00:00
|
|
|
rpl::event_stream<> _connected;
|
|
|
|
rpl::event_stream<> _disconnected;
|
|
|
|
rpl::event_stream<> _readyRead;
|
|
|
|
rpl::event_stream<> _error;
|
2019-07-10 15:03:48 +00:00
|
|
|
rpl::event_stream<> _syncTimeRequests;
|
2019-07-05 07:54:53 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-12-02 13:10:19 +00:00
|
|
|
} // namespace MTP::details
|