Skip to content

Commit

Permalink
prepared 0.5.13 - greatly improved network support (bad_msg_notificat…
Browse files Browse the repository at this point in the history
…ion handle, connecting notification, dc full config embed, getting config each launch, dc option notify handle, enum dc for new config
  • Loading branch information
john-preston committed Aug 1, 2014
1 parent 0e031f0 commit 5ce2e2b
Show file tree
Hide file tree
Showing 25 changed files with 266 additions and 76 deletions.
4 changes: 2 additions & 2 deletions Telegram/PrepareLinux.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AppVersionStr=0.5.12
AppVersion=5012
AppVersionStr=0.5.13
AppVersion=5013

if [ -d "./../Linux/Release/deploy/$AppVersionStr" ]; then
echo "Deploy folder for version $AppVersionStr already exists!"
Expand Down
4 changes: 2 additions & 2 deletions Telegram/PrepareLinux32.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AppVersionStr=0.5.12
AppVersion=5012
AppVersionStr=0.5.13
AppVersion=5013

if [ -d "./../Linux/Release/deploy/$AppVersionStr" ]; then
echo "Deploy folder for version $AppVersionStr already exists!"
Expand Down
4 changes: 2 additions & 2 deletions Telegram/PrepareMac.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AppVersionStr=0.5.12
AppVersion=5012
AppVersionStr=0.5.13
AppVersion=5013

if [ -d "./../Mac/Release/deploy/$AppVersionStr" ]; then
echo "Deploy folder for version $AppVersionStr already exists!"
Expand Down
6 changes: 3 additions & 3 deletions Telegram/Setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#define MyAppShortName "Telegram"
#define MyAppName "Telegram Win (Unofficial)"
#define MyAppVersion "0.5.12"
#define MyAppVersionZero "0.5.12"
#define MyAppFullVersion "0.5.12.0"
#define MyAppVersion "0.5.13"
#define MyAppVersionZero "0.5.13"
#define MyAppFullVersion "0.5.13.0"
#define MyAppPublisher "Telegram (Unofficial)"
#define MyAppURL "https://tdesktop.com"
#define MyAppExeName "Telegram.exe"
Expand Down
7 changes: 7 additions & 0 deletions Telegram/SourceFiles/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ namespace {
}
}

void mtpSessionReset(int32 dc) {
if (App::main() && dc == MTP::maindc()) {
App::main()->getDifference();
}
}

