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.27 by pcg, Sat Mar 12 18:10:40 2005 UTC vs.
Revision 1.30 by pcg, Mon Mar 14 17:40:01 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.
52 51
53#define INITIAL_TIMEOUT 0.1 // retry timeouts 52#define INITIAL_TIMEOUT 0.1 // retry timeouts
54#define INITIAL_SYN_TIMEOUT 10. // retry timeout for initial syn 53#define INITIAL_SYN_TIMEOUT 10. // retry timeout for initial syn
55 54
56#define MIN_SEND_INTERVAL 0.01 // wait at least this time between sending requests 55#define MIN_SEND_INTERVAL 0.001 // wait at least this time between sending requests
57#define MAX_SEND_INTERVAL 2. // optimistic? 56#define MAX_SEND_INTERVAL 2. // optimistic?
58 57
59#define LATENCY_FACTOR 0.5 // RTT * LATENCY_FACTOR == sending rate 58#define LATENCY_FACTOR 0.5 // RTT * LATENCY_FACTOR == sending rate
60#define MAX_OUTSTANDING 40 // max. outstanding requests 59#define MAX_OUTSTANDING 2 // max. outstanding requests
61#define MAX_WINDOW 1000 // max. for MAX_OUTSTANDING, and backlog 60#define MAX_WINDOW 1000 // max. for MAX_OUTSTANDING, and backlog
62#define MAX_BACKLOG (100*1024) // size of gvpe protocol backlog (bytes), must be > MAXSIZE 61#define MAX_BACKLOG (100*1024) // size of gvpe protocol backlog (bytes), must be > MAXSIZE
63 62
64#define MAX_DOMAIN_SIZE 200 // 255 is legal limit, but bind doesn't compress well 63#define MAX_DOMAIN_SIZE 240 // 255 is legal limit, but bind doesn't compress well
65// 240 leaves about 4 bytes of server reply data 64// 240 leaves about 4 bytes of server reply data
66// every two request bytes less give room for one reply byte 65// every two request bytes less give room for one reply byte
67 66
68#define SEQNO_MASK 0x3fff 67#define SEQNO_MASK 0x3fff
69#define SEQNO_EQ(a,b) ( 0 == ( ((a) ^ (b)) & SEQNO_MASK) ) 68#define SEQNO_EQ(a,b) ( 0 == ( ((a) ^ (b)) & SEQNO_MASK) )
424 u16 max_size; 423 u16 max_size;
425 u8 seq_cdc; 424 u8 seq_cdc;
426 u8 req_cdc; 425 u8 req_cdc;
427 426
428 u8 rep_cdc; 427 u8 rep_cdc;
428 u8 delay; // time in 0.01s units that the server may delay replying packets
429 u8 r2, r3, r4; 429 u8 r3, r4;
430 430
431 u8 r5, r6, r7, r8; 431 u8 r5, r6, r7, r8;
432 432
433 void reset (int clientid); 433 void reset (int clientid);
434 bool valid (); 434 bool valid ();
452 req_cdc = 62; 452 req_cdc = 62;
453 rep_cdc = 0; 453 rep_cdc = 0;
454 max_size = htons (MAX_PKT_SIZE); 454 max_size = htons (MAX_PKT_SIZE);
455 client = htons (clientid); 455 client = htons (clientid);
456 uid = next_uid++; 456 uid = next_uid++;
457 delay = 0;
457 458
458 r2 = r3 = r4 = 0; 459 r3 = r4 = 0;
459 r4 = r5 = r6 = r7 = 0; 460 r4 = r5 = r6 = r7 = 0;
460} 461}
461 462
462bool dns_cfg::valid () 463bool dns_cfg::valid ()
463{ 464{
729 established = false; 730 established = false;
730 731
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 = 0.5; // starting here
735 send_interval = 0.5; // starting rate 736 send_interval = 0.5; // starting rate
736 min_latency = INITIAL_TIMEOUT; 737 min_latency = INITIAL_TIMEOUT;
737} 738}
738 739
739dns_connection::~dns_connection () 740dns_connection::~dns_connection ()
1238 } 1239 }
1239 else 1240 else
1240 NEXT (r->timeout); 1241 NEXT (r->timeout);
1241 } 1242 }
1242 1243
1243 if (send || (last_sent + send_interval <= NOW))
1244 {
1245 if (!send) 1244 if (!send)
1245 {
1246 // generate a new packet, if wise
1247
1248 if (!established)
1246 { 1249 {
1247 // generate a new packet, if wise 1250 if (vpn->dns_sndpq.empty ())
1248
1249 if (!established)
1250 { 1251 {
1251 if (vpn->dns_sndpq.empty ())
1252 {
1253 send = new dns_snd (this); 1252 send = new dns_snd (this);
1254 1253
1255 cfg.reset (THISNODE->id); 1254 cfg.reset (THISNODE->id);
1256 send->gen_syn_req (); 1255 send->gen_syn_req ();
1257 }
1258 } 1256 }
1257 }
1259 else if (vpn->dns_sndpq.size () < MAX_OUTSTANDING 1258 else if (vpn->dns_sndpq.size () < MAX_OUTSTANDING
1260 && !SEQNO_EQ (rcvseq, sndseq - (MAX_WINDOW - 1))) 1259 && !SEQNO_EQ (rcvseq, sndseq - (MAX_WINDOW - 1)))
1260 {
1261 if (last_sent + send_interval <= NOW)
1261 { 1262 {
1262 //printf ("sending data request etc.\n"); //D 1263 //printf ("sending data request etc.\n"); //D
1263 if (!snddq.empty () || last_received + 1. > NOW) 1264 if (!snddq.empty () || last_received + 1. > NOW)
1264 { 1265 {
1265 poll_interval = send_interval; 1266 poll_interval = send_interval;
1270 send->gen_stream_req (sndseq, snddq); 1271 send->gen_stream_req (sndseq, snddq);
1271 send->timeout = NOW + min_latency * 8.; 1272 send->timeout = NOW + min_latency * 8.;
1272 1273
1273 sndseq = (sndseq + 1) & SEQNO_MASK; 1274 sndseq = (sndseq + 1) & SEQNO_MASK;
1274 } 1275 }
1275 1276 else
1276 if (send && !send->retry) 1277 NEXT (last_sent + send_interval);
1277 vpn->dns_sndpq.push_back (send);
1278 } 1278 }
1279 1279
1280 if (send) 1280 if (send)
1281 { 1281 vpn->dns_sndpq.push_back (send);
1282 }
1283
1284 if (send)
1285 {
1282 last_sent = NOW; 1286 last_sent = NOW;
1283 sendto (vpn->dnsv4_fd, 1287 sendto (vpn->dnsv4_fd,
1284 send->pkt->at (0), send->pkt->len, 0, 1288 send->pkt->at (0), send->pkt->len, 0,
1285 vpn->dns_forwarder.sav4 (), vpn->dns_forwarder.salenv4 ()); 1289 vpn->dns_forwarder.sav4 (), vpn->dns_forwarder.salenv4 ());
1286 }
1287 } 1290 }
1288 else
1289 NEXT (last_sent + send_interval);
1290 1291
1291 slog (L_NOISE, "DNS: pi %f si %f N %f (%d:%d %d)", 1292 slog (L_NOISE, "DNS: pi %f si %f N %f (%d:%d %d)",
1292 poll_interval, send_interval, next - NOW, 1293 poll_interval, send_interval, next - NOW,
1293 vpn->dns_sndpq.size (), snddq.size (), 1294 vpn->dns_sndpq.size (), snddq.size (),
1294 rcvpq.size ()); 1295 rcvpq.size ());
1295 1296
1296 // TODO: no idea when this happens, but when next < NOW, we have a problem 1297 // TODO: no idea when this happens, but when next < NOW, we have a problem
1297 if (next < NOW + 0.0001) 1298 if (next < NOW + 0.001)
1298 next = NOW + 0.1; 1299 next = NOW + 0.1;
1299 1300
1300 w.start (next); 1301 w.start (next);
1301} 1302}
1302 1303

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines