You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ch...@apache.org on 2017/07/07 20:39:51 UTC
[14/14] qpid-dispatch git commit: DISPATCH-760: Change magic numbers
into formal constants
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 <cr...@redhat.com>
Authored: Thu Jul 6 16:14:35 2017 -0400
Committer: Chuck Rolke <cr...@redhat.com>
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