diff options
40 files changed, 1940 insertions, 1659 deletions
diff --git a/configure.ac b/configure.ac index 535ce0ffe..6a75b1ebf 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -1758,6 +1758,7 @@ src/vpn/vpn.conf | |||
1758 | src/zonemaster/Makefile | 1758 | src/zonemaster/Makefile |
1759 | src/zonemaster/zonemaster.conf | 1759 | src/zonemaster/zonemaster.conf |
1760 | src/rest/Makefile | 1760 | src/rest/Makefile |
1761 | src/rest-plugins/Makefile | ||
1761 | src/abe/Makefile | 1762 | src/abe/Makefile |
1762 | src/reclaim-attribute/Makefile | 1763 | src/reclaim-attribute/Makefile |
1763 | src/reclaim/Makefile | 1764 | src/reclaim/Makefile |
diff --git a/po/POTFILES.in b/po/POTFILES.in index 070ecc4ce..5eda765b1 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in | |||
@@ -235,7 +235,6 @@ src/namestore/namestore_api_monitor.c | |||
235 | src/namestore/plugin_namestore_flat.c | 235 | src/namestore/plugin_namestore_flat.c |
236 | src/namestore/plugin_namestore_postgres.c | 236 | src/namestore/plugin_namestore_postgres.c |
237 | src/namestore/plugin_namestore_sqlite.c | 237 | src/namestore/plugin_namestore_sqlite.c |
238 | src/namestore/plugin_rest_namestore.c | ||
239 | src/nat-auto/gnunet-nat-auto.c | 238 | src/nat-auto/gnunet-nat-auto.c |
240 | src/nat-auto/gnunet-nat-auto_legacy.c | 239 | src/nat-auto/gnunet-nat-auto_legacy.c |
241 | src/nat-auto/gnunet-nat-server.c | 240 | src/nat-auto/gnunet-nat-server.c |
@@ -262,7 +261,6 @@ src/nse/nse_api.c | |||
262 | src/peerinfo/gnunet-service-peerinfo.c | 261 | src/peerinfo/gnunet-service-peerinfo.c |
263 | src/peerinfo/peerinfo_api.c | 262 | src/peerinfo/peerinfo_api.c |
264 | src/peerinfo/peerinfo_api_notify.c | 263 | src/peerinfo/peerinfo_api_notify.c |
265 | src/peerinfo/plugin_rest_peerinfo.c | ||
266 | src/peerinfo-tool/gnunet-peerinfo.c | 264 | src/peerinfo-tool/gnunet-peerinfo.c |
267 | src/peerinfo-tool/gnunet-peerinfo_plugins.c | 265 | src/peerinfo-tool/gnunet-peerinfo_plugins.c |
268 | src/peerstore/gnunet-peerstore.c | 266 | src/peerstore/gnunet-peerstore.c |
@@ -297,8 +295,6 @@ src/reclaim/jwt.c | |||
297 | src/reclaim/oidc_helper.c | 295 | src/reclaim/oidc_helper.c |
298 | src/reclaim/plugin_gnsrecord_reclaim.c | 296 | src/reclaim/plugin_gnsrecord_reclaim.c |
299 | src/reclaim/plugin_reclaim_sqlite.c | 297 | src/reclaim/plugin_reclaim_sqlite.c |
300 | src/reclaim/plugin_rest_openid_connect.c | ||
301 | src/reclaim/plugin_rest_reclaim.c | ||
302 | src/reclaim/reclaim_api.c | 298 | src/reclaim/reclaim_api.c |
303 | src/regex/gnunet-daemon-regexprofiler.c | 299 | src/regex/gnunet-daemon-regexprofiler.c |
304 | src/regex/gnunet-regex-profiler.c | 300 | src/regex/gnunet-regex-profiler.c |
@@ -314,6 +310,13 @@ src/regex/regex_internal_dht.c | |||
314 | src/regex/regex_test_graph.c | 310 | src/regex/regex_test_graph.c |
315 | src/regex/regex_test_lib.c | 311 | src/regex/regex_test_lib.c |
316 | src/regex/regex_test_random.c | 312 | src/regex/regex_test_random.c |
313 | src/rest-plugins/oidc_helper.c | ||
314 | src/rest-plugins/plugin_rest_copying.c | ||
315 | src/rest-plugins/plugin_rest_gns.c | ||
316 | src/rest-plugins/plugin_rest_identity.c | ||
317 | src/rest-plugins/plugin_rest_namestore.c | ||
318 | src/rest-plugins/plugin_rest_openid_connect.c | ||
319 | src/rest-plugins/plugin_rest_peerinfo.c | ||
317 | src/rest/gnunet-rest-server.c | 320 | src/rest/gnunet-rest-server.c |
318 | src/rest/plugin_rest_copying.c | 321 | src/rest/plugin_rest_copying.c |
319 | src/rest/rest.c | 322 | src/rest/rest.c |
@@ -329,6 +332,7 @@ src/rps/gnunet-service-rps_sampler.c | |||
329 | src/rps/gnunet-service-rps_sampler_elem.c | 332 | src/rps/gnunet-service-rps_sampler_elem.c |
330 | src/rps/gnunet-service-rps_view.c | 333 | src/rps/gnunet-service-rps_view.c |
331 | src/rps/rps_api.c | 334 | src/rps/rps_api.c |
335 | src/rps/rps_test_lib.c | ||
332 | src/rps/rps-test_util.c | 336 | src/rps/rps-test_util.c |
333 | src/scalarproduct/gnunet-scalarproduct.c | 337 | src/scalarproduct/gnunet-scalarproduct.c |
334 | src/scalarproduct/gnunet-service-scalarproduct_alice.c | 338 | src/scalarproduct/gnunet-service-scalarproduct_alice.c |
diff --git a/src/Makefile.am b/src/Makefile.am index 53d157da3..43b1004eb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -65,9 +65,8 @@ if HAVE_POSTGRESQL | |||
65 | endif | 65 | endif |
66 | 66 | ||
67 | if HAVE_MHD | 67 | if HAVE_MHD |
68 | REST_DIR = rest | ||
69 | if HAVE_JSON | 68 | if HAVE_JSON |
70 | JSONAPI_DIR = jsonapi | 69 | REST_DIR = rest jsonapi rest-plugins |
71 | endif | 70 | endif |
72 | endif | 71 | endif |
73 | 72 | ||
@@ -82,9 +81,6 @@ SUBDIRS = \ | |||
82 | include $(INTLEMU_SUBDIRS) \ | 81 | include $(INTLEMU_SUBDIRS) \ |
83 | util \ | 82 | util \ |
84 | gnsrecord \ | 83 | gnsrecord \ |
85 | $(JSON_DIR) \ | ||
86 | $(REST_DIR) \ | ||
87 | $(JSONAPI_DIR) \ | ||
88 | hello \ | 84 | hello \ |
89 | block \ | 85 | block \ |
90 | statistics \ | 86 | statistics \ |
@@ -130,6 +126,8 @@ SUBDIRS = \ | |||
130 | exit \ | 126 | exit \ |
131 | pt \ | 127 | pt \ |
132 | secretsharing \ | 128 | secretsharing \ |
129 | $(JSON_DIR) \ | ||
130 | $(REST_DIR) \ | ||
133 | integration-tests \ | 131 | integration-tests \ |
134 | $(EXP_DIR) | 132 | $(EXP_DIR) |
135 | 133 | ||
diff --git a/src/cadet/Makefile.am b/src/cadet/Makefile.am index ce30ebe46..b2d436061 100644 --- a/src/cadet/Makefile.am +++ b/src/cadet/Makefile.am | |||
@@ -90,6 +90,7 @@ check_PROGRAMS = \ | |||
90 | test_cadet_2_speed_backwards \ | 90 | test_cadet_2_speed_backwards \ |
91 | test_cadet_2_speed_reliable \ | 91 | test_cadet_2_speed_reliable \ |
92 | test_cadet_2_speed_reliable_backwards \ | 92 | test_cadet_2_speed_reliable_backwards \ |
93 | test_cadet_2_reopen \ | ||
93 | test_cadet_5_forward \ | 94 | test_cadet_5_forward \ |
94 | test_cadet_5_signal \ | 95 | test_cadet_5_signal \ |
95 | test_cadet_5_keepalive \ | 96 | test_cadet_5_keepalive \ |
@@ -97,7 +98,8 @@ check_PROGRAMS = \ | |||
97 | test_cadet_5_speed_ack \ | 98 | test_cadet_5_speed_ack \ |
98 | test_cadet_5_speed_reliable \ | 99 | test_cadet_5_speed_reliable \ |
99 | test_cadet_5_speed_reliable_backwards \ | 100 | test_cadet_5_speed_reliable_backwards \ |
100 | test_cadet_5_speed_backwards | 101 | test_cadet_5_speed_backwards \ |
102 | test_cadet_5_reopen | ||
101 | endif | 103 | endif |
102 | 104 | ||
103 | 105 | ||
@@ -197,6 +199,14 @@ test_cadet_5_speed_reliable_backwards_SOURCES = \ | |||
197 | test_cadet.c | 199 | test_cadet.c |
198 | test_cadet_5_speed_reliable_backwards_LDADD = $(ld_cadet_test_lib) | 200 | test_cadet_5_speed_reliable_backwards_LDADD = $(ld_cadet_test_lib) |
199 | 201 | ||
202 | test_cadet_2_reopen_SOURCES = \ | ||
203 | test_cadet.c | ||
204 | test_cadet_2_reopen_LDADD = $(ld_cadet_test_lib) | ||
205 | |||
206 | test_cadet_5_reopen_SOURCES = \ | ||
207 | test_cadet.c | ||
208 | test_cadet_5_reopen_LDADD = $(ld_cadet_test_lib) | ||
209 | |||
200 | 210 | ||
201 | if ENABLE_TEST_RUN | 211 | if ENABLE_TEST_RUN |
202 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; | 212 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; |
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c index e2ca461a5..23ea46e59 100644 --- a/src/cadet/cadet_api.c +++ b/src/cadet/cadet_api.c | |||
@@ -549,6 +549,9 @@ cadet_mq_error_handler (void *cls, | |||
549 | else | 549 | else |
550 | { | 550 | { |
551 | GNUNET_break (0); | 551 | GNUNET_break (0); |
552 | if (NULL != ch->disconnects) | ||
553 | ch->disconnects (ch->ctx, | ||
554 | ch); | ||
552 | GNUNET_CADET_channel_destroy (ch); | 555 | GNUNET_CADET_channel_destroy (ch); |
553 | } | 556 | } |
554 | } | 557 | } |
diff --git a/src/cadet/gnunet-service-cadet_hello.c b/src/cadet/gnunet-service-cadet_hello.c index 61686e5da..0061bddc2 100644 --- a/src/cadet/gnunet-service-cadet_hello.c +++ b/src/cadet/gnunet-service-cadet_hello.c | |||
@@ -17,13 +17,10 @@ | |||
17 | */ | 17 | */ |
18 | /** | 18 | /** |
19 | * @file cadet/gnunet-service-cadet_hello.c | 19 | * @file cadet/gnunet-service-cadet_hello.c |
20 | * @brief spread knowledge about how to contact other peers from PEERINFO | 20 | * @brief spread knowledge about how to contact us (get HELLO from peerinfo), |
21 | * and remember HELLOs of other peers we have an interest in | ||
21 | * @author Bartlomiej Polot | 22 | * @author Bartlomiej Polot |
22 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
23 | * | ||
24 | * TODO: | ||
25 | * - is most of this necessary/helpful? | ||
26 | * - should we not simply restrict this to OUR hello? | ||
27 | */ | 24 | */ |
28 | #include "platform.h" | 25 | #include "platform.h" |
29 | #include "gnunet_util_lib.h" | 26 | #include "gnunet_util_lib.h" |
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c index 5187bc504..76ff258e0 100644 --- a/src/cadet/test_cadet.c +++ b/src/cadet/test_cadet.c | |||
@@ -70,6 +70,7 @@ struct CadetTestChannelWrapper | |||
70 | #define SPEED_ACK 4 | 70 | #define SPEED_ACK 4 |
71 | #define SPEED_REL 8 | 71 | #define SPEED_REL 8 |
72 | #define P2P_SIGNAL 10 | 72 | #define P2P_SIGNAL 10 |
73 | #define REOPEN 11 | ||
73 | 74 | ||
74 | /** | 75 | /** |
75 | * Which test are we running? | 76 | * Which test are we running? |
@@ -177,6 +178,11 @@ struct GNUNET_CADET_TEST_Context *test_ctx; | |||
177 | static struct GNUNET_SCHEDULER_Task *disconnect_task; | 178 | static struct GNUNET_SCHEDULER_Task *disconnect_task; |
178 | 179 | ||
179 | /** | 180 | /** |
181 | * Task called to reconnect peers. | ||
182 | */ | ||
183 | static struct GNUNET_SCHEDULER_Task *reconnect_task; | ||
184 | |||
185 | /** | ||
180 | * Task To perform tests | 186 | * Task To perform tests |
181 | */ | 187 | */ |
182 | static struct GNUNET_SCHEDULER_Task *test_task; | 188 | static struct GNUNET_SCHEDULER_Task *test_task; |
@@ -374,7 +380,8 @@ stats_cont (void *cls, | |||
374 | "KA sent: %u, KA received: %u\n", | 380 | "KA sent: %u, KA received: %u\n", |
375 | ka_sent, | 381 | ka_sent, |
376 | ka_received); | 382 | ka_received); |
377 | if ((KEEPALIVE == test) && ((ka_sent < 2) || (ka_sent > ka_received + 1))) | 383 | if ((KEEPALIVE == test || REOPEN == test) && |
384 | ((ka_sent < 2) || (ka_sent > ka_received + 1))) | ||
378 | { | 385 | { |
379 | GNUNET_break (0); | 386 | GNUNET_break (0); |
380 | ok--; | 387 | ok--; |
@@ -459,6 +466,152 @@ gather_stats_and_exit (void *cls) | |||
459 | 466 | ||
460 | 467 | ||
461 | /** | 468 | /** |
469 | * Send a message on the channel with the appropriate size and payload. | ||
470 | * | ||
471 | * Update the appropriate *_sent counter. | ||
472 | * | ||
473 | * @param channel Channel to send the message on. | ||
474 | */ | ||
475 | static void | ||
476 | send_test_message (struct GNUNET_CADET_Channel *channel); | ||
477 | |||
478 | /** | ||
479 | * Check if payload is sane (size contains payload). | ||
480 | * | ||
481 | * @param cls should match #ch | ||
482 | * @param message The actual message. | ||
483 | * @return #GNUNET_OK to keep the channel open, | ||
484 | * #GNUNET_SYSERR to close it (signal serious error). | ||
485 | */ | ||
486 | static int | ||
487 | check_data (void *cls, | ||
488 | const struct GNUNET_MessageHeader *message); | ||
489 | |||
490 | /** | ||
491 | * Function is called whenever a message is received. | ||
492 | * | ||
493 | * @param cls closure (set from GNUNET_CADET_connect(), peer number) | ||
494 | * @param message the actual message | ||
495 | */ | ||
496 | static void | ||
497 | handle_data (void *cls, | ||
498 | const struct GNUNET_MessageHeader *message); | ||
499 | |||
500 | /** | ||
501 | * Function called whenever an MQ-channel is destroyed, even if the destruction | ||
502 | * was requested by #GNUNET_CADET_channel_destroy. | ||
503 | * It must NOT call #GNUNET_CADET_channel_destroy on the channel. | ||
504 | * | ||
505 | * It should clean up any associated state, including cancelling any pending | ||
506 | * transmission on this channel. | ||
507 | * | ||
508 | * @param cls Channel closure (channel wrapper). | ||
509 | * @param channel Connection to the other end (henceforth invalid). | ||
510 | */ | ||
511 | static void | ||
512 | disconnect_handler (void *cls, | ||
513 | const struct GNUNET_CADET_Channel *channel); | ||
514 | |||
515 | |||
516 | /** | ||
517 | * Task to reconnect to other peer. | ||
518 | * | ||
519 | * @param cls Closure (line from which the task was scheduled). | ||
520 | */ | ||
521 | static void | ||
522 | reconnect_op (void *cls) | ||
523 | { | ||
524 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
525 | GNUNET_MQ_hd_var_size (data, | ||
526 | GNUNET_MESSAGE_TYPE_DUMMY, | ||
527 | struct GNUNET_MessageHeader, | ||
528 | NULL), | ||
529 | GNUNET_MQ_handler_end () | ||
530 | }; | ||
531 | long l = (long) cls; | ||
532 | struct CadetTestChannelWrapper *ch; | ||
533 | enum GNUNET_CADET_ChannelOption flags; | ||
534 | |||
535 | reconnect_task = NULL; | ||
536 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
537 | "reconnecting from line %ld\n", | ||
538 | l); | ||
539 | if (NULL != outgoing_ch) | ||
540 | { | ||
541 | GNUNET_CADET_channel_destroy (outgoing_ch); | ||
542 | outgoing_ch = NULL; | ||
543 | } | ||
544 | flags = GNUNET_CADET_OPTION_DEFAULT; | ||
545 | ch = GNUNET_new (struct CadetTestChannelWrapper); | ||
546 | outgoing_ch = GNUNET_CADET_channel_create (h1, | ||
547 | ch, | ||
548 | p_id[1], | ||
549 | &port, | ||
550 | flags, | ||
551 | NULL, | ||
552 | &disconnect_handler, | ||
553 | handlers); | ||
554 | ch->ch = outgoing_ch; | ||
555 | send_test_message (outgoing_ch); | ||
556 | } | ||
557 | |||
558 | /** | ||
559 | * Function called whenever an MQ-channel is destroyed, even if the destruction | ||
560 | * was requested by #GNUNET_CADET_channel_destroy. | ||
561 | * It must NOT call #GNUNET_CADET_channel_destroy on the channel. | ||
562 | * | ||
563 | * It should clean up any associated state, including cancelling any pending | ||
564 | * transmission on this channel. | ||
565 | * | ||
566 | * @param cls Channel closure (channel wrapper). | ||
567 | * @param channel Connection to the other end (henceforth invalid). | ||
568 | */ | ||
569 | static void | ||
570 | disconnect_handler (void *cls, | ||
571 | const struct GNUNET_CADET_Channel *channel) | ||
572 | { | ||
573 | struct CadetTestChannelWrapper *ch_w = cls; | ||
574 | |||
575 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
576 | "Channel disconnected at %d\n", | ||
577 | ok); | ||
578 | GNUNET_assert (ch_w->ch == channel); | ||
579 | if (channel == incoming_ch) | ||
580 | { | ||
581 | ok++; | ||
582 | incoming_ch = NULL; | ||
583 | } | ||
584 | else if (outgoing_ch == channel) | ||
585 | { | ||
586 | if (P2P_SIGNAL == test) | ||
587 | { | ||
588 | ok++; | ||
589 | } | ||
590 | outgoing_ch = NULL; | ||
591 | } | ||
592 | else | ||
593 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
594 | "Unknown channel! %p\n", | ||
595 | channel); | ||
596 | if (NULL != disconnect_task && REOPEN != test) | ||
597 | { | ||
598 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
599 | disconnect_task = | ||
600 | GNUNET_SCHEDULER_add_now (&gather_stats_and_exit, | ||
601 | (void *) __LINE__); | ||
602 | } | ||
603 | else if (NULL != reconnect_task && REOPEN == test) | ||
604 | { | ||
605 | GNUNET_SCHEDULER_cancel (reconnect_task); | ||
606 | reconnect_task = | ||
607 | GNUNET_SCHEDULER_add_now (&reconnect_op, | ||
608 | (void *) __LINE__); | ||
609 | } | ||
610 | GNUNET_free (ch_w); | ||
611 | } | ||
612 | |||
613 | |||
614 | /** | ||
462 | * Abort test: schedule disconnect and shutdown immediately | 615 | * Abort test: schedule disconnect and shutdown immediately |
463 | * | 616 | * |
464 | * @param line Line in the code the abort is requested from (__LINE__). | 617 | * @param line Line in the code the abort is requested from (__LINE__). |
@@ -536,6 +689,14 @@ send_test_message (struct GNUNET_CADET_Channel *channel) | |||
536 | { | 689 | { |
537 | payload = data_sent; | 690 | payload = data_sent; |
538 | } | 691 | } |
692 | else if (REOPEN == test) | ||
693 | { | ||
694 | payload = data_sent; | ||
695 | data_sent++; | ||
696 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
697 | "Sending DATA %u [%d bytes]\n", | ||
698 | data_sent, size); | ||
699 | } | ||
539 | else | 700 | else |
540 | { | 701 | { |
541 | GNUNET_assert (0); | 702 | GNUNET_assert (0); |
@@ -784,13 +945,29 @@ connect_handler (void *cls, | |||
784 | (long) cls); | 945 | (long) cls); |
785 | GNUNET_assert (0); | 946 | GNUNET_assert (0); |
786 | } | 947 | } |
787 | if (NULL != disconnect_task) | 948 | if (NULL != disconnect_task && REOPEN != test) |
788 | { | 949 | { |
789 | GNUNET_SCHEDULER_cancel (disconnect_task); | 950 | GNUNET_SCHEDULER_cancel (disconnect_task); |
790 | disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, | 951 | disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, |
791 | &gather_stats_and_exit, | 952 | &gather_stats_and_exit, |
792 | (void *) __LINE__); | 953 | (void *) __LINE__); |
793 | } | 954 | } |
955 | else if ((NULL != disconnect_task) && (REOPEN == test)) | ||
956 | { | ||
957 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
958 | disconnect_task = GNUNET_SCHEDULER_add_delayed ( | ||
959 | GNUNET_TIME_relative_multiply (short_time, 2), | ||
960 | &gather_stats_and_exit, | ||
961 | (void *) __LINE__); | ||
962 | } | ||
963 | |||
964 | if ((NULL != reconnect_task) && (REOPEN == test)) | ||
965 | { | ||
966 | GNUNET_SCHEDULER_cancel (reconnect_task); | ||
967 | reconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, | ||
968 | &reconnect_op, | ||
969 | (void *) __LINE__); | ||
970 | } | ||
794 | 971 | ||
795 | /* TODO: cannot return channel as-is, in order to unify the data handlers */ | 972 | /* TODO: cannot return channel as-is, in order to unify the data handlers */ |
796 | ch = GNUNET_new (struct CadetTestChannelWrapper); | 973 | ch = GNUNET_new (struct CadetTestChannelWrapper); |
@@ -801,55 +978,6 @@ connect_handler (void *cls, | |||
801 | 978 | ||
802 | 979 | ||
803 | /** | 980 | /** |
804 | * Function called whenever an MQ-channel is destroyed, even if the destruction | ||
805 | * was requested by #GNUNET_CADET_channel_destroy. | ||
806 | * It must NOT call #GNUNET_CADET_channel_destroy on the channel. | ||
807 | * | ||
808 | * It should clean up any associated state, including cancelling any pending | ||
809 | * transmission on this channel. | ||
810 | * | ||
811 | * @param cls Channel closure (channel wrapper). | ||
812 | * @param channel Connection to the other end (henceforth invalid). | ||
813 | */ | ||
814 | static void | ||
815 | disconnect_handler (void *cls, | ||
816 | const struct GNUNET_CADET_Channel *channel) | ||
817 | { | ||
818 | struct CadetTestChannelWrapper *ch_w = cls; | ||
819 | |||
820 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
821 | "Channel disconnected at %d\n", | ||
822 | ok); | ||
823 | GNUNET_assert (ch_w->ch == channel); | ||
824 | if (channel == incoming_ch) | ||
825 | { | ||
826 | ok++; | ||
827 | incoming_ch = NULL; | ||
828 | } | ||
829 | else if (outgoing_ch == channel) | ||
830 | { | ||
831 | if (P2P_SIGNAL == test) | ||
832 | { | ||
833 | ok++; | ||
834 | } | ||
835 | outgoing_ch = NULL; | ||
836 | } | ||
837 | else | ||
838 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
839 | "Unknown channel! %p\n", | ||
840 | channel); | ||
841 | if (NULL != disconnect_task) | ||
842 | { | ||
843 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
844 | disconnect_task = | ||
845 | GNUNET_SCHEDULER_add_now (&gather_stats_and_exit, | ||
846 | (void *) __LINE__); | ||
847 | } | ||
848 | GNUNET_free (ch_w); | ||
849 | } | ||
850 | |||
851 | |||
852 | /** | ||
853 | * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES. | 981 | * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES. |
854 | * | 982 | * |
855 | * Testcase continues when the root receives confirmation of connected peers, | 983 | * Testcase continues when the root receives confirmation of connected peers, |
@@ -871,7 +999,7 @@ start_test (void *cls) | |||
871 | enum GNUNET_CADET_ChannelOption flags; | 999 | enum GNUNET_CADET_ChannelOption flags; |
872 | 1000 | ||
873 | test_task = NULL; | 1001 | test_task = NULL; |
874 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "start_test\n"); | 1002 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "start_test: %s\n", test_name); |
875 | if (NULL != disconnect_task) | 1003 | if (NULL != disconnect_task) |
876 | { | 1004 | { |
877 | GNUNET_SCHEDULER_cancel (disconnect_task); | 1005 | GNUNET_SCHEDULER_cancel (disconnect_task); |
@@ -903,7 +1031,6 @@ start_test (void *cls) | |||
903 | if (KEEPALIVE == test) | 1031 | if (KEEPALIVE == test) |
904 | return; /* Don't send any data. */ | 1032 | return; /* Don't send any data. */ |
905 | 1033 | ||
906 | |||
907 | data_received = 0; | 1034 | data_received = 0; |
908 | data_sent = 0; | 1035 | data_sent = 0; |
909 | ack_received = 0; | 1036 | ack_received = 0; |
@@ -912,6 +1039,18 @@ start_test (void *cls) | |||
912 | "Sending data initializer on channel %p...\n", | 1039 | "Sending data initializer on channel %p...\n", |
913 | outgoing_ch); | 1040 | outgoing_ch); |
914 | send_test_message (outgoing_ch); | 1041 | send_test_message (outgoing_ch); |
1042 | if (REOPEN == test) | ||
1043 | { | ||
1044 | reconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, | ||
1045 | &reconnect_op, | ||
1046 | (void *) __LINE__); | ||
1047 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
1048 | disconnect_task = GNUNET_SCHEDULER_add_delayed ( | ||
1049 | GNUNET_TIME_relative_multiply (short_time, 2), | ||
1050 | &gather_stats_and_exit, | ||
1051 | (void *) __LINE__); | ||
1052 | } | ||
1053 | |||
915 | } | 1054 | } |
916 | 1055 | ||
917 | 1056 | ||
@@ -1055,6 +1194,11 @@ main (int argc, char *argv[]) | |||
1055 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "5 PEER LINE\n"); | 1194 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "5 PEER LINE\n"); |
1056 | peers_requested = 5; | 1195 | peers_requested = 5; |
1057 | } | 1196 | } |
1197 | else if (strstr (argv[0], "_6_") != NULL) | ||
1198 | { | ||
1199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "6 PEER LINE\n"); | ||
1200 | peers_requested = 6; | ||
1201 | } | ||
1058 | else | 1202 | else |
1059 | { | 1203 | { |
1060 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "SIZE UNKNOWN, USING 2\n"); | 1204 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "SIZE UNKNOWN, USING 2\n"); |
@@ -1122,6 +1266,17 @@ main (int argc, char *argv[]) | |||
1122 | */ | 1266 | */ |
1123 | ok_goal = 2; | 1267 | ok_goal = 2; |
1124 | } | 1268 | } |
1269 | else if (strstr (argv[0], "_reopen") != NULL) | ||
1270 | { | ||
1271 | test = REOPEN; | ||
1272 | test_name = "reopen"; | ||
1273 | ///* Test is supposed to generate the following callbacks: | ||
1274 | // * 1 incoming channel (@dest) | ||
1275 | // * [wait] | ||
1276 | // * 1 received channel destroy (@dest) | ||
1277 | // */ | ||
1278 | ok_goal = 7; | ||
1279 | } | ||
1125 | else | 1280 | else |
1126 | { | 1281 | { |
1127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n"); | 1282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n"); |
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 2c7bb8ebb..2659f7e6a 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am | |||
@@ -92,12 +92,6 @@ plugin_LTLIBRARIES = \ | |||
92 | libgnunet_plugin_gnsrecord_gns.la | 92 | libgnunet_plugin_gnsrecord_gns.la |
93 | 93 | ||
94 | 94 | ||
95 | if HAVE_MHD | ||
96 | if HAVE_JSON | ||
97 | plugin_LTLIBRARIES += libgnunet_plugin_rest_gns.la | ||
98 | endif | ||
99 | endif | ||
100 | |||
101 | libgnunet_plugin_gnsrecord_gns_la_SOURCES = \ | 95 | libgnunet_plugin_gnsrecord_gns_la_SOURCES = \ |
102 | plugin_gnsrecord_gns.c | 96 | plugin_gnsrecord_gns.c |
103 | libgnunet_plugin_gnsrecord_gns_la_LIBADD = \ | 97 | libgnunet_plugin_gnsrecord_gns_la_LIBADD = \ |
@@ -238,19 +232,6 @@ libgnunet_plugin_block_gns_la_LIBADD = \ | |||
238 | libgnunet_plugin_block_gns_la_LDFLAGS = \ | 232 | libgnunet_plugin_block_gns_la_LDFLAGS = \ |
239 | $(GN_PLUGIN_LDFLAGS) | 233 | $(GN_PLUGIN_LDFLAGS) |
240 | 234 | ||
241 | libgnunet_plugin_rest_gns_la_SOURCES = \ | ||
242 | plugin_rest_gns.c | ||
243 | libgnunet_plugin_rest_gns_la_LIBADD = \ | ||
244 | libgnunetgns.la \ | ||
245 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
246 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
247 | $(top_builddir)/src/jsonapi/libgnunetjsonapi.la \ | ||
248 | $(top_builddir)/src/jsonapi/libgnunetjsonapiutils.la \ | ||
249 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
250 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
251 | libgnunet_plugin_rest_gns_la_LDFLAGS = \ | ||
252 | $(GN_PLUGIN_LDFLAGS) | ||
253 | |||
254 | 235 | ||
255 | check_SCRIPTS = \ | 236 | check_SCRIPTS = \ |
256 | test_gns_lookup.sh \ | 237 | test_gns_lookup.sh \ |
diff --git a/src/hostlist/hostlist.conf b/src/hostlist/hostlist.conf index 59cc351cc..32e5d8320 100644 --- a/src/hostlist/hostlist.conf +++ b/src/hostlist/hostlist.conf | |||
@@ -41,3 +41,5 @@ SERVERS = http://v10.gnunet.org/hostlist https://gnunet.io/hostlist | |||
41 | # Valid values: HTTP, HTTP_1_0, SOCKS4, SOCKS5, SOCKS4A, SOCKS5_HOSTNAME | 41 | # Valid values: HTTP, HTTP_1_0, SOCKS4, SOCKS5, SOCKS4A, SOCKS5_HOSTNAME |
42 | # Default: HTTP | 42 | # Default: HTTP |
43 | # PROXY_TYPE = HTTP | 43 | # PROXY_TYPE = HTTP |
44 | |||
45 | |||
diff --git a/src/identity/Makefile.am b/src/identity/Makefile.am index e7104f0c3..1f21fc65d 100644 --- a/src/identity/Makefile.am +++ b/src/identity/Makefile.am | |||
@@ -39,14 +39,6 @@ bin_PROGRAMS = \ | |||
39 | libexec_PROGRAMS = \ | 39 | libexec_PROGRAMS = \ |
40 | gnunet-service-identity | 40 | gnunet-service-identity |
41 | 41 | ||
42 | if HAVE_MHD | ||
43 | if HAVE_JSON | ||
44 | plugin_LTLIBRARIES = \ | ||
45 | libgnunet_plugin_rest_identity.la | ||
46 | endif | ||
47 | endif | ||
48 | |||
49 | |||
50 | gnunet_service_identity_SOURCES = \ | 42 | gnunet_service_identity_SOURCES = \ |
51 | gnunet-service-identity.c | 43 | gnunet-service-identity.c |
52 | gnunet_service_identity_LDADD = \ | 44 | gnunet_service_identity_LDADD = \ |
@@ -55,17 +47,6 @@ gnunet_service_identity_LDADD = \ | |||
55 | $(GN_LIBINTL) | 47 | $(GN_LIBINTL) |
56 | 48 | ||
57 | 49 | ||
58 | libgnunet_plugin_rest_identity_la_SOURCES = \ | ||
59 | plugin_rest_identity.c | ||
60 | libgnunet_plugin_rest_identity_la_LIBADD = \ | ||
61 | libgnunetidentity.la \ | ||
62 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
63 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
64 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
65 | libgnunet_plugin_rest_identity_la_LDFLAGS = \ | ||
66 | $(GN_PLUGIN_LDFLAGS) | ||
67 | |||
68 | |||
69 | gnunet_identity_SOURCES = \ | 50 | gnunet_identity_SOURCES = \ |
70 | gnunet-identity.c | 51 | gnunet-identity.c |
71 | gnunet_identity_LDADD = \ | 52 | gnunet_identity_LDADD = \ |
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c index 266f5ccc3..155c49cc5 100644 --- a/src/identity/gnunet-service-identity.c +++ b/src/identity/gnunet-service-identity.c | |||
@@ -752,7 +752,7 @@ handle_rename_message (void *cls, | |||
752 | old_name = GNUNET_strdup (old_name_tmp); | 752 | old_name = GNUNET_strdup (old_name_tmp); |
753 | GNUNET_STRINGS_utf8_tolower (old_name_tmp, old_name); | 753 | GNUNET_STRINGS_utf8_tolower (old_name_tmp, old_name); |
754 | new_name = GNUNET_strdup (&old_name_tmp[old_name_len]); | 754 | new_name = GNUNET_strdup (&old_name_tmp[old_name_len]); |
755 | GNUNET_STRINGS_utf8_tolower (&old_name_tmp[old_name_len], old_name); | 755 | GNUNET_STRINGS_utf8_tolower (&old_name_tmp[old_name_len], new_name); |
756 | 756 | ||
757 | /* check if new name is already in use */ | 757 | /* check if new name is already in use */ |
758 | for (ego = ego_head; NULL != ego; ego = ego->next) | 758 | for (ego = ego_head; NULL != ego; ego = ego->next) |
diff --git a/src/identity/test_plugin_rest_identity.sh b/src/identity/test_plugin_rest_identity.sh deleted file mode 100755 index d9377500e..000000000 --- a/src/identity/test_plugin_rest_identity.sh +++ /dev/null | |||
@@ -1,159 +0,0 @@ | |||
1 | #!/usr/bin/bash | ||
2 | |||
3 | #First, start gnunet-arm and the rest-service. | ||
4 | #Exit 0 means success, exit 1 means failed test | ||
5 | |||
6 | identity_link="http://localhost:7776/identity" | ||
7 | wrong_link="http://localhost:7776/identityandmore" | ||
8 | |||
9 | |||
10 | curl_get () { | ||
11 | #$1 is link | ||
12 | #$2 is grep | ||
13 | cache="$(curl -v "$1" 2>&1 | grep "$2")" | ||
14 | #echo $cache | ||
15 | if [ "" == "$cache" ] | ||
16 | then | ||
17 | exit 1 | ||
18 | fi | ||
19 | } | ||
20 | |||
21 | curl_post () { | ||
22 | #$1 is link | ||
23 | #$2 is data | ||
24 | #$3 is grep | ||
25 | cache="$(curl -v -X "POST" "$1" --data "$2" 2>&1 | grep "$3")" | ||
26 | #echo $cache | ||
27 | if [ "" == "$cache" ] | ||
28 | then | ||
29 | exit 1 | ||
30 | fi | ||
31 | } | ||
32 | |||
33 | curl_delete () { | ||
34 | #$1 is link | ||
35 | #$2 is grep | ||
36 | cache="$(curl -v -X "DELETE" "$1" 2>&1 | grep "$2")" | ||
37 | #echo $cache | ||
38 | if [ "" == "$cache" ] | ||
39 | then | ||
40 | exit 1 | ||
41 | fi | ||
42 | } | ||
43 | |||
44 | curl_put () { | ||
45 | #$1 is link | ||
46 | #$2 is data | ||
47 | #$3 is grep | ||
48 | cache="$(curl -v -X "PUT" "$1" --data "$2" 2>&1 | grep "$3")" | ||
49 | #echo $cache | ||
50 | if [ "" == "$cache" ] | ||
51 | then | ||
52 | exit 1 | ||
53 | fi | ||
54 | } | ||
55 | |||
56 | #Test GET | ||
57 | test="$(gnunet-identity -d)" | ||
58 | #if no identity exists | ||
59 | if [ "" == "$test" ] | ||
60 | then | ||
61 | curl_get "$identity_link" "error" | ||
62 | gnunet-identity -C "test_plugin_rest_identity" | ||
63 | name="$(gnunet-identity -d | awk 'NR==1{print $1}')" | ||
64 | public="$(gnunet-identity -d | awk 'NR==1{print $3}')" | ||
65 | |||
66 | curl_get "${identity_link}?name=$name" "$public" | ||
67 | curl_get "${identity_link}?name=" "error" | ||
68 | curl_get "${identity_link}?name=$public" "error" | ||
69 | |||
70 | curl_get "${identity_link}?pubkey=$public" "$name" | ||
71 | curl_get "${identity_link}?pubkey=$name" "error" | ||
72 | curl_get "${identity_link}?pubkey=" "error" | ||
73 | |||
74 | gnunet-identity -D "test_plugin_rest_identity" | ||
75 | else | ||
76 | name="$(gnunet-identity -d | awk 'NR==1{print $1}')" | ||
77 | public="$(gnunet-identity -d | awk 'NR==1{print $3}')" | ||
78 | |||
79 | curl_get "${identity_link}?name=$name" "$public" | ||
80 | curl_get "${identity_link}?name=" "error" | ||
81 | curl_get "${identity_link}?name=$public" "error" | ||
82 | |||
83 | curl_get "${identity_link}?pubkey=$public" "$name" | ||
84 | curl_get "${identity_link}?pubkey=$name" "error" | ||
85 | curl_get "${identity_link}?pubkey=" "error" | ||
86 | fi | ||
87 | |||
88 | #Test POST | ||
89 | gnunet-identity -D "test_plugin_rest_identity" > /dev/null 2>&1 | ||
90 | gnunet-identity -D "test_plugin_rest_identity1" > /dev/null 2>&1 | ||
91 | |||
92 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 201 Created" | ||
93 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 409" | ||
94 | curl_post "${identity_link}" '{"name":"Test_plugin_rest_identity"}' "HTTP/1.1 409" | ||
95 | curl_post "${identity_link}" '{}' "error" | ||
96 | curl_post "${identity_link}" '' "error" | ||
97 | curl_post "${identity_link}" '{"name":""}' "error" | ||
98 | curl_post "${identity_link}" '{"name":123}' "error" | ||
99 | curl_post "${identity_link}" '{"name":[]}' "error" | ||
100 | curl_post "${identity_link}" '{"name1":"test_plugin_rest_identity"}' "error" | ||
101 | curl_post "${identity_link}" '{"other":""}' "error" | ||
102 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1", "other":"test_plugin_rest_identity2"}' "error" | ||
103 | |||
104 | #Test PUT | ||
105 | name="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $1}')" | ||
106 | public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $3}')" | ||
107 | |||
108 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","pubkey":"'$public'"}' "HTTP/1.1 204" | ||
109 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","pubkey":"'$public'"}' "HTTP/1.1 409" | ||
110 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","pubkey":"'$public'xx"}' "HTTP/1.1 404" | ||
111 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","pubkey":""}' "HTTP/1.1 404" | ||
112 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","pubke":""}' "HTTP/1.1 404" | ||
113 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","pubke":"","other":"sdfdsf"}' "HTTP/1.1 404" | ||
114 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","pubke":"","name":"sdfdsf"}' "HTTP/1.1 404" | ||
115 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity","pubke":"","name":"test_plugin_rest_identity1"}' "HTTP/1.1 204" | ||
116 | curl_put "${identity_link}" '{"newnam":"test_plugin_rest_identity","pubkey":"'$public'"}' "error" | ||
117 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","name":"test_plugin_rest_identity"}' "HTTP/1.1 204" | ||
118 | curl_put "${identity_link}" '{"newname":"TEST_plugin_rest_identity1","name":"test_plugin_rest_identity1"}' "HTTP/1.1 409" | ||
119 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","name":"test_plugin_rest_identity1"}' "HTTP/1.1 409" | ||
120 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity","name":"test_plugin_rest_identityxxx"}' "HTTP/1.1 404" | ||
121 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity","name":"test_plugin_rest_identity1"}' "HTTP/1.1 204" | ||
122 | curl_put "${identity_link}" '{"newnam":"test_plugin_rest_identityfail","name":"test_plugin_rest_identity"}' "error" | ||
123 | |||
124 | |||
125 | #Test subsystem | ||
126 | curl_put "${identity_link}" '{"subsystem":"namestore","name":"test_plugin_rest_identity"}' "HTTP/1.1 204" | ||
127 | curl_put "${identity_link}" '{"subsystem":"namestore","name":"test_plugin_rest_identity"}' "HTTP/1.1 204" | ||
128 | curl_get "${identity_link}?subsystem=namestore" "test_plugin_rest_identity" | ||
129 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 201 Created" | ||
130 | public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $3}')" | ||
131 | curl_put "${identity_link}" '{"subsystem":"namestore","pubkey":"'"$public"'"}' "HTTP/1.1 204" | ||
132 | curl_get "${identity_link}?subsystem=namestore" "test_plugin_rest_identity1" | ||
133 | curl_get "${identity_link}?subsystem=test_plugin_rest_identity_no_subsystem" "error" | ||
134 | curl_put "${identity_link}" '{"subsystem":"test_plugin_rest_identity_no_subsystem","name":"test_plugin_rest_identity1"}' "HTTP/1.1 204" | ||
135 | curl_get "${identity_link}?subsystem=test_plugin_rest_identity_no_subsystem" "test_plugin_rest_identity1" | ||
136 | |||
137 | curl_put "${identity_link}" '{"subsyste":"test_plugin_rest_identity_no_subsystem","name":"test_plugin_rest_identity1"}' "error" | ||
138 | curl_put "${identity_link}" '{"subsystem":"test_plugin_rest_identity_no_subsystem","name":"Test_plugin_rest_identity1"}' "HTTP/1.1 204" | ||
139 | |||
140 | #Test DELETE | ||
141 | curl_delete "${identity_link}?name=test_plugin_rest_identity" "HTTP/1.1 204" | ||
142 | curl_get "${identity_link}?name=test_plugin_rest_identity" "error" | ||
143 | curl_delete "${identity_link}?name=TEST_plugin_rest_identity1" "HTTP/1.1 404" | ||
144 | curl_delete "${identity_link}?name=test_plugin_rest_identity1" "HTTP/1.1 204" | ||
145 | curl_get "${identity_link}?name=test_plugin_rest_identity1" "error" | ||
146 | curl_delete "${identity_link}?name=test_plugin_rest_identity_not_found" "HTTP/1.1 404" | ||
147 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 201 Created" | ||
148 | public="$(gnunet-identity -d | grep "test_plugin_rest_identity1" | awk 'NR==1{print $3}')" | ||
149 | curl_delete "${identity_link}?pubkey=$public" "HTTP/1.1 204" | ||
150 | curl_delete "${identity_link}?pubke=$public" "error" | ||
151 | curl_delete "${identity_link}?pubkey=$public&other=232" "HTTP/1.1 404" | ||
152 | |||
153 | #Test wrong_link | ||
154 | curl_get "$wrong_link" "HTTP/1.1 404" | ||
155 | curl_post "$wrong_link" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 404" | ||
156 | curl_put "$wrong_link" '{"newname":"test_plugin_rest_identity1","name":"test_plugin_rest_identity"}' "HTTP/1.1 404" | ||
157 | curl_delete "$wrong_link?name=test_plugin_rest_identity1" "HTTP/1.1 404" | ||
158 | |||
159 | exit 0; | ||
diff --git a/src/json/json_generator.c b/src/json/json_generator.c index d8c82bc86..96f07bdc2 100644 --- a/src/json/json_generator.c +++ b/src/json/json_generator.c | |||
@@ -182,12 +182,32 @@ GNUNET_JSON_from_gns_record (const char* rname, | |||
182 | record_type_str = GNUNET_GNSRECORD_number_to_typename(rd->record_type); | 182 | record_type_str = GNUNET_GNSRECORD_number_to_typename(rd->record_type); |
183 | 183 | ||
184 | // ? for possible NULL values | 184 | // ? for possible NULL values |
185 | ret = json_pack("{s:s?,s:s?,s:s?,s:i,s:s?}", | 185 | if (NULL != rname) |
186 | "value", value_str, | 186 | { |
187 | "type", record_type_str, | 187 | ret = json_pack ("{s:s?,s:s?,s:s?,s:i,s:s?}", |
188 | "expiration_time", expiration_time_str, | 188 | "value", |
189 | "flag", flags, | 189 | value_str, |
190 | "label", rname); | 190 | "record_type", |
191 | record_type_str, | ||
192 | "expiration_time", | ||
193 | expiration_time_str, | ||
194 | "flag", | ||
195 | flags, | ||
196 | "record_name", | ||
197 | rname); | ||
198 | } | ||
199 | else | ||
200 | { | ||
201 | ret = json_pack ("{s:s?,s:s?,s:s?,s:i}", | ||
202 | "value", | ||
203 | value_str, | ||
204 | "record_type", | ||
205 | record_type_str, | ||
206 | "expiration_time", | ||
207 | expiration_time_str, | ||
208 | "flag", | ||
209 | flags); | ||
210 | } | ||
191 | GNUNET_free_non_null(value_str); | 211 | GNUNET_free_non_null(value_str); |
192 | return ret; | 212 | return ret; |
193 | } | 213 | } |
diff --git a/src/json/json_gnsrecord.c b/src/json/json_gnsrecord.c index 7bdf97f06..fe51119b1 100644 --- a/src/json/json_gnsrecord.c +++ b/src/json/json_gnsrecord.c | |||
@@ -26,10 +26,10 @@ | |||
26 | #include "gnunet_json_lib.h" | 26 | #include "gnunet_json_lib.h" |
27 | 27 | ||
28 | #define GNUNET_JSON_GNSRECORD_VALUE "value" | 28 | #define GNUNET_JSON_GNSRECORD_VALUE "value" |
29 | #define GNUNET_JSON_GNSRECORD_TYPE "type" | 29 | #define GNUNET_JSON_GNSRECORD_TYPE "record_type" |
30 | #define GNUNET_JSON_GNSRECORD_EXPIRATION_TIME "expiration_time" | 30 | #define GNUNET_JSON_GNSRECORD_EXPIRATION_TIME "expiration_time" |
31 | #define GNUNET_JSON_GNSRECORD_FLAG "flag" | 31 | #define GNUNET_JSON_GNSRECORD_FLAG "flag" |
32 | #define GNUNET_JSON_GNSRECORD_LABEL "label" | 32 | #define GNUNET_JSON_GNSRECORD_RECORD_NAME "record_name" |
33 | #define GNUNET_JSON_GNSRECORD_NEVER "never" | 33 | #define GNUNET_JSON_GNSRECORD_NEVER "never" |
34 | 34 | ||
35 | 35 | ||
@@ -52,7 +52,7 @@ parse_gnsrecordobject (void *cls, | |||
52 | const char *value; | 52 | const char *value; |
53 | const char *expiration_time; | 53 | const char *expiration_time; |
54 | const char *record_type; | 54 | const char *record_type; |
55 | const char *label; | 55 | const char *name; |
56 | int flag; | 56 | int flag; |
57 | void *rdata = NULL; | 57 | void *rdata = NULL; |
58 | size_t rdata_size; | 58 | size_t rdata_size; |
@@ -71,7 +71,7 @@ parse_gnsrecordobject (void *cls, | |||
71 | GNUNET_JSON_GNSRECORD_TYPE, &record_type, | 71 | GNUNET_JSON_GNSRECORD_TYPE, &record_type, |
72 | GNUNET_JSON_GNSRECORD_EXPIRATION_TIME, &expiration_time, | 72 | GNUNET_JSON_GNSRECORD_EXPIRATION_TIME, &expiration_time, |
73 | GNUNET_JSON_GNSRECORD_FLAG, &flag, | 73 | GNUNET_JSON_GNSRECORD_FLAG, &flag, |
74 | GNUNET_JSON_GNSRECORD_LABEL, &label); | 74 | GNUNET_JSON_GNSRECORD_RECORD_NAME, &name); |
75 | if (0 != unpack_state) | 75 | if (0 != unpack_state) |
76 | { | 76 | { |
77 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 77 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
diff --git a/src/jsonapi/Makefile.am b/src/jsonapi/Makefile.am index 054d3c550..489c4d9f2 100644 --- a/src/jsonapi/Makefile.am +++ b/src/jsonapi/Makefile.am | |||
@@ -10,6 +10,25 @@ lib_LTLIBRARIES = \ | |||
10 | libgnunetjsonapi.la \ | 10 | libgnunetjsonapi.la \ |
11 | libgnunetjsonapiutils.la | 11 | libgnunetjsonapiutils.la |
12 | 12 | ||
13 | if HAVE_ABE | ||
14 | lib_LTLIBRARIES += libgnunet_plugin_rest_reclaim.la | ||
15 | endif | ||
16 | |||
17 | libgnunet_plugin_rest_reclaim_la_SOURCES = \ | ||
18 | plugin_rest_reclaim.c | ||
19 | libgnunet_plugin_rest_reclaim_la_LIBADD = \ | ||
20 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
21 | $(top_builddir)/src/reclaim/libgnunetreclaim.la \ | ||
22 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
23 | libgnunetjsonapi.la \ | ||
24 | $(top_builddir)/src/reclaim-attribute/libgnunetreclaimattribute.la \ | ||
25 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | ||
26 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
27 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
28 | libgnunet_plugin_rest_reclaim_la_LDFLAGS = \ | ||
29 | i$(GN_PLUGIN_LDFLAGS) | ||
30 | |||
31 | |||
13 | libgnunetjsonapiutils_la_LDFLAGS = \ | 32 | libgnunetjsonapiutils_la_LDFLAGS = \ |
14 | -version-info 0:0:0 \ | 33 | -version-info 0:0:0 \ |
15 | -no-undefined | 34 | -no-undefined |
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/jsonapi/plugin_rest_reclaim.c index 38ffc4ddb..38ffc4ddb 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/jsonapi/plugin_rest_reclaim.c | |||
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index 7f44c2a71..a349921d7 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am | |||
@@ -97,12 +97,6 @@ check_PROGRAMS = \ | |||
97 | $(FLAT_TESTS) | 97 | $(FLAT_TESTS) |
98 | endif | 98 | endif |
99 | 99 | ||
100 | if HAVE_MHD | ||
101 | if HAVE_JSON | ||
102 | REST_PLUGIN=libgnunet_plugin_rest_namestore.la | ||
103 | endif | ||
104 | endif | ||
105 | |||
106 | if ENABLE_TEST_RUN | 100 | if ENABLE_TEST_RUN |
107 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; | 101 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; |
108 | TESTS = \ | 102 | TESTS = \ |
@@ -186,8 +180,7 @@ gnunet_service_namestore_LDADD = \ | |||
186 | plugin_LTLIBRARIES = \ | 180 | plugin_LTLIBRARIES = \ |
187 | $(SQLITE_PLUGIN) \ | 181 | $(SQLITE_PLUGIN) \ |
188 | $(POSTGRES_PLUGIN) \ | 182 | $(POSTGRES_PLUGIN) \ |
189 | $(FLAT_PLUGIN) \ | 183 | $(FLAT_PLUGIN) |
190 | $(REST_PLUGIN) | ||
191 | 184 | ||
192 | 185 | ||
193 | 186 | ||
@@ -224,20 +217,6 @@ libgnunet_plugin_namestore_postgres_la_LIBADD = \ | |||
224 | libgnunet_plugin_namestore_postgres_la_LDFLAGS = \ | 217 | libgnunet_plugin_namestore_postgres_la_LDFLAGS = \ |
225 | $(GN_PLUGIN_LDFLAGS) $(POSTGRESQL_LDFLAGS) | 218 | $(GN_PLUGIN_LDFLAGS) $(POSTGRESQL_LDFLAGS) |
226 | 219 | ||
227 | libgnunet_plugin_rest_namestore_la_SOURCES = \ | ||
228 | plugin_rest_namestore.c | ||
229 | libgnunet_plugin_rest_namestore_la_LIBADD = \ | ||
230 | libgnunetnamestore.la \ | ||
231 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
232 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
233 | $(top_builddir)/src/json/libgnunetjson.la \ | ||
234 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
235 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
236 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
237 | libgnunet_plugin_rest_namestore_la_LDFLAGS = \ | ||
238 | $(GN_PLUGIN_LDFLAGS) | ||
239 | |||
240 | |||
241 | test_namestore_api_store_flat_SOURCES = \ | 220 | test_namestore_api_store_flat_SOURCES = \ |
242 | test_namestore_api_store.c | 221 | test_namestore_api_store.c |
243 | test_namestore_api_store_flat_LDADD = \ | 222 | test_namestore_api_store_flat_LDADD = \ |
diff --git a/src/namestore/test_plugin_rest_namestore.sh b/src/namestore/test_plugin_rest_namestore.sh deleted file mode 100755 index de02dfafc..000000000 --- a/src/namestore/test_plugin_rest_namestore.sh +++ /dev/null | |||
@@ -1,208 +0,0 @@ | |||
1 | #!/usr/bin/bash | ||
2 | |||
3 | #First, start gnunet-arm and the rest-service. | ||
4 | #Exit 0 means success, exit 1 means failed test | ||
5 | |||
6 | namestore_link="http://localhost:7776/namestore" | ||
7 | wrong_link="http://localhost:7776/namestoreandmore" | ||
8 | |||
9 | |||
10 | curl_get () { | ||
11 | #$1 is link | ||
12 | #$2 is grep | ||
13 | cache="$(curl -v "$1" 2>&1 | grep "$2")" | ||
14 | #echo $cache | ||
15 | if [ "" == "$cache" ] | ||
16 | then | ||
17 | exit 1 | ||
18 | fi | ||
19 | } | ||
20 | |||
21 | curl_post () { | ||
22 | #$1 is link | ||
23 | #$2 is data | ||
24 | #$3 is grep | ||
25 | cache="$(curl -v -X "POST" "$1" --data "$2" 2>&1 | grep "$3")" | ||
26 | #echo $cache | ||
27 | if [ "" == "$cache" ] | ||
28 | then | ||
29 | exit 1 | ||
30 | fi | ||
31 | } | ||
32 | |||
33 | curl_delete () { | ||
34 | #$1 is link | ||
35 | #$2 is grep | ||
36 | cache="$(curl -v -X "DELETE" "$1" 2>&1 | grep "$2")" | ||
37 | #echo $cache | ||
38 | if [ "" == "$cache" ] | ||
39 | then | ||
40 | exit 1 | ||
41 | fi | ||
42 | } | ||
43 | |||
44 | # curl_put () { | ||
45 | # #$1 is link | ||
46 | # #$2 is data | ||
47 | # #$3 is grep | ||
48 | # cache="$(curl -v -X "PUT" "$1" --data "$2" 2>&1 | grep "$3")" | ||
49 | # #echo $cache | ||
50 | # if [ "" == "$cache" ] | ||
51 | # then | ||
52 | # exit 1 | ||
53 | # fi | ||
54 | # } | ||
55 | |||
56 | #Test subsystem default identity | ||
57 | |||
58 | #Test GET | ||
59 | gnunet-identity -D "test_plugin_rest_namestore" | ||
60 | gnunet-identity -C "test_plugin_rest_namestore" | ||
61 | test="$(gnunet-namestore -D -z "test_plugin_rest_namestore")" | ||
62 | name="test_plugin_rest_namestore" | ||
63 | public="$(gnunet-identity -d | grep "test_plugin_rest_namestore" | awk 'NR==1{print $3}')" | ||
64 | if [ "" == "$test" ] | ||
65 | then | ||
66 | #if no entries for test_plugin_rest_namestore | ||
67 | curl_get "${namestore_link}?name=$name" "error" | ||
68 | curl_get "${namestore_link}?name=" "error" | ||
69 | curl_get "${namestore_link}?name=$public" "error" | ||
70 | |||
71 | curl_get "${namestore_link}?pubkey=$public" "error" | ||
72 | curl_get "${namestore_link}?pubkey=$name" "error" | ||
73 | curl_get "${namestore_link}?pubkey=" "error" | ||
74 | else | ||
75 | #if entries exists (that should not be possible) | ||
76 | curl_get "${namestore_link}" "HTTP/1.1 200 OK" | ||
77 | curl_get "${namestore_link}?name=$name" "HTTP/1.1 200 OK" | ||
78 | curl_get "${namestore_link}?name=" "error" | ||
79 | curl_get "${namestore_link}?name=$public" "error" | ||
80 | |||
81 | curl_get "${namestore_link}?pubkey=$public" "HTTP/1.1 200 OK" | ||
82 | curl_get "${namestore_link}?pubkey=$name" "error" | ||
83 | curl_get "${namestore_link}?pubkey=" "error" | ||
84 | fi | ||
85 | gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" | ||
86 | curl_get "${namestore_link}" "HTTP/1.1 200 OK" | ||
87 | curl_get "${namestore_link}?name=$name" "HTTP/1.1 200 OK" | ||
88 | curl_get "${namestore_link}?name=" "error" | ||
89 | curl_get "${namestore_link}?name=$public" "error" | ||
90 | curl_get "${namestore_link}?pubkey=$public" "HTTP/1.1 200 OK" | ||
91 | curl_get "${namestore_link}?pubkey=$name" "error" | ||
92 | curl_get "${namestore_link}?pubkey=" "error" | ||
93 | gnunet-namestore -z $name -d -n "test_entry" | ||
94 | |||
95 | #Test POST with NAME | ||
96 | curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content" | ||
97 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
98 | #value | ||
99 | curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error" | ||
100 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
101 | curl_post "${namestore_link}?name=$name" '{"value":"", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error" | ||
102 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
103 | curl_post "${namestore_link}?name=$name" '{"value_missing":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error" | ||
104 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
105 | #time | ||
106 | curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"0d","flag":0,"label":"test_entry"}' "HTTP/1.1 204" | ||
107 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
108 | curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"10000d","flag":0,"label":"test_entry"}' "HTTP/1.1 204" | ||
109 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
110 | curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"now","flag":0,"label":"test_entry"}' "error" | ||
111 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
112 | curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"","flag":0,"label":"test_entry"}' "error" | ||
113 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
114 | curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time_missing":"1d","flag":0,"label":"test_entry"}' "error" | ||
115 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
116 | #flag | ||
117 | curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content" | ||
118 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
119 | curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":2,"label":"test_entry"}' "HTTP/1.1 204 No Content" | ||
120 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
121 | curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":8,"label":"test_entry"}' "HTTP/1.1 204 No Content" | ||
122 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
123 | curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":16,"label":"test_entry"}' "HTTP/1.1 204 No Content" | ||
124 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
125 | curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":-1,"label":"test_entry"}' "error" | ||
126 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
127 | curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":"Test","label":"test_entry"}' "error" | ||
128 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
129 | curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":,"label":"test_entry"}' "error" | ||
130 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
131 | curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag_missing":0,"label":"test_entry"}' "error" | ||
132 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
133 | #label | ||
134 | curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content" | ||
135 | curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 409" | ||
136 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
137 | curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":""}' "error" | ||
138 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
139 | curl_post "${namestore_link}?name=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label_missing":"test_entry"}' "error" | ||
140 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
141 | |||
142 | #Test POST with PUBKEY | ||
143 | curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content" | ||
144 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
145 | #value | ||
146 | curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error" | ||
147 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
148 | curl_post "${namestore_link}?pubkey=$public" '{"value":"", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error" | ||
149 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
150 | curl_post "${namestore_link}?pubkey=$public" '{"value_missing":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error" | ||
151 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
152 | #time | ||
153 | curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"0d","flag":0,"label":"test_entry"}' "HTTP/1.1 204" | ||
154 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
155 | curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"10000d","flag":0,"label":"test_entry"}' "HTTP/1.1 204" | ||
156 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
157 | curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"now","flag":0,"label":"test_entry"}' "error" | ||
158 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
159 | curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"","flag":0,"label":"test_entry"}' "error" | ||
160 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
161 | curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time_missing":"1d","flag":0,"label":"test_entry"}' "error" | ||
162 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
163 | #flag | ||
164 | curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content" | ||
165 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
166 | curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":2,"label":"test_entry"}' "HTTP/1.1 204 No Content" | ||
167 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
168 | curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":8,"label":"test_entry"}' "HTTP/1.1 204 No Content" | ||
169 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
170 | curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":16,"label":"test_entry"}' "HTTP/1.1 204 No Content" | ||
171 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
172 | curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":-1,"label":"test_entry"}' "error" | ||
173 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
174 | curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":"Test","label":"test_entry"}' "error" | ||
175 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
176 | curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":,"label":"test_entry"}' "error" | ||
177 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
178 | curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag_missing":0,"label":"test_entry"}' "error" | ||
179 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
180 | #label | ||
181 | curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 204 No Content" | ||
182 | curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "HTTP/1.1 409" | ||
183 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
184 | curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":""}' "error" | ||
185 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
186 | curl_post "${namestore_link}?pubkey=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label_missing":"test_entry"}' "error" | ||
187 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
188 | |||
189 | #wrong zone | ||
190 | curl_post "${namestore_link}?name=$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error" | ||
191 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
192 | curl_post "${namestore_link}?pubkey=$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "type":"PKEY", "expiration_time":"1d","flag":0,"label":"test_entry"}' "error" | ||
193 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
194 | |||
195 | #Test DELETE | ||
196 | gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" | ||
197 | curl_delete "${namestore_link}?label=test_entry&name=$name" "HTTP/1.1 204" | ||
198 | gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" | ||
199 | curl_delete "${namestore_link}?label=test_entry&pubkey=$public" "HTTP/1.1 204" | ||
200 | gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" | ||
201 | curl_delete "${namestore_link}?label=test_entry&pubkey=$name" "HTTP/1.1 404" | ||
202 | |||
203 | |||
204 | #Test default identity | ||
205 | #not possible without defining | ||
206 | |||
207 | exit 0; | ||
208 | |||
diff --git a/src/peerinfo-tool/Makefile.am b/src/peerinfo-tool/Makefile.am index 6f9a3360c..429224650 100644 --- a/src/peerinfo-tool/Makefile.am +++ b/src/peerinfo-tool/Makefile.am | |||
@@ -26,27 +26,6 @@ gnunet_peerinfo_LDADD = \ | |||
26 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 26 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
27 | $(top_builddir)/src/util/libgnunetutil.la | 27 | $(top_builddir)/src/util/libgnunetutil.la |
28 | 28 | ||
29 | if HAVE_MHD | ||
30 | if HAVE_JSON | ||
31 | plugin_LTLIBRARIES = \ | ||
32 | libgnunet_plugin_rest_peerinfo.la | ||
33 | endif | ||
34 | endif | ||
35 | |||
36 | |||
37 | libgnunet_plugin_rest_peerinfo_la_SOURCES = \ | ||
38 | plugin_rest_peerinfo.c | ||
39 | libgnunet_plugin_rest_peerinfo_la_LIBADD = \ | ||
40 | $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ | ||
41 | $(top_builddir)/src/transport/libgnunettransport.la \ | ||
42 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
43 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
44 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
45 | libgnunet_plugin_rest_peerinfo_la_LDFLAGS = \ | ||
46 | $(GN_PLUGIN_LDFLAGS) | ||
47 | |||
48 | |||
49 | |||
50 | if HAVE_PYTHON | 29 | if HAVE_PYTHON |
51 | check_SCRIPTS = \ | 30 | check_SCRIPTS = \ |
52 | test_gnunet_peerinfo.py | 31 | test_gnunet_peerinfo.py |
diff --git a/src/peerinfo/Makefile.am b/src/peerinfo/Makefile.am index 926b9ae94..ef79d6720 100644 --- a/src/peerinfo/Makefile.am +++ b/src/peerinfo/Makefile.am | |||
@@ -25,7 +25,6 @@ libgnunetpeerinfo_la_SOURCES = \ | |||
25 | libgnunetpeerinfo_la_LIBADD = \ | 25 | libgnunetpeerinfo_la_LIBADD = \ |
26 | $(top_builddir)/src/hello/libgnunethello.la \ | 26 | $(top_builddir)/src/hello/libgnunethello.la \ |
27 | $(top_builddir)/src/util/libgnunetutil.la \ | 27 | $(top_builddir)/src/util/libgnunetutil.la \ |
28 | $(top_builddir)/src/json/libgnunetjson.la \ | ||
29 | $(XLIB) \ | 28 | $(XLIB) \ |
30 | $(LTLIBINTL) | 29 | $(LTLIBINTL) |
31 | libgnunetpeerinfo_la_LDFLAGS = \ | 30 | libgnunetpeerinfo_la_LDFLAGS = \ |
diff --git a/src/reclaim/Makefile.am b/src/reclaim/Makefile.am index 2ee43d21a..093442181 100644 --- a/src/reclaim/Makefile.am +++ b/src/reclaim/Makefile.am | |||
@@ -31,8 +31,6 @@ pkgcfg_DATA = \ | |||
31 | lib_LTLIBRARIES = \ | 31 | lib_LTLIBRARIES = \ |
32 | libgnunetreclaim.la | 32 | libgnunetreclaim.la |
33 | plugin_LTLIBRARIES = \ | 33 | plugin_LTLIBRARIES = \ |
34 | libgnunet_plugin_rest_reclaim.la \ | ||
35 | libgnunet_plugin_rest_openid_connect.la \ | ||
36 | libgnunet_plugin_gnsrecord_reclaim.la \ | 34 | libgnunet_plugin_gnsrecord_reclaim.la \ |
37 | $(SQLITE_PLUGIN) | 35 | $(SQLITE_PLUGIN) |
38 | 36 | ||
@@ -88,37 +86,6 @@ libgnunetreclaim_la_LDFLAGS = \ | |||
88 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ | 86 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ |
89 | -version-info 0:0:0 | 87 | -version-info 0:0:0 |
90 | 88 | ||
91 | libgnunet_plugin_rest_reclaim_la_SOURCES = \ | ||
92 | plugin_rest_reclaim.c | ||
93 | libgnunet_plugin_rest_reclaim_la_LIBADD = \ | ||
94 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
95 | libgnunetreclaim.la \ | ||
96 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
97 | $(top_builddir)/src/jsonapi/libgnunetjsonapi.la \ | ||
98 | $(top_builddir)/src/reclaim-attribute/libgnunetreclaimattribute.la \ | ||
99 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | ||
100 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
101 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
102 | libgnunet_plugin_rest_reclaim_la_LDFLAGS = \ | ||
103 | $(GN_PLUGIN_LDFLAGS) | ||
104 | |||
105 | libgnunet_plugin_rest_openid_connect_la_SOURCES = \ | ||
106 | plugin_rest_openid_connect.c \ | ||
107 | oidc_helper.c | ||
108 | libgnunet_plugin_rest_openid_connect_la_LIBADD = \ | ||
109 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
110 | libgnunetreclaim.la \ | ||
111 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
112 | $(top_builddir)/src/jsonapi/libgnunetjsonapi.la \ | ||
113 | $(top_builddir)/src/reclaim-attribute/libgnunetreclaimattribute.la \ | ||
114 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | ||
115 | $(top_builddir)/src/gns/libgnunetgns.la \ | ||
116 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
117 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
118 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
119 | libgnunet_plugin_rest_openid_connect_la_LDFLAGS = \ | ||
120 | $(GN_PLUGIN_LDFLAGS) | ||
121 | |||
122 | gnunet_reclaim_SOURCES = \ | 89 | gnunet_reclaim_SOURCES = \ |
123 | gnunet-reclaim.c | 90 | gnunet-reclaim.c |
124 | gnunet_reclaim_LDADD = \ | 91 | gnunet_reclaim_LDADD = \ |
diff --git a/src/rest-plugins/Makefile.am b/src/rest-plugins/Makefile.am new file mode 100644 index 000000000..486692b72 --- /dev/null +++ b/src/rest-plugins/Makefile.am | |||
@@ -0,0 +1,105 @@ | |||
1 | # This Makefile.am is in the public domain | ||
2 | AM_CPPFLAGS = -I$(top_srcdir)/src/include | ||
3 | |||
4 | plugindir = $(libdir)/gnunet | ||
5 | |||
6 | pkgcfgdir= $(pkgdatadir)/config.d/ | ||
7 | |||
8 | libexecdir= $(pkglibdir)/libexec/ | ||
9 | |||
10 | |||
11 | if MINGW | ||
12 | WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols | ||
13 | endif | ||
14 | |||
15 | if USE_COVERAGE | ||
16 | AM_CFLAGS = --coverage -O0 | ||
17 | XLIBS = -lgcov | ||
18 | endif | ||
19 | |||
20 | plugin_LTLIBRARIES = \ | ||
21 | libgnunet_plugin_rest_copying.la \ | ||
22 | libgnunet_plugin_rest_peerinfo.la \ | ||
23 | libgnunet_plugin_rest_identity.la \ | ||
24 | libgnunet_plugin_rest_namestore.la \ | ||
25 | libgnunet_plugin_rest_gns.la | ||
26 | if HAVE_ABE | ||
27 | plugin_LTLIBRARIES += libgnunet_plugin_rest_openid_connect.la | ||
28 | endif | ||
29 | |||
30 | |||
31 | libgnunet_plugin_rest_copying_la_SOURCES = \ | ||
32 | plugin_rest_copying.c | ||
33 | libgnunet_plugin_rest_copying_la_LIBADD = \ | ||
34 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
35 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
36 | $(LTLIBINTL) -lmicrohttpd | ||
37 | libgnunet_plugin_rest_copying_la_LDFLAGS = \ | ||
38 | $(GN_PLUGIN_LDFLAGS) | ||
39 | |||
40 | libgnunet_plugin_rest_peerinfo_la_SOURCES = \ | ||
41 | plugin_rest_peerinfo.c | ||
42 | libgnunet_plugin_rest_peerinfo_la_LIBADD = \ | ||
43 | $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ | ||
44 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
45 | $(top_builddir)/src/json/libgnunetjson.la \ | ||
46 | $(top_builddir)/src/transport/libgnunettransport.la \ | ||
47 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
48 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
49 | libgnunet_plugin_rest_peerinfo_la_LDFLAGS = \ | ||
50 | $(GN_PLUGIN_LDFLAGS) | ||
51 | |||
52 | libgnunet_plugin_rest_identity_la_SOURCES = \ | ||
53 | plugin_rest_identity.c | ||
54 | libgnunet_plugin_rest_identity_la_LIBADD = \ | ||
55 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
56 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
57 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
58 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
59 | libgnunet_plugin_rest_identity_la_LDFLAGS = \ | ||
60 | $(GN_PLUGIN_LDFLAGS) | ||
61 | |||
62 | |||
63 | |||
64 | libgnunet_plugin_rest_namestore_la_SOURCES = \ | ||
65 | plugin_rest_namestore.c | ||
66 | libgnunet_plugin_rest_namestore_la_LIBADD = \ | ||
67 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | ||
68 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
69 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
70 | $(top_builddir)/src/json/libgnunetjson.la \ | ||
71 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
72 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
73 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
74 | libgnunet_plugin_rest_namestore_la_LDFLAGS = \ | ||
75 | $(GN_PLUGIN_LDFLAGS) | ||
76 | |||
77 | libgnunet_plugin_rest_gns_la_SOURCES = \ | ||
78 | plugin_rest_gns.c | ||
79 | libgnunet_plugin_rest_gns_la_LIBADD = \ | ||
80 | $(top_builddir)/src/gns/libgnunetgns.la \ | ||
81 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
82 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
83 | $(top_builddir)/src/json/libgnunetjson.la \ | ||
84 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
85 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
86 | libgnunet_plugin_rest_gns_la_LDFLAGS = \ | ||
87 | $(GN_PLUGIN_LDFLAGS) | ||
88 | |||
89 | libgnunet_plugin_rest_openid_connect_la_SOURCES = \ | ||
90 | plugin_rest_openid_connect.c \ | ||
91 | oidc_helper.c | ||
92 | libgnunet_plugin_rest_openid_connect_la_LIBADD = \ | ||
93 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
94 | $(top_builddir)/src/reclaim/libgnunetreclaim.la \ | ||
95 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
96 | $(top_builddir)/src/jsonapi/libgnunetjsonapi.la \ | ||
97 | $(top_builddir)/src/reclaim-attribute/libgnunetreclaimattribute.la \ | ||
98 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | ||
99 | $(top_builddir)/src/gns/libgnunetgns.la \ | ||
100 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
101 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
102 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
103 | libgnunet_plugin_rest_openid_connect_la_LDFLAGS = \ | ||
104 | $(GN_PLUGIN_LDFLAGS) | ||
105 | |||
diff --git a/src/reclaim/oidc_helper.c b/src/rest-plugins/oidc_helper.c index 1e9e64fec..1e9e64fec 100644 --- a/src/reclaim/oidc_helper.c +++ b/src/rest-plugins/oidc_helper.c | |||
diff --git a/src/reclaim/oidc_helper.h b/src/rest-plugins/oidc_helper.h index 7a0f45bf9..7a0f45bf9 100644 --- a/src/reclaim/oidc_helper.h +++ b/src/rest-plugins/oidc_helper.h | |||
diff --git a/src/rest/plugin_rest_copying.c b/src/rest-plugins/plugin_rest_copying.c index 668dc5d38..668dc5d38 100644 --- a/src/rest/plugin_rest_copying.c +++ b/src/rest-plugins/plugin_rest_copying.c | |||
diff --git a/src/gns/plugin_rest_gns.c b/src/rest-plugins/plugin_rest_gns.c index fd2469577..0bf4198fc 100644 --- a/src/gns/plugin_rest_gns.c +++ b/src/rest-plugins/plugin_rest_gns.c | |||
@@ -30,15 +30,27 @@ | |||
30 | #include "microhttpd.h" | 30 | #include "microhttpd.h" |
31 | #include <jansson.h> | 31 | #include <jansson.h> |
32 | 32 | ||
33 | /** | ||
34 | * Rest API GNS Namespace | ||
35 | */ | ||
33 | #define GNUNET_REST_API_NS_GNS "/gns" | 36 | #define GNUNET_REST_API_NS_GNS "/gns" |
34 | 37 | ||
35 | 38 | /** | |
36 | #define GNUNET_REST_GNS_PARAM_NAME "name" | 39 | * Rest API GNS Parameter record_type |
37 | 40 | */ | |
38 | #define GNUNET_REST_GNS_PARAM_RECORD_TYPE "record_type" | 41 | #define GNUNET_REST_GNS_PARAM_RECORD_TYPE "record_type" |
42 | |||
43 | /** | ||
44 | * Rest API GNS ERROR Unknown Error | ||
45 | */ | ||
39 | #define GNUNET_REST_GNS_ERROR_UNKNOWN "Unknown Error" | 46 | #define GNUNET_REST_GNS_ERROR_UNKNOWN "Unknown Error" |
40 | 47 | ||
41 | /** | 48 | /** |
49 | * Rest API GNS ERROR Record not found | ||
50 | */ | ||
51 | #define GNUNET_REST_GNS_NOT_FOUND "Record not found" | ||
52 | |||
53 | /** | ||
42 | * The configuration handle | 54 | * The configuration handle |
43 | */ | 55 | */ |
44 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 56 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
@@ -56,7 +68,9 @@ struct Plugin | |||
56 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 68 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
57 | }; | 69 | }; |
58 | 70 | ||
59 | 71 | /** | |
72 | * The request handle | ||
73 | */ | ||
60 | struct RequestHandle | 74 | struct RequestHandle |
61 | { | 75 | { |
62 | 76 | ||
@@ -116,7 +130,7 @@ struct RequestHandle | |||
116 | char *emsg; | 130 | char *emsg; |
117 | 131 | ||
118 | /** | 132 | /** |
119 | * Reponse code | 133 | * Response code |
120 | */ | 134 | */ |
121 | int response_code; | 135 | int response_code; |
122 | 136 | ||
@@ -214,7 +228,8 @@ handle_gns_response (void *cls, | |||
214 | 228 | ||
215 | if (GNUNET_NO == was_gns) | 229 | if (GNUNET_NO == was_gns) |
216 | { | 230 | { |
217 | handle->emsg = GNUNET_strdup("Name not found in GNS"); | 231 | handle->response_code = MHD_HTTP_NOT_FOUND; |
232 | handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND); | ||
218 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 233 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
219 | return; | 234 | return; |
220 | } | 235 | } |
@@ -260,21 +275,24 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
260 | char *record_type; | 275 | char *record_type; |
261 | char *name; | 276 | char *name; |
262 | 277 | ||
263 | GNUNET_CRYPTO_hash (GNUNET_REST_GNS_PARAM_NAME, | 278 | name = NULL; |
264 | strlen (GNUNET_REST_GNS_PARAM_NAME), | 279 | handle->name = NULL; |
265 | &key); | 280 | if (strlen (GNUNET_REST_API_NS_GNS) < strlen (handle->url)) |
266 | if ( GNUNET_NO | 281 | { |
267 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, | 282 | name = &handle->url[strlen (GNUNET_REST_API_NS_GNS) + 1]; |
268 | &key)) | 283 | } |
284 | |||
285 | if (NULL == name) | ||
269 | { | 286 | { |
270 | handle->emsg = GNUNET_strdup("Parameter name is missing"); | 287 | handle->response_code = MHD_HTTP_NOT_FOUND; |
288 | handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND); | ||
271 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 289 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
272 | return; | 290 | return; |
273 | } | 291 | } |
274 | name = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,&key); | 292 | if (0 >= strlen (name)) |
275 | if(0 >= strlen (name)) | ||
276 | { | 293 | { |
277 | handle->emsg = GNUNET_strdup("Length of parameter name is zero"); | 294 | handle->response_code = MHD_HTTP_NOT_FOUND; |
295 | handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND); | ||
278 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 296 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
279 | return; | 297 | return; |
280 | } | 298 | } |
@@ -292,27 +310,17 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
292 | handle->record_type = GNUNET_GNSRECORD_typename_to_number(record_type); | 310 | handle->record_type = GNUNET_GNSRECORD_typename_to_number(record_type); |
293 | } | 311 | } |
294 | 312 | ||
295 | |||
296 | if(UINT32_MAX == handle->record_type) | 313 | if(UINT32_MAX == handle->record_type) |
297 | { | 314 | { |
298 | handle->record_type = GNUNET_GNSRECORD_TYPE_ANY; | 315 | handle->record_type = GNUNET_GNSRECORD_TYPE_ANY; |
299 | } | 316 | } |
300 | 317 | ||
301 | handle->gns = GNUNET_GNS_connect (cfg); | ||
302 | if (NULL == handle->gns) | ||
303 | { | ||
304 | handle->emsg = GNUNET_strdup ("GNS not available"); | ||
305 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
306 | return; | ||
307 | } | ||
308 | |||
309 | handle->gns_lookup = GNUNET_GNS_lookup_with_tld (handle->gns, | 318 | handle->gns_lookup = GNUNET_GNS_lookup_with_tld (handle->gns, |
310 | handle->name, | 319 | handle->name, |
311 | handle->record_type, | 320 | handle->record_type, |
312 | GNUNET_NO, | 321 | GNUNET_NO, |
313 | &handle_gns_response, | 322 | &handle_gns_response, |
314 | handle); | 323 | handle); |
315 | return; | ||
316 | } | 324 | } |
317 | 325 | ||
318 | 326 | ||
@@ -397,7 +405,7 @@ rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, | |||
397 | if (handle->url[strlen (handle->url)-1] == '/') | 405 | if (handle->url[strlen (handle->url)-1] == '/') |
398 | handle->url[strlen (handle->url)-1] = '\0'; | 406 | handle->url[strlen (handle->url)-1] = '\0'; |
399 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); | 407 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); |
400 | 408 | handle->gns = GNUNET_GNS_connect (cfg); | |
401 | init_cont(handle); | 409 | init_cont(handle); |
402 | 410 | ||
403 | handle->timeout_task = | 411 | handle->timeout_task = |
diff --git a/src/identity/plugin_rest_identity.c b/src/rest-plugins/plugin_rest_identity.c index a518a74cc..9f1765a63 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/rest-plugins/plugin_rest_identity.c | |||
@@ -29,22 +29,79 @@ | |||
29 | #include "microhttpd.h" | 29 | #include "microhttpd.h" |
30 | #include <jansson.h> | 30 | #include <jansson.h> |
31 | 31 | ||
32 | /** | ||
33 | * Identity Namespace | ||
34 | */ | ||
32 | #define GNUNET_REST_API_NS_IDENTITY "/identity" | 35 | #define GNUNET_REST_API_NS_IDENTITY "/identity" |
33 | 36 | ||
34 | /** | 37 | /** |
35 | * Parameter names | 38 | * Identity Namespace with public key specifier |
39 | */ | ||
40 | #define GNUNET_REST_API_NS_IDENTITY_ALL "/identity/all" | ||
41 | |||
42 | /** | ||
43 | * Identity Namespace with public key specifier | ||
44 | */ | ||
45 | #define GNUNET_REST_API_NS_IDENTITY_PUBKEY "/identity/pubkey" | ||
46 | |||
47 | /** | ||
48 | * Identity Namespace with public key specifier | ||
49 | */ | ||
50 | #define GNUNET_REST_API_NS_IDENTITY_NAME "/identity/name" | ||
51 | |||
52 | /** | ||
53 | * Identity Subsystem Namespace | ||
54 | */ | ||
55 | #define GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM "/identity/subsystem" | ||
56 | |||
57 | /** | ||
58 | * Parameter public key | ||
59 | */ | ||
60 | #define GNUNET_REST_IDENTITY_PARAM_PUBKEY "pubkey" | ||
61 | |||
62 | /** | ||
63 | * Parameter subsystem | ||
64 | */ | ||
65 | #define GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM "subsystem" | ||
66 | |||
67 | /** | ||
68 | * Parameter name | ||
36 | */ | 69 | */ |
37 | #define GNUNET_REST_PARAM_PUBKEY "pubkey" | 70 | #define GNUNET_REST_IDENTITY_PARAM_NAME "name" |
38 | #define GNUNET_REST_PARAM_SUBSYSTEM "subsystem" | ||
39 | #define GNUNET_REST_PARAM_NAME "name" | ||
40 | #define GNUNET_REST_PARAM_NEWNAME "newname" | ||
41 | 71 | ||
42 | /** | 72 | /** |
43 | * Error messages | 73 | * Parameter new name |
74 | */ | ||
75 | #define GNUNET_REST_IDENTITY_PARAM_NEWNAME "newname" | ||
76 | |||
77 | /** | ||
78 | * Error message Unknown Error | ||
44 | */ | 79 | */ |
45 | #define GNUNET_REST_IDENTITY_ERROR_UNKNOWN "Unknown Error" | 80 | #define GNUNET_REST_IDENTITY_ERROR_UNKNOWN "Unknown Error" |
46 | #define GNUNET_REST_ERROR_RESOURCE_INVALID "Resource location invalid" | 81 | |
82 | /** | ||
83 | * Error message No identity found | ||
84 | */ | ||
85 | #define GNUNET_REST_IDENTITY_NOT_FOUND "No identity found" | ||
86 | |||
87 | /** | ||
88 | * Error message Missing identity name | ||
89 | */ | ||
90 | #define GNUNET_REST_IDENTITY_MISSING_NAME "Missing identity name" | ||
91 | |||
92 | /** | ||
93 | * Error message Missing identity name | ||
94 | */ | ||
95 | #define GNUNET_REST_IDENTITY_MISSING_PUBKEY "Missing identity public key" | ||
96 | |||
97 | /** | ||
98 | * Error message No data | ||
99 | */ | ||
47 | #define GNUNET_REST_ERROR_NO_DATA "No data" | 100 | #define GNUNET_REST_ERROR_NO_DATA "No data" |
101 | |||
102 | /** | ||
103 | * Error message Data invalid | ||
104 | */ | ||
48 | #define GNUNET_REST_ERROR_DATA_INVALID "Data invalid" | 105 | #define GNUNET_REST_ERROR_DATA_INVALID "Data invalid" |
49 | 106 | ||
50 | /** | 107 | /** |
@@ -106,6 +163,9 @@ struct EgoEntry | |||
106 | struct GNUNET_IDENTITY_Ego *ego; | 163 | struct GNUNET_IDENTITY_Ego *ego; |
107 | }; | 164 | }; |
108 | 165 | ||
166 | /** | ||
167 | * The request handle | ||
168 | */ | ||
109 | struct RequestHandle | 169 | struct RequestHandle |
110 | { | 170 | { |
111 | /** | 171 | /** |
@@ -123,10 +183,6 @@ struct RequestHandle | |||
123 | */ | 183 | */ |
124 | size_t data_size; | 184 | size_t data_size; |
125 | 185 | ||
126 | /** | ||
127 | * Requested Subsystem | ||
128 | */ | ||
129 | char *subsystem; | ||
130 | 186 | ||
131 | /** | 187 | /** |
132 | * Ego list | 188 | * Ego list |
@@ -189,7 +245,7 @@ struct RequestHandle | |||
189 | char *emsg; | 245 | char *emsg; |
190 | 246 | ||
191 | /** | 247 | /** |
192 | * Reponse code | 248 | * Response code |
193 | */ | 249 | */ |
194 | int response_code; | 250 | int response_code; |
195 | 251 | ||
@@ -213,8 +269,6 @@ cleanup_handle (void *cls) | |||
213 | handle->timeout_task = NULL; | 269 | handle->timeout_task = NULL; |
214 | } | 270 | } |
215 | 271 | ||
216 | if (NULL != handle->subsystem) | ||
217 | GNUNET_free(handle->subsystem); | ||
218 | if (NULL != handle->url) | 272 | if (NULL != handle->url) |
219 | GNUNET_free(handle->url); | 273 | GNUNET_free(handle->url); |
220 | if (NULL != handle->emsg) | 274 | if (NULL != handle->emsg) |
@@ -315,7 +369,9 @@ get_egoentry(struct RequestHandle *handle, char* pubkey, char *name) | |||
315 | * @param name the id of the ego | 369 | * @param name the id of the ego |
316 | */ | 370 | */ |
317 | static void | 371 | static void |
318 | ego_get_for_subsystem (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, | 372 | ego_get_for_subsystem (void *cls, |
373 | struct GNUNET_IDENTITY_Ego *ego, | ||
374 | void **ctx, | ||
319 | const char *name) | 375 | const char *name) |
320 | { | 376 | { |
321 | struct RequestHandle *handle = cls; | 377 | struct RequestHandle *handle = cls; |
@@ -327,7 +383,8 @@ ego_get_for_subsystem (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, | |||
327 | 383 | ||
328 | if(NULL == ego) | 384 | if(NULL == ego) |
329 | { | 385 | { |
330 | handle->emsg = GNUNET_strdup("No identity found for subsystem"); | 386 | handle->response_code = MHD_HTTP_NOT_FOUND; |
387 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | ||
331 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 388 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
332 | return; | 389 | return; |
333 | } | 390 | } |
@@ -337,8 +394,12 @@ ego_get_for_subsystem (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, | |||
337 | 394 | ||
338 | // create json with subsystem identity | 395 | // create json with subsystem identity |
339 | json_root = json_object (); | 396 | json_root = json_object (); |
340 | json_object_set_new (json_root, GNUNET_REST_PARAM_PUBKEY, json_string(public_key_string)); | 397 | json_object_set_new (json_root, |
341 | json_object_set_new (json_root, GNUNET_REST_PARAM_NAME, json_string(name)); | 398 | GNUNET_REST_IDENTITY_PARAM_PUBKEY, |
399 | json_string(public_key_string)); | ||
400 | json_object_set_new (json_root, | ||
401 | GNUNET_REST_IDENTITY_PARAM_NAME, | ||
402 | json_string(name)); | ||
342 | 403 | ||
343 | result_str = json_dumps (json_root, 0); | 404 | result_str = json_dumps (json_root, 0); |
344 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | 405 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); |
@@ -352,116 +413,76 @@ ego_get_for_subsystem (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, | |||
352 | } | 413 | } |
353 | 414 | ||
354 | /** | 415 | /** |
355 | * Handle identity GET request | 416 | * Handle identity GET request for subsystem |
356 | * | 417 | * |
357 | * @param con_handle the connection handle | 418 | * @param con_handle the connection handle |
358 | * @param url the url | 419 | * @param url the url |
359 | * @param cls the RequestHandle | 420 | * @param cls the RequestHandle |
360 | */ | 421 | */ |
361 | void | 422 | void |
362 | ego_get (struct GNUNET_REST_RequestHandle *con_handle, const char* url, | 423 | ego_get_subsystem (struct GNUNET_REST_RequestHandle *con_handle, |
363 | void *cls) | 424 | const char* url, |
425 | void *cls) | ||
364 | { | 426 | { |
365 | struct RequestHandle *handle = cls; | 427 | struct RequestHandle *handle = cls; |
366 | struct EgoEntry *ego_entry; | 428 | char *subsystem; |
367 | struct GNUNET_HashCode key; | ||
368 | struct MHD_Response *resp; | ||
369 | char *keystring; | ||
370 | char *egoname; | ||
371 | json_t *json_root; | ||
372 | json_t *json_ego; | ||
373 | char *result_str; | ||
374 | 429 | ||
375 | //requested default identity of subsystem | 430 | if (strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) >= strlen (handle->url)) |
376 | GNUNET_CRYPTO_hash (GNUNET_REST_PARAM_SUBSYSTEM, | ||
377 | strlen (GNUNET_REST_PARAM_SUBSYSTEM), &key); | ||
378 | if ( GNUNET_YES | ||
379 | == GNUNET_CONTAINER_multihashmap_contains ( | ||
380 | handle->rest_handle->url_param_map, &key)) | ||
381 | { | 431 | { |
382 | handle->subsystem = GNUNET_strdup( | 432 | handle->emsg = GNUNET_strdup("Missing subsystem name"); |
383 | GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map, | 433 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
384 | &key)); | ||
385 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Looking for %s's ego\n", | ||
386 | handle->subsystem); | ||
387 | |||
388 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, | ||
389 | handle->subsystem, | ||
390 | &ego_get_for_subsystem, | ||
391 | handle); | ||
392 | if (NULL == handle->op) | ||
393 | { | ||
394 | handle->emsg = GNUNET_strdup("No identity found for subsystem"); | ||
395 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
396 | return; | ||
397 | } | ||
398 | return; | 434 | return; |
399 | } | 435 | } |
400 | egoname = NULL; | 436 | subsystem = &handle->url[strlen ( |
401 | keystring = NULL; | 437 | GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) + 1]; |
402 | 438 | //requested default identity of subsystem | |
403 | //one identity requested with key | 439 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Looking for %s's ego\n", subsystem); |
404 | GNUNET_CRYPTO_hash (GNUNET_REST_PARAM_PUBKEY, | ||
405 | strlen (GNUNET_REST_PARAM_PUBKEY), | ||
406 | &key); | ||
407 | if ( GNUNET_YES | ||
408 | == GNUNET_CONTAINER_multihashmap_contains ( | ||
409 | handle->rest_handle->url_param_map, &key)) | ||
410 | { | ||
411 | keystring = GNUNET_CONTAINER_multihashmap_get ( | ||
412 | handle->rest_handle->url_param_map, &key); | ||
413 | 440 | ||
414 | ego_entry = get_egoentry(handle, keystring, NULL); | 441 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, |
415 | if (NULL == ego_entry) | 442 | subsystem, |
416 | { | 443 | &ego_get_for_subsystem, |
417 | handle->emsg = GNUNET_strdup("No identity found for public key"); | 444 | handle); |
418 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
419 | return; | ||
420 | } | ||
421 | egoname = ego_entry->identifier; | ||
422 | } | ||
423 | 445 | ||
424 | //one identity requested with name | 446 | if (NULL == handle->op) |
425 | if (NULL == egoname) | ||
426 | { | 447 | { |
427 | GNUNET_CRYPTO_hash (GNUNET_REST_PARAM_NAME, | 448 | handle->response_code = MHD_HTTP_NOT_FOUND; |
428 | strlen (GNUNET_REST_PARAM_NAME), | 449 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); |
429 | &key); | 450 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
430 | if ( GNUNET_YES | 451 | return; |
431 | == GNUNET_CONTAINER_multihashmap_contains ( | ||
432 | handle->rest_handle->url_param_map, &key)) | ||
433 | { | ||
434 | egoname = GNUNET_CONTAINER_multihashmap_get ( | ||
435 | handle->rest_handle->url_param_map, &key); | ||
436 | if (0 >= strlen(egoname)) | ||
437 | { | ||
438 | handle->emsg = GNUNET_strdup("No identity found for name"); | ||
439 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
440 | return; | ||
441 | } | ||
442 | //LOWERCASE ego names? | ||
443 | GNUNET_STRINGS_utf8_tolower(egoname, egoname); | ||
444 | } | ||
445 | } | 452 | } |
453 | } | ||
454 | |||
455 | |||
456 | /** | ||
457 | * Handle identity GET request - responds with all identities | ||
458 | * | ||
459 | * @param con_handle the connection handle | ||
460 | * @param url the url | ||
461 | * @param cls the RequestHandle | ||
462 | */ | ||
463 | void | ||
464 | ego_get_all (struct GNUNET_REST_RequestHandle *con_handle, | ||
465 | const char* url, | ||
466 | void *cls) | ||
467 | { | ||
468 | struct RequestHandle *handle = cls; | ||
469 | struct EgoEntry *ego_entry; | ||
470 | struct MHD_Response *resp; | ||
471 | json_t *json_root; | ||
472 | json_t *json_ego; | ||
473 | char *result_str; | ||
446 | 474 | ||
447 | json_root = json_array (); | 475 | json_root = json_array (); |
448 | //Return ego/egos | 476 | //Return ego/egos |
449 | for (ego_entry = handle->ego_head; | 477 | for (ego_entry = handle->ego_head; |
450 | NULL != ego_entry; ego_entry = ego_entry->next) | 478 | NULL != ego_entry; ego_entry = ego_entry->next) |
451 | { | 479 | { |
452 | //if only one ego requested | ||
453 | if ((NULL != egoname)){ | ||
454 | if(0 != strcmp (egoname, ego_entry->identifier)){ | ||
455 | continue; | ||
456 | } | ||
457 | } | ||
458 | |||
459 | json_ego = json_object (); | 480 | json_ego = json_object (); |
460 | json_object_set_new (json_ego, | 481 | json_object_set_new (json_ego, |
461 | GNUNET_REST_PARAM_PUBKEY, | 482 | GNUNET_REST_IDENTITY_PARAM_PUBKEY, |
462 | json_string (ego_entry->keystring)); | 483 | json_string (ego_entry->keystring)); |
463 | json_object_set_new (json_ego, | 484 | json_object_set_new (json_ego, |
464 | GNUNET_REST_PARAM_NAME, | 485 | GNUNET_REST_IDENTITY_PARAM_NAME, |
465 | json_string (ego_entry->identifier)); | 486 | json_string (ego_entry->identifier)); |
466 | json_array_append (json_root, json_ego); | 487 | json_array_append (json_root, json_ego); |
467 | json_decref (json_ego); | 488 | json_decref (json_ego); |
@@ -470,7 +491,8 @@ ego_get (struct GNUNET_REST_RequestHandle *con_handle, const char* url, | |||
470 | if ((size_t) 0 == json_array_size (json_root)) | 491 | if ((size_t) 0 == json_array_size (json_root)) |
471 | { | 492 | { |
472 | json_decref (json_root); | 493 | json_decref (json_root); |
473 | handle->emsg = GNUNET_strdup("No identities found!"); | 494 | handle->response_code = MHD_HTTP_NOT_FOUND; |
495 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | ||
474 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 496 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
475 | return; | 497 | return; |
476 | } | 498 | } |
@@ -487,6 +509,117 @@ ego_get (struct GNUNET_REST_RequestHandle *con_handle, const char* url, | |||
487 | 509 | ||
488 | 510 | ||
489 | /** | 511 | /** |
512 | * Responds with the ego_entry identity | ||
513 | * | ||
514 | * @param handle the struct RequestHandle | ||
515 | * @param ego_entry the struct EgoEntry for the response | ||
516 | */ | ||
517 | void | ||
518 | ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry) | ||
519 | { | ||
520 | struct MHD_Response *resp; | ||
521 | json_t *json_ego; | ||
522 | char *result_str; | ||
523 | |||
524 | json_ego = json_object (); | ||
525 | json_object_set_new (json_ego, | ||
526 | GNUNET_REST_IDENTITY_PARAM_PUBKEY, | ||
527 | json_string (ego_entry->keystring)); | ||
528 | json_object_set_new (json_ego, | ||
529 | GNUNET_REST_IDENTITY_PARAM_NAME, | ||
530 | json_string (ego_entry->identifier)); | ||
531 | |||
532 | result_str = json_dumps (json_ego, 0); | ||
533 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | ||
534 | resp = GNUNET_REST_create_response (result_str); | ||
535 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | ||
536 | |||
537 | json_decref (json_ego); | ||
538 | GNUNET_free(result_str); | ||
539 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | ||
540 | } | ||
541 | |||
542 | |||
543 | /** | ||
544 | * Handle identity GET request with a public key | ||
545 | * | ||
546 | * @param con_handle the connection handle | ||
547 | * @param url the url | ||
548 | * @param cls the RequestHandle | ||
549 | */ | ||
550 | void | ||
551 | ego_get_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | ||
552 | const char* url, | ||
553 | void *cls) | ||
554 | { | ||
555 | struct RequestHandle *handle = cls; | ||
556 | struct EgoEntry *ego_entry; | ||
557 | char *keystring; | ||
558 | |||
559 | keystring = NULL; | ||
560 | |||
561 | if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) | ||
562 | { | ||
563 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
564 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_PUBKEY); | ||
565 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
566 | return; | ||
567 | } | ||
568 | keystring = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY)+1]; | ||
569 | ego_entry = get_egoentry(handle, keystring, NULL); | ||
570 | |||
571 | if (NULL == ego_entry) | ||
572 | { | ||
573 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
574 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | ||
575 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
576 | return; | ||
577 | } | ||
578 | |||
579 | ego_get_response(handle, ego_entry); | ||
580 | } | ||
581 | |||
582 | /** | ||
583 | * Handle identity GET request with a name | ||
584 | * | ||
585 | * @param con_handle the connection handle | ||
586 | * @param url the url | ||
587 | * @param cls the RequestHandle | ||
588 | */ | ||
589 | void | ||
590 | ego_get_name (struct GNUNET_REST_RequestHandle *con_handle, | ||
591 | const char* url, | ||
592 | void *cls) | ||
593 | { | ||
594 | struct RequestHandle *handle = cls; | ||
595 | struct EgoEntry *ego_entry; | ||
596 | char *egoname; | ||
597 | |||
598 | egoname = NULL; | ||
599 | |||
600 | if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) | ||
601 | { | ||
602 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
603 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_NAME); | ||
604 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
605 | return; | ||
606 | } | ||
607 | egoname = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME)+1]; | ||
608 | ego_entry = get_egoentry(handle, NULL, egoname); | ||
609 | |||
610 | if (NULL == ego_entry) | ||
611 | { | ||
612 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
613 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | ||
614 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
615 | return; | ||
616 | } | ||
617 | |||
618 | ego_get_response(handle, ego_entry); | ||
619 | } | ||
620 | |||
621 | |||
622 | /** | ||
490 | * Processing finished | 623 | * Processing finished |
491 | * | 624 | * |
492 | * @param cls request handle | 625 | * @param cls request handle |
@@ -505,6 +638,10 @@ do_finished (void *cls, const char *emsg) | |||
505 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 638 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
506 | return; | 639 | return; |
507 | } | 640 | } |
641 | if (0 == handle->response_code) | ||
642 | { | ||
643 | handle->response_code = MHD_HTTP_NO_CONTENT; | ||
644 | } | ||
508 | resp = GNUNET_REST_create_response (NULL); | 645 | resp = GNUNET_REST_create_response (NULL); |
509 | handle->proc (handle->proc_cls, resp, handle->response_code); | 646 | handle->proc (handle->proc_cls, resp, handle->response_code); |
510 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 647 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); |
@@ -512,29 +649,21 @@ do_finished (void *cls, const char *emsg) | |||
512 | 649 | ||
513 | 650 | ||
514 | /** | 651 | /** |
515 | * Handle identity PUT request | 652 | * Processing edit ego with EgoEntry ego_entry |
516 | * | 653 | * |
517 | * @param con_handle the connection handle | 654 | * @param handle the struct RequestHandle |
518 | * @param url the url | 655 | * @param ego_entry the struct EgoEntry we want to edit |
519 | * @param cls the RequestHandle | ||
520 | */ | 656 | */ |
521 | void | 657 | void |
522 | ego_edit (struct GNUNET_REST_RequestHandle *con_handle, | 658 | ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) |
523 | const char* url, | ||
524 | void *cls) | ||
525 | { | 659 | { |
526 | struct RequestHandle *handle = cls; | ||
527 | struct EgoEntry *ego_entry; | ||
528 | struct EgoEntry *ego_entry_tmp; | 660 | struct EgoEntry *ego_entry_tmp; |
529 | struct MHD_Response *resp; | 661 | struct MHD_Response *resp; |
530 | int json_state; | ||
531 | json_t *data_js; | 662 | json_t *data_js; |
532 | json_error_t err; | 663 | json_error_t err; |
533 | char *pubkey; | ||
534 | char *name; | ||
535 | char *newsubsys; | ||
536 | char *newname; | 664 | char *newname; |
537 | char term_data[handle->data_size + 1]; | 665 | char term_data[handle->data_size + 1]; |
666 | int json_state; | ||
538 | 667 | ||
539 | //if no data | 668 | //if no data |
540 | if (0 >= handle->data_size) | 669 | if (0 >= handle->data_size) |
@@ -555,127 +684,252 @@ ego_edit (struct GNUNET_REST_RequestHandle *con_handle, | |||
555 | return; | 684 | return; |
556 | } | 685 | } |
557 | 686 | ||
558 | ego_entry = NULL; | ||
559 | pubkey = NULL; | ||
560 | name = NULL; | ||
561 | newname = NULL; | 687 | newname = NULL; |
562 | //NEW NAME | 688 | //NEW NAME |
563 | json_state = 0; | 689 | json_state = 0; |
564 | json_state = json_unpack(data_js, | 690 | json_state = json_unpack(data_js, |
565 | "{s:s,s?:s,s?:s}", | 691 | "{s:s!}", |
566 | GNUNET_REST_PARAM_NEWNAME, | 692 | GNUNET_REST_IDENTITY_PARAM_NEWNAME, |
567 | &newname, | 693 | &newname); |
568 | GNUNET_REST_PARAM_PUBKEY, | ||
569 | &pubkey, | ||
570 | GNUNET_REST_PARAM_NAME, | ||
571 | &name); | ||
572 | //Change name with pubkey or name identifier | 694 | //Change name with pubkey or name identifier |
573 | if (0 == json_state) | 695 | if (0 != json_state) |
574 | { | 696 | { |
575 | if (NULL == newname) | ||
576 | { | ||
577 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); | ||
578 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
579 | json_decref (data_js); | ||
580 | return; | ||
581 | } | ||
582 | 697 | ||
583 | if (0 >= strlen(newname)) | 698 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
584 | { | 699 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
585 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); | 700 | json_decref (data_js); |
586 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 701 | return; |
587 | json_decref (data_js); | 702 | } |
588 | return; | ||
589 | } | ||
590 | //lower case name | ||
591 | GNUNET_STRINGS_utf8_tolower(newname,newname); | ||
592 | 703 | ||
593 | ego_entry = get_egoentry(handle,pubkey,name); | 704 | if (NULL == newname) |
705 | { | ||
706 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); | ||
707 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
708 | json_decref (data_js); | ||
709 | return; | ||
710 | } | ||
594 | 711 | ||
595 | if (NULL == ego_entry) | 712 | if (0 >= strlen (newname)) |
596 | { | 713 | { |
597 | resp = GNUNET_REST_create_response (NULL); | 714 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
598 | handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND); | 715 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
599 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 716 | json_decref (data_js); |
600 | json_decref (data_js); | 717 | return; |
601 | return; | 718 | } |
602 | } | ||
603 | 719 | ||
604 | for (ego_entry_tmp = handle->ego_head; | 720 | ego_entry_tmp = get_egoentry (handle, NULL, newname); |
605 | NULL != ego_entry_tmp; ego_entry_tmp = ego_entry_tmp->next) | 721 | if (NULL != ego_entry_tmp) |
606 | { | 722 | { |
607 | if (0 == strcasecmp (newname, ego_entry_tmp->identifier)) | 723 | //Ego with same name not allowed (even if its the ego we change) |
608 | { | 724 | resp = GNUNET_REST_create_response (NULL); |
609 | //Ego with same name not allowed | 725 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); |
610 | resp = GNUNET_REST_create_response (NULL); | 726 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); |
611 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); | 727 | json_decref (data_js); |
612 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 728 | return; |
613 | json_decref (data_js); | 729 | } |
614 | return; | 730 | handle->op = GNUNET_IDENTITY_rename (handle->identity_handle, |
615 | } | 731 | ego_entry->identifier, |
616 | } | 732 | newname, |
617 | handle->response_code = MHD_HTTP_NO_CONTENT; | 733 | &do_finished, |
618 | handle->op = GNUNET_IDENTITY_rename (handle->identity_handle, | 734 | handle); |
619 | ego_entry->identifier, newname, | 735 | if (NULL == handle->op) |
620 | &do_finished, handle); | 736 | { |
737 | handle->emsg = GNUNET_strdup("Rename failed"); | ||
738 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
621 | json_decref (data_js); | 739 | json_decref (data_js); |
622 | return; | 740 | return; |
623 | } | 741 | } |
742 | json_decref (data_js); | ||
743 | return; | ||
744 | |||
745 | } | ||
746 | |||
747 | |||
748 | /** | ||
749 | * Handle identity PUT request with public key | ||
750 | * | ||
751 | * @param con_handle the connection handle | ||
752 | * @param url the url | ||
753 | * @param cls the RequestHandle | ||
754 | */ | ||
755 | void | ||
756 | ego_edit_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | ||
757 | const char* url, | ||
758 | void *cls) | ||
759 | { | ||
760 | struct RequestHandle *handle = cls; | ||
761 | struct EgoEntry *ego_entry; | ||
762 | char *keystring; | ||
763 | |||
764 | keystring = NULL; | ||
765 | |||
766 | if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) | ||
767 | { | ||
768 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
769 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_PUBKEY); | ||
770 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
771 | return; | ||
772 | } | ||
773 | keystring = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY)+1]; | ||
774 | ego_entry = get_egoentry(handle, keystring, NULL); | ||
775 | |||
776 | if (NULL == ego_entry) | ||
777 | { | ||
778 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
779 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | ||
780 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
781 | return; | ||
782 | } | ||
783 | |||
784 | ego_edit(handle,ego_entry); | ||
785 | } | ||
786 | |||
787 | /** | ||
788 | * Handle identity PUT request with name | ||
789 | * | ||
790 | * @param con_handle the connection handle | ||
791 | * @param url the url | ||
792 | * @param cls the RequestHandle | ||
793 | */ | ||
794 | void | ||
795 | ego_edit_name (struct GNUNET_REST_RequestHandle *con_handle, | ||
796 | const char* url, | ||
797 | void *cls) | ||
798 | { | ||
799 | struct RequestHandle *handle = cls; | ||
800 | struct EgoEntry *ego_entry; | ||
801 | char *name; | ||
802 | |||
803 | name = NULL; | ||
804 | |||
805 | if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) | ||
806 | { | ||
807 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
808 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_NAME); | ||
809 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
810 | return; | ||
811 | } | ||
812 | name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME)+1]; | ||
813 | ego_entry = get_egoentry(handle, NULL, name); | ||
814 | |||
815 | if (NULL == ego_entry) | ||
816 | { | ||
817 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
818 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | ||
819 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
820 | return; | ||
821 | } | ||
822 | |||
823 | ego_edit(handle,ego_entry); | ||
824 | } | ||
825 | |||
826 | /** | ||
827 | * Handle identity subsystem PUT request with name | ||
828 | * | ||
829 | * @param con_handle the connection handle | ||
830 | * @param url the url | ||
831 | * @param cls the RequestHandle | ||
832 | */ | ||
833 | void | ||
834 | ego_edit_subsystem (struct GNUNET_REST_RequestHandle *con_handle, | ||
835 | const char* url, | ||
836 | void *cls) | ||
837 | { | ||
838 | struct RequestHandle *handle = cls; | ||
839 | struct EgoEntry *ego_entry; | ||
840 | json_t *data_js; | ||
841 | json_error_t err; | ||
842 | char *newsubsys; | ||
843 | char *name; | ||
844 | char term_data[handle->data_size + 1]; | ||
845 | int json_state; | ||
846 | |||
847 | name = NULL; | ||
848 | |||
849 | if (strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) >= strlen (handle->url)) | ||
850 | { | ||
851 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
852 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_NAME); | ||
853 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
854 | return; | ||
855 | } | ||
856 | name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM)+1]; | ||
857 | ego_entry = get_egoentry(handle, NULL, name); | ||
858 | |||
859 | if (NULL == ego_entry) | ||
860 | { | ||
861 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
862 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | ||
863 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
864 | return; | ||
865 | } | ||
866 | |||
867 | //if no data | ||
868 | if (0 >= handle->data_size) | ||
869 | { | ||
870 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_NO_DATA); | ||
871 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
872 | return; | ||
873 | } | ||
874 | //if not json | ||
875 | term_data[handle->data_size] = '\0'; | ||
876 | GNUNET_memcpy(term_data, handle->data, handle->data_size); | ||
877 | data_js = json_loads (term_data,JSON_DECODE_ANY,&err); | ||
878 | |||
879 | if (NULL == data_js) | ||
880 | { | ||
881 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_NO_DATA); | ||
882 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
883 | return; | ||
884 | } | ||
624 | 885 | ||
625 | newsubsys = NULL; | 886 | newsubsys = NULL; |
626 | //SUBSYSTEM | 887 | //SUBSYSTEM |
627 | json_state = 0; | 888 | json_state = 0; |
628 | json_state = json_unpack(data_js, | 889 | json_state = json_unpack(data_js, |
629 | "{s:s,s?:s,s?:s}", | 890 | "{s:s!}", |
630 | GNUNET_REST_PARAM_SUBSYSTEM, | 891 | GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM, |
631 | &newsubsys, | 892 | &newsubsys); |
632 | GNUNET_REST_PARAM_PUBKEY, | ||
633 | &pubkey, | ||
634 | GNUNET_REST_PARAM_NAME, | ||
635 | &name); | ||
636 | //Change subsystem with pubkey or name identifier | 893 | //Change subsystem with pubkey or name identifier |
637 | if (0 == json_state) | 894 | if (0 != json_state) |
638 | { | 895 | { |
639 | if (NULL == newsubsys || (NULL == pubkey && NULL == name)) | 896 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
640 | { | 897 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
641 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); | 898 | json_decref (data_js); |
642 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 899 | return; |
643 | json_decref (data_js); | 900 | } |
644 | return; | ||
645 | } | ||
646 | |||
647 | if (0 >= strlen(newsubsys)) | ||
648 | { | ||
649 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); | ||
650 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
651 | json_decref (data_js); | ||
652 | return; | ||
653 | } | ||
654 | |||
655 | ego_entry = get_egoentry(handle, pubkey, name); | ||
656 | 901 | ||
657 | if (NULL == ego_entry) | 902 | if (NULL == newsubsys) |
658 | { | 903 | { |
659 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); | 904 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
660 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 905 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
661 | json_decref (data_js); | 906 | json_decref (data_js); |
662 | return; | 907 | return; |
663 | } | 908 | } |
664 | 909 | ||
665 | handle->response_code = MHD_HTTP_NO_CONTENT; | 910 | if (0 >= strlen (newsubsys)) |
666 | handle->op = GNUNET_IDENTITY_set (handle->identity_handle, | 911 | { |
667 | newsubsys, | 912 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
668 | ego_entry->ego, | 913 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
669 | &do_finished, | ||
670 | handle); | ||
671 | json_decref (data_js); | 914 | json_decref (data_js); |
672 | return; | 915 | return; |
673 | } | 916 | } |
674 | 917 | ||
675 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); | 918 | handle->response_code = MHD_HTTP_NO_CONTENT; |
676 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 919 | handle->op = GNUNET_IDENTITY_set (handle->identity_handle, |
920 | newsubsys, | ||
921 | ego_entry->ego, | ||
922 | &do_finished, | ||
923 | handle); | ||
924 | if (NULL == handle->op) | ||
925 | { | ||
926 | handle->emsg = GNUNET_strdup("Setting subsystem failed"); | ||
927 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
928 | return; | ||
929 | } | ||
677 | json_decref (data_js); | 930 | json_decref (data_js); |
678 | return; | 931 | return; |
932 | |||
679 | } | 933 | } |
680 | 934 | ||
681 | /** | 935 | /** |
@@ -686,7 +940,8 @@ ego_edit (struct GNUNET_REST_RequestHandle *con_handle, | |||
686 | * @param cls the RequestHandle | 940 | * @param cls the RequestHandle |
687 | */ | 941 | */ |
688 | void | 942 | void |
689 | ego_create (struct GNUNET_REST_RequestHandle *con_handle, const char* url, | 943 | ego_create (struct GNUNET_REST_RequestHandle *con_handle, |
944 | const char* url, | ||
690 | void *cls) | 945 | void *cls) |
691 | { | 946 | { |
692 | struct RequestHandle *handle = cls; | 947 | struct RequestHandle *handle = cls; |
@@ -700,7 +955,6 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, const char* url, | |||
700 | 955 | ||
701 | if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url)) | 956 | if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url)) |
702 | { | 957 | { |
703 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_RESOURCE_INVALID); | ||
704 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 958 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
705 | return; | 959 | return; |
706 | } | 960 | } |
@@ -726,7 +980,7 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, const char* url, | |||
726 | json_unpack_state = 0; | 980 | json_unpack_state = 0; |
727 | json_unpack_state = json_unpack(data_js, | 981 | json_unpack_state = json_unpack(data_js, |
728 | "{s:s!}", | 982 | "{s:s!}", |
729 | GNUNET_REST_PARAM_NAME, | 983 | GNUNET_REST_IDENTITY_PARAM_NAME, |
730 | &egoname); | 984 | &egoname); |
731 | if (0 != json_unpack_state) | 985 | if (0 != json_unpack_state) |
732 | { | 986 | { |
@@ -738,7 +992,7 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, const char* url, | |||
738 | 992 | ||
739 | if (NULL == egoname) | 993 | if (NULL == egoname) |
740 | { | 994 | { |
741 | handle->emsg = GNUNET_strdup("No name provided"); | 995 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
742 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 996 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
743 | json_decref (data_js); | 997 | json_decref (data_js); |
744 | return; | 998 | return; |
@@ -746,7 +1000,7 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, const char* url, | |||
746 | if (0 >= strlen (egoname)) | 1000 | if (0 >= strlen (egoname)) |
747 | { | 1001 | { |
748 | json_decref (data_js); | 1002 | json_decref (data_js); |
749 | handle->emsg = GNUNET_strdup("No name provided"); | 1003 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
750 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1004 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
751 | return; | 1005 | return; |
752 | } | 1006 | } |
@@ -771,93 +1025,93 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, const char* url, | |||
771 | } | 1025 | } |
772 | 1026 | ||
773 | /** | 1027 | /** |
774 | * Handle identity DELETE request | 1028 | * Handle identity DELETE request with public key |
775 | * | 1029 | * |
776 | * @param con_handle the connection handle | 1030 | * @param con_handle the connection handle |
777 | * @param url the url | 1031 | * @param url the url |
778 | * @param cls the RequestHandle | 1032 | * @param cls the RequestHandle |
779 | */ | 1033 | */ |
780 | void | 1034 | void |
781 | ego_delete (struct GNUNET_REST_RequestHandle *con_handle, const char* url, | 1035 | ego_delete_pubkey (struct GNUNET_REST_RequestHandle *con_handle, |
782 | void *cls) | 1036 | const char* url, |
1037 | void *cls) | ||
783 | { | 1038 | { |
784 | struct RequestHandle *handle = cls; | 1039 | struct RequestHandle *handle = cls; |
785 | struct EgoEntry *ego_entry; | 1040 | struct EgoEntry *ego_entry; |
786 | struct GNUNET_HashCode key; | 1041 | char *keystring; |
787 | struct MHD_Response *resp; | ||
788 | const char *keystring; | ||
789 | char *egoname; | ||
790 | int ego_exists = GNUNET_NO; | ||
791 | 1042 | ||
792 | keystring = NULL; | 1043 | keystring = NULL; |
793 | egoname = NULL; | ||
794 | 1044 | ||
795 | //delete with pubkey | 1045 | if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) |
796 | GNUNET_CRYPTO_hash (GNUNET_REST_PARAM_PUBKEY, | ||
797 | strlen (GNUNET_REST_PARAM_PUBKEY), &key); | ||
798 | if ( GNUNET_YES | ||
799 | == GNUNET_CONTAINER_multihashmap_contains ( | ||
800 | handle->rest_handle->url_param_map, &key)) | ||
801 | { | 1046 | { |
802 | keystring = GNUNET_CONTAINER_multihashmap_get ( | 1047 | handle->response_code = MHD_HTTP_NOT_FOUND; |
803 | handle->rest_handle->url_param_map,&key); | 1048 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_PUBKEY); |
1049 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
1050 | return; | ||
804 | } | 1051 | } |
1052 | keystring = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY)+1]; | ||
1053 | ego_entry = get_egoentry(handle, keystring, NULL); | ||
805 | 1054 | ||
806 | GNUNET_CRYPTO_hash (GNUNET_REST_PARAM_NAME, | 1055 | if (NULL == ego_entry) |
807 | strlen (GNUNET_REST_PARAM_NAME), &key); | ||
808 | if ( GNUNET_YES | ||
809 | == GNUNET_CONTAINER_multihashmap_contains ( | ||
810 | handle->rest_handle->url_param_map, &key)) | ||
811 | { | 1056 | { |
812 | egoname = GNUNET_CONTAINER_multihashmap_get ( | 1057 | handle->response_code = MHD_HTTP_NOT_FOUND; |
813 | handle->rest_handle->url_param_map, &key); | 1058 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); |
814 | //LOWERCASE ego names? | 1059 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
815 | //GNUNET_STRINGS_utf8_tolower(egoname, egoname); | 1060 | return; |
816 | } | 1061 | } |
817 | 1062 | ||
818 | if (NULL != keystring) | 1063 | handle->response_code = MHD_HTTP_NO_CONTENT; |
819 | { | 1064 | handle->op = GNUNET_IDENTITY_delete (handle->identity_handle, |
820 | for (ego_entry = handle->ego_head; | 1065 | ego_entry->identifier, |
821 | NULL != ego_entry; ego_entry = ego_entry->next) | 1066 | &do_finished, |
822 | { | 1067 | handle); |
823 | if (0 != strcasecmp (keystring, ego_entry->keystring)) | 1068 | } |
824 | continue; | 1069 | |
825 | ego_exists = GNUNET_YES; | 1070 | |
826 | break; | 1071 | /** |
827 | } | 1072 | * Handle identity DELETE request with name |
828 | } | 1073 | * |
829 | else if (NULL != egoname) | 1074 | * @param con_handle the connection handle |
830 | { | 1075 | * @param url the url |
831 | for (ego_entry = handle->ego_head; | 1076 | * @param cls the RequestHandle |
832 | NULL != ego_entry; ego_entry = ego_entry->next) | 1077 | */ |
833 | { | 1078 | void |
834 | if (0 != strcmp (egoname, ego_entry->identifier)) | 1079 | ego_delete_name (struct GNUNET_REST_RequestHandle *con_handle, |
835 | continue; | 1080 | const char* url, |
836 | ego_exists = GNUNET_YES; | 1081 | void *cls) |
837 | break; | 1082 | { |
838 | } | 1083 | struct RequestHandle *handle = cls; |
839 | } | 1084 | struct EgoEntry *ego_entry; |
840 | else | 1085 | char *name; |
1086 | |||
1087 | name = NULL; | ||
1088 | |||
1089 | if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) | ||
841 | { | 1090 | { |
842 | handle->emsg = GNUNET_strdup("Missing parameter pubkey or name"); | 1091 | handle->response_code = MHD_HTTP_NOT_FOUND; |
1092 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_NAME); | ||
843 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1093 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
844 | return; | 1094 | return; |
845 | } | 1095 | } |
1096 | name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME)+1]; | ||
1097 | ego_entry = get_egoentry(handle, NULL, name); | ||
846 | 1098 | ||
847 | if (GNUNET_NO == ego_exists) | 1099 | if (NULL == ego_entry) |
848 | { | 1100 | { |
849 | resp = GNUNET_REST_create_response (NULL); | 1101 | handle->response_code = MHD_HTTP_NOT_FOUND; |
850 | handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND); | 1102 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); |
851 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 1103 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
852 | return; | 1104 | return; |
853 | } | 1105 | } |
1106 | |||
854 | handle->response_code = MHD_HTTP_NO_CONTENT; | 1107 | handle->response_code = MHD_HTTP_NO_CONTENT; |
855 | handle->op = GNUNET_IDENTITY_delete (handle->identity_handle, | 1108 | handle->op = GNUNET_IDENTITY_delete (handle->identity_handle, |
856 | ego_entry->identifier, &do_finished, | 1109 | ego_entry->identifier, |
1110 | &do_finished, | ||
857 | handle); | 1111 | handle); |
858 | |||
859 | } | 1112 | } |
860 | 1113 | ||
1114 | |||
861 | /** | 1115 | /** |
862 | * Respond to OPTIONS request | 1116 | * Respond to OPTIONS request |
863 | * | 1117 | * |
@@ -890,10 +1144,16 @@ init_cont (struct RequestHandle *handle) | |||
890 | { | 1144 | { |
891 | struct GNUNET_REST_RequestHandlerError err; | 1145 | struct GNUNET_REST_RequestHandlerError err; |
892 | static const struct GNUNET_REST_RequestHandler handlers[] = { | 1146 | static const struct GNUNET_REST_RequestHandler handlers[] = { |
893 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_get }, | 1147 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_ALL, &ego_get_all }, |
894 | { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY, &ego_edit }, | 1148 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PUBKEY, &ego_get_pubkey }, |
1149 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_get_name }, | ||
1150 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, &ego_get_subsystem }, | ||
1151 | { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_PUBKEY, &ego_edit_pubkey }, | ||
1152 | { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_edit_name }, | ||
1153 | { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, &ego_edit_subsystem }, | ||
895 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create }, | 1154 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create }, |
896 | { MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_IDENTITY, &ego_delete }, | 1155 | { MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_IDENTITY_PUBKEY, &ego_delete_pubkey }, |
1156 | { MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_delete_name }, | ||
897 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont }, | 1157 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont }, |
898 | GNUNET_REST_HANDLER_END | 1158 | GNUNET_REST_HANDLER_END |
899 | }; | 1159 | }; |
diff --git a/src/namestore/plugin_rest_namestore.c b/src/rest-plugins/plugin_rest_namestore.c index f14707cce..2926f4b90 100644 --- a/src/namestore/plugin_rest_namestore.c +++ b/src/rest-plugins/plugin_rest_namestore.c | |||
@@ -32,22 +32,40 @@ | |||
32 | #include "microhttpd.h" | 32 | #include "microhttpd.h" |
33 | #include <jansson.h> | 33 | #include <jansson.h> |
34 | 34 | ||
35 | 35 | /** | |
36 | * Namestore Namespace | ||
37 | */ | ||
36 | #define GNUNET_REST_API_NS_NAMESTORE "/namestore" | 38 | #define GNUNET_REST_API_NS_NAMESTORE "/namestore" |
37 | #define GNUNET_REST_SUBSYSTEM_NAMESTORE "namestore" | ||
38 | 39 | ||
39 | /** | 40 | /** |
40 | * Parameter names | 41 | * Error message Unknown Error |
41 | */ | 42 | */ |
42 | #define GNUNET_REST_API_PARAM_PUBKEY "pubkey" | 43 | #define GNUNET_REST_NAMESTORE_ERROR_UNKNOWN "Unknown Error" |
43 | #define GNUNET_REST_API_PARAM_NAME "name" | ||
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Error messages | 46 | * Error message No identity found |
47 | */ | 47 | */ |
48 | #define GNUNET_REST_NAMESTORE_ERROR_UNKNOWN "Unknown Error" | 48 | #define GNUNET_REST_IDENTITY_NOT_FOUND "No identity found" |
49 | |||
50 | /** | ||
51 | * Error message No default zone specified | ||
52 | */ | ||
53 | #define GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE "No default zone specified" | ||
49 | 54 | ||
50 | #define GNUNET_REST_NAMESTORE_RD_COUNT 1 | 55 | /** |
56 | * Error message Failed request | ||
57 | */ | ||
58 | #define GNUNET_REST_NAMESTORE_FAILED "Namestore action failed" | ||
59 | |||
60 | /** | ||
61 | * Error message invalid data | ||
62 | */ | ||
63 | #define GNUNET_REST_NAMESTORE_INVALID_DATA "Data invalid" | ||
64 | |||
65 | /** | ||
66 | * Error message No data | ||
67 | */ | ||
68 | #define GNUNET_REST_NAMESTORE_NO_DATA "No data" | ||
51 | 69 | ||
52 | /** | 70 | /** |
53 | * State while collecting all egos | 71 | * State while collecting all egos |
@@ -107,13 +125,15 @@ struct EgoEntry | |||
107 | struct GNUNET_IDENTITY_Ego *ego; | 125 | struct GNUNET_IDENTITY_Ego *ego; |
108 | }; | 126 | }; |
109 | 127 | ||
110 | 128 | /** | |
129 | * The request handle | ||
130 | */ | ||
111 | struct RequestHandle | 131 | struct RequestHandle |
112 | { | 132 | { |
113 | /** | 133 | /** |
114 | * Records to store | 134 | * Records to store |
115 | */ | 135 | */ |
116 | char *label_name; | 136 | char *record_name; |
117 | 137 | ||
118 | /** | 138 | /** |
119 | * Records to store | 139 | * Records to store |
@@ -211,7 +231,7 @@ struct RequestHandle | |||
211 | char *emsg; | 231 | char *emsg; |
212 | 232 | ||
213 | /** | 233 | /** |
214 | * Reponse code | 234 | * Response code |
215 | */ | 235 | */ |
216 | int response_code; | 236 | int response_code; |
217 | 237 | ||
@@ -235,8 +255,8 @@ cleanup_handle (void *cls) | |||
235 | GNUNET_SCHEDULER_cancel (handle->timeout_task); | 255 | GNUNET_SCHEDULER_cancel (handle->timeout_task); |
236 | handle->timeout_task = NULL; | 256 | handle->timeout_task = NULL; |
237 | } | 257 | } |
238 | if (NULL != handle->label_name) | 258 | if (NULL != handle->record_name) |
239 | GNUNET_free(handle->label_name); | 259 | GNUNET_free(handle->record_name); |
240 | if (NULL != handle->url) | 260 | if (NULL != handle->url) |
241 | GNUNET_free(handle->url); | 261 | GNUNET_free(handle->url); |
242 | if (NULL != handle->emsg) | 262 | if (NULL != handle->emsg) |
@@ -318,20 +338,9 @@ do_error (void *cls) | |||
318 | * @return EgoEntry or NULL if not found | 338 | * @return EgoEntry or NULL if not found |
319 | */ | 339 | */ |
320 | struct EgoEntry* | 340 | struct EgoEntry* |
321 | get_egoentry(struct RequestHandle *handle, char* pubkey, char *name) | 341 | get_egoentry_namestore(struct RequestHandle *handle, char *name) |
322 | { | 342 | { |
323 | struct EgoEntry *ego_entry; | 343 | struct EgoEntry *ego_entry; |
324 | if (NULL != pubkey) | ||
325 | { | ||
326 | for (ego_entry = handle->ego_head; | ||
327 | NULL != ego_entry; | ||
328 | ego_entry = ego_entry->next) | ||
329 | { | ||
330 | if (0 != strcasecmp (pubkey, ego_entry->keystring)) | ||
331 | continue; | ||
332 | return ego_entry; | ||
333 | } | ||
334 | } | ||
335 | if (NULL != name) | 344 | if (NULL != name) |
336 | { | 345 | { |
337 | for (ego_entry = handle->ego_head; | 346 | for (ego_entry = handle->ego_head; |
@@ -349,17 +358,26 @@ get_egoentry(struct RequestHandle *handle, char* pubkey, char *name) | |||
349 | 358 | ||
350 | /** | 359 | /** |
351 | * Does internal server error when iteration failed. | 360 | * Does internal server error when iteration failed. |
361 | * | ||
362 | * @param cls the `struct RequestHandle` | ||
352 | */ | 363 | */ |
353 | static void | 364 | static void |
354 | namestore_iteration_error (void *cls) | 365 | namestore_iteration_error (void *cls) |
355 | { | 366 | { |
356 | struct RequestHandle *handle = cls; | 367 | struct RequestHandle *handle = cls; |
357 | struct MHD_Response *resp = GNUNET_REST_create_response (NULL); | 368 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); |
358 | handle->proc (handle->proc_cls, resp, MHD_HTTP_INTERNAL_SERVER_ERROR); | 369 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
359 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 370 | return; |
360 | } | 371 | } |
361 | 372 | ||
362 | 373 | ||
374 | /** | ||
375 | * Create finished callback | ||
376 | * | ||
377 | * @param cls the `struct RequestHandle` | ||
378 | * @param success the success indicating integer, GNUNET_OK on success | ||
379 | * @param emsg the error message (can be NULL) | ||
380 | */ | ||
363 | static void | 381 | static void |
364 | create_finished (void *cls, int32_t success, const char *emsg) | 382 | create_finished (void *cls, int32_t success, const char *emsg) |
365 | { | 383 | { |
@@ -369,6 +387,12 @@ create_finished (void *cls, int32_t success, const char *emsg) | |||
369 | handle->add_qe = NULL; | 387 | handle->add_qe = NULL; |
370 | if (GNUNET_YES != success) | 388 | if (GNUNET_YES != success) |
371 | { | 389 | { |
390 | if (NULL != emsg) | ||
391 | { | ||
392 | handle->emsg = GNUNET_strdup(emsg); | ||
393 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
394 | return; | ||
395 | } | ||
372 | handle->emsg = GNUNET_strdup("Error storing records"); | 396 | handle->emsg = GNUNET_strdup("Error storing records"); |
373 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 397 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
374 | return; | 398 | return; |
@@ -379,6 +403,13 @@ create_finished (void *cls, int32_t success, const char *emsg) | |||
379 | } | 403 | } |
380 | 404 | ||
381 | 405 | ||
406 | /** | ||
407 | * Delete finished callback | ||
408 | * | ||
409 | * @param cls the `struct RequestHandle` | ||
410 | * @param success the success indicating integer, GNUNET_OK on success | ||
411 | * @param emsg the error message (can be NULL) | ||
412 | */ | ||
382 | static void | 413 | static void |
383 | del_finished (void *cls, int32_t success, const char *emsg) | 414 | del_finished (void *cls, int32_t success, const char *emsg) |
384 | { | 415 | { |
@@ -387,12 +418,19 @@ del_finished (void *cls, int32_t success, const char *emsg) | |||
387 | handle->add_qe = NULL; | 418 | handle->add_qe = NULL; |
388 | if (GNUNET_NO == success) | 419 | if (GNUNET_NO == success) |
389 | { | 420 | { |
390 | handle->emsg = GNUNET_strdup("Deleting record failed. Record does not exist"); | 421 | handle->response_code = MHD_HTTP_NOT_FOUND; |
422 | handle->emsg = GNUNET_strdup("No record found"); | ||
391 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 423 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
392 | return; | 424 | return; |
393 | } | 425 | } |
394 | if (GNUNET_SYSERR == success) | 426 | if (GNUNET_SYSERR == success) |
395 | { | 427 | { |
428 | if (NULL != emsg) | ||
429 | { | ||
430 | handle->emsg = GNUNET_strdup(emsg); | ||
431 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
432 | return; | ||
433 | } | ||
396 | handle->emsg = GNUNET_strdup("Deleting record failed"); | 434 | handle->emsg = GNUNET_strdup("Deleting record failed"); |
397 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 435 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
398 | return; | 436 | return; |
@@ -420,10 +458,7 @@ namestore_list_finished (void *cls) | |||
420 | handle->list_it = NULL; | 458 | handle->list_it = NULL; |
421 | 459 | ||
422 | if (NULL == handle->resp_object) | 460 | if (NULL == handle->resp_object) |
423 | { | 461 | handle->resp_object = json_array(); |
424 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
425 | return; | ||
426 | } | ||
427 | 462 | ||
428 | result_str = json_dumps (handle->resp_object, 0); | 463 | result_str = json_dumps (handle->resp_object, 0); |
429 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | 464 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); |
@@ -452,17 +487,6 @@ namestore_list_iteration (void *cls, | |||
452 | if (NULL == handle->resp_object) | 487 | if (NULL == handle->resp_object) |
453 | handle->resp_object = json_array(); | 488 | handle->resp_object = json_array(); |
454 | 489 | ||
455 | /*if ( (NULL != handle->ego_entry->identifier) && | ||
456 | (0 != strcmp (handle->ego_entry->identifier, | ||
457 | rname)) ) | ||
458 | { | ||
459 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
460 | "%s does not match %s\n", rname, | ||
461 | handle->ego_entry->identifier); | ||
462 | GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1); | ||
463 | return; | ||
464 | }*/ | ||
465 | |||
466 | for (unsigned int i = 0; i < rd_len; i++) | 490 | for (unsigned int i = 0; i < rd_len; i++) |
467 | { | 491 | { |
468 | if ( (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) && | 492 | if ( (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) && |
@@ -481,6 +505,48 @@ namestore_list_iteration (void *cls, | |||
481 | GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1); | 505 | GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1); |
482 | } | 506 | } |
483 | 507 | ||
508 | /** | ||
509 | * @param cls closure | ||
510 | * @param ego ego handle | ||
511 | * @param ctx context for application to store data for this ego | ||
512 | * (during the lifetime of this process, initially NULL) | ||
513 | * @param identifier identifier assigned by the user for this ego, | ||
514 | * NULL if the user just deleted the ego and it | ||
515 | * must thus no longer be used | ||
516 | */ | ||
517 | static void | ||
518 | default_ego_get (void *cls, | ||
519 | struct GNUNET_IDENTITY_Ego *ego, | ||
520 | void **ctx, | ||
521 | const char *identifier) | ||
522 | { | ||
523 | struct RequestHandle *handle = cls; | ||
524 | handle->op = NULL; | ||
525 | |||
526 | if (ego == NULL) | ||
527 | { | ||
528 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE); | ||
529 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
530 | return; | ||
531 | } | ||
532 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego); | ||
533 | |||
534 | handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, | ||
535 | handle->zone_pkey, | ||
536 | &namestore_iteration_error, | ||
537 | handle, | ||
538 | &namestore_list_iteration, | ||
539 | handle, | ||
540 | &namestore_list_finished, | ||
541 | handle); | ||
542 | if (NULL == handle->list_it) | ||
543 | { | ||
544 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | ||
545 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
546 | return; | ||
547 | } | ||
548 | } | ||
549 | |||
484 | 550 | ||
485 | /** | 551 | /** |
486 | * Handle namestore GET request | 552 | * Handle namestore GET request |
@@ -495,40 +561,22 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle, | |||
495 | void *cls) | 561 | void *cls) |
496 | { | 562 | { |
497 | struct RequestHandle *handle = cls; | 563 | struct RequestHandle *handle = cls; |
498 | struct EgoEntry *ego_entry = NULL; | 564 | struct EgoEntry *ego_entry; |
499 | struct GNUNET_HashCode key; | 565 | char *egoname; |
500 | char *pubkey = NULL; | 566 | |
501 | char *name = NULL; | 567 | egoname = NULL; |
502 | 568 | ego_entry = NULL; | |
503 | //change zone if pubkey or name specified | ||
504 | GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_PUBKEY, | ||
505 | strlen (GNUNET_REST_API_PARAM_PUBKEY), | ||
506 | &key); | ||
507 | if ( GNUNET_YES | ||
508 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, | ||
509 | &key)) | ||
510 | { | ||
511 | pubkey = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, | ||
512 | &key); | ||
513 | } | ||
514 | GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_NAME, | ||
515 | strlen (GNUNET_REST_API_PARAM_NAME), | ||
516 | &key); | ||
517 | if ( GNUNET_YES | ||
518 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, | ||
519 | &key)) | ||
520 | { | ||
521 | name = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, | ||
522 | &key); | ||
523 | } | ||
524 | 569 | ||
525 | ego_entry = get_egoentry(handle,pubkey,name); | 570 | //set zone to name if given |
526 | if (NULL == ego_entry) | 571 | if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url)) |
527 | { | 572 | { |
528 | if (NULL != pubkey || NULL != name) | 573 | egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE)+1]; |
574 | ego_entry = get_egoentry_namestore(handle, egoname); | ||
575 | |||
576 | if (NULL == ego_entry) | ||
529 | { | 577 | { |
530 | handle->emsg = GNUNET_strdup("Invalid identity"); | ||
531 | handle->response_code = MHD_HTTP_NOT_FOUND; | 578 | handle->response_code = MHD_HTTP_NOT_FOUND; |
579 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | ||
532 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 580 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
533 | return; | 581 | return; |
534 | } | 582 | } |
@@ -537,6 +585,15 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle, | |||
537 | { | 585 | { |
538 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); | 586 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); |
539 | } | 587 | } |
588 | |||
589 | if (NULL == handle->zone_pkey) | ||
590 | { | ||
591 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, | ||
592 | "namestore", | ||
593 | &default_ego_get, | ||
594 | handle); | ||
595 | return; | ||
596 | } | ||
540 | handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, | 597 | handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, |
541 | handle->zone_pkey, | 598 | handle->zone_pkey, |
542 | &namestore_iteration_error, | 599 | &namestore_iteration_error, |
@@ -545,53 +602,57 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle, | |||
545 | handle, | 602 | handle, |
546 | &namestore_list_finished, | 603 | &namestore_list_finished, |
547 | handle); | 604 | handle); |
605 | if (NULL == handle->list_it) | ||
606 | { | ||
607 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | ||
608 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
609 | return; | ||
610 | } | ||
548 | } | 611 | } |
549 | 612 | ||
550 | 613 | ||
551 | /** | 614 | /** |
552 | * We're storing a new record; this requires | 615 | * @param cls closure |
553 | * that no record already exists | 616 | * @param ego ego handle |
554 | * | 617 | * @param ctx context for application to store data for this ego |
555 | * @param cls closure, unused | 618 | * (during the lifetime of this process, initially NULL) |
556 | * @param zone_key private key of the zone | 619 | * @param identifier identifier assigned by the user for this ego, |
557 | * @param rec_name name that is being mapped (at most 255 characters long) | 620 | * NULL if the user just deleted the ego and it |
558 | * @param rd_count number of entries in @a rd array | 621 | * must thus no longer be used |
559 | * @param rd array of records with data to store | ||
560 | */ | 622 | */ |
561 | static void | 623 | static void |
562 | create_new_record_cont (void *cls, | 624 | default_ego_post (void *cls, |
563 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 625 | struct GNUNET_IDENTITY_Ego *ego, |
564 | const char *rec_name, | 626 | void **ctx, |
565 | unsigned int rd_count, | 627 | const char *identifier) |
566 | const struct GNUNET_GNSRECORD_Data *rd) | ||
567 | { | 628 | { |
568 | struct RequestHandle *handle = cls; | 629 | struct RequestHandle *handle = cls; |
630 | handle->op = NULL; | ||
569 | 631 | ||
570 | handle->add_qe = NULL; | 632 | if (ego == NULL) |
571 | if (0 != strcmp (rec_name, handle->label_name)) | ||
572 | { | 633 | { |
573 | GNUNET_break (0); | 634 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE); |
574 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 635 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
575 | return; | 636 | return; |
576 | } | 637 | } |
638 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego); | ||
577 | 639 | ||
578 | if (0 != rd_count) | 640 | handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, |
641 | handle->zone_pkey, | ||
642 | handle->record_name, | ||
643 | 1, | ||
644 | handle->rd, | ||
645 | &create_finished, | ||
646 | handle); | ||
647 | if (NULL == handle->add_qe) | ||
579 | { | 648 | { |
580 | handle->proc (handle->proc_cls, | 649 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); |
581 | GNUNET_REST_create_response (NULL), | 650 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
582 | MHD_HTTP_CONFLICT); | ||
583 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | ||
584 | return; | 651 | return; |
585 | } | 652 | } |
586 | handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, | ||
587 | handle->zone_pkey, | ||
588 | handle->label_name, | ||
589 | GNUNET_REST_NAMESTORE_RD_COUNT, | ||
590 | handle->rd, | ||
591 | &create_finished, | ||
592 | handle); | ||
593 | } | 653 | } |
594 | 654 | ||
655 | |||
595 | /** | 656 | /** |
596 | * Handle namestore POST request | 657 | * Handle namestore POST request |
597 | * | 658 | * |
@@ -606,30 +667,21 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle, | |||
606 | { | 667 | { |
607 | struct RequestHandle *handle = cls; | 668 | struct RequestHandle *handle = cls; |
608 | struct GNUNET_GNSRECORD_Data *gns_record; | 669 | struct GNUNET_GNSRECORD_Data *gns_record; |
670 | struct EgoEntry *ego_entry; | ||
671 | char *egoname; | ||
609 | json_t *data_js; | 672 | json_t *data_js; |
610 | json_t *name_json; | 673 | json_t *name_json; |
611 | json_error_t err; | 674 | json_error_t err; |
612 | |||
613 | struct EgoEntry *ego_entry = NULL; | ||
614 | struct GNUNET_HashCode key; | ||
615 | char *pubkey = NULL; | ||
616 | char *name = NULL; | ||
617 | |||
618 | char term_data[handle->rest_handle->data_size + 1]; | 675 | char term_data[handle->rest_handle->data_size + 1]; |
676 | |||
619 | struct GNUNET_JSON_Specification gnsspec[] = { | 677 | struct GNUNET_JSON_Specification gnsspec[] = { |
620 | GNUNET_JSON_spec_gnsrecord_data(&gns_record), | 678 | GNUNET_JSON_spec_gnsrecord_data(&gns_record), |
621 | GNUNET_JSON_spec_end () | 679 | GNUNET_JSON_spec_end () |
622 | }; | 680 | }; |
623 | 681 | ||
624 | if (strlen (GNUNET_REST_API_NS_NAMESTORE) != strlen (handle->url)) | ||
625 | { | ||
626 | handle->emsg = GNUNET_strdup("Wrong URL"); | ||
627 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
628 | return; | ||
629 | } | ||
630 | if (0 >= handle->rest_handle->data_size) | 682 | if (0 >= handle->rest_handle->data_size) |
631 | { | 683 | { |
632 | handle->emsg = GNUNET_strdup("No data"); | 684 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DATA); |
633 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 685 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
634 | return; | 686 | return; |
635 | } | 687 | } |
@@ -639,7 +691,7 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle, | |||
639 | data_js = json_loads (term_data, JSON_DECODE_ANY, &err); | 691 | data_js = json_loads (term_data, JSON_DECODE_ANY, &err); |
640 | if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL)) | 692 | if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL)) |
641 | { | 693 | { |
642 | handle->emsg = GNUNET_strdup("Invalid data"); | 694 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA); |
643 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 695 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
644 | GNUNET_JSON_parse_free(gnsspec); | 696 | GNUNET_JSON_parse_free(gnsspec); |
645 | json_decref (data_js); | 697 | json_decref (data_js); |
@@ -647,109 +699,118 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle, | |||
647 | } | 699 | } |
648 | handle->rd = gns_record; | 700 | handle->rd = gns_record; |
649 | 701 | ||
650 | name_json = json_object_get(data_js, "label"); | 702 | name_json = json_object_get(data_js, "record_name"); |
651 | if (!json_is_string(name_json)) | 703 | if (!json_is_string(name_json)) |
652 | { | 704 | { |
653 | handle->emsg = GNUNET_strdup("Missing name"); | 705 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA); |
654 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 706 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
655 | json_decref (data_js); | 707 | json_decref (data_js); |
656 | return; | 708 | return; |
657 | } | 709 | } |
658 | handle->label_name = GNUNET_strdup(json_string_value(name_json)); | 710 | handle->record_name = GNUNET_strdup(json_string_value(name_json)); |
659 | if(NULL == handle->label_name) | 711 | if(NULL == handle->record_name) |
660 | { | 712 | { |
661 | handle->emsg = GNUNET_strdup("Missing name"); | 713 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA); |
662 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 714 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
663 | json_decref (data_js); | 715 | json_decref (data_js); |
664 | return; | 716 | return; |
665 | } | 717 | } |
666 | if (0 >= strlen(handle->label_name)) | 718 | if (0 >= strlen(handle->record_name)) |
667 | { | 719 | { |
668 | handle->emsg = GNUNET_strdup("Missing name"); | 720 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA); |
669 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 721 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
670 | json_decref (data_js); | 722 | json_decref (data_js); |
671 | return; | 723 | return; |
672 | } | 724 | } |
673 | json_decref (data_js); | 725 | json_decref (data_js); |
674 | 726 | ||
675 | //change zone if pubkey or name specified | 727 | egoname = NULL; |
676 | GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_PUBKEY, | 728 | ego_entry = NULL; |
677 | strlen (GNUNET_REST_API_PARAM_PUBKEY), | ||
678 | &key); | ||
679 | if ( GNUNET_YES | ||
680 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, | ||
681 | &key)) | ||
682 | { | ||
683 | pubkey = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, | ||
684 | &key); | ||
685 | } | ||
686 | GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_NAME, | ||
687 | strlen (GNUNET_REST_API_PARAM_NAME), | ||
688 | &key); | ||
689 | if ( GNUNET_YES | ||
690 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, | ||
691 | &key)) | ||
692 | { | ||
693 | name = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, | ||
694 | &key); | ||
695 | } | ||
696 | 729 | ||
697 | ego_entry = get_egoentry(handle,pubkey,name); | 730 | //set zone to name if given |
698 | if (NULL == ego_entry) | 731 | if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url)) |
699 | { | 732 | { |
700 | if (NULL != pubkey || NULL != name) | 733 | egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE)+1]; |
734 | ego_entry = get_egoentry_namestore(handle, egoname); | ||
735 | |||
736 | if (NULL == ego_entry) | ||
701 | { | 737 | { |
702 | handle->emsg = GNUNET_strdup("Invalid identity"); | ||
703 | handle->response_code = MHD_HTTP_NOT_FOUND; | 738 | handle->response_code = MHD_HTTP_NOT_FOUND; |
739 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | ||
704 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 740 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
705 | return; | 741 | return; |
706 | } | 742 | } |
707 | } | 743 | } |
708 | if ( NULL != ego_entry ) | 744 | if (NULL != ego_entry) |
709 | { | 745 | { |
710 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); | 746 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); |
711 | } | 747 | } |
712 | if (NULL == handle->zone_pkey) | 748 | if (NULL == handle->zone_pkey) |
713 | { | 749 | { |
714 | handle->emsg = GNUNET_strdup("No default identity for namestore"); | 750 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, |
751 | "namestore", | ||
752 | &default_ego_post, | ||
753 | handle); | ||
754 | return; | ||
755 | } | ||
756 | handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, | ||
757 | handle->zone_pkey, | ||
758 | handle->record_name, | ||
759 | 1, | ||
760 | handle->rd, | ||
761 | &create_finished, | ||
762 | handle); | ||
763 | if (NULL == handle->add_qe) | ||
764 | { | ||
765 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | ||
715 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 766 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
716 | return; | 767 | return; |
717 | } | 768 | } |
718 | handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, | ||
719 | handle->zone_pkey, | ||
720 | handle->label_name, | ||
721 | &do_error, | ||
722 | handle, | ||
723 | &create_new_record_cont, | ||
724 | handle); | ||
725 | } | 769 | } |
726 | 770 | ||
727 | 771 | ||
772 | /** | ||
773 | * @param cls closure | ||
774 | * @param ego ego handle | ||
775 | * @param ctx context for application to store data for this ego | ||
776 | * (during the lifetime of this process, initially NULL) | ||
777 | * @param identifier identifier assigned by the user for this ego, | ||
778 | * NULL if the user just deleted the ego and it | ||
779 | * must thus no longer be used | ||
780 | */ | ||
728 | static void | 781 | static void |
729 | del_cont (void *cls, | 782 | default_ego_delete (void *cls, |
730 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 783 | struct GNUNET_IDENTITY_Ego *ego, |
731 | const char *label, | 784 | void **ctx, |
732 | unsigned int rd_count, | 785 | const char *identifier) |
733 | const struct GNUNET_GNSRECORD_Data *rd) | ||
734 | { | 786 | { |
735 | struct RequestHandle *handle = cls; | 787 | struct RequestHandle *handle = cls; |
788 | handle->op = NULL; | ||
736 | 789 | ||
737 | handle->add_qe = NULL; | 790 | if (ego == NULL) |
738 | if (0 == rd_count) | ||
739 | { | 791 | { |
740 | handle->emsg = GNUNET_strdup("Record not found"); | 792 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE); |
741 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 793 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
742 | return; | 794 | return; |
743 | } | 795 | } |
796 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego); | ||
744 | 797 | ||
745 | handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, | 798 | handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, |
746 | handle->zone_pkey, | 799 | handle->zone_pkey, |
747 | handle->label_name, | 800 | handle->record_name, |
748 | 0, NULL, | 801 | 0, |
802 | NULL, | ||
749 | &del_finished, | 803 | &del_finished, |
750 | handle); | 804 | handle); |
805 | if (NULL == handle->add_qe) | ||
806 | { | ||
807 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | ||
808 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
809 | return; | ||
810 | } | ||
751 | } | 811 | } |
752 | 812 | ||
813 | |||
753 | /** | 814 | /** |
754 | * Handle namestore DELETE request | 815 | * Handle namestore DELETE request |
755 | * | 816 | * |
@@ -764,39 +825,22 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle, | |||
764 | { | 825 | { |
765 | struct RequestHandle *handle = cls; | 826 | struct RequestHandle *handle = cls; |
766 | struct GNUNET_HashCode key; | 827 | struct GNUNET_HashCode key; |
767 | struct EgoEntry *ego_entry = NULL; | 828 | struct EgoEntry *ego_entry; |
768 | char *pubkey = NULL; | 829 | char *egoname; |
769 | char *name = NULL; | 830 | |
770 | 831 | egoname = NULL; | |
771 | //change zone if pubkey or name specified | 832 | ego_entry = NULL; |
772 | GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_PUBKEY, | ||
773 | strlen (GNUNET_REST_API_PARAM_PUBKEY), | ||
774 | &key); | ||
775 | if ( GNUNET_YES | ||
776 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, | ||
777 | &key)) | ||
778 | { | ||
779 | pubkey = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, | ||
780 | &key); | ||
781 | } | ||
782 | GNUNET_CRYPTO_hash (GNUNET_REST_API_PARAM_NAME, | ||
783 | strlen (GNUNET_REST_API_PARAM_NAME), | ||
784 | &key); | ||
785 | if ( GNUNET_YES | ||
786 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, | ||
787 | &key)) | ||
788 | { | ||
789 | name = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, | ||
790 | &key); | ||
791 | } | ||
792 | 833 | ||
793 | ego_entry = get_egoentry(handle,pubkey,name); | 834 | //set zone to name if given |
794 | if (NULL == ego_entry) | 835 | if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url)) |
795 | { | 836 | { |
796 | if (NULL != pubkey || NULL != name) | 837 | egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE)+1]; |
838 | ego_entry = get_egoentry_namestore(handle, egoname); | ||
839 | |||
840 | if (NULL == ego_entry) | ||
797 | { | 841 | { |
798 | handle->emsg = GNUNET_strdup("Invalid identity"); | ||
799 | handle->response_code = MHD_HTTP_NOT_FOUND; | 842 | handle->response_code = MHD_HTTP_NOT_FOUND; |
843 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | ||
800 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 844 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
801 | return; | 845 | return; |
802 | } | 846 | } |
@@ -806,33 +850,40 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle, | |||
806 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); | 850 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); |
807 | } | 851 | } |
808 | 852 | ||
809 | GNUNET_CRYPTO_hash ("label", strlen ("label"), &key); | 853 | GNUNET_CRYPTO_hash ("record_name", strlen ("record_name"), &key); |
810 | if ( GNUNET_NO | 854 | if ( GNUNET_NO |
811 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, | 855 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, |
812 | &key)) | 856 | &key)) |
813 | { | 857 | { |
814 | handle->emsg = GNUNET_strdup("Missing name"); | 858 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA); |
815 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 859 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
816 | return; | 860 | return; |
817 | } | 861 | } |
818 | handle->label_name = GNUNET_strdup( | 862 | handle->record_name = GNUNET_strdup( |
819 | GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key)); | 863 | GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key)); |
820 | 864 | ||
821 | if (NULL == handle->zone_pkey) | 865 | if (NULL == handle->zone_pkey) |
822 | { | 866 | { |
823 | handle->emsg = GNUNET_strdup("No default identity for namestore"); | 867 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, |
824 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 868 | "namestore", |
869 | &default_ego_delete, | ||
870 | handle); | ||
825 | return; | 871 | return; |
826 | } | 872 | } |
827 | 873 | ||
828 | handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, | 874 | handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, |
829 | handle->zone_pkey, | 875 | handle->zone_pkey, |
830 | handle->label_name, | 876 | handle->record_name, |
831 | &do_error, | 877 | 0, |
832 | handle, | 878 | NULL, |
833 | &del_cont, | 879 | &del_finished, |
834 | handle); | 880 | handle); |
835 | 881 | if (NULL == handle->add_qe) | |
882 | { | ||
883 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | ||
884 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
885 | return; | ||
886 | } | ||
836 | } | 887 | } |
837 | 888 | ||
838 | 889 | ||
@@ -890,35 +941,39 @@ init_cont (struct RequestHandle *handle) | |||
890 | } | 941 | } |
891 | } | 942 | } |
892 | 943 | ||
944 | |||
893 | /** | 945 | /** |
946 | * This function is initially called for all egos and then again | ||
947 | * whenever a ego's identifier changes or if it is deleted. At the | ||
948 | * end of the initial pass over all egos, the function is once called | ||
949 | * with 'NULL' for 'ego'. That does NOT mean that the callback won't | ||
950 | * be invoked in the future or that there was an error. | ||
951 | * | ||
952 | * When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get', | ||
953 | * this function is only called ONCE, and 'NULL' being passed in | ||
954 | * 'ego' does indicate an error (i.e. name is taken or no default | ||
955 | * value is known). If 'ego' is non-NULL and if '*ctx' | ||
956 | * is set in those callbacks, the value WILL be passed to a subsequent | ||
957 | * call to the identity callback of 'GNUNET_IDENTITY_connect' (if | ||
958 | * that one was not NULL). | ||
959 | * | ||
960 | * When an identity is renamed, this function is called with the | ||
961 | * (known) ego but the NEW identifier. | ||
962 | * | ||
963 | * When an identity is deleted, this function is called with the | ||
964 | * (known) ego and "NULL" for the 'identifier'. In this case, | ||
965 | * the 'ego' is henceforth invalid (and the 'ctx' should also be | ||
966 | * cleaned up). | ||
967 | * | ||
894 | * @param cls closure | 968 | * @param cls closure |
895 | * @param ego ego handle | 969 | * @param ego ego handle |
896 | * @param ctx context for application to store data for this ego | 970 | * @param ctx context for application to store data for this ego |
897 | * (during the lifetime of this process, initially NULL) | 971 | * (during the lifetime of this process, initially NULL) |
898 | * @param identifier identifier assigned by the user for this ego, | 972 | * @param name identifier assigned by the user for this ego, |
899 | * NULL if the user just deleted the ego and it | 973 | * NULL if the user just deleted the ego and it |
900 | * must thus no longer be used | 974 | * must thus no longer be used |
901 | */ | 975 | */ |
902 | static void | 976 | static void |
903 | default_ego_cb (void *cls, | ||
904 | struct GNUNET_IDENTITY_Ego *ego, | ||
905 | void **ctx, | ||
906 | const char *identifier) | ||
907 | { | ||
908 | struct RequestHandle *handle = cls; | ||
909 | handle->op = NULL; | ||
910 | |||
911 | if (ego != NULL) | ||
912 | { | ||
913 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego); | ||
914 | } | ||
915 | } | ||
916 | |||
917 | |||
918 | /** | ||
919 | * Connect to identity callback | ||
920 | */ | ||
921 | static void | ||
922 | id_connect_cb (void *cls, | 977 | id_connect_cb (void *cls, |
923 | struct GNUNET_IDENTITY_Ego *ego, | 978 | struct GNUNET_IDENTITY_Ego *ego, |
924 | void **ctx, | 979 | void **ctx, |
@@ -928,17 +983,10 @@ id_connect_cb (void *cls, | |||
928 | struct EgoEntry *ego_entry; | 983 | struct EgoEntry *ego_entry; |
929 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 984 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; |
930 | 985 | ||
931 | if ((NULL == ego) && (NULL == handle->zone_pkey)) | ||
932 | { | ||
933 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, | ||
934 | GNUNET_REST_SUBSYSTEM_NAMESTORE, | ||
935 | &default_ego_cb, | ||
936 | handle); | ||
937 | } | ||
938 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) | 986 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) |
939 | { | 987 | { |
940 | handle->state = ID_REST_STATE_POST_INIT; | 988 | handle->state = ID_REST_STATE_POST_INIT; |
941 | init_cont (handle); | 989 | init_cont(handle); |
942 | return; | 990 | return; |
943 | } | 991 | } |
944 | if (ID_REST_STATE_INIT == handle->state) | 992 | if (ID_REST_STATE_INIT == handle->state) |
@@ -985,8 +1033,8 @@ rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, | |||
985 | handle->url[strlen (handle->url)-1] = '\0'; | 1033 | handle->url[strlen (handle->url)-1] = '\0'; |
986 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); | 1034 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); |
987 | 1035 | ||
988 | handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &id_connect_cb, handle); | ||
989 | handle->ns_handle = GNUNET_NAMESTORE_connect (cfg); | 1036 | handle->ns_handle = GNUNET_NAMESTORE_connect (cfg); |
1037 | handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &id_connect_cb, handle); | ||
990 | handle->timeout_task = | 1038 | handle->timeout_task = |
991 | GNUNET_SCHEDULER_add_delayed (handle->timeout, | 1039 | GNUNET_SCHEDULER_add_delayed (handle->timeout, |
992 | &do_error, | 1040 | &do_error, |
diff --git a/src/reclaim/plugin_rest_openid_connect.c b/src/rest-plugins/plugin_rest_openid_connect.c index 24673c692..24673c692 100644 --- a/src/reclaim/plugin_rest_openid_connect.c +++ b/src/rest-plugins/plugin_rest_openid_connect.c | |||
diff --git a/src/peerinfo-tool/plugin_rest_peerinfo.c b/src/rest-plugins/plugin_rest_peerinfo.c index 97c473e36..29b40088d 100644 --- a/src/peerinfo-tool/plugin_rest_peerinfo.c +++ b/src/rest-plugins/plugin_rest_peerinfo.c | |||
@@ -31,13 +31,30 @@ | |||
31 | #include "microhttpd.h" | 31 | #include "microhttpd.h" |
32 | #include <jansson.h> | 32 | #include <jansson.h> |
33 | 33 | ||
34 | /** | ||
35 | * Peerinfo Namespace | ||
36 | */ | ||
34 | #define GNUNET_REST_API_NS_PEERINFO "/peerinfo" | 37 | #define GNUNET_REST_API_NS_PEERINFO "/peerinfo" |
35 | 38 | ||
36 | #define GNUNET_REST_API_PEERINFO_PEER "peer" | 39 | /** |
37 | #define GNUNET_REST_API_PEERINFO_FRIEND "friend" | 40 | * Peerinfo parameter peer |
38 | #define GNUNET_REST_API_PEERINFO_ARRAY "array" | 41 | */ |
42 | #define GNUNET_REST_PEERINFO_PEER "peer" | ||
39 | 43 | ||
40 | #define GNUNET_REST_ERROR_UNKNOWN "Unkown Error" | 44 | /** |
45 | * Peerinfo parameter friend | ||
46 | */ | ||
47 | #define GNUNET_REST_PEERINFO_FRIEND "friend" | ||
48 | |||
49 | /** | ||
50 | * Peerinfo parameter array | ||
51 | */ | ||
52 | #define GNUNET_REST_PEERINFO_ARRAY "array" | ||
53 | |||
54 | /** | ||
55 | * Error message Unknown Error | ||
56 | */ | ||
57 | #define GNUNET_REST_PEERINFO_ERROR_UNKNOWN "Unknown Error" | ||
41 | 58 | ||
42 | /** | 59 | /** |
43 | * How long until we time out during address lookup? | 60 | * How long until we time out during address lookup? |
@@ -94,7 +111,6 @@ struct AddressRecord | |||
94 | */ | 111 | */ |
95 | struct PrintContext | 112 | struct PrintContext |
96 | { | 113 | { |
97 | |||
98 | /** | 114 | /** |
99 | * Kept in DLL. | 115 | * Kept in DLL. |
100 | */ | 116 | */ |
@@ -152,6 +168,9 @@ static struct PrintContext *pc_head; | |||
152 | */ | 168 | */ |
153 | static struct PrintContext *pc_tail; | 169 | static struct PrintContext *pc_tail; |
154 | 170 | ||
171 | /** | ||
172 | * The request handle | ||
173 | */ | ||
155 | struct RequestHandle | 174 | struct RequestHandle |
156 | { | 175 | { |
157 | /** | 176 | /** |
@@ -299,7 +318,7 @@ do_error (void *cls) | |||
299 | char *response; | 318 | char *response; |
300 | 319 | ||
301 | if (NULL == handle->emsg) | 320 | if (NULL == handle->emsg) |
302 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_UNKNOWN); | 321 | handle->emsg = GNUNET_strdup(GNUNET_REST_PEERINFO_ERROR_UNKNOWN); |
303 | 322 | ||
304 | json_object_set_new(json_error,"error", json_string(handle->emsg)); | 323 | json_object_set_new(json_error,"error", json_string(handle->emsg)); |
305 | 324 | ||
@@ -315,7 +334,9 @@ do_error (void *cls) | |||
315 | 334 | ||
316 | 335 | ||
317 | /** | 336 | /** |
318 | * Function that assembles our response. | 337 | * Function that assembles the response. |
338 | * | ||
339 | * @param cls the `struct RequestHandle` | ||
319 | */ | 340 | */ |
320 | static void | 341 | static void |
321 | peerinfo_list_finished (void *cls) | 342 | peerinfo_list_finished (void *cls) |
@@ -326,6 +347,7 @@ peerinfo_list_finished (void *cls) | |||
326 | 347 | ||
327 | if (NULL == handle->response) | 348 | if (NULL == handle->response) |
328 | { | 349 | { |
350 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
329 | handle->emsg = GNUNET_strdup ("No peers found"); | 351 | handle->emsg = GNUNET_strdup ("No peers found"); |
330 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 352 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
331 | return; | 353 | return; |
@@ -386,9 +408,6 @@ dump_pc (struct PrintContext *pc) | |||
386 | temp_array = json_array(); | 408 | temp_array = json_array(); |
387 | response_entry = json_object(); | 409 | response_entry = json_object(); |
388 | 410 | ||
389 | // printf (_("%sPeer `%s'\n"), | ||
390 | // (GNUNET_YES == pc->friend_only) ? "F2F: " : "", | ||
391 | // GNUNET_i2s_full (&pc->peer)); | ||
392 | for (i = 0; i < pc->num_addresses; i++) | 411 | for (i = 0; i < pc->num_addresses; i++) |
393 | { | 412 | { |
394 | if (NULL != pc->address_list[i].result) | 413 | if (NULL != pc->address_list[i].result) |
@@ -417,10 +436,10 @@ dump_pc (struct PrintContext *pc) | |||
417 | GNUNET_i2s_full (&pc->peer)); | 436 | GNUNET_i2s_full (&pc->peer)); |
418 | friend_and_peer_json = json_string(friend_and_peer); | 437 | friend_and_peer_json = json_string(friend_and_peer); |
419 | json_object_set(response_entry, | 438 | json_object_set(response_entry, |
420 | GNUNET_REST_API_PEERINFO_PEER, | 439 | GNUNET_REST_PEERINFO_PEER, |
421 | friend_and_peer_json); | 440 | friend_and_peer_json); |
422 | json_object_set(response_entry, | 441 | json_object_set(response_entry, |
423 | GNUNET_REST_API_PEERINFO_ARRAY, | 442 | GNUNET_REST_PEERINFO_ARRAY, |
424 | temp_array); | 443 | temp_array); |
425 | json_array_append(pc->handle->response, response_entry); | 444 | json_array_append(pc->handle->response, response_entry); |
426 | json_decref(friend_and_peer_json); | 445 | json_decref(friend_and_peer_json); |
@@ -610,13 +629,13 @@ peerinfo_get (struct GNUNET_REST_RequestHandle *con_handle, | |||
610 | struct RequestHandle *handle = cls; | 629 | struct RequestHandle *handle = cls; |
611 | struct GNUNET_HashCode key; | 630 | struct GNUNET_HashCode key; |
612 | const struct GNUNET_PeerIdentity *specific_peer; | 631 | const struct GNUNET_PeerIdentity *specific_peer; |
613 | GNUNET_PEER_Id peer_id; | 632 | //GNUNET_PEER_Id peer_id; |
614 | int include_friend_only; | 633 | int include_friend_only; |
615 | char* include_friend_only_str; | 634 | char* include_friend_only_str; |
616 | 635 | ||
617 | include_friend_only = GNUNET_NO; | 636 | include_friend_only = GNUNET_NO; |
618 | GNUNET_CRYPTO_hash (GNUNET_REST_API_PEERINFO_FRIEND, | 637 | GNUNET_CRYPTO_hash (GNUNET_REST_PEERINFO_FRIEND, |
619 | strlen (GNUNET_REST_API_PEERINFO_FRIEND), | 638 | strlen (GNUNET_REST_PEERINFO_FRIEND), |
620 | &key); | 639 | &key); |
621 | if ( GNUNET_YES | 640 | if ( GNUNET_YES |
622 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, | 641 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, |
@@ -631,15 +650,15 @@ peerinfo_get (struct GNUNET_REST_RequestHandle *con_handle, | |||
631 | } | 650 | } |
632 | 651 | ||
633 | specific_peer = NULL; | 652 | specific_peer = NULL; |
634 | GNUNET_CRYPTO_hash (GNUNET_REST_API_PEERINFO_PEER, | 653 | GNUNET_CRYPTO_hash (GNUNET_REST_PEERINFO_PEER, |
635 | strlen (GNUNET_REST_API_PEERINFO_PEER), | 654 | strlen (GNUNET_REST_PEERINFO_PEER), |
636 | &key); | 655 | &key); |
637 | if ( GNUNET_YES | 656 | if ( GNUNET_YES |
638 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, | 657 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, |
639 | &key)) | 658 | &key)) |
640 | { | 659 | { |
641 | peer_id = *(unsigned int*)GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key); | 660 | //peer_id = *(unsigned int*)GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key); |
642 | specific_peer = GNUNET_PEER_resolve2(peer_id); | 661 | //specific_peer = GNUNET_PEER_resolve2(peer_id); |
643 | } | 662 | } |
644 | 663 | ||
645 | handle->list_it = GNUNET_PEERINFO_iterate(handle->peerinfo_handle, | 664 | handle->list_it = GNUNET_PEERINFO_iterate(handle->peerinfo_handle, |
diff --git a/src/gns/test_plugin_rest_gns.sh b/src/rest-plugins/test_plugin_rest_gns.sh index 7ede44501..ec495a04b 100755 --- a/src/gns/test_plugin_rest_gns.sh +++ b/src/rest-plugins/test_plugin_rest_gns.sh | |||
@@ -19,32 +19,32 @@ curl_get () { | |||
19 | 19 | ||
20 | gnunet-identity -D "test_plugin_rest_gns" > /dev/null 2>&1 | 20 | gnunet-identity -D "test_plugin_rest_gns" > /dev/null 2>&1 |
21 | 21 | ||
22 | curl_get "$gns_link?name=www.test_plugin_rest_gns" "error" | 22 | curl_get "$gns_link/www.test_plugin_rest_gns" "error" |
23 | 23 | ||
24 | gnunet-identity -C "test_plugin_rest_gns" | 24 | gnunet-identity -C "test_plugin_rest_gns" |
25 | 25 | ||
26 | curl_get "$gns_link?name=www.test_plugin_rest_gns" "\[\]" | 26 | curl_get "$gns_link/www.test_plugin_rest_gns" "\[\]" |
27 | 27 | ||
28 | gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1.1.1.1 -t A | 28 | gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1.1.1.1 -t A |
29 | 29 | ||
30 | curl_get "$gns_link?name=www.test_plugin_rest_gns" "1.1.1.1" | 30 | curl_get "$gns_link/www.test_plugin_rest_gns" "1.1.1.1" |
31 | 31 | ||
32 | gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1::1 -t AAAA | 32 | gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1::1 -t AAAA |
33 | 33 | ||
34 | curl_get "$gns_link?name=www.test_plugin_rest_gns" "1::1.*1.1.1.1" | 34 | curl_get "$gns_link/www.test_plugin_rest_gns" "1::1.*1.1.1.1" |
35 | 35 | ||
36 | gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1.1.1.2 -t A | 36 | gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1.1.1.2 -t A |
37 | 37 | ||
38 | curl_get "$gns_link?name=www.test_plugin_rest_gns" "1.1.1.2.*1::1.*1.1.1.1" | 38 | curl_get "$gns_link/www.test_plugin_rest_gns" "1.1.1.2.*1::1.*1.1.1.1" |
39 | curl_get "$gns_link?name=www.test_plugin_rest_gns&record_type=A" "1.1.1.2.*1.1.1.1" | 39 | curl_get "$gns_link/www.test_plugin_rest_gns?record_type=A" "1.1.1.2.*1.1.1.1" |
40 | curl_get "$gns_link?name=www.test_plugin_rest_gns&record_type=AAAA" "1::1" | 40 | curl_get "$gns_link/www.test_plugin_rest_gns?record_type=AAAA" "1::1" |
41 | curl_get "$gns_link?name=www.test_plugin_rest_gns&record_type=WRONG_TYPE" "1.1.1.2.*1::1.*1.1.1.1" | 41 | curl_get "$gns_link/www.test_plugin_rest_gns?record_type=WRONG_TYPE" "1.1.1.2.*1::1.*1.1.1.1" |
42 | 42 | ||
43 | gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www1 -e 1d -V 1.1.1.1 -t A | 43 | gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www1 -e 1d -V 1.1.1.1 -t A |
44 | curl_get "$gns_link?name=www1.test_plugin_rest_gns" "1.1.1.1" | 44 | curl_get "$gns_link/www1.test_plugin_rest_gns" "1.1.1.1" |
45 | 45 | ||
46 | gnunet-identity -D "test_plugin_rest_gns" | 46 | gnunet-identity -D "test_plugin_rest_gns" > /dev/null 2>&1 |
47 | 47 | ||
48 | curl_get "$gns_link?name=www1.test_plugin_rest_gns" "error" | 48 | curl_get "$gns_link/www1.test_plugin_rest_gns" "error" |
49 | 49 | ||
50 | exit 0 | 50 | exit 0 |
diff --git a/src/rest-plugins/test_plugin_rest_identity.sh b/src/rest-plugins/test_plugin_rest_identity.sh new file mode 100755 index 000000000..a5879dd7e --- /dev/null +++ b/src/rest-plugins/test_plugin_rest_identity.sh | |||
@@ -0,0 +1,157 @@ | |||
1 | #!/usr/bin/bash | ||
2 | |||
3 | #First, start gnunet-arm and the rest-service. | ||
4 | #Exit 0 means success, exit 1 means failed test | ||
5 | |||
6 | identity_link="http://localhost:7776/identity" | ||
7 | wrong_link="http://localhost:7776/identityandmore" | ||
8 | |||
9 | |||
10 | curl_get () { | ||
11 | #$1 is link | ||
12 | #$2 is grep | ||
13 | cache="$(curl -v "$1" 2>&1 | grep "$2")" | ||
14 | #echo $cache | ||
15 | if [ "" == "$cache" ] | ||
16 | then | ||
17 | exit 1 | ||
18 | fi | ||
19 | } | ||
20 | |||
21 | curl_post () { | ||
22 | #$1 is link | ||
23 | #$2 is data | ||
24 | #$3 is grep | ||
25 | cache="$(curl -v -X "POST" "$1" --data "$2" 2>&1 | grep "$3")" | ||
26 | #echo $cache | ||
27 | if [ "" == "$cache" ] | ||
28 | then | ||
29 | exit 1 | ||
30 | fi | ||
31 | } | ||
32 | |||
33 | curl_delete () { | ||
34 | #$1 is link | ||
35 | #$2 is grep | ||
36 | cache="$(curl -v -X "DELETE" "$1" 2>&1 | grep "$2")" | ||
37 | #echo $cache | ||
38 | if [ "" == "$cache" ] | ||
39 | then | ||
40 | exit 1 | ||
41 | fi | ||
42 | } | ||
43 | |||
44 | curl_put () { | ||
45 | #$1 is link | ||
46 | #$2 is data | ||
47 | #$3 is grep | ||
48 | cache="$(curl -v -X "PUT" "$1" --data "$2" 2>&1 | grep "$3")" | ||
49 | #echo $cache | ||
50 | if [ "" == "$cache" ] | ||
51 | then | ||
52 | exit 1 | ||
53 | fi | ||
54 | } | ||
55 | |||
56 | #Test GET | ||
57 | test="$(gnunet-identity -d)" | ||
58 | #if no identity exists | ||
59 | if [ "" == "$test" ] | ||
60 | then | ||
61 | curl_get "$identity_link/all" "error" | ||
62 | gnunet-identity -C "test_plugin_rest_identity" | ||
63 | name="$(gnunet-identity -d | awk 'NR==1{print $1}')" | ||
64 | public="$(gnunet-identity -d | awk 'NR==1{print $3}')" | ||
65 | |||
66 | curl_get "${identity_link}/name/$name" "$public" | ||
67 | curl_get "${identity_link}/name/$public" "error" | ||
68 | curl_get "${identity_link}/name/" "error" | ||
69 | |||
70 | curl_get "${identity_link}/pubkey/$public" "$name" | ||
71 | curl_get "${identity_link}/pubkey/$name" "error" | ||
72 | curl_get "${identity_link}/pubkey/" "error" | ||
73 | |||
74 | gnunet-identity -D "test_plugin_rest_identity" | ||
75 | else | ||
76 | name="$(gnunet-identity -d | awk 'NR==1{print $1}')" | ||
77 | public="$(gnunet-identity -d | awk 'NR==1{print $3}')" | ||
78 | |||
79 | curl_get "${identity_link}/name/$name" "$public" | ||
80 | curl_get "${identity_link}/name/$public" "error" | ||
81 | curl_get "${identity_link}/name/" "error" | ||
82 | |||
83 | curl_get "${identity_link}/pubkey/$public" "$name" | ||
84 | curl_get "${identity_link}/pubkey/$name" "error" | ||
85 | curl_get "${identity_link}/pubkey/" "error" | ||
86 | fi | ||
87 | |||
88 | #Test POST | ||
89 | gnunet-identity -D "test_plugin_rest_identity" > /dev/null 2>&1 | ||
90 | gnunet-identity -D "test_plugin_rest_identity1" > /dev/null 2>&1 | ||
91 | |||
92 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 201 Created" | ||
93 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 409" | ||
94 | curl_post "${identity_link}" '{"name":"Test_plugin_rest_identity"}' "HTTP/1.1 409" | ||
95 | curl_post "${identity_link}" '{}' "error" | ||
96 | curl_post "${identity_link}" '' "error" | ||
97 | curl_post "${identity_link}" '{"name":""}' "error" | ||
98 | curl_post "${identity_link}" '{"name":123}' "error" | ||
99 | curl_post "${identity_link}" '{"name":[]}' "error" | ||
100 | curl_post "${identity_link}" '{"name1":"test_plugin_rest_identity"}' "error" | ||
101 | curl_post "${identity_link}" '{"other":""}' "error" | ||
102 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1", "other":"test_plugin_rest_identity2"}' "error" | ||
103 | |||
104 | #Test PUT | ||
105 | name="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $1}')" | ||
106 | public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $3}')" | ||
107 | |||
108 | curl_put "${identity_link}/pubkey/$public" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 204" | ||
109 | curl_put "${identity_link}/pubkey/$public" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 409" | ||
110 | curl_put "${identity_link}/pubkey/${public}xx" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 404" | ||
111 | curl_put "${identity_link}/pubkey/" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 404" | ||
112 | curl_put "${identity_link}/pubke" '{"newname":"test_plugin_rest_identity1"}' "error" | ||
113 | curl_put "${identity_link}" '{"newname":"test_plugin_rest_identity1","other":"sdfdsf"}' "error" | ||
114 | curl_put "${identity_link}/pubkey/$name" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 404" | ||
115 | curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"newname":"test_plugin_rest_identity"}' "HTTP/1.1 204" | ||
116 | curl_put "${identity_link}/pubkey/$public" '{"newnam":"test_plugin_rest_identity"}' "error" | ||
117 | curl_put "${identity_link}/name/test_plugin_rest_identity" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 204" | ||
118 | curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"newname":"TEST_plugin_rest_identity1"}' "HTTP/1.1 409" | ||
119 | curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 409" | ||
120 | curl_put "${identity_link}/name/test_plugin_rest_identityxxx" '{"newname":"test_plugin_rest_identity"}' "HTTP/1.1 404" | ||
121 | curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"newname":"test_plugin_rest_identity"}' "HTTP/1.1 204" | ||
122 | curl_put "${identity_link}/name/test_plugin_rest_identity" '{"newnam":"test_plugin_rest_identityfail"}' "error" | ||
123 | |||
124 | #Test subsystem | ||
125 | curl_put "${identity_link}/subsystem/test_plugin_rest_identity" '{"subsystem":"namestore"}' "HTTP/1.1 204" | ||
126 | curl_put "${identity_link}/subsystem/test_plugin_rest_identity" '{"subsystem":"namestore"}' "HTTP/1.1 204" | ||
127 | curl_get "${identity_link}/subsystem/namestore" "test_plugin_rest_identity" | ||
128 | public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $3}')" | ||
129 | curl_put "${identity_link}/subsystem/$public" '{"subsystem":"namestore"}' "HTTP/1.1 404" | ||
130 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 201 Created" | ||
131 | curl_get "${identity_link}/subsystem/test_plugin_rest_identity_no_subsystem" "error" | ||
132 | curl_put "${identity_link}/subsystem/test_plugin_rest_identity1" '{"subsystem":"test_plugin_rest_identity_no_subsystem"}' "HTTP/1.1 204" | ||
133 | curl_get "${identity_link}/subsystem/test_plugin_rest_identity_no_subsystem" "test_plugin_rest_identity1" | ||
134 | |||
135 | curl_put "${identity_link}/subsystem/test_plugin_rest_identity1" '{"subsyste":"test_plugin_rest_identity_no_subsystem"}' "error" | ||
136 | curl_put "${identity_link}/subsystem/test_plugin_rest_identity1" '{"subsystem":"test_plugin_rest_identity_no_subsystem"}' "HTTP/1.1 204" | ||
137 | |||
138 | #Test DELETE | ||
139 | curl_delete "${identity_link}/name/test_plugin_rest_identity" "HTTP/1.1 204" | ||
140 | curl_get "${identity_link}/name/test_plugin_rest_identity" "error" | ||
141 | curl_delete "${identity_link}/name/TEST_plugin_rest_identity1" "HTTP/1.1 204" | ||
142 | curl_delete "${identity_link}/name/test_plugin_rest_identity1" "HTTP/1.1 404" | ||
143 | curl_get "${identity_link}/name/test_plugin_rest_identity1" "error" | ||
144 | curl_delete "${identity_link}/name/test_plugin_rest_identity_not_found" "HTTP/1.1 404" | ||
145 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 201 Created" | ||
146 | public="$(gnunet-identity -d | grep "test_plugin_rest_identity1" | awk 'NR==1{print $3}')" | ||
147 | curl_delete "${identity_link}/pubkey/$public" "HTTP/1.1 204" | ||
148 | curl_delete "${identity_link}/pubke/$public" "error" | ||
149 | curl_delete "${identity_link}/pubkey/${public}other=232" "HTTP/1.1 404" | ||
150 | |||
151 | #Test wrong_link | ||
152 | curl_get "$wrong_link" "HTTP/1.1 404" | ||
153 | curl_post "$wrong_link" '{"name":"test_plugin_rest_identity"}' "HTTP/1.1 404" | ||
154 | curl_put "$wrong_link/name/test_plugin_rest_identity" '{"newname":"test_plugin_rest_identity1"}' "HTTP/1.1 404" | ||
155 | curl_delete "$wrong_link/name/test_plugin_rest_identity1" "HTTP/1.1 404" | ||
156 | |||
157 | exit 0; | ||
diff --git a/src/rest-plugins/test_plugin_rest_namestore.sh b/src/rest-plugins/test_plugin_rest_namestore.sh new file mode 100755 index 000000000..532c7caae --- /dev/null +++ b/src/rest-plugins/test_plugin_rest_namestore.sh | |||
@@ -0,0 +1,147 @@ | |||
1 | #!/usr/bin/bash | ||
2 | |||
3 | #First, start gnunet-arm and the rest-service. | ||
4 | #Exit 0 means success, exit 1 means failed test | ||
5 | |||
6 | namestore_link="http://localhost:7776/namestore" | ||
7 | wrong_link="http://localhost:7776/namestoreandmore" | ||
8 | |||
9 | |||
10 | curl_get () { | ||
11 | #$1 is link | ||
12 | #$2 is grep | ||
13 | cache="$(curl -v "$1" 2>&1 | grep "$2")" | ||
14 | echo $cache | ||
15 | if [ "" == "$cache" ] | ||
16 | then | ||
17 | exit 1 | ||
18 | fi | ||
19 | } | ||
20 | |||
21 | curl_post () { | ||
22 | #$1 is link | ||
23 | #$2 is data | ||
24 | #$3 is grep | ||
25 | cache="$(curl -v -X "POST" "$1" --data "$2" 2>&1 | grep "$3")" | ||
26 | echo $cache | ||
27 | if [ "" == "$cache" ] | ||
28 | then | ||
29 | exit 1 | ||
30 | fi | ||
31 | } | ||
32 | |||
33 | curl_delete () { | ||
34 | #$1 is link | ||
35 | #$2 is grep | ||
36 | cache="$(curl -v -X "DELETE" "$1" 2>&1 | grep "$2")" | ||
37 | echo $cache | ||
38 | if [ "" == "$cache" ] | ||
39 | then | ||
40 | exit 1 | ||
41 | fi | ||
42 | } | ||
43 | |||
44 | # curl_put () { | ||
45 | # #$1 is link | ||
46 | # #$2 is data | ||
47 | # #$3 is grep | ||
48 | # cache="$(curl -v -X "PUT" "$1" --data "$2" 2>&1 | grep "$3")" | ||
49 | # #echo $cache | ||
50 | # if [ "" == "$cache" ] | ||
51 | # then | ||
52 | # exit 1 | ||
53 | # fi | ||
54 | # } | ||
55 | |||
56 | #Test subsystem default identity | ||
57 | |||
58 | #Test GET | ||
59 | gnunet-identity -D "test_plugin_rest_namestore" | ||
60 | gnunet-identity -C "test_plugin_rest_namestore" | ||
61 | test="$(gnunet-namestore -D -z "test_plugin_rest_namestore")" | ||
62 | name="test_plugin_rest_namestore" | ||
63 | public="$(gnunet-identity -d | grep "test_plugin_rest_namestore" | awk 'NR==1{print $3}')" | ||
64 | if [ "" == "$test" ] | ||
65 | then | ||
66 | #if no entries for test_plugin_rest_namestore | ||
67 | curl_get "${namestore_link}/$name" "error" | ||
68 | curl_get "${namestore_link}/" "error" | ||
69 | curl_get "${namestore_link}/$public" "error" | ||
70 | else | ||
71 | #if entries exists (that should not be possible) | ||
72 | curl_get "${namestore_link}" "HTTP/1.1 200 OK" | ||
73 | curl_get "${namestore_link}/$name" "HTTP/1.1 200 OK" | ||
74 | curl_get "${namestore_link}/" "error" | ||
75 | curl_get "${namestore_link}/$public" "error" | ||
76 | fi | ||
77 | gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" | ||
78 | curl_get "${namestore_link}" "HTTP/1.1 200 OK" | ||
79 | curl_get "${namestore_link}/$name" "HTTP/1.1 200 OK" | ||
80 | curl_get "${namestore_link}/" "error" | ||
81 | curl_get "${namestore_link}/$public" "error" | ||
82 | gnunet-namestore -z $name -d -n "test_entry" | ||
83 | |||
84 | #Test POST with NAME | ||
85 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" | ||
86 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
87 | #value | ||
88 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error" | ||
89 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
90 | curl_post "${namestore_link}/$name" '{"value":"", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error" | ||
91 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
92 | curl_post "${namestore_link}/$name" '{"value_missing":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRGxxx", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error" | ||
93 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
94 | #time | ||
95 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"0d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204" | ||
96 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
97 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"10000d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204" | ||
98 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
99 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"now","flag":0,"record_name":"test_entry"}' "error" | ||
100 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
101 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"","flag":0,"record_name":"test_entry"}' "error" | ||
102 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
103 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time_missing":"1d","flag":0,"record_name":"test_entry"}' "error" | ||
104 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
105 | #flag | ||
106 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" | ||
107 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
108 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":2,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" | ||
109 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
110 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":8,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" | ||
111 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
112 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":16,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" | ||
113 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
114 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":-1,"record_name":"test_entry"}' "error" | ||
115 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
116 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":"Test","record_name":"test_entry"}' "error" | ||
117 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
118 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":,"record_name":"test_entry"}' "error" | ||
119 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
120 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag_missing":0,"record_name":"test_entry"}' "error" | ||
121 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
122 | #record_name | ||
123 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" | ||
124 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "HTTP/1.1 204 No Content" | ||
125 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
126 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":""}' "error" | ||
127 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
128 | curl_post "${namestore_link}/$name" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name_missing":"test_entry"}' "error" | ||
129 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
130 | |||
131 | #wrong zone | ||
132 | curl_post "${namestore_link}/$public" '{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","flag":0,"record_name":"test_entry"}' "error" | ||
133 | gnunet-namestore -z $name -d -n "test_entry" > /dev/null 2>&1 | ||
134 | |||
135 | #Test DELETE | ||
136 | gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" | ||
137 | curl_delete "${namestore_link}/$name?record_name=test_entry" "HTTP/1.1 204" | ||
138 | curl_delete "${namestore_link}/$name?record_name=test_entry" "error" | ||
139 | gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" | ||
140 | curl_delete "${namestore_link}/$public?record_name=test_entry" "error" | ||
141 | |||
142 | |||
143 | #Test default identity | ||
144 | #not possible without defining | ||
145 | |||
146 | exit 0; | ||
147 | |||
diff --git a/src/rest/Makefile.am b/src/rest/Makefile.am index f87335152..6c23ad2a6 100644 --- a/src/rest/Makefile.am +++ b/src/rest/Makefile.am | |||
@@ -10,7 +10,6 @@ libexecdir= $(pkglibdir)/libexec/ | |||
10 | pkgcfg_DATA = \ | 10 | pkgcfg_DATA = \ |
11 | rest.conf | 11 | rest.conf |
12 | 12 | ||
13 | |||
14 | if MINGW | 13 | if MINGW |
15 | WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols | 14 | WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols |
16 | endif | 15 | endif |
@@ -29,18 +28,6 @@ libexec_PROGRAMS = \ | |||
29 | EXTRA_DIST = \ | 28 | EXTRA_DIST = \ |
30 | rest.conf | 29 | rest.conf |
31 | 30 | ||
32 | plugin_LTLIBRARIES = libgnunet_plugin_rest_copying.la | ||
33 | |||
34 | libgnunet_plugin_rest_copying_la_SOURCES = \ | ||
35 | plugin_rest_copying.c | ||
36 | libgnunet_plugin_rest_copying_la_LIBADD = \ | ||
37 | libgnunetrest.la \ | ||
38 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
39 | $(LTLIBINTL) -lmicrohttpd | ||
40 | libgnunet_plugin_rest_copying_la_LDFLAGS = \ | ||
41 | $(GN_PLUGIN_LDFLAGS) | ||
42 | |||
43 | |||
44 | gnunet_rest_server_SOURCES = \ | 31 | gnunet_rest_server_SOURCES = \ |
45 | gnunet-rest-server.c | 32 | gnunet-rest-server.c |
46 | 33 | ||
diff --git a/src/rps/gnunet-rps-profiler.c b/src/rps/gnunet-rps-profiler.c index 49714872f..277688b56 100644 --- a/src/rps/gnunet-rps-profiler.c +++ b/src/rps/gnunet-rps-profiler.c | |||
@@ -2311,14 +2311,14 @@ void write_final_stats (void){ | |||
2311 | 2311 | ||
2312 | for (uint32_t i = 0; i < num_peers; i++) | 2312 | for (uint32_t i = 0; i < num_peers; i++) |
2313 | { | 2313 | { |
2314 | to_file ("/tmp/rps/final_stats.dat", | 2314 | to_file ("/tmp/rps/final_stats.csv", |
2315 | "%" PRIu32 " " /* index */ | 2315 | ", %" PRIu32 ", " /* index */ |
2316 | "%s %" /* id */ | 2316 | "%s, %" /* id */ |
2317 | PRIu64 " %" /* rounds */ | 2317 | PRIu64 ", %" /* rounds */ |
2318 | PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" /* blocking */ | 2318 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* blocking */ |
2319 | PRIu64 " %" PRIu64 " %" PRIu64 " %" /* issued */ | 2319 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */ |
2320 | PRIu64 " %" PRIu64 " %" PRIu64 " %" /* sent */ | 2320 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */ |
2321 | PRIu64 " %" PRIu64 " %" PRIu64 /* recv */, | 2321 | PRIu64 ", %" PRIu64 ", %" PRIu64 /* recv */, |
2322 | i, | 2322 | i, |
2323 | GNUNET_i2s (rps_peers[i].peer_id), | 2323 | GNUNET_i2s (rps_peers[i].peer_id), |
2324 | rps_peers[i].stats[STAT_TYPE_ROUNDS], | 2324 | rps_peers[i].stats[STAT_TYPE_ROUNDS], |
@@ -2407,10 +2407,10 @@ post_test_shutdown_ready_cb (void *cls, | |||
2407 | GNUNET_TESTBED_operation_done (rps_peer->stat_op); | 2407 | GNUNET_TESTBED_operation_done (rps_peer->stat_op); |
2408 | } | 2408 | } |
2409 | 2409 | ||
2410 | write_final_stats (); | 2410 | //write_final_stats (); |
2411 | if (GNUNET_YES == check_statistics_collect_completed()) | 2411 | if (GNUNET_YES == check_statistics_collect_completed()) |
2412 | { | 2412 | { |
2413 | //write_final_stats (); | 2413 | write_final_stats (); |
2414 | GNUNET_free (stat_cls); | 2414 | GNUNET_free (stat_cls); |
2415 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2415 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2416 | "Shutting down\n"); | 2416 | "Shutting down\n"); |
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 6b0ecc58c..1f155b14f 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -84,7 +84,7 @@ static struct GNUNET_HashCode port; | |||
84 | /** | 84 | /** |
85 | * Set a peer flag of given peer context. | 85 | * Set a peer flag of given peer context. |
86 | */ | 86 | */ |
87 | #define set_peer_flag(peer_ctx, mask) ((peer_ctx->peer_flags) |= (mask)) | 87 | #define SET_PEER_FLAG(peer_ctx, mask) ((peer_ctx->peer_flags) |= (mask)) |
88 | 88 | ||
89 | /** | 89 | /** |
90 | * Get peer flag of given peer context. | 90 | * Get peer flag of given peer context. |
@@ -95,7 +95,7 @@ static struct GNUNET_HashCode port; | |||
95 | /** | 95 | /** |
96 | * Unset flag of given peer context. | 96 | * Unset flag of given peer context. |
97 | */ | 97 | */ |
98 | #define unset_peer_flag(peer_ctx, mask) ((peer_ctx->peer_flags) &= ~(mask)) | 98 | #define UNSET_PEER_FLAG(peer_ctx, mask) ((peer_ctx->peer_flags) &= ~(mask)) |
99 | 99 | ||
100 | /** | 100 | /** |
101 | * Get channel flag of given channel context. | 101 | * Get channel flag of given channel context. |
@@ -233,11 +233,6 @@ struct PeerContext | |||
233 | struct PendingMessage *pending_messages_tail; | 233 | struct PendingMessage *pending_messages_tail; |
234 | 234 | ||
235 | /** | 235 | /** |
236 | * @brief Task to destroy this context. | ||
237 | */ | ||
238 | struct GNUNET_SCHEDULER_Task *destruction_task; | ||
239 | |||
240 | /** | ||
241 | * This is pobably followed by 'statistical' data (when we first saw | 236 | * This is pobably followed by 'statistical' data (when we first saw |
242 | * it, how did we get its ID, how many pushes (in a timeinterval), | 237 | * it, how did we get its ID, how many pushes (in a timeinterval), |
243 | * ...) | 238 | * ...) |
@@ -282,7 +277,9 @@ struct ChannelCtx | |||
282 | struct PeerContext *peer_ctx; | 277 | struct PeerContext *peer_ctx; |
283 | 278 | ||
284 | /** | 279 | /** |
285 | * @brief Scheduled task that will destroy this context | 280 | * @brief When channel destruction needs to be delayed (because it is called |
281 | * from within the cadet routine of another channel destruction) this task | ||
282 | * refers to the respective _SCHEDULER_Task. | ||
286 | */ | 283 | */ |
287 | struct GNUNET_SCHEDULER_Task *destruction_task; | 284 | struct GNUNET_SCHEDULER_Task *destruction_task; |
288 | }; | 285 | }; |
@@ -314,7 +311,6 @@ static struct GNUNET_CONTAINER_MultiPeerMap *peer_map; | |||
314 | static struct GNUNET_CADET_Handle *cadet_handle; | 311 | static struct GNUNET_CADET_Handle *cadet_handle; |
315 | 312 | ||
316 | 313 | ||
317 | |||
318 | /** | 314 | /** |
319 | * @brief Get the #PeerContext associated with a peer | 315 | * @brief Get the #PeerContext associated with a peer |
320 | * | 316 | * |
@@ -335,8 +331,28 @@ get_peer_ctx (const struct GNUNET_PeerIdentity *peer) | |||
335 | return ctx; | 331 | return ctx; |
336 | } | 332 | } |
337 | 333 | ||
338 | int | 334 | /** |
339 | Peers_check_peer_known (const struct GNUNET_PeerIdentity *peer); | 335 | * @brief Check whether we have information about the given peer. |
336 | * | ||
337 | * FIXME probably deprecated. Make this the new _online. | ||
338 | * | ||
339 | * @param peer peer in question | ||
340 | * | ||
341 | * @return #GNUNET_YES if peer is known | ||
342 | * #GNUNET_NO if peer is not knwon | ||
343 | */ | ||
344 | static int | ||
345 | check_peer_known (const struct GNUNET_PeerIdentity *peer) | ||
346 | { | ||
347 | if (NULL != peer_map) | ||
348 | { | ||
349 | return GNUNET_CONTAINER_multipeermap_contains (peer_map, peer); | ||
350 | } else | ||
351 | { | ||
352 | return GNUNET_NO; | ||
353 | } | ||
354 | } | ||
355 | |||
340 | 356 | ||
341 | /** | 357 | /** |
342 | * @brief Create a new #PeerContext and insert it into the peer map | 358 | * @brief Create a new #PeerContext and insert it into the peer map |
@@ -351,7 +367,7 @@ create_peer_ctx (const struct GNUNET_PeerIdentity *peer) | |||
351 | struct PeerContext *ctx; | 367 | struct PeerContext *ctx; |
352 | int ret; | 368 | int ret; |
353 | 369 | ||
354 | GNUNET_assert (GNUNET_NO == Peers_check_peer_known (peer)); | 370 | GNUNET_assert (GNUNET_NO == check_peer_known (peer)); |
355 | 371 | ||
356 | ctx = GNUNET_new (struct PeerContext); | 372 | ctx = GNUNET_new (struct PeerContext); |
357 | ctx->peer_id = *peer; | 373 | ctx->peer_id = *peer; |
@@ -372,18 +388,13 @@ create_peer_ctx (const struct GNUNET_PeerIdentity *peer) | |||
372 | static struct PeerContext * | 388 | static struct PeerContext * |
373 | create_or_get_peer_ctx (const struct GNUNET_PeerIdentity *peer) | 389 | create_or_get_peer_ctx (const struct GNUNET_PeerIdentity *peer) |
374 | { | 390 | { |
375 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 391 | if (GNUNET_NO == check_peer_known (peer)) |
376 | { | 392 | { |
377 | return create_peer_ctx (peer); | 393 | return create_peer_ctx (peer); |
378 | } | 394 | } |
379 | return get_peer_ctx (peer); | 395 | return get_peer_ctx (peer); |
380 | } | 396 | } |
381 | 397 | ||
382 | void | ||
383 | Peers_unset_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags); | ||
384 | |||
385 | void | ||
386 | Peers_set_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags); | ||
387 | 398 | ||
388 | /** | 399 | /** |
389 | * @brief Check whether we have a connection to this @a peer | 400 | * @brief Check whether we have a connection to this @a peer |
@@ -395,13 +406,13 @@ Peers_set_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlag | |||
395 | * @return #GNUNET_YES if we are connected | 406 | * @return #GNUNET_YES if we are connected |
396 | * #GNUNET_NO otherwise | 407 | * #GNUNET_NO otherwise |
397 | */ | 408 | */ |
398 | int | 409 | static int |
399 | Peers_check_connected (const struct GNUNET_PeerIdentity *peer) | 410 | check_connected (const struct GNUNET_PeerIdentity *peer) |
400 | { | 411 | { |
401 | const struct PeerContext *peer_ctx; | 412 | struct PeerContext *peer_ctx; |
402 | 413 | ||
403 | /* If we don't know about this peer we don't know whether it's online */ | 414 | /* If we don't know about this peer we don't know whether it's online */ |
404 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 415 | if (GNUNET_NO == check_peer_known (peer)) |
405 | { | 416 | { |
406 | return GNUNET_NO; | 417 | return GNUNET_NO; |
407 | } | 418 | } |
@@ -411,11 +422,11 @@ Peers_check_connected (const struct GNUNET_PeerIdentity *peer) | |||
411 | if ( (NULL == peer_ctx->send_channel_ctx) && | 422 | if ( (NULL == peer_ctx->send_channel_ctx) && |
412 | (NULL == peer_ctx->recv_channel_ctx) ) | 423 | (NULL == peer_ctx->recv_channel_ctx) ) |
413 | { | 424 | { |
414 | Peers_unset_peer_flag (peer, Peers_ONLINE); | 425 | UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE); |
415 | return GNUNET_NO; | 426 | return GNUNET_NO; |
416 | } | 427 | } |
417 | /* Otherwise (if we have a channel, we know that it's online */ | 428 | /* Otherwise (if we have a channel, we know that it's online */ |
418 | Peers_set_peer_flag (peer, Peers_ONLINE); | 429 | SET_PEER_FLAG (peer_ctx, Peers_ONLINE); |
419 | return GNUNET_YES; | 430 | return GNUNET_YES; |
420 | } | 431 | } |
421 | 432 | ||
@@ -559,7 +570,7 @@ set_peer_live (struct PeerContext *peer_ctx) | |||
559 | } | 570 | } |
560 | 571 | ||
561 | (void) add_valid_peer (peer); | 572 | (void) add_valid_peer (peer); |
562 | set_peer_flag (peer_ctx, Peers_ONLINE); | 573 | SET_PEER_FLAG (peer_ctx, Peers_ONLINE); |
563 | 574 | ||
564 | /* Call pending operations */ | 575 | /* Call pending operations */ |
565 | for (i = 0; i < peer_ctx->num_pending_ops; i++) | 576 | for (i = 0; i < peer_ctx->num_pending_ops; i++) |
@@ -604,15 +615,37 @@ handle_peer_pull_reply (void *cls, | |||
604 | * @return The channel context | 615 | * @return The channel context |
605 | */ | 616 | */ |
606 | static struct ChannelCtx * | 617 | static struct ChannelCtx * |
607 | add_channel_ctx (struct PeerContext *peer_ctx); | 618 | add_channel_ctx (struct PeerContext *peer_ctx) |
619 | { | ||
620 | struct ChannelCtx *channel_ctx; | ||
621 | channel_ctx = GNUNET_new (struct ChannelCtx); | ||
622 | channel_ctx->peer_ctx = peer_ctx; | ||
623 | return channel_ctx; | ||
624 | } | ||
625 | |||
608 | 626 | ||
609 | /** | 627 | /** |
610 | * @brief Remove the channel context from the DLL and free the memory. | 628 | * @brief Free memory and NULL pointers. |
611 | * | 629 | * |
612 | * @param channel_ctx The channel context. | 630 | * @param channel_ctx The channel context. |
613 | */ | 631 | */ |
614 | static void | 632 | static void |
615 | remove_channel_ctx (struct ChannelCtx *channel_ctx); | 633 | remove_channel_ctx (struct ChannelCtx *channel_ctx) |
634 | { | ||
635 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; | ||
636 | |||
637 | if (channel_ctx == peer_ctx->send_channel_ctx) | ||
638 | { | ||
639 | GNUNET_free (channel_ctx); | ||
640 | peer_ctx->send_channel_ctx = NULL; | ||
641 | peer_ctx->mq = NULL; | ||
642 | } | ||
643 | else if (channel_ctx == peer_ctx->recv_channel_ctx) | ||
644 | { | ||
645 | GNUNET_free (channel_ctx); | ||
646 | peer_ctx->recv_channel_ctx = NULL; | ||
647 | } | ||
648 | } | ||
616 | 649 | ||
617 | 650 | ||
618 | /** | 651 | /** |
@@ -664,7 +697,7 @@ get_channel (const struct GNUNET_PeerIdentity *peer) | |||
664 | &port, | 697 | &port, |
665 | GNUNET_CADET_OPTION_RELIABLE, | 698 | GNUNET_CADET_OPTION_RELIABLE, |
666 | NULL, /* WindowSize handler */ | 699 | NULL, /* WindowSize handler */ |
667 | cleanup_destroyed_channel, /* Disconnect handler */ | 700 | &cleanup_destroyed_channel, /* Disconnect handler */ |
668 | cadet_handlers); | 701 | cadet_handlers); |
669 | } | 702 | } |
670 | GNUNET_assert (NULL != peer_ctx->send_channel_ctx); | 703 | GNUNET_assert (NULL != peer_ctx->send_channel_ctx); |
@@ -823,8 +856,155 @@ check_operation_scheduled (const struct GNUNET_PeerIdentity *peer, | |||
823 | return GNUNET_NO; | 856 | return GNUNET_NO; |
824 | } | 857 | } |
825 | 858 | ||
859 | |||
860 | /** | ||
861 | * @brief Callback for scheduler to destroy a channel | ||
862 | * | ||
863 | * @param cls Context of the channel | ||
864 | */ | ||
865 | static void | ||
866 | destroy_channel (struct ChannelCtx *channel_ctx) | ||
867 | { | ||
868 | struct GNUNET_CADET_Channel *channel; | ||
869 | |||
870 | if (NULL != channel_ctx->destruction_task) | ||
871 | { | ||
872 | GNUNET_SCHEDULER_cancel (channel_ctx->destruction_task); | ||
873 | channel_ctx->destruction_task = NULL; | ||
874 | } | ||
875 | GNUNET_assert (channel_ctx->channel != NULL); | ||
876 | channel = channel_ctx->channel; | ||
877 | channel_ctx->channel = NULL; | ||
878 | GNUNET_CADET_channel_destroy (channel); | ||
879 | remove_channel_ctx (channel_ctx); | ||
880 | } | ||
881 | |||
882 | |||
883 | /** | ||
884 | * @brief Destroy a cadet channel. | ||
885 | * | ||
886 | * This satisfies the function signature of #GNUNET_SCHEDULER_TaskCallback. | ||
887 | * | ||
888 | * @param cls | ||
889 | */ | ||
890 | static void | ||
891 | destroy_channel_cb (void *cls) | ||
892 | { | ||
893 | struct ChannelCtx *channel_ctx = cls; | ||
894 | |||
895 | channel_ctx->destruction_task = NULL; | ||
896 | destroy_channel (channel_ctx); | ||
897 | } | ||
898 | |||
899 | |||
900 | /** | ||
901 | * @brief Schedule the destruction of a channel for immediately afterwards. | ||
902 | * | ||
903 | * In case a channel is to be destroyed from within the callback to the | ||
904 | * destruction of another channel (send channel), we cannot call | ||
905 | * GNUNET_CADET_channel_destroy directly, but need to use this scheduling | ||
906 | * construction. | ||
907 | * | ||
908 | * @param channel_ctx channel to be destroyed. | ||
909 | */ | ||
910 | static void | ||
911 | schedule_channel_destruction (struct ChannelCtx *channel_ctx) | ||
912 | { | ||
913 | GNUNET_assert (NULL == | ||
914 | channel_ctx->destruction_task); | ||
915 | GNUNET_assert (NULL != | ||
916 | channel_ctx->channel); | ||
917 | channel_ctx->destruction_task = | ||
918 | GNUNET_SCHEDULER_add_now (&destroy_channel_cb, | ||
919 | channel_ctx); | ||
920 | } | ||
921 | |||
922 | |||
923 | /** | ||
924 | * @brief Remove peer | ||
925 | * | ||
926 | * @param peer the peer to clean | ||
927 | * @return #GNUNET_YES if peer was removed | ||
928 | * #GNUNET_NO otherwise | ||
929 | */ | ||
826 | static int | 930 | static int |
827 | Peers_remove_peer (const struct GNUNET_PeerIdentity *peer); | 931 | destroy_peer (struct PeerContext *peer_ctx) |
932 | { | ||
933 | GNUNET_assert (NULL != peer_ctx); | ||
934 | GNUNET_assert (NULL != peer_map); | ||
935 | if (GNUNET_NO == | ||
936 | GNUNET_CONTAINER_multipeermap_contains (peer_map, | ||
937 | &peer_ctx->peer_id)) | ||
938 | { | ||
939 | return GNUNET_NO; | ||
940 | } | ||
941 | SET_PEER_FLAG (peer_ctx, Peers_TO_DESTROY); | ||
942 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
943 | "Going to remove peer %s\n", | ||
944 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
945 | UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE); | ||
946 | |||
947 | /* Clear list of pending operations */ | ||
948 | // TODO this probably leaks memory | ||
949 | // ('only' the cls to the function. Not sure what to do with it) | ||
950 | GNUNET_array_grow (peer_ctx->pending_ops, | ||
951 | peer_ctx->num_pending_ops, | ||
952 | 0); | ||
953 | /* Remove all pending messages */ | ||
954 | while (NULL != peer_ctx->pending_messages_head) | ||
955 | { | ||
956 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
957 | "Removing unsent %s\n", | ||
958 | peer_ctx->pending_messages_head->type); | ||
959 | /* Cancle pending message, too */ | ||
960 | if ( (NULL != peer_ctx->liveliness_check_pending) && | ||
961 | (0 == memcmp (peer_ctx->pending_messages_head, | ||
962 | peer_ctx->liveliness_check_pending, | ||
963 | sizeof (struct PendingMessage))) ) | ||
964 | { | ||
965 | // TODO this may leak memory | ||
966 | peer_ctx->liveliness_check_pending = NULL; | ||
967 | } | ||
968 | remove_pending_message (peer_ctx->pending_messages_head, | ||
969 | GNUNET_YES); | ||
970 | } | ||
971 | |||
972 | /* If we are still waiting for notification whether this peer is live | ||
973 | * cancel the according task */ | ||
974 | if (NULL != peer_ctx->liveliness_check_pending) | ||
975 | { | ||
976 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
977 | "Removing pending liveliness check for peer %s\n", | ||
978 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
979 | // TODO wait until cadet sets mq->cancel_impl | ||
980 | //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev); | ||
981 | remove_pending_message (peer_ctx->liveliness_check_pending, | ||
982 | GNUNET_YES); | ||
983 | peer_ctx->liveliness_check_pending = NULL; | ||
984 | } | ||
985 | |||
986 | if (NULL != peer_ctx->send_channel_ctx) | ||
987 | { | ||
988 | /* This is possibly called from within channel destruction */ | ||
989 | schedule_channel_destruction (peer_ctx->send_channel_ctx); | ||
990 | } | ||
991 | if (NULL != peer_ctx->recv_channel_ctx) | ||
992 | { | ||
993 | /* This is possibly called from within channel destruction */ | ||
994 | schedule_channel_destruction (peer_ctx->recv_channel_ctx); | ||
995 | } | ||
996 | |||
997 | if (GNUNET_YES != | ||
998 | GNUNET_CONTAINER_multipeermap_remove_all (peer_map, | ||
999 | &peer_ctx->peer_id)) | ||
1000 | { | ||
1001 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1002 | "removing peer from peer_map failed\n"); | ||
1003 | } | ||
1004 | GNUNET_free (peer_ctx); | ||
1005 | return GNUNET_YES; | ||
1006 | } | ||
1007 | |||
828 | 1008 | ||
829 | /** | 1009 | /** |
830 | * Iterator over hash map entries. Deletes all contexts of peers. | 1010 | * Iterator over hash map entries. Deletes all contexts of peers. |
@@ -840,7 +1020,7 @@ peermap_clear_iterator (void *cls, | |||
840 | const struct GNUNET_PeerIdentity *key, | 1020 | const struct GNUNET_PeerIdentity *key, |
841 | void *value) | 1021 | void *value) |
842 | { | 1022 | { |
843 | Peers_remove_peer (key); | 1023 | destroy_peer (get_peer_ctx (key)); |
844 | return GNUNET_YES; | 1024 | return GNUNET_YES; |
845 | } | 1025 | } |
846 | 1026 | ||
@@ -1084,8 +1264,8 @@ restore_valid_peers () | |||
1084 | * @param cadet_h cadet handle | 1264 | * @param cadet_h cadet handle |
1085 | * @param own_id own peer identity | 1265 | * @param own_id own peer identity |
1086 | */ | 1266 | */ |
1087 | void | 1267 | static void |
1088 | Peers_initialise (char* fn_valid_peers, | 1268 | initialise_peers (char* fn_valid_peers, |
1089 | struct GNUNET_CADET_Handle *cadet_h) | 1269 | struct GNUNET_CADET_Handle *cadet_h) |
1090 | { | 1270 | { |
1091 | filename_valid_peers = GNUNET_strdup (fn_valid_peers); | 1271 | filename_valid_peers = GNUNET_strdup (fn_valid_peers); |
@@ -1097,7 +1277,7 @@ Peers_initialise (char* fn_valid_peers, | |||
1097 | 1277 | ||
1098 | 1278 | ||
1099 | /** | 1279 | /** |
1100 | * @brief Delete storage of peers that was created with #Peers_initialise () | 1280 | * @brief Delete storage of peers that was created with #initialise_peers () |
1101 | */ | 1281 | */ |
1102 | static void | 1282 | static void |
1103 | peers_terminate () | 1283 | peers_terminate () |
@@ -1150,9 +1330,9 @@ valid_peer_iterator (void *cls, | |||
1150 | * @return the number of key value pairs processed, | 1330 | * @return the number of key value pairs processed, |
1151 | * #GNUNET_SYSERR if it aborted iteration | 1331 | * #GNUNET_SYSERR if it aborted iteration |
1152 | */ | 1332 | */ |
1153 | int | 1333 | static int |
1154 | Peers_get_valid_peers (PeersIterator iterator, | 1334 | get_valid_peers (PeersIterator iterator, |
1155 | void *it_cls) | 1335 | void *it_cls) |
1156 | { | 1336 | { |
1157 | struct PeersIteratorCls *cls; | 1337 | struct PeersIteratorCls *cls; |
1158 | int ret; | 1338 | int ret; |
@@ -1179,10 +1359,10 @@ Peers_get_valid_peers (PeersIterator iterator, | |||
1179 | * @return #GNUNET_YES if peer was inserted | 1359 | * @return #GNUNET_YES if peer was inserted |
1180 | * #GNUNET_NO otherwise | 1360 | * #GNUNET_NO otherwise |
1181 | */ | 1361 | */ |
1182 | int | 1362 | static int |
1183 | Peers_insert_peer (const struct GNUNET_PeerIdentity *peer) | 1363 | insert_peer (const struct GNUNET_PeerIdentity *peer) |
1184 | { | 1364 | { |
1185 | if (GNUNET_YES == Peers_check_peer_known (peer)) | 1365 | if (GNUNET_YES == check_peer_known (peer)) |
1186 | { | 1366 | { |
1187 | return GNUNET_NO; /* We already know this peer - nothing to do */ | 1367 | return GNUNET_NO; /* We already know this peer - nothing to do */ |
1188 | } | 1368 | } |
@@ -1190,8 +1370,30 @@ Peers_insert_peer (const struct GNUNET_PeerIdentity *peer) | |||
1190 | return GNUNET_YES; | 1370 | return GNUNET_YES; |
1191 | } | 1371 | } |
1192 | 1372 | ||
1193 | int | 1373 | |
1194 | Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags); | 1374 | /** |
1375 | * @brief Check whether flags on a peer are set. | ||
1376 | * | ||
1377 | * @param peer the peer to check the flag of | ||
1378 | * @param flags the flags to check | ||
1379 | * | ||
1380 | * @return #GNUNET_SYSERR if peer is not known | ||
1381 | * #GNUNET_YES if all given flags are set | ||
1382 | * #GNUNET_NO otherwise | ||
1383 | */ | ||
1384 | static int | ||
1385 | check_peer_flag (const struct GNUNET_PeerIdentity *peer, | ||
1386 | enum Peers_PeerFlags flags) | ||
1387 | { | ||
1388 | struct PeerContext *peer_ctx; | ||
1389 | |||
1390 | if (GNUNET_NO == check_peer_known (peer)) | ||
1391 | { | ||
1392 | return GNUNET_SYSERR; | ||
1393 | } | ||
1394 | peer_ctx = get_peer_ctx (peer); | ||
1395 | return check_peer_flag_set (peer_ctx, flags); | ||
1396 | } | ||
1195 | 1397 | ||
1196 | /** | 1398 | /** |
1197 | * @brief Try connecting to a peer to see whether it is online | 1399 | * @brief Try connecting to a peer to see whether it is online |
@@ -1202,15 +1404,15 @@ Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFl | |||
1202 | * @return #GNUNET_YES if peer had to be inserted | 1404 | * @return #GNUNET_YES if peer had to be inserted |
1203 | * #GNUNET_NO otherwise | 1405 | * #GNUNET_NO otherwise |
1204 | */ | 1406 | */ |
1205 | int | 1407 | static int |
1206 | Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer) | 1408 | issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer) |
1207 | { | 1409 | { |
1208 | struct PeerContext *peer_ctx; | 1410 | struct PeerContext *peer_ctx; |
1209 | int ret; | 1411 | int ret; |
1210 | 1412 | ||
1211 | ret = Peers_insert_peer (peer); | 1413 | ret = insert_peer (peer); |
1212 | peer_ctx = get_peer_ctx (peer); | 1414 | peer_ctx = get_peer_ctx (peer); |
1213 | if ( (GNUNET_NO == Peers_check_peer_flag (peer, Peers_ONLINE)) && | 1415 | if ( (GNUNET_NO == check_peer_flag (peer, Peers_ONLINE)) && |
1214 | (NULL == peer_ctx->liveliness_check_pending) ) | 1416 | (NULL == peer_ctx->liveliness_check_pending) ) |
1215 | { | 1417 | { |
1216 | check_peer_live (peer_ctx); | 1418 | check_peer_live (peer_ctx); |
@@ -1232,8 +1434,8 @@ Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer) | |||
1232 | * #GNUNET_NO if peer is NOT removable | 1434 | * #GNUNET_NO if peer is NOT removable |
1233 | * #GNUNET_SYSERR if peer is not known | 1435 | * #GNUNET_SYSERR if peer is not known |
1234 | */ | 1436 | */ |
1235 | int | 1437 | static int |
1236 | Peers_check_removable (const struct GNUNET_PeerIdentity *peer) | 1438 | check_removable (const struct GNUNET_PeerIdentity *peer) |
1237 | { | 1439 | { |
1238 | struct PeerContext *peer_ctx; | 1440 | struct PeerContext *peer_ctx; |
1239 | 1441 | ||
@@ -1252,262 +1454,6 @@ Peers_check_removable (const struct GNUNET_PeerIdentity *peer) | |||
1252 | return GNUNET_YES; | 1454 | return GNUNET_YES; |
1253 | } | 1455 | } |
1254 | 1456 | ||
1255 | uint32_t * | ||
1256 | Peers_get_channel_flag (const struct GNUNET_PeerIdentity *peer, | ||
1257 | enum Peers_ChannelRole role); | ||
1258 | |||
1259 | int | ||
1260 | Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags); | ||
1261 | |||
1262 | /** | ||
1263 | * @brief Callback for the scheduler to destroy the knowledge of a peer. | ||
1264 | * | ||
1265 | * @param cls Context of the peer | ||
1266 | */ | ||
1267 | static void | ||
1268 | destroy_peer (void *cls) | ||
1269 | { | ||
1270 | struct PeerContext *peer_ctx = cls; | ||
1271 | |||
1272 | GNUNET_assert (NULL != peer_ctx); | ||
1273 | peer_ctx->destruction_task = NULL; | ||
1274 | Peers_remove_peer (&peer_ctx->peer_id); | ||
1275 | } | ||
1276 | |||
1277 | |||
1278 | static void | ||
1279 | destroy_channel (void *cls); | ||
1280 | |||
1281 | |||
1282 | /** | ||
1283 | * @brief Schedule the destruction of the given channel. | ||
1284 | * | ||
1285 | * Do so only if it was not already scheduled and not during shutdown. | ||
1286 | * | ||
1287 | * @param channel_ctx The context of the channel to destroy. | ||
1288 | */ | ||
1289 | static void | ||
1290 | schedule_channel_destruction (struct ChannelCtx *channel_ctx) | ||
1291 | { | ||
1292 | GNUNET_assert (NULL != channel_ctx); | ||
1293 | if (NULL != channel_ctx->destruction_task && | ||
1294 | GNUNET_NO == in_shutdown) | ||
1295 | { | ||
1296 | channel_ctx->destruction_task = | ||
1297 | GNUNET_SCHEDULER_add_now (&destroy_channel, | ||
1298 | channel_ctx); | ||
1299 | } | ||
1300 | } | ||
1301 | |||
1302 | |||
1303 | /** | ||
1304 | * @brief Schedule the destruction of the given peer. | ||
1305 | * | ||
1306 | * Do so only if it was not already scheduled and not during shutdown. | ||
1307 | * | ||
1308 | * @param peer_ctx The context of the peer to destroy. | ||
1309 | */ | ||
1310 | static void | ||
1311 | schedule_peer_destruction (struct PeerContext *peer_ctx) | ||
1312 | { | ||
1313 | GNUNET_assert (NULL != peer_ctx); | ||
1314 | if (NULL != peer_ctx->destruction_task && | ||
1315 | GNUNET_NO == in_shutdown) | ||
1316 | { | ||
1317 | peer_ctx->destruction_task = | ||
1318 | GNUNET_SCHEDULER_add_now (&destroy_peer, | ||
1319 | peer_ctx); | ||
1320 | } | ||
1321 | } | ||
1322 | |||
1323 | |||
1324 | /** | ||
1325 | * @brief Remove peer | ||
1326 | * | ||
1327 | * @param peer the peer to clean | ||
1328 | * @return #GNUNET_YES if peer was removed | ||
1329 | * #GNUNET_NO otherwise | ||
1330 | */ | ||
1331 | static int | ||
1332 | Peers_remove_peer (const struct GNUNET_PeerIdentity *peer) | ||
1333 | { | ||
1334 | struct PeerContext *peer_ctx; | ||
1335 | |||
1336 | GNUNET_assert (NULL != peer_map); | ||
1337 | if (GNUNET_NO == | ||
1338 | GNUNET_CONTAINER_multipeermap_contains (peer_map, | ||
1339 | peer)) | ||
1340 | { | ||
1341 | return GNUNET_NO; | ||
1342 | } | ||
1343 | peer_ctx = get_peer_ctx (peer); | ||
1344 | set_peer_flag (peer_ctx, Peers_TO_DESTROY); | ||
1345 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1346 | "Going to remove peer %s\n", | ||
1347 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
1348 | Peers_unset_peer_flag (peer, Peers_ONLINE); | ||
1349 | |||
1350 | /* Clear list of pending operations */ | ||
1351 | // TODO this probably leaks memory | ||
1352 | // ('only' the cls to the function. Not sure what to do with it) | ||
1353 | GNUNET_array_grow (peer_ctx->pending_ops, | ||
1354 | peer_ctx->num_pending_ops, | ||
1355 | 0); | ||
1356 | /* Remove all pending messages */ | ||
1357 | while (NULL != peer_ctx->pending_messages_head) | ||
1358 | { | ||
1359 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1360 | "Removing unsent %s\n", | ||
1361 | peer_ctx->pending_messages_head->type); | ||
1362 | /* Cancle pending message, too */ | ||
1363 | if ( (NULL != peer_ctx->liveliness_check_pending) && | ||
1364 | (0 == memcmp (peer_ctx->pending_messages_head, | ||
1365 | peer_ctx->liveliness_check_pending, | ||
1366 | sizeof (struct PendingMessage))) ) | ||
1367 | { | ||
1368 | // TODO this may leak memory | ||
1369 | peer_ctx->liveliness_check_pending = NULL; | ||
1370 | } | ||
1371 | remove_pending_message (peer_ctx->pending_messages_head, | ||
1372 | GNUNET_YES); | ||
1373 | } | ||
1374 | |||
1375 | /* If we are still waiting for notification whether this peer is live | ||
1376 | * cancel the according task */ | ||
1377 | if (NULL != peer_ctx->liveliness_check_pending) | ||
1378 | { | ||
1379 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1380 | "Removing pending liveliness check for peer %s\n", | ||
1381 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
1382 | // TODO wait until cadet sets mq->cancel_impl | ||
1383 | //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev); | ||
1384 | remove_pending_message (peer_ctx->liveliness_check_pending, | ||
1385 | GNUNET_YES); | ||
1386 | peer_ctx->liveliness_check_pending = NULL; | ||
1387 | } | ||
1388 | |||
1389 | |||
1390 | /* Do we still have to wait for destruction of channels | ||
1391 | * or issue the destruction? */ | ||
1392 | if (NULL != peer_ctx->send_channel_ctx && | ||
1393 | NULL != peer_ctx->send_channel_ctx->destruction_task) | ||
1394 | { | ||
1395 | schedule_peer_destruction (peer_ctx); | ||
1396 | return GNUNET_NO; | ||
1397 | } | ||
1398 | if (NULL != peer_ctx->recv_channel_ctx && | ||
1399 | NULL != peer_ctx->recv_channel_ctx->destruction_task) | ||
1400 | { | ||
1401 | schedule_peer_destruction (peer_ctx); | ||
1402 | return GNUNET_NO; | ||
1403 | } | ||
1404 | if (NULL != peer_ctx->recv_channel_ctx) | ||
1405 | { | ||
1406 | schedule_channel_destruction (peer_ctx->recv_channel_ctx); | ||
1407 | schedule_peer_destruction (peer_ctx); | ||
1408 | return GNUNET_NO; | ||
1409 | } | ||
1410 | if (NULL != peer_ctx->send_channel_ctx) | ||
1411 | { | ||
1412 | schedule_channel_destruction (peer_ctx->send_channel_ctx); | ||
1413 | schedule_peer_destruction (peer_ctx); | ||
1414 | return GNUNET_NO; | ||
1415 | } | ||
1416 | |||
1417 | if (NULL != peer_ctx->destruction_task) | ||
1418 | { | ||
1419 | GNUNET_SCHEDULER_cancel (peer_ctx->destruction_task); | ||
1420 | } | ||
1421 | |||
1422 | if (GNUNET_YES != | ||
1423 | GNUNET_CONTAINER_multipeermap_remove_all (peer_map, | ||
1424 | &peer_ctx->peer_id)) | ||
1425 | { | ||
1426 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1427 | "removing peer from peer_map failed\n"); | ||
1428 | } | ||
1429 | GNUNET_free (peer_ctx); | ||
1430 | return GNUNET_YES; | ||
1431 | } | ||
1432 | |||
1433 | |||
1434 | /** | ||
1435 | * @brief set flags on a given peer. | ||
1436 | * | ||
1437 | * @param peer the peer to set flags on | ||
1438 | * @param flags the flags | ||
1439 | */ | ||
1440 | void | ||
1441 | Peers_set_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags) | ||
1442 | { | ||
1443 | struct PeerContext *peer_ctx; | ||
1444 | |||
1445 | peer_ctx = get_peer_ctx (peer); | ||
1446 | set_peer_flag (peer_ctx, flags); | ||
1447 | } | ||
1448 | |||
1449 | |||
1450 | /** | ||
1451 | * @brief unset flags on a given peer. | ||
1452 | * | ||
1453 | * @param peer the peer to unset flags on | ||
1454 | * @param flags the flags | ||
1455 | */ | ||
1456 | void | ||
1457 | Peers_unset_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags) | ||
1458 | { | ||
1459 | struct PeerContext *peer_ctx; | ||
1460 | |||
1461 | peer_ctx = get_peer_ctx (peer); | ||
1462 | unset_peer_flag (peer_ctx, flags); | ||
1463 | } | ||
1464 | |||
1465 | |||
1466 | /** | ||
1467 | * @brief Check whether flags on a peer are set. | ||
1468 | * | ||
1469 | * @param peer the peer to check the flag of | ||
1470 | * @param flags the flags to check | ||
1471 | * | ||
1472 | * @return #GNUNET_SYSERR if peer is not known | ||
1473 | * #GNUNET_YES if all given flags are set | ||
1474 | * #GNUNET_NO otherwise | ||
1475 | */ | ||
1476 | int | ||
1477 | Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags) | ||
1478 | { | ||
1479 | struct PeerContext *peer_ctx; | ||
1480 | |||
1481 | if (GNUNET_NO == Peers_check_peer_known (peer)) | ||
1482 | { | ||
1483 | return GNUNET_SYSERR; | ||
1484 | } | ||
1485 | peer_ctx = get_peer_ctx (peer); | ||
1486 | return check_peer_flag_set (peer_ctx, flags); | ||
1487 | } | ||
1488 | |||
1489 | /** | ||
1490 | * @brief Check whether we have information about the given peer. | ||
1491 | * | ||
1492 | * FIXME probably deprecated. Make this the new _online. | ||
1493 | * | ||
1494 | * @param peer peer in question | ||
1495 | * | ||
1496 | * @return #GNUNET_YES if peer is known | ||
1497 | * #GNUNET_NO if peer is not knwon | ||
1498 | */ | ||
1499 | int | ||
1500 | Peers_check_peer_known (const struct GNUNET_PeerIdentity *peer) | ||
1501 | { | ||
1502 | if (NULL != peer_map) | ||
1503 | { | ||
1504 | return GNUNET_CONTAINER_multipeermap_contains (peer_map, peer); | ||
1505 | } else | ||
1506 | { | ||
1507 | return GNUNET_NO; | ||
1508 | } | ||
1509 | } | ||
1510 | |||
1511 | 1457 | ||
1512 | /** | 1458 | /** |
1513 | * @brief Check whether @a peer is actually a peer. | 1459 | * @brief Check whether @a peer is actually a peer. |
@@ -1519,8 +1465,8 @@ Peers_check_peer_known (const struct GNUNET_PeerIdentity *peer) | |||
1519 | * @return #GNUNET_YES if peer is valid | 1465 | * @return #GNUNET_YES if peer is valid |
1520 | * #GNUNET_NO if peer is not valid | 1466 | * #GNUNET_NO if peer is not valid |
1521 | */ | 1467 | */ |
1522 | int | 1468 | static int |
1523 | Peers_check_peer_valid (const struct GNUNET_PeerIdentity *peer) | 1469 | check_peer_valid (const struct GNUNET_PeerIdentity *peer) |
1524 | { | 1470 | { |
1525 | return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer); | 1471 | return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer); |
1526 | } | 1472 | } |
@@ -1533,10 +1479,10 @@ Peers_check_peer_valid (const struct GNUNET_PeerIdentity *peer) | |||
1533 | * | 1479 | * |
1534 | * @param peer the peer to establish channel to | 1480 | * @param peer the peer to establish channel to |
1535 | */ | 1481 | */ |
1536 | void | 1482 | static void |
1537 | Peers_indicate_sending_intention (const struct GNUNET_PeerIdentity *peer) | 1483 | indicate_sending_intention (const struct GNUNET_PeerIdentity *peer) |
1538 | { | 1484 | { |
1539 | GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer)); | 1485 | GNUNET_assert (GNUNET_YES == check_peer_known (peer)); |
1540 | (void) get_channel (peer); | 1486 | (void) get_channel (peer); |
1541 | } | 1487 | } |
1542 | 1488 | ||
@@ -1550,8 +1496,8 @@ Peers_indicate_sending_intention (const struct GNUNET_PeerIdentity *peer) | |||
1550 | * @return #GNUNET_YES if peer has the intention to send | 1496 | * @return #GNUNET_YES if peer has the intention to send |
1551 | * #GNUNET_NO otherwise | 1497 | * #GNUNET_NO otherwise |
1552 | */ | 1498 | */ |
1553 | int | 1499 | static int |
1554 | Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer) | 1500 | check_peer_send_intention (const struct GNUNET_PeerIdentity *peer) |
1555 | { | 1501 | { |
1556 | const struct PeerContext *peer_ctx; | 1502 | const struct PeerContext *peer_ctx; |
1557 | 1503 | ||
@@ -1574,10 +1520,10 @@ Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer) | |||
1574 | * @return initial channel context for the channel | 1520 | * @return initial channel context for the channel |
1575 | * (can be NULL -- that's not an error) | 1521 | * (can be NULL -- that's not an error) |
1576 | */ | 1522 | */ |
1577 | void * | 1523 | static void * |
1578 | Peers_handle_inbound_channel (void *cls, | 1524 | handle_inbound_channel (void *cls, |
1579 | struct GNUNET_CADET_Channel *channel, | 1525 | struct GNUNET_CADET_Channel *channel, |
1580 | const struct GNUNET_PeerIdentity *initiator) | 1526 | const struct GNUNET_PeerIdentity *initiator) |
1581 | { | 1527 | { |
1582 | struct PeerContext *peer_ctx; | 1528 | struct PeerContext *peer_ctx; |
1583 | struct GNUNET_PeerIdentity *ctx_peer; | 1529 | struct GNUNET_PeerIdentity *ctx_peer; |
@@ -1595,14 +1541,12 @@ Peers_handle_inbound_channel (void *cls, | |||
1595 | channel_ctx = add_channel_ctx (peer_ctx); | 1541 | channel_ctx = add_channel_ctx (peer_ctx); |
1596 | channel_ctx->channel = channel; | 1542 | channel_ctx->channel = channel; |
1597 | /* We only accept one incoming channel per peer */ | 1543 | /* We only accept one incoming channel per peer */ |
1598 | if (GNUNET_YES == Peers_check_peer_send_intention (initiator)) | 1544 | if (GNUNET_YES == check_peer_send_intention (initiator)) |
1599 | { | 1545 | { |
1600 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1546 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1601 | "Already got one receive channel. Destroying old one.\n"); | 1547 | "Already got one receive channel. Destroying old one.\n"); |
1602 | GNUNET_break_op (0); | 1548 | GNUNET_break_op (0); |
1603 | GNUNET_CADET_channel_destroy (peer_ctx->recv_channel_ctx->channel); | 1549 | destroy_channel (peer_ctx->recv_channel_ctx); |
1604 | peer_ctx->recv_channel_ctx->channel = NULL; | ||
1605 | remove_channel_ctx (peer_ctx->recv_channel_ctx); | ||
1606 | peer_ctx->recv_channel_ctx = channel_ctx; | 1550 | peer_ctx->recv_channel_ctx = channel_ctx; |
1607 | /* return the channel context */ | 1551 | /* return the channel context */ |
1608 | return channel_ctx; | 1552 | return channel_ctx; |
@@ -1620,12 +1564,12 @@ Peers_handle_inbound_channel (void *cls, | |||
1620 | * @return #GNUNET_YES if a sending channel towards that peer exists | 1564 | * @return #GNUNET_YES if a sending channel towards that peer exists |
1621 | * #GNUNET_NO otherwise | 1565 | * #GNUNET_NO otherwise |
1622 | */ | 1566 | */ |
1623 | int | 1567 | static int |
1624 | Peers_check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer) | 1568 | check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer) |
1625 | { | 1569 | { |
1626 | struct PeerContext *peer_ctx; | 1570 | struct PeerContext *peer_ctx; |
1627 | 1571 | ||
1628 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 1572 | if (GNUNET_NO == check_peer_known (peer)) |
1629 | { /* If no such peer exists, there is no channel */ | 1573 | { /* If no such peer exists, there is no channel */ |
1630 | return GNUNET_NO; | 1574 | return GNUNET_NO; |
1631 | } | 1575 | } |
@@ -1639,46 +1583,6 @@ Peers_check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer) | |||
1639 | 1583 | ||
1640 | 1584 | ||
1641 | /** | 1585 | /** |
1642 | * @brief check whether the given channel is the sending channel of the given | ||
1643 | * peer | ||
1644 | * | ||
1645 | * @param peer the peer in question | ||
1646 | * @param channel the channel to check for | ||
1647 | * @param role either #Peers_CHANNEL_ROLE_SENDING, or | ||
1648 | * #Peers_CHANNEL_ROLE_RECEIVING | ||
1649 | * | ||
1650 | * @return #GNUNET_YES if the given chennel is the sending channel of the peer | ||
1651 | * #GNUNET_NO otherwise | ||
1652 | */ | ||
1653 | int | ||
1654 | Peers_check_channel_role (const struct GNUNET_PeerIdentity *peer, | ||
1655 | const struct GNUNET_CADET_Channel *channel, | ||
1656 | enum Peers_ChannelRole role) | ||
1657 | { | ||
1658 | const struct PeerContext *peer_ctx; | ||
1659 | |||
1660 | if (GNUNET_NO == Peers_check_peer_known (peer)) | ||
1661 | { | ||
1662 | return GNUNET_NO; | ||
1663 | } | ||
1664 | peer_ctx = get_peer_ctx (peer); | ||
1665 | if ( (Peers_CHANNEL_ROLE_SENDING == role) && | ||
1666 | (NULL != peer_ctx->send_channel_ctx) && | ||
1667 | (channel == peer_ctx->send_channel_ctx->channel) ) | ||
1668 | { | ||
1669 | return GNUNET_YES; | ||
1670 | } | ||
1671 | if ( (Peers_CHANNEL_ROLE_RECEIVING == role) && | ||
1672 | (NULL != peer_ctx->recv_channel_ctx) && | ||
1673 | (channel == peer_ctx->recv_channel_ctx->channel) ) | ||
1674 | { | ||
1675 | return GNUNET_YES; | ||
1676 | } | ||
1677 | return GNUNET_NO; | ||
1678 | } | ||
1679 | |||
1680 | |||
1681 | /** | ||
1682 | * @brief Destroy the send channel of a peer e.g. stop indicating a sending | 1586 | * @brief Destroy the send channel of a peer e.g. stop indicating a sending |
1683 | * intention to another peer | 1587 | * intention to another peer |
1684 | * | 1588 | * |
@@ -1690,46 +1594,26 @@ Peers_check_channel_role (const struct GNUNET_PeerIdentity *peer, | |||
1690 | * @return #GNUNET_YES if channel was destroyed | 1594 | * @return #GNUNET_YES if channel was destroyed |
1691 | * #GNUNET_NO otherwise | 1595 | * #GNUNET_NO otherwise |
1692 | */ | 1596 | */ |
1693 | int | 1597 | static int |
1694 | Peers_destroy_sending_channel (const struct GNUNET_PeerIdentity *peer) | 1598 | destroy_sending_channel (const struct GNUNET_PeerIdentity *peer) |
1695 | { | 1599 | { |
1696 | struct PeerContext *peer_ctx; | 1600 | struct PeerContext *peer_ctx; |
1697 | 1601 | ||
1698 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 1602 | if (GNUNET_NO == check_peer_known (peer)) |
1699 | { | 1603 | { |
1700 | return GNUNET_NO; | 1604 | return GNUNET_NO; |
1701 | } | 1605 | } |
1702 | peer_ctx = get_peer_ctx (peer); | 1606 | peer_ctx = get_peer_ctx (peer); |
1703 | if (NULL != peer_ctx->send_channel_ctx) | 1607 | if (NULL != peer_ctx->send_channel_ctx) |
1704 | { | 1608 | { |
1705 | schedule_channel_destruction (peer_ctx->send_channel_ctx); | 1609 | destroy_channel (peer_ctx->send_channel_ctx); |
1706 | (void) Peers_check_connected (peer); | 1610 | (void) check_connected (peer); |
1707 | return GNUNET_YES; | 1611 | return GNUNET_YES; |
1708 | } | 1612 | } |
1709 | return GNUNET_NO; | 1613 | return GNUNET_NO; |
1710 | } | 1614 | } |
1711 | 1615 | ||
1712 | /** | 1616 | /** |
1713 | * @brief Callback for scheduler to destroy a channel | ||
1714 | * | ||
1715 | * @param cls Context of the channel | ||
1716 | */ | ||
1717 | static void | ||
1718 | destroy_channel (void *cls) | ||
1719 | { | ||
1720 | struct ChannelCtx *channel_ctx = cls; | ||
1721 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; | ||
1722 | |||
1723 | GNUNET_assert (channel_ctx == peer_ctx->send_channel_ctx || | ||
1724 | channel_ctx == peer_ctx->recv_channel_ctx); | ||
1725 | |||
1726 | channel_ctx->destruction_task = NULL; | ||
1727 | GNUNET_CADET_channel_destroy (channel_ctx->channel); | ||
1728 | remove_channel_ctx (peer_ctx->send_channel_ctx); | ||
1729 | } | ||
1730 | |||
1731 | |||
1732 | /** | ||
1733 | * @brief Send a message to another peer. | 1617 | * @brief Send a message to another peer. |
1734 | * | 1618 | * |
1735 | * Keeps track about pending messages so they can be properly removed when the | 1619 | * Keeps track about pending messages so they can be properly removed when the |
@@ -1739,10 +1623,10 @@ destroy_channel (void *cls) | |||
1739 | * @param ev envelope of the message | 1623 | * @param ev envelope of the message |
1740 | * @param type type of the message | 1624 | * @param type type of the message |
1741 | */ | 1625 | */ |
1742 | void | 1626 | static void |
1743 | Peers_send_message (const struct GNUNET_PeerIdentity *peer, | 1627 | send_message (const struct GNUNET_PeerIdentity *peer, |
1744 | struct GNUNET_MQ_Envelope *ev, | 1628 | struct GNUNET_MQ_Envelope *ev, |
1745 | const char *type) | 1629 | const char *type) |
1746 | { | 1630 | { |
1747 | struct PendingMessage *pending_msg; | 1631 | struct PendingMessage *pending_msg; |
1748 | struct GNUNET_MQ_Handle *mq; | 1632 | struct GNUNET_MQ_Handle *mq; |
@@ -1769,14 +1653,14 @@ Peers_send_message (const struct GNUNET_PeerIdentity *peer, | |||
1769 | * @return #GNUNET_YES if the operation was scheduled | 1653 | * @return #GNUNET_YES if the operation was scheduled |
1770 | * #GNUNET_NO otherwise | 1654 | * #GNUNET_NO otherwise |
1771 | */ | 1655 | */ |
1772 | int | 1656 | static int |
1773 | Peers_schedule_operation (const struct GNUNET_PeerIdentity *peer, | 1657 | schedule_operation (const struct GNUNET_PeerIdentity *peer, |
1774 | const PeerOp peer_op) | 1658 | const PeerOp peer_op) |
1775 | { | 1659 | { |
1776 | struct PeerPendingOp pending_op; | 1660 | struct PeerPendingOp pending_op; |
1777 | struct PeerContext *peer_ctx; | 1661 | struct PeerContext *peer_ctx; |
1778 | 1662 | ||
1779 | GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer)); | 1663 | GNUNET_assert (GNUNET_YES == check_peer_known (peer)); |
1780 | 1664 | ||
1781 | //TODO if LIVE/ONLINE execute immediately | 1665 | //TODO if LIVE/ONLINE execute immediately |
1782 | 1666 | ||
@@ -1793,24 +1677,6 @@ Peers_schedule_operation (const struct GNUNET_PeerIdentity *peer, | |||
1793 | return GNUNET_NO; | 1677 | return GNUNET_NO; |
1794 | } | 1678 | } |
1795 | 1679 | ||
1796 | /** | ||
1797 | * @brief Get the recv_channel of @a peer. | ||
1798 | * Needed to correctly handle (call #GNUNET_CADET_receive_done()) incoming | ||
1799 | * messages. | ||
1800 | * | ||
1801 | * @param peer The peer to get the recv_channel from. | ||
1802 | * | ||
1803 | * @return The recv_channel. | ||
1804 | */ | ||
1805 | struct GNUNET_CADET_Channel * | ||
1806 | Peers_get_recv_channel (const struct GNUNET_PeerIdentity *peer) | ||
1807 | { | ||
1808 | struct PeerContext *peer_ctx; | ||
1809 | |||
1810 | GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer)); | ||
1811 | peer_ctx = get_peer_ctx (peer); | ||
1812 | return peer_ctx->recv_channel_ctx->channel; | ||
1813 | } | ||
1814 | /*********************************************************************** | 1680 | /*********************************************************************** |
1815 | * /Old gnunet-service-rps_peers.c | 1681 | * /Old gnunet-service-rps_peers.c |
1816 | ***********************************************************************/ | 1682 | ***********************************************************************/ |
@@ -2266,16 +2132,16 @@ insert_in_view (const struct GNUNET_PeerIdentity *peer) | |||
2266 | { | 2132 | { |
2267 | int online; | 2133 | int online; |
2268 | 2134 | ||
2269 | online = Peers_check_peer_flag (peer, Peers_ONLINE); | 2135 | online = check_peer_flag (peer, Peers_ONLINE); |
2270 | if ( (GNUNET_NO == online) || | 2136 | if ( (GNUNET_NO == online) || |
2271 | (GNUNET_SYSERR == online) ) /* peer is not even known */ | 2137 | (GNUNET_SYSERR == online) ) /* peer is not even known */ |
2272 | { | 2138 | { |
2273 | (void) Peers_issue_peer_liveliness_check (peer); | 2139 | (void) issue_peer_liveliness_check (peer); |
2274 | (void) Peers_schedule_operation (peer, insert_in_view_op); | 2140 | (void) schedule_operation (peer, insert_in_view_op); |
2275 | return GNUNET_NO; | 2141 | return GNUNET_NO; |
2276 | } | 2142 | } |
2277 | /* Open channel towards peer to keep connection open */ | 2143 | /* Open channel towards peer to keep connection open */ |
2278 | Peers_indicate_sending_intention (peer); | 2144 | indicate_sending_intention (peer); |
2279 | return View_put (peer); | 2145 | return View_put (peer); |
2280 | } | 2146 | } |
2281 | 2147 | ||
@@ -2468,7 +2334,7 @@ send_pull_reply (const struct GNUNET_PeerIdentity *peer_id, | |||
2468 | GNUNET_memcpy (&out_msg[1], peer_ids, | 2334 | GNUNET_memcpy (&out_msg[1], peer_ids, |
2469 | send_size * sizeof (struct GNUNET_PeerIdentity)); | 2335 | send_size * sizeof (struct GNUNET_PeerIdentity)); |
2470 | 2336 | ||
2471 | Peers_send_message (peer_id, ev, "PULL REPLY"); | 2337 | send_message (peer_id, ev, "PULL REPLY"); |
2472 | GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO); | 2338 | GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO); |
2473 | // TODO check with send intention: as send_channel is used/opened we indicate | 2339 | // TODO check with send intention: as send_channel is used/opened we indicate |
2474 | // a sending intention without intending it. | 2340 | // a sending intention without intending it. |
@@ -2519,10 +2385,10 @@ insert_in_sampler (void *cls, | |||
2519 | if (0 < RPS_sampler_count_id (prot_sampler, peer)) | 2385 | if (0 < RPS_sampler_count_id (prot_sampler, peer)) |
2520 | { | 2386 | { |
2521 | /* Make sure we 'know' about this peer */ | 2387 | /* Make sure we 'know' about this peer */ |
2522 | (void) Peers_issue_peer_liveliness_check (peer); | 2388 | (void) issue_peer_liveliness_check (peer); |
2523 | /* Establish a channel towards that peer to indicate we are going to send | 2389 | /* Establish a channel towards that peer to indicate we are going to send |
2524 | * messages to it */ | 2390 | * messages to it */ |
2525 | //Peers_indicate_sending_intention (peer); | 2391 | //indicate_sending_intention (peer); |
2526 | } | 2392 | } |
2527 | #ifdef TO_FILE | 2393 | #ifdef TO_FILE |
2528 | num_observed_peers++; | 2394 | num_observed_peers++; |
@@ -2554,10 +2420,10 @@ static void | |||
2554 | got_peer (const struct GNUNET_PeerIdentity *peer) | 2420 | got_peer (const struct GNUNET_PeerIdentity *peer) |
2555 | { | 2421 | { |
2556 | /* If we did not know this peer already, insert it into sampler and view */ | 2422 | /* If we did not know this peer already, insert it into sampler and view */ |
2557 | if (GNUNET_YES == Peers_issue_peer_liveliness_check (peer)) | 2423 | if (GNUNET_YES == issue_peer_liveliness_check (peer)) |
2558 | { | 2424 | { |
2559 | Peers_schedule_operation (peer, insert_in_sampler); | 2425 | schedule_operation (peer, insert_in_sampler); |
2560 | Peers_schedule_operation (peer, insert_in_view_op); | 2426 | schedule_operation (peer, insert_in_view_op); |
2561 | } | 2427 | } |
2562 | } | 2428 | } |
2563 | 2429 | ||
@@ -2572,17 +2438,17 @@ static int | |||
2572 | check_sending_channel_needed (const struct GNUNET_PeerIdentity *peer) | 2438 | check_sending_channel_needed (const struct GNUNET_PeerIdentity *peer) |
2573 | { | 2439 | { |
2574 | /* struct GNUNET_CADET_Channel *channel; */ | 2440 | /* struct GNUNET_CADET_Channel *channel; */ |
2575 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 2441 | if (GNUNET_NO == check_peer_known (peer)) |
2576 | { | 2442 | { |
2577 | return GNUNET_NO; | 2443 | return GNUNET_NO; |
2578 | } | 2444 | } |
2579 | if (GNUNET_YES == Peers_check_sending_channel_exists (peer)) | 2445 | if (GNUNET_YES == check_sending_channel_exists (peer)) |
2580 | { | 2446 | { |
2581 | if ( (0 < RPS_sampler_count_id (prot_sampler, peer)) || | 2447 | if ( (0 < RPS_sampler_count_id (prot_sampler, peer)) || |
2582 | (GNUNET_YES == View_contains_peer (peer)) || | 2448 | (GNUNET_YES == View_contains_peer (peer)) || |
2583 | (GNUNET_YES == CustomPeerMap_contains_peer (push_map, peer)) || | 2449 | (GNUNET_YES == CustomPeerMap_contains_peer (push_map, peer)) || |
2584 | (GNUNET_YES == CustomPeerMap_contains_peer (pull_map, peer)) || | 2450 | (GNUNET_YES == CustomPeerMap_contains_peer (pull_map, peer)) || |
2585 | (GNUNET_YES == Peers_check_peer_flag (peer, Peers_PULL_REPLY_PENDING))) | 2451 | (GNUNET_YES == check_peer_flag (peer, Peers_PULL_REPLY_PENDING))) |
2586 | { /* If we want to keep the connection to peer open */ | 2452 | { /* If we want to keep the connection to peer open */ |
2587 | return GNUNET_YES; | 2453 | return GNUNET_YES; |
2588 | } | 2454 | } |
@@ -2605,7 +2471,7 @@ remove_peer (const struct GNUNET_PeerIdentity *peer) | |||
2605 | CustomPeerMap_remove_peer (push_map, peer); | 2471 | CustomPeerMap_remove_peer (push_map, peer); |
2606 | RPS_sampler_reinitialise_by_value (prot_sampler, peer); | 2472 | RPS_sampler_reinitialise_by_value (prot_sampler, peer); |
2607 | RPS_sampler_reinitialise_by_value (client_sampler, peer); | 2473 | RPS_sampler_reinitialise_by_value (client_sampler, peer); |
2608 | schedule_peer_destruction (get_peer_ctx (peer)); | 2474 | destroy_peer (get_peer_ctx (peer)); |
2609 | } | 2475 | } |
2610 | 2476 | ||
2611 | 2477 | ||
@@ -2626,19 +2492,19 @@ clean_peer (const struct GNUNET_PeerIdentity *peer) | |||
2626 | GNUNET_i2s (peer)); | 2492 | GNUNET_i2s (peer)); |
2627 | #ifdef ENABLE_MALICIOUS | 2493 | #ifdef ENABLE_MALICIOUS |
2628 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&attacked_peer, peer)) | 2494 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&attacked_peer, peer)) |
2629 | (void) Peers_destroy_sending_channel (peer); | 2495 | (void) destroy_sending_channel (peer); |
2630 | #else /* ENABLE_MALICIOUS */ | 2496 | #else /* ENABLE_MALICIOUS */ |
2631 | (void) Peers_destroy_sending_channel (peer); | 2497 | (void) destroy_sending_channel (peer); |
2632 | #endif /* ENABLE_MALICIOUS */ | 2498 | #endif /* ENABLE_MALICIOUS */ |
2633 | } | 2499 | } |
2634 | 2500 | ||
2635 | if ( (GNUNET_NO == Peers_check_peer_send_intention (peer)) && | 2501 | if ( (GNUNET_NO == check_peer_send_intention (peer)) && |
2636 | (GNUNET_NO == View_contains_peer (peer)) && | 2502 | (GNUNET_NO == View_contains_peer (peer)) && |
2637 | (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) && | 2503 | (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) && |
2638 | (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) && | 2504 | (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) && |
2639 | (0 == RPS_sampler_count_id (prot_sampler, peer)) && | 2505 | (0 == RPS_sampler_count_id (prot_sampler, peer)) && |
2640 | (0 == RPS_sampler_count_id (client_sampler, peer)) && | 2506 | (0 == RPS_sampler_count_id (client_sampler, peer)) && |
2641 | (GNUNET_NO != Peers_check_removable (peer)) ) | 2507 | (GNUNET_NO != check_removable (peer)) ) |
2642 | { /* We can safely remove this peer */ | 2508 | { /* We can safely remove this peer */ |
2643 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2509 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2644 | "Going to remove peer %s\n", | 2510 | "Going to remove peer %s\n", |
@@ -2648,53 +2514,6 @@ clean_peer (const struct GNUNET_PeerIdentity *peer) | |||
2648 | } | 2514 | } |
2649 | } | 2515 | } |
2650 | 2516 | ||
2651 | /** | ||
2652 | * @brief Allocate memory for a new channel context and insert it into DLL | ||
2653 | * | ||
2654 | * @param peer_ctx context of the according peer | ||
2655 | * | ||
2656 | * @return The channel context | ||
2657 | */ | ||
2658 | static struct ChannelCtx * | ||
2659 | add_channel_ctx (struct PeerContext *peer_ctx) | ||
2660 | { | ||
2661 | struct ChannelCtx *channel_ctx; | ||
2662 | channel_ctx = GNUNET_new (struct ChannelCtx); | ||
2663 | channel_ctx->peer_ctx = peer_ctx; | ||
2664 | return channel_ctx; | ||
2665 | } | ||
2666 | |||
2667 | |||
2668 | /** | ||
2669 | * @brief Remove the channel context from the DLL and free the memory. | ||
2670 | * | ||
2671 | * @param channel_ctx The channel context. | ||
2672 | */ | ||
2673 | static void | ||
2674 | remove_channel_ctx (struct ChannelCtx *channel_ctx) | ||
2675 | { | ||
2676 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; | ||
2677 | |||
2678 | if (NULL != channel_ctx->destruction_task) | ||
2679 | { | ||
2680 | GNUNET_SCHEDULER_cancel (channel_ctx->destruction_task); | ||
2681 | } | ||
2682 | GNUNET_free (channel_ctx); | ||
2683 | if (channel_ctx == peer_ctx->send_channel_ctx) | ||
2684 | { | ||
2685 | peer_ctx->send_channel_ctx = NULL; | ||
2686 | peer_ctx->mq = NULL; | ||
2687 | } | ||
2688 | else if (channel_ctx == peer_ctx->recv_channel_ctx) | ||
2689 | { | ||
2690 | peer_ctx->recv_channel_ctx = NULL; | ||
2691 | } | ||
2692 | else | ||
2693 | { | ||
2694 | GNUNET_assert (0); | ||
2695 | } | ||
2696 | } | ||
2697 | |||
2698 | 2517 | ||
2699 | /** | 2518 | /** |
2700 | * @brief This is called when a channel is destroyed. | 2519 | * @brief This is called when a channel is destroyed. |
@@ -2719,7 +2538,7 @@ cleanup_destroyed_channel (void *cls, | |||
2719 | // * cleanup everything related to the channel | 2538 | // * cleanup everything related to the channel |
2720 | // * memory | 2539 | // * memory |
2721 | // * remove peer if necessary | 2540 | // * remove peer if necessary |
2722 | 2541 | channel_ctx->channel = NULL; | |
2723 | if (peer_ctx->recv_channel_ctx == channel_ctx) | 2542 | if (peer_ctx->recv_channel_ctx == channel_ctx) |
2724 | { | 2543 | { |
2725 | remove_channel_ctx (channel_ctx); | 2544 | remove_channel_ctx (channel_ctx); |
@@ -3184,7 +3003,7 @@ handle_peer_push (void *cls, | |||
3184 | /* Add the sending peer to the push_map */ | 3003 | /* Add the sending peer to the push_map */ |
3185 | CustomPeerMap_put (push_map, peer); | 3004 | CustomPeerMap_put (push_map, peer); |
3186 | 3005 | ||
3187 | GNUNET_break_op (Peers_check_peer_known (peer)); | 3006 | GNUNET_break_op (check_peer_known (peer)); |
3188 | GNUNET_CADET_receive_done (channel_ctx->channel); | 3007 | GNUNET_CADET_receive_done (channel_ctx->channel); |
3189 | } | 3008 | } |
3190 | 3009 | ||
@@ -3224,7 +3043,7 @@ handle_peer_pull_request (void *cls, | |||
3224 | } | 3043 | } |
3225 | #endif /* ENABLE_MALICIOUS */ | 3044 | #endif /* ENABLE_MALICIOUS */ |
3226 | 3045 | ||
3227 | GNUNET_break_op (Peers_check_peer_known (peer)); | 3046 | GNUNET_break_op (check_peer_known (peer)); |
3228 | GNUNET_CADET_receive_done (channel_ctx->channel); | 3047 | GNUNET_CADET_receive_done (channel_ctx->channel); |
3229 | view_array = View_get_as_array (); | 3048 | view_array = View_get_as_array (); |
3230 | send_pull_reply (peer, view_array, View_size ()); | 3049 | send_pull_reply (peer, view_array, View_size ()); |
@@ -3262,7 +3081,7 @@ check_peer_pull_reply (void *cls, | |||
3262 | return GNUNET_SYSERR; | 3081 | return GNUNET_SYSERR; |
3263 | } | 3082 | } |
3264 | 3083 | ||
3265 | if (GNUNET_YES != Peers_check_peer_flag (sender, Peers_PULL_REPLY_PENDING)) | 3084 | if (GNUNET_YES != check_peer_flag (sender, Peers_PULL_REPLY_PENDING)) |
3266 | { | 3085 | { |
3267 | LOG (GNUNET_ERROR_TYPE_WARNING, | 3086 | LOG (GNUNET_ERROR_TYPE_WARNING, |
3268 | "Received a pull reply from a peer (%s) we didn't request one from!\n", | 3087 | "Received a pull reply from a peer (%s) we didn't request one from!\n", |
@@ -3336,23 +3155,23 @@ handle_peer_pull_reply (void *cls, | |||
3336 | } | 3155 | } |
3337 | #endif /* ENABLE_MALICIOUS */ | 3156 | #endif /* ENABLE_MALICIOUS */ |
3338 | /* Make sure we 'know' about this peer */ | 3157 | /* Make sure we 'know' about this peer */ |
3339 | (void) Peers_insert_peer (&peers[i]); | 3158 | (void) insert_peer (&peers[i]); |
3340 | 3159 | ||
3341 | if (GNUNET_YES == Peers_check_peer_valid (&peers[i])) | 3160 | if (GNUNET_YES == check_peer_valid (&peers[i])) |
3342 | { | 3161 | { |
3343 | CustomPeerMap_put (pull_map, &peers[i]); | 3162 | CustomPeerMap_put (pull_map, &peers[i]); |
3344 | } | 3163 | } |
3345 | else | 3164 | else |
3346 | { | 3165 | { |
3347 | Peers_schedule_operation (&peers[i], insert_in_pull_map); | 3166 | schedule_operation (&peers[i], insert_in_pull_map); |
3348 | (void) Peers_issue_peer_liveliness_check (&peers[i]); | 3167 | (void) issue_peer_liveliness_check (&peers[i]); |
3349 | } | 3168 | } |
3350 | } | 3169 | } |
3351 | 3170 | ||
3352 | Peers_unset_peer_flag (sender, Peers_PULL_REPLY_PENDING); | 3171 | UNSET_PEER_FLAG (get_peer_ctx (sender), Peers_PULL_REPLY_PENDING); |
3353 | clean_peer (sender); | 3172 | clean_peer (sender); |
3354 | 3173 | ||
3355 | GNUNET_break_op (Peers_check_peer_known (sender)); | 3174 | GNUNET_break_op (check_peer_known (sender)); |
3356 | GNUNET_CADET_receive_done (channel_ctx->channel); | 3175 | GNUNET_CADET_receive_done (channel_ctx->channel); |
3357 | } | 3176 | } |
3358 | 3177 | ||
@@ -3416,16 +3235,16 @@ send_pull_request (const struct GNUNET_PeerIdentity *peer) | |||
3416 | { | 3235 | { |
3417 | struct GNUNET_MQ_Envelope *ev; | 3236 | struct GNUNET_MQ_Envelope *ev; |
3418 | 3237 | ||
3419 | GNUNET_assert (GNUNET_NO == Peers_check_peer_flag (peer, | 3238 | GNUNET_assert (GNUNET_NO == check_peer_flag (peer, |
3420 | Peers_PULL_REPLY_PENDING)); | 3239 | Peers_PULL_REPLY_PENDING)); |
3421 | Peers_set_peer_flag (peer, Peers_PULL_REPLY_PENDING); | 3240 | SET_PEER_FLAG (get_peer_ctx (peer), Peers_PULL_REPLY_PENDING); |
3422 | 3241 | ||
3423 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3242 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3424 | "Going to send PULL REQUEST to peer %s.\n", | 3243 | "Going to send PULL REQUEST to peer %s.\n", |
3425 | GNUNET_i2s (peer)); | 3244 | GNUNET_i2s (peer)); |
3426 | 3245 | ||
3427 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); | 3246 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); |
3428 | Peers_send_message (peer, ev, "PULL REQUEST"); | 3247 | send_message (peer, ev, "PULL REQUEST"); |
3429 | GNUNET_STATISTICS_update(stats, "# pull request send issued", 1, GNUNET_NO); | 3248 | GNUNET_STATISTICS_update(stats, "# pull request send issued", 1, GNUNET_NO); |
3430 | } | 3249 | } |
3431 | 3250 | ||
@@ -3445,7 +3264,7 @@ send_push (const struct GNUNET_PeerIdentity *peer_id) | |||
3445 | GNUNET_i2s (peer_id)); | 3264 | GNUNET_i2s (peer_id)); |
3446 | 3265 | ||
3447 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); | 3266 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); |
3448 | Peers_send_message (peer_id, ev, "PUSH"); | 3267 | send_message (peer_id, ev, "PUSH"); |
3449 | GNUNET_STATISTICS_update(stats, "# push send issued", 1, GNUNET_NO); | 3268 | GNUNET_STATISTICS_update(stats, "# push send issued", 1, GNUNET_NO); |
3450 | } | 3269 | } |
3451 | 3270 | ||
@@ -3569,9 +3388,9 @@ handle_client_act_malicious (void *cls, | |||
3569 | &msg->attacked_peer, | 3388 | &msg->attacked_peer, |
3570 | sizeof (struct GNUNET_PeerIdentity)); | 3389 | sizeof (struct GNUNET_PeerIdentity)); |
3571 | /* Set the flag of the attacked peer to valid to avoid problems */ | 3390 | /* Set the flag of the attacked peer to valid to avoid problems */ |
3572 | if (GNUNET_NO == Peers_check_peer_known (&attacked_peer)) | 3391 | if (GNUNET_NO == check_peer_known (&attacked_peer)) |
3573 | { | 3392 | { |
3574 | (void) Peers_issue_peer_liveliness_check (&attacked_peer); | 3393 | (void) issue_peer_liveliness_check (&attacked_peer); |
3575 | } | 3394 | } |
3576 | 3395 | ||
3577 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3396 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -3661,8 +3480,8 @@ do_mal_round (void *cls) | |||
3661 | * Send as many pushes to the attacked peer as possible | 3480 | * Send as many pushes to the attacked peer as possible |
3662 | * That is one push per round as it will ignore more. | 3481 | * That is one push per round as it will ignore more. |
3663 | */ | 3482 | */ |
3664 | (void) Peers_issue_peer_liveliness_check (&attacked_peer); | 3483 | (void) issue_peer_liveliness_check (&attacked_peer); |
3665 | if (GNUNET_YES == Peers_check_peer_flag (&attacked_peer, Peers_ONLINE)) | 3484 | if (GNUNET_YES == check_peer_flag (&attacked_peer, Peers_ONLINE)) |
3666 | send_push (&attacked_peer); | 3485 | send_push (&attacked_peer); |
3667 | } | 3486 | } |
3668 | 3487 | ||
@@ -3671,10 +3490,10 @@ do_mal_round (void *cls) | |||
3671 | { /* Combined attack */ | 3490 | { /* Combined attack */ |
3672 | 3491 | ||
3673 | /* Send PUSH to attacked peers */ | 3492 | /* Send PUSH to attacked peers */ |
3674 | if (GNUNET_YES == Peers_check_peer_known (&attacked_peer)) | 3493 | if (GNUNET_YES == check_peer_known (&attacked_peer)) |
3675 | { | 3494 | { |
3676 | (void) Peers_issue_peer_liveliness_check (&attacked_peer); | 3495 | (void) issue_peer_liveliness_check (&attacked_peer); |
3677 | if (GNUNET_YES == Peers_check_peer_flag (&attacked_peer, Peers_ONLINE)) | 3496 | if (GNUNET_YES == check_peer_flag (&attacked_peer, Peers_ONLINE)) |
3678 | { | 3497 | { |
3679 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3498 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3680 | "Goding to send push to attacked peer (%s)\n", | 3499 | "Goding to send push to attacked peer (%s)\n", |
@@ -3682,7 +3501,7 @@ do_mal_round (void *cls) | |||
3682 | send_push (&attacked_peer); | 3501 | send_push (&attacked_peer); |
3683 | } | 3502 | } |
3684 | } | 3503 | } |
3685 | (void) Peers_issue_peer_liveliness_check (&attacked_peer); | 3504 | (void) issue_peer_liveliness_check (&attacked_peer); |
3686 | 3505 | ||
3687 | /* The maximum of pushes we're going to send this round */ | 3506 | /* The maximum of pushes we're going to send this round */ |
3688 | num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit - 1, | 3507 | num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit - 1, |
@@ -3799,7 +3618,7 @@ do_round (void *cls) | |||
3799 | for (i = first_border; i < second_border; i++) | 3618 | for (i = first_border; i < second_border; i++) |
3800 | { | 3619 | { |
3801 | peer = view_array[permut[i]]; | 3620 | peer = view_array[permut[i]]; |
3802 | if ( GNUNET_NO == Peers_check_peer_flag (&peer, Peers_PULL_REPLY_PENDING)) | 3621 | if ( GNUNET_NO == check_peer_flag (&peer, Peers_PULL_REPLY_PENDING)) |
3803 | { // FIXME if this fails schedule/loop this for later | 3622 | { // FIXME if this fails schedule/loop this for later |
3804 | send_pull_request (&peer); | 3623 | send_pull_request (&peer); |
3805 | } | 3624 | } |
@@ -4098,13 +3917,14 @@ shutdown_task (void *cls) | |||
4098 | do_round_task = NULL; | 3917 | do_round_task = NULL; |
4099 | } | 3918 | } |
4100 | 3919 | ||
4101 | Peers_terminate (); | 3920 | peers_terminate (); |
4102 | 3921 | ||
4103 | GNUNET_NSE_disconnect (nse); | 3922 | GNUNET_NSE_disconnect (nse); |
4104 | RPS_sampler_destroy (prot_sampler); | 3923 | RPS_sampler_destroy (prot_sampler); |
4105 | RPS_sampler_destroy (client_sampler); | 3924 | RPS_sampler_destroy (client_sampler); |
4106 | GNUNET_CADET_close_port (cadet_port); | 3925 | GNUNET_CADET_close_port (cadet_port); |
4107 | GNUNET_CADET_disconnect (cadet_handle); | 3926 | GNUNET_CADET_disconnect (cadet_handle); |
3927 | cadet_handle = NULL; | ||
4108 | View_destroy (); | 3928 | View_destroy (); |
4109 | CustomPeerMap_destroy (push_map); | 3929 | CustomPeerMap_destroy (push_map); |
4110 | CustomPeerMap_destroy (pull_map); | 3930 | CustomPeerMap_destroy (pull_map); |
@@ -4315,7 +4135,7 @@ run (void *cls, | |||
4315 | &port); | 4135 | &port); |
4316 | cadet_port = GNUNET_CADET_open_port (cadet_handle, | 4136 | cadet_port = GNUNET_CADET_open_port (cadet_handle, |
4317 | &port, | 4137 | &port, |
4318 | &Peers_handle_inbound_channel, /* Connect handler */ | 4138 | &handle_inbound_channel, /* Connect handler */ |
4319 | NULL, /* cls */ | 4139 | NULL, /* cls */ |
4320 | NULL, /* WindowSize handler */ | 4140 | NULL, /* WindowSize handler */ |
4321 | &cleanup_destroyed_channel, /* Disconnect handler */ | 4141 | &cleanup_destroyed_channel, /* Disconnect handler */ |
@@ -4330,7 +4150,7 @@ run (void *cls, | |||
4330 | 4150 | ||
4331 | 4151 | ||
4332 | peerinfo_handle = GNUNET_PEERINFO_connect (cfg); | 4152 | peerinfo_handle = GNUNET_PEERINFO_connect (cfg); |
4333 | Peers_initialise (fn_valid_peers, cadet_handle); | 4153 | initialise_peers (fn_valid_peers, cadet_handle); |
4334 | GNUNET_free (fn_valid_peers); | 4154 | GNUNET_free (fn_valid_peers); |
4335 | 4155 | ||
4336 | /* Initialise sampler */ | 4156 | /* Initialise sampler */ |
@@ -4353,7 +4173,7 @@ run (void *cls, | |||
4353 | // TODO send push/pull to each of those peers? | 4173 | // TODO send push/pull to each of those peers? |
4354 | // TODO read stored valid peers from last run | 4174 | // TODO read stored valid peers from last run |
4355 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n"); | 4175 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n"); |
4356 | Peers_get_valid_peers (valid_peers_iterator, NULL); | 4176 | get_valid_peers (valid_peers_iterator, NULL); |
4357 | 4177 | ||
4358 | peerinfo_notify_handle = GNUNET_PEERINFO_notify (cfg, | 4178 | peerinfo_notify_handle = GNUNET_PEERINFO_notify (cfg, |
4359 | GNUNET_NO, | 4179 | GNUNET_NO, |
diff --git a/src/rps/gnunet-service-rps_custommap.c b/src/rps/gnunet-service-rps_custommap.c index 9e003eb39..3513ff8da 100644 --- a/src/rps/gnunet-service-rps_custommap.c +++ b/src/rps/gnunet-service-rps_custommap.c | |||
@@ -202,6 +202,7 @@ CustomPeerMap_remove_peer (const struct CustomPeerMap *c_peer_map, | |||
202 | p = GNUNET_CONTAINER_multihashmap32_get (c_peer_map->hash_map, *index); | 202 | p = GNUNET_CONTAINER_multihashmap32_get (c_peer_map->hash_map, *index); |
203 | GNUNET_assert (NULL != p); | 203 | GNUNET_assert (NULL != p); |
204 | GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map, *index); | 204 | GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map, *index); |
205 | // TODO wrong peerid? | ||
205 | GNUNET_CONTAINER_multipeermap_remove_all (c_peer_map->peer_map, peer); | 206 | GNUNET_CONTAINER_multipeermap_remove_all (c_peer_map->peer_map, peer); |
206 | if (*index != CustomPeerMap_size (c_peer_map)) | 207 | if (*index != CustomPeerMap_size (c_peer_map)) |
207 | { /* fill 'gap' with peer at last index */ | 208 | { /* fill 'gap' with peer at last index */ |
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c index 08fe96097..ed682c251 100644 --- a/src/rps/rps-test_util.c +++ b/src/rps/rps-test_util.c | |||
@@ -239,7 +239,7 @@ to_file_raw_unaligned (const char *file_name, | |||
239 | /* needed bits of the input byte that have not been moved */ | 239 | /* needed bits of the input byte that have not been moved */ |
240 | char byte_input_leftover; | 240 | char byte_input_leftover; |
241 | unsigned num_bits_leftover; | 241 | unsigned num_bits_leftover; |
242 | unsigned num_bits_discard; | 242 | //unsigned num_bits_discard; |
243 | char byte_unaligned_new; | 243 | char byte_unaligned_new; |
244 | 244 | ||
245 | if ( (bits_needed - (i * 8)) <= 8) | 245 | if ( (bits_needed - (i * 8)) <= 8) |
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c index 08424022f..92d8c12ea 100644 --- a/src/rps/test_rps.c +++ b/src/rps/test_rps.c | |||
@@ -2850,7 +2850,7 @@ main (int argc, char *argv[]) | |||
2850 | { | 2850 | { |
2851 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n"); | 2851 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n"); |
2852 | cur_test_run.name = "test-rps-profiler"; | 2852 | cur_test_run.name = "test-rps-profiler"; |
2853 | num_peers = 100; | 2853 | num_peers = 16; |
2854 | mal_type = 3; | 2854 | mal_type = 3; |
2855 | cur_test_run.init_peer = profiler_init_peer; | 2855 | cur_test_run.init_peer = profiler_init_peer; |
2856 | //cur_test_run.pre_test = mal_pre; | 2856 | //cur_test_run.pre_test = mal_pre; |
diff --git a/src/rps/test_rps.conf b/src/rps/test_rps.conf index 05bb9f444..84e0e5049 100644 --- a/src/rps/test_rps.conf +++ b/src/rps/test_rps.conf | |||
@@ -1,6 +1,7 @@ | |||
1 | [rps] | 1 | [rps] |
2 | #PREFIX = valgrind --leak-check=full --show-leak-kinds=all --log-file=/tmp/rps/valgrind!gnunet-service-rps!%p | 2 | #PREFIX = valgrind --leak-check=full --show-leak-kinds=all --log-file=/tmp/rps/valgrind!gnunet-service-rps!%p |
3 | #BINARY = gnunet-service-rps | 3 | #PREFIX = valgrind --log-file=/tmp/rps/valgrind!gnunet-service-rps!%p |
4 | #PREFIX = valgrind | ||
4 | UNIXPATH = $GNUNET_TMP/gnunet-service-rps.sock | 5 | UNIXPATH = $GNUNET_TMP/gnunet-service-rps.sock |
5 | HOME = $SERVICEHOME | 6 | HOME = $SERVICEHOME |
6 | # PORT = 2106 | 7 | # PORT = 2106 |