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.46 by pcg, Thu Dec 6 00:35:29 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"
559 vector<dns_rcv *> rcvpq; 560 vector<dns_rcv *> rcvpq;
560 561
561 byte_stream rcvdq; int rcvseq; int repseq; 562 byte_stream rcvdq; int rcvseq; int repseq;
562 byte_stream snddq; int sndseq; 563 byte_stream snddq; int sndseq;
563 564
564 void time_cb (ev::timer &w, int revents); ev::timer tw; 565 inline void time_cb (ev::timer &w, int revents); ev::timer tw;
565 void receive_rep (dns_rcv *r); 566 void receive_rep (dns_rcv *r);
566 567
567 dns_connection (connection *c); 568 dns_connection (connection *c);
568 ~dns_connection (); 569 ~dns_connection ();
569}; 570};
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;
724 725
725dns_connection::dns_connection (connection *c) 726dns_connection::dns_connection (connection *c)
726: c (c) 727: c (c)
727, rcvdq (MAX_BACKLOG * 2) 728, rcvdq (MAX_BACKLOG * 2)
728, snddq (MAX_BACKLOG) 729, snddq (MAX_BACKLOG)
729, tw (this, &dns_connection::time_cb)
730{ 730{
731 tw.set<dns_connection, &dns_connection::time_cb> (this);
732
731 vpn = c->vpn; 733 vpn = c->vpn;
732 734
733 established = false; 735 established = false;
734 736
735 rcvseq = repseq = sndseq = 0; 737 rcvseq = repseq = sndseq = 0;
750 752
751void dns_connection::receive_rep (dns_rcv *r) 753void dns_connection::receive_rep (dns_rcv *r)
752{ 754{
753 if (r->datalen) 755 if (r->datalen)
754 { 756 {
755 last_received = ev::ev_now (); 757 last_received = ev_now ();
756 tw (); 758 tw ();
757 759
758 poll_interval = send_interval; 760 poll_interval = send_interval;
759 } 761 }
760 else 762 else
1032#if 0 1034#if 0
1033 dns->send_interval *= 0.999; 1035 dns->send_interval *= 0.999;
1034#endif 1036#endif
1035 // the latency surely puts an upper bound on 1037 // the latency surely puts an upper bound on
1036 // the minimum send interval 1038 // the minimum send interval
1037 double latency = ev::ev_now () - (*i)->sent; 1039 double latency = ev_now () - (*i)->sent;
1038 1040
1039 if (latency < dns->min_latency) 1041 if (latency < dns->min_latency)
1040 dns->min_latency = latency; 1042 dns->min_latency = latency;
1041 1043
1042 if (dns->send_interval > dns->min_latency * conf.dns_overlap_factor) 1044 if (dns->send_interval > dns->min_latency * conf.dns_overlap_factor)
1225 i != vpn->dns_sndpq.end (); 1227 i != vpn->dns_sndpq.end ();
1226 ++i) 1228 ++i)
1227 { 1229 {
1228 dns_snd *r = *i; 1230 dns_snd *r = *i;
1229 1231
1230 if (r->timeout <= ev::ev_now ()) 1232 if (r->timeout <= ev_now ())
1231 { 1233 {
1232 if (!send) 1234 if (!send)
1233 { 1235 {
1234 send = r; 1236 send = r;
1235 1237
1236 r->retry++; 1238 r->retry++;
1237 r->timeout = ev::ev_now () + (r->retry * min_latency * conf.dns_timeout_factor); 1239 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 1240 //printf ("RETRY %x (%d, %f)\n", r->seqno, r->retry, r->timeout - ev_now ());//D
1239 1241
1240 // the following code changes the query section a bit, forcing 1242 // the following code changes the query section a bit, forcing
1241 // the forwarder to generate a new request 1243 // the forwarder to generate a new request
1242 if (r->stdhdr) 1244 if (r->stdhdr)
1243 encode_header ((char *)r->pkt->at (6 * 2 + 1), THISNODE->id, r->seqno, r->retry); 1245 encode_header ((char *)r->pkt->at (6 * 2 + 1), THISNODE->id, r->seqno, r->retry);
1262 } 1264 }
1263 } 1265 }
1264 else if (vpn->dns_sndpq.size () < conf.dns_max_outstanding 1266 else if (vpn->dns_sndpq.size () < conf.dns_max_outstanding
1265 && !SEQNO_EQ (rcvseq, sndseq - (MAX_WINDOW - 1))) 1267 && !SEQNO_EQ (rcvseq, sndseq - (MAX_WINDOW - 1)))
1266 { 1268 {
1267 if (last_sent + send_interval <= ev::ev_now ()) 1269 if (last_sent + send_interval <= ev_now ())
1268 { 1270 {
1269 //printf ("sending data request etc.\n"); //D 1271 //printf ("sending data request etc.\n"); //D
1270 if (!snddq.empty () || last_received + 1. > ev::ev_now ()) 1272 if (!snddq.empty () || last_received + 1. > ev_now ())
1271 { 1273 {
1272 poll_interval = send_interval; 1274 poll_interval = send_interval;
1273 NEXT (ev::ev_now () + send_interval); 1275 NEXT (ev_now () + send_interval);
1274 } 1276 }
1275 1277
1276 send = new dns_snd (this); 1278 send = new dns_snd (this);
1277 send->gen_stream_req (sndseq, snddq); 1279 send->gen_stream_req (sndseq, snddq);
1278 send->timeout = ev::ev_now () + min_latency * conf.dns_timeout_factor; 1280 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 1281 //printf ("SEND %x (%f)\n", send->seqno, send->timeout - ev_now (), min_latency, conf.dns_timeout_factor);//D
1280 1282
1281 sndseq = (sndseq + 1) & SEQNO_MASK; 1283 sndseq = (sndseq + 1) & SEQNO_MASK;
1282 } 1284 }
1283 else 1285 else
1284 NEXT (last_sent + send_interval); 1286 NEXT (last_sent + send_interval);
1288 vpn->dns_sndpq.push_back (send); 1290 vpn->dns_sndpq.push_back (send);
1289 } 1291 }
1290 1292
1291 if (send) 1293 if (send)
1292 { 1294 {
1293 last_sent = ev::ev_now (); 1295 last_sent = ev_now ();
1294 sendto (vpn->dnsv4_fd, 1296 sendto (vpn->dnsv4_fd,
1295 send->pkt->at (0), send->pkt->len, 0, 1297 send->pkt->at (0), send->pkt->len, 0,
1296 vpn->dns_forwarder.sav4 (), vpn->dns_forwarder.salenv4 ()); 1298 vpn->dns_forwarder.sav4 (), vpn->dns_forwarder.salenv4 ());
1297 } 1299 }
1298 1300
1299 slog (L_NOISE, "DNS: pi %f si %f N %f (%d:%d %d)", 1301 slog (L_NOISE, "DNS: pi %f si %f N %f (%d:%d %d)",
1300 poll_interval, send_interval, next - ev::ev_now (), 1302 poll_interval, send_interval, next - ev_now (),
1301 vpn->dns_sndpq.size (), snddq.size (), 1303 vpn->dns_sndpq.size (), snddq.size (),
1302 rcvpq.size ()); 1304 rcvpq.size ());
1303 1305
1304 // TODO: no idea when this happens, but when next < ev::ev_now (), we have a problem 1306 // TODO: no idea when this happens, but when next < ev_now (), we have a problem
1305 // doesn't seem to happen anymore 1307 // doesn't seem to happen anymore
1306 if (next < ev::ev_now () + 0.001) 1308 if (next < ev_now () + 0.001)
1307 next = ev::ev_now () + 0.1; 1309 next = ev_now () + 0.1;
1308 1310
1309 w.start (next - ev::ev_now ()); 1311 w.start (next - ev_now ());
1310} 1312}
1311 1313
1312#endif 1314#endif
1313 1315

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines