- struct RPS_SamplerElement *s;
-
- s = GNUNET_new (struct RPS_SamplerElement);
-
- RPS_sampler_elem_reinit (s);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: initialised with empty PeerID\n");
-
- return s;
-}
-
-
-/**
- * Input an PeerID into the given sampler.
- */
- static void
-RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, const struct GNUNET_PeerIdentity *other,
- RPS_sampler_insert_cb insert_cb, void *insert_cls,
- RPS_sampler_remove_cb remove_cb, void *remove_cls)
-{
- struct GNUNET_HashCode other_hash;
-
- if ( 0 == GNUNET_CRYPTO_cmp_peer_identity(other, &(s_elem->peer_id)) )
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Got PeerID %s\n",
- GNUNET_i2s(other));
- LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Have already PeerID %s\n",
- GNUNET_i2s(&(s_elem->peer_id)));
- }
- else
- {
- GNUNET_CRYPTO_hmac(&s_elem->auth_key,
- other,
- sizeof(struct GNUNET_PeerIdentity),
- &other_hash);
-
- if ( EMPTY == s_elem->is_empty )
- { // Or whatever is a valid way to say
- // "we have no PeerID at the moment"
- LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Got PeerID %s; Simply accepting (was empty previously).\n",
- GNUNET_i2s(other));
- s_elem->peer_id = *other;
- //s_elem->peer_id = other;
- s_elem->peer_id_hash = other_hash;
- if (NULL != sampler->insert_cb)
- {
- sampler->insert_cb(sampler->insert_cls, &(s_elem->peer_id));
- }
- }
- else if ( 0 > GNUNET_CRYPTO_hash_cmp(&other_hash, &s_elem->peer_id_hash) )
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Got PeerID %s\n",
- GNUNET_i2s(other));
- LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Discarding old PeerID %s\n",
- GNUNET_i2s(&s_elem->peer_id));
-
- if ( NULL != sampler->remove_cb )
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Removing old PeerID %s with the remove callback.\n",
- GNUNET_i2s(&s_elem->peer_id));
- sampler->remove_cb(sampler->remove_cls, &s_elem->peer_id);
- }
-
- memcpy(&s_elem->peer_id, other, sizeof(struct GNUNET_PeerIdentity));
- //s_elem->peer_id = other;
- s_elem->peer_id_hash = other_hash;
-
- if ( NULL != sampler->insert_cb )
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Inserting new PeerID %s with the insert callback.\n",
- GNUNET_i2s(&s_elem->peer_id));
- sampler->insert_cb(sampler->insert_cls, &s_elem->peer_id);
- }
- }
- else
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Got PeerID %s\n",
- GNUNET_i2s(other));
- LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Keeping old PeerID %s\n",
- GNUNET_i2s(&s_elem->peer_id));
- }
- }
- s_elem->is_empty = NOT_EMPTY;