+/**
+ * Add all peers in @a peer_array to @a 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)
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Trying to add peers to an empty peermap.\n");
+ return;
+ }
+
+ 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);
+}
+
+
+/**
+ * This function is called on new peer_ids from 'external' sources
+ * (client seed, cadet get_peers(), ...)
+ *
+ * @param peer_id the new peer_id
+ */
+static void
+new_peer_id (const struct GNUNET_PeerIdentity *peer_id)
+{
+ struct PeerOutstandingOp out_op;
+ struct PeerContext *peer_ctx;
+
+ if (NULL != peer_id &&
+ 0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, peer_id))
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Got peer_id %s (at %p, view size: %u)\n",
+ GNUNET_i2s (peer_id),
+ peer_id,
+ GNUNET_CONTAINER_multipeermap_size (view));
+
+ peer_ctx = get_peer_ctx (peer_map, peer_id);
+ if (GNUNET_YES != get_peer_flag (peer_ctx, VALID))
+ {
+ if (GNUNET_NO == insert_in_sampler_scheduled (peer_ctx))
+ {
+ out_op.op = insert_in_sampler;
+ out_op.op_cls = NULL;
+ GNUNET_array_append (peer_ctx->outstanding_ops,
+ peer_ctx->num_outstanding_ops,
+ out_op);
+ }
+
+ if (GNUNET_NO == insert_in_view_scheduled (peer_ctx))
+ {
+ out_op.op = insert_in_view;
+ out_op.op_cls = NULL;
+ GNUNET_array_append (peer_ctx->outstanding_ops,
+ peer_ctx->num_outstanding_ops,
+ out_op);
+ }
+
+ /* Trigger livelyness test on peer */
+ check_peer_live (peer_ctx);
+ }
+ // else...?
+
+ // send push/pull to each of those peers?
+ }
+}
+
+