Commits

Anonymous committed a6c4884

Code polishing after sync

Comments (0)

Files changed (8)

modules/channel/DionaeaHarvester-ng/DionaeaHarvester-ng.cc

         //LOG(DEBUG)  << "txn: " << d << " vs. " << txn->src_port;
         if(d!=0 && d != txn->src_port)
             continue;
+
+        LOG(DEBUG)  <<  "Erasing txn "
+                    << txn->src_host << ":" << txn->src_port
+                    << " -> "
+                    << txn->dst_host << ":" << txn->dst_port
+                    << " because of itemset: "
+                    << freq_itemsets[i][0].as<const char*>() << " "
+                    << freq_itemsets[i][1].as<const char*>() << ":"
+                    << freq_itemsets[i][2].as<u_int16_t>()
+                    << freq_itemsets[i][3].as<const char*>() << ":"
+                    << freq_itemsets[i][4].as<u_int16_t>() << std::endl ;
         
         return true;
     }
             txn->src_port = result[i][6].as<u_int16_t>();
 
             if(txn_subsets_itemsets(freq_itemsets,txn)) {
-                LOG(DEBUG)  << "Deleting txn " << ++x << " out of  " << result.size() << " " << txn->src_host << ": "
-                            << txn->src_port << " -> " 
-                            << txn->dst_host << ":" << txn->dst_port;
+                //LOG(DEBUG)  << "Deleting txn " << ++x << " out of  " << result.size() << " " << txn->src_host << ": "
+                //            << txn->src_port << " -> " 
+                //            << txn->dst_host << ":" << txn->dst_port;
                 delete txn;
                 continue;
             } else

