aboutsummaryrefslogtreecommitdiff
path: root/src/rps/rps_api.c
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2015-01-27 16:09:07 +0000
committerJulius Bünger <buenger@mytum.de>2015-01-27 16:09:07 +0000
commita02cd5c8e35615551bb8240f2ce744fb5164fe5d (patch)
treed191b0f9f9539cde5e82700024e181b0618ee3cc /src/rps/rps_api.c
parent92627182d83bb49b07e6f0a78285ca8b3a2fd4d9 (diff)
downloadgnunet-a02cd5c8e35615551bb8240f2ce744fb5164fe5d.tar.gz
gnunet-a02cd5c8e35615551bb8240f2ce744fb5164fe5d.zip
fixed _seed() funktion
Diffstat (limited to 'src/rps/rps_api.c')
-rw-r--r--src/rps/rps_api.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c
index d7e3fc4ed..a2cdd0fba 100644
--- a/src/rps/rps_api.c
+++ b/src/rps/rps_api.c
@@ -217,6 +217,7 @@ GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *h, uint32_t n,
217 return rh; 217 return rh;
218} 218}
219 219
220
220/** 221/**
221 * Seed rps service with peerIDs. 222 * Seed rps service with peerIDs.
222 * 223 *
@@ -229,33 +230,40 @@ GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, uint64_t n,
229 const struct GNUNET_PeerIdentity * ids) 230 const struct GNUNET_PeerIdentity * ids)
230{ 231{
231 uint32_t size_needed; 232 uint32_t size_needed;
232 uint32_t tmp_num_peers; 233 uint32_t num_peers_max;
234 const struct GNUNET_PeerIdentity *tmp_peer_pointer;
233 struct GNUNET_MQ_Envelope *ev; 235 struct GNUNET_MQ_Envelope *ev;
234 struct GNUNET_RPS_CS_SeedMessage *msg; 236 struct GNUNET_RPS_CS_SeedMessage *msg;
235 237
238 /* The actual size the message occupies */
236 size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) + 239 size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
237 n * sizeof (struct GNUNET_PeerIdentity); 240 n * sizeof (struct GNUNET_PeerIdentity);
241 /* The number of peers that fits in one message together with
242 * the respective header */
243 num_peers_max = (GNUNET_SERVER_MAX_MESSAGE_SIZE -
244 sizeof (struct GNUNET_RPS_CS_SeedMessage)) /
245 sizeof (struct GNUNET_PeerIdentity);
246 tmp_peer_pointer = ids;
238 247
239 while (GNUNET_SERVER_MAX_MESSAGE_SIZE < size_needed) 248 while (GNUNET_SERVER_MAX_MESSAGE_SIZE < size_needed)
240 { 249 {
241 tmp_num_peers = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 250 ev = GNUNET_MQ_msg_extra (msg, num_peers_max * sizeof (struct GNUNET_PeerIdentity),
242 sizeof (struct GNUNET_RPS_CS_SeedMessage)) /
243 sizeof (struct GNUNET_PeerIdentity);
244 n -= tmp_num_peers;
245 size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
246 n * sizeof (struct GNUNET_PeerIdentity);
247
248 ev = GNUNET_MQ_msg_extra (msg, tmp_num_peers * sizeof (struct GNUNET_PeerIdentity),
249 GNUNET_MESSAGE_TYPE_RPS_CS_SEED); 251 GNUNET_MESSAGE_TYPE_RPS_CS_SEED);
250 msg->num_peers = GNUNET_htonll (tmp_num_peers); 252 msg->num_peers = ntohl (num_peers_max);
251 memcpy (&msg[1], ids, tmp_num_peers * sizeof (struct GNUNET_PeerIdentity)); 253 memcpy (&msg[1], tmp_peer_pointer, num_peers_max * sizeof (struct GNUNET_PeerIdentity));
252 GNUNET_MQ_send (h->mq, ev); 254 GNUNET_MQ_send (h->mq, ev);
255
256 n -= num_peers_max;
257 size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
258 n * sizeof (struct GNUNET_PeerIdentity);
259 /* Set pointer to beginning of next block of num_peers_max peers */
260 tmp_peer_pointer = &ids[num_peers_max];
253 } 261 }
254 262
255 ev = GNUNET_MQ_msg_extra (msg, n * sizeof (struct GNUNET_PeerIdentity), 263 ev = GNUNET_MQ_msg_extra (msg, n * sizeof (struct GNUNET_PeerIdentity),
256 GNUNET_MESSAGE_TYPE_RPS_CS_SEED); 264 GNUNET_MESSAGE_TYPE_RPS_CS_SEED);
257 msg->num_peers = GNUNET_htonll (n); 265 msg->num_peers = GNUNET_htonll (n);
258 memcpy (&msg[1], ids, n * sizeof (struct GNUNET_PeerIdentity)); 266 memcpy (&msg[1], tmp_peer_pointer, n * sizeof (struct GNUNET_PeerIdentity));
259 GNUNET_MQ_send (h->mq, ev); 267 GNUNET_MQ_send (h->mq, ev);
260} 268}
261 269