Skip to content

Commit

Permalink
Respond to multiple identical queries
Browse files Browse the repository at this point in the history
  • Loading branch information
jedisct1 committed Jan 5, 2015
1 parent 52e4c67 commit ca2ad7a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions udp_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ static int udp_request_cmp(const UDPRequest *r1, const UDPRequest *r2) {
return -1;
} else if (r1->id > r2->id) {
return 1;
} else if (r1->gen < r2->gen) {
return -1;
} else if (r1->gen > r2->gen) {
return 1;
}
return 0;
}
Expand Down Expand Up @@ -367,8 +371,10 @@ client_to_proxy_cb(evutil_socket_t client_proxy_handle, short ev_flags,
udp_request_kill(udp_request);
}

c->connections++;
static uint16_t gen;
udp_request->gen = gen++;
udp_request->status.is_in_queue = 1;
c->connections++;
RB_INSERT(UDPRequestQueue_, &c->udp_request_queue, udp_request);

udp_request->timeout_timer =
Expand Down Expand Up @@ -402,8 +408,13 @@ lookup_request(struct context *c, uint16_t id, uint64_t hash)

scanned_udp_request.hash = hash;
scanned_udp_request.id = id;
found_udp_request = RB_FIND(UDPRequestQueue_, &c->udp_request_queue,
&scanned_udp_request);
scanned_udp_request.gen = (uint16_t) 0U;
found_udp_request = RB_NFIND(UDPRequestQueue_, &c->udp_request_queue,
&scanned_udp_request);
if (found_udp_request == NULL ||
found_udp_request->hash != hash || found_udp_request->id != id) {
return NULL;
}
return found_udp_request;
}

Expand Down
1 change: 1 addition & 0 deletions udp_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ typedef struct UDPRequest_ {
struct event *timeout_timer;
uint64_t hash;
uint16_t id;
uint16_t gen;
uint8_t client_nonce[crypto_box_HALF_NONCEBYTES];
uint8_t nmkey[crypto_box_BEFORENMBYTES];
struct sockaddr_storage client_sockaddr;
Expand Down

0 comments on commit ca2ad7a

Please sign in to comment.