To avoid ambiguity, address should be explicitly set by caller, not automatically by the module.

This commit is contained in:
Adam Dunkels 2011-08-29 21:56:49 +02:00
parent 823f28e87c
commit 6699f6a6f6
2 changed files with 31 additions and 32 deletions

View file

@ -86,6 +86,8 @@ PROCESS(servreg_hack_process, "Service regstry hack");
static struct etimer sendtimer; static struct etimer sendtimer;
static uint8_t started = 0;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Go through the list of registrations and remove those that are too /* Go through the list of registrations and remove those that are too
old. */ old. */
@ -117,15 +119,18 @@ purge_registrations(void)
void void
servreg_hack_init(void) servreg_hack_init(void)
{ {
if(started == 0) {
list_init(others_services); list_init(others_services);
list_init(own_services); list_init(own_services);
memb_init(&registrations); memb_init(&registrations);
process_start(&servreg_hack_process, NULL); process_start(&servreg_hack_process, NULL);
started = 1;
}
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
servreg_hack_register(servreg_hack_id_t id) servreg_hack_register(servreg_hack_id_t id, const uip_ipaddr_t *addr)
{ {
servreg_hack_item_t *t; servreg_hack_item_t *t;
struct servreg_hack_registration *r; struct servreg_hack_registration *r;
@ -149,6 +154,7 @@ servreg_hack_register(servreg_hack_id_t id)
} }
r->id = id; r->id = id;
r->seqno = 1; r->seqno = 1;
uip_ipaddr_copy(&r->addr, addr);
timer_set(&r->timer, LIFETIME / 2); timer_set(&r->timer, LIFETIME / 2);
list_push(own_services, r); list_push(own_services, r);
@ -212,8 +218,6 @@ handle_incoming_reg(const uip_ipaddr_t *owner, servreg_hack_id_t id, uint8_t seq
now - we might later choose to discard the oldest registration now - we might later choose to discard the oldest registration
that we have). */ that we have). */
/* printf("Handle incoming reg id %d seqno %d\n", id, seqno);*/
for(t = servreg_hack_list_head(); for(t = servreg_hack_list_head();
t != NULL; t != NULL;
t = list_item_next(t)) { t = list_item_next(t)) {
@ -276,23 +280,18 @@ send_udp_packet(struct uip_udp_conn *conn)
uint8_t buf[MAX_BUFSIZE]; uint8_t buf[MAX_BUFSIZE];
int bufptr; int bufptr;
servreg_hack_item_t *t; servreg_hack_item_t *t;
uip_ds6_addr_t *addr;
addr = uip_ds6_get_global(-1);
buf[MSG_FLAGS_OFFSET] = 0; buf[MSG_FLAGS_OFFSET] = 0;
numregs = 0; numregs = 0;
bufptr = MSG_ADDRS_OFFSET; bufptr = MSG_ADDRS_OFFSET;
if(addr != NULL) {
for(t = list_head(own_services); for(t = list_head(own_services);
(bufptr + MSG_ADDRS_LEN <= MAX_BUFSIZE) && t != NULL; (bufptr + MSG_ADDRS_LEN <= MAX_BUFSIZE) && t != NULL;
t = list_item_next(t)) { t = list_item_next(t)) {
uip_ipaddr_copy((uip_ipaddr_t *)&buf[bufptr + MSG_IPADDR_SUBOFFSET], uip_ipaddr_copy((uip_ipaddr_t *)&buf[bufptr + MSG_IPADDR_SUBOFFSET],
&addr->ipaddr); servreg_hack_item_address(t));
buf[bufptr + MSG_REGS_SUBOFFSET] = buf[bufptr + MSG_REGS_SUBOFFSET] =
servreg_hack_item_id(t); servreg_hack_item_id(t);
buf[bufptr + MSG_REGS_SUBOFFSET + 1] = buf[bufptr + MSG_REGS_SUBOFFSET + 1] =
@ -302,7 +301,6 @@ send_udp_packet(struct uip_udp_conn *conn)
bufptr += MSG_ADDRS_LEN; bufptr += MSG_ADDRS_LEN;
++numregs; ++numregs;
} }
}
for(t = servreg_hack_list_head(); for(t = servreg_hack_list_head();
(bufptr + MSG_ADDRS_LEN <= MAX_BUFSIZE) && t != NULL; (bufptr + MSG_ADDRS_LEN <= MAX_BUFSIZE) && t != NULL;
@ -338,7 +336,7 @@ parse_incoming_packet(const u8_t *buf, int len)
numregs = buf[MSG_NUMREGS_OFFSET]; numregs = buf[MSG_NUMREGS_OFFSET];
flags = buf[MSG_FLAGS_OFFSET]; flags = buf[MSG_FLAGS_OFFSET];
/* printf("Numregs %d flags %d\n", numregs, flags);*/ /* printf("parse_incoming_packet Numregs %d flags %d\n", numregs, flags);*/
bufptr = MSG_ADDRS_OFFSET; bufptr = MSG_ADDRS_OFFSET;
for(i = 0; i < numregs; ++i) { for(i = 0; i < numregs; ++i) {

View file

@ -81,6 +81,7 @@ void servreg_hack_init(void);
/** /**
* \brief Register that this node provides a service * \brief Register that this node provides a service
* \param service_id The 8-bit ID for the service * \param service_id The 8-bit ID for the service
* \param addr The address associated with the service
* *
* This function is used to register a * This function is used to register a
* service. Registering a service means that other nodes * service. Registering a service means that other nodes
@ -91,7 +92,7 @@ void servreg_hack_init(void);
* reached: this is up to the application that uses the * reached: this is up to the application that uses the
* servreg-hack application. * servreg-hack application.
*/ */
void servreg_hack_register(servreg_hack_id_t service_id); void servreg_hack_register(servreg_hack_id_t service_id, const uip_ipaddr_t *addr);
/** /**