+ dest_peer_info =
+ GNUNET_CONTAINER_multihashmap_get (peers, &pi[size - 1].hashPubKey);
+ if (NULL == dest_peer_info)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "MESH: Creating PeerInfo for destination.\n");
+ dest_peer_info = GNUNET_malloc (sizeof (struct MeshPeerInfo));
+ dest_peer_info->id = GNUNET_PEER_intern (&pi[size - 1]);
+ GNUNET_CONTAINER_multihashmap_put (peers, &pi[size - 1].hashPubKey,
+ dest_peer_info,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ }
+ orig_peer_info = GNUNET_CONTAINER_multihashmap_get (peers, &pi->hashPubKey);
+ if (NULL == orig_peer_info)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "MESH: Creating PeerInfo for origin.\n");
+ orig_peer_info = GNUNET_malloc (sizeof (struct MeshPeerInfo));
+ orig_peer_info->id = GNUNET_PEER_intern (pi);
+ GNUNET_CONTAINER_multihashmap_put (peers, &pi->hashPubKey, orig_peer_info,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Creating path...\n");
+ path = path_new (size);
+ own_pos = 0;
+ for (i = 0; i < size; i++)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: ... adding %s\n",
+ GNUNET_i2s (&pi[i]));
+ path->peers[i] = GNUNET_PEER_intern (&pi[i]);
+ if (path->peers[i] == myid)
+ own_pos = i;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Own position: %u\n", own_pos);
+ if (own_pos == 0)
+ {
+ /* cannot be self, must be 'not found' */
+ /* create path: self not found in path through self */
+ GNUNET_break_op (0);
+ path_destroy (path);
+ /* FIXME error. destroy tunnel? leave for timeout? */
+ return 0;
+ }
+ path_add_to_peers (path, GNUNET_NO);
+ tunnel_add_path (t, path, own_pos);
+ if (own_pos == size - 1)
+ {
+ /* It is for us! Send ack. */
+ struct MeshTransmissionDescriptor *info;
+ unsigned int j;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: It's for us!\n");
+ peer_info_add_path_to_origin (orig_peer_info, path, GNUNET_NO);
+ if (NULL == t->peers)
+ {
+ /* New tunnel! Notify clients! */
+ struct GNUNET_MESH_TunnelNotification cmsg;
+
+ cmsg.header.size = htons (sizeof (cmsg));
+ cmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE);
+ GNUNET_PEER_resolve (t->id.oid, &cmsg.peer);
+ cmsg.tunnel_id = htonl (t->local_tid);
+ GNUNET_SERVER_notification_context_broadcast (nc, &cmsg.header,
+ GNUNET_NO);
+
+ t->peers = GNUNET_CONTAINER_multihashmap_create (4);
+ }
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (t->peers,
+ &my_full_id.hashPubKey,
+ peer_info_get
+ (&my_full_id),
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
+ /* FIXME use send_message */
+ info = GNUNET_malloc (sizeof (struct MeshTransmissionDescriptor));
+ info->origin = &t->id;
+ info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
+ GNUNET_assert (NULL != info->peer);
+ j = peer_info_transmit_slot (info->peer);
+ info->handler_n = j;
+ info->peer->types[j] = GNUNET_MESSAGE_TYPE_MESH_PATH_ACK;
+ info->peer->infos[j] = info;
+ info->peer->core_transmit[j] =
+ GNUNET_CORE_notify_transmit_ready (core_handle, 0, 100,
+ GNUNET_TIME_UNIT_FOREVER_REL, peer,
+ sizeof (struct GNUNET_MESH_PathACK),
+ &send_core_path_ack, info);
+ }
+ else
+ {
+ struct MeshPeerPath *path2;
+
+ /* It's for somebody else! Retransmit. */
+ path2 = path_duplicate (path);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Retransmitting.\n");
+ peer_info_add_path (dest_peer_info, path2, GNUNET_NO);
+ path2 = path_duplicate (path);
+ peer_info_add_path_to_origin (orig_peer_info, path2, GNUNET_NO);
+ send_create_path (dest_peer_info, path, t);
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Core handler for path destruction
+ *
+ * @param cls closure
+ * @param message message
+ * @param peer peer identity this notification is about
+ * @param atsi performance data
+ * @param atsi_count number of records in 'atsi'
+ *
+ * @return GNUNET_OK to keep the connection open,
+ * GNUNET_SYSERR to close it (signal serious error)
+ */
+static int
+handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
+{
+ struct GNUNET_MESH_ManipulatePath *msg;
+ struct GNUNET_PeerIdentity *pi;
+ struct MeshPeerPath *path;
+ struct MeshTunnel *t;
+ unsigned int own_pos;
+ unsigned int i;
+ size_t size;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "MESH: Received a PATH DESTROY msg from %s\n", GNUNET_i2s (peer));
+ size = ntohs (message->size);
+ if (size < sizeof (struct GNUNET_MESH_ManipulatePath))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_OK;
+ }
+
+ size -= sizeof (struct GNUNET_MESH_ManipulatePath);
+ if (size % sizeof (struct GNUNET_PeerIdentity))