void MTProtoSession::start(int32 dcenter, uint32 connects) { if (dcId) { DEBUG_LOG(("Session Info: MTProtoSession::start called on already started session")); return; } if (connects < 1) { connects = cConnectionsInSession(); } else if (connects > 4) { connects = 4; } msSendCall = msWait = 0; connect(&timeouter, SIGNAL(timeout()), this, SLOT(checkRequestsByTimer())); timeouter.start(1000); connect(&sender, SIGNAL(timeout()), this, SIGNAL(needToSend())); connect(this, SIGNAL(startSendTimer(int)), &sender, SLOT(start(int))); connect(this, SIGNAL(stopSendTimer()), &sender, SLOT(stop())); connect(this, SIGNAL(needToSendAsync()), this, SIGNAL(needToSend())); MTProtoDCMap &dcs(mtpDCMap()); connections.reserve(connects); for (uint32 i = 0; i < connects; ++i) { connections.push_back(new MTProtoConnection()); dcId = connections.back()->start(&data, dcenter); if (!dcId) { for (MTProtoConnections::const_iterator j = connections.cbegin(), e = connections.cend(); j != e; ++j) { delete *j; } connections.clear(); DEBUG_LOG(("Session Info: could not start connection %1 to dc %2").arg(i).arg(dcenter)); return; } if (!dc) { dcenter = dcId; MTProtoDCMap::const_iterator dcIndex = dcs.constFind(dcId % _mtp_internal::dcShift); if (dcIndex == dcs.cend()) { dc = MTProtoDCPtr(new MTProtoDC(dcId % _mtp_internal::dcShift, mtpAuthKeyPtr())); dcs.insert(dcId % _mtp_internal::dcShift, dc); } else { dc = dcIndex.value(); } ReadLockerAttempt lock(keyMutex()); data.setKey(lock ? dc->getKey() : mtpAuthKeyPtr(0)); if (lock && dc->connectionInited()) { data.setLayerWasInited(true); } connect(dc.data(), SIGNAL(authKeyCreated()), this, SLOT(authKeyCreatedForDC())); connect(dc.data(), SIGNAL(layerWasInited(bool)), this, SLOT(layerWasInitedForDC(bool))); } }
void MTProtoDC::destroyKey() { setKey(mtpAuthKeyPtr()); QMutexLocker lock(&_keysMapForWriteMutex); _keysMapForWrite.remove(_id); }