Next: , Previous: , Up: Writing a Client Library   [Contents] Sending messages

In GNUnet, messages are always sent beginning with a struct GNUNET\_MessageHeader in big endian format. This header defines the size and the type of the message, the payload follows after this header.

struct GNUNET_MessageHeader
  uint16_t size GNUNET_PACKED;
  uint16_t type GNUNET_PACKED;

Existing message types are defined in gnunet\_protocols.h. A common way to create a message is with an envelope:

struct GNUNET_MQ_Envelope *env;
struct GNUNET_MessageHeader *msg;

env = GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MY_MESSAGE_TYPE);
GNUNET_memcpy (&msg[1],
// Send message via message queue 'mq'
GNUNET_mq_send (mq, env);

Exercise: Define a message struct that includes a 32-bit unsigned integer in addition to the standard GNUnet MessageHeader. Add a C struct and define a fresh protocol number for your message. Protocol numbers in gnunet-ext are defined in gnunet-ext/src/include/gnunet_protocols_ext.h

Exercise: Find out how you can determine the number of messages in a message queue.

Exercise: Find out how you can determine when a message you have queued was actually transmitted.

Exercise: Define a helper function to transmit a 32-bit unsigned integer (as payload) to a service using some given client handle.