#include "platform.h"
+#include "gnunet_util_lib.h"
+
+#include "gnunet_statistics_service.h"
+
#include "mesh_enc.h"
#include "mesh_protocol_enc.h" // GNUNET_MESH_Data is shared
+
#include "gnunet-service-mesh_local.h"
+#include "gnunet-service-mesh_tunnel.h"
+
+#define LOG(level, ...) GNUNET_log_from(level,"mesh-loc",__VA_ARGS__)
/******************************************************************************/
/******************************** STRUCTS **********************************/
/**
* Struct containing information about a client of the service
- *
+ *
* TODO: add a list of 'waiting' ports
*/
struct MeshClient
/******************************* GLOBALS ***********************************/
/******************************************************************************/
+/**
+ * Global handle to the statistics service.
+ */
+extern struct GNUNET_STATISTICS_Handle *stats;
+
/**
* Handle to server lib.
*/
if (GNUNET_YES != res)
{
GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ LOG (GNUNET_ERROR_TYPE_WARNING,
"Port %u by client %p was not registered.\n",
key, value);
}
* @param cls Closure (unused).
* @param client Client handler.
*/
-void
-GMLH_client_connect (void *cls, struct GNUNET_SERVER_Client *client)
+static void
+handle_client_connect (void *cls, struct GNUNET_SERVER_Client *client)
{
struct MeshClient *c;
* @param client identification of the client; NULL
* for the last call when the server is destroyed
*/
-void
-GMLH_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
+static void
+handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
{
struct MeshClient *c;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client disconnected: %p\n", client);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "client disconnected: %p\n", client);
if (client == NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (SERVER DOWN)\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " (SERVER DOWN)\n");
return;
}
c = client_get (client);
if (NULL != c)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "matching client found (%u, %p)\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "matching client found (%u, %p)\n",
c->id, c);
GNUNET_SERVER_client_drop (c->handle);
c->shutting_down = GNUNET_YES;
}
GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c);
GNUNET_STATISTICS_update (stats, "# clients", -1, GNUNET_NO);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client free (%p)\n", c);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " client free (%p)\n", c);
GNUNET_free (c);
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, " context NULL!\n");
+ LOG (GNUNET_ERROR_TYPE_WARNING, " context NULL!\n");
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "done!\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "done!\n");
return;
}
* @param client identification of the client
* @param message the actual message, which includes messages the client wants
*/
-void
-GMLH_new_client (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+static void
+handle_new_client (void *cls, struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_ClientConnect *cc_msg;
struct MeshClient *c;
uint32_t *p;
unsigned int i;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new client connected %p\n", client);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "new client connected %p\n", client);
/* Check data sanity */
size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect);
/* Initialize new client structure */
c = GNUNET_SERVER_client_get_user_context (client, struct MeshClient);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client id %u\n", c->id);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client has %u ports\n", size);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " client id %u\n", c->id);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " client has %u ports\n", size);
if (size > 0)
{
uint32_t u32;
for (i = 0; i < size; i++)
{
u32 = ntohl (p[i]);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " port: %u\n", u32);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " port: %u\n", u32);
/* store in client's hashmap */
GNUNET_CONTAINER_multihashmap32_put (c->ports, u32, c,
GNUNET_STATISTICS_update (stats, "# clients", 1, GNUNET_NO);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new client processed\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "new client processed\n");
}
* @param client Identification of the client.
* @param message The actual message.
*/
-void
-GMLH_channel_create (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+static void
+handle_channel_create (void *cls, struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_ChannelMessage *msg;
struct MeshPeer *peer;
struct MeshClient *c;
MESH_ChannelNumber chid;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new channel requested\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "new channel requested\n");
/* Sanity check for client registration */
if (NULL == (c = client_get (client)))
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
/* Message size sanity check */
if (sizeof (struct GNUNET_MESH_ChannelMessage) != ntohs (message->size))
}
msg = (struct GNUNET_MESH_ChannelMessage *) message;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " towards %s:%u\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " towards %s:%u\n",
GNUNET_i2s (&msg->peer), ntohl (msg->port));
chid = ntohl (msg->channel_id);
ch->root_rel->ch = ch;
ch->root_rel->expected_delay = MESH_RETRANSMIT_TIME;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATED CHANNEL %s[%x]:%u (%x)\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "CREATED CHANNEL %s[%x]:%u (%x)\n",
peer2s (t->peer), ch->gid, ch->port, ch->lid_root);
/* Send create channel */
msgcc.port = msg->port;
msgcc.opt = msg->opt;
- tunnel_queue_data (t, ch, &msgcc.header, GNUNET_YES);
+ GMT_queue_data (t, ch, &msgcc.header, GNUNET_YES);
}
GNUNET_SERVER_receive_done (client, GNUNET_OK);
* @param client identification of the client
* @param message the actual message
*/
-void
-GMLH_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+static void
+handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_ChannelMessage *msg;
struct MeshClient *c;
struct MeshTunnel2 *t;
MESH_ChannelNumber chid;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"Got a DESTROY CHANNEL from client!\n");
/* Sanity check for client registration */
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
/* Message sanity check */
if (sizeof (struct GNUNET_MESH_ChannelMessage) != ntohs (message->size))
ch = channel_get_by_local_id (c, chid);
if (NULL == ch)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " channel %X not found\n", chid);
+ LOG (GNUNET_ERROR_TYPE_ERROR, " channel %X not found\n", chid);
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
{
ch->root = NULL;
}
- else
+ else
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ LOG (GNUNET_ERROR_TYPE_ERROR,
" channel %X client %p (%p, %p)\n",
chid, c, ch->root, ch->dest);
GNUNET_break (0);
* @param client identification of the client
* @param message the actual message
*/
-void
-GMLH_data (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+static void
+handle_data (void *cls, struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_LocalData *msg;
struct MeshClient *c;
size_t size;
int fwd;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"Got data from a client!\n");
/* Sanity check for client registration */
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
msg = (struct GNUNET_MESH_LocalData *) message;
ch->root->handle == client)
||
(!fwd &&
- ch->dest &&
+ ch->dest &&
ch->dest->handle == client) ) )
{
GNUNET_break (0);
payload->header.size = htons (p2p_size);
payload->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_DATA);
payload->chid = htonl (ch->gid);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " sending on channel...\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on channel...\n");
send_prebuilt_message_channel (&payload->header, ch, fwd);
if (GNUNET_YES == ch->reliable)
}
if (tunnel_get_buffer (ch->t, fwd) > 0)
send_local_ack (ch, fwd);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "receive done OK\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "receive done OK\n");
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
* @param client Identification of the client.
* @param message The actual message.
*/
-void
-GMLH_ack (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+static void
+handle_ack (void *cls, struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_LocalAck *msg;
struct MeshChannelReliability *rel;
MESH_ChannelNumber chid;
int fwd;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a local ACK\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a local ACK\n");
/* Sanity check for client registration */
if (NULL == (c = client_get (client)))
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
msg = (struct GNUNET_MESH_LocalAck *) message;
/* Channel exists? */
chid = ntohl (msg->channel_id);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", chid);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", chid);
ch = channel_get_by_local_id (c, chid);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " -- ch %p\n", ch);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " -- ch %p\n", ch);
if (NULL == ch)
{
GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Channel %X unknown.\n", chid);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, " for client %u.\n", c->id);
+ LOG (GNUNET_ERROR_TYPE_WARNING, "Channel %X unknown.\n", chid);
+ LOG (GNUNET_ERROR_TYPE_WARNING, " for client %u.\n", c->id);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
// struct GNUNET_SERVER_Client *client = cls;
// struct MeshChannel *ch = value;
// struct GNUNET_MESH_LocalMonitor *msg;
-//
+//
// msg = GNUNET_malloc (sizeof(struct GNUNET_MESH_LocalMonitor));
// msg->channel_id = htonl (ch->gid);
// msg->header.size = htons (sizeof (struct GNUNET_MESH_LocalMonitor));
// msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS);
-//
-// GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+//
+// LOG (GNUNET_ERROR_TYPE_INFO,
// "* sending info about tunnel %s\n",
// GNUNET_i2s (&msg->owner));
-//
+//
// GNUNET_SERVER_notification_context_unicast (nc, client,
// &msg->header, GNUNET_NO);
// return GNUNET_YES;
* @param client Identification of the client.
* @param message The actual message.
*/
-void
-GMLH_get_tunnels (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+static void
+handle_get_tunnels (void *cls, struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
struct MeshClient *c;
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ LOG (GNUNET_ERROR_TYPE_INFO,
"Received get tunnels request from client %u\n",
c->id);
// GNUNET_CONTAINER_multihashmap_iterate (tunnels,
// monitor_all_tunnels_iterator,
// client);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ LOG (GNUNET_ERROR_TYPE_INFO,
"Get tunnels request from client %u completed\n",
c->id);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
* @param message The actual message.
*/
void
-GMLH_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct GNUNET_MESH_LocalMonitor *msg;
struct GNUNET_MESH_LocalMonitor *resp;
}
msg = (struct GNUNET_MESH_LocalMonitor *) message;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ LOG (GNUNET_ERROR_TYPE_INFO,
"Received tunnel info request from client %u for tunnel %s[%X]\n",
c->id,
&msg->owner,
&resp->header, GNUNET_NO);
GNUNET_free (resp);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ LOG (GNUNET_ERROR_TYPE_INFO,
"Monitor tunnel request from client %u completed\n",
c->id);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
* Functions to handle messages from clients
*/
static struct GNUNET_SERVER_MessageHandler client_handlers[] = {
- {&GMLH_new_client, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0},
- {&GMLH_channel_create, NULL, GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE,
+ {&handle_new_client, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0},
+ {&handle_channel_create, NULL, GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE,
sizeof (struct GNUNET_MESH_ChannelMessage)},
- {&GMLH_channel_destroy, NULL, GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY,
+ {&handle_channel_destroy, NULL, GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY,
sizeof (struct GNUNET_MESH_ChannelMessage)},
- {&GMLH_data, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0},
- {&GMLH_ack, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK,
+ {&handle_data, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0},
+ {&handle_ack, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK,
sizeof (struct GNUNET_MESH_LocalAck)},
- {&GMLH_get_tunnels, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS,
+ {&handle_get_tunnels, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS,
sizeof (struct GNUNET_MessageHeader)},
- {&GMLH_show_tunnel, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL,
+ {&handle_show_tunnel, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL,
sizeof (struct GNUNET_MESH_LocalMonitor)},
{NULL, NULL, 0, 0}
};
/******************************** API ***********************************/
/******************************************************************************/
-void
-GML_init (void)
-{
- ports = GNUNET_CONTAINER_multihashmap32_create (32);
-}
-
-
/**
* Initialize server subsystem.
- *
+ *
* @param handle Server handle.
*/
void
{
server_handle = handle;
GNUNET_SERVER_suspend (server_handle);
+ ports = GNUNET_CONTAINER_multihashmap32_create (32);
}
+
/**
* Install server (service) handlers and start listening to clients.
*/
GML_start (void)
{
GNUNET_SERVER_add_handlers (server_handle, client_handlers);
- GNUNET_SERVER_connect_notify (server_handle, &GMLH_client_connect, NULL);
- GNUNET_SERVER_disconnect_notify (server_handle, &GMLH_client_disconnect,
+ GNUNET_SERVER_connect_notify (server_handle, &handle_client_connect, NULL);
+ GNUNET_SERVER_disconnect_notify (server_handle, &handle_client_disconnect,
NULL);
nc = GNUNET_SERVER_notification_context_create (server_handle, 1);
res = GNUNET_CONTAINER_multihashmap32_remove (c->own_channels,
ch->lid_root, ch);
if (GNUNET_YES != res)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client_delete_channel owner KO\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "client_delete_channel owner KO\n");
}
if (c == ch->dest)
{
res = GNUNET_CONTAINER_multihashmap32_remove (c->incoming_channels,
ch->lid_dest, ch);
if (GNUNET_YES != res)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client_delete_tunnel client KO\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "client_delete_tunnel client KO\n");
}
}
rel->client_ready = GNUNET_YES;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"send local %s ack on %s:%X towards %p\n",
fwd ? "FWD" : "BCK", peer2s (ch->t->peer), ch->gid, c);