check point with protocol refusal working

This commit is contained in:
Brad Hefta-Gaub 2016-05-24 15:20:11 -07:00
parent 1cf8236860
commit 12a1857280
7 changed files with 72 additions and 14 deletions

View file

@ -548,12 +548,27 @@ void DomainGatekeeper::sendConnectionDeniedPacket(const QString& reason, const H
quint16 payloadSize = utfString.size(); quint16 payloadSize = utfString.size();
// setup the DomainConnectionDenied packet // setup the DomainConnectionDenied packet
auto connectionDeniedPacket = NLPacket::create(PacketType::DomainConnectionDenied, payloadSize + sizeof(payloadSize)); auto connectionDeniedPacket = NLPacket::create(PacketType::DomainConnectionDenied); // , payloadSize + sizeof(payloadSize)
// pack in the reason the connection was denied (the client displays this) // pack in the reason the connection was denied (the client displays this)
if (payloadSize > 0) { if (payloadSize > 0) {
qDebug() << __FUNCTION__ << "line:" << __LINE__ << "connectionDeniedPacket->getDataSize():" << connectionDeniedPacket->getDataSize();
qDebug() << __FUNCTION__ << "about to write reasonCode:" << (int)reasonCode;
uint8_t reasonCodeWire = (uint8_t)reasonCode;
qDebug() << __FUNCTION__ << "about to write reasonCodeWire:" << (int)reasonCodeWire;
qDebug() << __FUNCTION__ << "line:" << __LINE__ << "connectionDeniedPacket->getDataSize():" << connectionDeniedPacket->getDataSize();
connectionDeniedPacket->writePrimitive(reasonCodeWire);
qDebug() << __FUNCTION__ << "line:" << __LINE__ << "connectionDeniedPacket->getDataSize():" << connectionDeniedPacket->getDataSize();
qDebug() << __FUNCTION__ << "about to write payloadSize:" << payloadSize;
qDebug() << __FUNCTION__ << "line:" << __LINE__ << "connectionDeniedPacket->getDataSize():" << connectionDeniedPacket->getDataSize();
connectionDeniedPacket->writePrimitive(payloadSize); connectionDeniedPacket->writePrimitive(payloadSize);
qDebug() << __FUNCTION__ << "line:" << __LINE__ << "connectionDeniedPacket->getDataSize():" << connectionDeniedPacket->getDataSize();
qDebug() << __FUNCTION__ << "about to write utfString:" << utfString;
qDebug() << __FUNCTION__ << "about to write utfString.size():" << utfString.size();
qDebug() << __FUNCTION__ << "line:" << __LINE__ << "connectionDeniedPacket->getDataSize():" << connectionDeniedPacket->getDataSize();
connectionDeniedPacket->write(utfString); connectionDeniedPacket->write(utfString);
qDebug() << __FUNCTION__ << "line:" << __LINE__ << "connectionDeniedPacket->getDataSize():" << connectionDeniedPacket->getDataSize();
} }
// send the packet off // send the packet off

View file

@ -630,8 +630,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
connect(&domainHandler, SIGNAL(connectedToDomain(const QString&)), SLOT(updateWindowTitle())); connect(&domainHandler, SIGNAL(connectedToDomain(const QString&)), SLOT(updateWindowTitle()));
connect(&domainHandler, SIGNAL(disconnectedFromDomain()), SLOT(updateWindowTitle())); connect(&domainHandler, SIGNAL(disconnectedFromDomain()), SLOT(updateWindowTitle()));
connect(&domainHandler, SIGNAL(disconnectedFromDomain()), SLOT(clearDomainOctreeDetails())); connect(&domainHandler, SIGNAL(disconnectedFromDomain()), SLOT(clearDomainOctreeDetails()));
connect(&domainHandler, &DomainHandler::resetting, nodeList.data(), &NodeList::resetDomainServerCheckInVersion); connect(&domainHandler, &DomainHandler::resetting, nodeList.data(), &NodeList::resetDomainServerCheckInVersion);
connect(&domainHandler, &DomainHandler::domainConnectionRefused, this, &Application::domainConnectionRefused);
// update our location every 5 seconds in the metaverse server, assuming that we are authenticated with one // update our location every 5 seconds in the metaverse server, assuming that we are authenticated with one
const qint64 DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS = 5 * MSECS_PER_SECOND; const qint64 DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS = 5 * MSECS_PER_SECOND;
@ -1068,6 +1068,17 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
firstRun.set(false); firstRun.set(false);
} }
void Application::domainConnectionRefused(const QString& reasonMessage, int reasonCode) {
qDebug() << __FUNCTION__ << "message:" << reasonMessage << "code:" << reasonCode;
qDebug() << __FUNCTION__ << "DomainHandler::ConnectionRefusedReason::ProtocolMismatch:" << (int)DomainHandler::ConnectionRefusedReason::ProtocolMismatch;
if (static_cast<DomainHandler::ConnectionRefusedReason>(reasonCode) == DomainHandler::ConnectionRefusedReason::ProtocolMismatch) {
qDebug() << __FUNCTION__ << " PROTOCOL MISMATCH!!!";
notifyPacketVersionMismatch();
}
}
QString Application::getUserAgent() { QString Application::getUserAgent() {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
QString userAgent; QString userAgent;

View file

@ -330,6 +330,7 @@ private slots:
static void packetSent(quint64 length); static void packetSent(quint64 length);
void updateDisplayMode(); void updateDisplayMode();
void updateInputModes(); void updateInputModes();
void domainConnectionRefused(const QString& reasonMessage, int reason);
private: private:
static void initDisplay(); static void initDisplay();

View file

@ -47,7 +47,7 @@ public slots:
signals: signals:
void domainChanged(const QString& domainHostname); void domainChanged(const QString& domainHostname);
void svoImportRequested(const QString& url); void svoImportRequested(const QString& url);
void domainConnectionRefused(const QString& reasonMessage, DomainHandler::ConnectionRefusedReason reason = DomainHandler::ConnectionRefusedReason::Unknown); void domainConnectionRefused(const QString& reasonMessage, int reason);
private slots: private slots:
WebWindowClass* doCreateWebWindow(const QString& title, const QString& url, int width, int height); WebWindowClass* doCreateWebWindow(const QString& title, const QString& url, int width, int height);

View file

@ -103,7 +103,9 @@ void DomainHandler::hardReset() {
_sockAddr.clear(); _sockAddr.clear();
_hasCheckedForAccessToken = false; _hasCheckedForAccessToken = false;
_domainConnectionRefusals.clear();
//qDebug() << __FUNCTION__ << "about to call _domainConnectionRefusals.clear();";
//_domainConnectionRefusals.clear();
// clear any pending path we may have wanted to ask the previous DS about // clear any pending path we may have wanted to ask the previous DS about
_pendingPath.clear(); _pendingPath.clear();
@ -142,6 +144,10 @@ void DomainHandler::setSocketAndID(const QString& hostname, quint16 port, const
// set the new hostname // set the new hostname
_hostname = hostname; _hostname = hostname;
// FIXME - is this the right place???
qDebug() << __FUNCTION__ << "about to call _domainConnectionRefusals.clear();";
_domainConnectionRefusals.clear();
qCDebug(networking) << "Updated domain hostname to" << _hostname; qCDebug(networking) << "Updated domain hostname to" << _hostname;
// re-set the sock addr to null and fire off a lookup of the IP address for this domain-server's hostname // re-set the sock addr to null and fire off a lookup of the IP address for this domain-server's hostname
@ -366,25 +372,50 @@ bool DomainHandler::reasonSuggestsLogin(ConnectionRefusedReason reasonCode) {
void DomainHandler::processDomainServerConnectionDeniedPacket(QSharedPointer<ReceivedMessage> message) { void DomainHandler::processDomainServerConnectionDeniedPacket(QSharedPointer<ReceivedMessage> message) {
// Read deny reason from packet // Read deny reason from packet
ConnectionRefusedReason reasonCode = DomainHandler::ConnectionRefusedReason::Unknown; uint8_t reasonCodeWire;
qDebug() << __FUNCTION__ << "line:" << __LINE__ << "message->getPosition():" << message->getPosition();
message->readPrimitive(&reasonCodeWire);
qDebug() << __FUNCTION__ << "reasonCodeWire:" << reasonCodeWire;
ConnectionRefusedReason reasonCode = static_cast<ConnectionRefusedReason>(reasonCodeWire);
qDebug() << __FUNCTION__ << "reasonCode:" << (int)reasonCode;
qDebug() << __FUNCTION__ << "line:" << __LINE__ << "message->getPosition():" << message->getPosition();
quint16 reasonSize; quint16 reasonSize;
message->readPrimitive(&reasonSize); message->readPrimitive(&reasonSize);
QString reasonMessage = QString::fromUtf8(message->readWithoutCopy(reasonSize)); qDebug() << __FUNCTION__ << "reasonSize:" << reasonSize;
qDebug() << __FUNCTION__ << "line:" << __LINE__ << "message->getPosition():" << message->getPosition();
auto reasonText = message->readWithoutCopy(reasonSize);
qDebug() << __FUNCTION__ << "line:" << __LINE__ << "reasonText:" << reasonText;
QString reasonMessage = QString::fromUtf8(reasonText);
qDebug() << __FUNCTION__ << "line:" << __LINE__ << "reasonMessage:" << reasonMessage;
qDebug() << __FUNCTION__ << "line:" << __LINE__ << "message->getPosition():" << message->getPosition();
// output to the log so the user knows they got a denied connection request // output to the log so the user knows they got a denied connection request
// and check and signal for an access token so that we can make sure they are logged in // and check and signal for an access token so that we can make sure they are logged in
qCWarning(networking) << "The domain-server denied a connection request: " << reasonMessage; qCWarning(networking) << "The domain-server denied a connection request: " << reasonMessage;
qCWarning(networking) << "Make sure you are logged in.";
qDebug(networking) << "_domainConnectionRefusals:" << _domainConnectionRefusals;
if (!_domainConnectionRefusals.contains(reasonMessage)) { if (!_domainConnectionRefusals.contains(reasonMessage)) {
qDebug(networking) << "about to call _domainConnectionRefusals.append(reasonMessage);";
_domainConnectionRefusals.append(reasonMessage); _domainConnectionRefusals.append(reasonMessage);
emit domainConnectionRefused(reasonMessage, reasonCode); qDebug(networking) << "_domainConnectionRefusals:" << _domainConnectionRefusals;
emit domainConnectionRefused(reasonMessage, (int)reasonCode);
} else {
qDebug(networking) << "ALREADY EMITTED domainConnectionRefused() ----------------------------";
} }
auto accountManager = DependencyManager::get<AccountManager>(); auto accountManager = DependencyManager::get<AccountManager>();
// Some connection refusal reasons imply that a login is required. If so, suggest a new login // Some connection refusal reasons imply that a login is required. If so, suggest a new login
if (reasonSuggestsLogin(reasonCode)) { if (reasonSuggestsLogin(reasonCode)) {
qCWarning(networking) << "Make sure you are logged in.";
if (!_hasCheckedForAccessToken) { if (!_hasCheckedForAccessToken) {
accountManager->checkAndSignalForAccessToken(); accountManager->checkAndSignalForAccessToken();
_hasCheckedForAccessToken = true; _hasCheckedForAccessToken = true;

View file

@ -124,7 +124,7 @@ signals:
void settingsReceived(const QJsonObject& domainSettingsObject); void settingsReceived(const QJsonObject& domainSettingsObject);
void settingsReceiveFail(); void settingsReceiveFail();
void domainConnectionRefused(QString reasonMessage, ConnectionRefusedReason reason = ConnectionRefusedReason::Unknown); void domainConnectionRefused(QString reasonMessage, int reason);
private: private:
bool reasonSuggestsLogin(ConnectionRefusedReason reasonCode); bool reasonSuggestsLogin(ConnectionRefusedReason reasonCode);

View file

@ -310,7 +310,7 @@ void PacketReceiver::handleVerifiedMessage(QSharedPointer<ReceivedMessage> recei
Q_ARG(QSharedPointer<ReceivedMessage>, receivedMessage), Q_ARG(QSharedPointer<ReceivedMessage>, receivedMessage),
Q_ARG(SharedNodePointer, matchingNode)); Q_ARG(SharedNodePointer, matchingNode));
qDebug() << __FUNCTION__ << "line:" << __LINE__ << "success:" << success << "packetType:" << packetType; //qDebug() << __FUNCTION__ << "line:" << __LINE__ << "success:" << success << "packetType:" << packetType;
} else if (metaMethod.parameterTypes().contains(QSHAREDPOINTER_NODE_NORMALIZED)) { } else if (metaMethod.parameterTypes().contains(QSHAREDPOINTER_NODE_NORMALIZED)) {
success = metaMethod.invoke(listener.object, success = metaMethod.invoke(listener.object,
@ -318,19 +318,19 @@ void PacketReceiver::handleVerifiedMessage(QSharedPointer<ReceivedMessage> recei
Q_ARG(QSharedPointer<ReceivedMessage>, receivedMessage), Q_ARG(QSharedPointer<ReceivedMessage>, receivedMessage),
Q_ARG(QSharedPointer<Node>, matchingNode)); Q_ARG(QSharedPointer<Node>, matchingNode));
qDebug() << __FUNCTION__ << "line:" << __LINE__ << "success:" << success << "packetType:" << packetType; //qDebug() << __FUNCTION__ << "line:" << __LINE__ << "success:" << success << "packetType:" << packetType;
} else { } else {
success = metaMethod.invoke(listener.object, success = metaMethod.invoke(listener.object,
connectionType, connectionType,
Q_ARG(QSharedPointer<ReceivedMessage>, receivedMessage)); Q_ARG(QSharedPointer<ReceivedMessage>, receivedMessage));
qDebug() << __FUNCTION__ << "line:" << __LINE__ << "success:" << success << "packetType:" << packetType; //qDebug() << __FUNCTION__ << "line:" << __LINE__ << "success:" << success << "packetType:" << packetType;
} }
} else { } else {
listenerIsDead = true; listenerIsDead = true;
} }
} else { } else {
qDebug() << __FUNCTION__ << "line:" << __LINE__ << "Got verified unsourced packet list." << "packetType:" << packetType; //qDebug() << __FUNCTION__ << "line:" << __LINE__ << "Got verified unsourced packet list." << "packetType:" << packetType;
// qDebug() << "Got verified unsourced packet list: " << QString(nlPacketList->getMessage()); // qDebug() << "Got verified unsourced packet list: " << QString(nlPacketList->getMessage());
emit dataReceived(NodeType::Unassigned, receivedMessage->getSize()); emit dataReceived(NodeType::Unassigned, receivedMessage->getSize());
@ -340,7 +340,7 @@ void PacketReceiver::handleVerifiedMessage(QSharedPointer<ReceivedMessage> recei
success = listener.method.invoke(listener.object, success = listener.method.invoke(listener.object,
Q_ARG(QSharedPointer<ReceivedMessage>, receivedMessage)); Q_ARG(QSharedPointer<ReceivedMessage>, receivedMessage));
qDebug() << __FUNCTION__ << "line:" << __LINE__ << "success:" << success << "packetType:" << packetType; //qDebug() << __FUNCTION__ << "line:" << __LINE__ << "success:" << success << "packetType:" << packetType;
} else { } else {
listenerIsDead = true; listenerIsDead = true;
} }