static void internal_adjust_major_fuzz(float *major_fuzz) { int i; float f; /* here we want a randomness of .40 - .80 */ i = RANDOM()%40; f = (float) i / 100; /* 0 - 100% */ f += .40f; *major_fuzz = internal_trim(f, 0.40f, 0.80f); }
static void internal_adjust_minor_fuzz(float *minor_fuzz) { int i; float f; /* here we want a randomness of .03 - .07 */ i = RANDOM()%4; f = (float) i / 100; f += .03f; *minor_fuzz = internal_trim (f, 0.03f, 0.07f); }
static void internal_adjust_next_event(struct NetKeepAlive *nka, int got_reply, int ct) { /* if we are in the comfort zone, apply minor_fuzz. Otherwise, apply major_fuzz If we are in the comfort zone and got no reply, force us out of it. */ int i; struct timeval tv; float minor_minimum, major_minimum; i = RANDOM()&0x01; /* positive or negative shift? */ minor_minimum = KA_INITIAL_KEEPALIVE; major_minimum = (float) nka->maximal_keepalive * 0.75f; /* next_event = current_event * +/- factor */ if (nka->current_keepalive >= major_minimum) { // we are in the comfort zone // did we get any reply? // if not, bump down outside the zone // also ensure that if we // are stuck at either ends of the // spectrum, we get out fast #ifdef FAST_HANDOVER if (got_reply == 0 && ct > 1) nka->current_keepalive = major_minimum - 1; else #endif { float fuzz_factor; if (nka->current_keepalive == nka->maximal_keepalive) fuzz_factor = 1 - nka->minor_fuzz; else if (nka->current_keepalive == major_minimum) fuzz_factor = 1 + nka->minor_fuzz; else fuzz_factor = i ? (1 - nka->minor_fuzz) : (1 + nka->minor_fuzz); nka->current_keepalive = internal_trim((float)nka->current_keepalive * fuzz_factor, major_minimum, (float) nka->maximal_keepalive); } } /* else we are NOT in the comfort zone */ if (nka->current_keepalive < major_minimum) { /* if we got_reply we go up, otherwise we go down */ #ifdef FAST_HANDOVER float fuzz_factor; fuzz_factor = (ct < 2) ? (1 + nka->major_fuzz) : ( 1 - nka->major_fuzz); #else float fuzz_factor = 1; if (ct < 2) fuzz_factor = 1 + nka->major_fuzz; #endif nka->current_keepalive = internal_trim((float)nka->current_keepalive * fuzz_factor, minor_minimum, (float) nka->maximal_keepalive); } /* then put the next event in the timeval */ GETTIMEOFDAY(&tv, NULL); nka->next_event.tv_sec = tv.tv_sec + (int) nka->current_keepalive; nka->next_event.tv_usec = (long)( nka->current_keepalive - (int) nka->current_keepalive ) * 1000000; Display(LOG_LEVEL_3, ELInfo, "internal_adjust_next_event", HEX_STR_NEXT_KA_IN, nka->current_keepalive); return; }
/* Removes leaves from the trie with frequency under a certain amount */ void trim(int level) { internal_trim(level); }