1
0
Fork 0
mirror of https://github.com/yarrick/iodine.git synced 2025-04-04 05:43:33 +03:00

Fixed client upenctest

This commit is contained in:
frekky 2016-12-09 08:33:09 +08:00
parent dbe9a10fc1
commit 192b73cf68
2 changed files with 22 additions and 11 deletions

View file

@ -1303,9 +1303,10 @@ client_tunnel()
if (this.conn == CONN_DNS_NULL) {
fprintf(stderr, " Frags resent: %4u, OOS: %4u down frag: %4" L "d ms\n",
this.outbuf->resends, this.inbuf->oos, this.downstream_timeout_ms);
fprintf(stderr, " TX fragments: %8" L "u" ", RX: %8" L "u" ", pings: %8" L "u" "\n\n",
fprintf(stderr, " TX fragments: %8" L "u" ", RX: %8" L "u" ", pings: %8" L "u" "\n",
this.num_frags_sent, this.num_frags_recv, this.num_pings);
}
fprintf(stderr, " Pending frags: %4" L "u\n", this.outbuf->numitems);
/* update since-last-report this.stats */
sent_since_report = this.num_sent;
recv_since_report = this.num_recv;
@ -1402,7 +1403,7 @@ send_upenctest(char *s)
/* NOTE: String may be at most 63-4=59 chars to fit in 1 dns chunk. */
{
char buf[512] = "zCMC";
size_t buf_space = 10;
size_t buf_space = 3;
uint32_t cmc = rand();
b32->encode((uint8_t *)buf + 1, &buf_space, (uint8_t *) &cmc, 4);

View file

@ -119,6 +119,12 @@ qmem_init(int userid)
}
}
static size_t
qmem_num_pending(int userid)
{
return users[userid].qmem.num_pending;
}
static int
qmem_is_cached(int dns_fd, int userid, struct query *q)
/* Check if an answer for a particular query is cached in qmem
@ -172,10 +178,11 @@ qmem_append(int userid, struct query *q)
buf = &users[userid].qmem;
if (buf->num_pending >= QMEM_LEN) {
/* this means we have QMEM_LEN *pending* queries; overwrite oldest one
* to prevent buildup of ancient queries */
/* this means we have QMEM_LEN *pending* queries; respond to oldest
* one to make space for new query */
QMEM_DEBUG(2, userid, "Full of pending queries! Replacing old query %d with new %d.",
buf->queries[buf->start].q.id, q->id);
send_data_or_ping(userid, &buf->queries[buf->start], 0, 0, NULL);
}
if (buf->length < QMEM_LEN) {
@ -187,7 +194,7 @@ qmem_append(int userid, struct query *q)
QMEM_DEBUG(5, userid, "add query ID %d, timeout %" L "u ms", q->id, timeval_to_ms(&users[userid].dns_timeout));
/* Copy query into buffer */
/* Copy query into end of buffer */
memcpy(&buf->queries[buf->end].q, q, sizeof(struct query));
#ifdef USE_DNSCACHE
buf->queries[buf->end].a.len = 0;
@ -432,7 +439,7 @@ send_data_or_ping(int userid, struct query *q, int ping, int immediate, char *tc
/* Sends current fragment to user, or a ping if no data available.
ping: 1=force send ping (even if data available), 0=only send if no data.
immediate: 1=not from qmem (ie. fresh query), 0=query is from qmem
disconnect: whether to tell user that TCP socket is closed (NULL if OK or pointer to error message) */
tcperror: whether to tell user that TCP socket is closed (NULL if OK or pointer to error message) */
{
uint8_t pkt[MAX_FRAGSIZE + DOWNSTREAM_PING_HDR];
size_t datalen, headerlen;
@ -462,7 +469,7 @@ send_data_or_ping(int userid, struct query *q, int ping, int immediate, char *tc
/* Build downstream data/ping header (see doc/proto_xxxxxxxx.txt) for details */
if (!f) {
/* No data, may as well send data/ping header (with extra info) */
/* No data, send data/ping header (with extra info) */
ping = 1;
datalen = 0;
pkt[0] = 0; /* Pings don't need seq IDs unless they have data */
@ -477,10 +484,12 @@ send_data_or_ping(int userid, struct query *q, int ping, int immediate, char *tc
headerlen = DOWNSTREAM_HDR;
}
/* If this is being responded to immediately (ie. not from qmem) */
/* If this is being responded to immediately (ie. not from qmem)
* This flag is used by client to calculate stats */
pkt[2] |= (immediate & 1) << 5;
if (tcperror)
if (tcperror) {
pkt[2] |= (1 << 6);
}
if (ping) {
/* set ping flag and build extra header */
@ -494,11 +503,12 @@ send_data_or_ping(int userid, struct query *q, int ping, int immediate, char *tc
if (datalen + headerlen > sizeof(pkt)) {
/* Should never happen, or at least user should be warned about
* fragsize > MAX_FRAGLEN earlier on */
warnx("send_frag_or_dataless: fragment too large to send! (%" L "u)", datalen);
warnx("send_data_or_ping: fragment too large to send! (%" L "u)", datalen);
return;
}
if (f)
if (f) {
memcpy(pkt + headerlen, f->data, datalen);
}
write_dns(get_dns_fd(&server.dns_fds, &q->from), q, (char *)pkt,
datalen + headerlen, users[userid].downenc);