+/**
+ * Connect to the mesh service.
+ *
+ * @param cfg configuration to use
+ * @param queue_size size of the data message queue, shared among all tunnels
+ * (each tunnel is guaranteed to accept at least one message,
+ * no matter what is the status of other tunnels)
+ * @param cls closure for the various callbacks that follow
+ * (including handlers in the handlers array)
+ * @param new_tunnel function called when an *inbound* tunnel is created
+ * @param cleaner function called when an *inbound* tunnel is destroyed
+ * @param handlers callbacks for messages we care about, NULL-terminated
+ * note that the mesh is allowed to drop notifications about
+ * inbound messages if the client does not process them fast
+ * enough (for this notification type, a bounded queue is used)
+ * @param stypes list of the applications that this client claims to provide
+ * @return handle to the mesh service NULL on error
+ * (in this case, init is never called)
+ */
+struct GNUNET_MESH_Handle *
+GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ unsigned int queue_size, void *cls,
+ GNUNET_MESH_InboundTunnelNotificationHandler new_tunnel,
+ GNUNET_MESH_TunnelEndHandler cleaner,
+ const struct GNUNET_MESH_MessageHandler *handlers,
+ const GNUNET_MESH_ApplicationType *stypes)
+{
+ struct GNUNET_MESH_Handle *h;
+
+ 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;
+ h->new_tunnel = new_tunnel;
+ h->cleaner = cleaner;
+ h->client = GNUNET_CLIENT_connect ("mesh", cfg);
+ if (h->client == NULL)
+ {
+ GNUNET_break (0);
+ GNUNET_free (h);
+ return NULL;
+ }
+ h->cls = cls;
+ /* FIXME memdup? */
+ h->applications = stypes;
+ h->message_handlers = handlers;
+ h->next_tid = GNUNET_MESH_LOCAL_TUNNEL_ID_CLI;
+ h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS;
+
+ /* 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);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect() END\n");
+ return h;
+}