ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/vpn_dns.C
(Generate patch)

Comparing gvpe/src/vpn_dns.C (file contents):
Revision 1.42 by pcg, Sat Nov 10 05:14:22 2007 UTC vs.
Revision 1.43 by pcg, Sat Dec 1 23:35:31 2007 UTC

588: dns (dns) 588: dns (dns)
589{ 589{
590 timeout = 0; 590 timeout = 0;
591 retry = 0; 591 retry = 0;
592 seqno = 0; 592 seqno = 0;
593 sent = ev::ev_now (); 593 sent = ev_now ();
594 stdhdr = false; 594 stdhdr = false;
595 595
596 pkt = new dns_packet; 596 pkt = new dns_packet;
597 597
598 pkt->id = next_id (); 598 pkt->id = next_id ();
629void dns_snd::gen_stream_req (int seqno, byte_stream &stream) 629void dns_snd::gen_stream_req (int seqno, byte_stream &stream)
630{ 630{
631 stdhdr = true; 631 stdhdr = true;
632 this->seqno = seqno; 632 this->seqno = seqno;
633 633
634 timeout = ev::ev_now () + INITIAL_TIMEOUT; 634 timeout = ev_now () + INITIAL_TIMEOUT;
635 635
636 pkt->flags = htons (DEFAULT_CLIENT_FLAGS); 636 pkt->flags = htons (DEFAULT_CLIENT_FLAGS);
637 pkt->qdcount = htons (1); 637 pkt->qdcount = htons (1);
638 638
639 int offs = 6*2; 639 int offs = 6*2;
674 pkt->len = offs; 674 pkt->len = offs;
675} 675}
676 676
677void dns_snd::gen_syn_req () 677void dns_snd::gen_syn_req ()
678{ 678{
679 timeout = ev::ev_now () + INITIAL_SYN_TIMEOUT; 679 timeout = ev_now () + INITIAL_SYN_TIMEOUT;
680 680
681 pkt->flags = htons (DEFAULT_CLIENT_FLAGS); 681 pkt->flags = htons (DEFAULT_CLIENT_FLAGS);
682 pkt->qdcount = htons (1); 682 pkt->qdcount = htons (1);
683 683
684 int offs = 6 * 2; 684 int offs = 6 * 2;
750 750
751void dns_connection::receive_rep (dns_rcv *r) 751void dns_connection::receive_rep (dns_rcv *r)
752{ 752{
753 if (r->datalen) 753 if (r->datalen)
754 { 754 {
755 last_received = ev::ev_now (); 755 last_received = ev_now ();
756 tw (); 756 tw ();
757 757
758 poll_interval = send_interval; 758 poll_interval = send_interval;
759 } 759 }
760 else 760 else
1032#if 0 1032#if 0
1033 dns->send_interval *= 0.999; 1033 dns->send_interval *= 0.999;
1034#endif 1034#endif
1035 // the latency surely puts an upper bound on 1035 // the latency surely puts an upper bound on
1036 // the minimum send interval 1036 // the minimum send interval
1037 double latency = ev::ev_now () - (*i)->sent; 1037 double latency = ev_now () - (*i)->sent;
1038 1038
1039 if (latency < dns->min_latency) 1039 if (latency < dns->min_latency)
1040 dns->min_latency = latency; 1040 dns->min_latency = latency;
1041 1041
1042 if (dns->send_interval > dns->min_latency * conf.dns_overlap_factor) 1042 if (dns->send_interval > dns->min_latency * conf.dns_overlap_factor)
1225 i != vpn->dns_sndpq.end (); 1225 i != vpn->dns_sndpq.end ();
1226 ++i) 1226 ++i)
1227 { 1227 {
1228 dns_snd *r = *i; 1228 dns_snd *r = *i;
1229 1229
1230 if (r->timeout <= ev::ev_now ()) 1230 if (r->timeout <= ev_now ())
1231 { 1231 {
1232 if (!send) 1232 if (!send)
1233 { 1233 {
1234 send = r; 1234 send = r;
1235 1235
1236 r->retry++; 1236 r->retry++;
1237 r->timeout = ev::ev_now () + (r->retry * min_latency * conf.dns_timeout_factor); 1237 r->timeout = ev_now () + (r->retry * min_latency * conf.dns_timeout_factor);
1238 //printf ("RETRY %x (%d, %f)\n", r->seqno, r->retry, r->timeout - ev::ev_now ());//D 1238 //printf ("RETRY %x (%d, %f)\n", r->seqno, r->retry, r->timeout - ev_now ());//D
1239 1239
1240 // the following code changes the query section a bit, forcing 1240 // the following code changes the query section a bit, forcing
1241 // the forwarder to generate a new request 1241 // the forwarder to generate a new request
1242 if (r->stdhdr) 1242 if (r->stdhdr)
1243 encode_header ((char *)r->pkt->at (6 * 2 + 1), THISNODE->id, r->seqno, r->retry); 1243 encode_header ((char *)r->pkt->at (6 * 2 + 1), THISNODE->id, r->seqno, r->retry);
1262 } 1262 }
1263 } 1263 }
1264 else if (vpn->dns_sndpq.size () < conf.dns_max_outstanding 1264 else if (vpn->dns_sndpq.size () < conf.dns_max_outstanding
1265 && !SEQNO_EQ (rcvseq, sndseq - (MAX_WINDOW - 1))) 1265 && !SEQNO_EQ (rcvseq, sndseq - (MAX_WINDOW - 1)))
1266 { 1266 {
1267 if (last_sent + send_interval <= ev::ev_now ()) 1267 if (last_sent + send_interval <= ev_now ())
1268 { 1268 {
1269 //printf ("sending data request etc.\n"); //D 1269 //printf ("sending data request etc.\n"); //D
1270 if (!snddq.empty () || last_received + 1. > ev::ev_now ()) 1270 if (!snddq.empty () || last_received + 1. > ev_now ())
1271 { 1271 {
1272 poll_interval = send_interval; 1272 poll_interval = send_interval;
1273 NEXT (ev::ev_now () + send_interval); 1273 NEXT (ev_now () + send_interval);
1274 } 1274 }
1275 1275
1276 send = new dns_snd (this); 1276 send = new dns_snd (this);
1277 send->gen_stream_req (sndseq, snddq); 1277 send->gen_stream_req (sndseq, snddq);
1278 send->timeout = ev::ev_now () + min_latency * conf.dns_timeout_factor; 1278 send->timeout = ev_now () + min_latency * conf.dns_timeout_factor;
1279 //printf ("SEND %x (%f)\n", send->seqno, send->timeout - ev::ev_now (), min_latency, conf.dns_timeout_factor);//D 1279 //printf ("SEND %x (%f)\n", send->seqno, send->timeout - ev_now (), min_latency, conf.dns_timeout_factor);//D
1280 1280
1281 sndseq = (sndseq + 1) & SEQNO_MASK; 1281 sndseq = (sndseq + 1) & SEQNO_MASK;
1282 } 1282 }
1283 else 1283 else
1284 NEXT (last_sent + send_interval); 1284 NEXT (last_sent + send_interval);
1288 vpn->dns_sndpq.push_back (send); 1288 vpn->dns_sndpq.push_back (send);
1289 } 1289 }
1290 1290
1291 if (send) 1291 if (send)
1292 { 1292 {
1293 last_sent = ev::ev_now (); 1293 last_sent = ev_now ();
1294 sendto (vpn->dnsv4_fd, 1294 sendto (vpn->dnsv4_fd,
1295 send->pkt->at (0), send->pkt->len, 0, 1295 send->pkt->at (0), send->pkt->len, 0,
1296 vpn->dns_forwarder.sav4 (), vpn->dns_forwarder.salenv4 ()); 1296 vpn->dns_forwarder.sav4 (), vpn->dns_forwarder.salenv4 ());
1297 } 1297 }
1298 1298
1299 slog (L_NOISE, "DNS: pi %f si %f N %f (%d:%d %d)", 1299 slog (L_NOISE, "DNS: pi %f si %f N %f (%d:%d %d)",
1300 poll_interval, send_interval, next - ev::ev_now (), 1300 poll_interval, send_interval, next - ev_now (),
1301 vpn->dns_sndpq.size (), snddq.size (), 1301 vpn->dns_sndpq.size (), snddq.size (),
1302 rcvpq.size ()); 1302 rcvpq.size ());
1303 1303
1304 // TODO: no idea when this happens, but when next < ev::ev_now (), we have a problem 1304 // TODO: no idea when this happens, but when next < ev_now (), we have a problem
1305 // doesn't seem to happen anymore 1305 // doesn't seem to happen anymore
1306 if (next < ev::ev_now () + 0.001) 1306 if (next < ev_now () + 0.001)
1307 next = ev::ev_now () + 0.1; 1307 next = ev_now () + 0.1;
1308 1308
1309 w.start (next - ev::ev_now ()); 1309 w.start (next - ev_now ());
1310} 1310}
1311 1311
1312#endif 1312#endif
1313 1313

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines