unsigned int tcp_cache_optim(pDeduplicator pd, __u8 *ippacket) { struct iphdr *iph = NULL; struct tcphdr *tcph = NULL; __u16 datasize = 0; /* Store the size of the TCP data. */ __u8 *tcpdata = NULL; /* Starting location for the TCP data. */ char message[LOGSZ]; if (DEBUG_DEDUPLICATION == true) { sprintf(message, "[CACHE OPTIM]: Entering into TCP CACHING \n"); logger(LOG_INFO, message); } if ((ippacket != NULL)) { // If the skb or state_decompress is NULL abort compression. iph = (struct iphdr *) ippacket; // Access ip header. if ((iph->protocol == IPPROTO_TCP)) { // If this is not a TCP segment abort compression. tcph = (struct tcphdr *) (((u_int32_t *) ippacket) + iph->ihl); // Access tcp header. datasize = (__u16)(ntohs(iph->tot_len) - iph->ihl * 4) - tcph->doff* 4; tcpdata = (__u8 *) tcph + tcph->doff * 4; // Find starting location of the TCP data. if (datasize > 0) { if (DEBUG_DEDUPLICATION == true) { sprintf(message, "[CACHE OPTIM]: IP Packet ID %u\n", ntohs(iph->id)); logger(LOG_INFO, message); } #ifdef BASIC cache(tcpdata, datasize); #endif #ifdef ROLLING put_in_cache(pd, tcpdata, datasize); #endif if (DEBUG_DEDUPLICATION == true) { sprintf( message, "[CACHE OPTIM] Cached packet \n"); logger(LOG_INFO, message); } return OK; } } } return ERROR; }
FileHolder Database_ResourceStorage::get_file_path(const std::string& key) { int ind = find_in_cache(key); if(ind >= 0) return FileCache[ind].file; guint32 entry_offset, entry_size; if(!ridx_file->lookup(key.c_str(), entry_offset, entry_size)) return FileHolder(); // key not found gchar *data = dict->GetData(entry_offset, entry_size); if(!data) return FileHolder(); std::string name_pattern; // in file name encoding if(!utf8_to_file_name(key, name_pattern)) return FileHolder(); std::string::size_type pos = name_pattern.find_last_of("."DB_DIR_SEPARATOR_S); if(pos != std::string::npos) { if(name_pattern[pos] == '.') name_pattern = name_pattern.substr(pos); else name_pattern.clear(); } else name_pattern.clear(); gint fd; FileHolder file(open_temp_file(name_pattern, fd)); if(file.empty()) return file; ssize_t write_size; #ifdef _WIN32 write_size = _write(fd, data+sizeof(guint32), entry_size); if (write_size == -1) { g_print("write error!\n"); } _close(fd); #else write_size = write(fd, data+sizeof(guint32), entry_size); if (write_size == -1) { g_print("write error!\n"); } close(fd); #endif ind = put_in_cache(key, file); return FileCache[ind].file; }
int sel_nb(void) { char trans, **s; int next, i; double pegel = 0.0, schwelle = 0.0, zufall = 0.0; int found_stop=0; /* before we select a move, store current conformation in cache */ /* ... unless it just came from there */ if ( !is_from_cache ) put_in_cache(); else /* laplace stuff */ for (i=0; i<top; i++) { L += (GSV.currE - energies[i]); D++; } is_from_cache = 0; /* draw 2 different a random number */ schwelle = urn(); while ( zufall==0 ) zufall = urn(); /* advance internal clock */ if (totalflux>0) zeitInc = (log(1. / zufall) / totalflux); else { if (GSV.grow>0) zeitInc=GSV.grow; else zeitInc = GSV.time; } Zeit += zeitInc; /* laplace stuff */ sumK += L*zeitInc; sumKK += L*L*zeitInc; sumD += D*zeitInc; if (GSV.grow>0 && GSV.len < strlen(GAV.farbe_full)) grow_chain(); /* meanE /= (double)top; */ /* normalize boltzmann weights */ schwelle *=totalflux; /* and choose a neighbour structure next */ for (next = 0; next < top; next++) { pegel += bmf[next]; if (pegel > schwelle) break; } /* in case of rounding errors */ if (next==top) next=top-1; /* process termination contitiones */ /* is current structure identical to a stop structure ?*/ for (found_stop = 0, s = GAV.stopform; *s; s++) { if (strcmp(*s, GAV.currform) == 0) { found_stop = (s - GAV.stopform) + 1; break; } } if ( ((found_stop > 0) && (GTV.fpt == 1)) || (Zeit > GSV.time) ) { /* met condition to stop simulation */ /* laplace stuff */ double K, KK, N, sigma; K = sumK/Zeit; KK = sumKK/Zeit; N = sumD/Zeit; /* graph Laplacian is - Laplace-Beltrami operator */ sigma = -1.0*sqrt((KK-K*K)/N)/(K/N); /* this gose to stdout */ if ( !GTV.silent ) { printf("%s %6.2f %10.3f", GAV.currform, GSV.currE, Zeit); /* laplace stuff*/ if (GTV.phi) printf(" %8.3f %8.3f %3g", zeitInc, L, D); if (GTV.verbose) printf(" %4d _ %d", top, lmin); if (found_stop) printf(" X%d\n", found_stop);/* found a stop structure */ else printf(" O\n"); /* time for simulation is exceeded */ /* laplace stuff */ if (GTV.phi) printf("Curvature fluctuation sigma = %7.5f\n", sigma); fflush(stdout); } /* this goes to log */ /* comment log steps of simulation as well !!! %6.2f round */ if ( found_stop ) { fprintf(logFP," X%02d %12.3f", found_stop, Zeit); /* laplace stuff */ if (GTV.phi) fprintf(logFP, " %3g %7.5f", GSV.phi, sigma); fprintf(logFP,"\n"); } else { fprintf(logFP," O %12.3f", Zeit); /* laplace stuff */ if (GTV.phi) fprintf(logFP, " %3g %7.5f", GSV.phi, sigma); fprintf(logFP," %d %s\n", lmin, GAV.currform); } GAV.subi[0] = xsubi[0]; GAV.subi[1] = xsubi[1]; GAV.subi[2] = xsubi[2]; fprintf(logFP, "(%5hu %5hu %5hu)", GAV.subi[0], GAV.subi[1], GAV.subi[2]); fflush(logFP); Zeit = 0.0; /* reset laplace stuff for next trajectory */ sumT = 0.0; sumK = 0.0; sumKK = 0.0; sumD = 0.0; L = 0.0; D = 0.0; /* highestE = OhighestE = -1000.0; */ reset_nbList(); return(1); } else { /* continue simulation */ int flag = 0; if( (!GTV.silent) && (GSV.currE <= GSV.stopE+GSV.cut) ) { if (!GTV.lmin || (lmin==1 && strcmp(GAV.prevform, GAV.currform) != 0)) { char format[64]; flag = 1; sprintf(format, "%%-%ds %%6.2f %%10.3f", strlen(GAV.farbe_full)); printf(format, GAV.currform, GSV.currE, Zeit); } /* laplace stuff */ if (GTV.phi) { printf(" %8.3f %8.3f %3g", zeitInc, L, D); L = D = 0.0; /* reset L and D for next structure */ } if ( flag && GTV.verbose ) { int ii, jj; if (next<0) trans='g'; /* growth */ else { ii = neighbor_list[2*next]; jj = neighbor_list[2*next+1]; if (abs(ii) < GSV.len) { if ((ii > 0) && (jj > 0)) trans = 'i'; else if ((ii < 0) && (jj < 0)) trans = 'd'; else if ((ii > 0) && (jj < 0)) trans = 's'; else trans = 'S'; } else { if ((ii > 0) && (jj > 0)) trans = 'I'; else trans = 'D'; } } printf(" %4d %c %d", top, trans, lmin); } if (flag) printf("\n"); } } /* store last lmin seen, so we can avoid printing the same lmin twice */ if (lmin==1) strcpy(GAV.prevform, GAV.currform); #if 0 if (lmin==1) { /* went back to previous lmin */ if (strcmp(GAV.prevform, GAV.currform) == 0) { if (OhighestE < highestE) { highestE = OhighestE; /* delete loop */ strcpy(highestS, OhighestS); } } else { strcpy(GAV.prevform, GAV.currform); OhighestE = 10000.; } } if ( strcmp(GAV.currform, GAV.startform)==0 ) { OhighestE = highestE = -1000.; highestS[0] = 0; } /* log highes energy */ if (GSV.currE > highestE) { OhighestE = highestE; highestE = GSV.currE; strcpy(OhighestS, highestS); strcpy(highestS, GAV.currform); } #endif if (next>=0) update_tree(neighbor_list[2*next], neighbor_list[2*next+1]); else { clean_up_rl(); ini_or_reset_rl(); } reset_nbList(); return(0); }