summaryrefslogtreecommitdiff
path: root/src/rps/rps_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rps/rps_api.c')
-rw-r--r--src/rps/rps_api.c57
1 files changed, 55 insertions, 2 deletions
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c
index 42102eef7..30f0a75c5 100644
--- a/src/rps/rps_api.c
+++ b/src/rps/rps_api.c
@@ -311,8 +311,61 @@ GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
311 uint32_t num_peers, 311 uint32_t num_peers,
312 const struct GNUNET_PeerIdentity *ids) 312 const struct GNUNET_PeerIdentity *ids)
313{ 313{
314 uint32_t size_needed;
315 uint32_t num_peers_max;
316 const struct GNUNET_PeerIdentity *tmp_peer_pointer;
317 struct GNUNET_MQ_Envelope *ev;
318 struct GNUNET_RPS_CS_ActMaliciousMessage *msg;
319
320 unsigned int i;
321
322 LOG (GNUNET_ERROR_TYPE_DEBUG,
323 "Client turns malicious with %" PRIX32 " other peers:\n",
324 n);
325 for (i = 0 ; i < n ; i++)
326 LOG (GNUNET_ERROR_TYPE_DEBUG,
327 "%u. peer: %s\n",
328 i,
329 GNUNET_i2s (&ids[i]));
330
331 /* The actual size the message occupies */
332 size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
333 n * sizeof (struct GNUNET_PeerIdentity);
334 /* The number of peers that fits in one message together with
335 * the respective header */
336 num_peers_max = (GNUNET_SERVER_MAX_MESSAGE_SIZE -
337 sizeof (struct GNUNET_RPS_CS_SeedMessage)) /
338 sizeof (struct GNUNET_PeerIdentity);
339 tmp_peer_pointer = ids;
340
341 while (GNUNET_SERVER_MAX_MESSAGE_SIZE < size_needed)
342 {
343 ev = GNUNET_MQ_msg_extra (msg,
344 num_peers_max * sizeof (struct GNUNET_PeerIdentity),
345 GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS);
346 msg->type = ntohl (type);
347 msg->num_peers = ntohl (num_peers_max);
348 memcpy (&msg[1], tmp_peer_pointer, num_peers_max * sizeof (struct GNUNET_PeerIdentity));
349 GNUNET_MQ_send (h->mq, ev);
350
351 n -= num_peers_max;
352 size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
353 n * sizeof (struct GNUNET_PeerIdentity);
354 /* Set pointer to beginning of next block of num_peers_max peers */
355 tmp_peer_pointer = &ids[num_peers_max];
356 }
357
358 ev = GNUNET_MQ_msg_extra (msg,
359 n * sizeof (struct GNUNET_PeerIdentity),
360 GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS);
361 msg->type = htonl (type);
362 msg->num_peers = htonl (n);
363 memcpy (&msg[1], tmp_peer_pointer, n * sizeof (struct GNUNET_PeerIdentity));
364
365 GNUNET_MQ_send (h->mq, ev);
366
314} 367}
315#endif 368#endif /* ENABLE_MALICIOUS */
316 369
317 370
318/** 371/**
@@ -335,7 +388,7 @@ GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh)
335 void 388 void
336GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h) 389GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h)
337{ 390{
338 if ( NULL != h->conn ) 391 if (NULL != h->conn)
339 GNUNET_CLIENT_disconnect (h->conn); 392 GNUNET_CLIENT_disconnect (h->conn);
340} 393}
341 394