From d7caaf4973c8d6abafc3094ae96f2640a1c84ae9 Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Mon, 29 Apr 2013 10:06:22 +0930 Subject: [PATCH] Add length of link record for forward compatibility --- overlay_buffer.c | 9 ++++++++- overlay_buffer.h | 1 + route_link.c | 21 +++++++++++++++++++++ tests/routing | 1 + 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/overlay_buffer.c b/overlay_buffer.c index 06b9a0a1..fab3c890 100644 --- a/overlay_buffer.c +++ b/overlay_buffer.c @@ -282,7 +282,6 @@ int ob_append_rfs(struct overlay_buffer *b,int l) } - /* Functions that read / write data within the existing length limit */ @@ -379,6 +378,14 @@ int ob_set_ui16(struct overlay_buffer *b, int offset, uint16_t v) return 0; } +int ob_set(struct overlay_buffer *b, int ofs, unsigned char byte) +{ + if (test_offset(b, ofs, 1)) + return -1; + b->bytes[ofs] = byte; + return 0; +} + int ob_patch_rfs(struct overlay_buffer *b){ return ob_set_ui16(b,b->var_length_offset,b->position - (b->var_length_offset + 2)); } diff --git a/overlay_buffer.h b/overlay_buffer.h index 17a0af1a..d12da32c 100644 --- a/overlay_buffer.h +++ b/overlay_buffer.h @@ -52,6 +52,7 @@ int ob_rewind(struct overlay_buffer *b); int ob_limitsize(struct overlay_buffer *b,int bytes); int ob_unlimitsize(struct overlay_buffer *b); int ob_makespace(struct overlay_buffer *b,int bytes); +int ob_set(struct overlay_buffer *b, int ofs, unsigned char byte); int ob_append_byte(struct overlay_buffer *b,unsigned char byte); int ob_append_bytes(struct overlay_buffer *b,unsigned char *bytes,int count); int ob_append_buffer(struct overlay_buffer *b,struct overlay_buffer *s); diff --git a/route_link.c b/route_link.c index 1f5fedd3..63ed9238 100644 --- a/route_link.c +++ b/route_link.c @@ -242,6 +242,10 @@ static int append_link_state(struct overlay_buffer *payload, char flags, struct if (!transmitter) flags|=FLAG_NO_PATH; + int length_pos = ob_position(payload); + if (ob_append_byte(payload, 0)) + return -1; + if (ob_append_byte(payload, flags)) return -1; @@ -259,6 +263,14 @@ static int append_link_state(struct overlay_buffer *payload, char flags, struct if (ob_append_byte(payload, interface)) return -1; + // TODO insert future fields here + + + // patch the record length + int end_pos = ob_position(payload); + if (ob_set(payload, length_pos, end_pos - length_pos)) + return -1; + ob_checkpoint(payload); return 0; } @@ -419,6 +431,12 @@ int link_receive(overlay_mdp_frame *mdp) context.invalid_addresses=0; struct subscriber *receiver=NULL, *transmitter=NULL; + + int start_pos = ob_position(payload); + int length = ob_get(payload); + if (length <=0) + break; + int flags = ob_get(payload); if (flags<0) break; @@ -438,6 +456,9 @@ int link_receive(overlay_mdp_frame *mdp) break; } + // jump to the position of the next record, even if there's more data we don't understand + payload->position = start_pos + length; + if (context.invalid_addresses) continue; diff --git a/tests/routing b/tests/routing index a7673a81..f6d566b8 100755 --- a/tests/routing +++ b/tests/routing @@ -43,6 +43,7 @@ start_routing_instance() { set log.console.show_pid on \ set log.console.show_time on \ set debug.mdprequests yes \ + set debug.linkstate yes \ set debug.verbose yes \ set rhizome.enable no start_servald_server