From 31f41d842e65755d4467e6ed3f0f2500f11fe123 Mon Sep 17 00:00:00 2001 From: nvt-se Date: Thu, 8 Oct 2009 16:30:26 +0000 Subject: [PATCH] * decline route discovery requests if we have one in the air * and, by popular demand, switched PRINTF to printf in the debug macro. :-) --- core/net/rime/route-discovery.c | 17 ++++++++++++++--- core/net/rime/route-discovery.h | 6 +++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/core/net/rime/route-discovery.c b/core/net/rime/route-discovery.c index 343d26f09..169ecd26c 100644 --- a/core/net/rime/route-discovery.c +++ b/core/net/rime/route-discovery.c @@ -33,7 +33,7 @@ * * This file is part of the Contiki operating system. * - * $Id: route-discovery.c,v 1.17 2009/05/10 21:10:23 adamdunkels Exp $ + * $Id: route-discovery.c,v 1.18 2009/10/08 16:30:26 nvt-se Exp $ */ /** @@ -72,11 +72,13 @@ struct rrep_hdr { #define DEBUG 0 #if DEBUG #include -#define PRINTF(...) PRINTF(__VA_ARGS__) +#define PRINTF(...) printf(__VA_ARGS__) #else #define PRINTF(...) #endif +/*---------------------------------------------------------------------------*/ +static char rrep_pending; /* A reply for a request is pending. */ /*---------------------------------------------------------------------------*/ static void send_rreq(struct route_discovery_conn *c, const rimeaddr_t *dest) @@ -182,6 +184,7 @@ rrep_packet_received(struct unicast_conn *uc, rimeaddr_t *from) if(rimeaddr_cmp(&msg->dest, &rimeaddr_node_addr)) { PRINTF("rrep for us!\n"); + rrep_pending = 0; ctimer_stop(&c->t); if(c->cb->new_route) { c->cb->new_route(c, &msg->originator); @@ -285,18 +288,26 @@ timeout_handler(void *ptr) { struct route_discovery_conn *c = ptr; PRINTF("route_discovery: timeout, timed out\n"); + rrep_pending = 0; if(c->cb->timedout) { c->cb->timedout(c); } } /*---------------------------------------------------------------------------*/ -void +int route_discovery_discover(struct route_discovery_conn *c, const rimeaddr_t *addr, clock_time_t timeout) { + if(rrep_pending) { + PRINTF("route_discovery_send: ignoring request because of pending response\n"); + return 0; + } + PRINTF("route_discovery_send: sending route request\n"); ctimer_set(&c->t, timeout, timeout_handler, c); + rrep_pending = 1; send_rreq(c, addr); + return 1; } /*---------------------------------------------------------------------------*/ /** @} */ diff --git a/core/net/rime/route-discovery.h b/core/net/rime/route-discovery.h index bb790b0a8..d06fe593c 100644 --- a/core/net/rime/route-discovery.h +++ b/core/net/rime/route-discovery.h @@ -45,7 +45,7 @@ * * This file is part of the Contiki operating system. * - * $Id: route-discovery.h,v 1.8 2009/03/24 07:15:04 adamdunkels Exp $ + * $Id: route-discovery.h,v 1.9 2009/10/08 16:30:26 nvt-se Exp $ */ /** @@ -83,8 +83,8 @@ struct route_discovery_conn { void route_discovery_open(struct route_discovery_conn *c, clock_time_t time, uint16_t channels, const struct route_discovery_callbacks *callbacks); -void route_discovery_discover(struct route_discovery_conn *c, const rimeaddr_t *dest, - clock_time_t timeout); +int route_discovery_discover(struct route_discovery_conn *c, const rimeaddr_t *dest, + clock_time_t timeout); void route_discovery_close(struct route_discovery_conn *c);