Beispiel #1
0
MTProtoDC::MTProtoDC(int32 id, const mtpAuthKeyPtr &key) : _id(id), _key(key), _connectionInited(false) {
	connect(this, SIGNAL(authKeyCreated()), this, SLOT(authKeyWrite()), Qt::QueuedConnection);

	QMutexLocker lock(&_keysMapForWriteMutex);
	if (_key) {
		_keysMapForWrite[_id] = _key;
	} else {
		_keysMapForWrite.remove(_id);
	}
}
Beispiel #2
0
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)));
		}
	}
Beispiel #3
0
void MTProtoDC::setKey(const mtpAuthKeyPtr &key) {
	DEBUG_LOG(("AuthKey Info: MTProtoDC::setKey(%1), emitting authKeyCreated, dc %2").arg(key ? key->keyId() : 0).arg(_id));
	_key = key;
	_connectionInited = false;
	emit authKeyCreated();

	QMutexLocker lock(&_keysMapForWriteMutex);
	if (_key) {
		_keysMapForWrite[_id] = _key;
	} else {
		_keysMapForWrite.remove(_id);
	}
}