if (GMC_is_pid_bigger (pid, t->prev_fc.last_pid_recv)
&&
(GNUNET_NO == t->reliable ||
- GNUNET_ntohll (msg->mid) == (t->bck_rel->mid_recv + 1)) )
+ (GNUNET_ntohll (msg->mid) == (t->bck_rel->mid_recv + 1) &&
+ t->bck_rel->mid_recv++)
+ )
+ )
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
" pid %u not seen yet, forwarding\n", pid);
t->prev_fc.last_pid_recv = pid;
- t->bck_rel->mid_recv++;
tunnel_send_client_ucast (t, msg);
}
else
/******************************************************************************/
+/**
+ * Handler for client connection.
+ *
+ * @param cls Closure (unused).
+ * @param client Client handler.
+ */
+static void
+handle_local_client_connect (void *cls, struct GNUNET_SERVER_Client *client)
+{
+ struct MeshClient *c;
+
+ if (NULL == client)
+ return;
+ c = GNUNET_malloc (sizeof (struct MeshClient));
+ c->handle = client;
+ GNUNET_SERVER_client_keep (client);
+ GNUNET_SERVER_client_set_user_context (client, c);
+ GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c);
+}
+
+
/**
* Handler for client disconnection
*
c->id);
GNUNET_SERVER_client_drop (c->handle);
c->shutting_down = GNUNET_YES;
- GNUNET_CONTAINER_multihashmap32_iterate (c->own_tunnels,
- &tunnel_destroy_iterator, c);
- GNUNET_CONTAINER_multihashmap32_iterate (c->incoming_tunnels,
+ if (NULL != c->own_tunnels)
+ {
+ GNUNET_CONTAINER_multihashmap32_iterate (c->own_tunnels,
+ &tunnel_destroy_iterator, c);
+ GNUNET_CONTAINER_multihashmap32_destroy (c->own_tunnels);
+ }
+
+ if (NULL != c->incoming_tunnels)
+ {
+ GNUNET_CONTAINER_multihashmap32_iterate (c->incoming_tunnels,
&tunnel_destroy_iterator, c);
- GNUNET_CONTAINER_multihashmap32_destroy (c->own_tunnels);
- GNUNET_CONTAINER_multihashmap32_destroy (c->incoming_tunnels);
+ GNUNET_CONTAINER_multihashmap32_destroy (c->incoming_tunnels);
+ }
if (NULL != c->ports)
GNUNET_CONTAINER_multihashmap32_destroy (c->ports);
}
size /= sizeof (uint32_t);
- /* Create new client structure */
- c = GNUNET_malloc (sizeof (struct MeshClient));
+ /* Initialize new client structure */
+ c = GNUNET_SERVER_client_get_user_context (client, struct MeshClient);
c->id = next_client_id++; /* overflow not important: just for debug */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client id %u\n", c->id);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client has %u ports\n", size);
- c->handle = client;
- GNUNET_SERVER_client_keep (client);
- GNUNET_SERVER_client_set_user_context (client, c);
if (size > 0)
{
uint32_t u32;
}
}
- GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c);
c->own_tunnels = GNUNET_CONTAINER_multihashmap32_create (32);
c->incoming_tunnels = GNUNET_CONTAINER_multihashmap32_create (32);
GNUNET_SERVER_notification_context_add (nc, client);
server_init (void)
{
GNUNET_SERVER_add_handlers (server_handle, client_handlers);
+ GNUNET_SERVER_connect_notify (server_handle,
+ &handle_local_client_connect, NULL);
GNUNET_SERVER_disconnect_notify (server_handle,
&handle_local_client_disconnect, NULL);
nc = GNUNET_SERVER_notification_context_create (server_handle, 1);