Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5619C200CBE for ; Fri, 7 Jul 2017 22:39:42 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 54D46169F32; Fri, 7 Jul 2017 20:39:42 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 195AA169F33 for ; Fri, 7 Jul 2017 22:39:40 +0200 (CEST) Received: (qmail 85916 invoked by uid 500); 7 Jul 2017 20:39:40 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 85587 invoked by uid 99); 7 Jul 2017 20:39:39 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Jul 2017 20:39:39 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A6650F5514; Fri, 7 Jul 2017 20:39:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: chug@apache.org To: commits@qpid.apache.org Date: Fri, 07 Jul 2017 20:39:51 -0000 Message-Id: <47f8916f24684c68acaeac22b95728bb@git.apache.org> In-Reply-To: <8419f7183d5f4814a663ea2e2c28b26e@git.apache.org> References: <8419f7183d5f4814a663ea2e2c28b26e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [14/14] qpid-dispatch git commit: DISPATCH-760: Change magic numbers into formal constants archived-at: Fri, 07 Jul 2017 20:39:42 -0000 DISPATCH-760: Change magic numbers into formal constants Router message annotation uses some of map keys and will at most use QD_MA_N_KEYS annotation entries. The longest key strlen is QD_MA_MAX_KEY_LEN bytes. Router message annotation keys are at the end of the annotation section. Code uses a sliding window to avoid searching each key for the router prefix that indicates a router annotation. The size of the sliding filter is QD_MA_FILTER_LEN map entries. When QD_MA_FILTER_LEN is larger than QD_MA_N_KEYS then the extra space may hold a future router version's new keys and successfully strip them from the input stream. Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/50637b77 Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/50637b77 Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/50637b77 Branch: refs/heads/master Commit: 50637b770400e106bfb1c2e2ad7c57f8f8b2321e Parents: 9672b71 Author: Chuck Rolke Authored: Thu Jul 6 16:14:35 2017 -0400 Committer: Chuck Rolke Committed: Fri Jul 7 10:39:23 2017 -0400 ---------------------------------------------------------------------- include/qpid/dispatch/amqp.h | 4 +++- src/amqp.c | 4 +++- src/message.c | 5 +---- src/parse.c | 8 +++----- tests/message_test.c | 4 ++-- 5 files changed, 12 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/50637b77/include/qpid/dispatch/amqp.h ---------------------------------------------------------------------- diff --git a/include/qpid/dispatch/amqp.h b/include/qpid/dispatch/amqp.h index 2de270c..393cf57 100644 --- a/include/qpid/dispatch/amqp.h +++ b/include/qpid/dispatch/amqp.h @@ -112,7 +112,9 @@ extern const char * const QD_MA_TRACE; ///< Trace extern const char * const QD_MA_TO; ///< To-Override extern const char * const QD_MA_PHASE; ///< Phase for override address extern const char * const QD_MA_CLASS; ///< Message-Class -extern const int QD_MA_MAX_KEY; ///< strlen of longest key name +extern const int QD_MA_MAX_KEY_LEN; ///< strlen of longest key name +extern const int QD_MA_N_KEYS; ///< number of router annotation keys +extern const int QD_MA_FILTER_LEN; ///< size of annotation filter buffer /// @} /** @name Container Capabilities */ http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/50637b77/src/amqp.c ---------------------------------------------------------------------- diff --git a/src/amqp.c b/src/amqp.c index 673d7b0..fcad53a 100644 --- a/src/amqp.c +++ b/src/amqp.c @@ -28,7 +28,9 @@ const char * const QD_MA_TRACE = "x-opt-qd.trace"; const char * const QD_MA_TO = "x-opt-qd.to"; const char * const QD_MA_PHASE = "x-opt-qd.phase"; const char * const QD_MA_CLASS = "x-opt-qd.class"; -const int QD_MA_MAX_KEY = 16; +const int QD_MA_MAX_KEY_LEN = 16; +const int QD_MA_N_KEYS = 4; // max number of router annotations to send/receive +const int QD_MA_FILTER_LEN = 5; // N tailing inbound entries to search for stripping const char * const QD_CAPABILITY_ROUTER_CONTROL = "qd.router"; const char * const QD_CAPABILITY_ROUTER_DATA = "qd.router-data"; http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/50637b77/src/message.c ---------------------------------------------------------------------- diff --git a/src/message.c b/src/message.c index c46419b..434857b 100644 --- a/src/message.c +++ b/src/message.c @@ -954,9 +954,6 @@ void qd_message_message_annotations(qd_message_t *in_msg) cf->offset = uab->cursor - qd_buffer_base(uab->buffer); cf->length = uab->remaining; cf->parsed = true; - if (content->ma_count > 4) { - //fprintf(stdout, "V2_DEV set ma_count to %d, len=%d\n", content->ma_count, (int)cf->length); - } } // extract phase @@ -1170,7 +1167,7 @@ static void compose_message_annotations_v1(qd_message_pvt_t *msg, qd_buffer_list field_count++; } // pad out to N fields - for (; field_count < 4; field_count++) { + for (; field_count < QD_MA_N_KEYS; field_count++) { qd_compose_insert_symbol(field, QD_MA_PREFIX); qd_compose_insert_string(field, "X"); } http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/50637b77/src/parse.c ---------------------------------------------------------------------- diff --git a/src/parse.c b/src/parse.c index 6072e15..fc67f3d 100644 --- a/src/parse.c +++ b/src/parse.c @@ -199,14 +199,12 @@ const char *qd_parse_turbo(qd_iterator_t *iter, if (count == 0) return 0; - // with four router annotations there will be 8 annos (4 key,val pairs) returned at most -#define MAX_ALLOCS 8 int n_allocs = 0; // Do skeletal parse of each map element for (uint32_t idx = 0; idx < count; idx++) { qd_parsed_turbo_t *turbo; - if (n_allocs < MAX_ALLOCS) { + if (n_allocs < QD_MA_FILTER_LEN * 2) { turbo = new_qd_parsed_turbo_t(); n_allocs++; @@ -638,8 +636,8 @@ const char *qd_parse_annotations_v1( assert(val_field); // Hoist the key name out of the buffers into a normal char array - char key_name[QD_MA_MAX_KEY + 1]; - (void)qd_iterator_strncpy(iter, key_name, QD_MA_MAX_KEY + 1); + char key_name[QD_MA_MAX_KEY_LEN + 1]; + (void)qd_iterator_strncpy(iter, key_name, QD_MA_MAX_KEY_LEN + 1); // transfer ownership of the extracted value to the message if (!strcmp(key_name, QD_MA_TRACE)) { http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/50637b77/tests/message_test.c ---------------------------------------------------------------------- diff --git a/tests/message_test.c b/tests/message_test.c index 0bc8452..116e304 100644 --- a/tests/message_test.c +++ b/tests/message_test.c @@ -272,9 +272,9 @@ static char* test_send_message_annotations(void *context) pn_data_rewind(ma); pn_data_next(ma); if (pn_data_type(ma) != PN_MAP) return "Invalid message annotation type"; - if (pn_data_get_map(ma) != 8) return "Invalid map length"; + if (pn_data_get_map(ma) != QD_MA_N_KEYS * 2) return "Invalid map length"; pn_data_enter(ma); - for (int i = 0; i < 8; i+=2) { + for (int i = 0; i < QD_MA_N_KEYS; i++) { pn_data_next(ma); if (pn_data_type(ma) != PN_SYMBOL) return "Bad map index"; pn_bytes_t sym = pn_data_get_symbol(ma); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org For additional commands, e-mail: commits-help@qpid.apache.org