예제 #1
0
bool AddressManager::handleNetworkAddress(const QString& lookupString) {
    const QString IP_ADDRESS_REGEX_STRING = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}"
        "([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(:\\d{1,5})?$";
    
    const QString HOSTNAME_REGEX_STRING = "^((?:[A-Z0-9]|[A-Z0-9][A-Z0-9\\-]{0,61}[A-Z0-9])"
        "(?:\\.(?:[A-Z0-9]|[A-Z0-9][A-Z0-9\\-]{0,61}[A-Z0-9]))+|localhost)(:{1}\\d{1,5})?$";
    
    QRegExp hostnameRegex(HOSTNAME_REGEX_STRING, Qt::CaseInsensitive);
    
    if (hostnameRegex.indexIn(lookupString) != -1) {
        emit possibleDomainChangeRequired(hostnameRegex.cap(0));
        emit lookupResultsFinished();
        return true;
    }
    
    QRegExp ipAddressRegex(IP_ADDRESS_REGEX_STRING);
    
    if (ipAddressRegex.indexIn(lookupString) != -1) {
        emit possibleDomainChangeRequired(ipAddressRegex.cap(0));
        emit lookupResultsFinished();
        return true;
    }
    
    return false;
}
예제 #2
0
void AddressManager::setDomainInfo(const QString& hostname, quint16 port) {
    _rootPlaceName = hostname;
    _rootPlaceID = QUuid();
    
    qDebug() << "Possible domain change required to connect to domain at" << hostname << "on" << port;
    
    emit possibleDomainChangeRequired(hostname, port);
}
예제 #3
0
void AddressManager::setDomainInfo(const QString& hostname, quint16 port, LookupTrigger trigger) {
    setHost(hostname, trigger);

    _rootPlaceID = QUuid();

    qCDebug(networking) << "Possible domain change required to connect to domain at" << hostname << "on" << port;

    DependencyManager::get<NodeList>()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::HandleAddress);

    emit possibleDomainChangeRequired(hostname, port);
}
예제 #4
0
bool AddressManager::setDomainInfo(const QString& hostname, quint16 port, LookupTrigger trigger) {
    bool hostChanged = setHost(hostname, trigger, port);

    // clear any current place information
    _rootPlaceID = QUuid();
    _placeName.clear();

    qCDebug(networking) << "Possible domain change required to connect to domain at" << hostname << "on" << port;

    DependencyManager::get<NodeList>()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::HandleAddress);

    emit possibleDomainChangeRequired(hostname, port);

    return hostChanged;
}
예제 #5
0
void AddressManager::handleAPIResponse(const QJsonObject &jsonObject) {
    QJsonObject dataObject = jsonObject["data"].toObject();
    
    const QString ADDRESS_API_DOMAIN_KEY = "domain";
    const QString ADDRESS_API_ONLINE_KEY = "online";
    
    if (!dataObject.contains(ADDRESS_API_ONLINE_KEY)
        || dataObject[ADDRESS_API_ONLINE_KEY].toBool()) {
        
        if (dataObject.contains(ADDRESS_API_DOMAIN_KEY)) {
            QJsonObject domainObject = dataObject[ADDRESS_API_DOMAIN_KEY].toObject();
            
            const QString DOMAIN_NETWORK_ADDRESS_KEY = "network_address";
            QString domainHostname = domainObject[DOMAIN_NETWORK_ADDRESS_KEY].toString();
            
            emit possibleDomainChangeRequired(domainHostname);
            
            // take the path that came back
            const QString LOCATION_KEY = "location";
            const QString LOCATION_PATH_KEY = "path";
            QString returnedPath;
            
            if (domainObject.contains(LOCATION_PATH_KEY)) {
                returnedPath = domainObject[LOCATION_PATH_KEY].toString();
            } else if (domainObject.contains(LOCATION_KEY)) {
                returnedPath = domainObject[LOCATION_KEY].toObject()[LOCATION_PATH_KEY].toString();
            }
            
            bool shouldFaceViewpoint = dataObject.contains(ADDRESS_API_ONLINE_KEY);
            
            if (!returnedPath.isEmpty()) {
                // try to parse this returned path as a viewpoint, that's the only thing it could be for now
                if (!handleRelativeViewpoint(returnedPath, shouldFaceViewpoint)) {
                    qDebug() << "Received a location path that was could not be handled as a viewpoint -" << returnedPath;
                }
            }
            
        } else {
            qDebug() << "Received an address manager API response with no domain key. Cannot parse.";
            qDebug() << jsonObject;
        }
    } else {
        // we've been told that this result exists but is offline, emit our signal so the application can handle
        emit lookupResultIsOffline();
    }
    emit lookupResultsFinished();
}
예제 #6
0
void AddressManager::goToAddressFromObject(const QVariantMap& dataObject, const QNetworkReply& reply) {

    const QString DATA_OBJECT_PLACE_KEY = "place";
    const QString DATA_OBJECT_USER_LOCATION_KEY = "location";

    QVariantMap locationMap;
    if (dataObject.contains(DATA_OBJECT_PLACE_KEY)) {
        locationMap = dataObject[DATA_OBJECT_PLACE_KEY].toMap();
    } else if (dataObject.contains(DATA_OBJECT_DOMAIN_KEY)) {
        locationMap = dataObject;
    } else {
        locationMap = dataObject[DATA_OBJECT_USER_LOCATION_KEY].toMap();
    }

    if (!locationMap.isEmpty()) {
        const QString LOCATION_API_ROOT_KEY = "root";
        const QString LOCATION_API_DOMAIN_KEY = "domain";
        const QString LOCATION_API_ONLINE_KEY = "online";

        if (!locationMap.contains(LOCATION_API_ONLINE_KEY)
            || locationMap[LOCATION_API_ONLINE_KEY].toBool()) {

            QVariantMap rootMap = locationMap[LOCATION_API_ROOT_KEY].toMap();
            if (rootMap.isEmpty()) {
                rootMap = locationMap;
            }

            QVariantMap domainObject = rootMap[LOCATION_API_DOMAIN_KEY].toMap();

            if (!domainObject.isEmpty()) {
                const QString DOMAIN_NETWORK_ADDRESS_KEY = "network_address";
                const QString DOMAIN_NETWORK_PORT_KEY = "network_port";
                const QString DOMAIN_ICE_SERVER_ADDRESS_KEY = "ice_server_address";

                DependencyManager::get<NodeList>()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::HandleAddress);

                const QString DOMAIN_ID_KEY = "id";
                QString domainIDString = domainObject[DOMAIN_ID_KEY].toString();
                QUuid domainID(domainIDString);

                if (domainObject.contains(DOMAIN_NETWORK_ADDRESS_KEY)) {
                    QString domainHostname = domainObject[DOMAIN_NETWORK_ADDRESS_KEY].toString();

                    quint16 domainPort = domainObject.contains(DOMAIN_NETWORK_PORT_KEY)
                        ? domainObject[DOMAIN_NETWORK_PORT_KEY].toUInt()
                        : DEFAULT_DOMAIN_SERVER_PORT;

                    qCDebug(networking) << "Possible domain change required to connect to" << domainHostname
                        << "on" << domainPort;
                    emit possibleDomainChangeRequired(domainHostname, domainPort);
                } else {
                    QString iceServerAddress = domainObject[DOMAIN_ICE_SERVER_ADDRESS_KEY].toString();

                    qCDebug(networking) << "Possible domain change required to connect to domain with ID" << domainID
                        << "via ice-server at" << iceServerAddress;

                    emit possibleDomainChangeRequiredViaICEForID(iceServerAddress, domainID);
                }

                LookupTrigger trigger = (LookupTrigger) reply.property(LOOKUP_TRIGGER_KEY).toInt();

                // set our current root place id to the ID that came back
                const QString PLACE_ID_KEY = "id";
                _rootPlaceID = rootMap[PLACE_ID_KEY].toUuid();

                // set our current root place name to the name that came back
                const QString PLACE_NAME_KEY = "name";
                QString placeName = rootMap[PLACE_NAME_KEY].toString();
                if (!placeName.isEmpty()) {
                    setHost(placeName, trigger);
                } else {
                    setHost(domainIDString, trigger);
                }

                // check if we had a path to override the path returned
                QString overridePath = reply.property(OVERRIDE_PATH_KEY).toString();

                if (!overridePath.isEmpty()) {
                    handlePath(overridePath, trigger);
                } else {
                    // take the path that came back
                    const QString PLACE_PATH_KEY = "path";
                    QString returnedPath = locationMap[PLACE_PATH_KEY].toString();

                    bool shouldFaceViewpoint = locationMap.contains(LOCATION_API_ONLINE_KEY);

                    if (!returnedPath.isEmpty()) {
                        if (shouldFaceViewpoint) {
                            // try to parse this returned path as a viewpoint, that's the only thing it could be for now
                            if (!handleViewpoint(returnedPath, shouldFaceViewpoint)) {
                                qCDebug(networking) << "Received a location path that was could not be handled as a viewpoint -"
                                    << returnedPath;
                            }
                        } else {
                            handlePath(returnedPath, trigger);
                        }
                    } else {
                        // we're going to hit the index path, set that as the _newHostLookupPath
                        _newHostLookupPath = INDEX_PATH;

                        // we didn't override the path or get one back - ask the DS for the viewpoint of its index path
                        // which we will jump to if it exists
                        emit pathChangeRequired(INDEX_PATH);
                    }
                }

            } else {
                qCDebug(networking) << "Received an address manager API response with no domain key. Cannot parse.";
                qCDebug(networking) << locationMap;
            }
        } else {
            // we've been told that this result exists but is offline, emit our signal so the application can handle
            emit lookupResultIsOffline();
        }
    } else {
        qCDebug(networking) << "Received an address manager API response with no location key or place key. Cannot parse.";
        qCDebug(networking) << locationMap;
    }
}
예제 #7
0
void AddressManager::goToAddressFromObject(const QVariantMap& dataObject, const QNetworkReply& reply) {
    
    const QString DATA_OBJECT_PLACE_KEY = "place";
    const QString DATA_OBJECT_USER_LOCATION_KEY = "location";
    
    QVariantMap locationMap;
    if (dataObject.contains(DATA_OBJECT_PLACE_KEY)) {
        locationMap = dataObject[DATA_OBJECT_PLACE_KEY].toMap();
    } else {
        locationMap = dataObject[DATA_OBJECT_USER_LOCATION_KEY].toMap();
    }
    
    if (!locationMap.isEmpty()) {
        const QString LOCATION_API_ROOT_KEY = "root";
        const QString LOCATION_API_DOMAIN_KEY = "domain";
        const QString LOCATION_API_ONLINE_KEY = "online";
        
        if (!locationMap.contains(LOCATION_API_ONLINE_KEY)
            || locationMap[LOCATION_API_ONLINE_KEY].toBool()) {
            
            QVariantMap rootMap = locationMap[LOCATION_API_ROOT_KEY].toMap();
            if (rootMap.isEmpty()) {
                rootMap = locationMap;
            }
            
            QVariantMap domainObject = rootMap[LOCATION_API_DOMAIN_KEY].toMap();
            
            if (!domainObject.isEmpty()) {
                const QString DOMAIN_NETWORK_ADDRESS_KEY = "network_address";
                const QString DOMAIN_ICE_SERVER_ADDRESS_KEY = "ice_server_address";
                
                if (domainObject.contains(DOMAIN_NETWORK_ADDRESS_KEY)) {
                    QString domainHostname = domainObject[DOMAIN_NETWORK_ADDRESS_KEY].toString();
                    
                    qDebug() << "Possible domain change required to connect to" << domainHostname
                        << "on" << DEFAULT_DOMAIN_SERVER_PORT;
                    emit possibleDomainChangeRequired(domainHostname, DEFAULT_DOMAIN_SERVER_PORT);
                } else {
                    QString iceServerAddress = domainObject[DOMAIN_ICE_SERVER_ADDRESS_KEY].toString();
                    
                    const QString DOMAIN_ID_KEY = "id";
                    QString domainIDString = domainObject[DOMAIN_ID_KEY].toString();
                    QUuid domainID(domainIDString);
                    
                    qDebug() << "Possible domain change required to connect to domain with ID" << domainID
                        << "via ice-server at" << iceServerAddress;
                    
                    emit possibleDomainChangeRequiredViaICEForID(iceServerAddress, domainID);
                }
                
                // set our current root place id to the ID that came back
                const QString PLACE_ID_KEY = "id";
                _rootPlaceID = rootMap[PLACE_ID_KEY].toUuid();
                
                // set our current root place name to the name that came back
                const QString PLACE_NAME_KEY = "name";
                QString newRootPlaceName = rootMap[PLACE_NAME_KEY].toString();
                setRootPlaceName(newRootPlaceName);
                
                // check if we had a path to override the path returned
                QString overridePath = reply.property(OVERRIDE_PATH_KEY).toString();
                
                if (!overridePath.isEmpty()) {
                    if (!handleRelativeViewpoint(overridePath)){
                        qDebug() << "User entered path could not be handled as a viewpoint - " << overridePath;
                    }
                } else {
                    // take the path that came back
                    const QString PLACE_PATH_KEY = "path";
                    QString returnedPath = locationMap[PLACE_PATH_KEY].toString();
                    
                    bool shouldFaceViewpoint = locationMap.contains(LOCATION_API_ONLINE_KEY);
                    
                    if (!returnedPath.isEmpty()) {
                        // try to parse this returned path as a viewpoint, that's the only thing it could be for now
                        if (!handleRelativeViewpoint(returnedPath, shouldFaceViewpoint)) {
                            qDebug() << "Received a location path that was could not be handled as a viewpoint -" << returnedPath;
                        }
                    }
                }
                
                
            } else {
                qDebug() << "Received an address manager API response with no domain key. Cannot parse.";
                qDebug() << locationMap;
            }
        } else {
            // we've been told that this result exists but is offline, emit our signal so the application can handle
            emit lookupResultIsOffline();
        }
    } else {
        qDebug() << "Received an address manager API response with no location key or place key. Cannot parse.";
        qDebug() << locationMap;
    }
}