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.21 by pcg, Sun Mar 6 21:33:40 2005 UTC vs.
Revision 1.33 by pcg, Tue Mar 15 19:23:33 2005 UTC

44 44
45#include "netcompat.h" 45#include "netcompat.h"
46 46
47#include "vpn.h" 47#include "vpn.h"
48 48
49#define MIN_POLL_INTERVAL .02 // how often to poll minimally when the server has data
50#define MAX_POLL_INTERVAL 6. // how often to poll minimally when the server has no data 49#define MAX_POLL_INTERVAL 5. // how often to poll minimally when the server has no data
51#define ACTIVITY_INTERVAL 5. 50#define ACTIVITY_INTERVAL 5.
51
52#define TIMEOUT_FACTOR 8.
52 53
53#define INITIAL_TIMEOUT 0.1 // retry timeouts 54#define INITIAL_TIMEOUT 0.1 // retry timeouts
54#define INITIAL_SYN_TIMEOUT 10. // retry timeout for initial syn 55#define INITIAL_SYN_TIMEOUT 10. // retry timeout for initial syn
55 56
56#define MIN_SEND_INTERVAL 0.01 // wait at least this time between sending requests 57#define MIN_SEND_INTERVAL 0.001 // wait at least this time between sending requests
57#define MAX_SEND_INTERVAL 0.5 // optimistic? 58#define MAX_SEND_INTERVAL 2. // optimistic?
58 59
60#define LATENCY_FACTOR 0.5 // RTT * LATENCY_FACTOR == sending rate
59#define MAX_OUTSTANDING 10 // max. outstanding requests 61#define MAX_OUTSTANDING 100 // max. outstanding requests
60#define MAX_WINDOW 1000 // max. for MAX_OUTSTANDING, and backlog 62#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 63#define MAX_BACKLOG (32*1024) // size of gvpe protocol backlog (bytes), must be > MAXSIZE
62 64
63#define MAX_DOMAIN_SIZE 220 // 255 is legal limit, but bind doesn't compress well 65#define MAX_DOMAIN_SIZE 220 // 255 is legal limit, but bind doesn't compress well
64// 240 leaves about 4 bytes of server reply data 66// 240 leaves about 4 bytes of server reply data
65// every two request bytes less give room for one reply byte 67// every request byte less give room for two reply bytes
66 68
67#define SEQNO_MASK 0x3fff 69#define SEQNO_MASK 0x3fff
68#define SEQNO_EQ(a,b) ( 0 == ( ((a) ^ (b)) & SEQNO_MASK) ) 70#define SEQNO_EQ(a,b) ( 0 == ( ((a) ^ (b)) & SEQNO_MASK) )
69 71
70#define MAX_LBL_SIZE 63 72#define MAX_LBL_SIZE 63
265static basecoder cdc26 ("dPhZrQmJkBtSvLxAeFwGyO"); 267static basecoder cdc26 ("dPhZrQmJkBtSvLxAeFwGyO");
266 268
267///////////////////////////////////////////////////////////////////////////// 269/////////////////////////////////////////////////////////////////////////////
268 270
269#define HDRSIZE 6 271#define HDRSIZE 6
270 272
271inline void encode_header (char *data, int clientid, int seqno, int retry = 0) 273inline void encode_header (char *data, int clientid, int seqno, int retry = 0)
272{ 274{
273 seqno &= SEQNO_MASK; 275 seqno &= SEQNO_MASK;
274 276
275 u8 hdr[3] = { 277 u8 hdr[3] = {
409struct dns_cfg 411struct dns_cfg
410{ 412{
411 static int next_uid; 413 static int next_uid;
412 414
413 u8 id1, id2, id3, id4; 415 u8 id1, id2, id3, id4;
416
414 u8 version; 417 u8 version;
418 u8 flags;
415 u8 rrtype; 419 u8 rrtype;
416 u8 flags;
417 u8 def_ttl; 420 u8 def_ttl;
418 u8 rcv_cdc; 421
419 u8 snd_cdc;
420 u16 max_size;
421 u16 client; 422 u16 client;
422 u16 uid; // to make request unique 423 u16 uid; // to make request unique
423 424
424 u8 reserved[8]; 425 u16 max_size;
426 u8 seq_cdc;
427 u8 req_cdc;
428
429 u8 rep_cdc;
430 u8 delay; // time in 0.01s units that the server may delay replying packets
431 u8 r3, r4;
432
433 u8 r5, r6, r7, r8;
425 434
426 void reset (int clientid); 435 void reset (int clientid);
427 bool valid (); 436 bool valid ();
428}; 437};
429 438
438 447
439 version = 1; 448 version = 1;
440 449
441 rrtype = RR_TYPE_TXT; 450 rrtype = RR_TYPE_TXT;
442 flags = 0; 451 flags = 0;
443 def_ttl = 1; 452 def_ttl = 0;
453 seq_cdc = 26;
454 req_cdc = 62;
444 rcv_cdc = 0; 455 rep_cdc = 0;
445 snd_cdc = 62;
446 max_size = ntohs (MAX_PKT_SIZE); 456 max_size = htons (MAX_PKT_SIZE);
447 client = ntohs (clientid); 457 client = htons (clientid);
448 uid = next_uid++; 458 uid = next_uid++;
459 delay = 0;
449 460
450 memset (reserved, 0, 8); 461 r3 = r4 = 0;
462 r4 = r5 = r6 = r7 = 0;
451} 463}
452 464
453bool dns_cfg::valid () 465bool dns_cfg::valid ()
454{ 466{
455 return id1 == 'G' 467 return id1 == 'G'
456 && id2 == 'V' 468 && id2 == 'V'
457 && id3 == 'P' 469 && id3 == 'P'
458 && id4 == 'E' 470 && id4 == 'E'
471 && seq_cdc == 26
472 && req_cdc == 62
473 && rep_cdc == 0
459 && version == 1 474 && version == 1;
460 && flags == 0
461 && rcv_cdc == 0
462 && snd_cdc == 62
463 && max_size == ntohs (MAX_PKT_SIZE);
464} 475}
465 476
466struct dns_packet : net_packet 477struct dns_packet : net_packet
467{ 478{
468 u16 id; 479 u16 id;
469 u16 flags; // QR:1 Opcode:4 AA:1 TC:1 RD:1 RA:1 Z:3 RCODE:4 480 u16 flags; // QR:1 Opcode:4 AA:1 TC:1 RD:1 RA:1 Z:3 RCODE:4
470 u16 qdcount, ancount, nscount, arcount; 481 u16 qdcount, ancount, nscount, arcount;
471 482
472 u8 data[MAXSIZE - 6 * 2]; 483 u8 data [MAXSIZE - 6 * 2];
473 484
474 int decode_label (char *data, int size, int &offs); 485 int decode_label (char *data, int size, int &offs);
475}; 486};
476 487
477int dns_packet::decode_label (char *data, int size, int &offs) 488int dns_packet::decode_label (char *data, int size, int &offs)
539 550
540 bool established; 551 bool established;
541 552
542 tstamp last_received; 553 tstamp last_received;
543 tstamp last_sent; 554 tstamp last_sent;
544 double last_latency; 555 double min_latency;
545 double poll_interval, send_interval; 556 double poll_interval, send_interval;
546 557
547 vector<dns_rcv *> rcvpq; 558 vector<dns_rcv *> rcvpq;
548 559
549 byte_stream rcvdq; int rcvseq; 560 byte_stream rcvdq; int rcvseq; int repseq;
550 byte_stream snddq; int sndseq; 561 byte_stream snddq; int sndseq;
551 562
552 void time_cb (time_watcher &w); time_watcher tw; 563 void time_cb (time_watcher &w); time_watcher tw;
553 void receive_rep (dns_rcv *r); 564 void receive_rep (dns_rcv *r);
554 565
664 675
665void dns_snd::gen_syn_req () 676void dns_snd::gen_syn_req ()
666{ 677{
667 timeout = NOW + INITIAL_SYN_TIMEOUT; 678 timeout = NOW + INITIAL_SYN_TIMEOUT;
668 679
669 printf ("send syn\n");//D
670
671 pkt->flags = htons (DEFAULT_CLIENT_FLAGS); 680 pkt->flags = htons (DEFAULT_CLIENT_FLAGS);
672 pkt->qdcount = htons (1); 681 pkt->qdcount = htons (1);
673 682
674 int offs = 6 * 2; 683 int offs = 6 * 2;
675 684
713///////////////////////////////////////////////////////////////////////////// 722/////////////////////////////////////////////////////////////////////////////
714 723
715dns_connection::dns_connection (connection *c) 724dns_connection::dns_connection (connection *c)
716: c (c) 725: c (c)
717, rcvdq (MAX_BACKLOG * 2) 726, rcvdq (MAX_BACKLOG * 2)
718, snddq (MAX_BACKLOG * 2) 727, snddq (MAX_BACKLOG)
719, tw (this, &dns_connection::time_cb) 728, tw (this, &dns_connection::time_cb)
720{ 729{
721 vpn = c->vpn; 730 vpn = c->vpn;
722 731
723 established = false; 732 established = false;
724 733
725 rcvseq = sndseq = 0; 734 rcvseq = repseq = sndseq = 0;
726 735
727 last_sent = last_received = 0; 736 last_sent = last_received = 0;
728 poll_interval = MIN_POLL_INTERVAL; 737 poll_interval = 0.5; // starting here
729 send_interval = 0.5; // starting rate 738 send_interval = 0.5; // starting rate
730 last_latency = INITIAL_TIMEOUT; 739 min_latency = INITIAL_TIMEOUT;
731} 740}
732 741
733dns_connection::~dns_connection () 742dns_connection::~dns_connection ()
734{ 743{
735 for (vector<dns_rcv *>::iterator i = rcvpq.begin (); 744 for (vector<dns_rcv *>::iterator i = rcvpq.begin ();
748 poll_interval = send_interval; 757 poll_interval = send_interval;
749 } 758 }
750 else 759 else
751 { 760 {
752 poll_interval *= 1.5; 761 poll_interval *= 1.5;
762
753 if (poll_interval > MAX_POLL_INTERVAL) 763 if (poll_interval > MAX_POLL_INTERVAL)
754 poll_interval = MAX_POLL_INTERVAL; 764 poll_interval = MAX_POLL_INTERVAL;
755 } 765 }
756 766
757 rcvpq.push_back (r); 767 rcvpq.push_back (r);
783 } 793 }
784 794
785 while (vpn_packet *pkt = rcvdq.get ()) 795 while (vpn_packet *pkt = rcvdq.get ())
786 { 796 {
787 sockinfo si; 797 sockinfo si;
788 si.host = 0x01010101; si.port = htons (c->conf->id); si.prot = PROT_DNSv4; 798 si.host = htonl (c->conf->id); si.port = 0; si.prot = PROT_DNSv4;
789 799
790 vpn->recv_vpn_packet (pkt, si); 800 vpn->recv_vpn_packet (pkt, si);
791 801
792 delete pkt; 802 delete pkt;
793 } 803 }
807 pkt.flags = htons (DEFAULT_SERVER_FLAGS | FLAG_RCODE_FORMERR); 817 pkt.flags = htons (DEFAULT_SERVER_FLAGS | FLAG_RCODE_FORMERR);
808 818
809 if (0 == (flags & (FLAG_RESPONSE | FLAG_OP_MASK)) 819 if (0 == (flags & (FLAG_RESPONSE | FLAG_OP_MASK))
810 && pkt.qdcount == htons (1)) 820 && pkt.qdcount == htons (1))
811 { 821 {
812 char qname[MAXSIZE]; 822 char qname [MAXSIZE];
813 int qlen = pkt.decode_label ((char *)qname, MAXSIZE - offs, offs); 823 int qlen = pkt.decode_label ((char *)qname, MAXSIZE - offs, offs);
814 824
815 u16 qtype = pkt [offs++] << 8; qtype |= pkt [offs++]; 825 u16 qtype = pkt [offs++] << 8; qtype |= pkt [offs++];
816 u16 qclass = pkt [offs++] << 8; qclass |= pkt [offs++]; 826 u16 qclass = pkt [offs++] << 8; qclass |= pkt [offs++];
817 827
824 834
825 int dlen = strlen (THISNODE->domain); 835 int dlen = strlen (THISNODE->domain);
826 836
827 if (qclass == RR_CLASS_IN 837 if (qclass == RR_CLASS_IN
828 && qlen > dlen + 1 838 && qlen > dlen + 1
829 && !memcmp (qname + qlen - dlen - 1, THISNODE->domain, dlen)) 839 && !memcmp (qname + qlen - (dlen + 1), THISNODE->domain, dlen))
830 { 840 {
831 // now generate reply 841 // now generate reply
832 pkt.ancount = htons (1); // one answer RR 842 pkt.ancount = htons (1); // one answer RR
833 pkt.flags = htons (DEFAULT_SERVER_FLAGS | FLAG_RCODE_OK); 843 pkt.flags = htons (DEFAULT_SERVER_FLAGS | FLAG_RCODE_OK);
834 844
847 if (0 < client && client <= conns.size ()) 857 if (0 < client && client <= conns.size ())
848 { 858 {
849 connection *c = conns [client - 1]; 859 connection *c = conns [client - 1];
850 dns_connection *dns = c->dns; 860 dns_connection *dns = c->dns;
851 dns_rcv *rcv; 861 dns_rcv *rcv;
852 bool in_seq;
853 862
854 if (dns) 863 if (dns)
855 { 864 {
856 for (vector<dns_rcv *>::iterator i = dns->rcvpq.end (); i-- != dns->rcvpq.begin (); ) 865 for (vector<dns_rcv *>::iterator i = dns->rcvpq.end (); i-- != dns->rcvpq.begin (); )
857 if (SEQNO_EQ ((*i)->seqno, seqno)) 866 if (SEQNO_EQ ((*i)->seqno, seqno))
868 memcpy (pkt.at (0), r->pkt->at (0), offs = r->pkt->len); 877 memcpy (pkt.at (0), r->pkt->at (0), offs = r->pkt->len);
869 878
870 goto duplicate_request; 879 goto duplicate_request;
871 } 880 }
872 881
873 in_seq = dns->rcvseq == seqno;
874
875 // new packet, queue 882 // new packet, queue
876 rcv = new dns_rcv (seqno, data, datalen); 883 rcv = new dns_rcv (seqno, data, datalen);
877 dns->receive_rep (rcv); 884 dns->receive_rep (rcv);
878 } 885 }
879 886
886 pkt [offs++] = 0; pkt [offs++] = 0; 893 pkt [offs++] = 0; pkt [offs++] = 0;
887 pkt [offs++] = 0; pkt [offs++] = dns ? dns->cfg.def_ttl : 0; // TTL 894 pkt [offs++] = 0; pkt [offs++] = dns ? dns->cfg.def_ttl : 0; // TTL
888 895
889 int rdlen_offs = offs += 2; 896 int rdlen_offs = offs += 2;
890 897
891 int dlen = (dns ? ntohs (dns->cfg.max_size) : MAX_PKT_SIZE) - offs;
892 // bind doesn't compress well, so reduce further by one label length
893 dlen -= qlen;
894
895 if (dns) 898 if (dns)
896 { 899 {
900 int dlen = ntohs (dns->cfg.max_size) - offs;
901
902 // bind doesn't compress well, so reduce further by one label length
903 dlen -= qlen;
904
897 // only put data into in-order sequence packets, if 905 // only put data into in-order sequence packets, if
898 // we receive out-of-order packets we generate empty 906 // we receive out-of-order packets we generate empty
899 // replies 907 // replies
900 while (dlen > 1 && !dns->snddq.empty () && in_seq) 908 //printf ("%d - %d & %x (=%d) < %d\n", seqno, dns->repseq, SEQNO_MASK, (seqno - dns->repseq) & SEQNO_MASK, MAX_WINDOW);//D
909 if (((seqno - dns->repseq) & SEQNO_MASK) <= MAX_WINDOW)
901 { 910 {
911 dns->repseq = seqno;
912
913 while (dlen > 1 && !dns->snddq.empty ())
914 {
902 int txtlen = dlen <= 255 ? dlen - 1 : 255; 915 int txtlen = dlen <= 255 ? dlen - 1 : 255;
903 916
904 if (txtlen > dns->snddq.size ()) 917 if (txtlen > dns->snddq.size ())
905 txtlen = dns->snddq.size (); 918 txtlen = dns->snddq.size ();
906 919
907 pkt[offs++] = txtlen; 920 pkt[offs++] = txtlen;
908 memcpy (pkt.at (offs), dns->snddq.begin (), txtlen); 921 memcpy (pkt.at (offs), dns->snddq.begin (), txtlen);
909 offs += txtlen; 922 offs += txtlen;
910 dns->snddq.remove (txtlen); 923 dns->snddq.remove (txtlen);
911 924
912 dlen -= txtlen + 1; 925 dlen -= txtlen + 1;
926 }
913 } 927 }
914 928
915 // avoid empty TXT rdata 929 // avoid completely empty TXT rdata
916 if (offs == rdlen_offs) 930 if (offs == rdlen_offs)
917 pkt[offs++] = 0; 931 pkt[offs++] = 0;
918 932
919 slog (L_NOISE, "DNS: snddq %d", dns->snddq.size ()); 933 slog (L_NOISE, "DNS: snddq %d", dns->snddq.size ());
920 } 934 }
956 pkt [offs++] = RR_CLASS_IN >> 8; pkt [offs++] = RR_CLASS_IN; // class 970 pkt [offs++] = RR_CLASS_IN >> 8; pkt [offs++] = RR_CLASS_IN; // class
957 pkt [offs++] = 0; pkt [offs++] = 0; 971 pkt [offs++] = 0; pkt [offs++] = 0;
958 pkt [offs++] = 0; pkt [offs++] = cfg.def_ttl; // TTL 972 pkt [offs++] = 0; pkt [offs++] = cfg.def_ttl; // TTL
959 pkt [offs++] = 0; pkt [offs++] = 4; // rdlength 973 pkt [offs++] = 0; pkt [offs++] = 4; // rdlength
960 974
961 slog (L_INFO, _("DNS: client %d tries to connect"), client); 975 slog (L_INFO, _("DNS: client %d connects"), client);
962 976
963 pkt [offs++] = CMD_IP_1; pkt [offs++] = CMD_IP_2; pkt [offs++] = CMD_IP_3; 977 pkt [offs++] = CMD_IP_1; pkt [offs++] = CMD_IP_2; pkt [offs++] = CMD_IP_3;
964 pkt [offs++] = CMD_IP_REJ; 978 pkt [offs++] = CMD_IP_REJ;
965 979
966 if (0 < client && client <= conns.size ()) 980 if (0 < client && client <= conns.size ())
1009 if (dns->send_interval > MAX_SEND_INTERVAL) 1023 if (dns->send_interval > MAX_SEND_INTERVAL)
1010 dns->send_interval = MAX_SEND_INTERVAL; 1024 dns->send_interval = MAX_SEND_INTERVAL;
1011 } 1025 }
1012 else 1026 else
1013 { 1027 {
1014#if 1 1028#if 0
1015 dns->send_interval *= 0.999; 1029 dns->send_interval *= 0.999;
1016#endif 1030#endif
1017 if (dns->send_interval < MIN_SEND_INTERVAL)
1018 dns->send_interval = MIN_SEND_INTERVAL;
1019
1020 // the latency surely puts an upper bound on 1031 // the latency surely puts an upper bound on
1021 // the minimum send interval 1032 // the minimum send interval
1022 double latency = NOW - (*i)->sent; 1033 double latency = NOW - (*i)->sent;
1034
1035 if (latency < dns->min_latency)
1023 dns->last_latency = latency; 1036 dns->min_latency = latency;
1024 1037
1025 if (dns->send_interval > latency) 1038 if (dns->send_interval > dns->min_latency * LATENCY_FACTOR)
1026 dns->send_interval = latency; 1039 dns->send_interval = dns->min_latency * LATENCY_FACTOR;
1040
1041 if (dns->send_interval < MIN_SEND_INTERVAL)
1042 dns->send_interval = MIN_SEND_INTERVAL;
1027 } 1043 }
1028 1044
1029 delete *i; 1045 delete *i;
1030 dns_sndpq.erase (i); 1046 dns_sndpq.erase (i);
1031 1047
1148 1164
1149 pkt->len = recvfrom (w.fd, pkt->at (0), MAXSIZE, 0, (sockaddr *)&sa, &sa_len); 1165 pkt->len = recvfrom (w.fd, pkt->at (0), MAXSIZE, 0, (sockaddr *)&sa, &sa_len);
1150 1166
1151 if (pkt->len > 0) 1167 if (pkt->len > 0)
1152 { 1168 {
1153 if (THISNODE->dns_port) 1169 if (ntohs (pkt->flags) & FLAG_RESPONSE)
1170 dnsv4_client (*pkt);
1171 else
1154 { 1172 {
1155 dnsv4_server (*pkt); 1173 dnsv4_server (*pkt);
1156 sendto (w.fd, pkt->at (0), pkt->len, 0, (sockaddr *)&sa, sa_len); 1174 sendto (w.fd, pkt->at (0), pkt->len, 0, (sockaddr *)&sa, sa_len);
1157 } 1175 }
1158 else
1159 dnsv4_client (*pkt);
1160 1176
1161 delete pkt; 1177 delete pkt;
1162 } 1178 }
1163 } 1179 }
1164} 1180}
1165 1181
1166bool 1182bool
1167vpn::send_dnsv4_packet (vpn_packet *pkt, const sockinfo &si, int tos) 1183vpn::send_dnsv4_packet (vpn_packet *pkt, const sockinfo &si, int tos)
1168{ 1184{
1169 int client = ntohs (si.port); 1185 int client = ntohl (si.host);
1170 1186
1171 assert (0 < client && client <= conns.size ()); 1187 assert (0 < client && client <= conns.size ());
1172 1188
1173 connection *c = conns [client - 1]; 1189 connection *c = conns [client - 1];
1174 1190
1175 if (!c->dns) 1191 if (!c->dns)
1176 c->dns = new dns_connection (c); 1192 c->dns = new dns_connection (c);
1177 1193
1178 if (!c->dns->snddq.put (pkt)) 1194 if (c->dns->snddq.put (pkt))
1179 return false;
1180
1181 c->dns->tw.trigger (); 1195 c->dns->tw.trigger ();
1182 1196
1197 // always return true even if the buffer overflows
1183 return true; 1198 return true;
1184} 1199}
1185 1200
1186void 1201void
1187connection::dnsv4_reset_connection () 1202connection::dnsv4_reset_connection ()
1213 if (!send) 1228 if (!send)
1214 { 1229 {
1215 send = r; 1230 send = r;
1216 1231
1217 r->retry++; 1232 r->retry++;
1218 r->timeout = NOW + (r->retry * last_latency * 8.); 1233 r->timeout = NOW + (r->retry * min_latency * TIMEOUT_FACTOR);
1234 printf ("TO %d %f\n", r->retry, r->timeout - NOW);//D
1219 1235
1220 // the following code changes the query section a bit, forcing 1236 // the following code changes the query section a bit, forcing
1221 // the forwarder to generate a new request 1237 // the forwarder to generate a new request
1222 if (r->stdhdr) 1238 if (r->stdhdr)
1223 { 1239 {
1224 //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); 1240 //printf ("reencoded header for ID %d retry %d:%d:%d (%p)\n", htons (r->pkt->id), THISNODE->id, r->seqno, r->retry);
1225 //encode_header ((char *)r->pkt->at (6 * 2 + 1), THISNODE->id, r->seqno, r->retry); 1241 //encode_header ((char *)r->pkt->at (6 * 2 + 1), THISNODE->id, r->seqno, r->retry);
1226 } 1242 }
1227 } 1243 }
1228 } 1244 }
1229 else 1245 else
1230 NEXT (r->timeout); 1246 NEXT (r->timeout);
1231 } 1247 }
1232 1248
1233 if (last_sent + send_interval <= NOW)
1234 {
1235 if (!send) 1249 if (!send)
1250 {
1251 // generate a new packet, if wise
1252
1253 if (!established)
1236 { 1254 {
1237 // generate a new packet, if wise 1255 if (vpn->dns_sndpq.empty ())
1238
1239 if (!established)
1240 { 1256 {
1241 if (vpn->dns_sndpq.empty ())
1242 {
1243 send = new dns_snd (this); 1257 send = new dns_snd (this);
1244 1258
1245 printf ("new conn %p %d\n", this, c->conf->id);//D
1246 cfg.reset (THISNODE->id); 1259 cfg.reset (THISNODE->id);
1247 send->gen_syn_req (); 1260 send->gen_syn_req ();
1248 }
1249 } 1261 }
1262 }
1250 else if (vpn->dns_sndpq.size () < MAX_OUTSTANDING 1263 else if (vpn->dns_sndpq.size () < MAX_OUTSTANDING
1251 && !SEQNO_EQ (rcvseq, sndseq - (MAX_WINDOW - 1))) 1264 && !SEQNO_EQ (rcvseq, sndseq - (MAX_WINDOW - 1)))
1265 {
1266 if (last_sent + send_interval <= NOW)
1252 { 1267 {
1253 //printf ("sending data request etc.\n"); //D 1268 //printf ("sending data request etc.\n"); //D
1254 if (!snddq.empty ()) 1269 if (!snddq.empty () || last_received + 1. > NOW)
1255 { 1270 {
1256 poll_interval = send_interval; 1271 poll_interval = send_interval;
1257 NEXT (NOW + send_interval); 1272 NEXT (NOW + send_interval);
1258 } 1273 }
1259 1274
1260 send = new dns_snd (this); 1275 send = new dns_snd (this);
1261 send->gen_stream_req (sndseq, snddq); 1276 send->gen_stream_req (sndseq, snddq);
1262 send->timeout = NOW + last_latency * 8.; 1277 send->timeout = NOW + min_latency * TIMEOUT_FACTOR;
1263 1278
1264 sndseq = (sndseq + 1) & SEQNO_MASK; 1279 sndseq = (sndseq + 1) & SEQNO_MASK;
1265 } 1280 }
1266 1281 else
1267 if (send) 1282 NEXT (last_sent + send_interval);
1268 vpn->dns_sndpq.push_back (send);
1269 } 1283 }
1270 1284
1271 if (send) 1285 if (send)
1272 { 1286 vpn->dns_sndpq.push_back (send);
1287 }
1288
1289 if (send)
1290 {
1273 last_sent = NOW; 1291 last_sent = NOW;
1274 sendto (vpn->dnsv4_fd, 1292 sendto (vpn->dnsv4_fd,
1275 send->pkt->at (0), send->pkt->len, 0, 1293 send->pkt->at (0), send->pkt->len, 0,
1276 vpn->dns_forwarder.sav4 (), vpn->dns_forwarder.salenv4 ()); 1294 vpn->dns_forwarder.sav4 (), vpn->dns_forwarder.salenv4 ());
1277 }
1278 } 1295 }
1279 else
1280 NEXT (last_sent + send_interval);
1281 1296
1282 slog (L_NOISE, "DNS: pi %f si %f N %f (%d:%d)", 1297 slog (L_NOISE, "DNS: pi %f si %f N %f (%d:%d %d)",
1283 poll_interval, send_interval, next - NOW, 1298 poll_interval, send_interval, next - NOW,
1284 vpn->dns_sndpq.size (), snddq.size ()); 1299 vpn->dns_sndpq.size (), snddq.size (),
1300 rcvpq.size ());
1285 1301
1286 // TODO: no idea when this happens, but when next < NOW, we have a problem 1302 // TODO: no idea when this happens, but when next < NOW, we have a problem
1287 if (next < NOW + 0.0001) 1303 if (next < NOW + 0.001)
1288 next = NOW + 0.1; 1304 next = NOW + 0.1;
1289 1305
1290 w.start (next); 1306 w.start (next);
1291} 1307}
1292 1308

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines