--- gvpe/src/vpn_dns.C 2005/03/07 01:31:26 1.24 +++ gvpe/src/vpn_dns.C 2005/03/13 12:33:34 1.28 @@ -54,13 +54,14 @@ #define INITIAL_SYN_TIMEOUT 10. // retry timeout for initial syn #define MIN_SEND_INTERVAL 0.01 // wait at least this time between sending requests -#define MAX_SEND_INTERVAL 0.5 // optimistic? +#define MAX_SEND_INTERVAL 2. // optimistic? -#define MAX_OUTSTANDING 10 // max. outstanding requests +#define LATENCY_FACTOR 0.5 // RTT * LATENCY_FACTOR == sending rate +#define MAX_OUTSTANDING 100 // max. outstanding requests #define MAX_WINDOW 1000 // max. for MAX_OUTSTANDING, and backlog #define MAX_BACKLOG (100*1024) // size of gvpe protocol backlog (bytes), must be > MAXSIZE -#define MAX_DOMAIN_SIZE 220 // 255 is legal limit, but bind doesn't compress well +#define MAX_DOMAIN_SIZE 240 // 255 is legal limit, but bind doesn't compress well // 240 leaves about 4 bytes of server reply data // every two request bytes less give room for one reply byte @@ -450,8 +451,8 @@ seq_cdc = 26; req_cdc = 62; rep_cdc = 0; - max_size = ntohs (MAX_PKT_SIZE); - client = ntohs (clientid); + max_size = htons (MAX_PKT_SIZE); + client = htons (clientid); uid = next_uid++; r2 = r3 = r4 = 0; @@ -467,8 +468,7 @@ && seq_cdc == 26 && req_cdc == 62 && rep_cdc == 0 - && version == 1 - && max_size == ntohs (MAX_PKT_SIZE); + && version == 1; } struct dns_packet : net_packet @@ -549,7 +549,7 @@ tstamp last_received; tstamp last_sent; - double last_latency; + double min_latency; double poll_interval, send_interval; vector rcvpq; @@ -733,7 +733,7 @@ last_sent = last_received = 0; poll_interval = MIN_POLL_INTERVAL; send_interval = 0.5; // starting rate - last_latency = INITIAL_TIMEOUT; + min_latency = INITIAL_TIMEOUT; } dns_connection::~dns_connection () @@ -756,6 +756,7 @@ else { poll_interval *= 1.5; + if (poll_interval > MAX_POLL_INTERVAL) poll_interval = MAX_POLL_INTERVAL; } @@ -894,12 +895,13 @@ int rdlen_offs = offs += 2; - int dlen = (dns ? ntohs (dns->cfg.max_size) : MAX_PKT_SIZE) - offs; - // bind doesn't compress well, so reduce further by one label length - dlen -= qlen; - if (dns) { + int dlen = ntohs (dns->cfg.max_size) - offs; + + // bind doesn't compress well, so reduce further by one label length + dlen -= qlen; + // only put data into in-order sequence packets, if // we receive out-of-order packets we generate empty // replies @@ -1017,19 +1019,21 @@ } else { -#if 1 +#if 0 dns->send_interval *= 0.999; #endif - if (dns->send_interval < MIN_SEND_INTERVAL) - dns->send_interval = MIN_SEND_INTERVAL; - // the latency surely puts an upper bound on // the minimum send interval double latency = NOW - (*i)->sent; - dns->last_latency = latency; - if (dns->send_interval > latency) - dns->send_interval = latency; + if (latency < dns->min_latency) + dns->min_latency = latency; + + if (dns->send_interval > dns->min_latency * LATENCY_FACTOR) + dns->send_interval = dns->min_latency * LATENCY_FACTOR; + + if (dns->send_interval < MIN_SEND_INTERVAL) + dns->send_interval = MIN_SEND_INTERVAL; } delete *i; @@ -1221,13 +1225,13 @@ send = r; r->retry++; - r->timeout = NOW + (r->retry * last_latency * 8.); + r->timeout = NOW + (r->retry * min_latency * 8.); // the following code changes the query section a bit, forcing // the forwarder to generate a new request if (r->stdhdr) { - //printf ("reencoded header for ID %d retry %d:%d:%d\n", htons (r->pkt->id), THISNODE->id, r->seqno, r->retry);printf ("reencoded header for ID %d retry %d:%d:%d\n", htons (r->pkt->id), THISNODE->id, r->seqno, r->retry); + //printf ("reencoded header for ID %d retry %d:%d:%d (%p)\n", htons (r->pkt->id), THISNODE->id, r->seqno, r->retry); //encode_header ((char *)r->pkt->at (6 * 2 + 1), THISNODE->id, r->seqno, r->retry); } } @@ -1236,9 +1240,9 @@ NEXT (r->timeout); } - if (last_sent + send_interval <= NOW) + if (!send) { - if (!send) + if (last_sent + send_interval <= NOW) { // generate a new packet, if wise @@ -1256,7 +1260,7 @@ && !SEQNO_EQ (rcvseq, sndseq - (MAX_WINDOW - 1))) { //printf ("sending data request etc.\n"); //D - if (!snddq.empty ()) + if (!snddq.empty () || last_received + 1. > NOW) { poll_interval = send_interval; NEXT (NOW + send_interval); @@ -1264,7 +1268,7 @@ send = new dns_snd (this); send->gen_stream_req (sndseq, snddq); - send->timeout = NOW + last_latency * 8.; + send->timeout = NOW + min_latency * 8.; sndseq = (sndseq + 1) & SEQNO_MASK; } @@ -1272,21 +1276,22 @@ if (send) vpn->dns_sndpq.push_back (send); } + else + NEXT (last_sent + send_interval); + } - if (send) - { - last_sent = NOW; - sendto (vpn->dnsv4_fd, - send->pkt->at (0), send->pkt->len, 0, - vpn->dns_forwarder.sav4 (), vpn->dns_forwarder.salenv4 ()); - } + if (send) + { + last_sent = NOW; + sendto (vpn->dnsv4_fd, + send->pkt->at (0), send->pkt->len, 0, + vpn->dns_forwarder.sav4 (), vpn->dns_forwarder.salenv4 ()); } - else - NEXT (last_sent + send_interval); - slog (L_NOISE, "DNS: pi %f si %f N %f (%d:%d)", + slog (L_NOISE, "DNS: pi %f si %f N %f (%d:%d %d)", poll_interval, send_interval, next - NOW, - vpn->dns_sndpq.size (), snddq.size ()); + vpn->dns_sndpq.size (), snddq.size (), + rcvpq.size ()); // TODO: no idea when this happens, but when next < NOW, we have a problem if (next < NOW + 0.0001)