Ejemplo n.º 1
0
key_event_t
key_limit_update (key_limit_t key)
{
#ifdef NO_64BIT_MATH
    if (low32(key->num_left) == 0) {
        // carry
        key->num_left = make64(high32(key->num_left) - 1, low32(key->num_left) - 1);
    }else  {
        // no carry
        key->num_left = make64(high32(key->num_left), low32(key->num_left) - 1);
    }
    if (high32(key->num_left) != 0 || low32(key->num_left) >= soft_limit) {
        return key_event_normal; /* we're above the soft limit */
    }
#else
    key->num_left--;
    if (key->num_left >= soft_limit) {
        return key_event_normal; /* we're above the soft limit */
    }
#endif
    if (key->state == key_state_normal) {
        /* we just passed the soft limit, so change the state */
        key->state = key_state_past_soft_limit;
    }
#ifdef NO_64BIT_MATH
    if (low32(key->num_left) == 0 && high32(key->num_left == 0))
#else
    if (key->num_left < 1)
#endif
    {   /* we just hit the hard limit */
        key->state = key_state_expired;
        return key_event_hard_limit;
    }
    return key_event_soft_limit;
}
Ejemplo n.º 2
0
void
index_advance(xtd_seq_num_t *pi, sequence_number_t s) {
#ifdef NO_64BIT_MATH
  /* a > ~b means a+b will generate a carry */
  /* s is uint16 here */
  *pi = make64(high32(*pi) + (s > ~low32(*pi) ? 1 : 0),low32(*pi) + s);
#else
  *pi += s;
#endif
}
err_status_t key_limit_set(key_limit_t key, const xtd_seq_num_t s) {
#ifdef NO_64BIT_MATH
    if (high32(s) == 0 && low32(s) < soft_limit)
    return err_status_bad_param;
#else
    if (s < soft_limit)
        return err_status_bad_param;
#endif
    key->num_left = s;
    key->state = key_state_normal;
    return err_status_ok;
}
Ejemplo n.º 4
0
 * (from a newly arrived packet), sets the contents of *guess to
 * contain the best guess of the packet index to which s corresponds,
 * and returns the difference between *guess and *local
 *
 * nota bene - the output is a signed integer, DON'T cast it to a
 * unsigned integer!  
 */

int
index_guess(const xtd_seq_num_t *local,
		   xtd_seq_num_t *guess,
		   sequence_number_t s) {
#ifdef NO_64BIT_MATH
  uint32_t local_roc = ((high32(*local) << 16) |
						(low32(*local) >> 16));
  uint16_t local_seq = (uint16_t) (low32(*local));
#else
  uint32_t local_roc = (uint32_t)(*local >> 16);
  uint16_t local_seq = (uint16_t) *local;
#endif
#ifdef NO_64BIT_MATH
  uint32_t guess_roc = ((high32(*guess) << 16) |
						(low32(*guess) >> 16));
  uint16_t guess_seq = (uint16_t) (low32(*guess));
#else
  uint32_t guess_roc = (uint32_t)(*guess >> 16);
  uint16_t guess_seq = (uint16_t) *guess;  
#endif
  int difference;
  
  if (local_seq < seq_num_median) {