void tst_QDnsLookup::lookupAbortRetry()
{
    QDnsLookup lookup;

    // try and abort the lookup
    lookup.setType(QDnsLookup::A);
    lookup.setName(domainName("a-single"));
    lookup.lookup();
    lookup.abort();
    QVERIFY(waitForDone(&lookup));
    QVERIFY(lookup.isFinished());
    QCOMPARE(int(lookup.error()), int(QDnsLookup::OperationCancelledError));
    QVERIFY(lookup.hostAddressRecords().isEmpty());

    // retry a different lookup
    lookup.setType(QDnsLookup::AAAA);
    lookup.setName(domainName("aaaa-single"));
    lookup.lookup();
    QVERIFY(waitForDone(&lookup));
    QVERIFY(lookup.isFinished());
    QCOMPARE(int(lookup.error()), int(QDnsLookup::NoError));
    QVERIFY(!lookup.hostAddressRecords().isEmpty());
    QCOMPARE(lookup.hostAddressRecords().first().name(), domainName("aaaa-single"));
    QCOMPARE(lookup.hostAddressRecords().first().value(), QHostAddress("2001:db8::1"));
}
Beispiel #2
0
void tst_QDnsLookup::lookupAbortRetry()
{
    QDnsLookup lookup;

    // try and abort the lookup
    lookup.setType(QDnsLookup::A);
    lookup.setName(domainName("a-single"));
    lookup.lookup();
    lookup.abort();
    QVERIFY(waitForDone(&lookup));
    QVERIFY(lookup.isFinished());
    QCOMPARE(int(lookup.error()), int(QDnsLookup::OperationCancelledError));
    QVERIFY(lookup.hostAddressRecords().isEmpty());

    // retry a different lookup
    lookup.setType(QDnsLookup::AAAA);
    lookup.setName(domainName("aaaa-single"));
    lookup.lookup();
    QVERIFY(waitForDone(&lookup));
    QVERIFY(lookup.isFinished());

#if defined(Q_OS_ANDROID)
    if (lookup.errorString() == QStringLiteral("Not yet supported on Android"))
        QEXPECT_FAIL("", "Not yet supported on Android", Abort);
#endif

    QCOMPARE(int(lookup.error()), int(QDnsLookup::NoError));
    QVERIFY(!lookup.hostAddressRecords().isEmpty());
    QCOMPARE(lookup.hostAddressRecords().first().name(), domainName("aaaa-single"));
    QCOMPARE(lookup.hostAddressRecords().first().value(), QHostAddress("2001:db8::1"));
}
void tst_QDnsLookup::lookupReuse()
{
    QDnsLookup lookup;

    // first lookup
    lookup.setType(QDnsLookup::A);
    lookup.setName(domainName("a-single"));
    lookup.lookup();
    QVERIFY(waitForDone(&lookup));
    QVERIFY(lookup.isFinished());
    QCOMPARE(int(lookup.error()), int(QDnsLookup::NoError));
    QVERIFY(!lookup.hostAddressRecords().isEmpty());
    QCOMPARE(lookup.hostAddressRecords().first().name(), domainName("a-single"));
    QCOMPARE(lookup.hostAddressRecords().first().value(), QHostAddress("192.0.2.1"));

    // second lookup
    lookup.setType(QDnsLookup::AAAA);
    lookup.setName(domainName("aaaa-single"));
    lookup.lookup();
    QVERIFY(waitForDone(&lookup));
    QVERIFY(lookup.isFinished());
    QCOMPARE(int(lookup.error()), int(QDnsLookup::NoError));
    QVERIFY(!lookup.hostAddressRecords().isEmpty());
    QCOMPARE(lookup.hostAddressRecords().first().name(), domainName("aaaa-single"));
    QCOMPARE(lookup.hostAddressRecords().first().value(), QHostAddress("2001:db8::1"));
}
Beispiel #4
0
void tst_QDnsLookup::lookup()
{
    QFETCH(int, type);
    QFETCH(QString, domain);
    QFETCH(int, error);
    QFETCH(QString, cname);
    QFETCH(QString, host);
    QFETCH(QString, mx);
    QFETCH(QString, ns);
    QFETCH(QString, ptr);
    QFETCH(QString, srv);
    QFETCH(QString, txt);

    // transform the inputs
    domain = domainName(domain);
    cname = domainName(cname);
    ns = domainNameList(ns);
    ptr = domainNameList(ptr);

    // SRV and MX have reply entries that can change order
    // and we can't sort
    QStringList mx_alternatives = domainNameListAlternatives(mx);
    QStringList srv_alternatives = domainNameListAlternatives(srv);

    QDnsLookup lookup;
    lookup.setType(static_cast<QDnsLookup::Type>(type));
    lookup.setName(domain);
    lookup.lookup();
    QVERIFY(waitForDone(&lookup));
    QVERIFY(lookup.isFinished());

#if defined(Q_OS_ANDROID)
    if (lookup.errorString() == QStringLiteral("Not yet supported on Android"))
        QEXPECT_FAIL("", "Not yet supported on Android", Abort);
#endif

    QVERIFY2(int(lookup.error()) == error,
             msgDnsLookup(lookup.error(), error, domain, cname, host, srv, mx, ns, ptr, lookup.errorString()));
    if (error == QDnsLookup::NoError)
        QVERIFY(lookup.errorString().isEmpty());
    QCOMPARE(int(lookup.type()), type);
    QCOMPARE(lookup.name(), domain);

    // canonical names
    if (!cname.isEmpty()) {
        QVERIFY(!lookup.canonicalNameRecords().isEmpty());
        const QDnsDomainNameRecord cnameRecord = lookup.canonicalNameRecords().first();
        QCOMPARE(cnameRecord.name(), domain);
        QCOMPARE(cnameRecord.value(), cname);
    } else {
        QVERIFY(lookup.canonicalNameRecords().isEmpty());
    }

    // host addresses
    const QString hostName = cname.isEmpty() ? domain : cname;
    QStringList addresses;
    foreach (const QDnsHostAddressRecord &record, lookup.hostAddressRecords()) {
        //reply may include A & AAAA records for nameservers, ignore them and only look at records matching the query
        if (record.name() == hostName)
            addresses << record.value().toString().toLower();
    }
    addresses.sort();
    QCOMPARE(addresses.join(';'), host);

    // mail exchanges
    QStringList mailExchanges;
    foreach (const QDnsMailExchangeRecord &record, lookup.mailExchangeRecords()) {
        QCOMPARE(record.name(), domain);
        mailExchanges << QString("%1 %2").arg(QString::number(record.preference()), record.exchange());
    }
    QVERIFY2(mx_alternatives.contains(mailExchanges.join(';')),
             qPrintable("Actual: " + mailExchanges.join(';') + "\nExpected one of:\n" + mx_alternatives.join('\n')));

    // name servers
    QStringList nameServers;
    foreach (const QDnsDomainNameRecord &record, lookup.nameServerRecords()) {
        //reply may include NS records for authoritative nameservers, ignore them and only look at records matching the query
        if (record.name() == domain)
            nameServers << record.value();
    }
    nameServers.sort();
    QCOMPARE(nameServers.join(';'), ns);

    // pointers
    if (!ptr.isEmpty()) {
        QVERIFY(!lookup.pointerRecords().isEmpty());
        const QDnsDomainNameRecord ptrRecord = lookup.pointerRecords().first();
        QCOMPARE(ptrRecord.name(), domain);
        QCOMPARE(ptrRecord.value(), ptr);
    } else {
        QVERIFY(lookup.pointerRecords().isEmpty());
    }

    // services
    QStringList services;
    foreach (const QDnsServiceRecord &record, lookup.serviceRecords()) {
        QCOMPARE(record.name(), domain);
        services << QString("%1 %2 %3 %4").arg(
                QString::number(record.priority()),
                QString::number(record.weight()),
                QString::number(record.port()),
                record.target());
    }
    QVERIFY2(srv_alternatives.contains(services.join(';')),
             qPrintable("Actual: " + services.join(';') + "\nExpected one of:\n" + srv_alternatives.join('\n')));

    // text
    QStringList texts;
    foreach (const QDnsTextRecord &record, lookup.textRecords()) {
        QCOMPARE(record.name(), domain);
        QString text;
        foreach (const QByteArray &ba, record.values()) {
            if (!text.isEmpty())
                text += '\0';
            text += QString::fromLatin1(ba);
        }
        texts << text;
    }
    texts.sort();
    QCOMPARE(texts.join(';'), txt);
}
Beispiel #5
0
void WhittedRenderer::render(Scene* scene)
{
    if (m_viewer)
        connect(m_viewer, &HdrViewer::clicked, this, &WhittedRenderer::onPicked);

    // TODO: this stuff should go to the base class
    qDebug() << Q_FUNC_INFO;

    qDebug() << "Rendering with" << m_hwThreadCount << "threads";

    m_activeCamera = scene->activeCamera();
    m_shapes.clear();
    m_shapes = scene->gatherShapes();
    m_lights.clear();
    m_lights = scene->gatherLights();


    qDebug() << "Rendering" << m_shapes.count() << "shapes with" << m_lights.count() << "lights";

    if (m_activeCamera->fov() <=0) {
        qCritical() << "Active camera has invalid fov";
        return;
    }

    if (m_buffer)
        delete m_buffer;

    m_buffer = new float[m_renderedWidth * m_renderedHeight * 3];

    emit renderingStarted();
    do {
        qDebug() << "Starting new frame" << scene->time();

        QElapsedTimer elapsed;
        elapsed.start();

        QElapsedTimer gridTime;
        gridTime.start();
        if (m_grid)
            delete m_grid;
        m_grid = new RegularGrid();
        m_grid->initialize(m_shapes);
        qDebug() << "Generated acceleration structure in" << gridTime.elapsed() << "ms";

        auto pool = QThreadPool::globalInstance();
        for (int i=0; i < m_hwThreadCount; i++) {
            WhittedRunnable* runnable = new WhittedRunnable(this, i, m_hwThreadCount);
            runnable->setAutoDelete(true);
            pool->start(runnable);
        }
        // TODO: write a thread pool that sends a signal when job is complete
        while (!pool->waitForDone(25)) {
            qApp->processEvents();
        }

        qDebug() << "Frame complete in:" << elapsed.elapsed() << "ms";
        emit frameComplete();
        qApp->processEvents();
    } while(scene->advanceFrame());

    emit renderingComplete();

}
Beispiel #6
0
int main(int argc, char **argv)
{
    std::string hostname;
    Aria::init();
    //ArLog::init(ArLog::StdOut, ArLog::Verbose);
    ArClientBase client;


    ArArgumentParser parser(&argc, argv);

    ArClientSimpleConnector clientConnector(&parser);

    parser.loadDefaultArguments();

    ArClientFileFromClient::SendSpeed speed = ArClientFileFromClient::SPEED_AUTO;


    if (parser.checkArgument("-speed_fast"))
    {
        ArLog::log(ArLog::Normal, "Putting file with speed_fast");
        speed = ArClientFileFromClient::SPEED_FAST;
    }
    else if (parser.checkArgument("-speed_slow"))
    {
        ArLog::log(ArLog::Normal, "Putting file with speed_slow");
        speed = ArClientFileFromClient::SPEED_SLOW;
    }
    else
    {
        ArLog::log(ArLog::Normal, "Putting file with speed_auto");
    }

    bool pauseAfterSend;

    if (parser.checkArgument("-pauseAfterSend"))
    {
        ArLog::log(ArLog::Normal, "Will pause after send");
        pauseAfterSend = true;
    }
    else
    {
        ArLog::log(ArLog::Normal, "Will not pause after send");
        pauseAfterSend = false;
    }

    /* Check for -help, and unhandled arguments: */
    if (!Aria::parseArgs() || !parser.checkHelpAndWarnUnparsed(1) ||
            parser.getArgc() <= 1)
    {
        ArLog::log(ArLog::Normal, "%s <fileName> [-speed_fast] [-speed_slow] [-pauseAfterSend]",
                   argv[0]);
        ArLog::log(ArLog::Normal, "Default send speed is speed_auto");
        ArLog::log(ArLog::Normal, "");
        Aria::logOptions();
        exit(0);
    }

    const char *fileName = parser.getArg(1);



    /* Connect our client object to the remote server: */
    if (!clientConnector.connectClient(&client))
    {
        if (client.wasRejected())
            printf("Server '%s' rejected connection, exiting\n", client.getHost());
        else
            printf("Could not connect to server '%s', exiting\n", client.getHost());
        exit(1);
    }

    fileFromClient = new ArClientFileFromClient(&client);
    fileFromClient->addFileSentCallback(
        new ArGlobalFunctor1<int>(&fileSent));

    client.runAsync();

    done = false;
    if (!fileFromClient->putFileToDirectory(NULL, fileName, fileName,
                                            speed))
    {
        printf("Error before sending file\n");
        Aria::exit(1);
    }

    waitForDone();

    if (pauseAfterSend)
        ArUtil::sleep(10000);

    Aria::exit(0);
    return 255;
}
int main(int argc, char **argv)
{
    std::string hostname;
    Aria::init();
    //ArLog::init(ArLog::StdOut, ArLog::Verbose);
    ArClientBase client;


    ArArgumentParser parser(&argc, argv);

    ArClientSimpleConnector clientConnector(&parser);

    parser.loadDefaultArguments();

    /* Check for -help, and unhandled arguments: */
    if (!Aria::parseArgs() || !parser.checkHelpAndWarnUnparsed())
    {
        Aria::logOptions();
        exit(0);
    }

    /* Connect our client object to the remote server: */
    if (!clientConnector.connectClient(&client))
    {
        if (client.wasRejected())
            printf("Server '%s' rejected connection, exiting\n", client.getHost());
        else
            printf("Could not connect to server '%s', exiting\n", client.getHost());
        exit(1);
    }

    fileLister = new ArClientFileLister(&client);
    fileLister->addUpdatedCallback(new ArGlobalFunctor1<int>(&updated));

    fileToClient = new ArClientFileToClient(&client);
    fileToClient->addFileReceivedCallback(
        new ArGlobalFunctor1<int>(&fileReceived));

    fileFromClient = new ArClientFileFromClient(&client);
    fileFromClient->addFileSentCallback(
        new ArGlobalFunctor1<int>(&fileSent));

    deleteFileOnServer = new ArClientDeleteFileOnServer(&client);
    deleteFileOnServer->addFileDeletedCallback(
        new ArGlobalFunctor1<int>(&fileDeleted));

    client.runAsync();

    /*
    if (deleteFileOnServer->deleteFileFromDirectory(NULL, "all.bob"))
      waitForDone();
    else
      printf("Error deleting file\n");

    if (deleteFileOnServer->deleteFileFromDirectory("1", "all.bob"))
      waitForDone();
    else
      printf("Error deleting file\n");

    if (deleteFileOnServer->deleteFileFromDirectory("1/3", "all.bob"))
      waitForDone();
    else
      printf("Error deleting file\n");


    if (deleteFileOnServer->deleteFileFromDirectory("fun", "all.bob"))
      waitForDone();
    else
      printf("Error deleting file\n");

    if (deleteFileOnServer->deleteFileFromDirectory("argh", "all.bob"))
      waitForDone();
    else
      printf("Error deleting file\n");
    */

    /*
    done = false;
    if (fileFromClient->putFileToDirectory("argh", "png", "app_logo.png", ArClientFileFromClient::SPEED_SLOW))
      waitForDone();
    else
      printf("Error before sending file\n");
    */
    done = false;
    if (fileFromClient->putFileToDirectory(NULL, "dox", "doxygen.conf", ArClientFileFromClient::SPEED_SLOW))
        waitForDone();
    else
        printf("Error before sending file\n");


    /*
      done = false;
      if (fileFromClient->putFileToDirectory("argh", "png", "app_logo.png")
        waitForDone();
      else
        printf("Error before sending file\n");

      done = false;
      if (fileFromClient->putFileToDirectory(NULL, "dox", "doxygen.conf")
        waitForDone();
      else
        printf("Error before sending file\n");
    */
    /*
      fileLister->changeToTopDir();
      waitForDone();
      fileLister->changeToDir("argh");
      waitForDone();
      fileLister->log(true);

      fileToClient->getFileFromDirectory("argh\\um", "doxygen", "slashes");
      waitForDone();
      fileToClient->getFileFromDirectory("argh", "DOXYGEN.Conf", "blah.um.2");
      waitForDone();
      fileToClient->getFileFromDirectory("argh", "wehlkjadsf", "blah.um.2");
      waitForDone();
      fileToClient->getFileFromDirectory("argh", "1", "blah.um");
      waitForDone();
      fileToClient->getFileFromDirectory(NULL, "1", "blah.um.2");
      waitForDone();
      */
    /*
    fileToClient->getFileFromDirectory(NULL, "all.map", "all.map.2");
    waitForDone();

    fileToClient->getFileFromDirectory(NULL, "um.map", "all.map.2");
    waitForDone();

    fileToClient->getFileFromDirectory(NULL, "all.map", "all.map.3");
    waitForDone();

    fileToClient->getFileFromDirectory(NULL, "configClient.txt", "something");
    waitForDone();

    */

    /*
    fileLister->changeToTopDir();
    waitForDone();
    fileLister->changeToDir("0level");
    waitForDone();
    fileLister->changeToDir("1level");
    waitForDone();
    fileLister->upOneDir();
    waitForDone();
    fileLister->changeToDir("1level2");
    waitForDone();
    */



    Aria::shutdown();
    return 0;

}
Beispiel #8
0
void QDnsLookupThreadPool::_q_applicationDestroyed()
{
    waitForDone();
    signalsConnected = false;
}
void tst_QDnsLookup::lookup()
{
    QFETCH(int, type);
    QFETCH(QString, domain);
    QFETCH(int, error);
    QFETCH(QString, cname);
    QFETCH(QString, host);
    QFETCH(QString, mx);
    QFETCH(QString, ns);
    QFETCH(QString, ptr);
    QFETCH(QString, srv);
    QFETCH(QByteArray, txt);

    // transform the inputs
    domain = domainName(domain);
    cname = domainName(cname);
    mx = domainNameList(mx);
    ns = domainNameList(ns);
    ptr = domainNameList(ptr);
    srv = domainNameList(srv);

    QDnsLookup lookup;
    lookup.setType(static_cast<QDnsLookup::Type>(type));
    lookup.setName(domain);
    lookup.lookup();
    QVERIFY(waitForDone(&lookup));
    QVERIFY(lookup.isFinished());
    QVERIFY2(int(lookup.error()) == error, qPrintable(lookup.errorString()));
    if (error == QDnsLookup::NoError)
        QVERIFY(lookup.errorString().isEmpty());
    QCOMPARE(int(lookup.type()), type);
    QCOMPARE(lookup.name(), domain);

    // canonical names
    if (!cname.isEmpty()) {
        QVERIFY(!lookup.canonicalNameRecords().isEmpty());
        const QDnsDomainNameRecord cnameRecord = lookup.canonicalNameRecords().first();
        QCOMPARE(cnameRecord.name(), domain);
        QCOMPARE(cnameRecord.value(), cname);
    } else {
        QVERIFY(lookup.canonicalNameRecords().isEmpty());
    }

    // host addresses
    const QString hostName = cname.isEmpty() ? domain : cname;
    QStringList addresses;
    foreach (const QDnsHostAddressRecord &record, lookup.hostAddressRecords()) {
        //reply may include A & AAAA records for nameservers, ignore them and only look at records matching the query
        if (record.name() == hostName)
            addresses << record.value().toString().toLower();
    }
    addresses.sort();
    QCOMPARE(addresses.join(';'), host);

    // mail exchanges
    QStringList mailExchanges;
    foreach (const QDnsMailExchangeRecord &record, lookup.mailExchangeRecords()) {
        QCOMPARE(record.name(), domain);
        mailExchanges << QString("%1 %2").arg(QString::number(record.preference()), record.exchange());
    }
    QCOMPARE(mailExchanges.join(';'), mx);

    // name servers
    QStringList nameServers;
    foreach (const QDnsDomainNameRecord &record, lookup.nameServerRecords()) {
        //reply may include NS records for authoritative nameservers, ignore them and only look at records matching the query
        if (record.name() == domain)
            nameServers << record.value();
    }
    nameServers.sort();
    QCOMPARE(nameServers.join(';'), ns);

    // pointers
    if (!ptr.isEmpty()) {
        QVERIFY(!lookup.pointerRecords().isEmpty());
        const QDnsDomainNameRecord ptrRecord = lookup.pointerRecords().first();
        QCOMPARE(ptrRecord.name(), domain);
        QCOMPARE(ptrRecord.value(), ptr);
    } else {
        QVERIFY(lookup.pointerRecords().isEmpty());
    }

    // services
    QStringList services;
    foreach (const QDnsServiceRecord &record, lookup.serviceRecords()) {
        QCOMPARE(record.name(), domain);
        services << QString("%1 %2 %3 %4").arg(
                QString::number(record.priority()),
                QString::number(record.weight()),
                QString::number(record.port()),
                record.target());
    }
    QCOMPARE(services.join(';'), srv);

    // text
    if (!txt.isEmpty()) {
        QVERIFY(!lookup.textRecords().isEmpty());
        const QDnsTextRecord firstRecord = lookup.textRecords().first();
        QCOMPARE(firstRecord.name(), domain);
        QCOMPARE(firstRecord.values().size(), 1);
        QCOMPARE(firstRecord.values().first(), txt);
    } else {
        QVERIFY(lookup.textRecords().isEmpty());
    }
}