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.44 by pcg, Tue Dec 4 14:55:59 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines