Added implied lazymode switch with server timeout of 0

This commit is contained in:
frekky 2015-10-04 22:15:56 +08:00
parent 7bc434536c
commit 2e0b7f8eae
2 changed files with 17 additions and 3 deletions

View File

@ -250,7 +250,10 @@ Client sends:
The server response to Ping and Data packets is a DNS NULL/TXT/.. type response, The server response to Ping and Data packets is a DNS NULL/TXT/.. type response,
always starting with the 3 bytes downstream data header as shown above. If R bit always starting with the 3 bytes downstream data header as shown above. If R bit
set, server must respond with a ping downstream header. set, server must respond with a ping downstream header. This also requires the
server to set its windowsizes to the ones provided.
If the T but is set, the server sets the user's DNS timeout to the value spec-
ified by the packet. A timeout value of 0 implies disabling lazy mode.
If server has nothing to send, no data is added after the header. If server has nothing to send, no data is added after the header.
If server has something to send, it will add the downstream data packet If server has something to send, it will add the downstream data packet
(or some fragment of it) after the header. (or some fragment of it) after the header.

View File

@ -262,8 +262,10 @@ qmem_max_wait(struct dnsfd *dns_fds, int *touser, struct query **sendq)
u = &users[userid]; u = &users[userid];
qnum = u->qmem.start_pending; qnum = u->qmem.start_pending;
if (u->qmem.num_pending == 0 || !u->lazy) if (u->qmem.num_pending == 0)
continue; continue;
/* Keep track of how many fragments we can send */ /* Keep track of how many fragments we can send */
total = window_sending(u->outgoing); total = window_sending(u->outgoing);
if (u->qmem.num_pending > u->outgoing->windowsize) { if (u->qmem.num_pending > u->outgoing->windowsize) {
@ -273,6 +275,11 @@ qmem_max_wait(struct dnsfd *dns_fds, int *touser, struct query **sendq)
sending = total; sending = total;
sent = 0; sent = 0;
if (!u->lazy && u->qmem.num_pending > 0) {
QMEM_DEBUG(2, userid, "User switched to immediate mode, answering all pending queries...");
sending = u->qmem.num_pending;
}
for (; qnum != u->qmem.end; qnum = (qnum + 1) % QMEM_LEN) { for (; qnum != u->qmem.end; qnum = (qnum + 1) % QMEM_LEN) {
q = &u->qmem.queries[qnum]; q = &u->qmem.queries[qnum];
@ -1697,8 +1704,12 @@ handle_null_request(int tun_fd, int dns_fd, struct dnsfd *dns_fds, struct query
respond = unpacked[8] & 1; respond = unpacked[8] & 1;
if ((unpacked[8] >> 3) & 1) { if ((unpacked[8] >> 3) & 1) {
/* update user's query timeout */ /* update user's query timeout if timeout flag set */
users[userid].dns_timeout = timeout; users[userid].dns_timeout = timeout;
if (timeout_ms == 0) {
/* immediate mode is implied by server timeout of 0 */
users[userid].lazy = 0;
}
} }
if (debug >= 2) { if (debug >= 2) {