… | |
… | |
47 | #include "vpn.h" |
47 | #include "vpn.h" |
48 | |
48 | |
49 | #define MAX_POLL_INTERVAL 5. // 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 |
50 | #define ACTIVITY_INTERVAL 5. |
50 | #define ACTIVITY_INTERVAL 5. |
51 | |
51 | |
52 | #define TIMEOUT_FACTOR 2. |
|
|
53 | |
|
|
54 | #define INITIAL_TIMEOUT 0.1 // retry timeouts |
52 | #define INITIAL_TIMEOUT 0.1 // retry timeouts |
55 | #define INITIAL_SYN_TIMEOUT 10. // retry timeout for initial syn |
53 | #define INITIAL_SYN_TIMEOUT 2. // retry timeout for initial syn |
56 | |
54 | |
57 | #define MIN_SEND_INTERVAL 0.001 // wait at least this time between sending requests |
|
|
58 | #define MAX_SEND_INTERVAL 2. // optimistic? |
55 | #define MAX_SEND_INTERVAL 2. // optimistic? |
59 | |
56 | |
60 | #define LATENCY_FACTOR 0.5 // RTT * LATENCY_FACTOR == sending rate |
|
|
61 | #define MAX_OUTSTANDING 100 // max. outstanding requests |
|
|
62 | #define MAX_WINDOW 1000 // max. for MAX_OUTSTANDING, and backlog |
57 | #define MAX_WINDOW 1000 // max. for MAX_OUTSTANDING, and backlog |
63 | #define MAX_BACKLOG (32*1024) // size of gvpe protocol backlog (bytes), must be > MAXSIZE |
58 | #define MAX_BACKLOG (64*1024) // size of gvpe protocol backlog (bytes), must be > MAXSIZE |
64 | |
59 | |
65 | #define MAX_DOMAIN_SIZE 240 // 255 is legal limit, but bind doesn't compress well |
60 | #define MAX_DOMAIN_SIZE 240 // 255 is legal limit, but bind doesn't compress well |
66 | // 240 leaves about 4 bytes of server reply data |
61 | // 240 leaves about 4 bytes of server reply data |
67 | // every two request bytes less give room for one reply byte |
62 | // every request byte less give room for two reply bytes |
68 | |
63 | |
69 | #define SEQNO_MASK 0x0fff |
64 | #define SEQNO_MASK 0x3fff |
70 | #define SEQNO_EQ(a,b) ( 0 == ( ((a) ^ (b)) & SEQNO_MASK) ) |
65 | #define SEQNO_EQ(a,b) ( 0 == ( ((a) ^ (b)) & SEQNO_MASK) ) |
71 | |
66 | |
72 | #define MAX_LBL_SIZE 63 |
67 | #define MAX_LBL_SIZE 63 |
73 | #define MAX_PKT_SIZE 512 |
68 | #define MAX_PKT_SIZE 512 |
74 | |
69 | |
… | |
… | |
793 | } |
788 | } |
794 | |
789 | |
795 | while (vpn_packet *pkt = rcvdq.get ()) |
790 | while (vpn_packet *pkt = rcvdq.get ()) |
796 | { |
791 | { |
797 | sockinfo si; |
792 | sockinfo si; |
798 | si.host = 0x01010101; si.port = htons (c->conf->id); si.prot = PROT_DNSv4; |
793 | si.host = htonl (c->conf->id); si.port = 0; si.prot = PROT_DNSv4; |
799 | |
794 | |
800 | vpn->recv_vpn_packet (pkt, si); |
795 | vpn->recv_vpn_packet (pkt, si); |
801 | |
796 | |
802 | delete pkt; |
797 | delete pkt; |
803 | } |
798 | } |
… | |
… | |
1033 | double latency = NOW - (*i)->sent; |
1028 | double latency = NOW - (*i)->sent; |
1034 | |
1029 | |
1035 | if (latency < dns->min_latency) |
1030 | if (latency < dns->min_latency) |
1036 | dns->min_latency = latency; |
1031 | dns->min_latency = latency; |
1037 | |
1032 | |
1038 | if (dns->send_interval > dns->min_latency * LATENCY_FACTOR) |
1033 | if (dns->send_interval > dns->min_latency * conf.dns_overlap_factor) |
1039 | dns->send_interval = dns->min_latency * LATENCY_FACTOR; |
1034 | dns->send_interval = dns->min_latency * conf.dns_overlap_factor; |
1040 | |
1035 | |
1041 | if (dns->send_interval < MIN_SEND_INTERVAL) |
1036 | if (dns->send_interval < conf.dns_send_interval) |
1042 | dns->send_interval = MIN_SEND_INTERVAL; |
1037 | dns->send_interval = conf.dns_send_interval; |
1043 | } |
1038 | } |
1044 | |
1039 | |
1045 | delete *i; |
1040 | delete *i; |
1046 | dns_sndpq.erase (i); |
1041 | dns_sndpq.erase (i); |
1047 | |
1042 | |
… | |
… | |
1180 | } |
1175 | } |
1181 | |
1176 | |
1182 | bool |
1177 | bool |
1183 | vpn::send_dnsv4_packet (vpn_packet *pkt, const sockinfo &si, int tos) |
1178 | vpn::send_dnsv4_packet (vpn_packet *pkt, const sockinfo &si, int tos) |
1184 | { |
1179 | { |
1185 | int client = ntohs (si.port); |
1180 | int client = ntohl (si.host); |
1186 | |
1181 | |
1187 | assert (0 < client && client <= conns.size ()); |
1182 | assert (0 < client && client <= conns.size ()); |
1188 | |
1183 | |
1189 | connection *c = conns [client - 1]; |
1184 | connection *c = conns [client - 1]; |
1190 | |
1185 | |
… | |
… | |
1228 | if (!send) |
1223 | if (!send) |
1229 | { |
1224 | { |
1230 | send = r; |
1225 | send = r; |
1231 | |
1226 | |
1232 | r->retry++; |
1227 | r->retry++; |
1233 | r->timeout = NOW + (r->retry * min_latency * TIMEOUT_FACTOR); |
1228 | r->timeout = NOW + (r->retry * min_latency * conf.dns_timeout_factor); |
1234 | |
1229 | |
1235 | // the following code changes the query section a bit, forcing |
1230 | // the following code changes the query section a bit, forcing |
1236 | // the forwarder to generate a new request |
1231 | // the forwarder to generate a new request |
1237 | if (r->stdhdr) |
1232 | if (r->stdhdr) |
1238 | { |
1233 | { |
… | |
… | |
1257 | |
1252 | |
1258 | cfg.reset (THISNODE->id); |
1253 | cfg.reset (THISNODE->id); |
1259 | send->gen_syn_req (); |
1254 | send->gen_syn_req (); |
1260 | } |
1255 | } |
1261 | } |
1256 | } |
1262 | else if (vpn->dns_sndpq.size () < MAX_OUTSTANDING |
1257 | else if (vpn->dns_sndpq.size () < conf.dns_max_outstanding |
1263 | && !SEQNO_EQ (rcvseq, sndseq - (MAX_WINDOW - 1))) |
1258 | && !SEQNO_EQ (rcvseq, sndseq - (MAX_WINDOW - 1))) |
1264 | { |
1259 | { |
1265 | if (last_sent + send_interval <= NOW) |
1260 | if (last_sent + send_interval <= NOW) |
1266 | { |
1261 | { |
1267 | //printf ("sending data request etc.\n"); //D |
1262 | //printf ("sending data request etc.\n"); //D |
… | |
… | |
1271 | NEXT (NOW + send_interval); |
1266 | NEXT (NOW + send_interval); |
1272 | } |
1267 | } |
1273 | |
1268 | |
1274 | send = new dns_snd (this); |
1269 | send = new dns_snd (this); |
1275 | send->gen_stream_req (sndseq, snddq); |
1270 | send->gen_stream_req (sndseq, snddq); |
1276 | send->timeout = NOW + min_latency * TIMEOUT_FACTOR; |
1271 | send->timeout = NOW + min_latency * conf.dns_timeout_factor; |
1277 | |
1272 | |
1278 | sndseq = (sndseq + 1) & SEQNO_MASK; |
1273 | sndseq = (sndseq + 1) & SEQNO_MASK; |
1279 | } |
1274 | } |
1280 | else |
1275 | else |
1281 | NEXT (last_sent + send_interval); |
1276 | NEXT (last_sent + send_interval); |
… | |
… | |
1286 | } |
1281 | } |
1287 | |
1282 | |
1288 | if (send) |
1283 | if (send) |
1289 | { |
1284 | { |
1290 | last_sent = NOW; |
1285 | last_sent = NOW; |
1291 | if (rand () & 15 != 0)//D |
|
|
1292 | sendto (vpn->dnsv4_fd, |
1286 | sendto (vpn->dnsv4_fd, |
1293 | send->pkt->at (0), send->pkt->len, 0, |
1287 | send->pkt->at (0), send->pkt->len, 0, |
1294 | vpn->dns_forwarder.sav4 (), vpn->dns_forwarder.salenv4 ()); |
1288 | vpn->dns_forwarder.sav4 (), vpn->dns_forwarder.salenv4 ()); |
1295 | } |
1289 | } |
1296 | |
1290 | |
… | |
… | |
1298 | poll_interval, send_interval, next - NOW, |
1292 | poll_interval, send_interval, next - NOW, |
1299 | vpn->dns_sndpq.size (), snddq.size (), |
1293 | vpn->dns_sndpq.size (), snddq.size (), |
1300 | rcvpq.size ()); |
1294 | rcvpq.size ()); |
1301 | |
1295 | |
1302 | // TODO: no idea when this happens, but when next < NOW, we have a problem |
1296 | // TODO: no idea when this happens, but when next < NOW, we have a problem |
|
|
1297 | // doesn't seem to happen anymore |
1303 | if (next < NOW + 0.001) |
1298 | if (next < NOW + 0.001) |
1304 | next = NOW + 0.1; |
1299 | next = NOW + 0.1; |
1305 | |
1300 | |
1306 | w.start (next); |
1301 | w.start (next); |
1307 | } |
1302 | } |