Contiki 3.x
Functions
A service registration and diseemination hack

This application is a quick'n'dirty hack for registering, disseminating, and looking up services. More...

Functions

void servreg_hack_init (void)
 Initialize and start the servreg-hack application. More...
 
void servreg_hack_register (servreg_hack_id_t service_id, const uip_ipaddr_t *addr)
 Register that this node provides a service. More...
 
servreg_hack_item_t * servreg_hack_list_head (void)
 Obtain the list of services provided by neighbors. More...
 
servreg_hack_id_t servreg_hack_item_id (servreg_hack_item_t *item)
 Get the service ID for a list item. More...
 
uip_ipaddr_t * servreg_hack_item_address (servreg_hack_item_t *item)
 Get the IP address for a list item. More...
 
uip_ipaddr_t * servreg_hack_lookup (servreg_hack_id_t service_id)
 Get the IP address of a node offering a service. More...
 

Detailed Description

This application is a quick'n'dirty hack for registering, disseminating, and looking up services.

A service is identified by an 8-bit integer between 1 and 255. Integers below 128 are reserved for system services.

A service is registered with the function servreg_hack_register(). Registered services will be transmitted to all neighbors that run the servreg-hack application. These will in turn resend the registration to their neighbors.

Services from neighbors are stored in a local table. Services stored in the table can be looked up using a combination of the servreg_hack_list() and servreg_hack_item_match() functions.

Function Documentation

void servreg_hack_init ( void  )

Initialize and start the servreg-hack application.

This function initializes and starts the servreg-hack application and daemon.

Definition at line 119 of file servreg-hack.c.

References list_init(), memb_init(), NULL, and process_start().

Referenced by servreg_hack_lookup(), and servreg_hack_register().

uip_ipaddr_t * servreg_hack_item_address ( servreg_hack_item_t *  item)

Get the IP address for a list item.

Parameters
itemThe list item
Returns
The IP address
        This function is used when iterating through the list
        of registered services.

Definition at line 183 of file servreg-hack.c.

Referenced by servreg_hack_lookup().

servreg_hack_id_t servreg_hack_item_id ( servreg_hack_item_t *  item)

Get the service ID for a list item.

Parameters
itemThe list item
Returns
The service ID for a list item
        This function is used when iterating through the list
        of registered services.

Definition at line 177 of file servreg-hack.c.

Referenced by servreg_hack_lookup(), and servreg_hack_register().

servreg_hack_item_t * servreg_hack_list_head ( void  )

Obtain the list of services provided by neighbors.

Returns
The list of services
        This function returns a list of services registered by
        other nodes. To find a specific service, the caller
        needs to iterate through the list and check each list
        item with the servreg_hack_item_match() function.

Definition at line 170 of file servreg-hack.c.

References list_head().

Referenced by servreg_hack_lookup().

uip_ipaddr_t * servreg_hack_lookup ( servreg_hack_id_t  service_id)

Get the IP address of a node offering a service.

Parameters
service_idThe service ID of the service
Returns
A pointer to the IP address of the node, or NULL if the service was not known
        This function returns the address of the node offering
        a specific service. If the service is not known, the
        function returns NULL. If there are more than one nodes
        offering the service, this function returns the address
        of the node that most recently announced its service.

        To get a list of all nodes offering a specific service,
        use the servreg_hack_list_head() function to get the
        full list of offered services.

Definition at line 189 of file servreg-hack.c.

References list_item_next(), NULL, servreg_hack_init(), servreg_hack_item_address(), servreg_hack_item_id(), and servreg_hack_list_head().

void servreg_hack_register ( servreg_hack_id_t  service_id,
const uip_ipaddr_t *  addr 
)

Register that this node provides a service.

Parameters
service_idThe 8-bit ID for the service
addrThe address associated with the service
        This function is used to register a
        service. Registering a service means that other nodes
        in the network will become aware that this node
        provides this service. The servreg-hack application
        does not specify what this service means, nor does it
        provide any mechanism by which the service can be
        reached: this is up to the application that uses the
        servreg-hack application.

Definition at line 132 of file servreg-hack.c.

References etimer_set(), list_head(), list_item_next(), list_push(), memb_alloc(), NULL, PROCESS_CONTEXT_BEGIN, PROCESS_CONTEXT_END, random_rand(), servreg_hack_init(), servreg_hack_item_id(), timer_set(), and uip_ipaddr_copy.