Lines Matching +full:we +full:- +full:extra +full:- +full:delay

2  * Copyright 2023-2025 The OpenSSL Project Authors. All Rights Reserved.
59 data->backoff = (int)num; in noisy_dgram_ctrl()
69 data->noise_rate = (int)num; in noisy_dgram_ctrl()
79 data->recv_limit.bw = (size_t)num; in noisy_dgram_ctrl()
89 data->send_limit.bw = (size_t)num; in noisy_dgram_ctrl()
100 data->now_cb = now_cb->now_cb; in noisy_dgram_ctrl()
101 data->now_cb_arg = now_cb->now_cb_arg; in noisy_dgram_ctrl()
119 if (limit->bw == 0) /* 0 -> no limit */ in bandwidth_limit()
126 for (i = 0; i < limit->num; i++) { in bandwidth_limit()
127 size_t idx = (limit->start + i) % MAX_PKTS_PER_WINDOW; in bandwidth_limit()
129 if (ossl_time_compare(limit->pinfos[idx].timestamp, sampling_start) >= 0) in bandwidth_limit()
131 limit->size_sum -= limit->pinfos[idx].size; in bandwidth_limit()
133 limit->start = (limit->start + i) % MAX_PKTS_PER_WINDOW; in bandwidth_limit()
134 limit->num -= i; in bandwidth_limit()
140 if ((limit->size_sum + pktsize) / SAMPLING_WINDOW_PERIOD > limit->bw) { in bandwidth_limit()
155 if (limit->num >= MAX_PKTS_PER_WINDOW) { in bandwidth_limit()
156 limit->size_sum -= limit->pinfos[limit->start].size; in bandwidth_limit()
157 limit->start = (limit->start + 1) % MAX_PKTS_PER_WINDOW; in bandwidth_limit()
159 ++limit->num; in bandwidth_limit()
161 end = (limit->start + limit->num) % MAX_PKTS_PER_WINDOW; in bandwidth_limit()
162 limit->pinfos[end].size = pktsize; in bandwidth_limit()
163 limit->pinfos[end].timestamp = now; in bandwidth_limit()
164 limit->size_sum += pktsize; in bandwidth_limit()
184 now = data->now_cb != NULL ? data->now_cb(data->now_cb_arg) in noisy_dgram_sendmmsg()
188 num_msg = bandwidth_limit(&data->send_limit, now, msg, num_msg); in noisy_dgram_sendmmsg()
196 * We only introduce noise when receiving messages. We just pass this on in noisy_dgram_sendmmsg()
206 * We have 3 different types of noise: drop, duplicate and delay
216 * When a duplicate occurs we reinject the new datagram after up to
221 * This also controls when a delay (not a duplicate) occurs. In that case
222 * we add 1 to the number because there is no point in skipping the current
243 * Of noisy datagrams, 25% drop, 25% duplicate, 25% delay, 25% flip bits in get_noise()
253 * Where a duplicate occurs we reinject the copy of the datagram up to in get_noise()
262 * dropped (i.e. this is a delay not a duplicate), so we reinject after an in get_noise()
263 * extra datagram in that case in get_noise()
269 /* we flip at most 8 bits of the 16 bit value at once */ in get_noise()
289 flip_offset = msg_len - 2; in flip_bits()
320 * For simplicity we assume that all elements in the msg array have the in noisy_dgram_recvmmsg()
322 * strange for that not to be the case - and our code that calls in noisy_dgram_recvmmsg()
324 * code). We test the invariant here. in noisy_dgram_recvmmsg()
340 printf("Pre-filter datagram list:\n"); in noisy_dgram_recvmmsg()
342 printf("Pre-filter Datagram:\n"); in noisy_dgram_recvmmsg()
346 printf("End of pre-filter datagram list\nApplying noise filters:\n"); in noisy_dgram_recvmmsg()
349 now = data->now_cb != NULL ? data->now_cb(data->now_cb_arg) in noisy_dgram_recvmmsg()
353 msg_cnt = bandwidth_limit(&data->recv_limit, now, msg, msg_cnt); in noisy_dgram_recvmmsg()
357 if (data->noise_rate == 0) in noisy_dgram_recvmmsg()
363 i++, thismsg++, data->this_dgram++) { in noisy_dgram_recvmmsg()
369 /* If we have a message to reinject then insert it now */ in noisy_dgram_recvmmsg()
370 if (data->reinject_dgram > 0 in noisy_dgram_recvmmsg()
371 && data->reinject_dgram == data->this_dgram) { in noisy_dgram_recvmmsg()
374 for (j = msg_cnt; j > i; j--) { in noisy_dgram_recvmmsg()
375 if (!bio_msg_copy(&msg[j], &msg[j - 1])) in noisy_dgram_recvmmsg()
378 if (!bio_msg_copy(thismsg, &data->msg)) in noisy_dgram_recvmmsg()
381 data->reinject_dgram = 0; in noisy_dgram_recvmmsg()
384 BIO_dump_fp(stdout, thismsg->data, thismsg->data_len); in noisy_dgram_recvmmsg()
388 } /* else we have no space for the injection, so just drop it */ in noisy_dgram_recvmmsg()
389 data->reinject_dgram = 0; in noisy_dgram_recvmmsg()
392 get_noise(data->noise_rate, in noisy_dgram_recvmmsg()
393 /* long header */ (((uint8_t *)thismsg->data)[0] & 0x80) != 0, in noisy_dgram_recvmmsg()
395 if (data->backoff) { in noisy_dgram_recvmmsg()
397 * We might be asked to back off on introducing too much noise if in noisy_dgram_recvmmsg()
399 * we always ensure that the next datagram does not get dropped so in noisy_dgram_recvmmsg()
400 * that the connection always survives. After that we can resume in noisy_dgram_recvmmsg()
410 data->backoff--; in noisy_dgram_recvmmsg()
413 flip_bits(thismsg->data, thismsg->data_len, flip, flip_offset); in noisy_dgram_recvmmsg()
416 * We ignore reinjection if a message is already waiting to be in noisy_dgram_recvmmsg()
419 if (reinject > 0 && data->reinject_dgram == 0) { in noisy_dgram_recvmmsg()
422 * delay period. Datagrams that are delayed only (not duplicated) in noisy_dgram_recvmmsg()
426 if (!bio_msg_copy(&data->msg, thismsg)) in noisy_dgram_recvmmsg()
429 data->reinject_dgram = data->this_dgram + reinject; in noisy_dgram_recvmmsg()
434 BIO_dump_fp(stdout, thismsg->data, thismsg->data_len); in noisy_dgram_recvmmsg()
442 BIO_dump_fp(stdout, thismsg->data, thismsg->data_len); in noisy_dgram_recvmmsg()
446 if (!bio_msg_copy(&msg[j - 1], &msg[j])) in noisy_dgram_recvmmsg()
449 msg_cnt--; in noisy_dgram_recvmmsg()
454 printf("End of noise filters\nPost-filter datagram list:\n"); in noisy_dgram_recvmmsg()
456 printf("Post-filter Datagram:\n"); in noisy_dgram_recvmmsg()
460 printf("End of post-filter datagram list\n"); in noisy_dgram_recvmmsg()
479 OPENSSL_free(data->msg.data); in data_free()
480 BIO_ADDR_free(data->msg.peer); in data_free()
481 BIO_ADDR_free(data->msg.local); in data_free()
492 data->noise_rate = NOISE_RATE; in noisy_dgram_new()
493 data->msg.data = OPENSSL_malloc(MSG_DATA_LEN_MAX); in noisy_dgram_new()
494 data->msg.peer = BIO_ADDR_new(); in noisy_dgram_new()
495 data->msg.local = BIO_ADDR_new(); in noisy_dgram_new()
496 if (data->msg.data == NULL in noisy_dgram_new()
497 || data->msg.peer == NULL in noisy_dgram_new()
498 || data->msg.local == NULL) { in noisy_dgram_new()