mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 15:13:57 +02:00
Set Send/Receive buffer size for download TCP sockets.
This commit is contained in:
parent
f18e157e46
commit
8dac6896d6
14 changed files with 73 additions and 20 deletions
|
@ -81,7 +81,8 @@ public:
|
|||
const QString &ip,
|
||||
int port,
|
||||
const bytes::vector &protocolSecret,
|
||||
int16 protocolDcId) = 0;
|
||||
int16 protocolDcId,
|
||||
bool protocolForFiles) = 0;
|
||||
virtual void timedOut() {
|
||||
}
|
||||
[[nodiscard]] virtual bool isConnected() const = 0;
|
||||
|
|
|
@ -67,7 +67,8 @@ void HttpConnection::connectToServer(
|
|||
const QString &address,
|
||||
int port,
|
||||
const bytes::vector &protocolSecret,
|
||||
int16 protocolDcId) {
|
||||
int16 protocolDcId,
|
||||
bool protocolForFiles) {
|
||||
_address = address;
|
||||
connect(
|
||||
&_manager,
|
||||
|
|
|
@ -29,7 +29,8 @@ public:
|
|||
const QString &address,
|
||||
int port,
|
||||
const bytes::vector &protocolSecret,
|
||||
int16 protocolDcId) override;
|
||||
int16 protocolDcId,
|
||||
bool protocolForFiles) override;
|
||||
bool isConnected() const override;
|
||||
bool usingHttpWait() override;
|
||||
bool needHttpWait() override;
|
||||
|
@ -40,7 +41,7 @@ public:
|
|||
QString tag() const override;
|
||||
|
||||
static mtpBuffer handleResponse(QNetworkReply *reply);
|
||||
static qint32 handleError(QNetworkReply *reply); // returnes error code
|
||||
static qint32 handleError(QNetworkReply *reply); // Returns error code.
|
||||
|
||||
private:
|
||||
QUrl url() const;
|
||||
|
|
|
@ -83,7 +83,8 @@ void ResolvingConnection::setChild(ConnectionPointer &&child) {
|
|||
_address,
|
||||
_port,
|
||||
_protocolSecret,
|
||||
_protocolDcId);
|
||||
_protocolDcId,
|
||||
_protocolForFiles);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,7 +219,8 @@ void ResolvingConnection::connectToServer(
|
|||
const QString &address,
|
||||
int port,
|
||||
const bytes::vector &protocolSecret,
|
||||
int16 protocolDcId) {
|
||||
int16 protocolDcId,
|
||||
bool protocolForFiles) {
|
||||
if (!_child) {
|
||||
InvokeQueued(this, [=] { emitError(kErrorCodeOther); });
|
||||
return;
|
||||
|
@ -227,6 +229,7 @@ void ResolvingConnection::connectToServer(
|
|||
_port = port;
|
||||
_protocolSecret = protocolSecret;
|
||||
_protocolDcId = protocolDcId;
|
||||
_protocolForFiles = protocolForFiles;
|
||||
DEBUG_LOG(("Resolving Info: dc:%1 proxy '%2' connects a child '%3'").arg(
|
||||
QString::number(_protocolDcId),
|
||||
_proxy.host +':' + QString::number(_proxy.port),
|
||||
|
@ -237,7 +240,8 @@ void ResolvingConnection::connectToServer(
|
|||
address,
|
||||
port,
|
||||
protocolSecret,
|
||||
protocolDcId);
|
||||
protocolDcId,
|
||||
protocolForFiles);
|
||||
}
|
||||
|
||||
bool ResolvingConnection::isConnected() const {
|
||||
|
|
|
@ -32,7 +32,8 @@ public:
|
|||
const QString &address,
|
||||
int port,
|
||||
const bytes::vector &protocolSecret,
|
||||
int16 protocolDcId) override;
|
||||
int16 protocolDcId,
|
||||
bool protocolForFiles) override;
|
||||
bool isConnected() const override;
|
||||
bool requiresExtendedPadding() const override;
|
||||
|
||||
|
@ -63,6 +64,7 @@ private:
|
|||
int _port = 0;
|
||||
bytes::vector _protocolSecret;
|
||||
int16 _protocolDcId = 0;
|
||||
bool _protocolForFiles = false;
|
||||
base::Timer _timeoutTimer;
|
||||
|
||||
};
|
||||
|
|
|
@ -512,7 +512,8 @@ void TcpConnection::connectToServer(
|
|||
const QString &address,
|
||||
int port,
|
||||
const bytes::vector &protocolSecret,
|
||||
int16 protocolDcId) {
|
||||
int16 protocolDcId,
|
||||
bool protocolForFiles) {
|
||||
Expects(_address.isEmpty());
|
||||
Expects(_port == 0);
|
||||
Expects(_protocol == nullptr);
|
||||
|
@ -543,7 +544,8 @@ void TcpConnection::connectToServer(
|
|||
_socket = AbstractSocket::Create(
|
||||
thread(),
|
||||
secret,
|
||||
ToNetworkProxy(_proxy));
|
||||
ToNetworkProxy(_proxy),
|
||||
protocolForFiles);
|
||||
_protocolDcId = protocolDcId;
|
||||
|
||||
_socket->connected(
|
||||
|
|
|
@ -32,7 +32,8 @@ public:
|
|||
const QString &address,
|
||||
int port,
|
||||
const bytes::vector &protocolSecret,
|
||||
int16 protocolDcId) override;
|
||||
int16 protocolDcId,
|
||||
bool protocolForFiles) override;
|
||||
void timedOut() override;
|
||||
bool isConnected() const override;
|
||||
bool requiresExtendedPadding() const override;
|
||||
|
|
|
@ -15,11 +15,16 @@ namespace MTP::details {
|
|||
std::unique_ptr<AbstractSocket> AbstractSocket::Create(
|
||||
not_null<QThread*> thread,
|
||||
const bytes::vector &secret,
|
||||
const QNetworkProxy &proxy) {
|
||||
const QNetworkProxy &proxy,
|
||||
bool protocolForFiles) {
|
||||
if (secret.size() >= 21 && secret[0] == bytes::type(0xEE)) {
|
||||
return std::make_unique<TlsSocket>(thread, secret, proxy);
|
||||
return std::make_unique<TlsSocket>(
|
||||
thread,
|
||||
secret,
|
||||
proxy,
|
||||
protocolForFiles);
|
||||
} else {
|
||||
return std::make_unique<TcpSocket>(thread, proxy);
|
||||
return std::make_unique<TcpSocket>(thread, proxy, protocolForFiles);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,8 @@ public:
|
|||
static std::unique_ptr<AbstractSocket> Create(
|
||||
not_null<QThread*> thread,
|
||||
const bytes::vector &secret,
|
||||
const QNetworkProxy &proxy);
|
||||
const QNetworkProxy &proxy,
|
||||
bool protocolForFiles);
|
||||
|
||||
explicit AbstractSocket(not_null<QThread*> thread) {
|
||||
moveToThread(thread);
|
||||
|
@ -53,6 +54,9 @@ public:
|
|||
virtual int32 debugState() = 0;
|
||||
|
||||
protected:
|
||||
static const int kFilesSendBufferSize = 2 * 1024 * 1024;
|
||||
static const int kFilesReceiveBufferSize = 2 * 1024 * 1024;
|
||||
|
||||
rpl::event_stream<> _connected;
|
||||
rpl::event_stream<> _disconnected;
|
||||
rpl::event_stream<> _readyRead;
|
||||
|
|
|
@ -12,10 +12,21 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
namespace MTP::details {
|
||||
|
||||
TcpSocket::TcpSocket(not_null<QThread*> thread, const QNetworkProxy &proxy)
|
||||
TcpSocket::TcpSocket(
|
||||
not_null<QThread*> thread,
|
||||
const QNetworkProxy &proxy,
|
||||
bool protocolForFiles)
|
||||
: AbstractSocket(thread) {
|
||||
_socket.moveToThread(thread);
|
||||
_socket.setProxy(proxy);
|
||||
if (protocolForFiles) {
|
||||
_socket.setSocketOption(
|
||||
QAbstractSocket::SendBufferSizeSocketOption,
|
||||
kFilesSendBufferSize);
|
||||
_socket.setSocketOption(
|
||||
QAbstractSocket::ReceiveBufferSizeSocketOption,
|
||||
kFilesReceiveBufferSize);
|
||||
}
|
||||
const auto wrap = [&](auto handler) {
|
||||
return [=](auto &&...args) {
|
||||
InvokeQueued(this, [=] { handler(args...); });
|
||||
|
|
|
@ -13,7 +13,10 @@ namespace MTP::details {
|
|||
|
||||
class TcpSocket final : public AbstractSocket {
|
||||
public:
|
||||
TcpSocket(not_null<QThread*> thread, const QNetworkProxy &proxy);
|
||||
TcpSocket(
|
||||
not_null<QThread*> thread,
|
||||
const QNetworkProxy &proxy,
|
||||
bool protocolForFiles);
|
||||
|
||||
void connectToHost(const QString &address, int port) override;
|
||||
bool isGoodStartNonce(bytes::const_span nonce) override;
|
||||
|
|
|
@ -446,13 +446,22 @@ void ClientHelloGenerator::writeTimestamp() {
|
|||
TlsSocket::TlsSocket(
|
||||
not_null<QThread*> thread,
|
||||
const bytes::vector &secret,
|
||||
const QNetworkProxy &proxy)
|
||||
const QNetworkProxy &proxy,
|
||||
bool protocolForFiles)
|
||||
: AbstractSocket(thread)
|
||||
, _secret(secret) {
|
||||
Expects(_secret.size() >= 21 && _secret[0] == bytes::type(0xEE));
|
||||
|
||||
_socket.moveToThread(thread);
|
||||
_socket.setProxy(proxy);
|
||||
if (protocolForFiles) {
|
||||
_socket.setSocketOption(
|
||||
QAbstractSocket::SendBufferSizeSocketOption,
|
||||
kFilesSendBufferSize);
|
||||
_socket.setSocketOption(
|
||||
QAbstractSocket::ReceiveBufferSizeSocketOption,
|
||||
kFilesReceiveBufferSize);
|
||||
}
|
||||
const auto wrap = [&](auto handler) {
|
||||
return [=](auto &&...args) {
|
||||
InvokeQueued(this, [=] { handler(args...); });
|
||||
|
|
|
@ -16,7 +16,8 @@ public:
|
|||
TlsSocket(
|
||||
not_null<QThread*> thread,
|
||||
const bytes::vector &secret,
|
||||
const QNetworkProxy &proxy);
|
||||
const QNetworkProxy &proxy,
|
||||
bool protocolForFiles);
|
||||
|
||||
void connectToHost(const QString &address, int port) override;
|
||||
bool isGoodStartNonce(bytes::const_span nonce) override;
|
||||
|
|
|
@ -226,9 +226,17 @@ void SessionPrivate::appendTestConnection(
|
|||
});
|
||||
});
|
||||
|
||||
const auto protocolForFiles = isDownloadDcId(_shiftedDcId)
|
||||
//|| isUploadDcId(_shiftedDcId)
|
||||
|| (_realDcType == DcType::Cdn);
|
||||
const auto protocolDcId = getProtocolDcId();
|
||||
InvokeQueued(_testConnections.back().data, [=] {
|
||||
weak->connectToServer(ip, port, protocolSecret, protocolDcId);
|
||||
weak->connectToServer(
|
||||
ip,
|
||||
port,
|
||||
protocolSecret,
|
||||
protocolDcId,
|
||||
protocolForFiles);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue