#include <gnunet_container_lib.h>
#include <gnunet_applications.h>
+#define LOG(kind,...) GNUNET_log_from (kind, "mesh-api",__VA_ARGS__)
+
struct tunnel_id
{
uint32_t id GNUNET_PACKED;
if (cls == NULL)
return 0;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending hello\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending hello\n");
struct peer_list_element *element = cls;
struct GNUNET_MESH_Handle *handle = element->handle;
{
struct GNUNET_MESH_Handle *handle = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core tells us we are connected to peer %s\n", GNUNET_i2s (peer));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Core tells us we are connected to peer %s\n",
+ GNUNET_i2s (peer));
/* put the new peer into the list of connected peers */
struct peer_list_element *element =
{
struct GNUNET_MESH_Handle *handle = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core tells us we are no longer connected to peer %s\n",
- GNUNET_i2s (peer));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Core tells us we are no longer connected to peer %s\n",
+ GNUNET_i2s (peer));
struct peer_list_element *element = handle->connected_peers.head;
(GNUNET_MESH_ApplicationType *) (num + 1);
unsigned int i;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "The peer %s tells us he supports %d application-types.\n",
- GNUNET_i2s (other), ntohs (*num));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "The peer %s tells us he supports %d application-types.\n",
+ GNUNET_i2s (other), ntohs (*num));
struct peer_list_element *element = handle->connected_peers.head;
for (i = 0; i < ntohs (*num); i++)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "The peer %s newly supports the application-type %d\n",
- GNUNET_i2s (other), ntohs (ports[i]));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "The peer %s newly supports the application-type %d\n",
+ GNUNET_i2s (other), ntohs (ports[i]));
if (GNUNET_APPLICATION_TYPE_END == ntohs (ports[i]))
continue;
struct type_list_element *new_type = GNUNET_malloc (sizeof *new_type);
for (type = element->type_head; type != NULL; type = type->next)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "The peer %s supports the application-type %d\n",
- GNUNET_i2s (other), type->type);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "The peer %s supports the application-type %d\n", GNUNET_i2s (other),
+ type->type);
}
struct tunnel_list_element *tunnel = handle->pending_by_type_tunnels.head;
/* If no handler was found, drop the message but keep the channel open */
if (handler->callback == NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received message of type %d from peer %s; dropping it.\n",
- ntohs (rmessage->type), GNUNET_i2s (other));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received message of type %d from peer %s; dropping it.\n",
+ ntohs (rmessage->type), GNUNET_i2s (other));
return GNUNET_OK;
}
/* if no tunnel was found: create a new inbound tunnel */
if (tunnel == NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "New inbound tunnel from peer %s; first message has type %d.\n",
- GNUNET_i2s (other), ntohs (rmessage->type));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "New inbound tunnel from peer %s; first message has type %d.\n",
+ GNUNET_i2s (other), ntohs (rmessage->type));
tunnel = GNUNET_malloc (sizeof (struct tunnel_list_element));
tunnel->tunnel.connect_handler = NULL;
tunnel->tunnel.disconnect_handler = NULL;
tunnel);
}
else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Inbound message from peer %s; type %d.\n", GNUNET_i2s (other),
- ntohs (rmessage->type));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Inbound message from peer %s; type %d.\n",
+ GNUNET_i2s (other), ntohs (rmessage->type));
return handler->callback (handle->cls, &tunnel->tunnel, &tunnel->tunnel.ctx,
other, rmessage, atsi);
element = element->next;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect by tupe %d.\n",
- application_type);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect by tupe %d.\n",
+ application_type);
/* Put into pending list */
struct tunnel_list_element *tunnel =
for (t = stypes; *t != GNUNET_APPLICATION_TYPE_END; t++, num++) ;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I can handle %d app-types.\n", num);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "I can handle %d app-types.\n", num);
handle->hello_message_size = sizeof (uint16_t) + /* For the number of types */
num * sizeof (GNUNET_MESH_ApplicationType); /* For the types */
for (i = 0; i < num; i++)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I can handle the app-type %d\n",
- stypes[i]);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "I can handle the app-type %d\n", stypes[i]);
types[i] = htons (stypes[i]);
}
ret->core =
GNUNET_CORE_connect (cfg, 42, ret, &core_startup, &core_connect,
- &core_disconnect, NULL, GNUNET_NO, NULL,
- GNUNET_NO, core_handlers);
- ret->transport =
- GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, NULL, NULL);
+ &core_disconnect, NULL, GNUNET_NO, NULL, GNUNET_NO,
+ core_handlers);
+ ret->transport = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, NULL, NULL);
return ret;
}
#define DEBUG GNUNET_YES
+#define LOG(kind,...) GNUNET_log_from (kind, "mesh-api",__VA_ARGS__)
+
/******************************************************************************/
/************************ DATA STRUCTURES ****************************/
/******************************************************************************/
/**
* Send a connect packet to the service with the applications and types
* requested by the user.
- *
+ *
* @param h The mesh handle.
- *
+ *
*/
static void
send_connect (struct GNUNET_MESH_Handle *h)
for (napps = 0; napps < h->n_applications; napps++)
{
apps[napps] = htonl (h->applications[napps]);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: app %u\n",
- h->applications[napps]);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: app %u\n", h->applications[napps]);
}
types = (uint16_t *) & apps[napps];
for (ntypes = 0; ntypes < h->n_handlers; ntypes++)
msg->applications = htons (napps);
msg->types = htons (ntypes);
#if DEBUG
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "mesh: Sending %lu bytes long message %d types and %d apps\n",
- ntohs (msg->header.size), ntypes, napps);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "mesh: Sending %lu bytes long message %d types and %d apps\n",
+ ntohs (msg->header.size), ntypes, napps);
#endif
send_packet (h, &msg->header);
}
unsigned int i;
#if DEBUG
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: *****************************\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: ******* RECONNECT *******\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: *****************************\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: *****************************\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: ******* RECONNECT *******\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: *****************************\n");
#endif
h->in_receive = GNUNET_NO;
/* disconnect */
GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS,
GNUNET_TIME_relative_multiply
(h->reconnect_time, 2));
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "mesh: Next retry in %sms\n",
- GNUNET_TIME_relative_to_string(h->reconnect_time));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Next retry in %sms\n",
+ GNUNET_TIME_relative_to_string (h->reconnect_time));
GNUNET_break (0);
return GNUNET_NO;
}
{
h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS;
}
- send_connect(h);
+ send_connect (h);
/* Rebuild all tunnels */
for (t = h->tunnels_head; NULL != t; t = t->next)
{
GNUNET_PEER_Id id;
uint16_t size;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: processig peer event\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: processig peer event\n");
size = ntohs (msg->header.size);
if (size != sizeof (struct GNUNET_MESH_PeerControl))
{
p = add_peer_to_tunnel (t, &msg->peer);
if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD == ntohs (msg->header.type))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: adding peer\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: adding peer\n");
if (NULL != t->connect_handler)
{
atsi.type = 0;
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: removing peer\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: removing peer\n");
if (NULL != t->disconnect_handler && p->connected)
{
t->disconnect_handler (t->cls, &msg->peer);
remove_peer_from_tunnel (p);
GNUNET_free (p);
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: processing peer event END\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: processing peer event END\n");
}
if (GNUNET_OK !=
handler->callback (h->cls, t, &t->ctx, peer, payload, &atsi))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: callback caused disconnection\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "MESH: callback caused disconnection\n");
GNUNET_MESH_disconnect (h);
return;
}
#if DEBUG
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "MESH: callback completed successfully\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "MESH: callback completed successfully\n");
}
#endif
reconnect (h);
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "mesh: received a message type %hu from MESH\n",
- ntohs (msg->type));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: received a message type %hu from MESH\n",
+ ntohs (msg->type));
switch (ntohs (msg->type))
{
/* Notify of a new incoming tunnel */
break;
/* We shouldn't get any other packages, log and ignore */
default:
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "MESH: unsolicited message form service (type %d)\n",
- ntohs (msg->type));
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "MESH: unsolicited message form service (type %d)\n",
+ ntohs (msg->type));
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: message processed\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: message processed\n");
GNUNET_CLIENT_receive (h->client, &msg_received, h,
GNUNET_TIME_UNIT_FOREVER_REL);
}
size_t tsize;
size_t psize;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Send packet() Buffer %u\n", size);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Send packet() Buffer %u\n", size);
h->th = NULL;
if ((0 == size) || (NULL == buf))
{
while ((NULL != (th = h->th_head)) && (size >= th->size))
{
#if DEBUG
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: type: %u\n",
- ntohs (((struct GNUNET_MessageHeader *) &th[1])->type));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: size: %u\n",
- ntohs (((struct GNUNET_MessageHeader *) &th[1])->size));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: type: %u\n",
+ ntohs (((struct GNUNET_MessageHeader *) &th[1])->type));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: size: %u\n",
+ ntohs (((struct GNUNET_MessageHeader *) &th[1])->size));
#endif
if (NULL != th->notify)
{
size -= psize;
tsize += psize;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: total size: %u\n", tsize);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: total size: %u\n", tsize);
if (NULL != (th = h->th_head))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: next size: %u\n", th->size);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: next size: %u\n", th->size);
h->th =
GNUNET_CLIENT_notify_transmit_ready (h->client, th->size,
GNUNET_TIME_UNIT_FOREVER_REL,
GNUNET_YES, &send_callback, h);
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Send packet() END\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Send packet() END\n");
if (GNUNET_NO == h->in_receive)
{
h->in_receive = GNUNET_YES;
{
struct GNUNET_MESH_Handle *h;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect()\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect()\n");
h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle));
h->cfg = cfg;
h->max_queue_size = queue_size;
/* count handlers and apps, calculate size */
for (h->n_applications = 0; stypes[h->n_applications]; h->n_applications++) ;
for (h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++) ;
- send_connect(h);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect() END\n");
+ send_connect (h);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect() END\n");
return h;
}
struct GNUNET_MESH_Tunnel *t;
struct GNUNET_MESH_TunnelMessage msg;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Creating new tunnel\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Creating new tunnel\n");
t = create_tunnel (h, 0);
t->connect_handler = connect_handler;
t->disconnect_handler = disconnect_handler;
struct GNUNET_MESH_Handle *h;
struct GNUNET_MESH_TunnelMessage msg;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n");
h = tunnel->mesh;
if (0 != tunnel->owner)