Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
A service registration and diseemination hack

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.

Data Structures

struct  servreg_hack_registration
 

Files

file  servreg-hack.c
 
    Implementation of the servreg-hack application

 
file  servreg-hack.h
 
    Header file for the servreg-hack application

 

Macros

#define LIFETIME   10 * 60 * CLOCK_SECOND
 
#define MAX_BUFSIZE   2 + 80
 
#define MAX_REGISTRATIONS   16
 
#define MSG_ADDRS_LEN   20
 
#define MSG_ADDRS_OFFSET   2
 
#define MSG_FLAGS_OFFSET   1
 
#define MSG_IPADDR_SUBOFFSET   0
 
#define MSG_NUMREGS_OFFSET   0
 
#define MSG_REGS_SUBOFFSET   16
 
#define MSG_SEQNO_SUBOFFSET   19
 
#define NEW_REG_TIME   10 * CLOCK_SECOND
 
#define PERIOD_TIME   40 * CLOCK_SECOND
 
#define SEQNO_LT(a, b)   ((signed char)((a) - (b)) < 0)
 
#define UDP_PORT   61616
 

Typedefs

typedef uint8_t servreg_hack_id_t
 
typedef void servreg_hack_item_t
 

Functions

static void handle_incoming_reg (const uip_ipaddr_t *owner, servreg_hack_id_t id, uint8_t seqno)
 
 LIST (others_services)
 
 LIST (own_services)
 
 MEMB (registrations, struct servreg_hack_registration, MAX_REGISTRATIONS)
 
static void parse_incoming_packet (const uint8_t *buf, int len)
 
 PROCESS (servreg_hack_process,"Service regstry hack")
 
 PROCESS_THREAD (servreg_hack_process, ev, data)
 
static void purge_registrations (void)
 
static void send_udp_packet (struct uip_udp_conn *conn)
 
void servreg_hack_init (void)
 Initialize and start the servreg-hack application. More...
 
uip_ipaddr_tservreg_hack_item_address (servreg_hack_item_t *item)
 Get the IP address for a list item. More...
 
servreg_hack_id_t servreg_hack_item_id (servreg_hack_item_t *item)
 Get the service ID for a list item. More...
 
servreg_hack_item_tservreg_hack_list_head (void)
 Obtain the list of services provided by neighbors. More...
 
uip_ipaddr_tservreg_hack_lookup (servreg_hack_id_t service_id)
 Get the IP address of a node offering a service. More...
 
void servreg_hack_register (servreg_hack_id_t service_id, const uip_ipaddr_t *addr)
 Register that this node provides a service. More...
 

Variables

uip_ipaddr_t servreg_hack_registration::addr
 
servreg_hack_id_t servreg_hack_registration::id
 
struct servreg_hack_registrationservreg_hack_registration::next
 
static struct etimer sendtimer
 
uint8_t servreg_hack_registration::seqno
 
static uint8_t started = 0
 
struct timer servreg_hack_registration::timer
 

#define LIFETIME   10 * 60 * CLOCK_SECOND
#define MAX_BUFSIZE   2 + 80

Referenced by send_udp_packet().

#define MAX_REGISTRATIONS   16
#define MSG_ADDRS_LEN   20

Referenced by send_udp_packet().

#define MSG_ADDRS_OFFSET   2
#define MSG_FLAGS_OFFSET   1
#define MSG_IPADDR_SUBOFFSET   0
#define MSG_NUMREGS_OFFSET   0
#define MSG_REGS_SUBOFFSET   16
#define MSG_SEQNO_SUBOFFSET   19
#define NEW_REG_TIME   10 * CLOCK_SECOND

Referenced by servreg_hack_register().

#define PERIOD_TIME   40 * CLOCK_SECOND

Referenced by PROCESS_THREAD().

#define SEQNO_LT (   a,
 
)    ((signed char)((a) - (b)) < 0)

Referenced by handle_incoming_reg().

#define UDP_PORT   61616

Referenced by PROCESS_THREAD().

typedef uint8_t servreg_hack_id_t
typedef void servreg_hack_item_t

LIST ( others_services  )
LIST ( own_services  )
MEMB ( registrations  ,
struct servreg_hack_registration  ,
MAX_REGISTRATIONS   
)
static void parse_incoming_packet ( const uint8_t *  buf,
int  len 
)
static
PROCESS ( servreg_hack_process  ,
"Service regstry hack"   
)
void servreg_hack_init ( void  )

Initialize and start the servreg-hack application.

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

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

Referenced by PROCESS_THREAD(), 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.

Referenced by send_udp_packet(), and 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.

Referenced by handle_incoming_reg(), send_udp_packet(), 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.

References list_head(), and purge_registrations().

Referenced by handle_incoming_reg(), send_udp_packet(), and 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.

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

Referenced by PROCESS_THREAD().

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.

References servreg_hack_registration::addr, etimer_set(), servreg_hack_registration::id, id, LIFETIME, list_head(), list_item_next(), list_push(), memb_alloc(), NEW_REG_TIME, NULL, printf, PROCESS_CONTEXT_BEGIN, PROCESS_CONTEXT_END, random_rand(), sendtimer, servreg_hack_registration::seqno, servreg_hack_init(), servreg_hack_item_id(), servreg_hack_registration::timer, timer_set(), and uip_ipaddr_copy.

Referenced by PROCESS_THREAD().

uip_ipaddr_t servreg_hack_registration::addr
servreg_hack_id_t servreg_hack_registration::id
struct servreg_hack_registration* servreg_hack_registration::next
struct etimer sendtimer
static
uint8_t servreg_hack_registration::seqno
uint8_t started = 0
static

Referenced by servreg_hack_init().

struct timer servreg_hack_registration::timer