… | |
… | |
54 | #define INITIAL_SYN_TIMEOUT 10. // retry timeout for initial syn |
54 | #define INITIAL_SYN_TIMEOUT 10. // retry timeout for initial syn |
55 | |
55 | |
56 | #define MIN_SEND_INTERVAL 0.01 // wait at least this time between sending requests |
56 | #define MIN_SEND_INTERVAL 0.01 // wait at least this time between sending requests |
57 | #define MAX_SEND_INTERVAL 0.5 // optimistic? |
57 | #define MAX_SEND_INTERVAL 0.5 // optimistic? |
58 | |
58 | |
|
|
59 | #define LATENCY_FACTOR 0.5 // RTT * LATENCY_FACTOR == sending rate |
59 | #define MAX_OUTSTANDING 10 // max. outstanding requests |
60 | #define MAX_OUTSTANDING 20 // max. outstanding requests |
60 | #define MAX_WINDOW 1000 // max. for MAX_OUTSTANDING, and backlog |
61 | #define MAX_WINDOW 1000 // max. for MAX_OUTSTANDING, and backlog |
61 | #define MAX_BACKLOG (100*1024) // size of gvpe protocol backlog (bytes), must be > MAXSIZE |
62 | #define MAX_BACKLOG (100*1024) // size of gvpe protocol backlog (bytes), must be > MAXSIZE |
62 | |
63 | |
63 | #define MAX_DOMAIN_SIZE 220 // 255 is legal limit, but bind doesn't compress well |
64 | #define MAX_DOMAIN_SIZE 200 // 255 is legal limit, but bind doesn't compress well |
64 | // 240 leaves about 4 bytes of server reply data |
65 | // 240 leaves about 4 bytes of server reply data |
65 | // every two request bytes less give room for one reply byte |
66 | // every two request bytes less give room for one reply byte |
66 | |
67 | |
67 | #define SEQNO_MASK 0x3fff |
68 | #define SEQNO_MASK 0x3fff |
68 | #define SEQNO_EQ(a,b) ( 0 == ( ((a) ^ (b)) & SEQNO_MASK) ) |
69 | #define SEQNO_EQ(a,b) ( 0 == ( ((a) ^ (b)) & SEQNO_MASK) ) |
… | |
… | |
547 | |
548 | |
548 | bool established; |
549 | bool established; |
549 | |
550 | |
550 | tstamp last_received; |
551 | tstamp last_received; |
551 | tstamp last_sent; |
552 | tstamp last_sent; |
552 | double last_latency; |
553 | double min_latency; |
553 | double poll_interval, send_interval; |
554 | double poll_interval, send_interval; |
554 | |
555 | |
555 | vector<dns_rcv *> rcvpq; |
556 | vector<dns_rcv *> rcvpq; |
556 | |
557 | |
557 | byte_stream rcvdq; int rcvseq; |
558 | byte_stream rcvdq; int rcvseq; |
… | |
… | |
731 | rcvseq = sndseq = 0; |
732 | rcvseq = sndseq = 0; |
732 | |
733 | |
733 | last_sent = last_received = 0; |
734 | last_sent = last_received = 0; |
734 | poll_interval = MIN_POLL_INTERVAL; |
735 | poll_interval = MIN_POLL_INTERVAL; |
735 | send_interval = 0.5; // starting rate |
736 | send_interval = 0.5; // starting rate |
736 | last_latency = INITIAL_TIMEOUT; |
737 | min_latency = INITIAL_TIMEOUT; |
737 | } |
738 | } |
738 | |
739 | |
739 | dns_connection::~dns_connection () |
740 | dns_connection::~dns_connection () |
740 | { |
741 | { |
741 | for (vector<dns_rcv *>::iterator i = rcvpq.begin (); |
742 | for (vector<dns_rcv *>::iterator i = rcvpq.begin (); |
… | |
… | |
754 | poll_interval = send_interval; |
755 | poll_interval = send_interval; |
755 | } |
756 | } |
756 | else |
757 | else |
757 | { |
758 | { |
758 | poll_interval *= 1.5; |
759 | poll_interval *= 1.5; |
|
|
760 | |
759 | if (poll_interval > MAX_POLL_INTERVAL) |
761 | if (poll_interval > MAX_POLL_INTERVAL) |
760 | poll_interval = MAX_POLL_INTERVAL; |
762 | poll_interval = MAX_POLL_INTERVAL; |
761 | } |
763 | } |
762 | |
764 | |
763 | rcvpq.push_back (r); |
765 | rcvpq.push_back (r); |
… | |
… | |
1024 | dns->send_interval = MIN_SEND_INTERVAL; |
1026 | dns->send_interval = MIN_SEND_INTERVAL; |
1025 | |
1027 | |
1026 | // the latency surely puts an upper bound on |
1028 | // the latency surely puts an upper bound on |
1027 | // the minimum send interval |
1029 | // the minimum send interval |
1028 | double latency = NOW - (*i)->sent; |
1030 | double latency = NOW - (*i)->sent; |
|
|
1031 | |
|
|
1032 | if (latency < dns->min_latency) |
1029 | dns->last_latency = latency; |
1033 | dns->min_latency = latency; |
1030 | |
1034 | |
1031 | if (dns->send_interval > latency) |
1035 | if (dns->send_interval > dns->min_latency * LATENCY_FACTOR) |
1032 | dns->send_interval = latency; |
1036 | dns->send_interval = dns->min_latency * LATENCY_FACTOR; |
1033 | } |
1037 | } |
1034 | |
1038 | |
1035 | delete *i; |
1039 | delete *i; |
1036 | dns_sndpq.erase (i); |
1040 | dns_sndpq.erase (i); |
1037 | |
1041 | |
… | |
… | |
1219 | if (!send) |
1223 | if (!send) |
1220 | { |
1224 | { |
1221 | send = r; |
1225 | send = r; |
1222 | |
1226 | |
1223 | r->retry++; |
1227 | r->retry++; |
1224 | r->timeout = NOW + (r->retry * last_latency * 8.); |
1228 | r->timeout = NOW + (r->retry * min_latency * 8.); |
1225 | |
1229 | |
1226 | // the following code changes the query section a bit, forcing |
1230 | // the following code changes the query section a bit, forcing |
1227 | // the forwarder to generate a new request |
1231 | // the forwarder to generate a new request |
1228 | if (r->stdhdr) |
1232 | if (r->stdhdr) |
1229 | { |
1233 | { |
… | |
… | |
1254 | } |
1258 | } |
1255 | else if (vpn->dns_sndpq.size () < MAX_OUTSTANDING |
1259 | else if (vpn->dns_sndpq.size () < MAX_OUTSTANDING |
1256 | && !SEQNO_EQ (rcvseq, sndseq - (MAX_WINDOW - 1))) |
1260 | && !SEQNO_EQ (rcvseq, sndseq - (MAX_WINDOW - 1))) |
1257 | { |
1261 | { |
1258 | //printf ("sending data request etc.\n"); //D |
1262 | //printf ("sending data request etc.\n"); //D |
1259 | if (!snddq.empty ()) |
1263 | if (!snddq.empty () || last_received + 1. > NOW) |
1260 | { |
1264 | { |
1261 | poll_interval = send_interval; |
1265 | poll_interval = send_interval; |
1262 | NEXT (NOW + send_interval); |
1266 | NEXT (NOW + send_interval); |
1263 | } |
1267 | } |
1264 | |
1268 | |
1265 | send = new dns_snd (this); |
1269 | send = new dns_snd (this); |
1266 | send->gen_stream_req (sndseq, snddq); |
1270 | send->gen_stream_req (sndseq, snddq); |
1267 | send->timeout = NOW + last_latency * 8.; |
1271 | send->timeout = NOW + min_latency * 8.; |
1268 | |
1272 | |
1269 | sndseq = (sndseq + 1) & SEQNO_MASK; |
1273 | sndseq = (sndseq + 1) & SEQNO_MASK; |
1270 | } |
1274 | } |
1271 | |
1275 | |
1272 | if (send) |
1276 | if (send) |