X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fprotocol_misc.c;h=b8d2f67d39c6158484b89bc1ae91686c3faeaca8;hb=075e6828a7533e7daa790225f17aa6bb39703278;hp=95a240e18d8ffdbce7f2fe8aa599625ddc68c7d2;hpb=fbf305c09d91bf34b1504b58d50392df2e6bcfba;p=meshlink diff --git a/src/protocol_misc.c b/src/protocol_misc.c index 95a240e1..b8d2f67d 100644 --- a/src/protocol_misc.c +++ b/src/protocol_misc.c @@ -151,9 +151,10 @@ bool send_tcppacket(connection_t *c, vpn_packet_t *packet) { cp(); - /* If there already is a lot of data in the outbuf buffer, discard this packet. */ + /* If there already is a lot of data in the outbuf buffer, discard this packet. + We use a very simple Random Early Drop algorithm. */ - if(c->buffer->output->off > maxoutbufsize) + if(2.0 * c->buffer->output->off / (float)maxoutbufsize - 1 > (float)rand()/(float)RAND_MAX) return true; if(!send_request(c, "%d %hd", PACKET, packet->len))