+/**
+ * Add all peers in @a peer_array to @peer_map used as set.
+ *
+ * @param peer_array array containing the peers
+ * @param num_peers number of peers in @peer_array
+ * @param peer_map the peermap to use as set
+ */
+static void
+add_peer_array_to_set (const struct GNUNET_PeerIdentity *peer_array,
+ unsigned int num_peers,
+ struct GNUNET_CONTAINER_MultiPeerMap *peer_map)
+{
+ unsigned int i;
+ if (NULL == peer_map)
+ peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers,
+ GNUNET_NO);
+ for (i = 0 ; i < num_peers ; i++)
+ {
+ GNUNET_CONTAINER_multipeermap_put (peer_map,
+ &peer_array[i],
+ NULL,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+ }
+}
+
+
+/**
+ * Send a PULL REPLY to @a peer_id
+ *
+ * @param peer_id the peer to send the reply to.
+ * @param peer_ids the peers to send to @a peer_id
+ * @param num_peer_ids the number of peers to send to @a peer_id
+ */
+static void
+send_pull_reply (const struct GNUNET_PeerIdentity *peer_id,
+ const struct GNUNET_PeerIdentity *peer_ids,
+ unsigned int num_peer_ids)
+{
+ uint32_t send_size;
+ struct GNUNET_MQ_Handle *mq;
+ struct GNUNET_MQ_Envelope *ev;
+ struct GNUNET_RPS_P2P_PullReplyMessage *out_msg;
+
+ /* Compute actual size */
+ send_size = sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) +
+ num_peer_ids * sizeof (struct GNUNET_PeerIdentity);
+
+ if (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < send_size)
+ /* Compute number of peers to send
+ * If too long, simply truncate */
+ // TODO select random ones via permutation
+ // or even better: do good protocol design
+ send_size =
+ (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE -
+ sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) /
+ sizeof (struct GNUNET_PeerIdentity);
+ else
+ send_size = num_peer_ids;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "PULL REQUEST from peer %s received, going to send %u peers\n",
+ GNUNET_i2s (peer_id), send_size);
+
+ mq = get_mq (peer_map, peer_id);
+
+ ev = GNUNET_MQ_msg_extra (out_msg,
+ send_size * sizeof (struct GNUNET_PeerIdentity),
+ GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY);
+ out_msg->num_peers = htonl (send_size);
+ memcpy (&out_msg[1], peer_ids,
+ send_size * sizeof (struct GNUNET_PeerIdentity));
+
+ GNUNET_MQ_send (mq, ev);
+}
+
+