From: Wouter Wijngaards Date: Fri, 22 Feb 2008 09:23:42 +0000 (+0000) Subject: avoid reencoding the same reply in mesh reply. X-Git-Tag: release-0.10~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc7d3dc192a704e266a0dc4422fef3c74c4c6865;p=thirdparty%2Funbound.git avoid reencoding the same reply in mesh reply. git-svn-id: file:///svn/unbound/trunk@981 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/doc/Changelog b/doc/Changelog index 2b11a32f8..306ce9ebc 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -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%. diff --git a/services/mesh.c b/services/mesh.c index 595c7f497..cef363dc7 100644 --- a/services/mesh.c +++ b/services/mesh.c @@ -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);