Пример #1
0
static int MS_incr_outstanding(lua_State *L)
{
    if (lua_gettop(L) != 1 || !lua_isuserdata(L, 1)) {
        return luaL_error(L, "usage: <session>");
    }

    MolochSession_t *session = checkMolochSession(L, 1);
    moloch_session_incr_outstanding(session);

    return 0;
}
Пример #2
0
void moloch_session_add_tag_type(MolochSession_t *session, int tagtype, const char *tag) {
    moloch_session_incr_outstanding(session);
    moloch_db_get_tag(session, tagtype, tag, moloch_session_get_tag_cb);

    if (session->stopSaving == 0 && HASH_COUNT(s_, config.dontSaveTags)) {
        MolochString_t *tstring;

        HASH_FIND(s_, config.dontSaveTags, tag, tstring);
        if (tstring) {
            session->stopSaving = (long)tstring->uw;
        }
    }
}
Пример #3
0
void moloch_session_add_tag(MolochSession_t *session, const char *tag) {
    moloch_session_incr_outstanding(session);
    moloch_db_get_tag(session, config.tagsField, tag, moloch_session_get_tag_cb);
    moloch_field_string_add(config.tagsStringField, session, tag, -1, TRUE);

    if (session->stopSaving == 0 && HASH_COUNT(s_, config.dontSaveTags)) {
        MolochString_t *tstring;

        HASH_FIND(s_, config.dontSaveTags, tag, tstring);
        if (tstring) {
            session->stopSaving = (int)(long)tstring->uw;
        }
    }
}
Пример #4
0
void wise_lookup(MolochSession_t *session, WiseRequest_t *request, char *value, int type)
{

    if (*value == 0)
        return;

    if (request->numItems >= 256)
        return;

    MOLOCH_LOCK(item);

    static int lookups = 0;
    WiseItem_t *wi;

    lookups++;
    if ((lookups % 10000) == 0)
        wise_print_stats();

    stats[type][INTEL_STAT_LOOKUP]++;

    HASH_FIND(wih_, itemHash[type], value, wi);

    if (wi) {
        // Already being looked up
        if (wi->sessions) {
            if (wi->numSessions < wi->sessionsSize) {
                wi->sessions[wi->numSessions++] = session;
                moloch_session_incr_outstanding(session);
            }
            stats[type][INTEL_STAT_INPROGRESS]++;
            goto cleanup;
        }

        struct timeval currentTime;
        gettimeofday(&currentTime, NULL);

        if (wi->loadTime + cacheSecs > currentTime.tv_sec) {
            wise_process_ops(session, wi);
            stats[type][INTEL_STAT_CACHE]++;
            goto cleanup;
        }

        /* Had it in cache, but it is too old */
        DLL_REMOVE(wil_, &itemList[type], wi);
        wise_free_ops(wi);
    } else {
        // Know nothing about it
        wi = MOLOCH_TYPE_ALLOC0(WiseItem_t);
        wi->key          = g_strdup(value);
        wi->type         = type;
        wi->sessionsSize = 20;
        HASH_ADD(wih_, itemHash[type], wi->key, wi);
    }

    wi->sessions = malloc(sizeof(MolochSession_t *) * wi->sessionsSize);
    wi->sessions[wi->numSessions++] = session;
    moloch_session_incr_outstanding(session);

    stats[type][INTEL_STAT_REQUEST]++;

    BSB_EXPORT_u08(request->bsb, type);
    int len = strlen(value);
    BSB_EXPORT_u16(request->bsb, len);
    BSB_EXPORT_ptr(request->bsb, value, len);

    request->items[request->numItems++] = wi;

cleanup:
    MOLOCH_UNLOCK(item);
}