GNUnet  0.10.x
rps_api.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C)
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19 */
20 
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "rps.h"
29 #include "gnunet_rps_service.h"
30 #include "rps-sampler_client.h"
31 
32 #include "gnunet_nse_service.h"
33 
34 #include <inttypes.h>
35 
36 #define LOG(kind,...) GNUNET_log_from (kind, "rps-api",__VA_ARGS__)
37 
42 {
47 
52 
56  void *ready_cb_cls;
57 
62 
67 
72 };
73 
74 
79 {
84 
89 
94 
99 
104 
109 
114 
119 
124 
129 
134 
139 
145 
153 };
154 
155 
160 {
165 
169  uint32_t num_requests;
170 
175 
180 
186 
191 
196 
201 
206 };
207 
208 
213 {
218 
223 
228 
234 
239 
244 
249 
254 };
255 
256 
262 {
267 
271  void *cls;
272 
276  struct GNUNET_CLIENT_Connection *service_conn;
277 };
278 
279 
285 
290 static uint64_t srh_callback_num_peers;
291 
292 
303 static struct GNUNET_RPS_StreamRequestHandle *
306  void *cls)
307 {
308  struct GNUNET_RPS_StreamRequestHandle *srh;
309 
311  srh->rps_handle = rps_handle;
312  srh->ready_cb = ready_cb;
313  srh->ready_cb_cls = cls;
315  rps_handle->stream_requests_tail,
316  srh);
317 
318  return srh;
319 }
320 
321 
327 static void
329 {
330  struct GNUNET_RPS_Handle *rps_handle = srh->rps_handle;
331 
332  GNUNET_assert (NULL != srh);
333  if (NULL != srh->callback_task)
334  {
336  srh->callback_task = NULL;
337  }
339  rps_handle->stream_requests_tail,
340  srh);
341  GNUNET_free (srh);
342 }
343 
344 
354 static void
356  uint32_t num_peers,
357  void *cls)
358 {
359  struct GNUNET_RPS_Request_Handle *rh = cls;
360 
361  rh->sampler_rh = NULL;
362  rh->ready_cb (rh->ready_cb_cls,
363  num_peers,
364  peers);
366 }
367 
368 
380 static void
382  void *cls,
383  double probability,
384  uint32_t num_observed)
385 {
386  struct GNUNET_RPS_Request_Handle_Single_Info *rh = cls;
387 
388  rh->sampler_rh = NULL;
389  rh->ready_cb (rh->ready_cb_cls,
390  peers,
391  probability,
392  num_observed);
394 }
395 
396 
405 static void
406 collect_peers_cb (void *cls,
407  uint64_t num_peers,
408  const struct GNUNET_PeerIdentity *peers)
409 {
410  struct GNUNET_RPS_Request_Handle *rh = cls;
411 
413  "Service sent %" PRIu64 " peers from stream\n",
414  num_peers);
415  for (uint64_t i = 0; i < num_peers; i++)
416  {
417  RPS_sampler_update (rh->sampler, &peers[i]);
418  }
419 }
420 
421 
432 static void
434  uint64_t num_peers,
435  const struct GNUNET_PeerIdentity *peers)
436 {
437  struct GNUNET_RPS_Request_Handle_Single_Info *rhs = cls;
438 
440  "Service sent %" PRIu64 " peers from stream\n",
441  num_peers);
442  for (uint64_t i = 0; i < num_peers; i++)
443  {
444  RPS_sampler_update (rhs->sampler, &peers[i]);
445  }
446 }
447 
448 
449 /* Get internals for debugging/profiling purposes */
450 
460 void
462  uint32_t num_updates,
464  void *cls)
465 {
466  struct GNUNET_MQ_Envelope *ev;
468 
470  "Client requests %" PRIu32 " view updates\n",
471  num_updates);
472  rps_handle->view_update_cb = view_update_cb;
473  rps_handle->view_update_cls = cls;
474 
476  msg->num_updates = htonl (num_updates);
477  GNUNET_MQ_send (rps_handle->mq, ev);
478 }
479 
480 
481 void
483 {
484  struct GNUNET_MQ_Envelope *ev;
485 
486  GNUNET_assert (NULL != rps_handle->view_update_cb);
487 
488  rps_handle->view_update_cb = NULL;
489 
491  GNUNET_MQ_send (rps_handle->mq, ev);
492 }
493 
494 
504  GNUNET_RPS_NotifyReadyCB stream_input_cb,
505  void *cls)
506 {
507  struct GNUNET_RPS_StreamRequestHandle *srh;
508  struct GNUNET_MQ_Envelope *ev;
510 
511  srh = new_stream_request (rps_handle,
512  stream_input_cb,
513  cls);
514  LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requests biased stream updates\n");
515 
517  GNUNET_MQ_send (rps_handle->mq, ev);
518  return srh;
519 }
520 
521 
530 static int
531 check_view_update (void *cls,
532  const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg)
533 {
534  uint16_t msize = ntohs (msg->header.size);
535  uint32_t num_peers = ntohl (msg->num_peers);
536  (void) cls;
537 
538  msize -= sizeof (struct GNUNET_RPS_CS_DEBUG_ViewReply);
539  if ( (msize / sizeof (struct GNUNET_PeerIdentity) != num_peers) ||
540  (msize % sizeof (struct GNUNET_PeerIdentity) != 0) )
541  {
542  GNUNET_break (0);
543  return GNUNET_SYSERR;
544  }
545  return GNUNET_OK;
546 }
547 
548 
556 static void
558  const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg)
559 {
560  struct GNUNET_RPS_Handle *h = cls;
561  struct GNUNET_PeerIdentity *peers;
562 
563  /* Give the peers back */
565  "New view of %" PRIu32 " peers:\n",
566  ntohl (msg->num_peers));
567 
568  peers = (struct GNUNET_PeerIdentity *) &msg[1];
569  GNUNET_assert (NULL != h);
570  GNUNET_assert (NULL != h->view_update_cb);
571  h->view_update_cb (h->view_update_cls, ntohl (msg->num_peers), peers);
572 }
573 
574 
581 static void
583 {
584  struct GNUNET_MQ_Envelope *ev;
585 
587  GNUNET_MQ_send (rps_handle->mq, ev);
588 }
589 
590 
596 void
598 {
600 
601  rps_handle = srh->rps_handle;
602  remove_stream_request (srh);
603  if (NULL == rps_handle->stream_requests_head)
604  cancel_stream (rps_handle);
605 }
606 
607 
618 static int
620  const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg)
621 {
622  uint16_t msize = ntohs (msg->header.size);
623  uint32_t num_peers = ntohl (msg->num_peers);
624  (void) cls;
625 
626  msize -= sizeof (struct GNUNET_RPS_CS_DEBUG_StreamReply);
627  if ( (msize / sizeof (struct GNUNET_PeerIdentity) != num_peers) ||
628  (msize % sizeof (struct GNUNET_PeerIdentity) != 0) )
629  {
630  GNUNET_break (0);
631  return GNUNET_SYSERR;
632  }
633  return GNUNET_OK;
634 }
635 
636 
642 static void
644 {
645  struct GNUNET_RPS_StreamRequestHandle *srh = cls;
646 
647  srh->callback_task = NULL;
648  srh->ready_cb (srh->ready_cb_cls,
650  srh_callback_peers);
651 }
652 
653 
662 static void
664  const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg)
665 {
666  struct GNUNET_RPS_Handle *h = cls;
667  //const struct GNUNET_PeerIdentity *peers;
668  uint64_t num_peers;
669  struct GNUNET_RPS_StreamRequestHandle *srh_iter;
670  struct GNUNET_RPS_StreamRequestHandle *srh_next;
671 
672  //peers = (struct GNUNET_PeerIdentity *) &msg[1];
673  num_peers = ntohl (msg->num_peers);
675  GNUNET_free_non_null (srh_callback_peers);
676  srh_callback_peers = GNUNET_new_array (num_peers,
677  struct GNUNET_PeerIdentity);
678  GNUNET_memcpy (srh_callback_peers,
679  &msg[1],
680  num_peers * sizeof (struct GNUNET_PeerIdentity));
682  "Received %" PRIu64 " peer(s) from stream input.\n",
683  num_peers);
684  for (srh_iter = h->stream_requests_head;
685  NULL != srh_iter;
686  srh_iter = srh_next)
687  {
688  LOG (GNUNET_ERROR_TYPE_DEBUG, "Calling srh \n");
689  /* Store next pointer - srh might be removed/freed in callback */
690  srh_next = srh_iter->next;
691  if (NULL != srh_iter->callback_task)
693  srh_iter->callback_task =
695  srh_iter);
696  }
697 
698  if (NULL == h->stream_requests_head)
699  {
700  cancel_stream (h);
701  }
702 }
703 
704 
708 static void
709 reconnect (struct GNUNET_RPS_Handle *h);
710 
711 
721 static void
722 mq_error_handler (void *cls,
723  enum GNUNET_MQ_Error error)
724 {
725  struct GNUNET_RPS_Handle *h = cls;
726  //TODO LOG
727  LOG (GNUNET_ERROR_TYPE_WARNING, "Problem with message queue. error: %i\n\
728  1: READ,\n\
729  2: WRITE,\n\
730  4: TIMEOUT\n",
731  // TODO: write GNUNET_MQ_strerror (error)
732  error);
733  reconnect (h);
734  /* Resend all pending request as the service destroyed its knowledge
735  * about them */
736 }
737 
738 
746 static void
747 hash_from_share_val (const char *share_val,
748  struct GNUNET_HashCode *hash)
749 {
750  GNUNET_CRYPTO_kdf (hash,
751  sizeof (struct GNUNET_HashCode),
752  "rps",
753  strlen ("rps"),
754  share_val,
755  strlen (share_val),
756  NULL, 0);
757 }
758 
759 
771 static void
772 nse_cb (void *cls,
773  struct GNUNET_TIME_Absolute timestamp,
774  double logestimate,
775  double std_dev)
776 {
777  struct GNUNET_RPS_Handle *h = cls;
778  (void) timestamp;
779  (void) std_dev;
780 
781  for (struct GNUNET_RPS_Request_Handle *rh_iter = h->rh_head;
782  NULL != rh_iter && NULL != rh_iter->next;
783  rh_iter = rh_iter->next)
784  {
785  RPS_sampler_update_with_nw_size (rh_iter->sampler,
786  GNUNET_NSE_log_estimate_to_n (logestimate));
787  }
788  for (struct GNUNET_RPS_Request_Handle_Single_Info *rhs_iter = h->rhs_head;
789  NULL != rhs_iter && NULL != rhs_iter->next;
790  rhs_iter = rhs_iter->next)
791  {
792  RPS_sampler_update_with_nw_size (rhs_iter->sampler,
793  GNUNET_NSE_log_estimate_to_n (logestimate));
794  }
795 }
796 
797 
801 static void
803 {
804  struct GNUNET_MQ_MessageHandler mq_handlers[] = {
808  h),
812  h),
814  };
815 
816  if (NULL != h->mq)
817  GNUNET_MQ_destroy (h->mq);
818  h->mq = GNUNET_CLIENT_connect (h->cfg,
819  "rps",
820  mq_handlers,
822  h);
823  if (NULL != h->nse)
825  h->nse = GNUNET_NSE_connect (h->cfg, &nse_cb, h);
826 }
827 
828 
835 struct GNUNET_RPS_Handle *
837 {
838  struct GNUNET_RPS_Handle *h;
839 
840  h = GNUNET_new (struct GNUNET_RPS_Handle);
841  h->cfg = cfg;
842  if (GNUNET_OK !=
844  "RPS",
845  "DESIRED_PROBABILITY",
846  &h->desired_probability))
847  {
849  "RPS", "DESIRED_PROBABILITY");
850  GNUNET_free (h);
851  return NULL;
852  }
853  if (0 > h->desired_probability ||
854  1 < h->desired_probability)
855  {
857  "The desired probability must be in the interval [0;1]\n");
858  GNUNET_free (h);
859  return NULL;
860  }
861  if (GNUNET_OK !=
863  "RPS",
864  "DEFICIENCY_FACTOR",
865  &h->deficiency_factor))
866  {
868  "RPS", "DEFICIENCY_FACTOR");
869  GNUNET_free (h);
870  return NULL;
871  }
872  if (0 > h->desired_probability ||
873  1 < h->desired_probability)
874  {
876  "The deficiency factor must be in the interval [0;1]\n");
877  GNUNET_free (h);
878  return NULL;
879  }
880  reconnect (h);
881  if (NULL == h->mq)
882  {
883  GNUNET_free (h);
884  return NULL;
885  }
886  return h;
887 }
888 
889 
896 void
898  const char *shared_value)
899 {
901  struct GNUNET_MQ_Envelope *ev;
902 
904  hash_from_share_val (shared_value, &msg->hash);
905  msg->round_interval = GNUNET_TIME_relative_hton (// TODO read from config!
908 
909  GNUNET_MQ_send (h->mq, ev);
910 }
911 
912 
919 void
921  const char *shared_value)
922 {
924  struct GNUNET_MQ_Envelope *ev;
925 
927  hash_from_share_val (shared_value, &msg->hash);
928 
929  GNUNET_MQ_send (h->mq, ev);
930 }
931 
932 
944  uint32_t num_req_peers,
946  void *cls)
947 {
948  struct GNUNET_RPS_Request_Handle *rh;
949 
951  "Client requested %" PRIu32 " peers\n",
952  num_req_peers);
954  rh->rps_handle = rps_handle;
955  rh->num_requests = num_req_peers;
956  rh->sampler = RPS_sampler_mod_init (num_req_peers,
957  GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff
959  rps_handle->desired_probability);
961  rps_handle->deficiency_factor);
963  num_req_peers,
965  rh);
966  rh->srh = GNUNET_RPS_stream_request (rps_handle,
968  rh); /* cls */
969  rh->ready_cb = ready_cb;
970  rh->ready_cb_cls = cls;
972  rps_handle->rh_tail,
973  rh);
974 
975  return rh;
976 }
977 
978 
990  void *cls)
991 {
993  uint32_t num_req_peers = 1;
994 
996  "Client requested peer with additional info\n");
998  rhs->rps_handle = rps_handle;
999  rhs->sampler = RPS_sampler_mod_init (num_req_peers,
1000  GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff
1002  rps_handle->desired_probability);
1004  rps_handle->deficiency_factor);
1007  rhs);
1008  rhs->srh = GNUNET_RPS_stream_request (rps_handle,
1010  rhs); /* cls */
1011  rhs->ready_cb = ready_cb;
1012  rhs->ready_cb_cls = cls;
1014  rps_handle->rhs_tail,
1015  rhs);
1016 
1017  return rhs;
1018 }
1019 
1020 
1028 void
1030  uint32_t n,
1031  const struct GNUNET_PeerIdentity *ids)
1032 {
1033  size_t size_needed;
1034  uint32_t num_peers_max;
1035  const struct GNUNET_PeerIdentity *tmp_peer_pointer;
1036  struct GNUNET_MQ_Envelope *ev;
1038 
1040  "Client wants to seed %" PRIu32 " peers:\n",
1041  n);
1042  for (unsigned int i = 0 ; i < n ; i++)
1044  "%u. peer: %s\n",
1045  i,
1046  GNUNET_i2s (&ids[i]));
1047 
1048  /* The actual size the message occupies */
1049  size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
1050  n * sizeof (struct GNUNET_PeerIdentity);
1051  /* The number of peers that fits in one message together with
1052  * the respective header */
1053  num_peers_max = (GNUNET_MAX_MESSAGE_SIZE -
1054  sizeof (struct GNUNET_RPS_CS_SeedMessage)) /
1055  sizeof (struct GNUNET_PeerIdentity);
1056  tmp_peer_pointer = ids;
1057 
1058  while (GNUNET_MAX_MESSAGE_SIZE < size_needed)
1059  {
1060  ev = GNUNET_MQ_msg_extra (msg,
1061  num_peers_max * sizeof (struct GNUNET_PeerIdentity),
1063  msg->num_peers = htonl (num_peers_max);
1064  GNUNET_memcpy (&msg[1],
1065  tmp_peer_pointer,
1066  num_peers_max * sizeof (struct GNUNET_PeerIdentity));
1067  GNUNET_MQ_send (h->mq,
1068  ev);
1069  n -= num_peers_max;
1070  size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
1071  n * sizeof (struct GNUNET_PeerIdentity);
1072  /* Set pointer to beginning of next block of num_peers_max peers */
1073  tmp_peer_pointer = &ids[num_peers_max];
1074  }
1075 
1076  ev = GNUNET_MQ_msg_extra (msg,
1077  n * sizeof (struct GNUNET_PeerIdentity),
1079  msg->num_peers = htonl (n);
1080  GNUNET_memcpy (&msg[1],
1081  tmp_peer_pointer,
1082  n * sizeof (struct GNUNET_PeerIdentity));
1083  GNUNET_MQ_send (h->mq,
1084  ev);
1085 }
1086 
1087 
1088 #if ENABLE_MALICIOUS
1089 
1103 void
1104 GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
1105  uint32_t type,
1106  uint32_t num_peers,
1107  const struct GNUNET_PeerIdentity *peer_ids,
1108  const struct GNUNET_PeerIdentity *target_peer)
1109 {
1110  size_t size_needed;
1111  uint32_t num_peers_max;
1112  const struct GNUNET_PeerIdentity *tmp_peer_pointer;
1113  struct GNUNET_MQ_Envelope *ev;
1114  struct GNUNET_RPS_CS_ActMaliciousMessage *msg;
1115 
1116  unsigned int i;
1117 
1119  "Client turns malicious (type %" PRIu32 ") with %" PRIu32 " other peers:\n",
1120  type,
1121  num_peers);
1122  for (i = 0 ; i < num_peers ; i++)
1124  "%u. peer: %s\n",
1125  i,
1126  GNUNET_i2s (&peer_ids[i]));
1127 
1128  /* The actual size the message would occupy */
1129  size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
1130  num_peers * sizeof (struct GNUNET_PeerIdentity);
1131  /* The number of peers that fit in one message together with
1132  * the respective header */
1133  num_peers_max = (GNUNET_MAX_MESSAGE_SIZE -
1134  sizeof (struct GNUNET_RPS_CS_SeedMessage)) /
1135  sizeof (struct GNUNET_PeerIdentity);
1136  tmp_peer_pointer = peer_ids;
1137 
1138  while (GNUNET_MAX_MESSAGE_SIZE < size_needed)
1139  {
1141  "Too many peers to send at once, sending %" PRIu32 " (all we can so far)\n",
1142  num_peers_max);
1143  ev = GNUNET_MQ_msg_extra (msg,
1144  num_peers_max * sizeof (struct GNUNET_PeerIdentity),
1145  GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS);
1146  msg->type = htonl (type);
1147  msg->num_peers = htonl (num_peers_max);
1148  if ( (2 == type) ||
1149  (3 == type) )
1150  msg->attacked_peer = peer_ids[num_peers];
1151  GNUNET_memcpy (&msg[1],
1152  tmp_peer_pointer,
1153  num_peers_max * sizeof (struct GNUNET_PeerIdentity));
1154 
1155  GNUNET_MQ_send (h->mq, ev);
1156 
1157  num_peers -= num_peers_max;
1158  size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
1159  num_peers * sizeof (struct GNUNET_PeerIdentity);
1160  /* Set pointer to beginning of next block of num_peers_max peers */
1161  tmp_peer_pointer = &peer_ids[num_peers_max];
1162  }
1163 
1164  ev = GNUNET_MQ_msg_extra (msg,
1165  num_peers * sizeof (struct GNUNET_PeerIdentity),
1166  GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS);
1167  msg->type = htonl (type);
1168  msg->num_peers = htonl (num_peers);
1169  if ( (2 == type) ||
1170  (3 == type) )
1171  msg->attacked_peer = *target_peer;
1172  GNUNET_memcpy (&msg[1],
1173  tmp_peer_pointer,
1174  num_peers * sizeof (struct GNUNET_PeerIdentity));
1175 
1176  GNUNET_MQ_send (h->mq, ev);
1177 }
1178 #endif /* ENABLE_MALICIOUS */
1179 
1180 
1186 void
1188 {
1189  struct GNUNET_RPS_Handle *h;
1190 
1191  h = rh->rps_handle;
1192  GNUNET_assert (NULL != rh);
1193  GNUNET_assert (NULL != rh->srh);
1194  GNUNET_assert (h == rh->srh->rps_handle);
1196  rh->srh = NULL;
1197  if (NULL == h->stream_requests_head) cancel_stream(h);
1198  if (NULL != rh->sampler_rh)
1199  {
1201  }
1203  rh->sampler = NULL;
1205  h->rh_tail,
1206  rh);
1207  GNUNET_free (rh);
1208 }
1209 
1210 
1216 void
1219 {
1220  struct GNUNET_RPS_Handle *h;
1221 
1222  h = rhs->rps_handle;
1223  GNUNET_assert (NULL != rhs);
1224  GNUNET_assert (NULL != rhs->srh);
1225  GNUNET_assert (h == rhs->srh->rps_handle);
1227  rhs->srh = NULL;
1228  if (NULL == h->stream_requests_head) cancel_stream(h);
1229  if (NULL != rhs->sampler_rh)
1230  {
1232  }
1234  rhs->sampler = NULL;
1236  h->rhs_tail,
1237  rhs);
1238  GNUNET_free (rhs);
1239 }
1240 
1241 
1247 void
1249 {
1250  if (NULL != h->stream_requests_head)
1251  {
1252  struct GNUNET_RPS_StreamRequestHandle *srh_next;
1253 
1255  "Still waiting for replies\n");
1256  for (struct GNUNET_RPS_StreamRequestHandle *srh_iter = h->stream_requests_head;
1257  NULL != srh_iter;
1258  srh_iter = srh_next)
1259  {
1260  srh_next = srh_iter->next;
1261  GNUNET_RPS_stream_cancel (srh_iter);
1262  }
1263  }
1264  if (NULL != h->rh_head)
1265  {
1267  "Not all requests were cancelled!\n");
1268  for (struct GNUNET_RPS_Request_Handle *rh_iter = h->rh_head;
1269  h->rh_head != NULL;
1270  rh_iter = h->rh_head)
1271  {
1272  GNUNET_RPS_request_cancel (rh_iter);
1273  }
1274  }
1275  if (NULL != h->rhs_head)
1276  {
1278  "Not all requests were cancelled!\n");
1279  for (struct GNUNET_RPS_Request_Handle_Single_Info *rhs_iter = h->rhs_head;
1280  h->rhs_head != NULL;
1281  rhs_iter = h->rhs_head)
1282  {
1284  }
1285  }
1286  if (NULL != srh_callback_peers)
1287  {
1288  GNUNET_free (srh_callback_peers);
1289  srh_callback_peers = NULL;
1290  }
1291  if (NULL != h->view_update_cb)
1292  {
1294  "Still waiting for view updates\n");
1296  }
1297  if (NULL != h->nse)
1299  GNUNET_MQ_destroy (h->mq);
1300  GNUNET_free (h);
1301 }
1302 
1303 
1304 /* end of rps_api.c */
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_RPS_Request_Handle_Single_Info * rhs_head
Pointer to the head element in DLL of single request handles.
Definition: rps_api.c:133
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY
Send peer of biased stream.
static void collect_peers_cb(void *cls, uint64_t num_peers, const struct GNUNET_PeerIdentity *peers)
Callback to collect the peers from the biased stream and put those into the sampler.
Definition: rps_api.c:406
#define GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START
RPS client-service message to start a sub sampler.
struct GNUNET_RPS_Request_Handle * GNUNET_RPS_request_peers(struct GNUNET_RPS_Handle *rps_handle, uint32_t num_req_peers, GNUNET_RPS_NotifyReadyCB ready_cb, void *cls)
Request n random peers.
Definition: rps_api.c:943
Handle for a request to get peers from biased stream of ids.
Definition: rps_api.c:41
Message from service to client containing current update of view.
Definition: rps.h:186
struct GNUNET_RPS_Request_Handle * rh_tail
Pointer to the tail element in DLL of request handles.
Definition: rps_api.c:128
struct GNUNET_MessageHeader header
Header including size and type in NBO.
Definition: rps.h:225
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static void nse_cb(void *cls, struct GNUNET_TIME_Absolute timestamp, double logestimate, double std_dev)
Callback for network size estimate - called with new estimates about the network size, updates all samplers with the new estimate.
Definition: rps_api.c:772
Message from client to service indicating that clients wants to get stream of biased peers...
Definition: rps.h:209
struct GNUNET_RPS_StreamRequestHandle * srh
Request handle of the request of the biased stream of peers - needed to cancel the request...
Definition: rps_api.c:185
static void reconnect(struct GNUNET_RPS_Handle *h)
Reconnect to the service.
Definition: rps_api.c:802
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
GNUNET_RPS_NotifyReadyCB ready_cb
The callback to be called when we receive an answer.
Definition: rps_api.c:190
uint32_t num_updates
Number of updates 0 for sending updates until cancellation.
Definition: rps.h:180
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:901
void GNUNET_RPS_seed_ids(struct GNUNET_RPS_Handle *h, uint32_t n, const struct GNUNET_PeerIdentity *ids)
Seed rps service with peerIDs.
Definition: rps_api.c:1029
struct RPS_Sampler * sampler
The Sampler for the client request.
Definition: rps_api.c:174
Message from client to service indicating that clients wants to get updates of the view...
Definition: rps.h:169
GNUNET_MQ_Error
Error codes for the queue.
struct GNUNET_RPS_Request_Handle * rh_head
Pointer to the head element in DLL of request handles.
Definition: rps_api.c:123
#define GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP
RPS client-service message to stop a sub sampler.
void GNUNET_RPS_view_request(struct GNUNET_RPS_Handle *rps_handle, uint32_t num_updates, GNUNET_RPS_NotifyReadyCB view_update_cb, void *cls)
Request updates of view.
Definition: rps_api.c:461
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST
Request updates of the view.
void RPS_sampler_set_deficiency_factor(struct RPS_Sampler *sampler, double deficiency_factor)
Set the deficiency factor.
GNUNET_RPS_NotifyReadyCB ready_cb
The callback to be called when we receive an answer.
Definition: rps_api.c:51
client sampler implementation
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void RPS_sampler_set_desired_probability(struct RPS_Sampler *sampler, double desired_probability)
Set the probability that is needed at least with what a sampler element has to have observed all elem...
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_NSE_Handle * GNUNET_NSE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_NSE_Callback func, void *func_cls)
Connect to the network size estimation service.
Definition: nse_api.c:165
void(* GNUNET_RPS_NotifyReadyCB)(void *cls, uint64_t num_peers, const struct GNUNET_PeerIdentity *peers)
Callback called when requested random peers are available.
uint64_t rel_value_us__
The actual value (in network byte order).
struct GNUNET_RPS_Request_Handle_Single_Info * next
Pointer to next element in DLL.
Definition: rps_api.c:248
static int stream_input
Do we want to receive updates of the view? (Option –view)
Definition: gnunet-rps.c:56
void RPS_sampler_request_single_info_cancel(struct RPS_SamplerRequestHandleSingleInfo *req_single_info_handle)
Cancle a request issued through RPS_sampler_sinlge_info_ready_cb.
float deficiency_factor
A factor that catches the &#39;bias&#39; of a random stream of peer ids.
Definition: rps_api.c:152
int GNUNET_CONFIGURATION_get_value_float(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, float *number)
Get a configuration value that should be a floating point number.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
void RPS_sampler_update(struct RPS_Sampler *sampler, const struct GNUNET_PeerIdentity *id)
Update every sampler element of this sampler with given peer.
void GNUNET_RPS_stream_cancel(struct GNUNET_RPS_StreamRequestHandle *srh)
Cancel a specific request for updates from the biased peer stream.
Definition: rps_api.c:597
static void peers_ready_cb(const struct GNUNET_PeerIdentity *peers, uint32_t num_peers, void *cls)
Called once the sampler has collected all requested peers.
Definition: rps_api.c:355
void * ready_cb_cls
The closure for the callback.
Definition: rps_api.c:243
static void cancel_stream(struct GNUNET_RPS_Handle *rps_handle)
Send message to service that this client does not want to receive further updates from the biased pee...
Definition: rps_api.c:582
static void remove_stream_request(struct GNUNET_RPS_StreamRequestHandle *srh)
Remove the given stream request from the list of requests and memory.
Definition: rps_api.c:328
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static void collect_peers_info_cb(void *cls, uint64_t num_peers, const struct GNUNET_PeerIdentity *peers)
Callback to collect the peers from the biased stream and put those into the sampler.
Definition: rps_api.c:433
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY
Send update of the view.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
example IPC messages between RPS API and GNS service
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_RPS_disconnect(struct GNUNET_RPS_Handle *h)
Disconnect from the rps service.
Definition: rps_api.c:1248
static void handle_view_update(void *cls, const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg)
This function is called, when the service updated its view.
Definition: rps_api.c:557
Handler to handle requests from a client.
Definition: rps_api.c:78
struct GNUNET_RPS_Handle * rps_handle
The client issuing the request.
Definition: rps_api.c:217
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
GNUNET_RPS_NotifyReadyCB cb
Callback provided by the client.
Definition: rps_api.c:266
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
void GNUNET_RPS_sub_stop(struct GNUNET_RPS_Handle *h, const char *shared_value)
Stop a sub with the given shared value.
Definition: rps_api.c:920
static void srh_callback_scheduled(void *cls)
Called by the scheduler to call the callbacks of the srh handlers.
Definition: rps_api.c:643
Message from client to service with seed of peers.
Definition: rps.h:67
Closure to _get_n_rand_peers_ready_cb()
struct GNUNET_RPS_Handle * GNUNET_RPS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the rps service.
Definition: rps_api.c:836
void * cls
Closure provided by the client.
Definition: rps_api.c:271
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
struct RPS_Sampler * RPS_sampler_mod_init(size_t init_size, struct GNUNET_TIME_Relative max_round_interval)
Initialise a modified tuple of sampler elements.
struct GNUNET_CLIENT_Connection * service_conn
Handle to the service connection.
Definition: rps_api.c:276
GNUNET_RPS_NotifyReadyCB view_update_cb
Callback called on each update of the view.
Definition: rps_api.c:93
uint64_t num_peers
Number of peers.
Definition: rps.h:230
#define GNUNET_memcpy(dst, src, n)
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL
Cancel getting updates of the view.
struct GNUNET_RPS_Request_Handle * prev
Pointer to previous element in DLL.
Definition: rps_api.c:205
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
void GNUNET_RPS_request_single_info_cancel(struct GNUNET_RPS_Request_Handle_Single_Info *rhs)
Cancle an issued single info request.
Definition: rps_api.c:1217
struct GNUNET_MQ_Handle * mq
The message queue to the client.
Definition: rps_api.c:88
static struct GNUNET_PeerIdentity * peer_ids
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
struct GNUNET_RPS_Handle * rps_handle
The client issuing the request.
Definition: rps_api.c:164
static struct GNUNET_CONTAINER_MultiPeerMap * ids
GNUNET_PeerIdentity -> CadetPeer.
void view_update_cb(void *cls, uint64_t view_size, const struct GNUNET_PeerIdentity *peers)
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1273
struct GNUNET_RPS_Request_Handle * next
Pointer to next element in DLL.
Definition: rps_api.c:200
static struct GNUNET_RPS_StreamRequestHandle * new_stream_request(struct GNUNET_RPS_Handle *rps_handle, GNUNET_RPS_NotifyReadyCB ready_cb, void *cls)
Create a new handle for a stream request.
Definition: rps_api.c:304
struct GNUNET_HashCode hash
Length of the shared value represented as string.
Definition: rps.h:159
static void peer_info_ready_cb(const struct GNUNET_PeerIdentity *peers, void *cls, double probability, uint32_t num_observed)
Called once the sampler has collected the requested peer.
Definition: rps_api.c:381
struct GNUNET_RPS_StreamRequestHandle * stream_requests_tail
Tail of the DLL of stream requests.
Definition: rps_api.c:113
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
Message from client to service telling it to stop a new sub.
Definition: rps.h:149
void RPS_sampler_destroy(struct RPS_Sampler *sampler)
Cleans the samplers.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:439
struct RPS_SamplerRequestHandle * RPS_sampler_get_n_rand_peers(struct RPS_Sampler *sampler, uint32_t num_peers, RPS_sampler_n_rand_peers_ready_cb cb, void *cls)
Get n random peers out of the sampled peers.
void * stream_input_cls
Closure to each requested peer from the biased stream.
Definition: rps_api.c:103
Closure to _get_rand_peer_info()
struct GNUNET_RPS_Request_Handle_Single_Info * GNUNET_RPS_request_peer_info(struct GNUNET_RPS_Handle *rps_handle, GNUNET_RPS_NotifyReadySingleInfoCB ready_cb, void *cls)
Request one random peer, getting additional information.
Definition: rps_api.c:988
struct RPS_SamplerRequestHandle * sampler_rh
Request handle of the request to the sampler - needed to cancel the request.
Definition: rps_api.c:179
struct GNUNET_RPS_StreamRequestHandle * stream_requests_head
Head of the DLL of stream requests.
Definition: rps_api.c:108
#define GNUNET_MESSAGE_TYPE_RPS_CS_SEED
RPS CS SEED Message for the Client to seed peers into rps.
void RPS_sampler_update_with_nw_size(struct RPS_Sampler *sampler, uint32_t num_peers)
Update the current estimate of the network size stored at the sampler.
A 512-bit hashcode.
Message handler for a specific message type.
static int view_update
Do we want to receive updates of the view? (Option –view)
Definition: gnunet-rps.c:51
struct RPS_SamplerRequestHandleSingleInfo * RPS_sampler_get_rand_peer_info(struct RPS_Sampler *sampler, RPS_sampler_sinlge_info_ready_cb cb, void *cls)
Get one random peer with additional information.
Handler for a single request from a client.
Definition: rps_api.c:212
Message from service to client containing peer from biased stream.
Definition: rps.h:220
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL
Cancel getting biased strem.
void GNUNET_NSE_disconnect(struct GNUNET_NSE_Handle *h)
Disconnect from network size estimation service.
Definition: nse_api.c:193
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
void * ready_cb_cls
The closure for the callback.
Definition: rps_api.c:195
Message from client to service telling it to start a new sub.
Definition: rps.h:122
uint32_t num_requests
The number of requested peers.
Definition: rps_api.c:169
Handle for talking with the NSE service.
Definition: nse_api.c:40
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static void hash_from_share_val(const char *share_val, struct GNUNET_HashCode *hash)
Create the hash value from the share value that defines the sub (-group)
Definition: rps_api.c:747
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:622
struct GNUNET_RPS_StreamRequestHandle * srh
Request handle of the request of the biased stream of peers - needed to cancel the request...
Definition: rps_api.c:233
uint32_t num_peers
Number of peers.
Definition: rps.h:77
static unsigned int num_peers
static struct GNUNET_PeerIdentity * target_peer
ID of the targeted peer.
struct RPS_SamplerRequestHandleSingleInfo * sampler_rh
Request handle of the request to the sampler - needed to cancel the request.
Definition: rps_api.c:227
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
struct GNUNET_MessageHeader header
Header including size and type in NBO.
Definition: rps.h:191
Handle to a message queue.
Definition: mq.c:85
#define GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST
Request biased input stream.
GNUNET_RPS_NotifyReadySingleInfoCB ready_cb
The callback to be called when we receive an answer.
Definition: rps_api.c:238
struct GNUNET_TIME_RelativeNBO round_interval
Mean interval between two rounds.
Definition: rps.h:137
struct GNUNET_SCHEDULER_Task * callback_task
Scheduler task for scheduled callback.
Definition: rps_api.c:61
void GNUNET_RPS_view_request_cancel(struct GNUNET_RPS_Handle *rps_handle)
Definition: rps_api.c:482
#define GNUNET_MQ_msg_header(type)
Allocate a GNUNET_MQ_Envelope, where the message only consists of a header.
Definition: gnunet_mq_lib.h:76
The identity of the host (wraps the signing key of the peer).
const struct GNUNET_CONFIGURATION_Handle * cfg
The handle to the client configuration.
Definition: rps_api.c:83
struct RPS_Sampler * sampler
The Sampler for the client request.
Definition: rps_api.c:222
Struct used to pack the callback, its closure (provided by the caller) and the connection handler to ...
Definition: rps_api.c:261
void GNUNET_RPS_request_cancel(struct GNUNET_RPS_Request_Handle *rh)
Cancle an issued request.
Definition: rps_api.c:1187
configuration data
Definition: configuration.c:85
struct GNUNET_NSE_Handle * nse
Handle to nse service.
Definition: rps_api.c:118
static struct CadetPeer * peers
Operation to get peer ids.
static struct GNUNET_PeerIdentity * srh_callback_peers
Peers received from the biased stream to be passed to all srh_handlers.
Definition: rps_api.c:284
void * view_update_cls
Closure to each requested update of the view.
Definition: rps_api.c:98
struct GNUNET_RPS_StreamRequestHandle * prev
Previous element of the DLL.
Definition: rps_api.c:71
struct GNUNET_RPS_Request_Handle_Single_Info * rhs_tail
Pointer to the tail element in DLL of single request handles.
Definition: rps_api.c:138
Entry in list of pending tasks.
Definition: scheduler.c:134
struct GNUNET_RPS_StreamRequestHandle * GNUNET_RPS_stream_request(struct GNUNET_RPS_Handle *rps_handle, GNUNET_RPS_NotifyReadyCB stream_input_cb, void *cls)
Request biased stream of peers that are being put into the sampler.
Definition: rps_api.c:503
struct GNUNET_RPS_Request_Handle_Single_Info * prev
Pointer to previous element in DLL.
Definition: rps_api.c:253
void GNUNET_RPS_sub_start(struct GNUNET_RPS_Handle *h, const char *shared_value)
Start a sub with the given shared value.
Definition: rps_api.c:897
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Error handler for mq.
Definition: rps_api.c:722
static void handle_stream_input(void *cls, const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg)
This function is called, when the service sends another peer from the biased stream.
Definition: rps_api.c:663
void * ready_cb_cls
The closure for the callback.
Definition: rps_api.c:56
struct GNUNET_RPS_StreamRequestHandle * next
Next element of the DLL.
Definition: rps_api.c:66
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Handler for a single request from a client.
Definition: rps_api.c:159
float desired_probability
The desired probability with which we want to have observed all peers.
Definition: rps_api.c:144
Time for absolute times used by GNUnet, in microseconds.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
void RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle)
Cancle a request issued through RPS_sampler_n_rand_peers_ready_cb.
uint64_t num_peers
Number of peers in the view.
Definition: rps.h:201
#define GNUNET_NSE_log_estimate_to_n(loge)
Convert the logarithmic estimated returned to the &#39;GNUNET_NSE_Callback&#39; into an absolute estimate in ...
static int check_stream_input(void *cls, const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg)
This function is called, when the service sends another peer from the biased stream.
Definition: rps_api.c:619
int GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_kdf.c:91
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Sampler with its own array of SamplerElements.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
static uint64_t srh_callback_num_peers
Number of peers in the biased stream that are to be passed to all srh_handlers.
Definition: rps_api.c:290
void(* GNUNET_RPS_NotifyReadySingleInfoCB)(void *cls, const struct GNUNET_PeerIdentity *peer, double probability, uint32_t num_observed)
Callback called when requested random peer with additional information is available.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_RPS_Handle * rps_handle
The client issuing the request.
Definition: rps_api.c:46
#define LOG(kind,...)
Definition: rps_api.c:36
static int check_view_update(void *cls, const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg)
This function is called, when the service updates the view.
Definition: rps_api.c:531
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
struct GNUNET_HashCode hash
Length of the shared value represented as string.
Definition: rps.h:142