[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r34924 - gnunet/src/rps
From: |
gnunet |
Subject: |
[GNUnet-SVN] r34924 - gnunet/src/rps |
Date: |
Sun, 18 Jan 2015 06:06:13 +0100 |
Author: ch3
Date: 2015-01-18 06:06:13 +0100 (Sun, 18 Jan 2015)
New Revision: 34924
Modified:
gnunet/src/rps/gnunet-service-rps.c
gnunet/src/rps/gnunet-service-rps_sampler.c
gnunet/src/rps/gnunet-service-rps_sampler.h
Log:
fixed integer sizes and _get_rand_peer()
Modified: gnunet/src/rps/gnunet-service-rps.c
===================================================================
--- gnunet/src/rps/gnunet-service-rps.c 2015-01-18 03:23:23 UTC (rev 34923)
+++ gnunet/src/rps/gnunet-service-rps.c 2015-01-18 05:06:13 UTC (rev 34924)
@@ -349,7 +349,7 @@
struct GNUNET_PeerIdentity *
get_rand_peer (const struct GNUNET_PeerIdentity *peer_list, unsigned int
list_size)
{
- uint64_t r_index;
+ uint32_t r_index;
struct GNUNET_PeerIdentity *peer;
peer = GNUNET_new (struct GNUNET_PeerIdentity);
@@ -448,10 +448,10 @@
* Sum all time relatives of an array.
*/
struct GNUNET_TIME_Relative
-T_relative_sum (const struct GNUNET_TIME_Relative *rel_array, uint64_t
arr_size)
+T_relative_sum (const struct GNUNET_TIME_Relative *rel_array, uint32_t
arr_size)
{
struct GNUNET_TIME_Relative sum;
- uint64_t i;
+ uint32_t i;
sum = GNUNET_TIME_UNIT_ZERO;
for ( i = 0 ; i < arr_size ; i++ )
@@ -466,7 +466,7 @@
* Compute the average of given time relatives.
*/
struct GNUNET_TIME_Relative
-T_relative_avg (const struct GNUNET_TIME_Relative *rel_array, uint64_t
arr_size)
+T_relative_avg (const struct GNUNET_TIME_Relative *rel_array, uint32_t
arr_size)
{
return GNUNET_TIME_relative_divide (T_relative_sum (rel_array, arr_size),
arr_size); // FIXME find a way to devide that by arr_size
}
@@ -482,7 +482,7 @@
void
resize_wrapper ()
{
- uint64_t bigger_size;
+ uint32_t bigger_size;
// TODO statistics
@@ -541,8 +541,9 @@
* Sends those to the requesting client.
*/
void client_respond (void *cls,
- struct GNUNET_PeerIdentity *ids, uint64_t num_peers)
+ struct GNUNET_PeerIdentity *ids, uint32_t num_peers)
{
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "sampler returned %" PRIX32 " peers\n",
num_peers);
struct GNUNET_MQ_Envelope *ev;
struct GNUNET_RPS_CS_ReplyMessage *out_msg;
struct GNUNET_SERVER_Client *client;
@@ -553,7 +554,7 @@
ev = GNUNET_MQ_msg_extra (out_msg,
num_peers * sizeof (struct GNUNET_PeerIdentity),
GNUNET_MESSAGE_TYPE_RPS_CS_REPLY);
- out_msg->num_peers = GNUNET_htonll (num_peers);
+ out_msg->num_peers = htonl (num_peers);
memcpy (&out_msg[1],
ids,
@@ -583,10 +584,8 @@
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requested (a) random peer(s).\n");
-
struct GNUNET_RPS_CS_RequestMessage *msg;
- uint64_t num_peers;
+ uint32_t num_peers;
struct GNUNET_TIME_Relative max_round_duration;
@@ -618,6 +617,8 @@
num_peers = ntohl (msg->num_peers);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requested %" PRIX32 " random
peer(s).\n", num_peers);
+
RPS_sampler_get_n_rand_peers (client_respond, client, num_peers);
GNUNET_SERVER_receive_done (client,
@@ -639,7 +640,7 @@
{
struct GNUNET_RPS_CS_SeedMessage *in_msg;
struct GNUNET_PeerIdentity *peers;
- uint64_t i;
+ uint32_t i;
if (sizeof (struct GNUNET_RPS_CS_SeedMessage) < ntohs (message->size))
{
@@ -732,7 +733,7 @@
ev = GNUNET_MQ_msg_extra (out_msg,
gossip_list_size * sizeof (struct
GNUNET_PeerIdentity),
GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY);
- //out_msg->num_peers = GNUNET_htonll (gossip_list_size);
+ //out_msg->num_peers = htonl (gossip_list_size);
out_msg->num_peers = htonl (gossip_list_size);
memcpy (&out_msg[1], gossip_list,
gossip_list_size * sizeof (struct GNUNET_PeerIdentity));
@@ -763,7 +764,7 @@
struct GNUNET_RPS_P2P_PullReplyMessage *in_msg;
struct GNUNET_PeerIdentity *peers;
- uint64_t i;
+ uint32_t i;
if (sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs (msg->size))
{
@@ -805,7 +806,7 @@
{
LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to execute next round\n");
- uint64_t i;
+ uint32_t i;
//unsigned int *n_arr;
unsigned int n_peers; /* Number of peers we send pushes/pulls to */
struct GNUNET_MQ_Envelope *ev;
@@ -865,7 +866,7 @@
/* Update gossip list */
- uint64_t r_index;
+ uint32_t r_index;
if ( push_list_size <= alpha * gossip_list_size &&
push_list_size != 0 &&
@@ -873,8 +874,8 @@
{
LOG (GNUNET_ERROR_TYPE_DEBUG, "Update of the gossip list. ()\n");
- uint64_t first_border;
- uint64_t second_border;
+ uint32_t first_border;
+ uint32_t second_border;
GNUNET_array_grow (gossip_list, gossip_list_size, sampler_size_est_need);
@@ -1081,6 +1082,8 @@
if ( NULL != peer_ctx->from_channel)
GNUNET_CADET_channel_destroy (peer_ctx->from_channel);
+
+ // call _peermap_remove_all()?
return GNUNET_YES;
}
@@ -1098,7 +1101,7 @@
{
LOG (GNUNET_ERROR_TYPE_DEBUG, "RPS is going down\n");
- uint64_t num_peers;
+ uint32_t num_peers;
if ( NULL != do_round_task )
{
Modified: gnunet/src/rps/gnunet-service-rps_sampler.c
===================================================================
--- gnunet/src/rps/gnunet-service-rps_sampler.c 2015-01-18 03:23:23 UTC (rev
34923)
+++ gnunet/src/rps/gnunet-service-rps_sampler.c 2015-01-18 05:06:13 UTC (rev
34924)
@@ -121,13 +121,6 @@
struct RPS_SamplerElement **sampler_elements;
/**
- * Index to a sampler element.
- *
- * Gets cycled on every hist_request.
- */
- uint64_t sampler_elem_index;
-
- /**
* Max time a round takes
*
* Used in the context of RPS
@@ -163,12 +156,12 @@
/**
* Number of peers we are waiting for.
*/
- uint64_t num_peers;
+ uint32_t num_peers;
/**
* Number of peers we currently have.
*/
- uint64_t cur_num_peers;
+ uint32_t cur_num_peers;
/**
* Pointer to the array holding the ids.
@@ -252,7 +245,7 @@
/**
* Inedex to the sampler element that is the next to be returned
*/
-static uint64_t client_get_index;
+static uint32_t client_get_index;
/**
@@ -270,15 +263,15 @@
n_peers_cls = (struct RPS_GetNRandPeersReadyCls *) cls;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "SAMPLER: Got %" PRIX64 "th of %" PRIX64 " peers\n",
+ "SAMPLER: Got %" PRIX32 "th of %" PRIX32 " peers\n",
n_peers_cls->cur_num_peers, n_peers_cls->num_peers);
- if (n_peers_cls->num_peers == n_peers_cls->cur_num_peers)
+ if (n_peers_cls->num_peers - 1 == n_peers_cls->cur_num_peers)
{ /* All peers are ready -- return those to the client */
GNUNET_assert (NULL != n_peers_cls->callback);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "SAMPLER: returning %" PRIX64 " peers to the client\n",
+ "SAMPLER: returning %" PRIX32 " peers to the client\n",
n_peers_cls->num_peers);
n_peers_cls->callback (n_peers_cls->cls, n_peers_cls->ids,
n_peers_cls->num_peers);
@@ -423,7 +416,7 @@
RPS_sampler_resize (unsigned int new_size)
{
unsigned int old_size;
- uint64_t i;
+ uint32_t i;
struct RPS_SamplerElement **rem_list;
// TODO check min and max size
@@ -446,7 +439,7 @@
for (i = 0 ; i < old_size - new_size ; i++)
{/* Remove unneeded rest */
- LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Removing %" PRIX64 ".
sampler\n", i);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Removing %" PRIX32 ".
sampler\n", i);
if (NULL != sampler->remove_cb)
sampler->remove_cb (sampler->remove_cls, &rem_list[i]->peer_id);
GNUNET_free (rem_list[i]);
@@ -467,7 +460,7 @@
if (NULL != sampler->insert_cb)
sampler->insert_cb (sampler->insert_cls,
&sampler->sampler_elements[i]->peer_id);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "SAMPLER: Added %" PRIX64 ". sampler, now pointing to %p, contains
%s\n",
+ "SAMPLER: Added %" PRIX32 ". sampler, now pointing to %p, contains
%s\n",
i, &sampler->sampler_elements[i], GNUNET_i2s
(&sampler->sampler_elements[i]->peer_id));
}
}
@@ -502,7 +495,7 @@
RPS_sampler_remove_cb rem_cb, void *rem_cls)
{
//struct RPS_Sampler *sampler;
- //uint64_t i;
+ //uint32_t i;
/* Initialise context around extended sampler */
min_size = 10; // TODO make input to _samplers_init()
@@ -536,7 +529,7 @@
void
RPS_sampler_update_list (const struct GNUNET_PeerIdentity *id)
{
- uint64_t i;
+ uint32_t i;
for ( i = 0 ; i < sampler->sampler_size ; i++ )
RPS_sampler_elem_next (sampler->sampler_elements[i], id,
@@ -555,7 +548,7 @@
void
RPS_sampler_reinitialise_by_value (const struct GNUNET_PeerIdentity *id)
{
- uint64_t i;
+ uint32_t i;
for ( i = 0 ; i < sampler->sampler_size ; i++ )
{
@@ -578,7 +571,7 @@
const struct GNUNET_PeerIdentity *
RPS_sampler_get_rand_peer_ ()
{
- uint64_t r_index;
+ uint32_t r_index;
const struct GNUNET_PeerIdentity *peer; // do we have to malloc that?
// TODO implement extra logic
@@ -611,7 +604,7 @@
* Only used internally
*/
const struct GNUNET_PeerIdentity *
-RPS_sampler_get_n_rand_peers_ (uint64_t n)
+RPS_sampler_get_n_rand_peers_ (uint32_t n)
{
if ( 0 == sampler->sampler_size )
{
@@ -624,7 +617,7 @@
// TODO check if we have too much (distinct) sampled peers
// If we are not ready yet maybe schedule for later
struct GNUNET_PeerIdentity *peers;
- uint64_t i;
+ uint32_t i;
peers = GNUNET_malloc (n * sizeof(struct GNUNET_PeerIdentity));
@@ -654,23 +647,41 @@
struct RPS_SamplerElement *s_elem;
struct GNUNET_TIME_Relative last_request_diff;
struct GNUNET_HashCode *hash;
+ uint32_t tmp_client_get_index;
//struct GNUNET_TIME_Relative inv_last_request_diff;
LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Single peer was requested\n");
gpc = (struct GetPeerCls *) cls;
hash = GNUNET_new (struct GNUNET_HashCode);
+ if (0 < client_get_index)
+ tmp_client_get_index = client_get_index - 1;
+ else
+ tmp_client_get_index = sampler->sampler_size - 1;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "SAMPLER: scheduling for later if index reaches %" PRIX32 " (sampler
size: %" PRIX32 ".\n",
+ tmp_client_get_index, sampler->sampler_size);
+
do
{ /* Get first non empty sampler */
- // TODO schedule for later if all samplers are empty
+ if (tmp_client_get_index == client_get_index)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: reached tmp_index %" PRIX32
".\n", client_get_index);
+ gpc->get_peer_task = GNUNET_SCHEDULER_add_delayed
(sampler->max_round_interval,
+
&RPS_sampler_get_rand_peer,
+ cls);
+ return;
+ }
+
*gpc->id = sampler->sampler_elements[client_get_index]->peer_id;
RPS_sampler_elem_reinit (sampler->sampler_elements[client_get_index]);
- if ( client_get_index == sampler->sampler_size )
+ if ( client_get_index == sampler->sampler_size - 1 )
client_get_index = 0;
else
client_get_index++;
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: incremented index to %" PRIX32
".\n", client_get_index);
} while (EMPTY == sampler->sampler_elements[client_get_index]->is_empty);
s_elem = sampler->sampler_elements[client_get_index];
@@ -698,7 +709,7 @@
// TODO add other reasons to wait here
}
- GNUNET_CRYPTO_hash (gpc->get_peer_task, sizeof (struct GNUNET_SCHEDULER_Task
*), hash);
+ GNUNET_CRYPTO_hash (&gpc->get_peer_task, sizeof (struct
GNUNET_SCHEDULER_Task *), hash);
if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_remove (get_peer_tasks, hash,
gpc->get_peer_task))
LOG (GNUNET_ERROR_TYPE_WARNING, "SAMPLER: Key to remove is not in the
hashmap\n");
GNUNET_free (gpc->get_peer_task);
@@ -722,7 +733,7 @@
*/
void
RPS_sampler_get_n_rand_peers (RPS_sampler_n_rand_peers_ready_cb cb,
- void *cls, uint64_t num_peers)
+ void *cls, uint32_t num_peers)
{
if ( 0 == sampler->sampler_size )
{
@@ -734,35 +745,33 @@
{
// TODO check if we have too much (distinct) sampled peers
// If we are not ready yet maybe schedule for later
- struct GNUNET_PeerIdentity *peers;
- uint64_t i;
+ uint32_t i;
struct RPS_GetNRandPeersReadyCls *cb_cls;
struct GetPeerCls *gpc;
struct GNUNET_HashCode *hash;
-
- peers = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
+
hash = GNUNET_new (struct GNUNET_HashCode);
cb_cls = GNUNET_new (struct RPS_GetNRandPeersReadyCls);
cb_cls->num_peers = num_peers;
cb_cls->cur_num_peers = 0;
- cb_cls->ids = peers;
+ cb_cls->ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
cb_cls->callback = cb;
cb_cls->cls = cls;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "SAMPLER: Scheduling requests for %" PRIX64 " peers\n", num_peers);
+ "SAMPLER: Scheduling requests for %" PRIX32 " peers\n", num_peers);
for ( i = 0 ; i < num_peers ; i++ )
{
gpc = GNUNET_new (struct GetPeerCls);
gpc->cb = RPS_sampler_get_n_rand_peers_ready_cb;
gpc->cb_cls = cb_cls;
- gpc->id = &peers[i];
+ gpc->id = &cb_cls->ids[i];
// maybe add a little delay
gpc->get_peer_task = GNUNET_SCHEDULER_add_now
(&RPS_sampler_get_rand_peer, gpc);
- GNUNET_CRYPTO_hash (gpc->get_peer_task, sizeof (struct
GNUNET_SCHEDULER_Task *), hash);
+ GNUNET_CRYPTO_hash (&gpc->get_peer_task, sizeof (struct
GNUNET_SCHEDULER_Task *), hash);
(void) GNUNET_CONTAINER_multihashmap_put (get_peer_tasks, hash,
gpc->get_peer_task,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
//RPS_sampler_get_rand_peer (RPS_sampler_get_n_rand_peers_ready_cb,
@@ -779,11 +788,11 @@
*
* @return the number of occurrences of id.
*/
- uint64_t
+ uint32_t
RPS_sampler_count_id (const struct GNUNET_PeerIdentity *id)
{
- uint64_t count;
- uint64_t i;
+ uint32_t count;
+ uint32_t i;
count = 0;
for ( i = 0 ; i < sampler->sampler_size ; i++ )
Modified: gnunet/src/rps/gnunet-service-rps_sampler.h
===================================================================
--- gnunet/src/rps/gnunet-service-rps_sampler.h 2015-01-18 03:23:23 UTC (rev
34923)
+++ gnunet/src/rps/gnunet-service-rps_sampler.h 2015-01-18 05:06:13 UTC (rev
34924)
@@ -57,7 +57,7 @@
*/
typedef void
(*RPS_sampler_n_rand_peers_ready_cb) (void *cls,
- struct GNUNET_PeerIdentity *ids, uint64_t num_peers);
+ struct GNUNET_PeerIdentity *ids, uint32_t num_peers);
/**
@@ -124,7 +124,7 @@
* Only used internally
*/
const struct GNUNET_PeerIdentity *
-RPS_sampler_get_n_rand_peers_ (uint64_t n);
+RPS_sampler_get_n_rand_peers_ (uint32_t n);
/**
@@ -140,7 +140,7 @@
*/
void
RPS_sampler_get_n_rand_peers (RPS_sampler_n_rand_peers_ready_cb cb,
- void *cls, uint64_t num_peers);
+ void *cls, uint32_t num_peers);
/**
@@ -150,7 +150,7 @@
*
* @return the number of occurrences of id.
*/
- uint64_t
+ uint32_t
RPS_sampler_count_id (const struct GNUNET_PeerIdentity *id);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r34924 - gnunet/src/rps,
gnunet <=