aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am6
-rw-r--r--src/arm/arm_api.c8
-rw-r--r--src/cadet/gnunet-service-cadet.c3
-rw-r--r--src/cadet/gnunet-service-cadet_channel.c1
-rw-r--r--src/gns/Makefile.am3
-rw-r--r--src/gns/gnunet-bcd.c22
-rw-r--r--src/gns/gnunet-dns2gns.c8
-rw-r--r--src/gns/gnunet-gns-proxy.c23
-rw-r--r--src/gns/gnunet-service-gns_interceptor.c1
-rw-r--r--src/gns/gnunet-service-gns_resolver.c27
-rw-r--r--src/gns/plugin_rest_gns.c4
-rw-r--r--src/gnsrecord/gnsrecord_misc.c17
-rw-r--r--src/gnsrecord/gnunet-gnsrecord-tvg.c2
-rw-r--r--src/include/gnunet_testbed_ng_service.h247
-rw-r--r--src/include/gnunet_testbed_service.h2
-rw-r--r--src/messenger/Makefile.am39
-rwxr-xr-x[-rw-r--r--]src/messenger/gnunet-messenger.c14
-rwxr-xr-x[-rw-r--r--]src/messenger/gnunet-service-messenger.c4
-rwxr-xr-x[-rw-r--r--]src/messenger/gnunet-service-messenger_member.c10
-rwxr-xr-x[-rw-r--r--]src/messenger/gnunet-service-messenger_message_store.c10
-rwxr-xr-x[-rw-r--r--]src/messenger/gnunet-service-messenger_operation_store.c4
-rwxr-xr-x[-rw-r--r--]src/messenger/messenger_api_contact_store.c9
-rwxr-xr-x[-rw-r--r--]src/messenger/messenger_api_message.c2
-rwxr-xr-x[-rw-r--r--]src/messenger/messenger_api_room.c16
-rwxr-xr-x[-rw-r--r--]src/messenger/messenger_api_room.h6
-rw-r--r--src/namestore/gnunet-service-namestore.c16
-rw-r--r--src/namestore/namestore_api.c6
-rw-r--r--src/namestore/plugin_rest_namestore.c2
-rw-r--r--src/peerinfo-tool/plugin_rest_peerinfo.c4
-rw-r--r--src/peerstore/peerstore_api.c5
-rw-r--r--src/peerstore/test_peerstore_api_sync.c87
-rw-r--r--src/reclaim/gnunet-service-reclaim.c5
-rw-r--r--src/reclaim/gnunet-service-reclaim_tickets.c15
-rw-r--r--src/reclaim/oidc_helper.c14
-rw-r--r--src/reclaim/plugin_rest_openid_connect.c50
-rw-r--r--src/reclaim/plugin_rest_reclaim.c131
-rw-r--r--src/reclaim/reclaim_api.c20
-rw-r--r--src/rest/plugin_rest_copying.c6
-rw-r--r--src/revocation/gnunet-revocation.c14
-rw-r--r--src/revocation/gnunet-service-revocation.c12
-rw-r--r--src/revocation/plugin_block_revocation.c9
-rw-r--r--src/revocation/revocation_api.c9
-rw-r--r--src/rps/gnunet-rps-profiler.c7
-rw-r--r--src/rps/gnunet-service-rps.c18
-rw-r--r--src/rps/gnunet-service-rps_custommap.c9
-rw-r--r--src/rps/rps-test_util.c16
-rw-r--r--src/testbed/Makefile.am3
-rw-r--r--src/testbed/testbed_api_cmd_controller.c294
-rw-r--r--src/testbed/testbed_api_cmd_peer.c249
-rw-r--r--src/testbed/testbed_api_cmd_service.c140
-rw-r--r--src/testing/testing_api_cmd_hello_world_birth.c6
-rw-r--r--src/transport/gnunet-communicator-tcp.c48
-rw-r--r--src/transport/gnunet-communicator-udp.c13
-rw-r--r--src/transport/gnunet-service-tng.c7
-rw-r--r--src/transport/transport-testing-communicator.c5
-rw-r--r--src/util/Makefile.am18
-rw-r--r--src/util/configuration.c1
-rw-r--r--src/util/container_meta_data.c7
-rw-r--r--src/util/crypto_rsa.c1
-rw-r--r--src/util/gnunet-crypto-tvg.c124
-rw-r--r--src/util/os_installation.c5
61 files changed, 1531 insertions, 333 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index d8a869acb..564923e28 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -45,6 +45,10 @@ if HAVE_POSTGRESQL
45 POSTGRES_DIR = pq 45 POSTGRES_DIR = pq
46endif 46endif
47 47
48if HAVE_NOLIBGCRYPT19
49 SCALARPRODUCT_DIR = scalarproduct
50endif
51
48REST_DIR = rest 52REST_DIR = rest
49 53
50 54
@@ -93,7 +97,7 @@ SUBDIRS = \
93 seti \ 97 seti \
94 setu \ 98 setu \
95 consensus \ 99 consensus \
96 scalarproduct \ 100 $(SCALARPRODUCT_DIR) \
97 revocation \ 101 revocation \
98 vpn \ 102 vpn \
99 gns \ 103 gns \
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c
index 899b6f152..2ec913a0a 100644
--- a/src/arm/arm_api.c
+++ b/src/arm/arm_api.c
@@ -951,7 +951,8 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
951 * 2) We're not connected to ARM. 951 * 2) We're not connected to ARM.
952 * Cancel any reconnection attempts temporarily, then perform 952 * Cancel any reconnection attempts temporarily, then perform
953 * a service test. 953 * a service test.
954 */if (GNUNET_YES == h->currently_up) 954 */
955 if (GNUNET_YES == h->currently_up)
955 { 956 {
956 LOG (GNUNET_ERROR_TYPE_DEBUG, 957 LOG (GNUNET_ERROR_TYPE_DEBUG,
957 "ARM is already running\n"); 958 "ARM is already running\n");
@@ -970,7 +971,8 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
970 yet complete the MQ handshake. However, given that users 971 yet complete the MQ handshake. However, given that users
971 are unlikely to hammer 'gnunet-arm -s' on a busy system, 972 are unlikely to hammer 'gnunet-arm -s' on a busy system,
972 the above check should catch 99.99% of the cases where ARM 973 the above check should catch 99.99% of the cases where ARM
973 is already running. */LOG (GNUNET_ERROR_TYPE_DEBUG, 974 is already running. */
975 LOG (GNUNET_ERROR_TYPE_DEBUG,
974 "Starting ARM service\n"); 976 "Starting ARM service\n");
975 if (NULL == (sig = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE))) 977 if (NULL == (sig = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE)))
976 { 978 {
@@ -1003,13 +1005,13 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
1003 op->rfd, 1005 op->rfd,
1004 &notify_starting, 1006 &notify_starting,
1005 op); 1007 op);
1008 GNUNET_DISK_pipe_close (sig);
1006 } 1009 }
1007 else 1010 else
1008 { 1011 {
1009 op->async = GNUNET_SCHEDULER_add_now (&notify_starting, 1012 op->async = GNUNET_SCHEDULER_add_now (&notify_starting,
1010 op); 1013 op);
1011 } 1014 }
1012 GNUNET_DISK_pipe_close (sig);
1013 return op; 1015 return op;
1014} 1016}
1015 1017
diff --git a/src/cadet/gnunet-service-cadet.c b/src/cadet/gnunet-service-cadet.c
index 2d3b548dd..c8d69e43d 100644
--- a/src/cadet/gnunet-service-cadet.c
+++ b/src/cadet/gnunet-service-cadet.c
@@ -1027,7 +1027,8 @@ handle_drop_message (void *cls,
1027 ch = lookup_channel (c, 1027 ch = lookup_channel (c,
1028 message->ccn); 1028 message->ccn);
1029 1029
1030 GCCH_assign_type_to_drop (ch, message); 1030 if (NULL != ch)
1031 GCCH_assign_type_to_drop (ch, message);
1031 1032
1032 GNUNET_SERVICE_client_continue (c->client); 1033 GNUNET_SERVICE_client_continue (c->client);
1033} 1034}
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c
index 6b22ae2b4..ae5d9210f 100644
--- a/src/cadet/gnunet-service-cadet_channel.c
+++ b/src/cadet/gnunet-service-cadet_channel.c
@@ -1858,6 +1858,7 @@ GCCH_handle_local_data (struct CadetChannel *ch,
1858 } 1858 }
1859 else 1859 else
1860 { 1860 {
1861 GNUNET_free (env);
1861 GNUNET_break (0); 1862 GNUNET_break (0);
1862 return GNUNET_SYSERR; 1863 return GNUNET_SYSERR;
1863 } 1864 }
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 9f03311e1..3aaa734f2 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -80,9 +80,7 @@ bin_PROGRAMS = \
80noinst_PROGRAMS = \ 80noinst_PROGRAMS = \
81 gnunet-gns-benchmark 81 gnunet-gns-benchmark
82 82
83if LINUX
84bin_PROGRAMS += gnunet-bcd 83bin_PROGRAMS += gnunet-bcd
85endif
86 84
87REST_PLUGIN = libgnunet_plugin_rest_gns.la 85REST_PLUGIN = libgnunet_plugin_rest_gns.la
88 86
@@ -156,6 +154,7 @@ gnunet_bcd_SOURCES = \
156 gnunet-bcd.c 154 gnunet-bcd.c
157gnunet_bcd_LDADD = \ 155gnunet_bcd_LDADD = \
158 $(top_builddir)/src/util/libgnunetutil.la \ 156 $(top_builddir)/src/util/libgnunetutil.la \
157 $(top_builddir)/src/identity/libgnunetidentity.la \
159 $(GN_LIBINTL) $(MHD_LIBS) 158 $(GN_LIBINTL) $(MHD_LIBS)
160gnunet_bcd_CFLAGS = $(MHD_CFLAGS) $(AM_CFLAGS) 159gnunet_bcd_CFLAGS = $(MHD_CFLAGS) $(AM_CFLAGS)
161 160
diff --git a/src/gns/gnunet-bcd.c b/src/gns/gnunet-bcd.c
index f71f477ef..a2e94089c 100644
--- a/src/gns/gnunet-bcd.c
+++ b/src/gns/gnunet-bcd.c
@@ -27,6 +27,7 @@
27#include "platform.h" 27#include "platform.h"
28#include <microhttpd.h> 28#include <microhttpd.h>
29#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
30#include "gnunet_identity_service.h"
30#include "gnunet_mhd_compat.h" 31#include "gnunet_mhd_compat.h"
31 32
32/** 33/**
@@ -148,7 +149,7 @@ access_handler_callback (void *cls,
148 char *p; 149 char *p;
149 char *tmp; 150 char *tmp;
150 char *deffile; 151 char *deffile;
151 struct GNUNET_CRYPTO_EcdsaPublicKey pub; 152 struct GNUNET_IDENTITY_PublicKey pub;
152 size_t slen; 153 size_t slen;
153 FILE *f; 154 FILE *f;
154 struct stat st; 155 struct stat st;
@@ -166,9 +167,8 @@ access_handler_callback (void *cls,
166 MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "gnskey"); 167 MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "gnskey");
167 if ((NULL == gnskey) || 168 if ((NULL == gnskey) ||
168 (GNUNET_OK != 169 (GNUNET_OK !=
169 GNUNET_CRYPTO_ecdsa_public_key_from_string (gnskey, 170 GNUNET_IDENTITY_public_key_from_string (gnskey,
170 strlen (gnskey), 171 &pub)))
171 &pub)))
172 { 172 {
173 return MHD_queue_response (connection, 173 return MHD_queue_response (connection,
174 MHD_HTTP_OK, 174 MHD_HTTP_OK,
@@ -218,10 +218,10 @@ access_handler_callback (void *cls,
218 (NULL == gns_nick) ? "" : gns_nick); 218 (NULL == gns_nick) ? "" : gns_nick);
219 fclose (f); 219 fclose (f);
220 GNUNET_asprintf ( 220 GNUNET_asprintf (
221 &p, 221 &p,
222 "cd %s; cp %s gns-bcd.tex | pdflatex --enable-write18 gns-bcd.tex > /dev/null 2> /dev/null", 222 "cd %s; cp %s gns-bcd.tex | pdflatex --enable-write18 gns-bcd.tex > /dev/null 2> /dev/null",
223 tmp, 223 tmp,
224 resfile); 224 resfile);
225 GNUNET_free (deffile); 225 GNUNET_free (deffile);
226 ret = system (p); 226 ret = system (p);
227 if (WIFSIGNALED (ret) || (0 != WEXITSTATUS (ret))) 227 if (WIFSIGNALED (ret) || (0 != WEXITSTATUS (ret)))
@@ -506,7 +506,7 @@ main (int argc, char *const *argv)
506 "port", 506 "port",
507 "PORT", 507 "PORT",
508 gettext_noop ( 508 gettext_noop (
509 "Run HTTP serve on port PORT (default is 8888)"), 509 "Run HTTP serve on port PORT (default is 8888)"),
510 &port), 510 &port),
511 GNUNET_GETOPT_OPTION_END 511 GNUNET_GETOPT_OPTION_END
512 }; 512 };
@@ -523,8 +523,8 @@ main (int argc, char *const *argv)
523 options, 523 options,
524 &run, 524 &run,
525 NULL)) 525 NULL))
526 ? 0 526 ? 0
527 : 1; 527 : 1;
528 GNUNET_free_nz ((void *) argv); 528 GNUNET_free_nz ((void *) argv);
529 return ret; 529 return ret;
530} 530}
diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c
index 0a9b7c861..06f4c9841 100644
--- a/src/gns/gnunet-dns2gns.c
+++ b/src/gns/gnunet-dns2gns.c
@@ -309,6 +309,14 @@ dns_result_processor (void *cls,
309 } 309 }
310 request->packet = GNUNET_DNSPARSER_parse ((char *) dns, 310 request->packet = GNUNET_DNSPARSER_parse ((char *) dns,
311 r); 311 r);
312 if (NULL == request->packet)
313 {
314 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
315 _ ("Failed to parse DNS response!\n"));
316 GNUNET_SCHEDULER_cancel (request->timeout_task);
317 do_timeout (request);
318 return;
319 }
312 GNUNET_DNSSTUB_resolve_cancel (request->dns_lookup); 320 GNUNET_DNSSTUB_resolve_cancel (request->dns_lookup);
313 send_response (request); 321 send_response (request);
314} 322}
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index 833a8da01..d02f0f576 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -1841,6 +1841,7 @@ create_response (void *cls,
1841 char *curlurl; 1841 char *curlurl;
1842 char ipstring[INET6_ADDRSTRLEN]; 1842 char ipstring[INET6_ADDRSTRLEN];
1843 char ipaddr[INET6_ADDRSTRLEN + 2]; 1843 char ipaddr[INET6_ADDRSTRLEN + 2];
1844 char *curl_hosts;
1844 const struct sockaddr *sa; 1845 const struct sockaddr *sa;
1845 const struct sockaddr_in *s4; 1846 const struct sockaddr_in *s4;
1846 const struct sockaddr_in6 *s6; 1847 const struct sockaddr_in6 *s6;
@@ -1900,6 +1901,14 @@ create_response (void *cls,
1900 GNUNET_break (0); 1901 GNUNET_break (0);
1901 return MHD_NO; 1902 return MHD_NO;
1902 } 1903 }
1904 GNUNET_asprintf (&curl_hosts,
1905 "%s:%d:%s",
1906 s5r->leho,
1907 port,
1908 ipaddr);
1909 s5r->hosts = curl_slist_append (NULL,
1910 curl_hosts);
1911 GNUNET_free (curl_hosts);
1903 } 1912 }
1904 else 1913 else
1905 { 1914 {
@@ -1949,21 +1958,13 @@ create_response (void *cls,
1949 * Pre-populate cache to resolve Hostname. 1958 * Pre-populate cache to resolve Hostname.
1950 * This is necessary as the DNS name in the CURLOPT_URL is used 1959 * This is necessary as the DNS name in the CURLOPT_URL is used
1951 * for SNI http://de.wikipedia.org/wiki/Server_Name_Indication 1960 * for SNI http://de.wikipedia.org/wiki/Server_Name_Indication
1952 */if (NULL != s5r->leho) 1961 */
1962 if ((NULL != s5r->leho) &&
1963 (NULL != s5r->hosts))
1953 { 1964 {
1954 char *curl_hosts;
1955
1956 GNUNET_asprintf (&curl_hosts,
1957 "%s:%d:%s",
1958 s5r->leho,
1959 port,
1960 ipaddr);
1961 s5r->hosts = curl_slist_append (NULL,
1962 curl_hosts);
1963 curl_easy_setopt (s5r->curl, 1965 curl_easy_setopt (s5r->curl,
1964 CURLOPT_RESOLVE, 1966 CURLOPT_RESOLVE,
1965 s5r->hosts); 1967 s5r->hosts);
1966 GNUNET_free (curl_hosts);
1967 } 1968 }
1968 if (s5r->is_gns) 1969 if (s5r->is_gns)
1969 { 1970 {
diff --git a/src/gns/gnunet-service-gns_interceptor.c b/src/gns/gnunet-service-gns_interceptor.c
index b53f4af6b..255f85598 100644
--- a/src/gns/gnunet-service-gns_interceptor.c
+++ b/src/gns/gnunet-service-gns_interceptor.c
@@ -323,7 +323,6 @@ handle_dns_request (void *cls,
323 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 323 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
324 "Received malformed DNS packet, leaving it untouched.\n"); 324 "Received malformed DNS packet, leaving it untouched.\n");
325 GNUNET_DNS_request_forward (rh); 325 GNUNET_DNS_request_forward (rh);
326 GNUNET_DNSPARSER_free_packet (p);
327 return; 326 return;
328 } 327 }
329 328
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 49c1b340a..2f8a55804 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -764,6 +764,7 @@ transmit_lookup_dns_result (struct GNS_ResolverHandle *rh)
764 rd[i].data = pos->data; 764 rd[i].data = pos->data;
765 rd[i].data_size = pos->data_size; 765 rd[i].data_size = pos->data_size;
766 rd[i].record_type = pos->record_type; 766 rd[i].record_type = pos->record_type;
767 rd[i].flags = GNUNET_GNSRECORD_RF_NONE;
767 /** 768 /**
768 * If this is a LEHO, we added this before. It must be a supplemental 769 * If this is a LEHO, we added this before. It must be a supplemental
769 * record #LSD0001 770 * record #LSD0001
@@ -772,12 +773,11 @@ transmit_lookup_dns_result (struct GNS_ResolverHandle *rh)
772 rd[i].flags |= GNUNET_GNSRECORD_RF_SUPPLEMENTAL; 773 rd[i].flags |= GNUNET_GNSRECORD_RF_SUPPLEMENTAL;
773 if (0 == pos->expiration_time) 774 if (0 == pos->expiration_time)
774 { 775 {
775 rd[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 776 rd[i].flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
776 rd[i].expiration_time = 0; 777 rd[i].expiration_time = 0;
777 } 778 }
778 else 779 else
779 { 780 {
780 rd[i].flags = GNUNET_GNSRECORD_RF_NONE;
781 rd[i].expiration_time = pos->expiration_time; 781 rd[i].expiration_time = pos->expiration_time;
782 } 782 }
783 i++; 783 i++;
@@ -1764,6 +1764,8 @@ recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh,
1764 /** 1764 /**
1765 * Records other than GNS2DNS not allowed 1765 * Records other than GNS2DNS not allowed
1766 */ 1766 */
1767 if (NULL != ns)
1768 GNUNET_free (ns);
1767 return GNUNET_SYSERR; 1769 return GNUNET_SYSERR;
1768 } 1770 }
1769 off = 0; 1771 off = 0;
@@ -1771,15 +1773,22 @@ recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh,
1771 rd[i].data_size, 1773 rd[i].data_size,
1772 &off); 1774 &off);
1773 ip = GNUNET_strdup (&((const char *) rd[i].data)[off]); 1775 ip = GNUNET_strdup (&((const char *) rd[i].data)[off]);
1776 if ((NULL == n) ||
1777 (NULL == ip))
1778 {
1779 GNUNET_break_op (0);
1780 if (NULL != n)
1781 GNUNET_free (n);
1782 if (NULL != ip)
1783 GNUNET_free (ip);
1784 continue;
1785 }
1786
1774 off += strlen (ip) + 1; 1787 off += strlen (ip) + 1;
1775 1788
1776 if ((NULL == n) || 1789 if (off != rd[i].data_size)
1777 (NULL == ip) ||
1778 (off != rd[i].data_size))
1779 { 1790 {
1780 GNUNET_break_op (0); 1791 GNUNET_break_op (0);
1781 GNUNET_free (n);
1782 GNUNET_free (ip);
1783 continue; 1792 continue;
1784 } 1793 }
1785 /* resolve 'ip' to determine the IP(s) of the DNS 1794 /* resolve 'ip' to determine the IP(s) of the DNS
@@ -1909,6 +1918,8 @@ recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh,
1909 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1918 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1910 _ ("Name `%s' cannot be converted to IDNA."), 1919 _ ("Name `%s' cannot be converted to IDNA."),
1911 tmp); 1920 tmp);
1921 GNUNET_free (tmp);
1922 GNUNET_free (ac);
1912 return GNUNET_SYSERR; 1923 return GNUNET_SYSERR;
1913 } 1924 }
1914 GNUNET_free (tmp); 1925 GNUNET_free (tmp);
@@ -1922,6 +1933,8 @@ recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh,
1922 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1933 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1923 _ ("GNS lookup resulted in DNS name that is too long (`%s')\n"), 1934 _ ("GNS lookup resulted in DNS name that is too long (`%s')\n"),
1924 ac->label); 1935 ac->label);
1936 GNUNET_free (ac->label);
1937 GNUNET_free (ac);
1925 return GNUNET_SYSERR; 1938 return GNUNET_SYSERR;
1926 } 1939 }
1927 continue_with_gns2dns (ac); 1940 continue_with_gns2dns (ac);
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c
index 2ccb5be2b..3a35c9999 100644
--- a/src/gns/plugin_rest_gns.c
+++ b/src/gns/plugin_rest_gns.c
@@ -270,7 +270,9 @@ handle_gns_response (void *cls,
270 result = json_dumps (result_obj, 0); 270 result = json_dumps (result_obj, 0);
271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result); 271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result);
272 resp = GNUNET_REST_create_response (result); 272 resp = GNUNET_REST_create_response (result);
273 MHD_add_response_header (resp, "Content-Type", "application/json"); 273 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
274 "Content-Type",
275 "application/json"));
274 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 276 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
275 GNUNET_free (result); 277 GNUNET_free (result);
276 json_decref (result_obj); 278 json_decref (result_obj);
diff --git a/src/gnsrecord/gnsrecord_misc.c b/src/gnsrecord/gnsrecord_misc.c
index 82c38f19a..b907eed27 100644
--- a/src/gnsrecord/gnsrecord_misc.c
+++ b/src/gnsrecord/gnsrecord_misc.c
@@ -296,15 +296,20 @@ GNUNET_GNSRECORD_data_from_identity (const struct
296 size_t *data_size, 296 size_t *data_size,
297 uint32_t *type) 297 uint32_t *type)
298{ 298{
299 char *tmp;
299 *type = ntohl (key->type); 300 *type = ntohl (key->type);
300 *data_size = GNUNET_IDENTITY_key_get_length (key); 301 *data_size = GNUNET_IDENTITY_key_get_length (key);
301 if (0 == *data_size) 302 if (0 == *data_size)
302 return GNUNET_SYSERR; 303 return GNUNET_SYSERR;
303 *data = GNUNET_malloc (*data_size); 304 tmp = GNUNET_malloc (*data_size);
304 return (GNUNET_IDENTITY_write_key_to_buffer (key, *data, *data_size) == 305 if (GNUNET_IDENTITY_write_key_to_buffer (key, tmp, *data_size)
305 *data_size? 306 != *data_size) {
306 GNUNET_OK : 307 GNUNET_free (tmp);
307 GNUNET_SYSERR); 308 *data_size = 0;
309 return GNUNET_SYSERR;
310 }
311 *data = tmp;
312 return GNUNET_OK;
308} 313}
309 314
310 315
@@ -350,7 +355,7 @@ GNUNET_GNSRECORD_block_get_expiration (const struct
350 case GNUNET_GNSRECORD_TYPE_PKEY: 355 case GNUNET_GNSRECORD_TYPE_PKEY:
351 return GNUNET_TIME_absolute_ntoh (block->ecdsa_block.expiration_time); 356 return GNUNET_TIME_absolute_ntoh (block->ecdsa_block.expiration_time);
352 default: 357 default:
353 return GNUNET_TIME_absolute_get_zero_ (); 358 GNUNET_break (0); /* Hopefully we never get here, but we might */
354 } 359 }
355 return GNUNET_TIME_absolute_get_zero_ (); 360 return GNUNET_TIME_absolute_get_zero_ ();
356 361
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c b/src/gnsrecord/gnunet-gnsrecord-tvg.c
index 47b13bdab..d6b35544c 100644
--- a/src/gnsrecord/gnunet-gnsrecord-tvg.c
+++ b/src/gnsrecord/gnunet-gnsrecord-tvg.c
@@ -172,7 +172,7 @@ run (void *cls,
172 fprintf (stdout, "RRBLOCK:\n"); 172 fprintf (stdout, "RRBLOCK:\n");
173 print_bytes (rrblock, block_size, 8); 173 print_bytes (rrblock, block_size, 8);
174 fprintf (stdout, "\n"); 174 fprintf (stdout, "\n");
175 175 GNUNET_free (rdata);
176} 176}
177 177
178 178
diff --git a/src/include/gnunet_testbed_ng_service.h b/src/include/gnunet_testbed_ng_service.h
new file mode 100644
index 000000000..a6f30889f
--- /dev/null
+++ b/src/include/gnunet_testbed_ng_service.h
@@ -0,0 +1,247 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author t3sserakt
23 *
24 * @file
25 * API for writing tests and creating large-scale emulation testbeds for GNUnet with command pattern.
26 *
27 * @defgroup testbed Testbed service
28 * Writing tests and creating large-scale emulation testbeds for GNUnet with command pattern.
29 *
30 * @see [Documentation](https://docs.gnunet.org/handbook/gnunet.html#TESTBED-NG-Subsystem)
31 *
32 * @{
33 */
34
35#ifndef GNUNET_TESTBED_NG_SERVICE_H
36#define GNUNET_TESTBED_NG_SERVICE_H
37
38#include "gnunet_util_lib.h"
39#include "gnunet_testing_ng_lib.h"
40
41struct ServiceState
42{
43 /**
44 * Handle to operation
45 */
46 struct GNUNET_TESTBED_Operation *operation;
47
48 /**
49 * Flag indicating if service is ready.
50 */
51 int service_ready;
52
53 /**
54 * Abort task identifier
55 */
56 struct GNUNET_SCHEDULER_Task *abort_task;
57
58 /**
59 * Label of peer command.
60 */
61 const char *peer_label;
62
63 /**
64 * Name of service to start.
65 */
66 const char *servicename;
67};
68
69struct PeerCmdState
70{
71 /**
72 * The label of a controller command.
73 */
74 const char *controller_label;
75
76 /**
77 * Handle to operation
78 */
79 struct GNUNET_TESTBED_Operation *operation;
80
81 /**
82 * Name of the host, use "NULL" for localhost.
83 */
84 const char *hostname;
85
86 /**
87 * Username to use for the login; may be NULL.
88 */
89 const char *username;
90
91 /**
92 * Port number to use for ssh; use 0 to let ssh decide.
93 */
94 uint16_t port;
95
96 /**
97 * The configuration to use as a template while starting a controller
98 * on this host. Operation queue sizes specific to a host are also
99 * read from this configuration handle.
100 */
101 struct GNUNET_CONFIGURATION_Handle *cfg;
102
103 /**
104 * The host to run peers and controllers on
105 */
106 struct GNUNET_TESTBED_Host *host;
107
108 /**
109 * Abort task identifier
110 */
111 struct GNUNET_SCHEDULER_Task *abort_task;
112
113 /**
114 * Handle for host registration
115 */
116 struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;
117
118 /**
119 * Flag indicating if peer is ready.
120 */
121 int peer_ready;
122
123 /**
124 * Flag indicating controller is going down.
125 */
126 int peer_going_down;
127
128 /**
129 * Interpreter state.
130 */
131 struct GNUNET_TESTING_Interpreter *is;
132
133 /**
134 * Peer to start
135 */
136 struct GNUNET_TESTBED_Peer *peer;
137};
138
139struct ControllerState
140{
141 /**
142 * The ip address of the controller which will be set as TRUSTED
143 * HOST(all connections form this ip are permitted by the testbed) when
144 * starting testbed controller at host. This can either be a single ip
145 * address or a network address in CIDR notation.
146 */
147 const char *trusted_ip;
148
149 /**
150 * Name of the host, use "NULL" for localhost.
151 */
152 const char *hostname;
153
154 /**
155 * Username to use for the login; may be NULL.
156 */
157 const char *username;
158
159 /**
160 * Port number to use for ssh; use 0 to let ssh decide.
161 */
162 uint16_t port;
163
164 /**
165 * The configuration to use as a template while starting a controller
166 * on this host. Operation queue sizes specific to a host are also
167 * read from this configuration handle.
168 */
169 struct GNUNET_CONFIGURATION_Handle *cfg;
170
171 /**
172 * The host to run peers and controllers on
173 */
174 struct GNUNET_TESTBED_Host *host;
175
176 /**
177 * The controller process
178 */
179 struct GNUNET_TESTBED_ControllerProc *cp;
180
181 /**
182 * The controller handle
183 */
184 struct GNUNET_TESTBED_Controller *controller;
185
186 /**
187 * A bit mask with set of events to call the controller for.
188 */
189 uint64_t event_mask;
190
191 /**
192 * Abort task identifier
193 */
194 struct GNUNET_SCHEDULER_Task *abort_task;
195
196 /**
197 * Handle for host registration
198 */
199 struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;
200
201 /**
202 * Flag indicating if host create with controller is ready.
203 */
204 int host_ready;
205
206 /**
207 * Flag indicating controller is going down.
208 */
209 int controller_going_down;
210
211 /**
212 * Interpreter state.
213 */
214 struct GNUNET_TESTING_Interpreter *is;
215};
216
217/**
218 * Offer data from trait
219 *
220 * @param cmd command to extract the controller from.
221 * @param pt pointer to controller.
222 * @return #GNUNET_OK on success.
223 */
224int
225GNUNET_TESTBED_get_trait_controller (const struct GNUNET_TESTING_Command *cmd,
226 struct GNUNET_TESTBED_Controller **
227 controller);
228
229struct GNUNET_TESTING_Command
230GNUNET_TESTBED_cmd_controller (const char *label,
231 const char *trusted_ip,
232 const char *hostname,
233 const char *username,
234 uint16_t port,
235 struct GNUNET_CONFIGURATION_Handle *cfg,
236 uint64_t event_mask);
237
238void
239GNUNET_TESTBED_shutdown_controller (struct ControllerState *cs);
240
241void
242GNUNET_TESTBED_shutdown_peer (struct PeerCmdState *ps);
243
244void
245GNUNET_TESTBED_shutdown_service (struct ServiceState *ss);
246
247#endif
diff --git a/src/include/gnunet_testbed_service.h b/src/include/gnunet_testbed_service.h
index 70cbfa90d..acdfb2034 100644
--- a/src/include/gnunet_testbed_service.h
+++ b/src/include/gnunet_testbed_service.h
@@ -27,7 +27,7 @@
27 * @defgroup testbed Testbed service 27 * @defgroup testbed Testbed service
28 * Writing tests and creating large-scale emulation testbeds for GNUnet. 28 * Writing tests and creating large-scale emulation testbeds for GNUnet.
29 * 29 *
30 * @see [Documentation](https://gnunet.org/gnunet-testbed-subsystem) 30 * @see [Documentation](https://docs.gnunet.org/handbook/gnunet.html#TESTBED-Subsystem)
31 * 31 *
32 * @{ 32 * @{
33 */ 33 */
diff --git a/src/messenger/Makefile.am b/src/messenger/Makefile.am
index 1ebfbe5ed..2bb9ad922 100644
--- a/src/messenger/Makefile.am
+++ b/src/messenger/Makefile.am
@@ -25,35 +25,23 @@ bin_PROGRAMS = \
25 gnunet-messenger 25 gnunet-messenger
26 26
27lib_LTLIBRARIES = \ 27lib_LTLIBRARIES = \
28 libgnunetmessenger_common.la \
29 libgnunetmessenger.la \ 28 libgnunetmessenger.la \
30 $(EXP_LIB) 29 $(EXP_LIB)
31 30
32libgnunetmessenger_common_la_SOURCES = \ 31libgnunetmessenger_la_SOURCES = \
32 messenger_api.c \
33 messenger_api_ego.h \ 33 messenger_api_ego.h \
34 messenger_api_contact.c messenger_api_contact.h \ 34 messenger_api_contact.c messenger_api_contact.h \
35 messenger_api_contact_store.c messenger_api_contact_store.h \ 35 messenger_api_contact_store.c messenger_api_contact_store.h \
36 messenger_api_message.c messenger_api_message.h \ 36 messenger_api_message.c messenger_api_message.h \
37 messenger_api_list_tunnels.c messenger_api_list_tunnels.h \ 37 messenger_api_list_tunnels.c messenger_api_list_tunnels.h \
38 messenger_api_util.c messenger_api_util.h 38 messenger_api_util.c messenger_api_util.h \
39libgnunetmessenger_common_la_LIBADD = \
40 $(top_builddir)/src/util/libgnunetutil.la \
41 $(top_builddir)/src/cadet/libgnunetcadet.la \
42 $(top_builddir)/src/identity/libgnunetidentity.la \
43 $(XLIB) \
44 $(LTLIBINTL)
45libgnunetmessenger_common_la_LDFLAGS = \
46 $(GN_LIB_LDFLAGS) \
47 -version-info 0:0:0
48
49libgnunetmessenger_la_SOURCES = \
50 messenger_api.c \
51 messenger_api_handle.c messenger_api_handle.h \ 39 messenger_api_handle.c messenger_api_handle.h \
52 messenger_api_room.c messenger_api_room.h 40 messenger_api_room.c messenger_api_room.h
53libgnunetmessenger_la_LIBADD = \ 41libgnunetmessenger_la_LIBADD = \
54 $(top_builddir)/src/util/libgnunetutil.la \ 42 $(top_builddir)/src/util/libgnunetutil.la \
43 $(top_builddir)/src/cadet/libgnunetcadet.la \
55 $(top_builddir)/src/identity/libgnunetidentity.la \ 44 $(top_builddir)/src/identity/libgnunetidentity.la \
56 libgnunetmessenger_common.la \
57 $(XLIB) \ 45 $(XLIB) \
58 $(LTLIBINTL) 46 $(LTLIBINTL)
59libgnunetmessenger_la_LDFLAGS = \ 47libgnunetmessenger_la_LDFLAGS = \
@@ -63,10 +51,8 @@ libgnunetmessenger_la_LDFLAGS = \
63gnunet_messenger_SOURCES = \ 51gnunet_messenger_SOURCES = \
64 gnunet-messenger.c 52 gnunet-messenger.c
65gnunet_messenger_LDADD = \ 53gnunet_messenger_LDADD = \
66 libgnunetmessenger_common.la \
67 libgnunetmessenger.la \ 54 libgnunetmessenger.la \
68 $(top_builddir)/src/util/libgnunetutil.la \ 55 $(top_builddir)/src/util/libgnunetutil.la
69 $(top_builddir)/src/identity/libgnunetidentity.la
70gnunet_messenger_LDFLAGS = \ 56gnunet_messenger_LDFLAGS = \
71 $(GN_LIBINTL) 57 $(GN_LIBINTL)
72 58
@@ -91,11 +77,10 @@ gnunet_service_messenger_SOURCES = \
91 gnunet-service-messenger_room.c gnunet-service-messenger_room.h \ 77 gnunet-service-messenger_room.c gnunet-service-messenger_room.h \
92 gnunet-service-messenger_tunnel.c gnunet-service-messenger_tunnel.h 78 gnunet-service-messenger_tunnel.c gnunet-service-messenger_tunnel.h
93gnunet_service_messenger_LDADD = \ 79gnunet_service_messenger_LDADD = \
80 libgnunetmessenger.la \
94 $(top_builddir)/src/util/libgnunetutil.la \ 81 $(top_builddir)/src/util/libgnunetutil.la \
95 $(top_builddir)/src/cadet/libgnunetcadet.la \ 82 $(top_builddir)/src/cadet/libgnunetcadet.la \
96 $(top_builddir)/src/identity/libgnunetidentity.la \ 83 $(top_builddir)/src/identity/libgnunetidentity.la \
97 libgnunetmessenger_common.la \
98 libgnunetmessenger.la \
99 $(GN_LIBINTL) 84 $(GN_LIBINTL)
100 85
101check_PROGRAMS = \ 86check_PROGRAMS = \
@@ -121,7 +106,6 @@ endif
121test_messenger_api_SOURCES = \ 106test_messenger_api_SOURCES = \
122 test_messenger.c 107 test_messenger.c
123test_messenger_api_LDADD = \ 108test_messenger_api_LDADD = \
124 libgnunetmessenger_common.la \
125 libgnunetmessenger.la \ 109 libgnunetmessenger.la \
126 $(top_builddir)/src/testing/libgnunettesting.la \ 110 $(top_builddir)/src/testing/libgnunettesting.la \
127 $(top_builddir)/src/util/libgnunetutil.la 111 $(top_builddir)/src/util/libgnunetutil.la
@@ -129,7 +113,6 @@ test_messenger_api_LDADD = \
129test_messenger_anonymous_SOURCES = \ 113test_messenger_anonymous_SOURCES = \
130 test_messenger_anonymous.c 114 test_messenger_anonymous.c
131test_messenger_anonymous_LDADD = \ 115test_messenger_anonymous_LDADD = \
132 libgnunetmessenger_common.la \
133 libgnunetmessenger.la \ 116 libgnunetmessenger.la \
134 $(top_builddir)/src/testing/libgnunettesting.la \ 117 $(top_builddir)/src/testing/libgnunettesting.la \
135 $(top_builddir)/src/util/libgnunetutil.la 118 $(top_builddir)/src/util/libgnunetutil.la
@@ -139,7 +122,6 @@ test_messenger_sync_client_SOURCES = \
139 testing_messenger_barrier.c testing_messenger_barrier.h \ 122 testing_messenger_barrier.c testing_messenger_barrier.h \
140 testing_messenger_setup.c testing_messenger_setup.h 123 testing_messenger_setup.c testing_messenger_setup.h
141test_messenger_sync_client_LDADD = \ 124test_messenger_sync_client_LDADD = \
142 libgnunetmessenger_common.la \
143 libgnunetmessenger.la \ 125 libgnunetmessenger.la \
144 $(top_builddir)/src/testbed/libgnunettestbed.la \ 126 $(top_builddir)/src/testbed/libgnunettestbed.la \
145 $(top_builddir)/src/testing/libgnunettesting.la \ 127 $(top_builddir)/src/testing/libgnunettesting.la \
@@ -150,7 +132,6 @@ test_messenger_async_client_SOURCES = \
150 testing_messenger_barrier.c testing_messenger_barrier.h \ 132 testing_messenger_barrier.c testing_messenger_barrier.h \
151 testing_messenger_setup.c testing_messenger_setup.h 133 testing_messenger_setup.c testing_messenger_setup.h
152test_messenger_async_client_LDADD = \ 134test_messenger_async_client_LDADD = \
153 libgnunetmessenger_common.la \
154 libgnunetmessenger.la \ 135 libgnunetmessenger.la \
155 $(top_builddir)/src/testbed/libgnunettestbed.la \ 136 $(top_builddir)/src/testbed/libgnunettestbed.la \
156 $(top_builddir)/src/testing/libgnunettesting.la \ 137 $(top_builddir)/src/testing/libgnunettesting.la \
@@ -161,7 +142,6 @@ test_messenger_worst_client_SOURCES = \
161 testing_messenger_barrier.c testing_messenger_barrier.h \ 142 testing_messenger_barrier.c testing_messenger_barrier.h \
162 testing_messenger_setup.c testing_messenger_setup.h 143 testing_messenger_setup.c testing_messenger_setup.h
163test_messenger_worst_client_LDADD = \ 144test_messenger_worst_client_LDADD = \
164 libgnunetmessenger_common.la \
165 libgnunetmessenger.la \ 145 libgnunetmessenger.la \
166 $(top_builddir)/src/testbed/libgnunettestbed.la \ 146 $(top_builddir)/src/testbed/libgnunettestbed.la \
167 $(top_builddir)/src/testing/libgnunettesting.la \ 147 $(top_builddir)/src/testing/libgnunettesting.la \
@@ -172,7 +152,6 @@ test_messenger_sync_p2p_SOURCES = \
172 testing_messenger_barrier.c testing_messenger_barrier.h \ 152 testing_messenger_barrier.c testing_messenger_barrier.h \
173 testing_messenger_setup.c testing_messenger_setup.h 153 testing_messenger_setup.c testing_messenger_setup.h
174test_messenger_sync_p2p_LDADD = \ 154test_messenger_sync_p2p_LDADD = \
175 libgnunetmessenger_common.la \
176 libgnunetmessenger.la \ 155 libgnunetmessenger.la \
177 $(top_builddir)/src/testbed/libgnunettestbed.la \ 156 $(top_builddir)/src/testbed/libgnunettestbed.la \
178 $(top_builddir)/src/testing/libgnunettesting.la \ 157 $(top_builddir)/src/testing/libgnunettesting.la \
@@ -183,7 +162,6 @@ test_messenger_async_p2p_SOURCES = \
183 testing_messenger_barrier.c testing_messenger_barrier.h \ 162 testing_messenger_barrier.c testing_messenger_barrier.h \
184 testing_messenger_setup.c testing_messenger_setup.h 163 testing_messenger_setup.c testing_messenger_setup.h
185test_messenger_async_p2p_LDADD = \ 164test_messenger_async_p2p_LDADD = \
186 libgnunetmessenger_common.la \
187 libgnunetmessenger.la \ 165 libgnunetmessenger.la \
188 $(top_builddir)/src/testbed/libgnunettestbed.la \ 166 $(top_builddir)/src/testbed/libgnunettestbed.la \
189 $(top_builddir)/src/testing/libgnunettesting.la \ 167 $(top_builddir)/src/testing/libgnunettesting.la \
@@ -194,7 +172,6 @@ test_messenger_worst_p2p_SOURCES = \
194 testing_messenger_barrier.c testing_messenger_barrier.h \ 172 testing_messenger_barrier.c testing_messenger_barrier.h \
195 testing_messenger_setup.c testing_messenger_setup.h 173 testing_messenger_setup.c testing_messenger_setup.h
196test_messenger_worst_p2p_LDADD = \ 174test_messenger_worst_p2p_LDADD = \
197 libgnunetmessenger_common.la \
198 libgnunetmessenger.la \ 175 libgnunetmessenger.la \
199 $(top_builddir)/src/testbed/libgnunettestbed.la \ 176 $(top_builddir)/src/testbed/libgnunettestbed.la \
200 $(top_builddir)/src/testing/libgnunettesting.la \ 177 $(top_builddir)/src/testing/libgnunettesting.la \
@@ -205,7 +182,6 @@ test_messenger_server_SOURCES = \
205 testing_messenger_barrier.c testing_messenger_barrier.h \ 182 testing_messenger_barrier.c testing_messenger_barrier.h \
206 testing_messenger_setup.c testing_messenger_setup.h 183 testing_messenger_setup.c testing_messenger_setup.h
207test_messenger_server_LDADD = \ 184test_messenger_server_LDADD = \
208 libgnunetmessenger_common.la \
209 libgnunetmessenger.la \ 185 libgnunetmessenger.la \
210 $(top_builddir)/src/testbed/libgnunettestbed.la \ 186 $(top_builddir)/src/testbed/libgnunettestbed.la \
211 $(top_builddir)/src/testing/libgnunettesting.la \ 187 $(top_builddir)/src/testing/libgnunettesting.la \
@@ -216,7 +192,6 @@ test_messenger_growth_SOURCES = \
216 testing_messenger_barrier.c testing_messenger_barrier.h \ 192 testing_messenger_barrier.c testing_messenger_barrier.h \
217 testing_messenger_setup.c testing_messenger_setup.h 193 testing_messenger_setup.c testing_messenger_setup.h
218test_messenger_growth_LDADD = \ 194test_messenger_growth_LDADD = \
219 libgnunetmessenger_common.la \
220 libgnunetmessenger.la \ 195 libgnunetmessenger.la \
221 $(top_builddir)/src/testbed/libgnunettestbed.la \ 196 $(top_builddir)/src/testbed/libgnunettestbed.la \
222 $(top_builddir)/src/testing/libgnunettesting.la \ 197 $(top_builddir)/src/testing/libgnunettesting.la \
@@ -227,7 +202,6 @@ test_messenger_ring_SOURCES = \
227 testing_messenger_barrier.c testing_messenger_barrier.h \ 202 testing_messenger_barrier.c testing_messenger_barrier.h \
228 testing_messenger_setup.c testing_messenger_setup.h 203 testing_messenger_setup.c testing_messenger_setup.h
229test_messenger_ring_LDADD = \ 204test_messenger_ring_LDADD = \
230 libgnunetmessenger_common.la \
231 libgnunetmessenger.la \ 205 libgnunetmessenger.la \
232 $(top_builddir)/src/testbed/libgnunettestbed.la \ 206 $(top_builddir)/src/testbed/libgnunettestbed.la \
233 $(top_builddir)/src/testing/libgnunettesting.la \ 207 $(top_builddir)/src/testing/libgnunettesting.la \
@@ -238,7 +212,6 @@ test_messenger_adapt_SOURCES = \
238 testing_messenger_barrier.c testing_messenger_barrier.h \ 212 testing_messenger_barrier.c testing_messenger_barrier.h \
239 testing_messenger_setup.c testing_messenger_setup.h 213 testing_messenger_setup.c testing_messenger_setup.h
240test_messenger_adapt_LDADD = \ 214test_messenger_adapt_LDADD = \
241 libgnunetmessenger_common.la \
242 libgnunetmessenger.la \ 215 libgnunetmessenger.la \
243 $(top_builddir)/src/testbed/libgnunettestbed.la \ 216 $(top_builddir)/src/testbed/libgnunettestbed.la \
244 $(top_builddir)/src/testing/libgnunettesting.la \ 217 $(top_builddir)/src/testing/libgnunettesting.la \
diff --git a/src/messenger/gnunet-messenger.c b/src/messenger/gnunet-messenger.c
index 737bb83c8..094ae398d 100644..100755
--- a/src/messenger/gnunet-messenger.c
+++ b/src/messenger/gnunet-messenger.c
@@ -229,18 +229,12 @@ on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle)
229 if (room_key) 229 if (room_key)
230 GNUNET_CRYPTO_hash (room_key, strlen (room_key), &key); 230 GNUNET_CRYPTO_hash (room_key, strlen (room_key), &key);
231 231
232 struct GNUNET_PeerIdentity door_peer;
232 struct GNUNET_PeerIdentity *door = NULL; 233 struct GNUNET_PeerIdentity *door = NULL;
233 234
234 if (door_id) 235 if ((door_id) &&
235 { 236 (GNUNET_OK == GNUNET_CRYPTO_eddsa_public_key_from_string (door_id, strlen (door_id), &(door_peer.public_key))))
236 door = GNUNET_new(struct GNUNET_PeerIdentity); 237 door = &door_peer;
237
238 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (door_id, strlen (door_id), &(door->public_key)))
239 {
240 GNUNET_free(door);
241 door = NULL;
242 }
243 }
244 238
245 const char *name = GNUNET_MESSENGER_get_name (handle); 239 const char *name = GNUNET_MESSENGER_get_name (handle);
246 240
diff --git a/src/messenger/gnunet-service-messenger.c b/src/messenger/gnunet-service-messenger.c
index 187b65ed5..76fb31d95 100644..100755
--- a/src/messenger/gnunet-service-messenger.c
+++ b/src/messenger/gnunet-service-messenger.c
@@ -191,7 +191,7 @@ check_send_message (void *cls, const struct GNUNET_MESSENGER_SendMessage *msg)
191 const uint16_t length = full_length - sizeof(*msg); 191 const uint16_t length = full_length - sizeof(*msg);
192 const char *buffer = ((const char*) msg) + sizeof(*msg); 192 const char *buffer = ((const char*) msg) + sizeof(*msg);
193 193
194 uint16_t key_length = 0; 194 ssize_t key_length = 0;
195 195
196 if (!(flags & GNUNET_MESSENGER_FLAG_PRIVATE)) 196 if (!(flags & GNUNET_MESSENGER_FLAG_PRIVATE))
197 goto check_for_message; 197 goto check_for_message;
@@ -231,7 +231,7 @@ handle_send_message (void *cls, const struct GNUNET_MESSENGER_SendMessage *msg)
231 const char *buffer = ((const char*) msg) + sizeof(*msg); 231 const char *buffer = ((const char*) msg) + sizeof(*msg);
232 232
233 const uint16_t length = ntohs (msg->header.size) - sizeof(*msg); 233 const uint16_t length = ntohs (msg->header.size) - sizeof(*msg);
234 uint16_t key_length = 0; 234 ssize_t key_length = 0;
235 235
236 struct GNUNET_IDENTITY_PublicKey public_key; 236 struct GNUNET_IDENTITY_PublicKey public_key;
237 237
diff --git a/src/messenger/gnunet-service-messenger_member.c b/src/messenger/gnunet-service-messenger_member.c
index 6e39cec13..7f00e8438 100644..100755
--- a/src/messenger/gnunet-service-messenger_member.c
+++ b/src/messenger/gnunet-service-messenger_member.c
@@ -335,7 +335,11 @@ add_member_session (struct GNUNET_MESSENGER_Member *member, struct GNUNET_MESSEN
335 struct GNUNET_HashCode hash; 335 struct GNUNET_HashCode hash;
336 GNUNET_CRYPTO_hash(public_key, sizeof(*public_key), &hash); 336 GNUNET_CRYPTO_hash(public_key, sizeof(*public_key), &hash);
337 337
338 GNUNET_CONTAINER_multihashmap_put(member->sessions, &hash, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 338 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(
339 member->sessions, &hash, session,
340 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
341 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Adding a member session failed: %s\n",
342 GNUNET_h2s(&hash));
339} 343}
340 344
341void 345void
@@ -348,7 +352,9 @@ remove_member_session (struct GNUNET_MESSENGER_Member *member, struct GNUNET_MES
348 struct GNUNET_HashCode hash; 352 struct GNUNET_HashCode hash;
349 GNUNET_CRYPTO_hash(public_key, sizeof(*public_key), &hash); 353 GNUNET_CRYPTO_hash(public_key, sizeof(*public_key), &hash);
350 354
351 GNUNET_CONTAINER_multihashmap_remove(member->sessions, &hash, session); 355 if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove(member->sessions, &hash, session))
356 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Removing a member session failed: %s\n",
357 GNUNET_h2s(&hash));
352} 358}
353 359
354struct GNUNET_MESSENGER_ClosureIterateSessions { 360struct GNUNET_MESSENGER_ClosureIterateSessions {
diff --git a/src/messenger/gnunet-service-messenger_message_store.c b/src/messenger/gnunet-service-messenger_message_store.c
index 1f3d262ac..b143c6c98 100644..100755
--- a/src/messenger/gnunet-service-messenger_message_store.c
+++ b/src/messenger/gnunet-service-messenger_message_store.c
@@ -158,6 +158,8 @@ load_message_store_links (struct GNUNET_MESSENGER_MessageStore *store, const cha
158 struct GNUNET_MESSENGER_MessageLinkStorage storage; 158 struct GNUNET_MESSENGER_MessageLinkStorage storage;
159 struct GNUNET_MESSENGER_MessageLink *link = NULL; 159 struct GNUNET_MESSENGER_MessageLink *link = NULL;
160 160
161 memset(&storage, 0, sizeof(storage));
162
161 do 163 do
162 { 164 {
163 if ((sizeof(storage.hash) != GNUNET_DISK_file_read (entries, &(storage.hash), sizeof(storage.hash))) || 165 if ((sizeof(storage.hash) != GNUNET_DISK_file_read (entries, &(storage.hash), sizeof(storage.hash))) ||
@@ -311,6 +313,8 @@ save_message_store (struct GNUNET_MESSENGER_MessageStore *store, const char *dir
311 save.store = store; 313 save.store = store;
312 save.storage = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, permission); 314 save.storage = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, permission);
313 315
316 GNUNET_free(filename);
317
314 if (!save.storage) 318 if (!save.storage)
315 goto save_entries; 319 goto save_entries;
316 320
@@ -324,7 +328,6 @@ close_links:
324 GNUNET_DISK_file_close (save.storage); 328 GNUNET_DISK_file_close (save.storage);
325 329
326save_entries: 330save_entries:
327 GNUNET_free(filename);
328 GNUNET_asprintf (&filename, "%s%s", directory, "entries.store"); 331 GNUNET_asprintf (&filename, "%s%s", directory, "entries.store");
329 332
330 save.store = store; 333 save.store = store;
@@ -417,7 +420,10 @@ get_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNU
417 420
418 if ((GNUNET_YES != decoding) || (GNUNET_CRYPTO_hash_cmp (hash, &check) != 0)) 421 if ((GNUNET_YES != decoding) || (GNUNET_CRYPTO_hash_cmp (hash, &check) != 0))
419 { 422 {
420 GNUNET_CONTAINER_multihashmap_remove (store->entries, hash, entry); 423 if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (store->entries, hash, entry))
424 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Corrupted entry could not be removed from store: %s\n",
425 GNUNET_h2s(hash));
426
421 store->rewrite_entries = GNUNET_YES; 427 store->rewrite_entries = GNUNET_YES;
422 428
423 goto free_message; 429 goto free_message;
diff --git a/src/messenger/gnunet-service-messenger_operation_store.c b/src/messenger/gnunet-service-messenger_operation_store.c
index 05985ef84..a32fbad2c 100644..100755
--- a/src/messenger/gnunet-service-messenger_operation_store.c
+++ b/src/messenger/gnunet-service-messenger_operation_store.c
@@ -184,7 +184,9 @@ cancel_store_operation (struct GNUNET_MESSENGER_OperationStore *store,
184 184
185 stop_operation(op); 185 stop_operation(op);
186 186
187 GNUNET_CONTAINER_multihashmap_remove(store->operations, hash, op); 187 if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove(store->operations, hash, op))
188 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Canceled operation could not be removed: %s\n",
189 GNUNET_h2s(hash));
188 190
189 destroy_operation(op); 191 destroy_operation(op);
190} 192}
diff --git a/src/messenger/messenger_api_contact_store.c b/src/messenger/messenger_api_contact_store.c
index 5238b2c58..6a517c2e0 100644..100755
--- a/src/messenger/messenger_api_contact_store.c
+++ b/src/messenger/messenger_api_contact_store.c
@@ -155,8 +155,10 @@ update_store_contact (struct GNUNET_MESSENGER_ContactStore *store, struct GNUNET
155 store, next_context, &hash 155 store, next_context, &hash
156 ); 156 );
157 157
158 GNUNET_CONTAINER_multihashmap_put (map, &hash, contact, 158 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (map, &hash, contact,
159 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 159 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
160 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Updating a contact failed: %s\n",
161 GNUNET_h2s(&hash));
160 } 162 }
161} 163}
162 164
@@ -176,7 +178,8 @@ remove_store_contact (struct GNUNET_MESSENGER_ContactStore *store, struct GNUNET
176 ); 178 );
177 179
178 if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (map, &hash, contact)) 180 if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (map, &hash, contact))
179 return; 181 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Removing a contact failed: %s\n",
182 GNUNET_h2s(&hash));
180 183
181 destroy_contact (contact); 184 destroy_contact (contact);
182} 185}
diff --git a/src/messenger/messenger_api_message.c b/src/messenger/messenger_api_message.c
index d88859186..0d885f9ee 100644..100755
--- a/src/messenger/messenger_api_message.c
+++ b/src/messenger/messenger_api_message.c
@@ -590,7 +590,7 @@ int
590decode_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, 590decode_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer,
591 int include_signature, uint16_t *padding) 591 int include_signature, uint16_t *padding)
592{ 592{
593 GNUNET_assert((message) && (buffer)); 593 GNUNET_assert((message) && (buffer) && (length >= sizeof(message->header)));
594 594
595 uint16_t offset = 0; 595 uint16_t offset = 0;
596 596
diff --git a/src/messenger/messenger_api_room.c b/src/messenger/messenger_api_room.c
index df141ca12..5b7edee60 100644..100755
--- a/src/messenger/messenger_api_room.c
+++ b/src/messenger/messenger_api_room.c
@@ -106,7 +106,7 @@ get_room_sender (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_H
106 return (entry? entry->sender : NULL); 106 return (entry? entry->sender : NULL);
107} 107}
108 108
109static void 109static struct GNUNET_MESSENGER_Contact*
110handle_join_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, 110handle_join_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender,
111 const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) 111 const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
112{ 112{
@@ -124,6 +124,8 @@ handle_join_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER
124 (GNUNET_OK == GNUNET_CONTAINER_multishortmap_put(room->members, &(message->header.sender_id), sender, 124 (GNUNET_OK == GNUNET_CONTAINER_multishortmap_put(room->members, &(message->header.sender_id), sender,
125 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE))) 125 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)))
126 increase_contact_rc(sender); 126 increase_contact_rc(sender);
127
128 return sender;
127} 129}
128 130
129static void 131static void
@@ -140,7 +142,7 @@ handle_leave_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGE
140 struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store(room->handle); 142 struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store(room->handle);
141 143
142 if (GNUNET_YES == decrease_contact_rc(sender)) 144 if (GNUNET_YES == decrease_contact_rc(sender))
143 remove_store_contact(store, sender, &context); 145 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "A contact does not share any room with you anymore!\n");
144} 146}
145 147
146static void 148static void
@@ -216,17 +218,17 @@ handle_delete_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENG
216 } 218 }
217} 219}
218 220
219void 221struct GNUNET_MESSENGER_Contact*
220handle_room_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, 222handle_room_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender,
221 const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) 223 const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
222{ 224{
223 if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains (room->messages, hash)) 225 if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains (room->messages, hash))
224 return; 226 return sender;
225 227
226 switch (message->header.kind) 228 switch (message->header.kind)
227 { 229 {
228 case GNUNET_MESSENGER_KIND_JOIN: 230 case GNUNET_MESSENGER_KIND_JOIN:
229 handle_join_message (room, sender, message, hash); 231 sender = handle_join_message (room, sender, message, hash);
230 break; 232 break;
231 case GNUNET_MESSENGER_KIND_LEAVE: 233 case GNUNET_MESSENGER_KIND_LEAVE:
232 handle_leave_message (room, sender, message, hash); 234 handle_leave_message (room, sender, message, hash);
@@ -253,7 +255,7 @@ handle_room_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER
253 struct GNUNET_MESSENGER_RoomMessageEntry *entry = GNUNET_new(struct GNUNET_MESSENGER_RoomMessageEntry); 255 struct GNUNET_MESSENGER_RoomMessageEntry *entry = GNUNET_new(struct GNUNET_MESSENGER_RoomMessageEntry);
254 256
255 if (!entry) 257 if (!entry)
256 return; 258 return sender;
257 259
258 entry->sender = sender; 260 entry->sender = sender;
259 entry->message = copy_message (message); 261 entry->message = copy_message (message);
@@ -264,6 +266,8 @@ handle_room_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER
264 destroy_message (entry->message); 266 destroy_message (entry->message);
265 GNUNET_free(entry); 267 GNUNET_free(entry);
266 } 268 }
269
270 return sender;
267} 271}
268 272
269struct GNUNET_MESSENGER_MemberCall 273struct GNUNET_MESSENGER_MemberCall
diff --git a/src/messenger/messenger_api_room.h b/src/messenger/messenger_api_room.h
index 9455fd43b..eb41cf740 100644..100755
--- a/src/messenger/messenger_api_room.h
+++ b/src/messenger/messenger_api_room.h
@@ -100,12 +100,16 @@ get_room_sender (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_H
100 * Handles a <i>message</i> with a given <i>hash</i> in a <i>room</i> for the client API to update 100 * Handles a <i>message</i> with a given <i>hash</i> in a <i>room</i> for the client API to update
101 * members and its information. The function also stores the message in map locally for access afterwards. 101 * members and its information. The function also stores the message in map locally for access afterwards.
102 * 102 *
103 * The contact of the message's sender could be updated or even created. It may not be freed or destroyed though!
104 * (The contact may still be in use for old messages...)
105 *
103 * @param[in/out] room Room 106 * @param[in/out] room Room
104 * @param[in/out] sender Contact of sender 107 * @param[in/out] sender Contact of sender
105 * @param[in] message Message 108 * @param[in] message Message
106 * @param[in] hash Hash of message 109 * @param[in] hash Hash of message
110 * @return Contact of sender
107 */ 111 */
108void 112struct GNUNET_MESSENGER_Contact*
109handle_room_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, 113handle_room_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender,
110 const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); 114 const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash);
111 115
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index d6774b37b..79210939f 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -743,13 +743,14 @@ send_lookup_response (struct NamestoreClient *nc,
743 nick->flags = 743 nick->flags =
744 (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; 744 (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE;
745 merge_with_nick_records (nick, rd_count, rd, &res_count, &res); 745 merge_with_nick_records (nick, rd_count, rd, &res_count, &res);
746 GNUNET_free (nick);
747 } 746 }
748 else 747 else
749 { 748 {
750 res_count = rd_count; 749 res_count = rd_count;
751 res = (struct GNUNET_GNSRECORD_Data *) rd; 750 res = (struct GNUNET_GNSRECORD_Data *) rd;
752 } 751 }
752 if (NULL != nick)
753 GNUNET_free (nick);
753 754
754 GNUNET_assert (-1 != GNUNET_GNSRECORD_records_get_size (res_count, res)); 755 GNUNET_assert (-1 != GNUNET_GNSRECORD_records_get_size (res_count, res));
755 756
@@ -758,12 +759,16 @@ send_lookup_response (struct NamestoreClient *nc,
758 rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, res); 759 rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, res);
759 if (rd_ser_len < 0) 760 if (rd_ser_len < 0)
760 { 761 {
762 if (rd != res)
763 GNUNET_free (res);
761 GNUNET_break (0); 764 GNUNET_break (0);
762 GNUNET_SERVICE_client_drop (nc->client); 765 GNUNET_SERVICE_client_drop (nc->client);
763 return; 766 return;
764 } 767 }
765 if (((size_t) rd_ser_len) >= UINT16_MAX - name_len - sizeof(*zir_msg)) 768 if (((size_t) rd_ser_len) >= UINT16_MAX - name_len - sizeof(*zir_msg))
766 { 769 {
770 if (rd != res)
771 GNUNET_free (res);
767 GNUNET_break (0); 772 GNUNET_break (0);
768 GNUNET_SERVICE_client_drop (nc->client); 773 GNUNET_SERVICE_client_drop (nc->client);
769 return; 774 return;
@@ -920,12 +925,15 @@ refresh_block (struct NamestoreClient *nc,
920 nick->flags = 925 nick->flags =
921 (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; 926 (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE;
922 merge_with_nick_records (nick, rd_count, rd, &res_count, &res); 927 merge_with_nick_records (nick, rd_count, rd, &res_count, &res);
923 GNUNET_free (nick);
924 } 928 }
929 if (NULL != nick)
930 GNUNET_free (nick);
925 if (0 == res_count) 931 if (0 == res_count)
926 { 932 {
927 if (NULL != nc) 933 if (NULL != nc)
928 send_store_response (nc, GNUNET_OK, rid); 934 send_store_response (nc, GNUNET_OK, rid);
935 if (rd != res)
936 GNUNET_free (res);
929 return; /* no data, no need to update cache */ 937 return; /* no data, no need to update cache */
930 } 938 }
931 if (GNUNET_YES == disable_namecache) 939 if (GNUNET_YES == disable_namecache)
@@ -936,6 +944,8 @@ refresh_block (struct NamestoreClient *nc,
936 GNUNET_NO); 944 GNUNET_NO);
937 if (NULL != nc) 945 if (NULL != nc)
938 send_store_response (nc, GNUNET_OK, rid); 946 send_store_response (nc, GNUNET_OK, rid);
947 if (rd != res)
948 GNUNET_free (res);
939 return; 949 return;
940 } 950 }
941 exp_time = GNUNET_GNSRECORD_record_get_expiration_time (res_count, res); 951 exp_time = GNUNET_GNSRECORD_record_get_expiration_time (res_count, res);
@@ -970,6 +980,8 @@ refresh_block (struct NamestoreClient *nc,
970 &finish_cache_operation, 980 &finish_cache_operation,
971 cop); 981 cop);
972 GNUNET_free (block); 982 GNUNET_free (block);
983 if (rd != res)
984 GNUNET_free (res);
973} 985}
974 986
975 987
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index c845b5019..2d5327e06 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -690,6 +690,12 @@ handle_zone_to_name_response (void *cls,
690 690
691 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME_RESPONSE\n"); 691 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME_RESPONSE\n");
692 qe = find_qe (h, ntohl (msg->gns_header.r_id)); 692 qe = find_qe (h, ntohl (msg->gns_header.r_id));
693 if (NULL == qe)
694 {
695 LOG (GNUNET_ERROR_TYPE_WARNING,
696 "Response queue already gone...\n");
697 return;
698 }
693 res = ntohs (msg->res); 699 res = ntohs (msg->res);
694 switch (res) 700 switch (res)
695 { 701 {
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c
index edcbeb874..ae93e5eff 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -375,6 +375,8 @@ get_egoentry_namestore (struct RequestHandle *handle, char *name)
375 if (NULL == name) 375 if (NULL == name)
376 return NULL; 376 return NULL;
377 tmp = strtok (copy, "/"); 377 tmp = strtok (copy, "/");
378 if (NULL == tmp)
379 return NULL;
378 for (ego_entry = ego_head; NULL != ego_entry; 380 for (ego_entry = ego_head; NULL != ego_entry;
379 ego_entry = ego_entry->next) 381 ego_entry = ego_entry->next)
380 { 382 {
diff --git a/src/peerinfo-tool/plugin_rest_peerinfo.c b/src/peerinfo-tool/plugin_rest_peerinfo.c
index 4bbc7442e..f969a175b 100644
--- a/src/peerinfo-tool/plugin_rest_peerinfo.c
+++ b/src/peerinfo-tool/plugin_rest_peerinfo.c
@@ -379,7 +379,9 @@ peerinfo_list_finished (void *cls)
379 result_str = json_dumps (handle->response, 0); 379 result_str = json_dumps (handle->response, 0);
380 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); 380 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
381 resp = GNUNET_REST_create_response (result_str); 381 resp = GNUNET_REST_create_response (result_str);
382 MHD_add_response_header (resp, "Content-Type", "application/json"); 382 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
383 "Content-Type",
384 "application/json"));
383 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 385 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
384 GNUNET_free (result_str); 386 GNUNET_free (result_str);
385 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); 387 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c
index db5aee0d5..196d44faa 100644
--- a/src/peerstore/peerstore_api.c
+++ b/src/peerstore/peerstore_api.c
@@ -823,7 +823,12 @@ reconnect (void *cls)
823 &handle_client_error, 823 &handle_client_error,
824 h); 824 h);
825 if (NULL == h->mq) 825 if (NULL == h->mq)
826 {
827 h->reconnect_task =
828 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
829 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
826 return; 830 return;
831 }
827 LOG (GNUNET_ERROR_TYPE_DEBUG, 832 LOG (GNUNET_ERROR_TYPE_DEBUG,
828 "Resending pending requests after reconnect.\n"); 833 "Resending pending requests after reconnect.\n");
829 if (NULL != h->watches) 834 if (NULL != h->watches)
diff --git a/src/peerstore/test_peerstore_api_sync.c b/src/peerstore/test_peerstore_api_sync.c
index 4c826c654..5057c98b5 100644
--- a/src/peerstore/test_peerstore_api_sync.c
+++ b/src/peerstore/test_peerstore_api_sync.c
@@ -67,6 +67,24 @@ static const char *val = "test_peerstore_api_store_val";
67 67
68 68
69/** 69/**
70 * Timeout
71 */
72#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
73
74/**
75 * Timeout task
76 */
77static struct GNUNET_SCHEDULER_Task *to;
78
79/**
80 * Iterate handle
81 */
82static struct GNUNET_PEERSTORE_IterateContext *it;
83
84static void
85test_cont (void *cls);
86
87/**
70 * Function that should be called with the result of the 88 * Function that should be called with the result of the
71 * lookup, and finally once with NULL to signal the end 89 * lookup, and finally once with NULL to signal the end
72 * of the iteration. 90 * of the iteration.
@@ -89,9 +107,24 @@ iterate_cb (void *cls,
89 GNUNET_break (NULL == emsg); 107 GNUNET_break (NULL == emsg);
90 if (NULL == record) 108 if (NULL == record)
91 { 109 {
92 GNUNET_PEERSTORE_disconnect (h, 110 it = NULL;
93 GNUNET_NO); 111 if (0 == ok)
94 GNUNET_SCHEDULER_shutdown (); 112 {
113 GNUNET_PEERSTORE_disconnect (h,
114 GNUNET_NO);
115 if (NULL != to)
116 {
117 GNUNET_SCHEDULER_cancel (to);
118 to = NULL;
119 }
120 GNUNET_SCHEDULER_shutdown ();
121 return;
122 }
123 /**
124 * Try again
125 */
126 GNUNET_SCHEDULER_add_now (&test_cont,
127 NULL);
95 return; 128 return;
96 } 129 }
97 rec_val = record->value; 130 rec_val = record->value;
@@ -100,6 +133,22 @@ iterate_cb (void *cls,
100} 133}
101 134
102 135
136static void
137timeout_task (void *cls)
138{
139 to = NULL;
140 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
141 "Timeout reached\n");
142 if (NULL != it)
143 GNUNET_PEERSTORE_iterate_cancel (it);
144 it = NULL;
145 GNUNET_PEERSTORE_disconnect (h,
146 GNUNET_NO);
147 GNUNET_SCHEDULER_shutdown ();
148 return;
149}
150
151
103/** 152/**
104 * Run the 2nd stage of the test where we fetch the 153 * Run the 2nd stage of the test where we fetch the
105 * data that should have been stored. 154 * data that should have been stored.
@@ -109,12 +158,11 @@ iterate_cb (void *cls,
109static void 158static void
110test_cont (void *cls) 159test_cont (void *cls)
111{ 160{
112 h = GNUNET_PEERSTORE_connect (cfg); 161 it = GNUNET_PEERSTORE_iterate (h,
113 GNUNET_PEERSTORE_iterate (h, 162 subsystem,
114 subsystem, 163 &pid, key,
115 &pid, key, 164 &iterate_cb,
116 &iterate_cb, 165 NULL);
117 NULL);
118} 166}
119 167
120 168
@@ -122,10 +170,9 @@ static void
122disc_cont (void *cls) 170disc_cont (void *cls)
123{ 171{
124 GNUNET_PEERSTORE_disconnect (h, GNUNET_YES); 172 GNUNET_PEERSTORE_disconnect (h, GNUNET_YES);
125 h = NULL; 173 h = GNUNET_PEERSTORE_connect (cfg);
126 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 174 GNUNET_SCHEDULER_add_now (&test_cont,
127 &test_cont, 175 NULL);
128 NULL);
129} 176}
130 177
131 178
@@ -133,12 +180,17 @@ static void
133store_cont (void *cls, int success) 180store_cont (void *cls, int success)
134{ 181{
135 ok = success; 182 ok = success;
183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
184 "Success: %s\n",
185 (GNUNET_SYSERR == ok) ? "no" : "yes");
136 /* We need to wait a little bit to give the disconnect 186 /* We need to wait a little bit to give the disconnect
137 a chance to actually finish the operation; otherwise, 187 a chance to actually finish the operation; otherwise,
138 the test may fail non-deterministically if the new 188 the test may fail non-deterministically if the new
139 connection is faster than the cleanup routine of the 189 connection is faster than the cleanup routine of the
140 old one. */GNUNET_SCHEDULER_add_now (&disc_cont, 190 old one. */
141 NULL); 191 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
192 &disc_cont,
193 NULL);
142} 194}
143 195
144 196
@@ -174,7 +226,10 @@ run (void *cls,
174{ 226{
175 cfg = c; 227 cfg = c;
176 memset (&pid, 1, sizeof(pid)); 228 memset (&pid, 1, sizeof(pid));
177 test1 (); 229 to = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
230 &timeout_task,
231 NULL);
232 GNUNET_SCHEDULER_add_now (&test1, NULL);
178} 233}
179 234
180 235
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c
index 913b667b7..04c12735b 100644
--- a/src/reclaim/gnunet-service-reclaim.c
+++ b/src/reclaim/gnunet-service-reclaim.c
@@ -731,9 +731,12 @@ static int
731check_issue_ticket_message (void *cls, const struct IssueTicketMessage *im) 731check_issue_ticket_message (void *cls, const struct IssueTicketMessage *im)
732{ 732{
733 uint16_t size; 733 uint16_t size;
734 size_t attrs_len;
734 735
735 size = ntohs (im->header.size); 736 size = ntohs (im->header.size);
736 if (size <= sizeof(struct IssueTicketMessage)) 737 attrs_len = ntohs (im->attr_len);
738
739 if (attrs_len > size - sizeof(struct IssueTicketMessage))
737 { 740 {
738 GNUNET_break (0); 741 GNUNET_break (0);
739 return GNUNET_SYSERR; 742 return GNUNET_SYSERR;
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c
index ef2303bd7..48b3fe214 100644
--- a/src/reclaim/gnunet-service-reclaim_tickets.c
+++ b/src/reclaim/gnunet-service-reclaim_tickets.c
@@ -690,7 +690,10 @@ rvk_move_attr_cb (void *cls,
690 return; 690 return;
691 } 691 }
692 GNUNET_RECLAIM_id_generate (&rvk->move_attr->new_id); 692 GNUNET_RECLAIM_id_generate (&rvk->move_attr->new_id);
693 new_label = NULL; 693 new_label =
694 GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id,
695 sizeof (rvk->move_attr->new_id));
696
694 attr_data = NULL; 697 attr_data = NULL;
695 // new_rd = *rd; 698 // new_rd = *rd;
696 for (int i = 0; i < rd_count; i++) 699 for (int i = 0; i < rd_count; i++)
@@ -714,9 +717,6 @@ rvk_move_attr_cb (void *cls,
714 new_rd[i].record_type = rd[i].record_type; 717 new_rd[i].record_type = rd[i].record_type;
715 new_rd[i].flags = rd[i].flags; 718 new_rd[i].flags = rd[i].flags;
716 new_rd[i].expiration_time = rd[i].expiration_time; 719 new_rd[i].expiration_time = rd[i].expiration_time;
717 new_label =
718 GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id,
719 sizeof (rvk->move_attr->new_id));
720 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute %s\n", new_label); 720 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute %s\n", new_label);
721 GNUNET_free (claim); 721 GNUNET_free (claim);
722 } 722 }
@@ -738,9 +738,6 @@ rvk_move_attr_cb (void *cls,
738 new_rd[i].record_type = rd[i].record_type; 738 new_rd[i].record_type = rd[i].record_type;
739 new_rd[i].flags = rd[i].flags; 739 new_rd[i].flags = rd[i].flags;
740 new_rd[i].expiration_time = rd[i].expiration_time; 740 new_rd[i].expiration_time = rd[i].expiration_time;
741 new_label =
742 GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id,
743 sizeof (rvk->move_attr->new_id));
744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding credential %s\n", 741 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding credential %s\n",
745 new_label); 742 new_label);
746 GNUNET_free (credential); 743 GNUNET_free (credential);
@@ -1400,7 +1397,7 @@ issue_ticket (struct TicketIssueHandle *ih)
1400 attrs_record, 1397 attrs_record,
1401 &store_ticket_issue_cont, 1398 &store_ticket_issue_cont,
1402 ih); 1399 ih);
1403 for (j = 0; j > i; j++) 1400 for (j = 0; j < i; j++)
1404 { 1401 {
1405 if (attrs_record[j].record_type 1402 if (attrs_record[j].record_type
1406 != GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION) 1403 != GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION)
@@ -1585,7 +1582,7 @@ filter_tickets_cb (void *cls,
1585 cleanup_issue_handle (tih); 1582 cleanup_issue_handle (tih);
1586 return; 1583 return;
1587 } 1584 }
1588 1585 GNUNET_RECLAIM_presentation_list_destroy (ticket_presentations);
1589 // ticket not found in current record, checking next record set 1586 // ticket not found in current record, checking next record set
1590 GNUNET_NAMESTORE_zone_iterator_next (tih->ns_it, 1); 1587 GNUNET_NAMESTORE_zone_iterator_next (tih->ns_it, 1);
1591} 1588}
diff --git a/src/reclaim/oidc_helper.c b/src/reclaim/oidc_helper.c
index bd3a8ee05..7b24ee598 100644
--- a/src/reclaim/oidc_helper.c
+++ b/src/reclaim/oidc_helper.c
@@ -839,11 +839,17 @@ int
839OIDC_access_token_parse (const char *token, 839OIDC_access_token_parse (const char *token,
840 struct GNUNET_RECLAIM_Ticket **ticket) 840 struct GNUNET_RECLAIM_Ticket **ticket)
841{ 841{
842 if (sizeof (struct GNUNET_RECLAIM_Ticket) != 842 size_t sret;
843 GNUNET_STRINGS_base64_decode (token, 843 char *decoded;
844 strlen (token), 844 sret = GNUNET_STRINGS_base64_decode (token,
845 (void**) ticket)) 845 strlen (token),
846 (void**) &decoded);
847 if (sizeof (struct GNUNET_RECLAIM_Ticket) != sret)
848 {
849 GNUNET_free (decoded);
846 return GNUNET_SYSERR; 850 return GNUNET_SYSERR;
851 }
852 *ticket = (struct GNUNET_RECLAIM_Ticket *) decoded;
847 return GNUNET_OK; 853 return GNUNET_OK;
848} 854}
849 855
diff --git a/src/reclaim/plugin_rest_openid_connect.c b/src/reclaim/plugin_rest_openid_connect.c
index 0ee61755b..c6259d745 100644
--- a/src/reclaim/plugin_rest_openid_connect.c
+++ b/src/reclaim/plugin_rest_openid_connect.c
@@ -686,7 +686,10 @@ do_userinfo_error (void *cls)
686 handle->emsg, 686 handle->emsg,
687 (NULL != handle->edesc) ? handle->edesc : ""); 687 (NULL != handle->edesc) ? handle->edesc : "");
688 resp = GNUNET_REST_create_response (""); 688 resp = GNUNET_REST_create_response ("");
689 MHD_add_response_header (resp, MHD_HTTP_HEADER_WWW_AUTHENTICATE, "Bearer"); 689 GNUNET_assert (MHD_NO !=
690 MHD_add_response_header (resp,
691 MHD_HTTP_HEADER_WWW_AUTHENTICATE,
692 "Bearer"));
690 handle->proc (handle->proc_cls, resp, handle->response_code); 693 handle->proc (handle->proc_cls, resp, handle->response_code);
691 cleanup_handle (handle); 694 cleanup_handle (handle);
692 GNUNET_free (error); 695 GNUNET_free (error);
@@ -713,7 +716,8 @@ do_redirect_error (void *cls)
713 (NULL != handle->oidc->state) ? "&state=" : "", 716 (NULL != handle->oidc->state) ? "&state=" : "",
714 (NULL != handle->oidc->state) ? handle->oidc->state : ""); 717 (NULL != handle->oidc->state) ? handle->oidc->state : "");
715 resp = GNUNET_REST_create_response (""); 718 resp = GNUNET_REST_create_response ("");
716 MHD_add_response_header (resp, "Location", redirect); 719 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
720 "Location", redirect));
717 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND); 721 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND);
718 cleanup_handle (handle); 722 cleanup_handle (handle);
719 GNUNET_free (redirect); 723 GNUNET_free (redirect);
@@ -1022,7 +1026,8 @@ oidc_ticket_issue_cb (void *cls,
1022 handle->oidc->state); 1026 handle->oidc->state);
1023 } 1027 }
1024 resp = GNUNET_REST_create_response (""); 1028 resp = GNUNET_REST_create_response ("");
1025 MHD_add_response_header (resp, "Location", redirect_uri); 1029 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
1030 "Location", redirect_uri));
1026 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND); 1031 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND);
1027 cleanup_handle (handle); 1032 cleanup_handle (handle);
1028 GNUNET_free (redirect_uri); 1033 GNUNET_free (redirect_uri);
@@ -1381,7 +1386,8 @@ build_redirect (void *cls)
1381 handle->oidc->state); 1386 handle->oidc->state);
1382 } 1387 }
1383 resp = GNUNET_REST_create_response (""); 1388 resp = GNUNET_REST_create_response ("");
1384 MHD_add_response_header (resp, "Location", redirect_uri); 1389 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
1390 "Location", redirect_uri));
1385 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND); 1391 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND);
1386 cleanup_handle (handle); 1392 cleanup_handle (handle);
1387 GNUNET_free (redirect_uri); 1393 GNUNET_free (redirect_uri);
@@ -1764,8 +1770,12 @@ login_cont (struct GNUNET_REST_RequestHandle *con_handle,
1764 "%s;Max-Age=%d", 1770 "%s;Max-Age=%d",
1765 cookie, 1771 cookie,
1766 OIDC_COOKIE_EXPIRATION); 1772 OIDC_COOKIE_EXPIRATION);
1767 MHD_add_response_header (resp, "Set-Cookie", header_val); 1773 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
1768 MHD_add_response_header (resp, "Access-Control-Allow-Methods", "POST"); 1774 "Set-Cookie", header_val));
1775 GNUNET_assert (MHD_NO !=
1776 MHD_add_response_header (resp,
1777 "Access-Control-Allow-Methods",
1778 "POST"));
1769 GNUNET_CRYPTO_hash (cookie, strlen (cookie), &cache_key); 1779 GNUNET_CRYPTO_hash (cookie, strlen (cookie), &cache_key);
1770 1780
1771 if (0 != strcmp (json_string_value (identity), "Denied")) 1781 if (0 != strcmp (json_string_value (identity), "Denied"))
@@ -1880,7 +1890,8 @@ parse_credentials_post_body (struct RequestHandle *handle,
1880 } 1890 }
1881 pass = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map, 1891 pass = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map,
1882 &cache_key); 1892 &cache_key);
1883 if (NULL == pass) { 1893 if (NULL == pass)
1894 {
1884 GNUNET_free (*client_id); 1895 GNUNET_free (*client_id);
1885 *client_id = NULL; 1896 *client_id = NULL;
1886 return GNUNET_SYSERR; 1897 return GNUNET_SYSERR;
@@ -2134,6 +2145,8 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
2134 GNUNET_free (code); 2145 GNUNET_free (code);
2135 if (NULL != nonce) 2146 if (NULL != nonce)
2136 GNUNET_free (nonce); 2147 GNUNET_free (nonce);
2148 GNUNET_RECLAIM_attribute_list_destroy (cl);
2149 GNUNET_RECLAIM_presentation_list_destroy (pl);
2137 GNUNET_SCHEDULER_add_now (&do_error, handle); 2150 GNUNET_SCHEDULER_add_now (&do_error, handle);
2138 return; 2151 return;
2139 } 2152 }
@@ -2149,6 +2162,8 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
2149 handle->edesc = GNUNET_strdup ("No signing secret configured!"); 2162 handle->edesc = GNUNET_strdup ("No signing secret configured!");
2150 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; 2163 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
2151 GNUNET_free (code); 2164 GNUNET_free (code);
2165 GNUNET_RECLAIM_attribute_list_destroy (cl);
2166 GNUNET_RECLAIM_presentation_list_destroy (pl);
2152 if (NULL != nonce) 2167 if (NULL != nonce)
2153 GNUNET_free (nonce); 2168 GNUNET_free (nonce);
2154 GNUNET_SCHEDULER_add_now (&do_error, handle); 2169 GNUNET_SCHEDULER_add_now (&do_error, handle);
@@ -2191,9 +2206,14 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
2191 &json_response); 2206 &json_response);
2192 2207
2193 resp = GNUNET_REST_create_response (json_response); 2208 resp = GNUNET_REST_create_response (json_response);
2194 MHD_add_response_header (resp, "Cache-Control", "no-store"); 2209 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
2195 MHD_add_response_header (resp, "Pragma", "no-cache"); 2210 "Cache-Control",
2196 MHD_add_response_header (resp, "Content-Type", "application/json"); 2211 "no-store"));
2212 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
2213 "Pragma", "no-cache"));
2214 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
2215 "Content-Type",
2216 "application/json"));
2197 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 2217 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
2198 GNUNET_RECLAIM_attribute_list_destroy (cl); 2218 GNUNET_RECLAIM_attribute_list_destroy (cl);
2199 GNUNET_RECLAIM_presentation_list_destroy (pl); 2219 GNUNET_RECLAIM_presentation_list_destroy (pl);
@@ -2665,8 +2685,14 @@ oidc_config_cors (struct GNUNET_REST_RequestHandle *con_handle,
2665 2685
2666 // For now, independent of path return all options 2686 // For now, independent of path return all options
2667 resp = GNUNET_REST_create_response (NULL); 2687 resp = GNUNET_REST_create_response (NULL);
2668 MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); 2688 GNUNET_assert (MHD_NO !=
2669 MHD_add_response_header (resp, "Access-Control-Allow-Origin", "*"); 2689 MHD_add_response_header (resp,
2690 "Access-Control-Allow-Methods",
2691 allow_methods));
2692 GNUNET_assert (MHD_NO !=
2693 MHD_add_response_header (resp,
2694 "Access-Control-Allow-Origin",
2695 "*"));
2670 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 2696 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
2671 cleanup_handle (handle); 2697 cleanup_handle (handle);
2672 return; 2698 return;
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c
index 84456b386..39d24ea61 100644
--- a/src/reclaim/plugin_rest_reclaim.c
+++ b/src/reclaim/plugin_rest_reclaim.c
@@ -353,14 +353,18 @@ finished_cont (void *cls, int32_t success, const char *emsg)
353 struct MHD_Response *resp; 353 struct MHD_Response *resp;
354 354
355 handle->idp_op = NULL; 355 handle->idp_op = NULL;
356 resp = GNUNET_REST_create_response (emsg);
357 MHD_add_response_header (resp, "Content-Type", "application/json");
358 MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
359 if (GNUNET_OK != success) 356 if (GNUNET_OK != success)
360 { 357 {
361 GNUNET_SCHEDULER_add_now (&do_error, handle); 358 GNUNET_SCHEDULER_add_now (&do_error, handle);
362 return; 359 return;
363 } 360 }
361 resp = GNUNET_REST_create_response (emsg);
362 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
363 "Content-Type",
364 "application/json"));
365 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
366 "Access-Control-Allow-Methods",
367 allow_methods));
364 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 368 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
365 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); 369 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
366} 370}
@@ -372,13 +376,15 @@ delete_finished_cb (void *cls, int32_t success, const char *emsg)
372 struct RequestHandle *handle = cls; 376 struct RequestHandle *handle = cls;
373 struct MHD_Response *resp; 377 struct MHD_Response *resp;
374 378
375 resp = GNUNET_REST_create_response (emsg);
376 MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
377 if (GNUNET_OK != success) 379 if (GNUNET_OK != success)
378 { 380 {
379 GNUNET_SCHEDULER_add_now (&do_error, handle); 381 GNUNET_SCHEDULER_add_now (&do_error, handle);
380 return; 382 return;
381 } 383 }
384 resp = GNUNET_REST_create_response (emsg);
385 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
386 "Access-Control-Allow-Methods",
387 allow_methods));
382 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 388 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
383 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); 389 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
384} 390}
@@ -399,7 +405,10 @@ return_response (void *cls)
399 result_str = json_dumps (handle->resp_object, 0); 405 result_str = json_dumps (handle->resp_object, 0);
400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); 406 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
401 resp = GNUNET_REST_create_response (result_str); 407 resp = GNUNET_REST_create_response (result_str);
402 MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); 408 GNUNET_assert (MHD_NO !=
409 MHD_add_response_header (resp,
410 "Access-Control-Allow-Methods",
411 allow_methods));
403 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 412 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
404 GNUNET_free (result_str); 413 GNUNET_free (result_str);
405 cleanup_handle (handle); 414 cleanup_handle (handle);
@@ -461,8 +470,8 @@ ticket_collect (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
461 470
462static void 471static void
463add_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, 472add_credential_cont (struct GNUNET_REST_RequestHandle *con_handle,
464 const char *url, 473 const char *url,
465 void *cls) 474 void *cls)
466{ 475{
467 struct RequestHandle *handle = cls; 476 struct RequestHandle *handle = cls;
468 const struct GNUNET_IDENTITY_PrivateKey *identity_priv; 477 const struct GNUNET_IDENTITY_PrivateKey *identity_priv;
@@ -513,7 +522,15 @@ add_credential_cont (struct GNUNET_REST_RequestHandle *con_handle,
513 handle->rest_handle->data, 522 handle->rest_handle->data,
514 handle->rest_handle->data_size); 523 handle->rest_handle->data_size);
515 data_json = json_loads (term_data, JSON_DECODE_ANY, &err); 524 data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
516 GNUNET_JSON_parse (data_json, attrspec, NULL, NULL); 525 if (GNUNET_OK != GNUNET_JSON_parse (data_json, attrspec, NULL, NULL))
526 {
527 json_decref (data_json);
528 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
529 "Unable to parse JSON from %s\n",
530 term_data);
531 GNUNET_SCHEDULER_add_now (&do_error, handle);
532 return;
533 }
517 json_decref (data_json); 534 json_decref (data_json);
518 if (NULL == attribute) 535 if (NULL == attribute)
519 { 536 {
@@ -530,11 +547,11 @@ add_credential_cont (struct GNUNET_REST_RequestHandle *con_handle,
530 GNUNET_RECLAIM_id_generate (&attribute->id); 547 GNUNET_RECLAIM_id_generate (&attribute->id);
531 exp = GNUNET_TIME_UNIT_HOURS; 548 exp = GNUNET_TIME_UNIT_HOURS;
532 handle->idp_op = GNUNET_RECLAIM_credential_store (idp, 549 handle->idp_op = GNUNET_RECLAIM_credential_store (idp,
533 identity_priv, 550 identity_priv,
534 attribute, 551 attribute,
535 &exp, 552 &exp,
536 &finished_cont, 553 &finished_cont,
537 handle); 554 handle);
538 GNUNET_JSON_parse_free (attrspec); 555 GNUNET_JSON_parse_free (attrspec);
539} 556}
540 557
@@ -545,8 +562,8 @@ add_credential_cont (struct GNUNET_REST_RequestHandle *con_handle,
545 */ 562 */
546static void 563static void
547cred_collect (void *cls, 564cred_collect (void *cls,
548 const struct GNUNET_IDENTITY_PublicKey *identity, 565 const struct GNUNET_IDENTITY_PublicKey *identity,
549 const struct GNUNET_RECLAIM_Credential *cred) 566 const struct GNUNET_RECLAIM_Credential *cred)
550{ 567{
551 struct RequestHandle *handle = cls; 568 struct RequestHandle *handle = cls;
552 struct GNUNET_RECLAIM_AttributeList *attrs; 569 struct GNUNET_RECLAIM_AttributeList *attrs;
@@ -565,8 +582,8 @@ cred_collect (void *cls,
565 attrs = GNUNET_RECLAIM_credential_get_attributes (cred); 582 attrs = GNUNET_RECLAIM_credential_get_attributes (cred);
566 issuer = GNUNET_RECLAIM_credential_get_issuer (cred); 583 issuer = GNUNET_RECLAIM_credential_get_issuer (cred);
567 tmp_value = GNUNET_RECLAIM_credential_value_to_string (cred->type, 584 tmp_value = GNUNET_RECLAIM_credential_value_to_string (cred->type,
568 cred->data, 585 cred->data,
569 cred->data_size); 586 cred->data_size);
570 cred_obj = json_object (); 587 cred_obj = json_object ();
571 json_object_set_new (cred_obj, "value", json_string (tmp_value)); 588 json_object_set_new (cred_obj, "value", json_string (tmp_value));
572 json_object_set_new (cred_obj, "name", json_string (cred->name)); 589 json_object_set_new (cred_obj, "name", json_string (cred->name));
@@ -578,7 +595,7 @@ cred_collect (void *cls,
578 GNUNET_free (issuer); 595 GNUNET_free (issuer);
579 } 596 }
580 if (GNUNET_OK == GNUNET_RECLAIM_credential_get_expiration (cred, 597 if (GNUNET_OK == GNUNET_RECLAIM_credential_get_expiration (cred,
581 &exp)) 598 &exp))
582 { 599 {
583 json_object_set_new (cred_obj, "expiration", json_integer ( 600 json_object_set_new (cred_obj, "expiration", json_integer (
584 exp.abs_value_us)); 601 exp.abs_value_us));
@@ -613,7 +630,8 @@ cred_collect (void *cls,
613 json_object_set_new (cred_obj, "attributes", attr_arr); 630 json_object_set_new (cred_obj, "attributes", attr_arr);
614 } 631 }
615 json_array_append_new (handle->resp_object, cred_obj); 632 json_array_append_new (handle->resp_object, cred_obj);
616 GNUNET_RECLAIM_attribute_list_destroy (attrs); 633 if (NULL != attrs)
634 GNUNET_RECLAIM_attribute_list_destroy (attrs);
617 GNUNET_RECLAIM_get_credentials_next (handle->cred_it); 635 GNUNET_RECLAIM_get_credentials_next (handle->cred_it);
618} 636}
619 637
@@ -627,8 +645,8 @@ cred_collect (void *cls,
627 */ 645 */
628static void 646static void
629list_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, 647list_credential_cont (struct GNUNET_REST_RequestHandle *con_handle,
630 const char *url, 648 const char *url,
631 void *cls) 649 void *cls)
632{ 650{
633 struct RequestHandle *handle = cls; 651 struct RequestHandle *handle = cls;
634 const struct GNUNET_IDENTITY_PrivateKey *priv_key; 652 const struct GNUNET_IDENTITY_PrivateKey *priv_key;
@@ -664,14 +682,14 @@ list_credential_cont (struct GNUNET_REST_RequestHandle *con_handle,
664 } 682 }
665 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 683 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
666 handle->cred_it = GNUNET_RECLAIM_get_credentials_start (idp, 684 handle->cred_it = GNUNET_RECLAIM_get_credentials_start (idp,
667 priv_key, 685 priv_key,
668 &collect_error_cb, 686 &collect_error_cb,
669 handle, 687 handle,
670 &cred_collect, 688 &cred_collect,
671 handle, 689 handle,
672 & 690 &
673 collect_finished_cb, 691 collect_finished_cb,
674 handle); 692 handle);
675} 693}
676 694
677 695
@@ -684,8 +702,8 @@ list_credential_cont (struct GNUNET_REST_RequestHandle *con_handle,
684 */ 702 */
685static void 703static void
686delete_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, 704delete_credential_cont (struct GNUNET_REST_RequestHandle *con_handle,
687 const char *url, 705 const char *url,
688 void *cls) 706 void *cls)
689{ 707{
690 struct RequestHandle *handle = cls; 708 struct RequestHandle *handle = cls;
691 const struct GNUNET_IDENTITY_PrivateKey *priv_key; 709 const struct GNUNET_IDENTITY_PrivateKey *priv_key;
@@ -734,10 +752,10 @@ delete_credential_cont (struct GNUNET_REST_RequestHandle *con_handle,
734 GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id)); 752 GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id));
735 attr.name = ""; 753 attr.name = "";
736 handle->idp_op = GNUNET_RECLAIM_credential_delete (idp, 754 handle->idp_op = GNUNET_RECLAIM_credential_delete (idp,
737 priv_key, 755 priv_key,
738 &attr, 756 &attr,
739 &delete_finished_cb, 757 &delete_finished_cb,
740 handle); 758 handle);
741 GNUNET_free (identity_id_str); 759 GNUNET_free (identity_id_str);
742} 760}
743 761
@@ -900,8 +918,8 @@ parse_jwt (const struct GNUNET_RECLAIM_Credential *cred,
900 json_error_t *json_err = NULL; 918 json_error_t *json_err = NULL;
901 919
902 jwt_string = GNUNET_RECLAIM_credential_value_to_string (cred->type, 920 jwt_string = GNUNET_RECLAIM_credential_value_to_string (cred->type,
903 cred->data, 921 cred->data,
904 cred->data_size); 922 cred->data_size);
905 char *jwt_body = strtok (jwt_string, delim); 923 char *jwt_body = strtok (jwt_string, delim);
906 jwt_body = strtok (NULL, delim); 924 jwt_body = strtok (NULL, delim);
907 GNUNET_STRINGS_base64_decode (jwt_body, strlen (jwt_body), 925 GNUNET_STRINGS_base64_decode (jwt_body, strlen (jwt_body),
@@ -1424,25 +1442,24 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
1424 static const struct GNUNET_REST_RequestHandler handlers[] = 1442 static const struct GNUNET_REST_RequestHandler handlers[] =
1425 { { MHD_HTTP_METHOD_GET, 1443 { { MHD_HTTP_METHOD_GET,
1426 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &list_attribute_cont }, 1444 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &list_attribute_cont },
1427 { MHD_HTTP_METHOD_POST, 1445 { MHD_HTTP_METHOD_POST,
1428 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &add_attribute_cont }, 1446 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &add_attribute_cont },
1429 { MHD_HTTP_METHOD_DELETE, 1447 { MHD_HTTP_METHOD_DELETE,
1430 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &delete_attribute_cont }, 1448 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &delete_attribute_cont },
1431 { MHD_HTTP_METHOD_GET, 1449 { MHD_HTTP_METHOD_GET,
1432 GNUNET_REST_API_NS_RECLAIM_CREDENTIAL, &list_credential_cont }, 1450 GNUNET_REST_API_NS_RECLAIM_CREDENTIAL, &list_credential_cont },
1433 { MHD_HTTP_METHOD_POST, 1451 { MHD_HTTP_METHOD_POST,
1434 GNUNET_REST_API_NS_RECLAIM_CREDENTIAL, &add_credential_cont }, 1452 GNUNET_REST_API_NS_RECLAIM_CREDENTIAL, &add_credential_cont },
1435 { MHD_HTTP_METHOD_DELETE, 1453 { MHD_HTTP_METHOD_DELETE,
1436 GNUNET_REST_API_NS_RECLAIM_CREDENTIAL, &delete_credential_cont }, 1454 GNUNET_REST_API_NS_RECLAIM_CREDENTIAL, &delete_credential_cont },
1437 { MHD_HTTP_METHOD_GET, 1455 { MHD_HTTP_METHOD_GET,
1438 GNUNET_REST_API_NS_IDENTITY_TICKETS, &list_tickets_cont }, 1456 GNUNET_REST_API_NS_IDENTITY_TICKETS, &list_tickets_cont },
1439 { MHD_HTTP_METHOD_POST, 1457 { MHD_HTTP_METHOD_POST,
1440 GNUNET_REST_API_NS_IDENTITY_REVOKE, &revoke_ticket_cont }, 1458 GNUNET_REST_API_NS_IDENTITY_REVOKE, &revoke_ticket_cont },
1441 { MHD_HTTP_METHOD_POST, 1459 { MHD_HTTP_METHOD_POST,
1442 GNUNET_REST_API_NS_IDENTITY_CONSUME, &consume_ticket_cont }, 1460 GNUNET_REST_API_NS_IDENTITY_CONSUME, &consume_ticket_cont },
1443 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont }, 1461 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont },
1444 GNUNET_REST_HANDLER_END 1462 GNUNET_REST_HANDLER_END};
1445 };
1446 1463
1447 handle->response_code = 0; 1464 handle->response_code = 0;
1448 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 1465 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c
index f4f2b946a..c08cc868c 100644
--- a/src/reclaim/reclaim_api.c
+++ b/src/reclaim/reclaim_api.c
@@ -651,18 +651,15 @@ handle_consume_ticket_result (void *cls,
651 le->attribute, NULL); 651 le->attribute, NULL);
652 } 652 }
653 } 653 }
654 if (NULL != attrs)
655 GNUNET_RECLAIM_attribute_list_destroy (attrs);
656 if (NULL != pl)
657 GNUNET_RECLAIM_presentation_list_destroy (pl);
658 attrs = NULL;
659 pl = NULL;
660 } 654 }
661 op->atr_cb (op->cls, NULL, NULL, NULL); 655 op->atr_cb (op->cls, NULL, NULL, NULL);
662 } 656 }
657 if (NULL != attrs)
658 GNUNET_RECLAIM_attribute_list_destroy (attrs);
659 if (NULL != pl)
660 GNUNET_RECLAIM_presentation_list_destroy (pl);
663 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); 661 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
664 free_op (op); 662 free_op (op);
665 GNUNET_free (attrs);
666 return; 663 return;
667 } 664 }
668 GNUNET_assert (0); 665 GNUNET_assert (0);
@@ -804,7 +801,7 @@ check_credential_result (void *cls, const struct CredentialResultMessage *msg)
804 */ 801 */
805static void 802static void
806handle_credential_result (void *cls, const struct 803handle_credential_result (void *cls, const struct
807 CredentialResultMessage *msg) 804 CredentialResultMessage *msg)
808{ 805{
809 static struct GNUNET_IDENTITY_PrivateKey identity_dummy; 806 static struct GNUNET_IDENTITY_PrivateKey identity_dummy;
810 struct GNUNET_RECLAIM_Handle *h = cls; 807 struct GNUNET_RECLAIM_Handle *h = cls;
@@ -871,6 +868,7 @@ handle_credential_result (void *cls, const struct
871 GNUNET_assert (0); 868 GNUNET_assert (0);
872} 869}
873 870
871
874/** 872/**
875 * Handle an incoming message of type 873 * Handle an incoming message of type
876 * #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT 874 * #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT
@@ -925,7 +923,7 @@ handle_ticket_result (void *cls, const struct TicketResultMessage *msg)
925 if (NULL != op) 923 if (NULL != op)
926 { 924 {
927 if (0 < pres_len) 925 if (0 < pres_len)
928 pres = GNUNET_RECLAIM_presentation_list_deserialize ((char*)&msg[1], 926 pres = GNUNET_RECLAIM_presentation_list_deserialize ((char*) &msg[1],
929 pres_len); 927 pres_len);
930 GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op); 928 GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op);
931 if (0 == 929 if (0 ==
@@ -1485,7 +1483,7 @@ GNUNET_RECLAIM_get_credentials_start (
1485 */ 1483 */
1486void 1484void
1487GNUNET_RECLAIM_get_credentials_next (struct 1485GNUNET_RECLAIM_get_credentials_next (struct
1488 GNUNET_RECLAIM_CredentialIterator *ait) 1486 GNUNET_RECLAIM_CredentialIterator *ait)
1489{ 1487{
1490 struct GNUNET_RECLAIM_Handle *h = ait->h; 1488 struct GNUNET_RECLAIM_Handle *h = ait->h;
1491 struct CredentialIterationNextMessage *msg; 1489 struct CredentialIterationNextMessage *msg;
@@ -1507,7 +1505,7 @@ GNUNET_RECLAIM_get_credentials_next (struct
1507 */ 1505 */
1508void 1506void
1509GNUNET_RECLAIM_get_credentials_stop (struct 1507GNUNET_RECLAIM_get_credentials_stop (struct
1510 GNUNET_RECLAIM_CredentialIterator *ait) 1508 GNUNET_RECLAIM_CredentialIterator *ait)
1511{ 1509{
1512 struct GNUNET_RECLAIM_Handle *h = ait->h; 1510 struct GNUNET_RECLAIM_Handle *h = ait->h;
1513 struct GNUNET_MQ_Envelope *env; 1511 struct GNUNET_MQ_Envelope *env;
diff --git a/src/rest/plugin_rest_copying.c b/src/rest/plugin_rest_copying.c
index 6d074d3d1..52783a81a 100644
--- a/src/rest/plugin_rest_copying.c
+++ b/src/rest/plugin_rest_copying.c
@@ -138,9 +138,9 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle,
138 struct RequestHandle *handle = cls; 138 struct RequestHandle *handle = cls;
139 139
140 resp = GNUNET_REST_create_response (NULL); 140 resp = GNUNET_REST_create_response (NULL);
141 MHD_add_response_header (resp, 141 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
142 "Access-Control-Allow-Methods", 142 "Access-Control-Allow-Methods",
143 MHD_HTTP_METHOD_GET); 143 MHD_HTTP_METHOD_GET));
144 handle->proc (handle->proc_cls, 144 handle->proc (handle->proc_cls,
145 resp, 145 resp,
146 MHD_HTTP_OK); 146 MHD_HTTP_OK);
diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c
index b5737158b..99fecdd35 100644
--- a/src/revocation/gnunet-revocation.c
+++ b/src/revocation/gnunet-revocation.c
@@ -307,17 +307,9 @@ calculate_pow (void *cls)
307 return; 307 return;
308 } 308 }
309 pow_passes++; 309 pow_passes++;
310 /** 310 pow_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
311 * Otherwise CTRL-C does not work 311 &calculate_pow,
312 */ 312 ph);
313 if (0 == pow_passes % 128)
314 pow_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
315 &calculate_pow,
316 ph);
317 else
318 pow_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
319 &calculate_pow,
320 ph);
321 313
322} 314}
323 315
diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c
index 863289aae..6f70720ba 100644
--- a/src/revocation/gnunet-service-revocation.c
+++ b/src/revocation/gnunet-service-revocation.c
@@ -306,12 +306,19 @@ publicize_rm (const struct RevokeMessage *rm)
306 struct RevokeMessage *cp; 306 struct RevokeMessage *cp;
307 struct GNUNET_HashCode hc; 307 struct GNUNET_HashCode hc;
308 struct GNUNET_SETU_Element e; 308 struct GNUNET_SETU_Element e;
309 ssize_t pklen;
309 const struct GNUNET_IDENTITY_PublicKey *pk; 310 const struct GNUNET_IDENTITY_PublicKey *pk;
310 311
311 struct GNUNET_REVOCATION_PowP *pow = (struct GNUNET_REVOCATION_PowP *) &rm[1]; 312 struct GNUNET_REVOCATION_PowP *pow = (struct GNUNET_REVOCATION_PowP *) &rm[1];
312 pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; 313 pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1];
314 pklen = GNUNET_IDENTITY_key_get_length (pk);
315 if (0 > pklen)
316 {
317 GNUNET_break_op (0);
318 return GNUNET_SYSERR;
319 }
313 GNUNET_CRYPTO_hash (pk, 320 GNUNET_CRYPTO_hash (pk,
314 GNUNET_IDENTITY_key_get_length (pk), 321 pklen,
315 &hc); 322 &hc);
316 if (GNUNET_YES == 323 if (GNUNET_YES ==
317 GNUNET_CONTAINER_multihashmap_contains (revocation_map, 324 GNUNET_CONTAINER_multihashmap_contains (revocation_map,
@@ -384,7 +391,8 @@ check_revoke_message (void *cls,
384 uint16_t size; 391 uint16_t size;
385 392
386 size = ntohs (rm->header.size); 393 size = ntohs (rm->header.size);
387 if (size <= sizeof(struct RevokeMessage)) 394 if (size <= sizeof(struct RevokeMessage) ||
395 (size > UINT16_MAX))
388 { 396 {
389 GNUNET_break (0); 397 GNUNET_break (0);
390 return GNUNET_SYSERR; 398 return GNUNET_SYSERR;
diff --git a/src/revocation/plugin_block_revocation.c b/src/revocation/plugin_block_revocation.c
index 3c9344a49..1928d09cd 100644
--- a/src/revocation/plugin_block_revocation.c
+++ b/src/revocation/plugin_block_revocation.c
@@ -134,6 +134,7 @@ block_plugin_revocation_evaluate (void *cls,
134{ 134{
135 struct InternalContext *ic = cls; 135 struct InternalContext *ic = cls;
136 struct GNUNET_HashCode chash; 136 struct GNUNET_HashCode chash;
137 ssize_t pklen;
137 const struct RevokeMessage *rm = reply_block; 138 const struct RevokeMessage *rm = reply_block;
138 139
139 if (NULL == reply_block) 140 if (NULL == reply_block)
@@ -153,8 +154,14 @@ block_plugin_revocation_evaluate (void *cls,
153 GNUNET_break_op (0); 154 GNUNET_break_op (0);
154 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 155 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
155 } 156 }
157 pklen = GNUNET_IDENTITY_key_get_length (pk);
158 if (0 > pklen)
159 {
160 GNUNET_break_op (0);
161 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
162 }
156 GNUNET_CRYPTO_hash (pk, 163 GNUNET_CRYPTO_hash (pk,
157 GNUNET_IDENTITY_key_get_length (pk), 164 pklen,
158 &chash); 165 &chash);
159 if (GNUNET_YES == 166 if (GNUNET_YES ==
160 GNUNET_BLOCK_GROUP_bf_test_and_set (group, 167 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c
index 5cf191847..e2f871c23 100644
--- a/src/revocation/revocation_api.c
+++ b/src/revocation/revocation_api.c
@@ -492,6 +492,7 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow,
492 unsigned int tmp_score = 0; 492 unsigned int tmp_score = 0;
493 unsigned int epochs; 493 unsigned int epochs;
494 uint64_t pow_val; 494 uint64_t pow_val;
495 ssize_t pklen;
495 const struct GNUNET_IDENTITY_PublicKey *pk; 496 const struct GNUNET_IDENTITY_PublicKey *pk;
496 497
497 pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; 498 pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1];
@@ -517,9 +518,15 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow,
517 GNUNET_memcpy (&buf[sizeof(uint64_t)], 518 GNUNET_memcpy (&buf[sizeof(uint64_t)],
518 &pow->timestamp, 519 &pow->timestamp,
519 sizeof (uint64_t)); 520 sizeof (uint64_t));
521 pklen = GNUNET_IDENTITY_key_get_length (pk);
522 if (0 > pklen)
523 {
524 GNUNET_break (0);
525 return GNUNET_NO;
526 }
520 GNUNET_memcpy (&buf[sizeof(uint64_t) * 2], 527 GNUNET_memcpy (&buf[sizeof(uint64_t) * 2],
521 pk, 528 pk,
522 GNUNET_IDENTITY_key_get_length (pk)); 529 pklen);
523 for (unsigned int i = 0; i < POW_COUNT; i++) 530 for (unsigned int i = 0; i < POW_COUNT; i++)
524 { 531 {
525 pow_val = GNUNET_ntohll (pow->pow[i]); 532 pow_val = GNUNET_ntohll (pow->pow[i]);
diff --git a/src/rps/gnunet-rps-profiler.c b/src/rps/gnunet-rps-profiler.c
index 82aeffb79..908dcca17 100644
--- a/src/rps/gnunet-rps-profiler.c
+++ b/src/rps/gnunet-rps-profiler.c
@@ -3067,9 +3067,10 @@ run (void *cls,
3067 } 3067 }
3068 else 3068 else
3069 { 3069 {
3070 duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3070 duration = GNUNET_TIME_relative_multiply (
3071 (timeout.rel_value_us / 1000000) 3071 GNUNET_TIME_UNIT_SECONDS,
3072 * 0.75); 3072 ( (double) timeout.rel_value_us / (double) 1000000)
3073 * 0.75);
3073 } 3074 }
3074 } 3075 }
3075 else 3076 else
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index dc4c5dab7..56eab288e 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -965,8 +965,6 @@ remove_channel_ctx (struct ChannelCtx *channel_ctx)
965 channel_ctx->destruction_task = NULL; 965 channel_ctx->destruction_task = NULL;
966 } 966 }
967 967
968 GNUNET_free (channel_ctx);
969
970 if (NULL == peer_ctx) 968 if (NULL == peer_ctx)
971 return; 969 return;
972 if (channel_ctx == peer_ctx->send_channel_ctx) 970 if (channel_ctx == peer_ctx->send_channel_ctx)
@@ -978,6 +976,7 @@ remove_channel_ctx (struct ChannelCtx *channel_ctx)
978 { 976 {
979 peer_ctx->recv_channel_ctx = NULL; 977 peer_ctx->recv_channel_ctx = NULL;
980 } 978 }
979 GNUNET_free (channel_ctx);
981} 980}
982 981
983 982
@@ -2637,7 +2636,7 @@ insert_in_sampler (void *cls,
2637 } 2636 }
2638#ifdef TO_FILE 2637#ifdef TO_FILE
2639 sub->num_observed_peers++; 2638 sub->num_observed_peers++;
2640 GNUNET_CONTAINER_multipeermap_put 2639 (void) GNUNET_CONTAINER_multipeermap_put
2641 (sub->observed_unique_peers, 2640 (sub->observed_unique_peers,
2642 peer, 2641 peer,
2643 NULL, 2642 NULL,
@@ -2802,7 +2801,7 @@ clean_peer (struct Sub *sub,
2802 peer))) && 2801 peer))) &&
2803 (GNUNET_NO == View_contains_peer (sub->view, peer)) && 2802 (GNUNET_NO == View_contains_peer (sub->view, peer)) &&
2804 (GNUNET_NO == CustomPeerMap_contains_peer (sub->push_map, peer)) && 2803 (GNUNET_NO == CustomPeerMap_contains_peer (sub->push_map, peer)) &&
2805 (GNUNET_NO == CustomPeerMap_contains_peer (sub->push_map, peer)) && 2804 (GNUNET_NO == CustomPeerMap_contains_peer (sub->pull_map, peer)) &&
2806 (0 == RPS_sampler_count_id (sub->sampler, peer)) && 2805 (0 == RPS_sampler_count_id (sub->sampler, peer)) &&
2807 (GNUNET_YES == check_removable (get_peer_ctx (sub->peer_map, peer)))) 2806 (GNUNET_YES == check_removable (get_peer_ctx (sub->peer_map, peer))))
2808 { /* We can safely remove this peer */ 2807 { /* We can safely remove this peer */
@@ -2836,13 +2835,20 @@ cleanup_destroyed_channel (void *cls,
2836 (void) channel; 2835 (void) channel;
2837 2836
2838 channel_ctx->channel = NULL; 2837 channel_ctx->channel = NULL;
2839 remove_channel_ctx (channel_ctx);
2840 if ((NULL != peer_ctx) && 2838 if ((NULL != peer_ctx) &&
2841 (peer_ctx->send_channel_ctx == channel_ctx) && 2839 (peer_ctx->send_channel_ctx == channel_ctx) &&
2842 (GNUNET_YES == check_sending_channel_needed (channel_ctx->peer_ctx)) ) 2840 (GNUNET_YES == check_sending_channel_needed (peer_ctx)) )
2843 { 2841 {
2842 remove_channel_ctx (channel_ctx);
2844 remove_peer (peer_ctx->sub, &peer_ctx->peer_id); 2843 remove_peer (peer_ctx->sub, &peer_ctx->peer_id);
2845 } 2844 }
2845 else
2846 {
2847 /* We need this if-else construct because we need to make sure the channel
2848 * (context) is cleaned up before removing the peer, but still neet to
2849 * compare it while checking the condition */
2850 remove_channel_ctx (channel_ctx);
2851 }
2846} 2852}
2847 2853
2848 2854
diff --git a/src/rps/gnunet-service-rps_custommap.c b/src/rps/gnunet-service-rps_custommap.c
index 54e361d32..392c29397 100644
--- a/src/rps/gnunet-service-rps_custommap.c
+++ b/src/rps/gnunet-service-rps_custommap.c
@@ -206,6 +206,7 @@ CustomPeerMap_remove_peer (const struct CustomPeerMap *c_peer_map,
206 struct GNUNET_PeerIdentity *p; 206 struct GNUNET_PeerIdentity *p;
207 uint32_t *last_index; 207 uint32_t *last_index;
208 struct GNUNET_PeerIdentity *last_p; 208 struct GNUNET_PeerIdentity *last_p;
209 int ret;
209 210
210 if (GNUNET_NO == CustomPeerMap_contains_peer (c_peer_map, 211 if (GNUNET_NO == CustomPeerMap_contains_peer (c_peer_map,
211 peer)) 212 peer))
@@ -234,9 +235,11 @@ CustomPeerMap_remove_peer (const struct CustomPeerMap *c_peer_map,
234 last_p); 235 last_p);
235 GNUNET_assert (NULL != last_index); 236 GNUNET_assert (NULL != last_index);
236 GNUNET_assert (CustomPeerMap_size (c_peer_map) == *last_index); 237 GNUNET_assert (CustomPeerMap_size (c_peer_map) == *last_index);
237 GNUNET_CONTAINER_multihashmap32_put (c_peer_map->hash_map, 238 ret = GNUNET_CONTAINER_multihashmap32_put (c_peer_map->hash_map,
238 *index, last_p, 239 *index,
239 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 240 last_p,
241 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
242 GNUNET_assert (GNUNET_OK == ret);
240 GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map, 243 GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map,
241 *last_index); 244 *last_index);
242 *last_index = *index; 245 *last_index = *index;
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c
index 497225973..6dee20c95 100644
--- a/src/rps/rps-test_util.c
+++ b/src/rps/rps-test_util.c
@@ -152,12 +152,16 @@ close_all_files ()
152{ 152{
153 int ret; 153 int ret;
154 154
155 ret = GNUNET_CONTAINER_multihashmap_iterate (open_files, 155 if (NULL != open_files)
156 close_files_iter, 156 {
157 NULL); 157 ret = GNUNET_CONTAINER_multihashmap_iterate (open_files,
158 GNUNET_CONTAINER_multihashmap_destroy (open_files); 158 close_files_iter,
159 open_files = NULL; 159 NULL);
160 return ret; 160 GNUNET_CONTAINER_multihashmap_destroy (open_files);
161 open_files = NULL;
162 return ret;
163 }
164 return GNUNET_YES;
161} 165}
162 166
163 167
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index 7c1e217bb..7a59670cb 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -94,6 +94,9 @@ lib_LTLIBRARIES = \
94libgnunettestbed_la_SOURCES = \ 94libgnunettestbed_la_SOURCES = \
95 testbed_api.c testbed_api.h testbed.h \ 95 testbed_api.c testbed_api.h testbed.h \
96 testbed_api_hosts.c testbed_api_hosts.h testbed_helper.h \ 96 testbed_api_hosts.c testbed_api_hosts.h testbed_helper.h \
97 testbed_api_cmd_controller.c \
98 testbed_api_cmd_peer.c \
99 testbed_api_cmd_service.c \
97 testbed_api_operations.c testbed_api_operations.h \ 100 testbed_api_operations.c testbed_api_operations.h \
98 testbed_api_peers.c testbed_api_peers.h \ 101 testbed_api_peers.c testbed_api_peers.h \
99 testbed_api_services.c \ 102 testbed_api_services.c \
diff --git a/src/testbed/testbed_api_cmd_controller.c b/src/testbed/testbed_api_cmd_controller.c
new file mode 100644
index 000000000..d65f41760
--- /dev/null
+++ b/src/testbed/testbed_api_cmd_controller.c
@@ -0,0 +1,294 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testbed/testbed_api_cmd_controller.c
23 * @brief Command to create a controller.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "gnunet-service-testbed.h"
30#include "testbed_api_hosts.h"
31#include "gnunet_testbed_ng_service.h"
32
33
34/**
35 * Generic logging shortcut
36 */
37#define LOG(kind, ...) \
38 GNUNET_log (kind, __VA_ARGS__)
39
40
41/**
42 * abort task to run on test timed out
43 *
44 * @param cls NULL
45 * @param tc the task context
46 */
47static void
48do_abort (void *cls)
49{
50 struct ControllerState *cs = cls;
51
52 if (GNUNET_NO == cs->host_ready)
53 {
54 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
55 cs->abort_task = NULL;
56 GNUNET_TESTBED_shutdown_controller (cs);
57 }
58}
59
60
61/**
62*
63*
64* @param cls closure
65* @param cmd current CMD being cleaned up.
66*/
67static void
68controller_cleanup (void *cls,
69 const struct GNUNET_TESTING_Command *cmd)
70{
71 (void) cls;
72}
73
74
75/**
76 * Signature of the event handler function called by the
77 * respective event controller.
78 *
79 * @param cls closure
80 * @param event information about the event
81 */
82static void
83controller_cb (void *cls,
84 const struct GNUNET_TESTBED_EventInformation *event)
85{
86 struct ControllerState *cs = cls;
87
88 if (NULL != event->details.operation_finished.emsg)
89 {
90 LOG (GNUNET_ERROR_TYPE_ERROR, "There was an operation error: %s\n",
91 event->details.operation_finished.emsg);
92 GNUNET_TESTBED_shutdown_controller (cs);
93 }
94 else if (NULL == event->details.operation_finished.generic)
95 {
96 GNUNET_TESTBED_operation_done (event->op);
97 }
98}
99
100
101/**
102 * Callback which will be called to after a host registration succeeded or failed
103 *
104 * @param cls the host which has been registered
105 * @param emsg the error message; NULL if host registration is successful
106 */
107static void
108registration_comp (void *cls,
109 const char *emsg)
110{
111 struct ControllerState *cs = cls;
112
113 if (NULL != emsg)
114 {
115 LOG (GNUNET_ERROR_TYPE_ERROR,
116 "There was an error during host registration: %s\n",
117 emsg);
118 GNUNET_TESTBED_shutdown_controller (cs);
119 }
120 else
121 {
122 cs->reg_handle = NULL;
123 cs->host_ready = GNUNET_YES;
124 GNUNET_TESTING_interpreter_next (cs->is);
125 }
126}
127
128
129/**
130 * Callback to signal successfull startup of the controller process
131 *
132 * @param cls the closure from GNUNET_TESTBED_controller_start()
133 * @param cfg the configuration with which the controller has been started;
134 * NULL if status is not #GNUNET_OK
135 * @param status #GNUNET_OK if the startup is successfull; #GNUNET_SYSERR if not,
136 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
137 */
138static void
139controller_status_cb (void *cls,
140 const struct GNUNET_CONFIGURATION_Handle *cfg_,
141 int status)
142{
143 struct ControllerState *cs = cls;
144
145 if (GNUNET_OK != status)
146 {
147 cs->cp = NULL;
148 return;
149 }
150
151 cs->controller =
152 GNUNET_TESTBED_controller_connect (cs->host, cs->event_mask, &controller_cb,
153 cs);
154 cs->reg_handle =
155 GNUNET_TESTBED_register_host (cs->controller, cs->host, &registration_comp,
156 cs);
157}
158
159
160static void
161controller_run (void *cls,
162 const struct GNUNET_TESTING_Command *cmd,
163 struct GNUNET_TESTING_Interpreter *is)
164{
165 struct ControllerState *cs = cls;
166
167 cs->is = is;
168 cs->host = GNUNET_TESTBED_host_create (cs->hostname, cs->username, cs->cfg,
169 cs->port);
170 cs->cp = GNUNET_TESTBED_controller_start (cs->trusted_ip,
171 cs->host,
172 &controller_status_cb,
173 cs);
174 cs->abort_task =
175 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
176 (GNUNET_TIME_UNIT_MINUTES, 5),
177 &do_abort,
178 cs);
179}
180
181/**
182*
183*
184* @param cls closure.
185* @param[out] ret result
186* @param trait name of the trait.
187* @param index index number of the object to offer.
188* @return #GNUNET_OK on success.
189*/
190static int
191controller_traits (void *cls,
192 const void **ret,
193 const char *trait,
194 unsigned int index)
195{
196 (void) cls;
197
198 struct ControllerState *cs = cls;
199
200
201 struct GNUNET_TESTING_Trait traits[] = {
202 {
203 .index = 0,
204 .trait_name = "controller",
205 .ptr = (const void *) cs->controller,
206 },
207 GNUNET_TESTING_trait_end ()
208 };
209
210 return GNUNET_TESTING_get_trait (traits,
211 ret,
212 trait,
213 index);
214 return GNUNET_OK;
215}
216
217
218/**
219 * Offer data from trait
220 *
221 * @param cmd command to extract the controller from.
222 * @param pt pointer to controller.
223 * @return #GNUNET_OK on success.
224 */
225int
226GNUNET_TESTBED_get_trait_controller (const struct GNUNET_TESTING_Command *cmd,
227 struct GNUNET_TESTBED_Controller **
228 controller)
229{
230 return cmd->traits (cmd->cls,
231 (const void **) controller,
232 "controller",
233 (unsigned int) 0);
234}
235
236
237/**
238 * Shutdown nicely
239 *
240 * @param cs controller state.
241 */
242void
243GNUNET_TESTBED_shutdown_controller (struct ControllerState *cs)
244{
245 LOG (GNUNET_ERROR_TYPE_DEBUG,
246 "Shutting down...\n");
247
248 cs->controller_going_down = GNUNET_YES;
249
250 if (NULL != cs->abort_task)
251 GNUNET_SCHEDULER_cancel (cs->abort_task);
252 if (NULL != cs->reg_handle)
253 GNUNET_TESTBED_cancel_registration (cs->reg_handle);
254 if (NULL != cs->controller)
255 GNUNET_TESTBED_controller_disconnect (cs->controller);
256 if (NULL != cs->cfg)
257 GNUNET_CONFIGURATION_destroy (cs->cfg);
258 if (NULL != cs->cp)
259 GNUNET_TESTBED_controller_stop (cs->cp);
260 if (NULL != cs->host)
261 GNUNET_TESTBED_host_destroy (cs->host);
262}
263
264
265
266struct GNUNET_TESTING_Command
267GNUNET_TESTBED_cmd_controller (const char *label,
268 const char *trusted_ip,
269 const char *hostname,
270 const char *username,
271 uint16_t port,
272 struct GNUNET_CONFIGURATION_Handle *cfg,
273 uint64_t event_mask)
274{
275 struct ControllerState *cs;
276
277 cs = GNUNET_new (struct ControllerState);
278 cs->event_mask = event_mask;
279 cs->trusted_ip = trusted_ip;
280 cs->hostname = hostname;
281 cs->username = username;
282 cs->port = port;
283 cs->cfg = cfg;
284
285 struct GNUNET_TESTING_Command cmd = {
286 .cls = cs,
287 .label = label,
288 .run = &controller_run,
289 .cleanup = &controller_cleanup,
290 .traits = &controller_traits
291 };
292
293 return cmd;
294}
diff --git a/src/testbed/testbed_api_cmd_peer.c b/src/testbed/testbed_api_cmd_peer.c
new file mode 100644
index 000000000..4a727bc94
--- /dev/null
+++ b/src/testbed/testbed_api_cmd_peer.c
@@ -0,0 +1,249 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21
22/**
23 * @file testbed/testbed_api_cmd_controller.c
24 * @brief Command to create a controller.
25 * @author t3sserakt
26 */
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_testing_ng_lib.h"
30#include "gnunet_testbed_ng_service.h"
31#include "gnunet-service-testbed.h"
32#include "testbed_api_peers.h"
33
34
35/**
36 * Generic logging shortcut
37 */
38#define LOG(kind, ...) \
39 GNUNET_log (kind, __VA_ARGS__)
40
41
42/**
43*
44*
45* @param cls closure.
46* @param[out] ret result
47* @param trait name of the trait.
48* @param index index number of the object to offer.
49* @return #GNUNET_OK on success.
50*/
51static int
52peer_traits (void *cls,
53 const void **ret,
54 const char *trait,
55 unsigned int index)
56{
57 (void) cls;
58 return GNUNET_OK;
59}
60
61
62/**
63*
64*
65* @param cls closure
66* @param cmd current CMD being cleaned up.
67*/
68static void
69peer_cleanup (void *cls,
70 const struct GNUNET_TESTING_Command *cmd)
71{
72 (void) cls;
73}
74
75
76/**
77 * abort task to run on test timed out
78 *
79 * @param cls NULL
80 * @param tc the task context
81 */
82static void
83do_abort (void *cls)
84{
85 struct PeerCmdState *ps = cls;
86
87 if (GNUNET_NO == ps->peer_ready)
88 {
89 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
90 ps->abort_task = NULL;
91 GNUNET_TESTBED_shutdown_peer (ps);
92 }
93}
94
95
96/**
97 * Functions of this signature are called when a peer has been successfully
98 * created
99 *
100 * @param cls the closure from GNUNET_TESTBED_peer_create()
101 * @param emsg MAY contain an error description, if starting peer failed.
102 */
103static void
104peer_started_cb (void *cls,
105 const char *emsg)
106{
107 struct PeerCmdState *ps = cls;
108
109 GNUNET_TESTBED_operation_done (ps->operation);
110 if (NULL == emsg)
111 {
112 ps->peer_ready = GNUNET_YES;
113 GNUNET_TESTING_interpreter_next (ps->is);
114 }
115 else
116 {
117 LOG (GNUNET_ERROR_TYPE_ERROR, "There was an error starting a peer: %s\n",
118 emsg);
119 }
120
121}
122
123
124/**
125 * Functions of this signature are called when a peer has been successfully
126 * created
127 *
128 * @param cls the closure from GNUNET_TESTBED_peer_create()
129 * @param peer the handle for the created peer; NULL on any error during
130 * creation
131 * @param emsg NULL if peer is not NULL; else MAY contain the error description
132 */
133static void
134peer_create_cb (void *cls,
135 struct GNUNET_TESTBED_Peer *peer,
136 const char *emsg)
137{
138 struct PeerCmdState *ps = cls;
139
140 ps->peer = peer;
141 GNUNET_TESTBED_operation_done (ps->operation);
142 ps->operation = GNUNET_TESTBED_peer_start (NULL,
143 peer,
144 &peer_started_cb,
145 ps);
146}
147
148
149static void
150peer_run (void *cls,
151 const struct GNUNET_TESTING_Command *cmd,
152 struct GNUNET_TESTING_Interpreter *is)
153{
154 struct PeerCmdState *ps = cls;
155 const struct GNUNET_TESTING_Command *controller_cmd;
156 struct GNUNET_TESTBED_Controller *controller;
157
158 ps->is = is;
159 controller_cmd = GNUNET_TESTING_interpreter_lookup_command (
160 ps->controller_label);
161 GNUNET_TESTBED_get_trait_controller (controller_cmd,
162 &controller);
163 ps->host = GNUNET_TESTBED_host_create (ps->hostname, ps->username, ps->cfg,
164 ps->port);
165 ps->operation =
166 GNUNET_TESTBED_peer_create (controller,
167 ps->host,
168 ps->cfg,
169 &peer_create_cb,
170 ps);
171
172 ps->abort_task =
173 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
174 (GNUNET_TIME_UNIT_MINUTES, 5),
175 &do_abort,
176 ps);
177}
178
179
180void
181peer_stopped_cb (void *cls,
182 const char *emsg)
183{
184 struct PeerCmdState *ps = cls;
185
186 if (NULL != emsg)
187 {
188 LOG (GNUNET_ERROR_TYPE_ERROR, "There was an error stopping a peer: %s\n",
189 emsg);
190 }
191 GNUNET_TESTBED_operation_done (ps->operation);
192 GNUNET_TESTBED_peer_destroy (ps->peer);
193}
194
195
196/**
197 * Shutdown nicely
198 *
199 * @param cs controller state.
200 */
201void
202GNUNET_TESTBED_shutdown_peer (struct PeerCmdState *ps)
203{
204 LOG (GNUNET_ERROR_TYPE_DEBUG,
205 "Shutting down...\n");
206
207 ps->peer_going_down = GNUNET_YES;
208
209 if (NULL != ps->abort_task)
210 GNUNET_SCHEDULER_cancel (ps->abort_task);
211 if (NULL != ps->cfg)
212 GNUNET_CONFIGURATION_destroy (ps->cfg);
213 if (NULL != ps->host)
214 GNUNET_TESTBED_host_destroy (ps->host);
215
216 GNUNET_TESTBED_operation_done (ps->operation);
217 ps->operation = GNUNET_TESTBED_peer_stop (NULL, ps->peer, peer_stopped_cb,
218 ps);
219
220}
221
222
223struct GNUNET_TESTING_Command
224GNUNET_TESTBED_cmd_peer (const char *label,
225 const char *controller_label,
226 const char *hostname,
227 const char *username,
228 uint16_t port,
229 struct GNUNET_CONFIGURATION_Handle *cfg)
230{
231 struct PeerCmdState *ps;
232
233 ps = GNUNET_new (struct PeerCmdState);
234 ps->hostname = hostname;
235 ps->username = username;
236 ps->port = port;
237 ps->cfg = cfg;
238 ps->controller_label = controller_label;
239
240 struct GNUNET_TESTING_Command cmd = {
241 .cls = ps,
242 .label = label,
243 .run = &peer_run,
244 .cleanup = &peer_cleanup,
245 .traits = &peer_traits
246 };
247
248 return cmd;
249}
diff --git a/src/testbed/testbed_api_cmd_service.c b/src/testbed/testbed_api_cmd_service.c
new file mode 100644
index 000000000..58b3309de
--- /dev/null
+++ b/src/testbed/testbed_api_cmd_service.c
@@ -0,0 +1,140 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testbed/testbed_api_cmd_controller.c
23 * @brief Command to create a controller.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "gnunet-service-testbed.h"
30#include "testbed_api_hosts.h"
31#include "gnunet_testbed_ng_service.h"
32
33/**
34 * Generic logging shortcut
35 */
36#define LOG(kind, ...) \
37 GNUNET_log (kind, __VA_ARGS__)
38
39
40/**
41 * abort task to run on test timed out
42 *
43 * @param cls NULL
44 * @param tc the task context
45 */
46static void
47do_abort (void *cls)
48{
49 struct ServiceState *ss = cls;
50
51 if (GNUNET_NO == ss->service_ready)
52 {
53 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
54 ss->abort_task = NULL;
55 GNUNET_TESTBED_shutdown_service (ss);
56 }
57}
58
59/**
60*
61*
62* @param cls closure
63* @param cmd current CMD being cleaned up.
64*/
65static void
66service_cleanup (void *cls,
67 const struct GNUNET_TESTING_Command *cmd)
68{
69 (void) cls;
70}
71
72/**
73*
74*
75* @param cls closure.
76* @param[out] ret result
77* @param trait name of the trait.
78* @param index index number of the object to offer.
79* @return #GNUNET_OK on success.
80*/
81static int
82service_traits (void *cls,
83 const void **ret,
84 const char *trait,
85 unsigned int index)
86{
87 (void) cls;
88 return GNUNET_OK;
89}
90
91static void
92service_run (void *cls,
93 const struct GNUNET_TESTING_Command *cmd,
94 struct GNUNET_TESTING_Interpreter *is)
95{
96 struct ServiceState *ss = cls;
97
98 // TODO this is unfinished code!
99 ss->operation =
100 GNUNET_TESTBED_service_connect (NULL, NULL, NULL,
101 NULL, NULL,
102 NULL,
103 NULL, NULL);
104
105}
106
107/**
108 * Shutdown nicely
109 *
110 * @param cs service state.
111 */
112void
113GNUNET_TESTBED_shutdown_service (struct ServiceState *cs)
114{
115 LOG (GNUNET_ERROR_TYPE_DEBUG,
116 "Shutting down...\n");
117}
118
119
120struct GNUNET_TESTING_Command
121GNUNET_TESTBED_cmd_service (const char *label,
122 const char *peer_label,
123 const char *servicename)
124{
125 struct ServiceState *ss;
126
127 ss = GNUNET_new (struct ServiceState);
128 ss->servicename = servicename;
129 ss->peer_label = peer_label;
130
131 struct GNUNET_TESTING_Command cmd = {
132 .cls = ss,
133 .label = label,
134 .run = &service_run,
135 .cleanup = &service_cleanup,
136 .traits = &service_traits
137 };
138
139 return cmd;
140}
diff --git a/src/testing/testing_api_cmd_hello_world_birth.c b/src/testing/testing_api_cmd_hello_world_birth.c
index 546b30212..0faf93cd8 100644
--- a/src/testing/testing_api_cmd_hello_world_birth.c
+++ b/src/testing/testing_api_cmd_hello_world_birth.c
@@ -118,10 +118,8 @@ hello_world_birth_run (void *cls,
118/** 118/**
119 * Offer data from trait 119 * Offer data from trait
120 * 120 *
121 * @param cmd command to extract the url from. 121 * @param cmd command to extract the message from.
122 * @param pt which url is to be picked, in case 122 * @param pt pointer to message.
123 * multiple are offered.
124 * @param[out] url where to write the url.
125 * @return #GNUNET_OK on success. 123 * @return #GNUNET_OK on success.
126 */ 124 */
127int 125int
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c
index c8a4c0375..9dd2797df 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -877,12 +877,14 @@ queue_destroy (struct Queue *queue)
877{ 877{
878 struct ListenTask *lt = NULL; 878 struct ListenTask *lt = NULL;
879 struct GNUNET_HashCode h_sock; 879 struct GNUNET_HashCode h_sock;
880 int sockfd;
880 881
881 GNUNET_CRYPTO_hash (queue->listen_sock, 882 sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock);
882 sizeof(queue->listen_sock), 883 GNUNET_CRYPTO_hash (&sockfd,
884 sizeof(int),
883 &h_sock); 885 &h_sock);
884 886
885 lt = GNUNET_CONTAINER_multihashmap_get (lt_map, &h_sock); 887 lt = GNUNET_CONTAINER_multihashmap_get (lt_map, &h_sock);
886 888
887 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
888 "Disconnecting queue for peer `%s'\n", 890 "Disconnecting queue for peer `%s'\n",
@@ -1263,7 +1265,8 @@ rekey_monotime_cb (void *cls,
1263 pid, 1265 pid,
1264 GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY, 1266 GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY,
1265 rekey_monotonic_time, 1267 rekey_monotonic_time,
1266 sizeof(rekey_monotonic_time), 1268 sizeof(*
1269 rekey_monotonic_time),
1267 GNUNET_TIME_UNIT_FOREVER_ABS, 1270 GNUNET_TIME_UNIT_FOREVER_ABS,
1268 GNUNET_PEERSTORE_STOREOPTION_REPLACE, 1271 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
1269 &rekey_monotime_store_cb, 1272 &rekey_monotime_store_cb,
@@ -1413,18 +1416,18 @@ handshake_ack_monotime_cb (void *cls,
1413 queue_finish (queue); 1416 queue_finish (queue);
1414 return; 1417 return;
1415 } 1418 }
1416 queue->handshake_ack_monotime_sc = GNUNET_PEERSTORE_store (peerstore, 1419 queue->handshake_ack_monotime_sc =
1417 "transport_tcp_communicator", 1420 GNUNET_PEERSTORE_store (peerstore,
1418 pid, 1421 "transport_tcp_communicator",
1419 GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK, 1422 pid,
1420 handshake_ack_monotonic_time, 1423 GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK,
1421 sizeof( 1424 handshake_ack_monotonic_time,
1422 handshake_ack_monotonic_time), 1425 sizeof(*handshake_ack_monotonic_time),
1423 GNUNET_TIME_UNIT_FOREVER_ABS, 1426 GNUNET_TIME_UNIT_FOREVER_ABS,
1424 GNUNET_PEERSTORE_STOREOPTION_REPLACE, 1427 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
1425 & 1428 &
1426 handshake_ack_monotime_store_cb, 1429 handshake_ack_monotime_store_cb,
1427 queue); 1430 queue);
1428} 1431}
1429 1432
1430 1433
@@ -3255,6 +3258,7 @@ init_socket (struct sockaddr *addr,
3255 socklen_t sto_len; 3258 socklen_t sto_len;
3256 struct GNUNET_NETWORK_Handle *listen_sock; 3259 struct GNUNET_NETWORK_Handle *listen_sock;
3257 struct ListenTask *lt; 3260 struct ListenTask *lt;
3261 int sockfd;
3258 struct GNUNET_HashCode h_sock; 3262 struct GNUNET_HashCode h_sock;
3259 3263
3260 if (NULL == addr) 3264 if (NULL == addr)
@@ -3343,8 +3347,9 @@ init_socket (struct sockaddr *addr,
3343 3347
3344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3345 "creating hash\n"); 3349 "creating hash\n");
3346 GNUNET_CRYPTO_hash (lt->listen_sock, 3350 sockfd = GNUNET_NETWORK_get_fd (lt->listen_sock);
3347 sizeof(lt->listen_sock), 3351 GNUNET_CRYPTO_hash (&sockfd,
3352 sizeof(int),
3348 &h_sock); 3353 &h_sock);
3349 3354
3350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -3564,6 +3569,7 @@ run (void *cls,
3564 peerstore = GNUNET_PEERSTORE_connect (cfg); 3569 peerstore = GNUNET_PEERSTORE_connect (cfg);
3565 if (NULL == peerstore) 3570 if (NULL == peerstore)
3566 { 3571 {
3572 GNUNET_free (bindto);
3567 GNUNET_break (0); 3573 GNUNET_break (0);
3568 GNUNET_SCHEDULER_shutdown (); 3574 GNUNET_SCHEDULER_shutdown ();
3569 return; 3575 return;
@@ -3596,7 +3602,6 @@ run (void *cls,
3596 GNUNET_free (po); 3602 GNUNET_free (po);
3597 nat_register (); 3603 nat_register ();
3598 GNUNET_free (bindto); 3604 GNUNET_free (bindto);
3599
3600 return; 3605 return;
3601 } 3606 }
3602 3607
@@ -3609,8 +3614,8 @@ run (void *cls,
3609 in = tcp_address_to_sockaddr_numeric_v4 (&in_len, v4, bind_port); 3614 in = tcp_address_to_sockaddr_numeric_v4 (&in_len, v4, bind_port);
3610 init_socket (in, in_len); 3615 init_socket (in, in_len);
3611 nat_register (); 3616 nat_register ();
3617 GNUNET_free (start);
3612 GNUNET_free (bindto); 3618 GNUNET_free (bindto);
3613
3614 return; 3619 return;
3615 } 3620 }
3616 3621
@@ -3620,8 +3625,8 @@ run (void *cls,
3620 in = tcp_address_to_sockaddr_numeric_v6 (&in_len, v6, bind_port); 3625 in = tcp_address_to_sockaddr_numeric_v6 (&in_len, v6, bind_port);
3621 init_socket (in, in_len); 3626 init_socket (in, in_len);
3622 nat_register (); 3627 nat_register ();
3628 GNUNET_free (start);
3623 GNUNET_free (bindto); 3629 GNUNET_free (bindto);
3624
3625 return; 3630 return;
3626 } 3631 }
3627 3632
@@ -3635,6 +3640,7 @@ run (void *cls,
3635 &init_socket_resolv, 3640 &init_socket_resolv,
3636 &port); 3641 &port);
3637 GNUNET_free (bindto); 3642 GNUNET_free (bindto);
3643 GNUNET_free (start);
3638} 3644}
3639 3645
3640 3646
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c
index 415dc4b48..d75f4ae00 100644
--- a/src/transport/gnunet-communicator-udp.c
+++ b/src/transport/gnunet-communicator-udp.c
@@ -1492,16 +1492,9 @@ add_acks (struct SharedSecret *ss, int acks_to_add)
1492 1492
1493 struct ReceiverAddress *receiver = ss->receiver; 1493 struct ReceiverAddress *receiver = ss->receiver;
1494 1494
1495 if (NULL == ss) 1495 GNUNET_assert (NULL != ss);
1496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1496 GNUNET_assert (NULL != receiver);
1497 "secret NULL!\n"); 1497 GNUNET_assert (NULL != receiver->d_qh);
1498
1499 if (NULL == receiver)
1500 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1501 "Receiver NULL!\n");
1502 if (NULL == receiver->d_qh)
1503 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1504 "Queue NULL!\n");
1505 1498
1506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1499 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1507 "Tell transport we have %u more acks!\n", 1500 "Tell transport we have %u more acks!\n",
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index 3cba49250..cbf795eea 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -6976,7 +6976,6 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
6976 if (MAX_DV_HOPS_ALLOWED == nhops) 6976 if (MAX_DV_HOPS_ALLOWED == nhops)
6977 { 6977 {
6978 /* At limit, we're out of here! */ 6978 /* At limit, we're out of here! */
6979 finish_cmc_handling (cmc);
6980 return; 6979 return;
6981 } 6980 }
6982 6981
@@ -9640,11 +9639,13 @@ handle_add_queue_message (void *cls,
9640 { 9639 {
9641 if (queue->qid != aqm->qid) 9640 if (queue->qid != aqm->qid)
9642 continue; 9641 continue;
9643 neighbour = queue->neighbour;
9644 break; 9642 break;
9645 } 9643 }
9646 if (NULL == queue) 9644
9645 if (NULL != queue)
9647 { 9646 {
9647 neighbour = queue->neighbour;
9648 } else {
9648 neighbour = lookup_neighbour (&aqm->receiver); 9649 neighbour = lookup_neighbour (&aqm->receiver);
9649 if (NULL == neighbour) 9650 if (NULL == neighbour)
9650 { 9651 {
diff --git a/src/transport/transport-testing-communicator.c b/src/transport/transport-testing-communicator.c
index de356fb9c..040f16d5d 100644
--- a/src/transport/transport-testing-communicator.c
+++ b/src/transport/transport-testing-communicator.c
@@ -548,6 +548,11 @@ handle_update_queue_message (void *cls,
548 tc_queue = tc_queue->next; 548 tc_queue = tc_queue->next;
549 } 549 }
550 } 550 }
551 if (NULL == tc_queue)
552 {
553 GNUNET_SERVICE_client_continue (client->client);
554 return;
555 }
551 GNUNET_assert (tc_queue->qid == msg->qid); 556 GNUNET_assert (tc_queue->qid == msg->qid);
552 GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id, &msg->receiver)); 557 GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id, &msg->receiver));
553 tc_queue->nt = msg->nt; 558 tc_queue->nt = msg->nt;
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index 6b9e083a7..e2614e5e3 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -25,6 +25,11 @@ if ENABLE_BENCHMARK
25 PTHREAD = -lpthread 25 PTHREAD = -lpthread
26endif 26endif
27 27
28if HAVE_NOLIBGCRYPT19
29 DLOG = crypto_ecc_dlog.c
30 DLOG_TEST = test_crypto_ecc_dlog
31endif
32
28gnunet_config_diff_SOURCES = \ 33gnunet_config_diff_SOURCES = \
29 gnunet-config-diff.c 34 gnunet-config-diff.c
30gnunet_config_diff_LDADD = \ 35gnunet_config_diff_LDADD = \
@@ -58,7 +63,7 @@ libgnunetutil_la_SOURCES = \
58 crypto_symmetric.c \ 63 crypto_symmetric.c \
59 crypto_crc.c \ 64 crypto_crc.c \
60 crypto_ecc.c \ 65 crypto_ecc.c \
61 crypto_ecc_dlog.c \ 66 $(DLOG) \
62 crypto_ecc_setup.c \ 67 crypto_ecc_setup.c \
63 crypto_hash.c \ 68 crypto_hash.c \
64 crypto_hash_file.c \ 69 crypto_hash_file.c \
@@ -248,7 +253,6 @@ libgnunet_plugin_test_la_LDFLAGS = \
248if HAVE_BENCHMARKS 253if HAVE_BENCHMARKS
249 BENCHMARKS = \ 254 BENCHMARKS = \
250 perf_crypto_hash \ 255 perf_crypto_hash \
251 perf_crypto_ecc_dlog \
252 perf_crypto_rsa \ 256 perf_crypto_rsa \
253 perf_crypto_paillier \ 257 perf_crypto_paillier \
254 perf_crypto_symmetric \ 258 perf_crypto_symmetric \
@@ -256,6 +260,10 @@ if HAVE_BENCHMARKS
256 perf_malloc \ 260 perf_malloc \
257 perf_mq \ 261 perf_mq \
258 perf_scheduler 262 perf_scheduler
263
264if HAVE_NOLIBGCRYPT19
265 BENCHMARKS += perf_crypto_ecc_dlog
266endif
259endif 267endif
260 268
261if HAVE_SSH_KEY 269if HAVE_SSH_KEY
@@ -287,7 +295,7 @@ check_PROGRAMS = \
287 test_crypto_ecdhe \ 295 test_crypto_ecdhe \
288 test_crypto_ecdh_eddsa \ 296 test_crypto_ecdh_eddsa \
289 test_crypto_ecdh_ecdsa \ 297 test_crypto_ecdh_ecdsa \
290 test_crypto_ecc_dlog \ 298 $(DLOG_TEST) \
291 test_crypto_hash \ 299 test_crypto_hash \
292 test_crypto_hash_context \ 300 test_crypto_hash_context \
293 test_crypto_hkdf \ 301 test_crypto_hkdf \
@@ -448,11 +456,13 @@ test_crypto_eddsa_LDADD = \
448 libgnunetutil.la \ 456 libgnunetutil.la \
449 $(LIBGCRYPT_LIBS) 457 $(LIBGCRYPT_LIBS)
450 458
459if HAVE_NOLIBGCRYPT19
451test_crypto_ecc_dlog_SOURCES = \ 460test_crypto_ecc_dlog_SOURCES = \
452 test_crypto_ecc_dlog.c 461 test_crypto_ecc_dlog.c
453test_crypto_ecc_dlog_LDADD = \ 462test_crypto_ecc_dlog_LDADD = \
454 libgnunetutil.la \ 463 libgnunetutil.la \
455 $(LIBGCRYPT_LIBS) 464 $(LIBGCRYPT_LIBS)
465endif
456 466
457test_crypto_ecdhe_SOURCES = \ 467test_crypto_ecdhe_SOURCES = \
458 test_crypto_ecdhe.c 468 test_crypto_ecdhe.c
@@ -595,11 +605,13 @@ perf_crypto_hash_SOURCES = \
595perf_crypto_hash_LDADD = \ 605perf_crypto_hash_LDADD = \
596 libgnunetutil.la 606 libgnunetutil.la
597 607
608if HAVE_NOLIBGCRYPT19
598perf_crypto_ecc_dlog_SOURCES = \ 609perf_crypto_ecc_dlog_SOURCES = \
599 perf_crypto_ecc_dlog.c 610 perf_crypto_ecc_dlog.c
600perf_crypto_ecc_dlog_LDADD = \ 611perf_crypto_ecc_dlog_LDADD = \
601 libgnunetutil.la \ 612 libgnunetutil.la \
602 -lgcrypt 613 -lgcrypt
614endif
603 615
604perf_crypto_rsa_SOURCES = \ 616perf_crypto_rsa_SOURCES = \
605 perf_crypto_rsa.c 617 perf_crypto_rsa.c
diff --git a/src/util/configuration.c b/src/util/configuration.c
index bda643b83..3294d11f4 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -606,6 +606,7 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
606 if (NULL == h) 606 if (NULL == h)
607 { 607 {
608 GNUNET_free (fn); 608 GNUNET_free (fn);
609 GNUNET_free (cfg_buf);
609 return GNUNET_SYSERR; 610 return GNUNET_SYSERR;
610 } 611 }
611 if (((ssize_t) size) != 612 if (((ssize_t) size) !=
diff --git a/src/util/container_meta_data.c b/src/util/container_meta_data.c
index b66a7b258..efaac1136 100644
--- a/src/util/container_meta_data.c
+++ b/src/util/container_meta_data.c
@@ -964,6 +964,9 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData
964 { 964 {
965 /* does not fit! */ 965 /* does not fit! */
966 GNUNET_free (ent); 966 GNUNET_free (ent);
967 if (NULL != cdata)
968 GNUNET_free (cdata);
969 cdata = NULL;
967 return GNUNET_SYSERR; 970 return GNUNET_SYSERR;
968 } 971 }
969 972
@@ -976,9 +979,9 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData
976 if (NULL != pos->mime_type) 979 if (NULL != pos->mime_type)
977 left -= strlen (pos->mime_type) + 1; 980 left -= strlen (pos->mime_type) + 1;
978 981
979 GNUNET_free (cdata); 982 if (NULL != cdata)
983 GNUNET_free (cdata);
980 cdata = NULL; 984 cdata = NULL;
981
982 i++; 985 i++;
983 } 986 }
984 GNUNET_free (ent); 987 GNUNET_free (ent);
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c
index 63232cab6..5e4c4d1e6 100644
--- a/src/util/crypto_rsa.c
+++ b/src/util/crypto_rsa.c
@@ -863,6 +863,7 @@ rsa_sign_mpi (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
863 __FILE__, 863 __FILE__,
864 __LINE__, 864 __LINE__,
865 gcry_strerror (rc)); 865 gcry_strerror (rc));
866 gcry_sexp_release (data);
866 GNUNET_break (0); 867 GNUNET_break (0);
867 return NULL; 868 return NULL;
868 } 869 }
diff --git a/src/util/gnunet-crypto-tvg.c b/src/util/gnunet-crypto-tvg.c
index 8949f427c..28e44e28b 100644
--- a/src/util/gnunet-crypto-tvg.c
+++ b/src/util/gnunet-crypto-tvg.c
@@ -128,6 +128,7 @@ d2j (json_t *vec,
128 json_object_set_new (vec, label, json); 128 json_object_set_new (vec, label, json);
129} 129}
130 130
131
131/** 132/**
132 * Add a number to a test vector. 133 * Add a number to a test vector.
133 * 134 *
@@ -138,8 +139,8 @@ d2j (json_t *vec,
138 */ 139 */
139static void 140static void
140uint2j (json_t *vec, 141uint2j (json_t *vec,
141 const char *label, 142 const char *label,
142 unsigned int num) 143 unsigned int num)
143{ 144{
144 json_t *json = json_integer (num); 145 json_t *json = json_integer (num);
145 146
@@ -154,7 +155,7 @@ expect_data_fixed (json_t *vec,
154 size_t expect_len) 155 size_t expect_len)
155{ 156{
156 const char *s = json_string_value (json_object_get (vec, name)); 157 const char *s = json_string_value (json_object_get (vec, name));
157 158
158 if (NULL == s) 159 if (NULL == s)
159 return GNUNET_NO; 160 return GNUNET_NO;
160 161
@@ -166,6 +167,7 @@ expect_data_fixed (json_t *vec,
166 return GNUNET_OK; 167 return GNUNET_OK;
167} 168}
168 169
170
169static int 171static int
170expect_data_dynamic (json_t *vec, 172expect_data_dynamic (json_t *vec,
171 const char *name, 173 const char *name,
@@ -173,6 +175,7 @@ expect_data_dynamic (json_t *vec,
173 size_t *ret_len) 175 size_t *ret_len)
174{ 176{
175 const char *s = json_string_value (json_object_get (vec, name)); 177 const char *s = json_string_value (json_object_get (vec, name));
178 char *tmp;
176 size_t len; 179 size_t len;
177 180
178 if (NULL == s) 181 if (NULL == s)
@@ -181,10 +184,14 @@ expect_data_dynamic (json_t *vec,
181 len = (strlen (s) * 5) / 8; 184 len = (strlen (s) * 5) / 8;
182 if (NULL != ret_len) 185 if (NULL != ret_len)
183 *ret_len = len; 186 *ret_len = len;
184 *data = GNUNET_malloc (len); 187 tmp = GNUNET_malloc (len);
185 188
186 if (GNUNET_OK != GNUNET_STRINGS_string_to_data (s, strlen (s), *data, len)) 189 if (GNUNET_OK != GNUNET_STRINGS_string_to_data (s, strlen (s), tmp, len))
190 {
191 GNUNET_free (tmp);
187 return GNUNET_NO; 192 return GNUNET_NO;
193 }
194 *data = tmp;
188 return GNUNET_OK; 195 return GNUNET_OK;
189} 196}
190 197
@@ -197,7 +204,7 @@ expect_data_dynamic (json_t *vec,
197 * 204 *
198 * @returns GNUNET_OK if the vector is okay 205 * @returns GNUNET_OK if the vector is okay
199 */ 206 */
200static int 207static int
201checkvec (const char *operation, 208checkvec (const char *operation,
202 json_t *vec) 209 json_t *vec)
203{ 210{
@@ -220,10 +227,11 @@ checkvec (const char *operation,
220 return GNUNET_SYSERR; 227 return GNUNET_SYSERR;
221 } 228 }
222 if (GNUNET_OK != expect_data_fixed (vec, 229 if (GNUNET_OK != expect_data_fixed (vec,
223 "output", 230 "output",
224 &hash_out, 231 &hash_out,
225 sizeof (hash_out))) 232 sizeof (hash_out)))
226 { 233 {
234 GNUNET_free (data);
227 GNUNET_break (0); 235 GNUNET_break (0);
228 return GNUNET_NO; 236 return GNUNET_NO;
229 } 237 }
@@ -232,9 +240,11 @@ checkvec (const char *operation,
232 240
233 if (0 != GNUNET_memcmp (&hc, &hash_out)) 241 if (0 != GNUNET_memcmp (&hc, &hash_out))
234 { 242 {
243 GNUNET_free (data);
235 GNUNET_break (0); 244 GNUNET_break (0);
236 return GNUNET_NO; 245 return GNUNET_NO;
237 } 246 }
247 GNUNET_free (data);
238 } 248 }
239 else if (0 == strcmp (operation, "ecc_ecdh")) 249 else if (0 == strcmp (operation, "ecc_ecdh"))
240 { 250 {
@@ -245,33 +255,33 @@ checkvec (const char *operation,
245 struct GNUNET_HashCode skm_comp; 255 struct GNUNET_HashCode skm_comp;
246 256
247 if (GNUNET_OK != expect_data_fixed (vec, 257 if (GNUNET_OK != expect_data_fixed (vec,
248 "priv1", 258 "priv1",
249 &priv1, 259 &priv1,
250 sizeof (priv1))) 260 sizeof (priv1)))
251 { 261 {
252 GNUNET_break (0); 262 GNUNET_break (0);
253 return GNUNET_NO; 263 return GNUNET_NO;
254 } 264 }
255 if (GNUNET_OK != expect_data_fixed (vec, 265 if (GNUNET_OK != expect_data_fixed (vec,
256 "priv2", 266 "priv2",
257 &priv2, 267 &priv2,
258 sizeof (priv2))) 268 sizeof (priv2)))
259 { 269 {
260 GNUNET_break (0); 270 GNUNET_break (0);
261 return GNUNET_NO; 271 return GNUNET_NO;
262 } 272 }
263 if (GNUNET_OK != expect_data_fixed (vec, 273 if (GNUNET_OK != expect_data_fixed (vec,
264 "pub1", 274 "pub1",
265 &pub1, 275 &pub1,
266 sizeof (pub1))) 276 sizeof (pub1)))
267 { 277 {
268 GNUNET_break (0); 278 GNUNET_break (0);
269 return GNUNET_NO; 279 return GNUNET_NO;
270 } 280 }
271 if (GNUNET_OK != expect_data_fixed (vec, 281 if (GNUNET_OK != expect_data_fixed (vec,
272 "skm", 282 "skm",
273 &skm, 283 &skm,
274 sizeof (skm))) 284 sizeof (skm)))
275 { 285 {
276 GNUNET_break (0); 286 GNUNET_break (0);
277 return GNUNET_NO; 287 return GNUNET_NO;
@@ -407,6 +417,8 @@ checkvec (const char *operation,
407 &ikm, 417 &ikm,
408 &ikm_len)) 418 &ikm_len))
409 { 419 {
420 GNUNET_free (out);
421 GNUNET_free (out_comp);
410 GNUNET_break (0); 422 GNUNET_break (0);
411 return GNUNET_SYSERR; 423 return GNUNET_SYSERR;
412 } 424 }
@@ -416,6 +428,9 @@ checkvec (const char *operation,
416 &salt, 428 &salt,
417 &salt_len)) 429 &salt_len))
418 { 430 {
431 GNUNET_free (out);
432 GNUNET_free (out_comp);
433 GNUNET_free (ikm);
419 GNUNET_break (0); 434 GNUNET_break (0);
420 return GNUNET_SYSERR; 435 return GNUNET_SYSERR;
421 } 436 }
@@ -425,6 +440,10 @@ checkvec (const char *operation,
425 &ctx, 440 &ctx,
426 &ctx_len)) 441 &ctx_len))
427 { 442 {
443 GNUNET_free (out);
444 GNUNET_free (out_comp);
445 GNUNET_free (ikm);
446 GNUNET_free (salt);
428 GNUNET_break (0); 447 GNUNET_break (0);
429 return GNUNET_SYSERR; 448 return GNUNET_SYSERR;
430 } 449 }
@@ -442,10 +461,19 @@ checkvec (const char *operation,
442 461
443 if (0 != memcmp (out, out_comp, out_len)) 462 if (0 != memcmp (out, out_comp, out_len))
444 { 463 {
464 GNUNET_free (out);
465 GNUNET_free (out_comp);
466 GNUNET_free (ikm);
467 GNUNET_free (salt);
468 GNUNET_free (ctx);
445 GNUNET_break (0); 469 GNUNET_break (0);
446 return GNUNET_NO; 470 return GNUNET_NO;
447 } 471 }
448 472 GNUNET_free (out);
473 GNUNET_free (out_comp);
474 GNUNET_free (ikm);
475 GNUNET_free (salt);
476 GNUNET_free (ctx);
449 } 477 }
450 else if (0 == strcmp (operation, "eddsa_ecdh")) 478 else if (0 == strcmp (operation, "eddsa_ecdh"))
451 { 479 {
@@ -562,6 +590,7 @@ checkvec (const char *operation,
562 &public_enc_data, 590 &public_enc_data,
563 &public_enc_len)) 591 &public_enc_len))
564 { 592 {
593 GNUNET_free (blinded_data);
565 GNUNET_break (0); 594 GNUNET_break (0);
566 return GNUNET_SYSERR; 595 return GNUNET_SYSERR;
567 } 596 }
@@ -571,6 +600,8 @@ checkvec (const char *operation,
571 &secret_enc_data, 600 &secret_enc_data,
572 &secret_enc_len)) 601 &secret_enc_len))
573 { 602 {
603 GNUNET_free (blinded_data);
604 GNUNET_free (public_enc_data);
574 GNUNET_break (0); 605 GNUNET_break (0);
575 return GNUNET_SYSERR; 606 return GNUNET_SYSERR;
576 } 607 }
@@ -580,6 +611,9 @@ checkvec (const char *operation,
580 &sig_enc_data, 611 &sig_enc_data,
581 &sig_enc_length)) 612 &sig_enc_length))
582 { 613 {
614 GNUNET_free (blinded_data);
615 GNUNET_free (public_enc_data);
616 GNUNET_free (secret_enc_data);
583 GNUNET_break (0); 617 GNUNET_break (0);
584 return GNUNET_SYSERR; 618 return GNUNET_SYSERR;
585 } 619 }
@@ -601,6 +635,11 @@ checkvec (const char *operation,
601 blinded_data_comp, 635 blinded_data_comp,
602 blinded_len)) ) 636 blinded_len)) )
603 { 637 {
638 GNUNET_free (blinded_data);
639 GNUNET_free (public_enc_data);
640 GNUNET_free (secret_enc_data);
641 GNUNET_free (sig_enc_data);
642 GNUNET_free (skey);
604 GNUNET_break (0); 643 GNUNET_break (0);
605 return GNUNET_NO; 644 return GNUNET_NO;
606 } 645 }
@@ -611,14 +650,27 @@ checkvec (const char *operation,
611 pkey)); 650 pkey));
612 public_enc_len = GNUNET_CRYPTO_rsa_public_key_encode (pkey, 651 public_enc_len = GNUNET_CRYPTO_rsa_public_key_encode (pkey,
613 &public_enc_data); 652 &public_enc_data);
614 sig_enc_length_comp = GNUNET_CRYPTO_rsa_signature_encode (sig, &sig_enc_data_comp); 653 sig_enc_length_comp = GNUNET_CRYPTO_rsa_signature_encode (sig,
654 &sig_enc_data_comp);
615 655
616 if ( (sig_enc_length != sig_enc_length_comp) || 656 if ( (sig_enc_length != sig_enc_length_comp) ||
617 (0 != memcmp (sig_enc_data, sig_enc_data_comp, sig_enc_length) )) 657 (0 != memcmp (sig_enc_data, sig_enc_data_comp, sig_enc_length) ))
618 { 658 {
659 GNUNET_free (blinded_sig);
660 GNUNET_free (blinded_data);
661 GNUNET_free (public_enc_data);
662 GNUNET_free (secret_enc_data);
663 GNUNET_free (sig_enc_data);
664 GNUNET_free (skey);
619 GNUNET_break (0); 665 GNUNET_break (0);
620 return GNUNET_NO; 666 return GNUNET_NO;
621 } 667 }
668 GNUNET_free (blinded_sig);
669 GNUNET_free (blinded_data);
670 GNUNET_free (public_enc_data);
671 GNUNET_free (secret_enc_data);
672 GNUNET_free (sig_enc_data);
673 GNUNET_free (skey);
622 } 674 }
623 else 675 else
624 { 676 {
@@ -629,6 +681,7 @@ checkvec (const char *operation,
629 return GNUNET_OK; 681 return GNUNET_OK;
630} 682}
631 683
684
632/** 685/**
633 * Check test vectors from stdin. 686 * Check test vectors from stdin.
634 * 687 *
@@ -656,7 +709,7 @@ check_vectors ()
656 return 1; 709 return 1;
657 } 710 }
658 vectors = json_object_get (vecfile, "vectors"); 711 vectors = json_object_get (vecfile, "vectors");
659 if (!json_is_array (vectors)) 712 if (! json_is_array (vectors))
660 { 713 {
661 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bad vectors\n"); 714 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bad vectors\n");
662 json_decref (vecfile); 715 json_decref (vecfile);
@@ -692,6 +745,7 @@ check_vectors ()
692 } 745 }
693} 746}
694 747
748
695/** 749/**
696 * Output test vectors. 750 * Output test vectors.
697 * 751 *
@@ -868,20 +922,20 @@ output_vectors ()
868 GNUNET_CRYPTO_ecdh_eddsa (&priv_ecdhe, &pub_eddsa, &key_material); 922 GNUNET_CRYPTO_ecdh_eddsa (&priv_ecdhe, &pub_eddsa, &key_material);
869 923
870 d2j (vec, "priv_ecdhe", 924 d2j (vec, "priv_ecdhe",
871 &priv_ecdhe, 925 &priv_ecdhe,
872 sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey)); 926 sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey));
873 d2j (vec, "pub_ecdhe", 927 d2j (vec, "pub_ecdhe",
874 &pub_ecdhe, 928 &pub_ecdhe,
875 sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); 929 sizeof (struct GNUNET_CRYPTO_EcdhePublicKey));
876 d2j (vec, "priv_eddsa", 930 d2j (vec, "priv_eddsa",
877 &priv_eddsa, 931 &priv_eddsa,
878 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); 932 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
879 d2j (vec, "pub_eddsa", 933 d2j (vec, "pub_eddsa",
880 &pub_eddsa, 934 &pub_eddsa,
881 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); 935 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
882 d2j (vec, "key_material", 936 d2j (vec, "key_material",
883 &key_material, 937 &key_material,
884 sizeof (struct GNUNET_HashCode)); 938 sizeof (struct GNUNET_HashCode));
885 } 939 }
886 940
887 { 941 {
@@ -968,6 +1022,7 @@ output_vectors ()
968 GNUNET_free (blinded_data); 1022 GNUNET_free (blinded_data);
969 GNUNET_free (sig_enc_data); 1023 GNUNET_free (sig_enc_data);
970 GNUNET_free (blinded_sig_enc_data); 1024 GNUNET_free (blinded_sig_enc_data);
1025 GNUNET_free (secret_enc_data);
971 } 1026 }
972 1027
973 json_dumpf (vecfile, stdout, JSON_INDENT (2)); 1028 json_dumpf (vecfile, stdout, JSON_INDENT (2));
@@ -977,6 +1032,7 @@ output_vectors ()
977 return 0; 1032 return 0;
978} 1033}
979 1034
1035
980/** 1036/**
981 * Main function that will be run. 1037 * Main function that will be run.
982 * 1038 *
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index d1e5e0da5..02d4d439d 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -736,7 +736,12 @@ GNUNET_OS_get_suid_binary_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
736 "SUID_BINARY_PATH", 736 "SUID_BINARY_PATH",
737 &path); 737 &path);
738 if ((NULL == path) || (0 == strlen (path))) 738 if ((NULL == path) || (0 == strlen (path)))
739 {
740 if (NULL != path)
741 GNUNET_free (path);
742 cache = NULL;
739 return GNUNET_OS_get_libexec_binary_path (progname); 743 return GNUNET_OS_get_libexec_binary_path (progname);
744 }
740 path_len = strlen (path); 745 path_len = strlen (path);
741 GNUNET_asprintf (&binary, 746 GNUNET_asprintf (&binary,
742 "%s%s%s", 747 "%s%s%s",