const struct GNUNET_CORE_MessageHandler *handlers;
/**
- * Our connection to the service.
+ * Our connection to the service for notifications.
*/
- struct GNUNET_CLIENT_Connection *client;
+ struct GNUNET_CLIENT_Connection *client_notifications;
+
+ /**
+ * Our connection to the service for normal requests.
+ */
+ struct GNUNET_CLIENT_Connection *client_requests;
/**
* Handle for our current transmission request.
static void
reconnect (struct GNUNET_CORE_Handle *h)
{
- GNUNET_CLIENT_disconnect (h->client);
+ GNUNET_CLIENT_disconnect (h->client_notifications);
h->currently_down = GNUNET_YES;
- h->client = GNUNET_CLIENT_connect (h->sched, "core", h->cfg);
- h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
+ h->client_notifications = GNUNET_CLIENT_connect (h->sched, "core", h->cfg);
+ h->th = GNUNET_CLIENT_notify_transmit_ready (h->client_notifications,
sizeof (struct InitMessage) +
sizeof (uint16_t) * h->hcnt,
GNUNET_TIME_UNIT_SECONDS,
trigger_next_request (struct GNUNET_CORE_Handle *h)
{
struct GNUNET_CORE_TransmitHandle *th;
+
if (h->currently_down)
return; /* connection temporarily down */
if (NULL == (th = h->pending_head))
GNUNET_SCHEDULER_cancel (h->sched, th->timeout_task);
th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
}
- h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
+ h->th = GNUNET_CLIENT_notify_transmit_ready (h->client_requests,
th->msize,
GNUNET_TIME_absolute_get_remaining
(th->timeout),
/**
- * Handler for most messages received from the core.
+ * Handler for notification messages received from the core.
*
* @param cls our "struct GNUNET_CORE_Handle"
* @param msg the message received from the core service
*/
static void
-main_handler (void *cls, const struct GNUNET_MessageHeader *msg)
+main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_CORE_Handle *h = cls;
unsigned int hpos;
const struct ConnectNotifyMessage *cnm;
const struct DisconnectNotifyMessage *dnm;
const struct NotifyTrafficMessage *ntm;
- const struct ConfigurationInfoMessage *cim;
const struct GNUNET_MessageHeader *em;
uint16_t msize;
uint16_t et;
GNUNET_TIME_relative_ntoh (ntm->latency),
ntohl (ntm->distance));
break;
- case GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO:
- if (msize != sizeof (struct ConfigurationInfoMessage))
- {
- GNUNET_break (0);
- break;
- }
- if (NULL == h->submitted)
- break;
- cim = (const struct ConfigurationInfoMessage *) msg;
-
- /* process configuration data */
- if (h->submitted->info != NULL)
- h->submitted->info (h->submitted->info_cls,
- &h->submitted->peer,
- ntohl (cim->bpm_in),
- ntohl (cim->bpm_out),
- (int) ntohl (cim->reserved_amount),
- cim->preference);
- /* done, clean up! */
- GNUNET_CORE_notify_transmit_ready_cancel (h->submitted); // HUH?
- trigger_next_request (h);
- break;
default:
GNUNET_break (0);
break;
}
- GNUNET_CLIENT_receive (h->client,
- &main_handler, h, GNUNET_TIME_UNIT_FOREVER_REL);
+ GNUNET_CLIENT_receive (h->client_notifications,
+ &main_notify_handler, h, GNUNET_TIME_UNIT_FOREVER_REL);
}
-
/**
* Function called when we are ready to transmit our
* "START" message (or when this operation timed out).
#endif
h->currently_down = GNUNET_NO;
trigger_next_request (h);
- GNUNET_CLIENT_receive (h->client,
- &main_handler, h, GNUNET_TIME_UNIT_FOREVER_REL);
+ GNUNET_CLIENT_receive (h->client_notifications,
+ &main_notify_handler, h, GNUNET_TIME_UNIT_FOREVER_REL);
if (NULL != (init = h->init))
{
/* mark so we don't call init on reconnect */
ts = (uint16_t *) & init[1];
for (hpos = 0; hpos < h->hcnt; hpos++)
ts[hpos] = htons (h->handlers[hpos].type);
- GNUNET_CLIENT_receive (h->client,
+ GNUNET_CLIENT_receive (h->client_notifications,
&init_reply_handler,
h,
GNUNET_TIME_absolute_get_remaining
h->inbound_hdr_only = inbound_hdr_only;
h->outbound_hdr_only = outbound_hdr_only;
h->handlers = handlers;
- h->client = GNUNET_CLIENT_connect (sched, "core", cfg);
- if (h->client == NULL)
+ h->client_notifications = GNUNET_CLIENT_connect (sched, "core", cfg);
+ if (h->client_notifications == NULL)
{
GNUNET_free (h);
return NULL;
timeout.value);
#endif
h->th =
- GNUNET_CLIENT_notify_transmit_ready (h->client,
+ GNUNET_CLIENT_notify_transmit_ready (h->client_notifications,
sizeof (struct InitMessage) +
sizeof (uint16_t) * h->hcnt, timeout,
GNUNET_YES,
GNUNET_CORE_notify_transmit_ready_cancel (handle->solicit_transmit_req);
if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (handle->sched, handle->reconnect_task);
- GNUNET_CLIENT_disconnect (handle->client);
+ GNUNET_CLIENT_disconnect (handle->client_notifications);
+ if (handle->client_requests != NULL)
+ GNUNET_CLIENT_disconnect (handle->client_requests);
GNUNET_free_non_null (handle->solicit_buffer);
GNUNET_free (handle);
}
};
-/**
- * Events are messages for clients. The struct
- * itself is followed by the actual message.
- */
-struct Event
-{
- /**
- * This is a linked list.
- */
- struct Event *next;
-
- /**
- * Size of the message.
- */
- size_t size;
-
- /**
- * Could this event be dropped if this queue
- * is getting too large? (NOT YET USED!)
- */
- int can_drop;
-
-};
-
-
/**
* Data structure for each client connected to the core service.
*/
*/
struct GNUNET_SERVER_Client *client_handle;
- /**
- * Linked list of messages we still need to deliver to
- * this client.
- */
- struct Event *event_head;
-
- /**
- * Tail of the linked list of events.
- */
- struct Event *event_tail;
-
- /**
- * Current transmit handle, NULL if no transmission request
- * is pending.
- */
- struct GNUNET_CONNECTION_TransmitHandle *th;
-
/**
* Array of the types of messages this peer cares
* about (with "tcnt" entries). Allocated as part
*/
static struct Client *clients;
+/**
+ * Context for notifications we need to send to our clients.
+ */
+static struct GNUNET_SERVER_NotificationContext *notifier;
+
/**
* We keep neighbours in a linked list (for now).
*/
}
-/**
- * Find the entry for the given client.
- *
- * @param client handle for the client
- * @return NULL if we are not connected, otherwise the
- * client's struct.
- */
-static struct Client *
-find_client (const struct GNUNET_SERVER_Client *client)
-{
- struct Client *ret;
-
- ret = clients;
- while ((ret != NULL) && (client != ret->client_handle))
- ret = ret->next;
- return ret;
-}
-
-
-/**
- * If necessary, initiate a request with the server to
- * transmit messages from the queue of the given client.
- * @param client who to transfer messages to
- */
-static void request_transmit (struct Client *client);
-
-
-/**
- * Client is ready to receive data, provide it.
- *
- * @param cls closure
- * @param size number of bytes available in buf
- * @param buf where the callee should write the message
- * @return number of bytes written to buf
- */
-static size_t
-do_client_transmit (void *cls, size_t size, void *buf)
-{
- struct Client *client = cls;
- struct Event *e;
- char *tgt;
- size_t ret;
-
- client->th = NULL;
-#if DEBUG_CORE_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client ready to receive %u bytes.\n", size);
-#endif
- if (buf == NULL)
- {
-#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to transmit data to client (disconnect)?\n");
-#endif
- return 0; /* we'll surely get a disconnect soon... */
- }
- tgt = buf;
- ret = 0;
- while ((NULL != (e = client->event_head)) && (e->size <= size))
- {
- memcpy (&tgt[ret], &e[1], e->size);
- size -= e->size;
- ret += e->size;
- client->event_head = e->next;
- GNUNET_free (e);
- }
- GNUNET_assert (ret > 0);
- if (client->event_head == NULL)
- client->event_tail = NULL;
-#if DEBUG_CORE_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting %u bytes to client\n", ret);
-#endif
- request_transmit (client);
- return ret;
-}
-
-
-/**
- * If necessary, initiate a request with the server to
- * transmit messages from the queue of the given client.
- * @param client who to transfer messages to
- */
-static void
-request_transmit (struct Client *client)
-{
-
- if (NULL != client->th)
- return; /* already pending */
- if (NULL == client->event_head)
- return; /* no more events pending */
-#if DEBUG_CORE_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking server to transmit %u bytes to client\n",
- client->event_head->size);
-#endif
- client->th
- = GNUNET_SERVER_notify_transmit_ready (client->client_handle,
- client->event_head->size,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &do_client_transmit, client);
-}
-
-
/**
* Send a message to one of our clients.
*
*/
static void
send_to_client (struct Client *client,
- const struct GNUNET_MessageHeader *msg, int can_drop)
+ const struct GNUNET_MessageHeader *msg,
+ int can_drop)
{
- struct Event *e;
- unsigned int queue_size;
- uint16_t msize;
-
#if DEBUG_CORE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Preparing to send message of type %u to client.\n",
ntohs (msg->type));
-#endif
- queue_size = 0;
- e = client->event_head;
- while (e != NULL)
- {
- queue_size++;
- e = e->next;
- }
- if ( (queue_size >= MAX_CLIENT_QUEUE_SIZE) &&
- (can_drop == GNUNET_YES) )
- {
-#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Too many messages in queue for the client, dropping the new message.\n");
-#endif
- return;
- }
-
- msize = ntohs (msg->size);
- e = GNUNET_malloc (sizeof (struct Event) + msize);
- /* append */
- if (client->event_tail != NULL)
- client->event_tail->next = e;
- else
- client->event_head = e;
- client->event_tail = e;
- e->can_drop = can_drop;
- e->size = msize;
- memcpy (&e[1], msg, msize);
- request_transmit (client);
+#endif
+ GNUNET_SERVER_notification_context_unicast (notifier,
+ client->client_handle,
+ msg,
+ can_drop);
}
/**
- * Send a message to all of our current clients.
+ * Send a message to all of our current clients that have
+ * the right options set.
+ *
+ * @param msg message to multicast
+ * @param can_drop can this message be discarded if the queue is too long
+ * @param options mask to use
*/
static void
send_to_all_clients (const struct GNUNET_MessageHeader *msg,
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
+ GNUNET_SERVER_notification_context_add (notifier, client);
im = (const struct InitMessage *) message;
types = (const uint16_t *) &im[1];
msize -= sizeof (struct InitMessage);
send_to_client (c, &cnm.header, GNUNET_NO);
n = n->next;
}
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
{
struct Client *pos;
struct Client *prev;
- struct Event *e;
if (client == NULL)
return;
clients = pos->next;
else
prev->next = pos->next;
- if (pos->th != NULL)
- GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th);
- while (NULL != (e = pos->event_head))
- {
- pos->event_head = e->next;
- GNUNET_free (e);
- }
GNUNET_free (pos);
return;
}
*/
static void
handle_client_request_info (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct RequestInfoMessage *rcm;
struct Neighbour *n;
struct ConfigurationInfoMessage cim;
- struct Client *c;
int reserv;
unsigned long long old_preference;
+ struct GNUNET_SERVER_TransmitContext *tc;
#if DEBUG_CORE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
cim.header.size = htons (sizeof (struct ConfigurationInfoMessage));
cim.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO);
cim.peer = rcm->peer;
- c = find_client (client);
- if (c == NULL)
- {
- GNUNET_break (0);
- return;
- }
+
#if DEBUG_CORE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending `%s' message to client.\n", "CONFIGURATION_INFO");
#endif
- send_to_client (c, &cim.header, GNUNET_NO);
+ tc = GNUNET_SERVER_transmit_context_create (client);
+ GNUNET_SERVER_transmit_context_append_message (tc, &cim.header);
+ GNUNET_SERVER_transmit_context_run (tc,
+ GNUNET_TIME_UNIT_FOREVER_REL);
}
neighbour_count--;
free_neighbour (n);
}
+ GNUNET_SERVER_notification_context_destroy (notifier);
+ notifier = NULL;
while (NULL != (c = clients))
handle_client_disconnect (NULL, c->client_handle);
if (my_private_key != NULL)
char *keyfile;
sched = s;
- cfg = c;
+ cfg = c;
/* parse configuration */
if (
(GNUNET_OK !=
sizeof (my_public_key), &my_identity.hashPubKey);
/* setup notification */
server = serv;
+ notifier = GNUNET_SERVER_notification_context_create (server, 0);
GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
/* setup transport connection */
transport = GNUNET_TRANSPORT_connect (sched,
ii->filename,
(const char*) GNUNET_CONTAINER_multihashmap_get (ifm,
&ii->file_id));
- GNUNET_SERVER_transmit_context_append (ii->tc,
- NULL, 0,
- GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
+ GNUNET_SERVER_transmit_context_append_data (ii->tc,
+ NULL, 0,
+ GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
GNUNET_SERVER_transmit_context_run (ii->tc,
GNUNET_TIME_UNIT_MINUTES);
GNUNET_free (ii);
ii->next = indexed_files;
indexed_files = ii;
write_index_list ();
- GNUNET_SERVER_transmit_context_append (ii->tc,
- NULL, 0,
- GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
+ GNUNET_SERVER_transmit_context_append_data (ii->tc,
+ NULL, 0,
+ GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
GNUNET_SERVER_transmit_context_run (ii->tc,
GNUNET_TIME_UNIT_MINUTES);
ii->tc = NULL;
"Wanted `%s'\n",
GNUNET_h2s (&ii->file_id));
#endif
- GNUNET_SERVER_transmit_context_append (ii->tc,
- NULL, 0,
- GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED);
+ GNUNET_SERVER_transmit_context_append_data (ii->tc,
+ NULL, 0,
+ GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED);
GNUNET_SERVER_transmit_context_run (ii->tc,
GNUNET_TIME_UNIT_MINUTES);
GNUNET_free (ii);
char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE];
size_t slen;
const char *fn;
- struct GNUNET_MessageHeader *msg;
struct IndexInfo *pos;
tc = GNUNET_SERVER_transmit_context_create (client);
iim = (struct IndexInfoMessage*) buf;
- msg = &iim->header;
pos = indexed_files;
while (NULL != pos)
{
- iim->reserved = 0;
- iim->file_id = pos->file_id;
fn = pos->filename;
slen = strlen (fn) + 1;
if (slen + sizeof (struct IndexInfoMessage) >
GNUNET_break (0);
break;
}
+ iim->header.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
+ iim->header.size = htons (slen + sizeof (struct IndexInfoMessage));
+ iim->reserved = 0;
+ iim->file_id = pos->file_id;
memcpy (&iim[1], fn, slen);
- GNUNET_SERVER_transmit_context_append
- (tc,
- &msg[1],
- sizeof (struct IndexInfoMessage)
- - sizeof (struct GNUNET_MessageHeader) + slen,
- GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
+ GNUNET_SERVER_transmit_context_append_message (tc,
+ &iim->header);
pos = pos->next;
}
- GNUNET_SERVER_transmit_context_append (tc,
- NULL, 0,
- GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
+ GNUNET_SERVER_transmit_context_append_data (tc,
+ NULL, 0,
+ GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
GNUNET_SERVER_transmit_context_run (tc,
GNUNET_TIME_UNIT_MINUTES);
}
if (GNUNET_YES == found)
write_index_list ();
tc = GNUNET_SERVER_transmit_context_create (client);
- GNUNET_SERVER_transmit_context_append (tc,
- NULL, 0,
- GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK);
+ GNUNET_SERVER_transmit_context_append_data (tc,
+ NULL, 0,
+ GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK);
GNUNET_SERVER_transmit_context_run (tc,
GNUNET_TIME_UNIT_MINUTES);
}
* @param type type of the message
*/
void
-GNUNET_SERVER_transmit_context_append (struct GNUNET_SERVER_TransmitContext
- *tc, const void *data, size_t length,
- uint16_t type);
+GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext
+ *tc, const void *data, size_t length,
+ uint16_t type);
+
+
+/**
+ * Append a message to the transmission context.
+ * All messages in the context will be sent by
+ * the transmit_context_run method.
+ *
+ * @param tc context to use
+ * @param msg message to append
+ */
+void
+GNUNET_SERVER_transmit_context_append_message (struct GNUNET_SERVER_TransmitContext
+ *tc, const struct GNUNET_MessageHeader *msg);
+
/**
* Execute a transmission context. If there is
{
struct HostEntry *pos;
struct InfoMessage *im;
- const struct GNUNET_MessageHeader *end;
uint16_t hs;
char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE];
struct GNUNET_SERVER_TransmitContext *tc;
change_host_trust (&pos->identity, trust_change);
hs = 0;
im = (struct InfoMessage *) buf;
+ im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
+ im->header.size = htons (sizeof (struct InfoMessage) + hs);
if (pos->hello != NULL)
{
hs = GNUNET_HELLO_size (pos->hello);
}
im->trust = htonl (pos->trust);
im->peer = pos->identity;
- end = &im->header;
- GNUNET_SERVER_transmit_context_append (tc,
- &end[1],
- hs +
- sizeof (struct InfoMessage) -
- sizeof (struct
- GNUNET_MessageHeader),
- GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
+ GNUNET_SERVER_transmit_context_append_message (tc,
+ &im->header);
}
pos = pos->next;
}
- GNUNET_SERVER_transmit_context_append (tc, NULL, 0,
- GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
+ GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
+ GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
}
const struct StatsEntry *e)
{
struct GNUNET_STATISTICS_ReplyMessage *m;
- struct GNUNET_MessageHeader *h;
size_t size;
- uint16_t msize;
size =
sizeof (struct GNUNET_STATISTICS_ReplyMessage) + strlen (e->service) + 1 +
strlen (e->name) + 1;
GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
- msize = size - sizeof (struct GNUNET_MessageHeader);
m = GNUNET_malloc (size);
+ m->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_VALUE);
+ m->header.size = htons (size);
m->uid = htonl (e->uid);
if (e->persistent)
m->uid |= htonl (GNUNET_STATISTICS_PERSIST_BIT);
"Transmitting value for `%s:%s': %llu\n",
e->service, e->name, e->value);
#endif
- h = &m->header;
- GNUNET_SERVER_transmit_context_append (tc,
- &h[1],
- msize,
- GNUNET_MESSAGE_TYPE_STATISTICS_VALUE);
+ GNUNET_SERVER_transmit_context_append_message (tc, &m->header);
GNUNET_free (m);
}
transmit (tc, pos);
pos = pos->next;
}
- GNUNET_SERVER_transmit_context_append (tc, NULL, 0,
- GNUNET_MESSAGE_TYPE_STATISTICS_END);
+ GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
+ GNUNET_MESSAGE_TYPE_STATISTICS_END);
GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
}
slen = 0;
else
slen = strlen (address) + 1;
- GNUNET_SERVER_transmit_context_append (tc, address, slen,
- GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+ GNUNET_SERVER_transmit_context_append_data (tc, address, slen,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
if (NULL == address)
GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
}
if (NULL == lsPlugin)
{
tc = GNUNET_SERVER_transmit_context_create (client);
- GNUNET_SERVER_transmit_context_append (tc, NULL, 0,
- GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+ GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
GNUNET_SERVER_transmit_context_run (tc, rtimeout);
return;
}
}
tc = GNUNET_SERVER_transmit_context_create (client);
if (cache->addr != NULL)
- GNUNET_SERVER_transmit_context_append (tc,
- cache->addr,
- strlen (cache->addr) + 1,
- GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
- GNUNET_SERVER_transmit_context_append (tc, NULL, 0,
- GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+ GNUNET_SERVER_transmit_context_append_data (tc,
+ cache->addr,
+ strlen (cache->addr) + 1,
+ GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+ GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
+ GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
}
pos = result;
while (pos != NULL)
{
- GNUNET_SERVER_transmit_context_append (tc,
- result->ai_addr,
- result->ai_addrlen,
- GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+ GNUNET_SERVER_transmit_context_append_data (tc,
+ result->ai_addr,
+ result->ai_addrlen,
+ GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
pos = pos->ai_next;
}
freeaddrinfo (result);
memset (&a4, 0, sizeof (a4));
a4.sin_family = AF_INET;
memcpy (&a4.sin_addr, hp->h_addr_list[0], hp->h_length);
- GNUNET_SERVER_transmit_context_append (tc,
- &a4,
- sizeof (a4),
- GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+ GNUNET_SERVER_transmit_context_append_data (tc,
+ &a4,
+ sizeof (a4),
+ GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
}
else
{
memset (&a6, 0, sizeof (a6));
a6.sin6_family = AF_INET6;
memcpy (&a6.sin6_addr, hp->h_addr_list[0], hp->h_length);
- GNUNET_SERVER_transmit_context_append (tc,
- &a6,
- sizeof (a6),
- GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+ GNUNET_SERVER_transmit_context_append_data (tc,
+ &a6,
+ sizeof (a6),
+ GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
}
return GNUNET_OK;
}
memset (&addr, 0, sizeof (addr));
addr.sin_family = AF_INET;
memcpy (&addr.sin_addr, hp->h_addr_list[0], hp->h_length);
- GNUNET_SERVER_transmit_context_append (tc,
- &addr,
- sizeof (addr),
- GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+ GNUNET_SERVER_transmit_context_append_data (tc,
+ &addr,
+ sizeof (addr),
+ GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
return GNUNET_OK;
}
#endif
if ((ret == GNUNET_NO) && ((domain == AF_UNSPEC) || (domain == PF_INET)))
gethostbyname_resolve (tc, hostname);
#endif
- GNUNET_SERVER_transmit_context_append (tc, NULL, 0,
- GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+ GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
+ GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
}
* @param type type of the message
*/
void
-GNUNET_SERVER_transmit_context_append (struct GNUNET_SERVER_TransmitContext
- *tc, const void *data, size_t length,
- uint16_t type)
+GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext
+ *tc, const void *data, size_t length,
+ uint16_t type)
{
struct GNUNET_MessageHeader *msg;
size_t size;
}
+/**
+ * Append a message to the transmission context.
+ * All messages in the context will be sent by
+ * the transmit_context_run method.
+ *
+ * @param tc context to use
+ * @param msg message to append
+ */
+void
+GNUNET_SERVER_transmit_context_append_message(struct GNUNET_SERVER_TransmitContext
+ *tc, const struct GNUNET_MessageHeader *msg)
+{
+ struct GNUNET_MessageHeader *m;
+ uint16_t size;
+
+ size = ntohs (msg->size);
+ tc->buf = GNUNET_realloc (tc->buf, tc->total + size);
+ m = (struct GNUNET_MessageHeader *) &tc->buf[tc->total];
+ tc->total += size;
+ memcpy (m, msg, size);
+}
+
+
/**
* Execute a transmission context. If there is
* an error in the transmission, the receive_done