aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2018-09-20 01:15:53 +0200
committerJulius Bünger <buenger@mytum.de>2018-09-20 01:15:53 +0200
commit67f690896f5bbbcd40efaec79a7c36d2e339990b (patch)
tree3043d6ad4d5a422b17944b199faaf118cc1fdaf1
parent69f439525cabfd0b65d5875e49d306588587cb23 (diff)
downloadgnunet-67f690896f5bbbcd40efaec79a7c36d2e339990b.tar.gz
gnunet-67f690896f5bbbcd40efaec79a7c36d2e339990b.zip
Start changing architecture of rps service/client
-rw-r--r--src/rps/Makefile.am7
-rw-r--r--src/rps/rps-test_util.c36
-rw-r--r--src/rps/rps-test_util.h2
-rw-r--r--src/rps/rps_api.c132
4 files changed, 148 insertions, 29 deletions
diff --git a/src/rps/Makefile.am b/src/rps/Makefile.am
index d477ade92..2ed93ef7c 100644
--- a/src/rps/Makefile.am
+++ b/src/rps/Makefile.am
@@ -19,7 +19,11 @@ pkgcfg_DATA = \
19 19
20bin_PROGRAMS = gnunet-rps 20bin_PROGRAMS = gnunet-rps
21 21
22gnunet_rps_SOURCES = gnunet-rps.c 22gnunet_rps_SOURCES = \
23 gnunet-service-rps_sampler_elem.h gnunet-service-rps_sampler_elem.c \
24 gnunet-service-rps_sampler.h gnunet-service-rps_sampler.c \
25 gnunet-rps.c
26
23gnunet_rps_LDADD = \ 27gnunet_rps_LDADD = \
24 libgnunetrps.la \ 28 libgnunetrps.la \
25 $(top_builddir)/src/util/libgnunetutil.la \ 29 $(top_builddir)/src/util/libgnunetutil.la \
@@ -143,6 +147,7 @@ test_rps_churn_LDADD = $(ld_rps_test_lib)
143 147
144gnunet_rps_profiler_SOURCES = \ 148gnunet_rps_profiler_SOURCES = \
145 gnunet-service-rps_sampler_elem.h gnunet-service-rps_sampler_elem.c \ 149 gnunet-service-rps_sampler_elem.h gnunet-service-rps_sampler_elem.c \
150 gnunet-service-rps_sampler.h gnunet-service-rps_sampler.c \
146 rps-test_util.h rps-test_util.c \ 151 rps-test_util.h rps-test_util.c \
147 gnunet-rps-profiler.c 152 gnunet-rps-profiler.c
148 153
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c
index ef39638bf..271c96648 100644
--- a/src/rps/rps-test_util.c
+++ b/src/rps/rps-test_util.c
@@ -379,23 +379,6 @@ auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key)
379} 379}
380 380
381 381
382struct GNUNET_CRYPTO_AuthKey
383string_to_auth_key (const char *str)
384{
385 struct GNUNET_CRYPTO_AuthKey auth_key;
386
387 if (GNUNET_OK !=
388 GNUNET_STRINGS_string_to_data (str,
389 strlen (str),
390 &auth_key.key,
391 sizeof (struct GNUNET_CRYPTO_AuthKey)))
392 {
393 LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to convert string to data\n");
394 }
395
396 return auth_key;
397}
398
399 382
400char * 383char *
401create_file (const char *name) 384create_file (const char *name)
@@ -435,6 +418,25 @@ create_file (const char *name)
435 418
436#endif /* TO_FILE */ 419#endif /* TO_FILE */
437 420
421
422struct GNUNET_CRYPTO_AuthKey
423string_to_auth_key (const char *str)
424{
425 struct GNUNET_CRYPTO_AuthKey auth_key;
426
427 if (GNUNET_OK !=
428 GNUNET_STRINGS_string_to_data (str,
429 strlen (str),
430 &auth_key.key,
431 sizeof (struct GNUNET_CRYPTO_AuthKey)))
432 {
433 LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to convert string to data\n");
434 }
435
436 return auth_key;
437}
438
439
438/** 440/**
439 * @brief Try to ensure that `/tmp/rps` exists. 441 * @brief Try to ensure that `/tmp/rps` exists.
440 * 442 *
diff --git a/src/rps/rps-test_util.h b/src/rps/rps-test_util.h
index bb9b39713..def52a0ac 100644
--- a/src/rps/rps-test_util.h
+++ b/src/rps/rps-test_util.h
@@ -36,7 +36,7 @@ auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key);
36struct GNUNET_CRYPTO_AuthKey 36struct GNUNET_CRYPTO_AuthKey
37string_to_auth_key (const char *str); 37string_to_auth_key (const char *str);
38 38
39char * 39char *
40create_file (const char *name); 40create_file (const char *name);
41 41
42/** 42/**
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c
index 7afe21d3a..a558c8a35 100644
--- a/src/rps/rps_api.c
+++ b/src/rps/rps_api.c
@@ -25,6 +25,7 @@
25#include "gnunet_util_lib.h" 25#include "gnunet_util_lib.h"
26#include "rps.h" 26#include "rps.h"
27#include "gnunet_rps_service.h" 27#include "gnunet_rps_service.h"
28#include "gnunet-service-rps_sampler.h"
28 29
29#include <inttypes.h> 30#include <inttypes.h>
30 31
@@ -524,6 +525,39 @@ GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
524 525
525 526
526/** 527/**
528 * @brief Create new request handle
529 *
530 * @param rps_handle Handle to the service
531 * @param num_requests Number of requests
532 * @param ready_cb Callback
533 * @param cls Closure
534 *
535 * @return The newly created request handle
536 */
537static struct GNUNET_RPS_Request_Handle *
538new_request_handle (struct GNUNET_RPS_Handle *rps_handle,
539 uint64_t num_requests,
540 struct RPS_Sampler *sampler,
541 GNUNET_RPS_NotifyReadyCB ready_cb,
542 void *cls)
543{
544 struct GNUNET_RPS_Request_Handle *rh;
545
546 rh = GNUNET_new (struct GNUNET_RPS_Request_Handle);
547 rh->rps_handle = rps_handle;
548 rh->id = rps_handle->current_request_id++;
549 rh->num_requests = num_requests;
550 rh->sampler = sampler;
551 rh->ready_cb = ready_cb;
552 rh->ready_cb_cls = cls;
553 GNUNET_CONTAINER_multihashmap32_put (rps_handle->req_handlers, rh->id, rh,
554 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
555
556 return rh;
557}
558
559
560/**
527 * Request n random peers. 561 * Request n random peers.
528 * 562 *
529 * @param rps_handle handle to the rps service 563 * @param rps_handle handle to the rps service
@@ -533,34 +567,112 @@ GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
533 * @return a handle to cancel this request 567 * @return a handle to cancel this request
534 */ 568 */
535struct GNUNET_RPS_Request_Handle * 569struct GNUNET_RPS_Request_Handle *
536GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle, 570GNUNET_RPS_request_peers_2 (struct GNUNET_RPS_Handle *rps_handle,
537 uint32_t num_req_peers, 571 uint32_t num_req_peers,
538 GNUNET_RPS_NotifyReadyCB ready_cb, 572 GNUNET_RPS_NotifyReadyCB ready_cb,
539 void *cls) 573 void *cls)
540{ 574{
541 struct GNUNET_RPS_Request_Handle *rh; 575 struct GNUNET_RPS_Request_Handle *rh;
542 576
543 rh = GNUNET_new (struct GNUNET_RPS_Request_Handle); 577 rh = new_request_handle (rps_handle,
544 rh->rps_handle = rps_handle; 578 num_req_peers,
545 rh->id = rps_handle->current_request_id++; 579 NULL, /* no sampler needed */
546 rh->num_peers = num_req_peers; 580 ready_cb,
547 rh->ready_cb = ready_cb; 581 cls);
548 rh->ready_cb_cls = cls;
549 582
550 LOG (GNUNET_ERROR_TYPE_DEBUG, 583 LOG (GNUNET_ERROR_TYPE_DEBUG,
551 "Requesting %" PRIu32 " peers with id %" PRIu32 "\n", 584 "Requesting %" PRIu32 " peers with id %" PRIu32 "\n",
552 num_req_peers, 585 num_req_peers,
553 rh->id); 586 rh->id);
554 587
555 GNUNET_CONTAINER_multihashmap32_put (rps_handle->req_handlers, rh->id, rh,
556 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
557
558 send_request (rps_handle, rh->id, num_req_peers); 588 send_request (rps_handle, rh->id, num_req_peers);
559 return rh; 589 return rh;
560} 590}
561 591
562 592
563/** 593/**
594 * @brief Callback to collect the peers from the biased stream and put those
595 * into the sampler.
596 *
597 * @param cls The #GNUNET_RPS_Request_Handle
598 * @param num_peers The number of peer that have been returned
599 * @param peers The array of @a num_peers that have been returned
600 */
601void
602collect_peers_cb (void *cls,
603 uint64_t num_peers,
604 const struct GNUNET_PeerIdentity *peers)
605{
606 struct GNUNET_RPS_Request_Handle *rh = cls;
607
608 for (uint64_t i = 0; i < num_peers; i++)
609 {
610 RPS_sampler_update (rh->sampler, &peers[i]);
611 }
612}
613
614
615/**
616 * @brief Called once the sampler has collected all requested peers.
617 *
618 * Calls the callback provided by the client with the corresponding cls.
619 *
620 * @param peers The array of @a num_peers that has been returned.
621 * @param num_peers The number of peers that have been returned
622 * @param cls The #GNUNET_RPS_Request_Handle
623 */
624void
625peers_ready_cb (const struct GNUNET_PeerIdentity *peers,
626 uint32_t num_peers,
627 void *cls)
628{
629 struct GNUNET_RPS_Request_Handle *rh = cls;
630
631 rh->ready_cb (rh->ready_cb_cls,
632 num_peers,
633 peers);
634 // TODO cleanup, sampler, rh, cancel stuff
635 // TODO screw this function. We can give the cb,cls directly to the sampler.
636}
637
638/**
639 * Request n random peers.
640 *
641 * @param rps_handle handle to the rps service
642 * @param num_req_peers number of peers we want to receive
643 * @param ready_cb the callback called when the peers are available
644 * @param cls closure given to the callback
645 * @return a handle to cancel this request
646 */
647struct GNUNET_RPS_Request_Handle *
648GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle,
649 uint32_t num_req_peers,
650 GNUNET_RPS_NotifyReadyCB ready_cb,
651 void *cls)
652{
653 struct GNUNET_RPS_Request_Handle *rh;
654
655 rh = new_request_handle (rps_handle,
656 num_req_peers,
657 RPS_sampler_mod_init (num_req_peers,
658 GNUNET_TIME_UNIT_SECONDS), // TODO remove this time-stuff
659 ready_cb,
660 cls);
661 RPS_sampler_get_n_rand_peers (rh->sampler,
662 num_req_peers,
663 peers_ready_cb,
664 rh);
665
666 GNUNET_RPS_stream_request (rps_handle,
667 0, /* infinite updates */
668 collect_peers_cb,
669 rh); /* cls */
670
671 return rh;
672}
673
674
675/**
564 * Seed rps service with peerIDs. 676 * Seed rps service with peerIDs.
565 * 677 *
566 * @param h handle to the rps service 678 * @param h handle to the rps service