When cnet informs your protocols that the Application Layer has a message for delivery, your protocols will read the message into a buffer supplied by you. You must first indicate the maximum message size that you are willing to receive. A successful read will then ``fill-in'' the address of the message's destination node and the actual length of the message. Your protocols are simply presented with ``a lump of bytes'', at least 32 bytes long, which they must deliver to other Application Layers. The message is to be considered as opaque data, its contents are immaterial, though suffice to say that there is sufficient information in the message for cnet to diagnose most protocol errors for you. A typical sequence is:
char msgbuffer[ MAX_MESSAGE_SIZE ];
CnetAddr destaddr;
int length;
length = sizeof(msgbuffer);
result = CNET_read_application(&destaddr,msgbuffer,&length);
/* prepare message for transmission ... */
When the message reaches the correct destination node, it may be written to the Application Layer:
/* ... receive message from another node */
result = CNET_write_application(msgbuffer, &length);
Protocols will typically need to restrict,
or throttle,
the generation of messages for certain destination nodes.
This may be achieved using the functions
CNET_enable_application and
CNET_disable_application which each accept a single parameter
indicating which destination address to throttle.
For example,
if the node whose address is busynode becomes busy or swamped,
we can stop our Application Layer from generating messages for this node with:
result = CNET_disable_application(busynode);
Similarly, we can permit messages to be generated for all nodes (other than ourselves, of course) with:
result = CNET_enable_application(ALLNODES);
This function would typically be called in each node's
reboot_node() function.
The default Application Layer prefers to generate messages for ``close nodes'', with a message having twice the chance of being for an immediate neighbour as for a node two hops away (and so on).
cnet was written and is maintained by Chris McDonald
(chris@cs.uwa.edu.au)