+/**
+ * Receive a message from core.
+ * This is a hello-message, containing the message-types the other peer can receive
+ */
+static int
+receive_hello (void *cls,
+ const struct GNUNET_PeerIdentity *other,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+{
+ struct GNUNET_MESH_Handle *handle = cls;
+ uint16_t *num = (uint16_t *) (message + 1);
+ uint16_t *ports = num + 1;
+ unsigned int i;
+
+ struct peer_list_element *element = handle->connected_peers.head;
+ while (element != NULL)
+ {
+ if (0 ==
+ memcmp (&element->peer, other, sizeof (struct GNUNET_PeerIdentity)))
+ break;
+ element = element->next;
+ }
+
+ /* TODO: add, not replace! */
+ /* TODO: if this changes anything: send new hello */
+ element->num_types = *num;
+ element->types = GNUNET_malloc (*num * sizeof (GNUNET_MESH_ApplicationType));
+
+ for (i = 0; i < *num; i++)
+ element->types[i] = (GNUNET_MESH_ApplicationType)ntohs (ports[i]);
+
+ struct tunnel_list_element *tunnel = handle->pending_by_type_tunnels.head;
+ while (tunnel != NULL)
+ {
+ struct tunnel_list_element *next = tunnel->next;
+ for (i = 0; i < *num; i++)
+ {
+ if (ntohs (ports[i]) == tunnel->tunnel.message_type)
+ {
+ GNUNET_CONTAINER_DLL_remove (handle->pending_tunnels.head,
+ handle->pending_tunnels.tail,
+ tunnel);
+ GNUNET_CONTAINER_DLL_insert_after (handle->established_tunnels.
+ head,
+ handle->established_tunnels.
+ tail,
+ handle->established_tunnels.
+ tail, tunnel);
+ tunnel->tunnel.connect_handler (tunnel->tunnel.handler_cls,
+ &tunnel->tunnel.peer, atsi);
+ GNUNET_SCHEDULER_add_now (send_end_connect, tunnel);
+ break;
+ }
+ }
+ if (ntohs (ports[i]) == tunnel->tunnel.message_type)
+ tunnel = next;
+ else
+ tunnel = tunnel->next;
+ }
+ return GNUNET_OK;
+}
+