* decline route discovery requests if we have one in the air

* and, by popular demand, switched PRINTF to printf in the debug macro. :-)
This commit is contained in:
nvt-se 2009-10-08 16:30:26 +00:00
parent 92eecd3e38
commit 31f41d842e
2 changed files with 17 additions and 6 deletions

View File

@ -33,7 +33,7 @@
* *
* This file is part of the Contiki operating system. * 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 #define DEBUG 0
#if DEBUG #if DEBUG
#include <stdio.h> #include <stdio.h>
#define PRINTF(...) PRINTF(__VA_ARGS__) #define PRINTF(...) printf(__VA_ARGS__)
#else #else
#define PRINTF(...) #define PRINTF(...)
#endif #endif
/*---------------------------------------------------------------------------*/
static char rrep_pending; /* A reply for a request is pending. */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
send_rreq(struct route_discovery_conn *c, const rimeaddr_t *dest) 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)) { if(rimeaddr_cmp(&msg->dest, &rimeaddr_node_addr)) {
PRINTF("rrep for us!\n"); PRINTF("rrep for us!\n");
rrep_pending = 0;
ctimer_stop(&c->t); ctimer_stop(&c->t);
if(c->cb->new_route) { if(c->cb->new_route) {
c->cb->new_route(c, &msg->originator); c->cb->new_route(c, &msg->originator);
@ -285,18 +288,26 @@ timeout_handler(void *ptr)
{ {
struct route_discovery_conn *c = ptr; struct route_discovery_conn *c = ptr;
PRINTF("route_discovery: timeout, timed out\n"); PRINTF("route_discovery: timeout, timed out\n");
rrep_pending = 0;
if(c->cb->timedout) { if(c->cb->timedout) {
c->cb->timedout(c); c->cb->timedout(c);
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void int
route_discovery_discover(struct route_discovery_conn *c, const rimeaddr_t *addr, route_discovery_discover(struct route_discovery_conn *c, const rimeaddr_t *addr,
clock_time_t timeout) 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"); PRINTF("route_discovery_send: sending route request\n");
ctimer_set(&c->t, timeout, timeout_handler, c); ctimer_set(&c->t, timeout, timeout_handler, c);
rrep_pending = 1;
send_rreq(c, addr); send_rreq(c, addr);
return 1;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** @} */ /** @} */

View File

@ -45,7 +45,7 @@
* *
* This file is part of the Contiki operating system. * 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, void route_discovery_open(struct route_discovery_conn *c, clock_time_t time,
uint16_t channels, uint16_t channels,
const struct route_discovery_callbacks *callbacks); const struct route_discovery_callbacks *callbacks);
void route_discovery_discover(struct route_discovery_conn *c, const rimeaddr_t *dest, int route_discovery_discover(struct route_discovery_conn *c, const rimeaddr_t *dest,
clock_time_t timeout); clock_time_t timeout);
void route_discovery_close(struct route_discovery_conn *c); void route_discovery_close(struct route_discovery_conn *c);