Пример #1
0
BSONObj _look_up_seedbank(scoped_ptr<ScopedDbConnection> const& scoped_conn, int seedbank_id)
{
    BSONObj sb_record;
    DBClientBase* conn = scoped_conn->get();
    if (conn->isFailed()) {
        log_util::error() << "torrentdb::_look_up_seedbank: mongodb connection failed" << endl;
    } else {
#ifdef _DEBUG
        log_util::debug() << "torrentdb::_look_up_seedbank: running mongodb query (" << seedbank_id << ")" << endl;
#endif
        std::auto_ptr<DBClientCursor> cursor = conn->query(_param_map["seedbankdb_ns"], QUERY("seedbank_id" << seedbank_id));
        bool found_results = false;

        //if (conn->getLastError().empty()) {
            while (cursor->more()) {
                // TODO: verify no more than one record returned?
                sb_record = cursor->next();
                found_results = true;
            }
        //}
        if (!found_results) {
            log_util::error() << "torrentdb::_look_up_seedbank: mongodb result not found" << endl;
        }
    }

    return sb_record;
}
Пример #2
0
BSONObj _look_up_info_hash(scoped_ptr<ScopedDbConnection> const& scoped_conn, sha1_hash const& info_hash)
{
    BSONObj torrent_record;
    char ih_hex[41];
    to_hex((char const*)&info_hash[0], sha1_hash::size, ih_hex);

    DBClientBase* conn = scoped_conn->get();
    if (conn->isFailed()) {
        log_util::error() << "torrentdb::_look_up_info_hash: mongodb connection failed" << endl;
    } else {
#ifdef _DEBUG
        log_util::debug() << "torrentdb::_look_up_info_hash: running mongodb query (" << ih_hex << ")" << endl;
#endif
        std::auto_ptr<DBClientCursor> cursor = conn->query(_param_map["torrentdb_ns"], QUERY("info_hash" << ih_hex));
        bool found_results = false;

        //if (conn->getLastError().empty()) {
            while (cursor->more()) {
                // TODO: verify no more than one record returned?
                torrent_record = cursor->next();
                found_results = true;
            }
        //}
#ifdef _DEBUG
        if (!found_results) {
            log_util::debug() << "torrentdb::_look_up_info_hash: torrent not found" << endl;
        }
#endif
    }
    return torrent_record;
}
Пример #3
0
void _execute_update_stats(scoped_ptr<ScopedDbConnection> const& scoped_conn, stats_update_t const& params) {
    char ih_hex[41];
    to_hex((char const*)&params.info_hash[0], sha1_hash::size, ih_hex);

    DBClientBase* conn = scoped_conn->get();
    if (conn->isFailed()) {
        log_util::error() << "mongodb connection failed trying to update stats (torrent: " << ih_hex << ", inc_completed: " << params.increment_completed << ")" << endl;
    } else {
#ifdef _DEBUG
        log_util::debug() << "torrentdb::_execute_update_stats: Running mongodb update query (" << ih_hex << ")" << endl;
#endif

        mongo::Date_t now = terasaur::date::get_now_mongo();
        mongo::Query query = QUERY("info_hash" << ih_hex);
        BSONObj update_bson;

        if (params.increment_completed) {
#ifdef _DEBUG
        log_util::debug() << "torrentdb::_execute_update_stats: increment completed true" << endl;
#endif
            update_bson = BSON("$set" << BSON("seeds" << params.seeds << "peers" << params.peers << "updated" << now)
                               << "$inc" << BSON( "completed" << 1));
        } else {
#ifdef _DEBUG
        log_util::debug() << "torrentdb::_execute_update_stats: increment completed false" << endl;
#endif
            update_bson = BSON("$set" << BSON("seeds" << params.seeds << "peers" << params.peers << "updated" << now));
        }

#ifdef _DEBUG
        log_util::debug() << "torrentdb::_execute_update_stats: query: " << query << endl;
        log_util::debug() << "torrentdb::_execute_update_stats: update bson: " << update_bson << endl;
        log_util::debug() << "torrentdb::_execute_update_stats: calling mongodb update()" << endl;
#endif
        conn->update(_param_map["torrentdb_ns"], query, update_bson);

#ifdef _DEBUG
        log_util::debug() << "torrentdb::_execute_update_stats: calling mongodb getLastError()" << endl;
#endif
        string err = conn->getLastError();
        bool success = err.empty();
        if (success == false) {
            log_util::error() << "torrentdb::_execute_update_stats: mongodb update returned error (" << err << ")" << endl;
        }
#ifdef _DEBUG
        else {
            log_util::debug() << "torrentdb::_execute_update_stats: mongodb update successful" << endl;
        }
#endif
    }

#ifdef _DEBUG
    log_util::debug() << "torrentdb::_execute_update_stats: returning" << endl;
#endif
}