+/**
+ * Find the first peer whom to send a packet to go down this path
+ *
+ * @param t The tunnel tree to use
+ * @param peer The peerinfo of the peer we are trying to reach
+ *
+ * @return peerinfo of the peer who is the first hop in the tunnel
+ * NULL on error
+ */
+struct GNUNET_PeerIdentity *
+tree_get_first_hop (struct MeshTunnelTree *t, GNUNET_PEER_Id peer)
+{
+ struct GNUNET_PeerIdentity id;
+ struct GNUNET_PeerIdentity *r;
+
+ GNUNET_PEER_resolve (peer, &id);
+ r = GNUNET_CONTAINER_multihashmap_get (t->first_hops, &id.hashPubKey);
+ if (NULL == r)
+ {
+ struct MeshTunnelTreeNode *n;
+
+ n = tree_find_peer (t, peer);
+ if (NULL != t->me && NULL != n)
+ {
+ tree_node_update_first_hops (t, n, NULL);
+ r = GNUNET_CONTAINER_multihashmap_get (t->first_hops, &id.hashPubKey);
+ GNUNET_assert (NULL != r);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Tree structure inconsistent! me: %p, n: %p", t->me, n);
+ GNUNET_break (0);
+ }
+ }
+
+ return r;
+}
+
+