]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
avoid reencoding the same reply in mesh reply.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Fri, 22 Feb 2008 09:23:42 +0000 (09:23 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Fri, 22 Feb 2008 09:23:42 +0000 (09:23 +0000)
git-svn-id: file:///svn/unbound/trunk@981 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
services/mesh.c

index 2b11a32f8982eae9b5007855fcbfb2d0a0aaa337..306ce9ebc5793def5dd4e3d8b0f4128a5d073f6f 100644 (file)
@@ -1,3 +1,7 @@
+22 February 2008: Wouter
+       - +2% for recursions, if identical queries (except for destination
+         and query ID) in the reply list, avoid re-encoding the answer.
+
 21 February 2008: Wouter
        - speedup of root-delegation message encoding by 15%.
        - minor speedup of compress tree_lookup, maybe 1%.
index 595c7f497a18db9fa73112bdab58d77da3c754a9..cef363dc746f35553163f943220c58adb104020b 100644 (file)
@@ -510,10 +510,11 @@ mesh_do_callback(struct mesh_state* m, int rcode, struct reply_info* rep,
  * @param rcode: if not 0, error code.
  * @param rep: reply to send (or NULL if rcode is set).
  * @param r: reply entry
+ * @param prev: previous reply, already has its answer encoded in buffer.
  */
 static void
 mesh_send_reply(struct mesh_state* m, int rcode, struct reply_info* rep,
-       struct mesh_reply* r)
+       struct mesh_reply* r, struct mesh_reply* prev)
 {
        struct timeval end_time;
        struct timeval duration;
@@ -529,7 +530,18 @@ mesh_send_reply(struct mesh_state* m, int rcode, struct reply_info* rep,
        if(!rep && rcode == LDNS_RCODE_NOERROR)
                rcode = LDNS_RCODE_SERVFAIL;
        /* send the reply */
-       if(rcode) {
+       if(prev && prev->qflags == r->qflags && 
+               prev->edns.edns_present == r->edns.edns_present && 
+               prev->edns.bits == r->edns.bits && 
+               prev->edns.udp_size == r->edns.udp_size) {
+               /* if the previous reply is identical to this one, fix ID */
+               if(prev->query_reply.c->buffer != r->query_reply.c->buffer)
+                       ldns_buffer_copy(r->query_reply.c->buffer, 
+                               prev->query_reply.c->buffer);
+               ldns_buffer_write_at(r->query_reply.c->buffer, 0, 
+                       &r->qid, sizeof(uint16_t));
+               comm_point_send_reply(&r->query_reply);
+       } else if(rcode) {
                error_encode(r->query_reply.c->buffer, rcode, &m->s.qinfo,
                        r->qid, r->qflags, &r->edns);
                comm_point_send_reply(&r->query_reply);
@@ -564,11 +576,13 @@ mesh_send_reply(struct mesh_state* m, int rcode, struct reply_info* rep,
 void mesh_query_done(struct mesh_state* mstate)
 {
        struct mesh_reply* r;
+       struct mesh_reply* prev = NULL;
        struct mesh_cb* c;
        struct reply_info* rep = (mstate->s.return_msg?
                mstate->s.return_msg->rep:NULL);
        for(r = mstate->reply_list; r; r = r->next) {
-               mesh_send_reply(mstate, mstate->s.return_rcode, rep, r);
+               mesh_send_reply(mstate, mstate->s.return_rcode, rep, r, prev);
+               prev = r;
        }
        for(c = mstate->cb_list; c; c = c->next) {
                mesh_do_callback(mstate, mstate->s.return_rcode, rep, c);