modules/data/hashtree.cc

 bool hashnode::add(itemset* item,int idx) {
     if(type==interior) {
         index_t branch_idx = branch(item->val(idx));
-//        {LOG(CRITIC) << "hashnode::add interior, branch_idx=" << branch_idx;}
+        LOG(CRITIC) << "hashnode::add interior, branch_idx=" << branch_idx;
         return children[branch_idx]->add(item,++idx);
     }
     if(type==leaf) {
         if(item->getsize() == depth) { // there are no items to hash
-//            {LOG(MESSAGE) << "hashnode:add size==depth==" << depth;}
-//            item->debug();
             items.push_back(item);
             return true;
         }
-        else if(items.size() < modulo) { // can
-//            {LOG(MESSAGE) << "hashnode:add items.size<modulo " << items.size();}
-//            item->debug();
-
+        else if(items.size() < modulo) {
             items.push_back(item);
             return true;
         }
         else { // we need to split items into children
-//            {LOG(MESSAGE) << "hashnode:add size==modulo==" << depth;}
-//            item->debug();
-
             type = interior;
             int branch_idx;
             items.push_back(item);
         int branch_idx;
         for(int i=idx;i<size-border;++i) {
             branch_idx = hash(txn[i]);
-//            {LOG(WARN) << "bidx: " << branch_idx 
-//                       << " i: " << i
-//                       << " depth: " << depth 
-//                       << " hashing: " << txn[i] ; };
             if(!children[branch_idx])
                 continue;
             tmp_set = children[branch_idx]->find(txn,size,i+1,border);
             tmp_set.clear();
         }
         return r_set;
-        //int branch_idx = hash(txn[depth-1]);
-        //if(!children[branch_idx] || depth==size)
-        //    return r_set;
-        //return children[branch_idx]->find(txn,size);
     }
     if(type==leaf) {
         for(int i=0;i<items.size();++i) {
            if(items[i]->intersection(txn,size)) r_set.insert(items[i]);
         }
-        // debug:
-//        {LOG(MESSAGE)  << "hashnode: For transaction: "
-//                       << txn[0] << ","
-//                       << txn[1] << ","
-//                       << txn[2] << ","
-//                       << txn[3] << ","
-//                       << txn[4] << " found sets:"; };
-        
-//        static string_t dbuf;
-//        static char buf[128];
-//        
-//        dbuf.clear();
-//        for(int i=0;i<size;++i) {
-//            memset(buf,0,128);
-//            sprintf(buf,"%lu ",txn[i]);
-//            dbuf.append(buf);
-//        }
-//
-//        {LOG(MESSAGE)  << "hashnode: For transaction: "
-//                       << dbuf;};
-//      
-//        
-//        set_it sit = r_set.begin();
-//        for(;sit!=r_set.end();++sit) {
-//            (*sit)->debug();
-//        };
-
         return r_set;
     }
 }

modules/data/indextransactions.cc

  */
 
 #include "indextransactions.h"
-/*
-IndexTransactions::IndexTransactions() : DataPack() {};
-IndexTransactions::~IndexTransactions() {
-    std::list<indexedTransaction*>::iterator it;
-    it = rows.begin();
-    for(;it!=rows.end();++it) {
-        cleanTransaction(*it);
-    };
-    rows.clear();
-
-};
-
-void IndexTransactions::cleanTransaction(indexedTransaction* txn) {
-    txn->size = 0;
-    delete []txn->values;
-    txn->values = NULL;
-};
-
-IndexTransactions::indexedTransaction* IndexTransactions::createindexedTransaction(int size) {
-    indexedTransaction* txn = new indexedTransaction;
-    txn->size = size;
-    txn->values = new index_t[size];
-    return txn;
-}
-
-*/
 
 IndexTransactions::IndexTransactions() : DataPack(), itemsets() {};
 IndexTransactions::~IndexTransactions() {};

modules/data/itemsets.cc

     int r_size = size + 1;
     itemset* r_itemset = new itemset(r_size);
 
-    a->clone(r_itemset,1); // copy a, but size - 1 elements
+    a->clone(r_itemset,1); // copy a, but size-1 elements
     
     if(a->val(size-1) >= b->val(size-1)) {
         r_itemset->val(size-1) = b->val(size-1);
 itemset* itemsets::find(const itemset* item) const {
     int idx = find_idx(item);
     if(idx==-1)
-        return NULL; // do sth with this!
+        return NULL;
     return values[idx];
 }
-#ifdef INSERT_V1
 
-// apparently this version of insert() is screwed
-itemset* itemsets::insert(itemset* item) {
-    if(values.empty()) {
-        values.push_back(item);
-        return item;
-    }
-   
-    int low, high, mid, cmp;
-    low = 0;
-    high= getsize() - 1;
-    while(low <= high) {
-        mid = (low + high)/2;
-        cmp = itemset::cmp(item,values[mid]);
-        if(cmp < 0) {// item < mid
-            high = mid - 1;
-        }
-        else if(cmp > 0) {// item > mid
-            low = mid + 1;
-        } 
-        else if(!cmp) return values[mid]; // cmp was 0 so equal
-    }
-
-    deque<itemset*>::iterator b = values.begin();
-    deque<itemset*>::iterator e = values.end();
-
-//    cmp = itemset::cmp(item,values[mid]);
-    // debug purpose
-//    {LOG(INFO) << "low:" << low << " high:" << high ;};
-    if (!cmp)
-        return values[mid];
-    else if(!low && cmp < 0) // insert as first elem - good!
-        values.push_front(item);
-    else if(!low)
-        values.insert(b+1,item);
-    else if(high == getsize() && cmp >0) // insert last elem - good!
-        values.push_back(item);
-    else if(high == getsize())
-        values.insert(e-1,item);
-    else
-        values.insert(b+high,item);
-//    LOG (INFO) << "itemsets:: size: " << values.size();
-    return item;
-
-}
-#else
 // TODO(marek):
 // plain old linear insert - to be optimized
 itemset* itemsets::insert(itemset* item) {
     values.push_back(item); // we got the end;
     return item;
 };
-#endif
 
 void itemsets::append(itemset* item) {
     values.push_back(item);
     deque<itemset*>::iterator it = values.begin();
     while(it!=values.end()) {
         if((*it)->getcount() < minsup) {
-//            {LOG(WARN) << "prunecandidates:"; }
-//            (*it)->debug();
             delete *it;
             it = values.erase(it);
         } else ++it;
         tmp_set = tree->find(&(compare->val(0)),compare->getsize(),i,0);
         r_set.insert(tmp_set.begin(),tmp_set.end());
     }
-    //set_t old_set = correlate_trad(txn,NULL);
-
-    //check_sets(r_set,old_set);
-
     int idx;
     set_it sit = r_set.begin();
     for(;sit!=r_set.end();++sit) {
     }
 };
 
-/*
-set_t itemsets::correlate_trad(const itemset_ptr compare,itemsets_ptr ct) {
-    set_t sset;
-    for(int i=0;i<getsize();++i) {
-        if(values[i]->intersection(&(compare->val(0)),compare->getsize())) 
-            sset.insert(values[i]);
-    };
-    return sset;
-}
-*/
+
 const itemset* itemsets::utilize(const itemset* mstr, const itemset* slv) {
     if(mstr == slv)
         return mstr;
 }
 
 /*
- * Returns -1 if  not found
- * Simple binary search algorithm implementation
+ * Returns -1 if  not found,otherwise index of the element
+ * Binary search algorithm implementation
  */
 int itemsets::find_idx(const itemset* item) const {
     if(values.empty())
 void itemsets::delitem(itemset* i) {
     delete i;
 };
-
-//void itemsets::check_sets(set_t& a, set_t& b) {
-//    assert(a.size()==b.size());
-//
-//    set_t::iterator ait,bit;
-//    ait = a.begin();
-//    bit = b.begin();
-//    for(;ait!=a.end();++ait,++bit) {
-//        assert(!itemset::cmp((*ait),(*bit)));
-//    };
-////    LOG(MESSAGE) << "itemsets::check_sets() done, all equal";
-//};
-

modules/logger/dionaealogger/dionaealogger.cc

    snprintf(buf,1024,insert_op,oid,from.c_str(),to.c_str(),interval);
    dbresult_t r; // we need faked object for exec_query() - how about making it static ?
    return exec_query(*w,r,buf,false);
-// w->exec(buf);
 }
 
 bool DionaeaLogger::insert_into_freq_itemsets(dbwork_t* w,index_t& oid,DionaeaConnections::unindexedTransaction* txn) {
 
    dbresult_t r;// we need faked object for exec_query() - how about making it static ?
    return exec_query(*w,r,buf,false);
-// w->exec(buf);
 }
 
 

modules/processor/IpProcessor/ipproc.cc

     IpTrie* tree;
     IpNode** node = new IpNode*;
     index_t idx;
-    //LOG(CRITIC) << "Indexing ip: " << ip;
     switch(ip_family(ip)) {
         case AF_INET:
             tree = ipv4;
 
             idx_ptr->handle_mem(true);
         }
-        //LOG(CRITIC) << "get_index_from tree(): we got ip: " << ip;
         idx_ptr->ip = ip;
 
         idx_ptr->ver = len==4?AF_INET:AF_INET6; // idx->ver

modules/processor/IpProcessor/iptrie.cc

 
 IpNode* IpTrie::getNode(const u_int8_t* label, u_int8_t len) {
     if(!root) {
-        LOG(WARN) << "IpNode getNode():"
-                  << " root was not initialized";
+        LOG(WARN) << "IpNode getNode(): "
+                  << "root was not initialized";
         return NULL;
     }
     return root->get(label,len);
                      bool overwrite) 
 { 
     if(!root) {
-        LOG(WARN) << "IpNode setNode():root was not initialized";
+        LOG(WARN) << "IpNode setNode(): "
+                  << "root was not initialized";
         return false;
     }
     return root->set(label,len,idx_node,overwrite);
 
 
 void Workflow::setup_scheduler(const setting_t& flow_config) {
-    if(type==SCHEDULED) {
-        string_t schedule = "1H";
-        ev_tstamp seconds = 3600.;
-        if(flow_config.exists("schedule"))
-            flow_config.lookupValue("schedule",schedule);
-        seconds =(ev_tstamp) Python::convert_to_seconds(schedule); 
-        periodic_watcher.set<Workflow,&Workflow::schedule_cb>(this);
-        periodic_watcher.set(0.,seconds);
-        periodic_watcher.set(*g_quechua->loop);
-        LOG(INFO) << "Workflow " << name << " scheduled for "
-                  << (double)seconds << " seconds interval";
-    } 
+    if(type!=SCHEDULED)
+        return;
+
+    string_t schedule = "1H";
+    ev_tstamp seconds = 3600.;
+    if(flow_config.exists("schedule"))
+        flow_config.lookupValue("schedule",schedule);
+    seconds =(ev_tstamp) Python::convert_to_seconds(schedule); 
+    periodic_watcher.set<Workflow,&Workflow::schedule_cb>(this);
+    periodic_watcher.set(0.,seconds);
+    periodic_watcher.set(*g_quechua->loop);
+    LOG(INFO) << "Workflow " << name << " scheduled for "
+              << (double)seconds << " seconds interval";
 };
 
 void Workflow::setup_type(const setting_t& flow_config) {