class _DebugWaiter : public QObject {
public:

Expand Down Expand Up @@ -569,6 +575,7 @@ void Application::startApp() {
MTP::start();

MTP::setStateChangedHandler(mtpStateChanged);
MTP::setSessionResetHandler(mtpSessionReset);

App::initMedia();

Expand Down
32 changes: 26 additions & 6 deletions Telegram/SourceFiles/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Copyright (c) 2014 John Preston, https://tdesktop.com
*/
#pragma once

static const int32 AppVersion = 5012;
static const wchar_t *AppVersionStr = L"0.5.12";
static const int32 AppVersion = 5013;
static const wchar_t *AppVersionStr = L"0.5.13";
#ifdef Q_OS_WIN
static const wchar_t *AppName = L"Telegram Win (Unofficial)";
#else
Expand All @@ -42,6 +42,8 @@ enum {
MTPTcpConnectionWaitTimeout = 3000, // 3 seconds waiting for tcp, until we accept http
MTPMillerRabinIterCount = 30, // 30 Miller-Rabin iterations for dh_prime primality check

MTPEnumDCTimeout = 4000, // 4 seconds timeout for help_getConfig to work (them move to other dc)

MinReceiveDelay = 1000, // 1 seconds
MaxSelectedItems = 100,

Expand Down Expand Up @@ -94,12 +96,30 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB\n\
return keys;
}

inline const char *cFirstDCIp() {
return cTestMode() ? "173.240.5.253" : "173.240.5.1";
struct BuiltInDc {
int id;
const char *ip;
int port;
};

static const BuiltInDc _builtInDcs[] = {
{ 1, "173.240.5.1", 443 },
{ 2, "149.154.167.50", 443 },
{ 3, "174.140.142.6", 443 },
{ 4, "149.154.167.90", 443 },
{ 5, "116.51.22.2", 443 }
};

static const BuiltInDc _builtInTestDcs[] = {
{ 1, "173.240.5.253", 443 }
};

inline const BuiltInDc *builtInDcs() {
return cTestMode() ? _builtInTestDcs : _builtInDcs;
}

inline int32 cFirstDCPort() {
return 443;
inline int builtInDcsCount() {
return (cTestMode() ? sizeof(_builtInTestDcs) : sizeof(_builtInDcs)) / sizeof(BuiltInDc);
}

static const char *UpdatesPublicKey = "\
Expand Down
14 changes: 1 addition & 13 deletions Telegram/SourceFiles/dialogswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,6 @@ DialogsListWidget::SearchResults &DialogsListWidget::searchList() {
}

DialogsWidget::DialogsWidget(MainWidget *parent) : QWidget(parent)
, _configLoaded(false)
, _drawShadow(true)
, dlgOffset(0)
, dlgCount(-1)
Expand Down Expand Up @@ -1070,7 +1069,6 @@ void DialogsWidget::dialogsReceived(const MTPmessages_Dialogs &dialogs) {
}
} else {
dlgCount = dlgOffset;
loadConfig();
}

dlgPreloading = 0;
Expand Down Expand Up @@ -1137,19 +1135,9 @@ void DialogsWidget::onSearchMore(MsgId minMsgId) {
}
}

void DialogsWidget::loadConfig() {
if (!_configLoaded) {
mtpConfigLoader()->load();
_configLoaded = true;
}
}

void DialogsWidget::loadDialogs() {
if (dlgPreloading) return;
if (dlgCount >= 0 && dlgOffset >= dlgCount) {
loadConfig();
return;
}
if (dlgCount >= 0 && dlgOffset >= dlgCount) return;

int32 loadCount = dlgOffset ? DialogsPerPage : DialogsFirstLoad;
dlgPreloading = MTP::send(MTPmessages_GetDialogs(MTP_int(dlgOffset), MTP_int(0), MTP_int(loadCount)), rpcDone(&DialogsWidget::dialogsReceived), rpcFail(&DialogsWidget::dialogsFailed));
Expand Down
3 changes: 0 additions & 3 deletions Telegram/SourceFiles/dialogswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ public slots:

private:

void loadConfig();
bool _configLoaded;

bool _drawShadow;

void unreadCountsReceived(const QVector<MTPDialog> &dialogs);
Expand Down
8 changes: 4 additions & 4 deletions Telegram/SourceFiles/gui/boxshadow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ void BoxShadow::paint(QPainter &p, const QRect &box, const QPoint &shift, int32
if (left && bottom) p.drawPixmap(box.left() - _size + minus + shift.x(), box.bottom() - minus + 1 + shift.y(), _corners, 0, _size, _size, _size);
for (int32 i = 1; i <= count; ++i) {
p.setPen(_colors[i - 1]->p);
if (top) p.fillRect(box.left() + (left ? minus : 0) + shift.x(), box.top() - count + i + shift.y(), box.width() - (right ? minus : 0) - (left ? minus : 0), st::lineWidth, _colors[i - 1]->b);
if (right) p.fillRect(box.right() + count - i + shift.x(), box.top() + (top ? minus : 0) + shift.y(), st::lineWidth, box.height() - (bottom ? minus : 0) - (top ? minus : 0), _colors[i - 1]->b);
if (bottom) p.fillRect(box.left() + (left ? minus : 0) + shift.x(), box.bottom() + count - i + shift.y(), box.width() - (right ? minus : 0) - (left ? minus : 0), st::lineWidth, _colors[i - 1]->b);
if (left) p.fillRect(box.left() - count + i + shift.x(), box.top() + (top ? minus : 0) + shift.y(), st::lineWidth, box.height() - (bottom ? minus : 0) - (top ? minus : 0), _colors[i - 1]->b);
if (top) p.fillRect(box.left() + (left ? minus : 0) + shift.x(), box.top() - count + i + shift.y(), box.width() - (right ? minus : 0) - (left ? minus : 0), cIntRetinaFactor(), _colors[i - 1]->b);
if (right) p.fillRect(box.right() + count - i + shift.x(), box.top() + (top ? minus : 0) + shift.y(), cIntRetinaFactor(), box.height() - (bottom ? minus : 0) - (top ? minus : 0), _colors[i - 1]->b);
if (bottom) p.fillRect(box.left() + (left ? minus : 0) + shift.x(), box.bottom() + count - i + shift.y(), box.width() - (right ? minus : 0) - (left ? minus : 0), cIntRetinaFactor(), _colors[i - 1]->b);
if (left) p.fillRect(box.left() - count + i + shift.x(), box.top() + (top ? minus : 0) + shift.y(), cIntRetinaFactor(), box.height() - (bottom ? minus : 0) - (top ? minus : 0), _colors[i - 1]->b);
}
}
5 changes: 5 additions & 0 deletions Telegram/SourceFiles/mainwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1734,5 +1734,10 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
const MTPDupdateNotifySettings &d(update.c_updateNotifySettings());
applyNotifySetting(d.vpeer, d.vnotify_settings);
} break;

case mtpc_updateDcOptions: {
const MTPDupdateDcOptions &d(update.c_updateDcOptions());
MTP::updateDcOptions(d.vdc_options.c_vector().v);
} break;
}
}
43 changes: 39 additions & 4 deletions Telegram/SourceFiles/mtproto/mtp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace {

RPCResponseHandler globalHandler;
MTPStateChangedHandler stateChangedHandler = 0;
MTPSessionResetHandler sessionResetHandler = 0;
_mtp_internal::RequestResender *resender = 0;

mtpAuthKey _localKey;
Expand Down Expand Up @@ -342,25 +343,27 @@ namespace _mtp_internal {
void execCallback(mtpRequestId requestId, const mtpPrime *from, const mtpPrime *end) {
ParserMap::iterator i = parserMap.find(requestId);
if (i != parserMap.cend()) {
RPCResponseHandler h(i.value());
parserMap.erase(i);

DEBUG_LOG(("RPC Info: found parser for request %1, trying to parse response..").arg(requestId));
try {
if (from >= end) throw mtpErrorInsufficient();

if (*from == mtpc_rpc_error) {
RPCError err(MTPRpcError(from, end));
DEBUG_LOG(("RPC Info: error received, code %1, type %2, description: %3").arg(err.code()).arg(err.type()).arg(err.description()));
if (!rpcErrorOccured(requestId, i.value(), err)) {
if (!rpcErrorOccured(requestId, h, err)) {
return;
}
} else {
if (i.value().onDone) (*i.value().onDone)(requestId, from, end);
if (h.onDone) (*h.onDone)(requestId, from, end);
}
} catch (Exception &e) {
if (!rpcErrorOccured(requestId, i.value(), rpcClientError("RESPONSE_PARSE_FAILED", QString("exception text: ") + e.what()))) {
if (!rpcErrorOccured(requestId, h, rpcClientError("RESPONSE_PARSE_FAILED", QString("exception text: ") + e.what()))) {
return;
}
}
parserMap.erase(i);
requestMap.remove(requestId);
} else {
DEBUG_LOG(("RPC Info: parser not found for %1").arg(requestId));
Expand All @@ -376,6 +379,10 @@ namespace _mtp_internal {
if (stateChangedHandler) stateChangedHandler(dc, state);
}

void onSessionReset(int32 dc) {
if (sessionResetHandler) sessionResetHandler(dc);
}

bool rpcErrorOccured(mtpRequestId requestId, const RPCFailHandlerPtr &onFail, const RPCError &err) { // return true if need to clean request data
if (onErrorDefault(requestId, err)) {
return false;
Expand Down Expand Up @@ -469,6 +476,15 @@ namespace MTP {
(*i)->restart();
}
}
void restart(int32 dcMask) {
if (!started) return;

for (Sessions::const_iterator i = sessions.cbegin(), e = sessions.cend(); i != e; ++i) {
if ((*i)->getDC() % _mtp_internal::dcShift == dcMask % _mtp_internal::dcShift) {
(*i)->restart();
}
}
}

void setLayer(uint32 l) {
if (l > mtpLayerMax) {
Expand Down Expand Up @@ -538,6 +554,14 @@ namespace MTP {
_mtp_internal::clearCallbacks(requestId);
}

void killSession(int32 dc) {
Sessions::iterator i = sessions.find(dc);
if (i != sessions.end()) {
i.value()->stop();
sessions.erase(i);
}
}

int32 state(mtpRequestId requestId) {
if (requestId > 0) {
QMutexLocker locker(&requestByDCLock);
Expand All @@ -556,6 +580,7 @@ namespace MTP {
}
delete resender;
resender = 0;
mtpDestroyConfigLoader();
}

void authed(int32 uid) {
Expand Down Expand Up @@ -583,10 +608,20 @@ namespace MTP {
stateChangedHandler = handler;
}

void setSessionResetHandler(MTPSessionResetHandler handler) {
sessionResetHandler = handler;
}

void clearGlobalHandlers() {
setGlobalDoneHandler(RPCDoneHandlerPtr());
setGlobalFailHandler(RPCFailHandlerPtr());
setStateChangedHandler(0);
setSessionResetHandler(0);
}

void updateDcOptions(const QVector<MTPDcOption> &options) {
mtpUpdateDcOptions(options);
App::writeUserConfig();
}

void writeConfig(QDataStream &stream) {
Expand Down
7 changes: 7 additions & 0 deletions Telegram/SourceFiles/mtproto/mtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace _mtp_internal {
void execCallback(mtpRequestId requestId, const mtpPrime *from, const mtpPrime *end);
void globalCallback(const mtpPrime *from, const mtpPrime *end);
void onStateChange(int32 dc, int32 state);
void onSessionReset(int32 dc);
bool rpcErrorOccured(mtpRequestId requestId, const RPCFailHandlerPtr &onFail, const RPCError &err); // return true if need to clean request data
inline bool rpcErrorOccured(mtpRequestId requestId, const RPCResponseHandler &handler, const RPCError &err) {
return rpcErrorOccured(requestId, handler.onFail, err);
Expand All @@ -59,9 +60,11 @@ namespace MTP {

static const uint32 dld = 1 * _mtp_internal::dcShift; // send(req, callbacks, MTP::dld + dc) - for download
static const uint32 upl = 2 * _mtp_internal::dcShift; // send(req, callbacks, MTP::upl + dc) - for upload
static const uint32 cfg = 3 * _mtp_internal::dcShift; // send(MTPhelp_GetConfig(), MTP::cfg + dc) - for dc enum

void start();
void restart();
void restart(int32 dcMask);

void setLayer(uint32 layer);

Expand All @@ -79,6 +82,7 @@ namespace MTP {
return send(request, RPCResponseHandler(onDone, onFail), dc, msCanWait);
}
void cancel(mtpRequestId req);
void killSession(int32 dc);

enum {
RequestSent = 0,
Expand All @@ -98,8 +102,11 @@ namespace MTP {
void setGlobalDoneHandler(RPCDoneHandlerPtr handler);
void setGlobalFailHandler(RPCFailHandlerPtr handler);
void setStateChangedHandler(MTPStateChangedHandler handler);
void setSessionResetHandler(MTPSessionResetHandler handler);
void clearGlobalHandlers();

void updateDcOptions(const QVector<MTPDcOption> &options);

template <typename T>
T nonce() {
T result;
Expand Down
3 changes: 3 additions & 0 deletions Telegram/SourceFiles/mtproto/mtpConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,7 @@ MTProtoConnectionPrivate::MTProtoConnectionPrivate(QThread *thread, MTProtoConne
connect(this, SIGNAL(needToReceive()), sessionData->owner(), SLOT(tryToReceive()));
connect(this, SIGNAL(stateChanged(qint32)), sessionData->owner(), SLOT(onConnectionStateChange(qint32)));
connect(sessionData->owner(), SIGNAL(needToSend()), this, SLOT(tryToSend()));
connect(this, SIGNAL(sessionResetDone()), sessionData->owner(), SLOT(onResetDone()));

oldConnectionTimer.setSingleShot(true);
connCheckTimer.setSingleShot(true);
Expand Down Expand Up @@ -1247,6 +1248,8 @@ void MTProtoConnectionPrivate::resetSession() { // recreate all msg_id and msg_s
}
}
}

emit sessionResetDone();
}

mtpMsgId MTProtoConnectionPrivate::prepareToSend(mtpRequest &request, mtpMsgId currentLastId) {
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/mtproto/mtpConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ class MTProtoConnectionPrivate : public QObject {
void needToReceive();
void needToRestart();
void stateChanged(qint32 newState);
void sessionResetDone();

public slots:

Expand Down
Loading

0 comments on commit 5ce2e2b

Please sign in to comment.