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_t * | servreg_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_t * | servreg_hack_list_head (void) |
Obtain the list of services provided by neighbors. More... | |
uip_ipaddr_t * | servreg_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_registration * | servreg_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 |
Referenced by handle_incoming_reg(), purge_registrations(), and servreg_hack_register().
#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 |
Referenced by parse_incoming_packet(), and send_udp_packet().
#define MSG_FLAGS_OFFSET 1 |
Referenced by parse_incoming_packet(), and send_udp_packet().
#define MSG_IPADDR_SUBOFFSET 0 |
Referenced by parse_incoming_packet(), and send_udp_packet().
#define MSG_NUMREGS_OFFSET 0 |
Referenced by parse_incoming_packet(), and send_udp_packet().
#define MSG_REGS_SUBOFFSET 16 |
Referenced by parse_incoming_packet(), and send_udp_packet().
#define MSG_SEQNO_SUBOFFSET 19 |
Referenced by parse_incoming_packet(), and send_udp_packet().
#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, | |
b | |||
) | ((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 |
|
static |
References servreg_hack_registration::addr, servreg_hack_registration::id, id, LIFETIME, list_add(), list_item_next(), list_push(), list_remove(), memb_alloc(), NULL, printf, servreg_hack_registration::seqno, SEQNO_LT, servreg_hack_item_id(), servreg_hack_list_head(), servreg_hack_registration::timer, timer_set(), and uip_ipaddr_copy.
Referenced by parse_incoming_packet().
LIST | ( | others_services | ) |
LIST | ( | own_services | ) |
MEMB | ( | registrations | , |
struct servreg_hack_registration | , | ||
MAX_REGISTRATIONS | |||
) |
|
static |
References bufptr, handle_incoming_reg(), i, MSG_ADDRS_OFFSET, MSG_FLAGS_OFFSET, MSG_IPADDR_SUBOFFSET, MSG_NUMREGS_OFFSET, MSG_REGS_SUBOFFSET, and MSG_SEQNO_SUBOFFSET.
Referenced by PROCESS_THREAD().
PROCESS | ( | servreg_hack_process | , |
"Service regstry hack" | |||
) |
PROCESS_THREAD | ( | servreg_hack_process | , |
ev | , | ||
data | |||
) |
References data, etimer_reset(), etimer_set(), NULL, parse_incoming_packet(), PERIOD_TIME, PROCESS_BEGIN, PROCESS_END, PROCESS_EVENT_TIMER, PROCESS_WAIT_EVENT, random_rand(), send_udp_packet(), sendtimer, tcpip_event, udp_bind, udp_broadcast_new(), udp_new(), UDP_PORT, uip_appdata, uip_datalen, and UIP_HTONS.
|
static |
References LIFETIME, list_head(), list_item_next(), list_remove(), memb_free(), NULL, servreg_hack_registration::seqno, servreg_hack_registration::timer, timer_expired(), and timer_set().
Referenced by servreg_hack_list_head(), and servreg_hack_lookup().
|
static |
References buf, bufptr, list_head(), list_item_next(), MAX_BUFSIZE, MSG_ADDRS_LEN, MSG_ADDRS_OFFSET, MSG_FLAGS_OFFSET, MSG_IPADDR_SUBOFFSET, MSG_NUMREGS_OFFSET, MSG_REGS_SUBOFFSET, MSG_SEQNO_SUBOFFSET, NULL, servreg_hack_item_address(), servreg_hack_item_id(), servreg_hack_list_head(), uip_ipaddr_copy, and uip_udp_packet_send().
Referenced by PROCESS_THREAD().
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.
item | The list item |
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.
item | The 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.
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.
service_id | The service ID of the service |
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.
service_id | The 8-bit ID for the service |
addr | The 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 |
Referenced by handle_incoming_reg(), and servreg_hack_register().
servreg_hack_id_t servreg_hack_registration::id |
Referenced by handle_incoming_reg(), and servreg_hack_register().
struct servreg_hack_registration* servreg_hack_registration::next |
|
static |
Referenced by PROCESS_THREAD(), and servreg_hack_register().
uint8_t servreg_hack_registration::seqno |
Referenced by handle_incoming_reg(), purge_registrations(), and servreg_hack_register().
|
static |
Referenced by servreg_hack_init().
struct timer servreg_hack_registration::timer |
Referenced by handle_incoming_reg(), purge_registrations(), and servreg_hack_register().