aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2018-01-08 10:49:06 +0100
committerSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2018-01-08 10:49:06 +0100
commitf2d31fb82a314dcf6819dd494ff4a11e4f871c4e (patch)
tree029043b01c23f6e780f7fd01c15d467c568664ff /src
parent9f5ea1f7f809d73cbeb7ce5538550c42e978d340 (diff)
parent3f52ce03cb13118bef9a6fbe380f229e2cbec45f (diff)
downloadgnunet-f2d31fb82a314dcf6819dd494ff4a11e4f871c4e.tar.gz
gnunet-f2d31fb82a314dcf6819dd494ff4a11e4f871c4e.zip
Merge remote-tracking branch 'origin/master' into identity_oidc
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am16
-rw-r--r--src/abe/Makefile.am47
-rw-r--r--src/abe/abe.c499
-rw-r--r--src/abe/test_cpabe.c (renamed from src/util/test_crypto_abe.c)13
-rw-r--r--src/arm/gnunet-service-arm.c3
-rw-r--r--src/auction/Makefile.am5
-rw-r--r--src/cadet/cadet_api.c127
-rw-r--r--src/cadet/cadet_test_lib.c1
-rw-r--r--src/cadet/gnunet-cadet.c1
-rw-r--r--src/cadet/gnunet-service-cadet_core.c42
-rw-r--r--src/cadet/gnunet-service-cadet_paths.c169
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c2
-rw-r--r--src/cadet/gnunet-service-cadet_tunnels.c4
-rw-r--r--src/cadet/test_cadet.c133
-rw-r--r--src/conversation/gnunet-helper-audio-playback-gst.c5
-rw-r--r--src/conversation/gnunet-helper-audio-playback.c5
-rw-r--r--src/conversation/gnunet_gst.c5
-rw-r--r--src/conversation/microphone.c4
-rw-r--r--src/core/gnunet-service-core.c3
-rw-r--r--src/core/gnunet-service-core_kx.c5
-rw-r--r--src/core/gnunet-service-core_sessions.c19
-rw-r--r--src/credential/credential.h2
-rw-r--r--src/credential/credential_api.c18
-rw-r--r--src/credential/credential_misc.c4
-rw-r--r--src/credential/credential_serialization.c14
-rw-r--r--src/credential/gnunet-credential.c23
-rw-r--r--src/credential/gnunet-service-credential.c130
-rw-r--r--src/credential/plugin_gnsrecord_credential.c12
-rw-r--r--src/credential/plugin_rest_credential.c59
-rwxr-xr-xsrc/credential/test_credential_verify_simple.sh8
-rw-r--r--src/curl/curl.c3
-rw-r--r--src/datacache/plugin_datacache_postgres.c8
-rw-r--r--src/dht/Makefile.am1
-rw-r--r--src/dht/gnunet-service-dht.c1
-rw-r--r--src/dns/dnsparser.c28
-rw-r--r--src/fs/fs_dirmetascan.c32
-rw-r--r--src/fs/fs_download.c3
-rw-r--r--src/fs/fs_search.c19
-rw-r--r--src/fs/fs_uri.c25
-rw-r--r--src/fs/gnunet-download.c145
-rw-r--r--src/fs/test_fs_download_persistence.c1
-rw-r--r--src/fs/test_fs_publish_persistence.c1
-rw-r--r--src/gns/gnunet-dns2gns.c45
-rw-r--r--src/gns/gnunet-service-gns_resolver.c66
-rw-r--r--src/hello/hello.c7
-rw-r--r--src/identity-attribute/identity_attribute.c8
-rw-r--r--src/identity-attribute/identity_attribute.h4
-rw-r--r--src/identity-attribute/plugin_identity_attribute_gnuid.c2
-rw-r--r--src/identity-provider/Makefile.am1
-rw-r--r--src/identity-provider/gnunet-idp.c5
-rw-r--r--src/identity-provider/gnunet-service-identity-provider.c310
-rw-r--r--src/identity-provider/identity_provider.h8
-rw-r--r--src/identity-provider/identity_provider_api.c41
-rw-r--r--src/identity-provider/plugin_gnsrecord_identity_provider.c4
-rw-r--r--src/identity-provider/plugin_identity_provider_sqlite.c4
-rw-r--r--src/identity-provider/plugin_rest_identity_provider.c11
-rw-r--r--src/identity/plugin_rest_identity.c11
-rw-r--r--src/include/Makefile.am7
-rw-r--r--src/include/gnunet_abe_lib.h193
-rw-r--r--src/include/gnunet_common.h15
-rw-r--r--src/include/gnunet_credential_service.h33
-rw-r--r--src/include/gnunet_crypto_lib.h82
-rw-r--r--src/include/gnunet_fs_service.h3
-rw-r--r--src/include/gnunet_identity_attribute_lib.h2
-rw-r--r--src/include/gnunet_identity_provider_service.h19
-rw-r--r--src/include/gnunet_mst_lib.h4
-rw-r--r--src/include/gnunet_network_lib.h8
-rw-r--r--src/include/gnunet_protocols.h30
-rw-r--r--src/include/gnunet_rest_lib.h6
-rw-r--r--src/include/gnunet_rest_plugin.h2
-rw-r--r--src/include/gnunet_scheduler_lib.h44
-rw-r--r--src/include/gnunet_service_lib.h7
-rw-r--r--src/include/gnunet_set_service.h3
-rw-r--r--src/jsonapi/Makefile.am2
-rw-r--r--src/jsonapi/test_jsonapi.c36
-rw-r--r--src/multicast/Makefile.am2
-rw-r--r--src/multicast/gnunet-service-multicast.c249
-rw-r--r--src/multicast/multicast_api.c51
-rw-r--r--src/multicast/test_multicast_multipeer.c312
-rw-r--r--src/nat/gnunet-nat.c12
-rw-r--r--src/nse/gnunet-nse-profiler.c19
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c71
-rw-r--r--src/psyc/gnunet-service-psyc.c131
-rw-r--r--src/psyc/psyc_api.c103
-rw-r--r--src/psyc/test_psyc.c28
-rw-r--r--src/psyc/test_psyc.conf16
-rw-r--r--src/psycstore/psycstore_api.c13
-rw-r--r--src/regex/regex_internal_dht.c29
-rw-r--r--src/regex/regex_test_lib.c23
-rw-r--r--src/rest/Makefile.am2
-rw-r--r--src/revocation/gnunet-service-revocation.c9
-rw-r--r--src/rps/.gitignore12
-rw-r--r--src/rps/Makefile.am15
-rw-r--r--src/rps/gnunet-service-rps.c1798
-rw-r--r--src/rps/gnunet-service-rps_peers.c1694
-rw-r--r--src/rps/gnunet-service-rps_peers.h437
-rw-r--r--src/rps/rps.h96
-rw-r--r--src/rps/test_rps.c298
-rw-r--r--src/rps/test_rps.conf38
-rw-r--r--src/rps/test_service_rps_peers.c137
-rw-r--r--src/set/Makefile.am2
-rw-r--r--src/set/gnunet-service-set_union.c13
-rw-r--r--src/set/set_api.c5
-rw-r--r--src/social/gnunet-service-social.c845
-rw-r--r--src/social/gnunet-social.c26
-rw-r--r--src/social/social_api.c292
-rw-r--r--src/social/test_social.c268
-rw-r--r--src/social/test_social.conf19
-rw-r--r--src/statistics/gnunet-service-statistics.c4
-rw-r--r--src/testbed/Makefile.am2
-rw-r--r--src/testbed/gnunet-daemon-testbed-blacklist.c4
-rw-r--r--src/testbed/gnunet-daemon-testbed-underlay.c6
-rw-r--r--src/testbed/gnunet-helper-testbed.c7
-rw-r--r--src/testbed/gnunet-service-testbed_oc.c15
-rw-r--r--src/testbed/gnunet-testbed-profiler.c15
-rw-r--r--src/transport/Makefile.am9
-rw-r--r--src/transport/gnunet-helper-transport-wlan-dummy.c6
-rw-r--r--src/transport/gnunet-service-transport.c4
-rw-r--r--src/transport/gnunet-service-transport_ats.c10
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c54
-rw-r--r--src/transport/gnunet-service-transport_validation.c13
-rw-r--r--src/transport/plugin_transport_http_server.c2
-rw-r--r--src/transport/plugin_transport_tcp.c17
-rw-r--r--src/transport/plugin_transport_udp.c11
-rw-r--r--src/transport/tcp_connection_legacy.c9
-rw-r--r--src/transport/tcp_server_legacy.c24
-rw-r--r--src/util/Makefile.am23
-rw-r--r--src/util/bio.c69
-rw-r--r--src/util/client.c44
-rw-r--r--src/util/common_allocation.c32
-rw-r--r--src/util/common_logging.c54
-rw-r--r--src/util/configuration.c39
-rw-r--r--src/util/container_bloomfilter.c60
-rw-r--r--src/util/crypto_ecc.c4
-rw-r--r--src/util/crypto_ecc_dlog.c1
-rw-r--r--src/util/crypto_ecc_setup.c98
-rw-r--r--src/util/crypto_hash.c6
-rw-r--r--src/util/crypto_hash_file.c16
-rw-r--r--src/util/disk.c27
-rw-r--r--src/util/getopt_helpers.c79
-rw-r--r--src/util/gnunet-config.c61
-rw-r--r--src/util/gnunet-ecc.c35
-rw-r--r--src/util/gnunet-resolver.c30
-rw-r--r--src/util/gnunet-service-resolver.c10
-rw-r--r--src/util/mq.c22
-rw-r--r--src/util/mst.c27
-rw-r--r--src/util/network.c94
-rw-r--r--src/util/os_installation.c23
-rw-r--r--src/util/os_priority.c1
-rw-r--r--src/util/peer.c3
-rw-r--r--src/util/program.c13
-rw-r--r--src/util/resolver_api.c24
-rw-r--r--src/util/scheduler.c1543
-rw-r--r--src/util/service.c35
-rw-r--r--src/util/speedup.c1
-rw-r--r--src/util/strings.c10
-rw-r--r--src/util/test_service.c39
-rw-r--r--src/util/time.c2
-rw-r--r--src/vpn/gnunet-helper-vpn.c1
-rw-r--r--src/vpn/gnunet-service-vpn.c3
160 files changed, 7131 insertions, 5343 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 68878b5a0..6d0284157 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,13 +12,12 @@ endif
12if HAVE_EXPERIMENTAL 12if HAVE_EXPERIMENTAL
13 EXP_DIR = \ 13 EXP_DIR = \
14 rps 14 rps
15endif
16# dv (FTBFS) 15# dv (FTBFS)
17 16if HAVE_ABE
18if HAVE_JSON 17 EXP_DIR += abe \
19if HAVE_MHD 18 credential \
20 ATTRIBUTE_DIR = identity-attribute 19 identity-attribute \
21 PROVIDER_DIR = identity-provider 20 identity-provider
22endif 21endif
23endif 22endif
24 23
@@ -117,7 +116,6 @@ SUBDIRS = \
117 revocation \ 116 revocation \
118 vpn \ 117 vpn \
119 gns \ 118 gns \
120 credential \
121 zonemaster \ 119 zonemaster \
122 $(CONVERSATION_DIR) \ 120 $(CONVERSATION_DIR) \
123 fs \ 121 fs \
@@ -131,8 +129,6 @@ SUBDIRS = \
131 psyc \ 129 psyc \
132 social \ 130 social \
133 $(AUCTION_DIR) \ 131 $(AUCTION_DIR) \
134 $(EXP_DIR) \ 132 $(EXP_DIR)
135 $(ATTRIBUTE_DIR) \
136 $(PROVIDER_DIR)
137 133
138endif 134endif
diff --git a/src/abe/Makefile.am b/src/abe/Makefile.am
new file mode 100644
index 000000000..23a7ae68e
--- /dev/null
+++ b/src/abe/Makefile.am
@@ -0,0 +1,47 @@
1# This Makefile.am is in the public domain
2AM_CPPFLAGS = -I$(top_srcdir)/src/include
3
4plugindir = $(libdir)/gnunet
5
6libexecdir= $(pkglibdir)/libexec/
7
8pkgcfgdir= $(pkgdatadir)/config.d/
9
10if USE_COVERAGE
11 AM_CFLAGS = --coverage -O0
12 XLIB = -lgcov
13endif
14
15libgnunetabe_la_SOURCES = abe.c
16
17libgnunetabe_la_LIBADD = \
18 $(GCLIBADD)\
19 $(LIBGCRYPT_LIBS) \
20 $(LTLIBICONV) \
21 $(LTLIBINTL) \
22 $(ABE_LIBADD) \
23 -lgabe \
24 -lpbc \
25 -lglib-2.0 \
26 -lltdl $(Z_LIBS) -lunistring $(XLIB)
27
28libgnunetabe_la_LDFLAGS = \
29 $(GN_LIB_LDFLAGS) \
30 -version-info 1:0:0
31
32lib_LTLIBRARIES = libgnunetabe.la
33
34if ENABLE_TEST_RUN
35AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
36TESTS = $(check_PROGRAMS)
37endif
38
39check_PROGRAMS = test_cpabe
40
41test_cpabe_SOURCES = \
42 test_cpabe.c
43test_cpabe_LDADD = \
44 libgnunetabe.la \
45 $(top_builddir)/src/util/libgnunetutil.la
46check_PROGRAMS += \
47 test_cpabe
diff --git a/src/abe/abe.c b/src/abe/abe.c
new file mode 100644
index 000000000..3f1f6dc5b
--- /dev/null
+++ b/src/abe/abe.c
@@ -0,0 +1,499 @@
1/*
2 This file is part of GNUnet. Copyright (C) 2001-2018 Christian Grothoff
3 (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19
20*/
21
22/**
23 * @file abe/abe.c
24 * @brief functions for Attribute-Based Encryption
25 * @author Martin Schanzenbach
26 */
27
28
29#include "platform.h"
30#include <pbc/pbc.h>
31#include <gabe.h>
32
33#include "gnunet_crypto_lib.h"
34#include "gnunet_abe_lib.h"
35
36struct GNUNET_ABE_AbeMasterKey
37{
38 gabe_pub_t* pub;
39 gabe_msk_t* msk;
40};
41
42struct GNUNET_ABE_AbeKey
43{
44 gabe_pub_t* pub;
45 gabe_prv_t* prv;
46};
47
48static int
49init_aes( element_t k, int enc,
50 gcry_cipher_hd_t* handle,
51 struct GNUNET_CRYPTO_SymmetricSessionKey *key,
52 unsigned char* iv)
53{
54 int rc;
55 int key_len;
56 unsigned char* key_buf;
57
58 key_len = element_length_in_bytes(k) < 33 ? 3 : element_length_in_bytes(k);
59 key_buf = (unsigned char*) malloc(key_len);
60 element_to_bytes(key_buf, k);
61
62 memcpy (key->aes_key, key_buf, GNUNET_CRYPTO_AES_KEY_LENGTH);
63 GNUNET_assert (0 ==
64 gcry_cipher_open (handle, GCRY_CIPHER_AES256,
65 GCRY_CIPHER_MODE_CFB, 0));
66 rc = gcry_cipher_setkey (*handle,
67 key->aes_key,
68 sizeof (key->aes_key));
69 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
70 memset (iv, 0, 16); //TODO make reasonable
71 rc = gcry_cipher_setiv (*handle,
72 iv,
73 16);
74 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
75
76 free(key_buf);
77 return rc;
78}
79
80static int
81aes_128_cbc_encrypt( char* pt,
82 int size,
83 element_t k,
84 char **ct )
85{
86 gcry_cipher_hd_t handle;
87 struct GNUNET_CRYPTO_SymmetricSessionKey skey;
88 unsigned char iv[16];
89 char* buf;
90 int padding;
91 int buf_size;
92 uint8_t len[4];
93 init_aes(k, 1, &handle, &skey, iv);
94
95 /* TODO make less crufty */
96
97 /* stuff in real length (big endian) before padding */
98 len[0] = (size & 0xff000000)>>24;
99 len[1] = (size & 0xff0000)>>16;
100 len[2] = (size & 0xff00)>>8;
101 len[3] = (size & 0xff)>>0;
102 padding = 16 - ((4+size) % 16);
103 buf_size = 4 + size + padding;
104 buf = GNUNET_malloc (buf_size);
105 GNUNET_memcpy (buf, len, 4);
106 GNUNET_memcpy (buf+4, pt, size);
107 *ct = GNUNET_malloc (buf_size);
108
109 GNUNET_assert (0 == gcry_cipher_encrypt (handle, *ct, buf_size, buf, buf_size));
110 gcry_cipher_close (handle);
111 //AES_cbc_encrypt(pt->data, ct->data, pt->len, &key, iv, AES_ENCRYPT);
112 GNUNET_free (buf);
113 return buf_size;
114}
115
116static int
117aes_128_cbc_decrypt( char* ct,
118 int size,
119 element_t k,
120 char **pt )
121{
122 struct GNUNET_CRYPTO_SymmetricSessionKey skey;
123 gcry_cipher_hd_t handle;
124 unsigned char iv[16];
125 char* tmp;
126 uint32_t len;
127
128 init_aes(k, 1, &handle, &skey, iv);
129
130 tmp = GNUNET_malloc (size);
131
132 //AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT);
133 GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size));
134 gcry_cipher_close (handle);
135 /* TODO make less crufty */
136
137 /* get real length */
138 len = 0;
139 len = len
140 | ((tmp[0])<<24) | ((tmp[1])<<16)
141 | ((tmp[2])<<8) | ((tmp[3])<<0);
142 /* truncate any garbage from the padding */
143 *pt = GNUNET_malloc (len);
144 GNUNET_memcpy (*pt, tmp+4, len);
145 GNUNET_free (tmp);
146 return len;
147}
148
149/**
150 * @ingroup abe
151 * Create a new CP-ABE master key. Caller must free return value.
152 *
153 * @return fresh private key; free using #GNUNET_ABE_cpabe_delete_master_key
154 */
155struct GNUNET_ABE_AbeMasterKey*
156GNUNET_ABE_cpabe_create_master_key (void)
157{
158 struct GNUNET_ABE_AbeMasterKey* key;
159 key = GNUNET_new (struct GNUNET_ABE_AbeMasterKey);
160 gabe_setup(&key->pub, &key->msk);
161 GNUNET_assert (NULL != key->pub);
162 GNUNET_assert (NULL != key->msk);
163 return key;
164}
165
166/**
167 * @ingroup abe
168 * Delete a CP-ABE master key.
169 *
170 * @param key the master key
171 * @return fresh private key; free using #GNUNET_free
172 */
173void
174GNUNET_ABE_cpabe_delete_master_key (struct GNUNET_ABE_AbeMasterKey *key)
175{
176 gabe_msk_free (key->msk);
177 gabe_pub_free (key->pub);
178 //GNUNET_free (key->msk);
179 //gabe_msk_free (key->msk); //For some reason free of pub implicit?
180 GNUNET_free (key);
181}
182
183/**
184 * @ingroup abe
185 * Create a new CP-ABE key. Caller must free return value.
186 *
187 * @param key the master key
188 * @param attrs the attributes to append to the key
189 * @return fresh private key; free using #GNUNET_ABE_cpabe_delete_key
190 */
191struct GNUNET_ABE_AbeKey*
192GNUNET_ABE_cpabe_create_key (struct GNUNET_ABE_AbeMasterKey *key,
193 char **attrs)
194{
195 struct GNUNET_ABE_AbeKey *prv_key;
196 int size;
197 char *tmp;
198
199 prv_key = GNUNET_new (struct GNUNET_ABE_AbeKey);
200 prv_key->prv = gabe_keygen(key->pub, key->msk, attrs);
201 size = gabe_pub_serialize(key->pub, &tmp);
202 prv_key->pub = gabe_pub_unserialize(tmp, size);
203 GNUNET_free (tmp);
204 GNUNET_assert (NULL != prv_key->prv);
205 return prv_key;
206}
207
208/**
209 * @ingroup abe
210 * Delete a CP-ABE key.
211 *
212 * @param key the key to delete
213 * @param delete_pub GNUNE_YES if the public key should also be freed (bug in gabe)
214 * @return fresh private key; free using #GNUNET_free
215 */
216void
217GNUNET_ABE_cpabe_delete_key (struct GNUNET_ABE_AbeKey *key,
218 int delete_pub)
219{
220 //Memory management in gabe is buggy
221 gabe_prv_free (key->prv);
222 if (GNUNET_YES == delete_pub)
223 gabe_pub_free (key->pub);
224 GNUNET_free (key);
225}
226
227static ssize_t
228write_cpabe (void **result,
229 uint32_t file_len,
230 char* cph_buf,
231 int cph_buf_len,
232 char* aes_buf,
233 int aes_buf_len)
234{
235 char *ptr;
236 uint32_t *len;
237
238 *result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len);
239 ptr = *result;
240 len = (uint32_t*) ptr;
241 *len = htonl (file_len);
242 ptr += 4;
243 len = (uint32_t*) ptr;
244 *len = htonl (aes_buf_len);
245 ptr += 4;
246 memcpy (ptr, aes_buf, aes_buf_len);
247 ptr += aes_buf_len;
248 len = (uint32_t*) ptr;
249 *len = htonl (cph_buf_len);
250 ptr += 4;
251 memcpy (ptr, cph_buf, cph_buf_len);
252 return 12 + cph_buf_len + aes_buf_len;
253}
254
255static ssize_t
256read_cpabe (const void *data,
257 char** cph_buf,
258 int *cph_buf_len,
259 char** aes_buf,
260 int *aes_buf_len)
261{
262 int buf_len;
263 char *ptr;
264 uint32_t *len;
265
266 ptr = (char*)data;
267 len = (uint32_t*)ptr;
268 buf_len = ntohl (*len);
269 ptr += 4;
270 len = (uint32_t*)ptr;
271 *aes_buf_len = ntohl (*len);
272 ptr += 4;
273 *aes_buf = GNUNET_malloc (*aes_buf_len);
274 memcpy(*aes_buf, ptr, *aes_buf_len);
275 ptr += *aes_buf_len;
276 len = (uint32_t*)ptr;
277 *cph_buf_len = ntohl (*len);
278 ptr += 4;
279 *cph_buf = GNUNET_malloc (*cph_buf_len);
280 memcpy(*cph_buf, ptr, *cph_buf_len);
281
282 return buf_len;
283}
284
285/**
286 * @ingroup abe
287 * Encrypt a block using sessionkey.
288 *
289 * @param block the block to encrypt
290 * @param size the size of the @a block
291 * @param policy the ABE policy
292 * @param key the key used to encrypt
293 * @param result the result buffer. Will be allocated. Free using #GNUNET_free
294 * @return the size of the encrypted block, -1 for errors
295 */
296ssize_t
297GNUNET_ABE_cpabe_encrypt (const void *block,
298 size_t size,
299 const char *policy,
300 const struct GNUNET_ABE_AbeMasterKey *key,
301 void **result)
302{
303 gabe_cph_t* cph;
304 char* plt;
305 char* cph_buf;
306 char* aes_buf;
307 element_t m;
308 int cph_buf_len;
309 int aes_buf_len;
310 ssize_t result_len;
311
312 if( !(cph = gabe_enc(key->pub, m, (char*)policy)) )
313 return GNUNET_SYSERR;
314 cph_buf_len = gabe_cph_serialize(cph,
315 &cph_buf);
316 gabe_cph_free(cph);
317 GNUNET_free (cph);
318 plt = GNUNET_memdup (block, size);
319 aes_buf_len = aes_128_cbc_encrypt(plt, size, m, &aes_buf);
320 GNUNET_free (plt);
321 element_clear(m);
322 result_len = write_cpabe(result, size, cph_buf, cph_buf_len, aes_buf, aes_buf_len);
323 GNUNET_free(cph_buf);
324 GNUNET_free(aes_buf);
325 return result_len;
326}
327
328/**
329 * @ingroup abe
330 * Decrypt a block using the ABE key.
331 *
332 * @param block the block to encrypt
333 * @param size the size of the @a block
334 * @param key the key used to decrypt
335 * @param result the result buffer. Will be allocated. Free using #GNUNET_free
336 * @return the size of the encrypted block, -1 for errors
337 */
338ssize_t
339GNUNET_ABE_cpabe_decrypt (const void *block,
340 size_t size,
341 const struct GNUNET_ABE_AbeKey *key,
342 void **result)
343{
344 char* aes_buf;
345 char* cph_buf;
346 gabe_cph_t* cph;
347 element_t m;
348 int cph_buf_size;
349 int aes_buf_size;
350 int plt_len;
351
352 read_cpabe(block, &cph_buf, &cph_buf_size, &aes_buf, &aes_buf_size);
353 cph = gabe_cph_unserialize(key->pub, cph_buf, cph_buf_size);
354 if( !gabe_dec(key->pub, key->prv, cph, m) ) {
355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
356 "%s\n", gabe_error());
357 GNUNET_free (aes_buf);
358 GNUNET_free (cph_buf);
359 gabe_cph_free(cph);
360 GNUNET_free (cph);
361 element_clear (m);
362 return GNUNET_SYSERR;
363 }
364 gabe_cph_free(cph);
365 GNUNET_free (cph);
366 plt_len = aes_128_cbc_decrypt(aes_buf, aes_buf_size, m, (char**)result);
367 GNUNET_free (cph_buf);
368 GNUNET_free (aes_buf);
369 element_clear (m);
370 //freeing is buggy in gabe
371 //gabe_prv_free (prv);
372 //gabe_pub_free (pub);
373 return plt_len;
374}
375
376/**
377 * @ingroup abe
378 * Serialize an ABE key.
379 *
380 * @param key the key to serialize
381 * @param result the result buffer. Will be allocated. Free using #GNUNET_free
382 * @return the size of the encrypted block, -1 for errors
383 */
384ssize_t
385GNUNET_ABE_cpabe_serialize_key (const struct GNUNET_ABE_AbeKey *key,
386 void **result)
387{
388 ssize_t len;
389 char *pub;
390 char *prv;
391 int pub_len;
392 int prv_len;
393
394 pub_len = gabe_pub_serialize (key->pub, &pub);
395 prv_len = gabe_prv_serialize (key->prv, &prv);
396
397 len = pub_len + prv_len + 12;
398 write_cpabe (result, len, pub, pub_len, prv, prv_len);
399
400 GNUNET_free (pub);
401 GNUNET_free (prv);
402
403 return len;
404}
405
406/**
407 * @ingroup abe
408 * Deserialize a serialized ABE key.
409 *
410 * @param data the data to deserialize
411 * @param len the length of the data.
412 * @return the ABE key. NULL of unsuccessful
413 */
414struct GNUNET_ABE_AbeKey*
415GNUNET_ABE_cpabe_deserialize_key (const void *data,
416 size_t len)
417{
418 struct GNUNET_ABE_AbeKey *key;
419 char *pub;
420 char *prv;
421 int prv_len;
422 int pub_len;
423
424 key = GNUNET_new (struct GNUNET_ABE_AbeKey);
425 read_cpabe (data,
426 &pub,
427 &pub_len,
428 &prv,
429 &prv_len);
430 key->pub = gabe_pub_unserialize (pub, pub_len);
431 key->prv = gabe_prv_unserialize (key->pub, prv, prv_len);
432
433 GNUNET_free (pub);
434 GNUNET_free (prv);
435 return key;
436}
437
438/**
439 * @ingroup abe
440 * Serialize an ABE master key.
441 *
442 * @param key the key to serialize
443 * @param result the result buffer. Will be allocated. Free using #GNUNET_free
444 * @return the size of the encrypted block, -1 for errors
445 */
446ssize_t
447GNUNET_ABE_cpabe_serialize_master_key (const struct GNUNET_ABE_AbeMasterKey *key,
448 void **result)
449{
450 ssize_t len;
451 char *pub;
452 char *msk;
453 int pub_len;
454 int msk_len;
455
456 pub_len = gabe_pub_serialize (key->pub, &pub);
457 msk_len = gabe_msk_serialize (key->msk, &msk);
458
459 len = pub_len + msk_len + 12;
460 write_cpabe (result, len, pub, pub_len, msk, msk_len);
461
462 GNUNET_free (pub);
463 GNUNET_free (msk);
464
465 return len;
466}
467
468/**
469 * @ingroup abe
470 * Deserialize an ABE master key.
471 *
472 * @param data the data to deserialize
473 * @param len the length of the data.
474 * @return the ABE key. NULL of unsuccessful
475 */
476struct GNUNET_ABE_AbeMasterKey*
477GNUNET_ABE_cpabe_deserialize_master_key (const void *data,
478 size_t len)
479{
480 struct GNUNET_ABE_AbeMasterKey *key;
481 char *msk;
482 char *pub;
483 int msk_len;
484 int pub_len;
485
486 key = GNUNET_new (struct GNUNET_ABE_AbeMasterKey);
487 read_cpabe (data,
488 &pub,
489 &pub_len,
490 &msk,
491 &msk_len);
492 key->pub = gabe_pub_unserialize (pub, pub_len);
493 key->msk = gabe_msk_unserialize (key->pub, msk, msk_len);
494
495 GNUNET_free (pub);
496 GNUNET_free (msk);
497
498 return key;
499}
diff --git a/src/util/test_crypto_abe.c b/src/abe/test_cpabe.c
index cb36dccae..9b2062b23 100644
--- a/src/util/test_crypto_abe.c
+++ b/src/abe/test_cpabe.c
@@ -25,20 +25,21 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_abe_lib.h"
28 29
29#define TESTSTRING "Hello World!" 30#define TESTSTRING "Hello World!"
30 31
31static int 32static int
32testAbecipher () 33testAbecipher ()
33{ 34{
34 struct GNUNET_CRYPTO_AbeMasterKey *msk; 35 struct GNUNET_ABE_AbeMasterKey *msk;
35 struct GNUNET_CRYPTO_AbeKey *key; 36 struct GNUNET_ABE_AbeKey *key;
36 char *result; 37 char *result;
37 char **attrs; 38 char **attrs;
38 int size; 39 int size;
39 char *res; 40 char *res;
40 msk = GNUNET_CRYPTO_cpabe_create_master_key (); 41 msk = GNUNET_ABE_cpabe_create_master_key ();
41 size = GNUNET_CRYPTO_cpabe_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, 42 size = GNUNET_ABE_cpabe_encrypt (TESTSTRING, strlen (TESTSTRING) + 1,
42 "testattr", //Policy 43 "testattr", //Policy
43 msk, 44 msk,
44 (void*)&result); 45 (void*)&result);
@@ -46,10 +47,10 @@ testAbecipher ()
46 attrs = GNUNET_malloc (2 * sizeof (char*)); 47 attrs = GNUNET_malloc (2 * sizeof (char*));
47 attrs[0] = "testattr"; 48 attrs[0] = "testattr";
48 attrs[1] = NULL; 49 attrs[1] = NULL;
49 key = GNUNET_CRYPTO_cpabe_create_key (msk, 50 key = GNUNET_ABE_cpabe_create_key (msk,
50 attrs); 51 attrs);
51 52
52 size = GNUNET_CRYPTO_cpabe_decrypt (result, size, 53 size = GNUNET_ABE_cpabe_decrypt (result, size,
53 key, 54 key,
54 (void*)&res); 55 (void*)&res);
55 if (strlen (TESTSTRING) + 1 != size) 56 if (strlen (TESTSTRING) + 1 != size)
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c
index 2db2ba0d1..bf5982d10 100644
--- a/src/arm/gnunet-service-arm.c
+++ b/src/arm/gnunet-service-arm.c
@@ -1915,7 +1915,6 @@ setup_service (void *cls,
1915 struct sockaddr **addrs; 1915 struct sockaddr **addrs;
1916 socklen_t *addr_lens; 1916 socklen_t *addr_lens;
1917 int ret; 1917 int ret;
1918 unsigned int i;
1919 1918
1920 if (0 == strcasecmp (section, 1919 if (0 == strcasecmp (section,
1921 "arm")) 1920 "arm"))
@@ -2027,7 +2026,7 @@ setup_service (void *cls,
2027 &addr_lens))) 2026 &addr_lens)))
2028 return; 2027 return;
2029 /* this will free (or capture) addrs[i] */ 2028 /* this will free (or capture) addrs[i] */
2030 for (i = 0; i < ret; i++) 2029 for (unsigned int i = 0; i < ret; i++)
2031 create_listen_socket (addrs[i], 2030 create_listen_socket (addrs[i],
2032 addr_lens[i], 2031 addr_lens[i],
2033 sl); 2032 sl);
diff --git a/src/auction/Makefile.am b/src/auction/Makefile.am
index bdede0ce0..f86e846e2 100644
--- a/src/auction/Makefile.am
+++ b/src/auction/Makefile.am
@@ -68,6 +68,11 @@ test_auction_api_LDADD = \
68check_SCRIPTS = \ 68check_SCRIPTS = \
69 test_auction_create.sh 69 test_auction_create.sh
70 70
71EXTRA_DIST = \
72 auction.h \
73 auction.conf \
74 $(check_SCRIPTS)
75
71if ENABLE_TEST_RUN 76if ENABLE_TEST_RUN
72 AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; 77 AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
73 TESTS = $(check_PROGRAMS) $(check_SCRIPTS) 78 TESTS = $(check_PROGRAMS) $(check_SCRIPTS)
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c
index 00a482452..6b07ab7b7 100644
--- a/src/cadet/cadet_api.c
+++ b/src/cadet/cadet_api.c
@@ -391,6 +391,8 @@ destroy_channel_on_reconnect_cb (void *cls,
391 /* struct GNUNET_CADET_Handle *handle = cls; */ 391 /* struct GNUNET_CADET_Handle *handle = cls; */
392 struct GNUNET_CADET_Channel *ch = value; 392 struct GNUNET_CADET_Channel *ch = value;
393 393
394 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
395 "Destroying channel due to reconnect\n");
394 destroy_channel (ch); 396 destroy_channel (ch);
395 return GNUNET_OK; 397 return GNUNET_OK;
396} 398}
@@ -489,7 +491,7 @@ cadet_mq_send_impl (struct GNUNET_MQ_Handle *mq,
489 struct GNUNET_CADET_Handle *h = ch->cadet; 491 struct GNUNET_CADET_Handle *h = ch->cadet;
490 uint16_t msize; 492 uint16_t msize;
491 struct GNUNET_MQ_Envelope *env; 493 struct GNUNET_MQ_Envelope *env;
492 struct GNUNET_CADET_LocalData *cadet_msg; 494 struct GNUNET_CADET_LocalData *cadet_msg = NULL;
493 495
494 if (NULL == h->mq) 496 if (NULL == h->mq)
495 { 497 {
@@ -636,7 +638,6 @@ handle_channel_created (void *cls,
636 ch = create_channel (h, 638 ch = create_channel (h,
637 &ccn); 639 &ccn);
638 ch->peer = msg->peer; 640 ch->peer = msg->peer;
639 ch->cadet = h;
640 ch->incoming_port = port; 641 ch->incoming_port = port;
641 ch->options = ntohl (msg->opt); 642 ch->options = ntohl (msg->opt);
642 LOG (GNUNET_ERROR_TYPE_DEBUG, 643 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -824,6 +825,29 @@ handle_mq_error (void *cls,
824 825
825 826
826/** 827/**
828 * Check that message received from CADET service is well-formed.
829 *
830 * @param cls the `struct GNUNET_CADET_Handle`
831 * @param message the message we got
832 * @return #GNUNET_OK if the message is well-formed,
833 * #GNUNET_SYSERR otherwise
834 */
835static int
836check_get_peers (void *cls,
837 const struct GNUNET_MessageHeader *message)
838{
839 size_t esize;
840
841 esize = ntohs (message->size);
842 if (sizeof (struct GNUNET_CADET_LocalInfoPeer) == esize)
843 return GNUNET_OK;
844 if (sizeof (struct GNUNET_MessageHeader) == esize)
845 return GNUNET_OK;
846 return GNUNET_SYSERR;
847}
848
849
850/**
827 * Process a local reply about info on all tunnels, pass info to the user. 851 * Process a local reply about info on all tunnels, pass info to the user.
828 * 852 *
829 * @param cls Closure (Cadet handle). 853 * @param cls Closure (Cadet handle).
@@ -831,17 +855,26 @@ handle_mq_error (void *cls,
831 */ 855 */
832static void 856static void
833handle_get_peers (void *cls, 857handle_get_peers (void *cls,
834 const struct GNUNET_CADET_LocalInfoPeer *msg) 858 const struct GNUNET_MessageHeader *msg)
835{ 859{
836 struct GNUNET_CADET_Handle *h = cls; 860 struct GNUNET_CADET_Handle *h = cls;
861 const struct GNUNET_CADET_LocalInfoPeer *info =
862 (const struct GNUNET_CADET_LocalInfoPeer *) msg;
837 863
838 if (NULL == h->info_cb.peers_cb) 864 if (NULL == h->info_cb.peers_cb)
839 return; 865 return;
840 h->info_cb.peers_cb (h->info_cls, 866 if (sizeof (struct GNUNET_CADET_LocalInfoPeer) == ntohs (msg->size))
841 &msg->destination, 867 h->info_cb.peers_cb (h->info_cls,
842 (int) ntohs (msg->tunnel), 868 &info->destination,
843 (unsigned int) ntohs (msg->paths), 869 (int) ntohs (info->tunnel),
844 0); 870 (unsigned int) ntohs (info->paths),
871 0);
872 else
873 h->info_cb.peers_cb (h->info_cls,
874 NULL,
875 0,
876 0,
877 0);
845} 878}
846 879
847 880
@@ -946,6 +979,29 @@ handle_get_peer (void *cls,
946 979
947 980
948/** 981/**
982 * Check that message received from CADET service is well-formed.
983 *
984 * @param cls the `struct GNUNET_CADET_Handle`
985 * @param message the message we got
986 * @return #GNUNET_OK if the message is well-formed,
987 * #GNUNET_SYSERR otherwise
988 */
989static int
990check_get_tunnels (void *cls,
991 const struct GNUNET_MessageHeader *message)
992{
993 size_t esize;
994
995 esize = ntohs (message->size);
996 if (sizeof (struct GNUNET_CADET_LocalInfoTunnel) == esize)
997 return GNUNET_OK;
998 if (sizeof (struct GNUNET_MessageHeader) == esize)
999 return GNUNET_OK;
1000 return GNUNET_SYSERR;
1001}
1002
1003
1004/**
949 * Process a local reply about info on all tunnels, pass info to the user. 1005 * Process a local reply about info on all tunnels, pass info to the user.
950 * 1006 *
951 * @param cls Closure (Cadet handle). 1007 * @param cls Closure (Cadet handle).
@@ -953,19 +1009,28 @@ handle_get_peer (void *cls,
953 */ 1009 */
954static void 1010static void
955handle_get_tunnels (void *cls, 1011handle_get_tunnels (void *cls,
956 const struct GNUNET_CADET_LocalInfoTunnel *msg) 1012 const struct GNUNET_MessageHeader *msg)
957{ 1013{
958 struct GNUNET_CADET_Handle *h = cls; 1014 struct GNUNET_CADET_Handle *h = cls;
1015 const struct GNUNET_CADET_LocalInfoTunnel *info =
1016 (const struct GNUNET_CADET_LocalInfoTunnel *) msg;
959 1017
960 if (NULL == h->info_cb.tunnels_cb) 1018 if (NULL == h->info_cb.tunnels_cb)
961 return; 1019 return;
962 h->info_cb.tunnels_cb (h->info_cls, 1020 if (sizeof (struct GNUNET_CADET_LocalInfoTunnel) == ntohs (msg->size))
963 &msg->destination, 1021 h->info_cb.tunnels_cb (h->info_cls,
964 ntohl (msg->channels), 1022 &info->destination,
965 ntohl (msg->connections), 1023 ntohl (info->channels),
966 ntohs (msg->estate), 1024 ntohl (info->connections),
967 ntohs (msg->cstate)); 1025 ntohs (info->estate),
968 1026 ntohs (info->cstate));
1027 else
1028 h->info_cb.tunnels_cb (h->info_cls,
1029 NULL,
1030 0,
1031 0,
1032 0,
1033 0);
969} 1034}
970 1035
971 1036
@@ -1075,18 +1140,18 @@ reconnect (struct GNUNET_CADET_Handle *h)
1075 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK, 1140 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK,
1076 struct GNUNET_CADET_LocalAck, 1141 struct GNUNET_CADET_LocalAck,
1077 h), 1142 h),
1078 GNUNET_MQ_hd_fixed_size (get_peers, 1143 GNUNET_MQ_hd_var_size (get_peers,
1079 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS, 1144 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS,
1080 struct GNUNET_CADET_LocalInfoPeer, 1145 struct GNUNET_MessageHeader,
1081 h), 1146 h),
1082 GNUNET_MQ_hd_var_size (get_peer, 1147 GNUNET_MQ_hd_var_size (get_peer,
1083 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER, 1148 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER,
1084 struct GNUNET_CADET_LocalInfoPeer, 1149 struct GNUNET_CADET_LocalInfoPeer,
1085 h), 1150 h),
1086 GNUNET_MQ_hd_fixed_size (get_tunnels, 1151 GNUNET_MQ_hd_var_size (get_tunnels,
1087 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS, 1152 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS,
1088 struct GNUNET_CADET_LocalInfoTunnel, 1153 struct GNUNET_MessageHeader,
1089 h), 1154 h),
1090 GNUNET_MQ_hd_var_size (get_tunnel, 1155 GNUNET_MQ_hd_var_size (get_tunnel,
1091 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL, 1156 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL,
1092 struct GNUNET_CADET_LocalInfoTunnel, 1157 struct GNUNET_CADET_LocalInfoTunnel,
@@ -1094,6 +1159,7 @@ reconnect (struct GNUNET_CADET_Handle *h)
1094 GNUNET_MQ_handler_end () 1159 GNUNET_MQ_handler_end ()
1095 }; 1160 };
1096 1161
1162 GNUNET_assert (NULL == h->mq);
1097 h->mq = GNUNET_CLIENT_connect (h->cfg, 1163 h->mq = GNUNET_CLIENT_connect (h->cfg,
1098 "cadet", 1164 "cadet",
1099 handlers, 1165 handlers,
@@ -1132,6 +1198,8 @@ destroy_channel_cb (void *cls,
1132 "channel %X not destroyed\n", 1198 "channel %X not destroyed\n",
1133 ntohl (ch->ccn.channel_of_client)); 1199 ntohl (ch->ccn.channel_of_client));
1134 } 1200 }
1201 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1202 "Destroying channel due to GNUNET_CADET_disconnect()\n");
1135 destroy_channel (ch); 1203 destroy_channel (ch);
1136 return GNUNET_OK; 1204 return GNUNET_OK;
1137} 1205}
@@ -1246,6 +1314,8 @@ GNUNET_CADET_channel_destroy (struct GNUNET_CADET_Channel *channel)
1246 GNUNET_MQ_send (h->mq, 1314 GNUNET_MQ_send (h->mq,
1247 env); 1315 env);
1248 } 1316 }
1317 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1318 "Destroying channel due to GNUNET_CADET_channel_destroy()\n");
1249 destroy_channel (channel); 1319 destroy_channel (channel);
1250} 1320}
1251 1321
@@ -1600,7 +1670,10 @@ GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h,
1600 1670
1601 GNUNET_assert (NULL != connects); 1671 GNUNET_assert (NULL != connects);
1602 GNUNET_assert (NULL != disconnects); 1672 GNUNET_assert (NULL != disconnects);
1603 1673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1674 "Listening to CADET port %s\n",
1675 GNUNET_h2s (port));
1676
1604 p = GNUNET_new (struct GNUNET_CADET_Port); 1677 p = GNUNET_new (struct GNUNET_CADET_Port);
1605 p->cadet = h; 1678 p->cadet = h;
1606 p->id = *port; 1679 p->id = *port;
@@ -1663,6 +1736,10 @@ GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h,
1663 struct GNUNET_MQ_Envelope *env; 1736 struct GNUNET_MQ_Envelope *env;
1664 1737
1665 GNUNET_assert (NULL != disconnects); 1738 GNUNET_assert (NULL != disconnects);
1739 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1740 "Creating channel to peer %s at port %s\n",
1741 GNUNET_i2s (destination),
1742 GNUNET_h2s (port));
1666 ch = create_channel (h, 1743 ch = create_channel (h,
1667 NULL); 1744 NULL);
1668 ch->ctx = channel_cls; 1745 ch->ctx = channel_cls;
diff --git a/src/cadet/cadet_test_lib.c b/src/cadet/cadet_test_lib.c
index 1df6bff0d..20ef028b2 100644
--- a/src/cadet/cadet_test_lib.c
+++ b/src/cadet/cadet_test_lib.c
@@ -241,6 +241,7 @@ GNUNET_CADET_TEST_cleanup (struct GNUNET_CADET_TEST_Context *ctx)
241 } 241 }
242 GNUNET_free (ctx->ops); 242 GNUNET_free (ctx->ops);
243 GNUNET_free (ctx->cadets); 243 GNUNET_free (ctx->cadets);
244 GNUNET_free (ctx->handlers);
244 GNUNET_free (ctx); 245 GNUNET_free (ctx);
245 GNUNET_SCHEDULER_shutdown (); 246 GNUNET_SCHEDULER_shutdown ();
246} 247}
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c
index 675e7faf0..a9b02714b 100644
--- a/src/cadet/gnunet-cadet.c
+++ b/src/cadet/gnunet-cadet.c
@@ -693,6 +693,7 @@ show_tunnel (void *cls)
693{ 693{
694 struct GNUNET_PeerIdentity pid; 694 struct GNUNET_PeerIdentity pid;
695 695
696 job = NULL;
696 if (GNUNET_OK != 697 if (GNUNET_OK !=
697 GNUNET_CRYPTO_eddsa_public_key_from_string (tunnel_id, 698 GNUNET_CRYPTO_eddsa_public_key_from_string (tunnel_id,
698 strlen (tunnel_id), 699 strlen (tunnel_id),
diff --git a/src/cadet/gnunet-service-cadet_core.c b/src/cadet/gnunet-service-cadet_core.c
index ae03b4f35..84aff1857 100644
--- a/src/cadet/gnunet-service-cadet_core.c
+++ b/src/cadet/gnunet-service-cadet_core.c
@@ -623,7 +623,7 @@ timeout_cb (void *cls)
623 { 623 {
624 exp = GNUNET_TIME_absolute_add (r->last_use, 624 exp = GNUNET_TIME_absolute_add (r->last_use,
625 linger); 625 linger);
626 if (0 != GNUNET_TIME_absolute_get_duration (exp).rel_value_us) 626 if (0 != GNUNET_TIME_absolute_get_remaining (exp).rel_value_us)
627 { 627 {
628 /* Route not yet timed out, wait until it does. */ 628 /* Route not yet timed out, wait until it does. */
629 timeout_task = GNUNET_SCHEDULER_add_at (exp, 629 timeout_task = GNUNET_SCHEDULER_add_at (exp,
@@ -631,6 +631,11 @@ timeout_cb (void *cls)
631 NULL); 631 NULL);
632 return; 632 return;
633 } 633 }
634 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
635 "Sending BROKEN due to timeout (%s was last use, %s linger)\n",
636 GNUNET_STRINGS_absolute_time_to_string (r->last_use),
637 GNUNET_STRINGS_relative_time_to_string (linger,
638 GNUNET_YES));
634 send_broken (&r->prev, 639 send_broken (&r->prev,
635 &r->cid, 640 &r->cid,
636 NULL, 641 NULL,
@@ -688,6 +693,8 @@ dir_ready_cb (void *cls,
688 return; 693 return;
689 } 694 }
690 odir = (dir == &route->next) ? &route->prev : &route->next; 695 odir = (dir == &route->next) ? &route->prev : &route->next;
696 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
697 "Sending BROKEN due to MQ going down\n");
691 send_broken (&route->next, 698 send_broken (&route->next,
692 &route->cid, 699 &route->cid,
693 GCP_get_id (odir->hop), 700 GCP_get_id (odir->hop),
@@ -771,6 +778,33 @@ handle_connection_create (void *cls,
771 778
772 options = (enum GNUNET_CADET_ChannelOption) ntohl (msg->options); 779 options = (enum GNUNET_CADET_ChannelOption) ntohl (msg->options);
773 path_length = size / sizeof (struct GNUNET_PeerIdentity); 780 path_length = size / sizeof (struct GNUNET_PeerIdentity);
781 if (0 == path_length)
782 {
783 LOG (GNUNET_ERROR_TYPE_DEBUG,
784 "Dropping CADET_CONNECTION_CREATE with empty path\n");
785 GNUNET_break_op (0);
786 return;
787 }
788 /* Check for loops */
789 struct GNUNET_CONTAINER_MultiPeerMap *map;
790 map = GNUNET_CONTAINER_multipeermap_create (path_length * 2,
791 GNUNET_YES);
792 GNUNET_assert (NULL != map);
793 for (off = 0; off < path_length; off++) {
794 if (GNUNET_SYSERR ==
795 GNUNET_CONTAINER_multipeermap_put (map,
796 &pids[off],
797 NULL,
798 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) {
799 /* bogus request */
800 GNUNET_CONTAINER_multipeermap_destroy (map);
801 LOG (GNUNET_ERROR_TYPE_DEBUG,
802 "Dropping CADET_CONNECTION_CREATE with cyclic path\n");
803 GNUNET_break_op (0);
804 return;
805 }
806 }
807 GNUNET_CONTAINER_multipeermap_destroy (map);
774 /* Initiator is at offset 0. */ 808 /* Initiator is at offset 0. */
775 for (off=1;off<path_length;off++) 809 for (off=1;off<path_length;off++)
776 if (0 == memcmp (&my_full_id, 810 if (0 == memcmp (&my_full_id,
@@ -779,7 +813,8 @@ handle_connection_create (void *cls,
779 break; 813 break;
780 if (off == path_length) 814 if (off == path_length)
781 { 815 {
782 /* We are not on the path, bogus request */ 816 LOG (GNUNET_ERROR_TYPE_DEBUG,
817 "Dropping CADET_CONNECTION_CREATE without us in the path\n");
783 GNUNET_break_op (0); 818 GNUNET_break_op (0);
784 return; 819 return;
785 } 820 }
@@ -787,7 +822,8 @@ handle_connection_create (void *cls,
787 if (sender != GCP_get (&pids[off - 1], 822 if (sender != GCP_get (&pids[off - 1],
788 GNUNET_NO)) 823 GNUNET_NO))
789 { 824 {
790 /* sender is not on the path, not allowed */ 825 LOG (GNUNET_ERROR_TYPE_DEBUG,
826 "Dropping CADET_CONNECTION_CREATE without sender in the path\n");
791 GNUNET_break_op (0); 827 GNUNET_break_op (0);
792 return; 828 return;
793 } 829 }
diff --git a/src/cadet/gnunet-service-cadet_paths.c b/src/cadet/gnunet-service-cadet_paths.c
index 7b90fe152..9dd6f1ddd 100644
--- a/src/cadet/gnunet-service-cadet_paths.c
+++ b/src/cadet/gnunet-service-cadet_paths.c
@@ -179,7 +179,7 @@ GCPP_del_connection (struct CadetPeerPath *path,
179 GCC_2s (cc), 179 GCC_2s (cc),
180 GCPP_2s (path), 180 GCPP_2s (path),
181 off); 181 off);
182 GNUNET_assert (off < path->entries_length); /* FIXME: #4909: This assertion fails sometimes! */ 182 GNUNET_assert (off < path->entries_length);
183 entry = path->entries[off]; 183 entry = path->entries[off];
184 GNUNET_assert (cc == entry->cc); 184 GNUNET_assert (cc == entry->cc);
185 entry->cc = NULL; 185 entry->cc = NULL;
@@ -187,33 +187,51 @@ GCPP_del_connection (struct CadetPeerPath *path,
187 187
188 188
189/** 189/**
190 * This path is no longer needed, free resources. 190 * Tries to attach @a path to a peer, working backwards from the end
191 * and stopping at @a stop_at. If path->hn is NULL on return then the
192 * path was not attached and you can assume that path->entries_length
193 * is equal to @a stop_at.
191 * 194 *
192 * @param path path resources to free 195 * @param path the path to attach
196 * @param stop_at the path length at which to stop trying
193 */ 197 */
194static void 198static void
195path_destroy (struct CadetPeerPath *path) 199attach_path (struct CadetPeerPath *path, unsigned int stop_at)
196{ 200{
197 LOG (GNUNET_ERROR_TYPE_DEBUG, 201 GNUNET_assert (NULL == path->hn);
198 "Destroying path %s\n", 202
199 GCPP_2s (path)); 203 /* Try to attach this path to a peer, working backwards from the end. */
200 for (unsigned int i=0;i<path->entries_length;i++) 204 while (path->entries_length > stop_at)
201 { 205 {
202 struct CadetPeerPathEntry *entry = path->entries[i]; 206 unsigned int end = path->entries_length - 1;
207 struct CadetPeerPathEntry *entry = path->entries[end];
208 int force = GNUNET_NO;
203 209
210 recalculate_path_desirability (path);
211 /* If the entry already has a connection using it, force attach. */
204 if (NULL != entry->cc) 212 if (NULL != entry->cc)
205 { 213 force = GNUNET_YES;
206 struct CadetTConnection *ct; 214 path->hn = GCP_attach_path (entry->peer,
215 path,
216 end,
217 force);
218 if (NULL != path->hn)
219 break;
207 220
208 ct = GCC_get_ct (entry->cc); 221 /* Attach failed, trim this entry from the path. */
209 if (NULL != ct) 222 GNUNET_assert (NULL == entry->cc);
210 GCT_connection_lost (ct); 223 GCP_path_entry_remove (entry->peer,
211 GCC_destroy_without_tunnel (entry->cc); 224 entry,
212 } 225 end);
213 GNUNET_free (entry); 226 GNUNET_free (entry);
227 path->entries[end] = NULL;
228 path->entries_length--;
214 } 229 }
215 GNUNET_free (path->entries); 230
216 GNUNET_free (path); 231 /* Shrink array to actual path length. */
232 GNUNET_array_grow (path->entries,
233 path->entries_length,
234 path->entries_length);
217} 235}
218 236
219 237
@@ -228,7 +246,6 @@ void
228GCPP_release (struct CadetPeerPath *path) 246GCPP_release (struct CadetPeerPath *path)
229{ 247{
230 struct CadetPeerPathEntry *entry; 248 struct CadetPeerPathEntry *entry;
231 int force;
232 249
233 LOG (GNUNET_ERROR_TYPE_DEBUG, 250 LOG (GNUNET_ERROR_TYPE_DEBUG,
234 "Owner releases path %s\n", 251 "Owner releases path %s\n",
@@ -236,34 +253,23 @@ GCPP_release (struct CadetPeerPath *path)
236 path->hn = NULL; 253 path->hn = NULL;
237 entry = path->entries[path->entries_length - 1]; 254 entry = path->entries[path->entries_length - 1];
238 GNUNET_assert (path == entry->path); 255 GNUNET_assert (path == entry->path);
239 while (1) 256 GNUNET_assert (NULL == entry->cc);
257 /* cut 'off' end of path */
258 GCP_path_entry_remove (entry->peer,
259 entry,
260 path->entries_length - 1);
261 GNUNET_free (entry);
262 path->entries[path->entries_length - 1] = NULL;
263 path->entries_length--;
264 /* see if new peer at the end likes this path any better */
265 attach_path (path, 0);
266 if (NULL == path->hn)
240 { 267 {
241 /* cut 'off' end of path */ 268 /* nobody wants us, discard the path */
242 GNUNET_assert (NULL == entry->cc); 269 GNUNET_assert (0 == path->entries_length);
243 GCP_path_entry_remove (entry->peer, 270 GNUNET_assert (NULL == path->entries);
244 entry, 271 GNUNET_free (path);
245 path->entries_length - 1);
246 path->entries_length--; /* We don't bother shrinking the 'entries' array,
247 as it's probably not worth it. */
248 GNUNET_free (entry);
249 if (0 == path->entries_length)
250 break; /* the end */
251
252 /* see if new peer at the end likes this path any better */
253 entry = path->entries[path->entries_length - 1];
254 GNUNET_assert (path == entry->path);
255 force = (NULL == entry->cc) ? GNUNET_NO : GNUNET_YES;
256 path->hn = GCP_attach_path (entry->peer,
257 path,
258 path->entries_length - 1,
259 force);
260 if (NULL != path->hn)
261 return; /* yep, got attached, we are done. */
262 GNUNET_assert (GNUNET_NO == force);
263 } 272 }
264
265 /* nobody wants us, discard the path */
266 path_destroy (path);
267} 273}
268 274
269 275
@@ -422,33 +428,13 @@ extend_path (struct CadetPeerPath *path,
422 path, 428 path,
423 path->hn); 429 path->hn);
424 path->hn = NULL; 430 path->hn = NULL;
425 for (i=num_peers-1;i>=0;i--) 431 path->entries_length = old_len + num_peers;
426 { 432 attach_path (path, old_len);
427 struct CadetPeerPathEntry *entry = path->entries[old_len + i];
428
429 path->entries_length = old_len + i + 1;
430 recalculate_path_desirability (path);
431 if (NULL != entry->cc)
432 force = GNUNET_YES;
433 path->hn = GCP_attach_path (peers[i],
434 path,
435 old_len + (unsigned int) i,
436 force);
437 if (NULL != path->hn)
438 break;
439 GCP_path_entry_remove (entry->peer,
440 entry,
441 old_len + i);
442 GNUNET_free (entry);
443 path->entries[old_len + i] = NULL;
444 }
445 if (NULL == path->hn) 433 if (NULL == path->hn)
446 { 434 {
447 /* none of the peers is interested in this path; 435 /* none of the peers is interested in this path;
448 shrink path back and re-attach. */ 436 re-attach. */
449 GNUNET_array_grow (path->entries, 437 GNUNET_assert (old_len == path->entries_length);
450 path->entries_length,
451 old_len);
452 path->hn = GCP_attach_path (path->entries[old_len - 1]->peer, 438 path->hn = GCP_attach_path (path->entries[old_len - 1]->peer,
453 path, 439 path,
454 old_len - 1, 440 old_len - 1,
@@ -483,7 +469,6 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
483 struct CadetPeer *cpath[get_path_length + put_path_length]; 469 struct CadetPeer *cpath[get_path_length + put_path_length];
484 struct CheckMatchContext cm_ctx; 470 struct CheckMatchContext cm_ctx;
485 struct CadetPeerPath *path; 471 struct CadetPeerPath *path;
486 struct GNUNET_CONTAINER_HeapNode *hn;
487 int i; 472 int i;
488 unsigned int skip; 473 unsigned int skip;
489 unsigned int total_len; 474 unsigned int total_len;
@@ -501,6 +486,14 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
501 pid = (off < get_path_length) 486 pid = (off < get_path_length)
502 ? &get_path[get_path_length - off - 1] 487 ? &get_path[get_path_length - off - 1]
503 : &put_path[get_path_length + put_path_length - off - 1]; 488 : &put_path[get_path_length + put_path_length - off - 1];
489 /* Check that I am not in the path */
490 if (0 == memcmp (&my_full_id,
491 pid,
492 sizeof (struct GNUNET_PeerIdentity)))
493 {
494 skip = off + 1;
495 continue;
496 }
504 cpath[off - skip] = GCP_get (pid, 497 cpath[off - skip] = GCP_get (pid,
505 GNUNET_YES); 498 GNUNET_YES);
506 /* Check that no peer is twice on the path */ 499 /* Check that no peer is twice on the path */
@@ -513,6 +506,12 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
513 } 506 }
514 } 507 }
515 } 508 }
509 if (skip >= total_len)
510 {
511 LOG (GNUNET_ERROR_TYPE_DEBUG,
512 "Path discovered from DHT is one big cycle?\n");
513 return;
514 }
516 total_len -= skip; 515 total_len -= skip;
517 516
518 /* First figure out if this path is a subset of an existing path, an 517 /* First figure out if this path is a subset of an existing path, an
@@ -573,39 +572,17 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
573 } 572 }
574 573
575 /* Finally, try to attach it */ 574 /* Finally, try to attach it */
576 hn = NULL; 575 attach_path (path, 0);
577 for (i=total_len-1;i>=0;i--) 576 if (NULL == path->hn)
578 {
579 struct CadetPeerPathEntry *entry = path->entries[i];
580
581 path->entries_length = i + 1;
582 recalculate_path_desirability (path);
583 hn = GCP_attach_path (cpath[i],
584 path,
585 (unsigned int) i,
586 GNUNET_NO);
587 if (NULL != hn)
588 break;
589 GCP_path_entry_remove (entry->peer,
590 entry,
591 i);
592 GNUNET_free (entry);
593 path->entries[i] = NULL;
594 }
595 if (NULL == hn)
596 { 577 {
597 /* None of the peers on the path care about it. */ 578 /* None of the peers on the path care about it. */
598 LOG (GNUNET_ERROR_TYPE_DEBUG, 579 LOG (GNUNET_ERROR_TYPE_DEBUG,
599 "Path discovered from DHT is not interesting to us\n"); 580 "Path discovered from DHT is not interesting to us\n");
600 GNUNET_free (path->entries); 581 GNUNET_assert (0 == path->entries_length);
582 GNUNET_assert (NULL == path->entries);
601 GNUNET_free (path); 583 GNUNET_free (path);
602 return; 584 return;
603 } 585 }
604 path->hn = hn;
605 /* Shrink path to actual useful length */
606 GNUNET_array_grow (path->entries,
607 path->entries_length,
608 i + 1);
609 LOG (GNUNET_ERROR_TYPE_DEBUG, 586 LOG (GNUNET_ERROR_TYPE_DEBUG,
610 "Created new path %s based on information from DHT\n", 587 "Created new path %s based on information from DHT\n",
611 GCPP_2s (path)); 588 GCPP_2s (path));
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index 71c7c67d0..da78a03c4 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -979,7 +979,7 @@ GCP_attach_path (struct CadetPeer *cp,
979 (desirability < root_desirability) ) 979 (desirability < root_desirability) )
980 { 980 {
981 LOG (GNUNET_ERROR_TYPE_DEBUG, 981 LOG (GNUNET_ERROR_TYPE_DEBUG,
982 "Decided to not attach path %p to peer %s due to undesirability\n", 982 "Decided to not attach path %s to peer %s due to undesirability\n",
983 GCPP_2s (path), 983 GCPP_2s (path),
984 GCP_2s (cp)); 984 GCP_2s (cp));
985 return NULL; 985 return NULL;
diff --git a/src/cadet/gnunet-service-cadet_tunnels.c b/src/cadet/gnunet-service-cadet_tunnels.c
index 22e19ef70..fb91a4a6a 100644
--- a/src/cadet/gnunet-service-cadet_tunnels.c
+++ b/src/cadet/gnunet-service-cadet_tunnels.c
@@ -2856,7 +2856,9 @@ handle_plaintext_channel_destroy (void *cls,
2856 * 2856 *
2857 * @param cls the `struct CadetTunnel` that got the message 2857 * @param cls the `struct CadetTunnel` that got the message
2858 * @param msg the message 2858 * @param msg the message
2859 * @return #GNUNET_OK (continue to process) 2859 * @return #GNUNET_OK on success (always)
2860 * #GNUNET_NO to stop further processing (no error)
2861 * #GNUNET_SYSERR to stop further processing with error
2860 */ 2862 */
2861static int 2863static int
2862handle_decrypted (void *cls, 2864handle_decrypted (void *cls,
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c
index 72df2203c..b9f177652 100644
--- a/src/cadet/test_cadet.c
+++ b/src/cadet/test_cadet.c
@@ -58,6 +58,11 @@ struct CadetTestChannelWrapper
58#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20) 58#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20)
59 59
60/** 60/**
61 * How fast do we send messages?
62 */
63#define SEND_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 10)
64
65/**
61 * DIFFERENT TESTS TO RUN 66 * DIFFERENT TESTS TO RUN
62 */ 67 */
63#define SETUP 0 68#define SETUP 0
@@ -269,12 +274,20 @@ show_end_data (void)
269 274
270 end_time = GNUNET_TIME_absolute_get (); 275 end_time = GNUNET_TIME_absolute_get ();
271 total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time); 276 total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time);
272 FPRINTF (stderr, "\nResults of test \"%s\"\n", test_name); 277 FPRINTF (stderr,
273 FPRINTF (stderr, "Test time %s\n", 278 "\nResults of test \"%s\"\n",
279 test_name);
280 FPRINTF (stderr,
281 "Test time %s\n",
274 GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES)); 282 GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES));
275 FPRINTF (stderr, "Test bandwidth: %f kb/s\n", 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms 283 FPRINTF (stderr,
276 FPRINTF (stderr, "Test throughput: %f packets/s\n\n", total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms 284 "Test bandwidth: %f kb/s\n",
277 GAUGER ("CADET", test_name, 285 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms
286 FPRINTF (stderr,
287 "Test throughput: %f packets/s\n\n",
288 total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms
289 GAUGER ("CADET",
290 test_name,
278 total_packets * 1000.0 / (total_time.rel_value_us / 1000), 291 total_packets * 1000.0 / (total_time.rel_value_us / 1000),
279 "packets/s"); 292 "packets/s");
280} 293}
@@ -290,13 +303,12 @@ static void
290disconnect_cadet_peers (void *cls) 303disconnect_cadet_peers (void *cls)
291{ 304{
292 long line = (long) cls; 305 long line = (long) cls;
293 unsigned int i;
294 306
295 disconnect_task = NULL; 307 disconnect_task = NULL;
296 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 308 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
297 "disconnecting cadet service of peers, called from line %ld\n", 309 "disconnecting cadet service of peers, called from line %ld\n",
298 line); 310 line);
299 for (i = 0; i < 2; i++) 311 for (unsigned int i = 0; i < 2; i++)
300 { 312 {
301 GNUNET_TESTBED_operation_done (t_op[i]); 313 GNUNET_TESTBED_operation_done (t_op[i]);
302 } 314 }
@@ -324,7 +336,8 @@ disconnect_cadet_peers (void *cls)
324static void 336static void
325shutdown_task (void *cls) 337shutdown_task (void *cls)
326{ 338{
327 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n"); 339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
340 "Ending test.\n");
328 if (NULL != send_next_msg_task) 341 if (NULL != send_next_msg_task)
329 { 342 {
330 GNUNET_SCHEDULER_cancel (send_next_msg_task); 343 GNUNET_SCHEDULER_cancel (send_next_msg_task);
@@ -339,7 +352,8 @@ shutdown_task (void *cls)
339 { 352 {
340 GNUNET_SCHEDULER_cancel (disconnect_task); 353 GNUNET_SCHEDULER_cancel (disconnect_task);
341 disconnect_task = 354 disconnect_task =
342 GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, (void *) __LINE__); 355 GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
356 (void *) __LINE__);
343 } 357 }
344} 358}
345 359
@@ -354,10 +368,14 @@ shutdown_task (void *cls)
354 * operation has executed successfully. 368 * operation has executed successfully.
355 */ 369 */
356static void 370static void
357stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) 371stats_cont (void *cls,
372 struct GNUNET_TESTBED_Operation *op,
373 const char *emsg)
358{ 374{
359 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " KA sent: %u, KA received: %u\n", 375 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
360 ka_sent, ka_received); 376 "KA sent: %u, KA received: %u\n",
377 ka_sent,
378 ka_received);
361 if ((KEEPALIVE == test) && ((ka_sent < 2) || (ka_sent > ka_received + 1))) 379 if ((KEEPALIVE == test) && ((ka_sent < 2) || (ka_sent > ka_received + 1)))
362 { 380 {
363 GNUNET_break (0); 381 GNUNET_break (0);
@@ -367,7 +385,8 @@ stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
367 385
368 if (NULL != disconnect_task) 386 if (NULL != disconnect_task)
369 GNUNET_SCHEDULER_cancel (disconnect_task); 387 GNUNET_SCHEDULER_cancel (disconnect_task);
370 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, cls); 388 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
389 cls);
371} 390}
372 391
373 392
@@ -438,7 +457,6 @@ gather_stats_and_exit (void *cls)
438} 457}
439 458
440 459
441
442/** 460/**
443 * Abort test: schedule disconnect and shutdown immediately 461 * Abort test: schedule disconnect and shutdown immediately
444 * 462 *
@@ -450,9 +468,12 @@ abort_test (long line)
450 if (NULL != disconnect_task) 468 if (NULL != disconnect_task)
451 { 469 {
452 GNUNET_SCHEDULER_cancel (disconnect_task); 470 GNUNET_SCHEDULER_cancel (disconnect_task);
453 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Aborting test from %ld\n", line); 471 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
472 "Aborting test from %ld\n",
473 line);
454 disconnect_task = 474 disconnect_task =
455 GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, (void *) line); 475 GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
476 (void *) line);
456 } 477 }
457} 478}
458 479
@@ -525,6 +546,7 @@ send_test_message (struct GNUNET_CADET_Channel *channel)
525 GNUNET_MQ_send (GNUNET_CADET_get_mq (channel), env); 546 GNUNET_MQ_send (GNUNET_CADET_get_mq (channel), env);
526} 547}
527 548
549
528/** 550/**
529 * Task to request a new data transmission in a SPEED test, without waiting 551 * Task to request a new data transmission in a SPEED test, without waiting
530 * for previous messages to be sent/arrrive. 552 * for previous messages to be sent/arrrive.
@@ -537,7 +559,9 @@ send_next_msg (void *cls)
537 struct GNUNET_CADET_Channel *channel; 559 struct GNUNET_CADET_Channel *channel;
538 560
539 send_next_msg_task = NULL; 561 send_next_msg_task = NULL;
540 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending next message: %d\n", data_sent); 562 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
563 "Sending next message: %d\n",
564 data_sent);
541 565
542 channel = GNUNET_YES == test_backwards ? incoming_ch : outgoing_ch; 566 channel = GNUNET_YES == test_backwards ? incoming_ch : outgoing_ch;
543 GNUNET_assert (NULL != channel); 567 GNUNET_assert (NULL != channel);
@@ -550,9 +574,9 @@ send_next_msg (void *cls)
550 "Scheduling message %d\n", 574 "Scheduling message %d\n",
551 data_sent + 1); 575 data_sent + 1);
552 send_next_msg_task = 576 send_next_msg_task =
553 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 577 GNUNET_SCHEDULER_add_delayed (SEND_INTERVAL,
554 &send_next_msg, 578 &send_next_msg,
555 NULL); 579 NULL);
556 } 580 }
557} 581}
558 582
@@ -571,7 +595,7 @@ reschedule_timeout_task (long line)
571 if (NULL != disconnect_task) 595 if (NULL != disconnect_task)
572 { 596 {
573 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 597 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
574 " reschedule timeout every 10 messages\n"); 598 "reschedule timeout every 10 messages\n");
575 GNUNET_SCHEDULER_cancel (disconnect_task); 599 GNUNET_SCHEDULER_cancel (disconnect_task);
576 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, 600 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
577 &gather_stats_and_exit, 601 &gather_stats_and_exit,
@@ -605,7 +629,8 @@ check_data (void *cls, const struct GNUNET_MessageHeader *message)
605 * @param message the actual message 629 * @param message the actual message
606 */ 630 */
607static void 631static void
608handle_data (void *cls, const struct GNUNET_MessageHeader *message) 632handle_data (void *cls,
633 const struct GNUNET_MessageHeader *message)
609{ 634{
610 struct CadetTestChannelWrapper *ch = cls; 635 struct CadetTestChannelWrapper *ch = cls;
611 struct GNUNET_CADET_Channel *channel = ch->ch; 636 struct GNUNET_CADET_Channel *channel = ch->ch;
@@ -770,19 +795,21 @@ connect_handler (void *cls, struct GNUNET_CADET_Channel *channel,
770 * @param channel Connection to the other end (henceforth invalid). 795 * @param channel Connection to the other end (henceforth invalid).
771 */ 796 */
772static void 797static void
773disconnect_handler (void *cls, const struct GNUNET_CADET_Channel *channel) 798disconnect_handler (void *cls,
799 const struct GNUNET_CADET_Channel *channel)
774{ 800{
775 struct CadetTestChannelWrapper *ch_w = cls; 801 struct CadetTestChannelWrapper *ch_w = cls;
776 802
777 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Channel disconnected\n"); 803 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
804 "Channel disconnected at %d\n",
805 ok);
778 GNUNET_assert (ch_w->ch == channel); 806 GNUNET_assert (ch_w->ch == channel);
779 if (channel == incoming_ch) 807 if (channel == incoming_ch)
780 { 808 {
781 ok++; 809 ok++;
782 incoming_ch = NULL; 810 incoming_ch = NULL;
783 } 811 }
784 else if (outgoing_ch == channel 812 else if (outgoing_ch == channel)
785 )
786 { 813 {
787 if (P2P_SIGNAL == test) 814 if (P2P_SIGNAL == test)
788 { 815 {
@@ -791,15 +818,17 @@ disconnect_handler (void *cls, const struct GNUNET_CADET_Channel *channel)
791 outgoing_ch = NULL; 818 outgoing_ch = NULL;
792 } 819 }
793 else 820 else
794 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unknown channel! %p\n", channel); 821 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
795 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok); 822 "Unknown channel! %p\n",
796 823 channel);
797 if (NULL != disconnect_task) 824 if (NULL != disconnect_task)
798 { 825 {
799 GNUNET_SCHEDULER_cancel (disconnect_task); 826 GNUNET_SCHEDULER_cancel (disconnect_task);
800 disconnect_task = 827 disconnect_task =
801 GNUNET_SCHEDULER_add_now (&gather_stats_and_exit, (void *) __LINE__); 828 GNUNET_SCHEDULER_add_now (&gather_stats_and_exit,
829 (void *) __LINE__);
802 } 830 }
831 GNUNET_free (ch_w);
803} 832}
804 833
805 834
@@ -879,25 +908,34 @@ start_test (void *cls)
879 * NULL if the operation is successfull 908 * NULL if the operation is successfull
880 */ 909 */
881static void 910static void
882pi_cb (void *cls, struct GNUNET_TESTBED_Operation *op, 911pi_cb (void *cls,
883 const struct GNUNET_TESTBED_PeerInformation *pinfo, const char *emsg) 912 struct GNUNET_TESTBED_Operation *op,
913 const struct GNUNET_TESTBED_PeerInformation *pinfo,
914 const char *emsg)
884{ 915{
885 long i = (long) cls; 916 long i = (long) cls;
886 917
887 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ID callback for %ld\n", i); 918 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
888 919 "ID callback for %ld\n",
889 if ((NULL == pinfo) || (NULL != emsg)) 920 i);
921 if ( (NULL == pinfo) ||
922 (NULL != emsg) )
890 { 923 {
891 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "pi_cb: %s\n", emsg); 924 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
925 "pi_cb: %s\n",
926 emsg);
892 abort_test (__LINE__); 927 abort_test (__LINE__);
893 return; 928 return;
894 } 929 }
895 p_id[i] = pinfo->result.id; 930 p_id[i] = pinfo->result.id;
896 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " id: %s\n", GNUNET_i2s (p_id[i])); 931 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
932 "id: %s\n",
933 GNUNET_i2s (p_id[i]));
897 p_ids++; 934 p_ids++;
898 if (p_ids < 2) 935 if (p_ids < 2)
899 return; 936 return;
900 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got all IDs, starting test\n"); 937 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
938 "Got all IDs, starting test\n");
901 test_task = GNUNET_SCHEDULER_add_now (&start_test, NULL); 939 test_task = GNUNET_SCHEDULER_add_now (&start_test, NULL);
902} 940}
903 941
@@ -929,7 +967,8 @@ tmain (void *cls,
929 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, 967 disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
930 &disconnect_cadet_peers, 968 &disconnect_cadet_peers,
931 (void *) __LINE__); 969 (void *) __LINE__);
932 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 970 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
971 NULL);
933 t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0], 972 t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0],
934 GNUNET_TESTBED_PIT_IDENTITY, 973 GNUNET_TESTBED_PIT_IDENTITY,
935 &pi_cb, 974 &pi_cb,
@@ -960,16 +999,16 @@ main (int argc, char *argv[])
960 char port_id[] = "test port"; 999 char port_id[] = "test port";
961 struct GNUNET_GETOPT_CommandLineOption options[] = { 1000 struct GNUNET_GETOPT_CommandLineOption options[] = {
962 GNUNET_GETOPT_option_relative_time ('t', 1001 GNUNET_GETOPT_option_relative_time ('t',
963 "time", 1002 "time",
964 "short_time", 1003 "short_time",
965 gettext_noop ("set short timeout"), 1004 gettext_noop ("set short timeout"),
966 &short_time), 1005 &short_time),
967 1006
968 GNUNET_GETOPT_option_uint ('m', 1007 GNUNET_GETOPT_option_uint ('m',
969 "messages", 1008 "messages",
970 "NUM_MESSAGES", 1009 "NUM_MESSAGES",
971 gettext_noop ("set number of messages to send"), 1010 gettext_noop ("set number of messages to send"),
972 &total_packets), 1011 &total_packets),
973 1012
974 GNUNET_GETOPT_OPTION_END 1013 GNUNET_GETOPT_OPTION_END
975 }; 1014 };
diff --git a/src/conversation/gnunet-helper-audio-playback-gst.c b/src/conversation/gnunet-helper-audio-playback-gst.c
index 264b14e76..002fed6c7 100644
--- a/src/conversation/gnunet-helper-audio-playback-gst.c
+++ b/src/conversation/gnunet-helper-audio-playback-gst.c
@@ -221,6 +221,11 @@ feed_buffer_to_gst (const char *audio, size_t b_len)
221 221
222/** 222/**
223 * Message callback 223 * Message callback
224 *
225 * @param msg message we received.
226 * @return #GNUNET_OK on success,
227 * #GNUNET_NO to stop further processing due to disconnect (no error)
228 * #GNUNET_SYSERR to stop further processing due to error
224 */ 229 */
225static int 230static int
226stdin_receiver (void *cls, 231stdin_receiver (void *cls,
diff --git a/src/conversation/gnunet-helper-audio-playback.c b/src/conversation/gnunet-helper-audio-playback.c
index 4344e1d41..18f63ad18 100644
--- a/src/conversation/gnunet-helper-audio-playback.c
+++ b/src/conversation/gnunet-helper-audio-playback.c
@@ -546,6 +546,11 @@ ogg_demux_and_decode ()
546 546
547/** 547/**
548 * Message callback 548 * Message callback
549 *
550 * @param msg message we received.
551 * @return #GNUNET_OK on success,
552 * #GNUNET_NO to stop further processing due to disconnect (no error)
553 * #GNUNET_SYSERR to stop further processing due to error
549 */ 554 */
550static int 555static int
551stdin_receiver (void *cls, 556stdin_receiver (void *cls,
diff --git a/src/conversation/gnunet_gst.c b/src/conversation/gnunet_gst.c
index 52cb2ccbc..828b35077 100644
--- a/src/conversation/gnunet_gst.c
+++ b/src/conversation/gnunet_gst.c
@@ -649,6 +649,11 @@ gnunet_read (GNUNET_gstData * d)
649 649
650/** 650/**
651 * Message callback 651 * Message callback
652 *
653 * @param msg message we received.
654 * @return #GNUNET_OK on success,
655 * #GNUNET_NO to stop further processing due to disconnect (no error)
656 * #GNUNET_SYSERR to stop further processing due to error
652 */ 657 */
653static int 658static int
654stdin_receiver (void *cls, 659stdin_receiver (void *cls,
diff --git a/src/conversation/microphone.c b/src/conversation/microphone.c
index 7871433a3..11468fc59 100644
--- a/src/conversation/microphone.c
+++ b/src/conversation/microphone.c
@@ -65,7 +65,9 @@ struct Microphone
65 * 65 *
66 * @param cls clsoure with our `struct Microphone` 66 * @param cls clsoure with our `struct Microphone`
67 * @param msg the message from the helper 67 * @param msg the message from the helper
68 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 68 * @return #GNUNET_OK on success,
69 * #GNUNET_NO to stop further processing (no error)
70 * #GNUNET_SYSERR to stop further processing with error
69 */ 71 */
70static int 72static int
71process_record_messages (void *cls, 73process_record_messages (void *cls,
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c
index 625bf9655..214f72904 100644
--- a/src/core/gnunet-service-core.c
+++ b/src/core/gnunet-service-core.c
@@ -426,6 +426,9 @@ struct TokenizerContext
426 * 426 *
427 * @param cls reservation request (`struct TokenizerContext`) 427 * @param cls reservation request (`struct TokenizerContext`)
428 * @param message the actual message 428 * @param message the actual message
429 * @return #GNUNET_OK on success,
430 * #GNUNET_NO to stop further processing (no error)
431 * #GNUNET_SYSERR to stop further processing with error
429 */ 432 */
430static int 433static int
431tokenized_cb (void *cls, 434tokenized_cb (void *cls,
diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c
index 8a7cada5c..944d1e692 100644
--- a/src/core/gnunet-service-core_kx.c
+++ b/src/core/gnunet-service-core_kx.c
@@ -708,6 +708,9 @@ setup_fresh_ping (struct GSC_KeyExchangeInfo *kx)
708 * 708 *
709 * @param cls the `struct GSC_KeyExchangeInfo` 709 * @param cls the `struct GSC_KeyExchangeInfo`
710 * @param m the message 710 * @param m the message
711 * @return #GNUNET_OK on success,
712 * #GNUNET_NO to stop further processing (no error)
713 * #GNUNET_SYSERR to stop further processing with error
711 */ 714 */
712static int 715static int
713deliver_message (void *cls, 716deliver_message (void *cls,
@@ -950,7 +953,7 @@ handle_ephemeral_key (void *cls,
950 kx->peer, 953 kx->peer,
951 sizeof (struct GNUNET_PeerIdentity))) 954 sizeof (struct GNUNET_PeerIdentity)))
952 { 955 {
953 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 956 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
954 "Received EPHEMERAL_KEY from %s, but expected %s\n", 957 "Received EPHEMERAL_KEY from %s, but expected %s\n",
955 GNUNET_i2s (&m->origin_identity), 958 GNUNET_i2s (&m->origin_identity),
956 GNUNET_i2s_full (kx->peer)); 959 GNUNET_i2s_full (kx->peer));
diff --git a/src/core/gnunet-service-core_sessions.c b/src/core/gnunet-service-core_sessions.c
index 5d34b7c26..babf169c0 100644
--- a/src/core/gnunet-service-core_sessions.c
+++ b/src/core/gnunet-service-core_sessions.c
@@ -147,12 +147,6 @@ struct Session
147 struct GNUNET_TIME_Relative typemap_delay; 147 struct GNUNET_TIME_Relative typemap_delay;
148 148
149 /** 149 /**
150 * Is the neighbour queue empty and thus ready for us
151 * to transmit an encrypted message?
152 */
153 int ready_to_transmit;
154
155 /**
156 * Is this the first time we're sending the typemap? If so, 150 * Is this the first time we're sending the typemap? If so,
157 * we want to send it a bit faster the second time. 0 if 151 * we want to send it a bit faster the second time. 0 if
158 * we are sending for the first time, 1 if not. 152 * we are sending for the first time, 1 if not.
@@ -641,13 +635,7 @@ try_transmission (struct Session *session)
641 enum GNUNET_CORE_Priority maxpc; 635 enum GNUNET_CORE_Priority maxpc;
642 struct GSC_ClientActiveRequest *car; 636 struct GSC_ClientActiveRequest *car;
643 int excess; 637 int excess;
644 638
645 if (GNUNET_YES != session->ready_to_transmit)
646 {
647 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
648 "Not yet ready to transmit, not evaluating queue\n");
649 return;
650 }
651 msize = 0; 639 msize = 0;
652 min_deadline = GNUNET_TIME_UNIT_FOREVER_ABS; 640 min_deadline = GNUNET_TIME_UNIT_FOREVER_ABS;
653 /* if the peer has excess bandwidth, background traffic is allowed, 641 /* if the peer has excess bandwidth, background traffic is allowed,
@@ -801,7 +789,6 @@ try_transmission (struct Session *session)
801 total_bytes / total_msgs, 789 total_bytes / total_msgs,
802 GNUNET_NO); 790 GNUNET_NO);
803 /* now actually transmit... */ 791 /* now actually transmit... */
804 session->ready_to_transmit = GNUNET_NO;
805 GSC_KX_encrypt_and_transmit (session->kx, 792 GSC_KX_encrypt_and_transmit (session->kx,
806 pbuf, 793 pbuf,
807 used); 794 used);
@@ -888,10 +875,12 @@ GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid)
888{ 875{
889 struct Session *session; 876 struct Session *session;
890 877
878 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
879 "Transport solicits for %s\n",
880 GNUNET_i2s (pid));
891 session = find_session (pid); 881 session = find_session (pid);
892 if (NULL == session) 882 if (NULL == session)
893 return; 883 return;
894 session->ready_to_transmit = GNUNET_YES;
895 try_transmission (session); 884 try_transmission (session);
896} 885}
897 886
diff --git a/src/credential/credential.h b/src/credential/credential.h
index f16249c1b..66a4636fc 100644
--- a/src/credential/credential.h
+++ b/src/credential/credential.h
@@ -20,7 +20,7 @@
20/** 20/**
21 * @file credential/credential.h 21 * @file credential/credential.h
22 * @brief IPC messages between CREDENTIAL API and CREDENTIAL service 22 * @brief IPC messages between CREDENTIAL API and CREDENTIAL service
23 * @author Adnan Husain 23 * @author Martin Schanzenbach
24 */ 24 */
25#ifndef CREDENTIAL_H 25#ifndef CREDENTIAL_H
26#define CREDENTIAL_H 26#define CREDENTIAL_H
diff --git a/src/credential/credential_api.c b/src/credential/credential_api.c
index ca54137ad..677cb9ad4 100644
--- a/src/credential/credential_api.c
+++ b/src/credential/credential_api.c
@@ -20,7 +20,7 @@
20/** 20/**
21 * @file credential/credential_api.c 21 * @file credential/credential_api.c
22 * @brief library to access the CREDENTIAL service 22 * @brief library to access the CREDENTIAL service
23 * @author Adnan Husain 23 * @author Martin Schanzenbach
24 */ 24 */
25#include "platform.h" 25#include "platform.h"
26#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
@@ -189,7 +189,7 @@ mq_error_handler (void *cls,
189 * Check validity of message received from the CREDENTIAL service 189 * Check validity of message received from the CREDENTIAL service
190 * 190 *
191 * @param cls the `struct GNUNET_CREDENTIAL_Handle *` 191 * @param cls the `struct GNUNET_CREDENTIAL_Handle *`
192 * @param loookup_msg the incoming message 192 * @param vr_msg the incoming message
193 */ 193 */
194static int 194static int
195check_result (void *cls, 195check_result (void *cls,
@@ -204,7 +204,7 @@ check_result (void *cls,
204 * Handler for messages received from the CREDENTIAL service 204 * Handler for messages received from the CREDENTIAL service
205 * 205 *
206 * @param cls the `struct GNUNET_CREDENTIAL_Handle *` 206 * @param cls the `struct GNUNET_CREDENTIAL_Handle *`
207 * @param loookup_msg the incoming message 207 * @param vr_msg the incoming message
208 */ 208 */
209static void 209static void
210handle_result (void *cls, 210handle_result (void *cls,
@@ -348,15 +348,15 @@ GNUNET_CREDENTIAL_disconnect (struct GNUNET_CREDENTIAL_Handle *handle)
348 * @param lr the verify request to cancel 348 * @param lr the verify request to cancel
349 */ 349 */
350void 350void
351GNUNET_CREDENTIAL_request_cancel (struct GNUNET_CREDENTIAL_Request *vr) 351GNUNET_CREDENTIAL_request_cancel (struct GNUNET_CREDENTIAL_Request *lr)
352{ 352{
353 struct GNUNET_CREDENTIAL_Handle *handle = vr->credential_handle; 353 struct GNUNET_CREDENTIAL_Handle *handle = lr->credential_handle;
354 354
355 GNUNET_CONTAINER_DLL_remove (handle->request_head, 355 GNUNET_CONTAINER_DLL_remove (handle->request_head,
356 handle->request_tail, 356 handle->request_tail,
357 vr); 357 lr);
358 GNUNET_MQ_discard (vr->env); 358 GNUNET_MQ_discard (lr->env);
359 GNUNET_free (vr); 359 GNUNET_free (lr);
360} 360}
361 361
362 362
@@ -369,8 +369,6 @@ GNUNET_CREDENTIAL_request_cancel (struct GNUNET_CREDENTIAL_Request *vr)
369 * @param issuer_key the issuer public key 369 * @param issuer_key the issuer public key
370 * @param issuer_attribute the issuer attribute 370 * @param issuer_attribute the issuer attribute
371 * @param subject_key the subject public key 371 * @param subject_key the subject public key
372 * @param credential_count number of credentials provided
373 * @param credentials subject credentials
374 * @param proc function to call on result 372 * @param proc function to call on result
375 * @param proc_cls closure for processor 373 * @param proc_cls closure for processor
376 * @return handle to the queued request 374 * @return handle to the queued request
diff --git a/src/credential/credential_misc.c b/src/credential/credential_misc.c
index 7849e81e6..2575f1de8 100644
--- a/src/credential/credential_misc.c
+++ b/src/credential/credential_misc.c
@@ -20,7 +20,7 @@
20 20
21 21
22/** 22/**
23 * @file credential/credential_mic.c 23 * @file credential/credential_misc.c
24 * @brief Misc API for credentials 24 * @brief Misc API for credentials
25 * 25 *
26 * @author Martin Schanzenbach 26 * @author Martin Schanzenbach
@@ -113,7 +113,6 @@ GNUNET_CREDENTIAL_credential_from_string (const char* s)
113/** 113/**
114 * Issue an attribute to a subject 114 * Issue an attribute to a subject
115 * 115 *
116 * @param handle handle to the Credential service
117 * @param issuer the ego that should be used to issue the attribute 116 * @param issuer the ego that should be used to issue the attribute
118 * @param subject the subject of the attribute 117 * @param subject the subject of the attribute
119 * @param attribute the name of the attribute 118 * @param attribute the name of the attribute
@@ -150,6 +149,7 @@ GNUNET_CREDENTIAL_credential_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *
150 { 149 {
151 GNUNET_break (0); 150 GNUNET_break (0);
152 GNUNET_free (crd); 151 GNUNET_free (crd);
152 GNUNET_free (cred);
153 return NULL; 153 return NULL;
154 } 154 }
155 cred->signature = crd->signature; 155 cred->signature = crd->signature;
diff --git a/src/credential/credential_serialization.c b/src/credential/credential_serialization.c
index 1fc72c203..2bbf3bfb8 100644
--- a/src/credential/credential_serialization.c
+++ b/src/credential/credential_serialization.c
@@ -34,11 +34,10 @@
34 34
35/** 35/**
36 * Calculate how many bytes we will need to serialize 36 * Calculate how many bytes we will need to serialize
37 * the given delegation chain and credential 37 * the given delegation chain
38 * 38 *
39 * @param d_count number of delegation chain entries 39 * @param ds_count number of delegation chain entries
40 * @param dd array of #GNUNET_CREDENTIAL_Delegation 40 * @param dsr array of #GNUNET_CREDENTIAL_DelegationSet
41 * @param cd a #GNUNET_CREDENTIAL_Credential
42 * @return the required size to serialize 41 * @return the required size to serialize
43 */ 42 */
44size_t 43size_t
@@ -62,8 +61,7 @@ GNUNET_CREDENTIAL_delegation_set_get_size (unsigned int ds_count,
62 * Serizalize the given delegation chain entries and credential 61 * Serizalize the given delegation chain entries and credential
63 * 62 *
64 * @param d_count number of delegation chain entries 63 * @param d_count number of delegation chain entries
65 * @param dd array of #GNUNET_CREDENTIAL_Delegation 64 * @param dsr array of #GNUNET_CREDENTIAL_DelegationSet
66 * @param cd a #GNUNET_CREDENTIAL_Credential
67 * @param dest_size size of the destination 65 * @param dest_size size of the destination
68 * @param dest where to store the result 66 * @param dest where to store the result
69 * @return the size of the data, -1 on failure 67 * @return the size of the data, -1 on failure
@@ -108,8 +106,7 @@ GNUNET_CREDENTIAL_delegation_set_serialize (unsigned int d_count,
108 * @param len size of the serialized delegation chain and cred 106 * @param len size of the serialized delegation chain and cred
109 * @param src the serialized data 107 * @param src the serialized data
110 * @param d_count the number of delegation chain entries 108 * @param d_count the number of delegation chain entries
111 * @param dd where to put the delegation chain entries 109 * @param dsr where to put the delegation chain entries
112 * @param cd where to put the credential data
113 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 110 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
114 */ 111 */
115int 112int
@@ -282,7 +279,6 @@ GNUNET_CREDENTIAL_delegation_chain_get_size (unsigned int d_count,
282 ret += dd[i].issuer_attribute_len + dd[i].subject_attribute_len; 279 ret += dd[i].issuer_attribute_len + dd[i].subject_attribute_len;
283 } 280 }
284 return ret+GNUNET_CREDENTIAL_credentials_get_size(c_count, cd); 281 return ret+GNUNET_CREDENTIAL_credentials_get_size(c_count, cd);
285 return ret;
286} 282}
287 283
288/** 284/**
diff --git a/src/credential/gnunet-credential.c b/src/credential/gnunet-credential.c
index 4a6dc5ccd..b5bcc4d43 100644
--- a/src/credential/gnunet-credential.c
+++ b/src/credential/gnunet-credential.c
@@ -20,7 +20,7 @@
20/** 20/**
21 * @file gnunet-credential.c 21 * @file gnunet-credential.c
22 * @brief command line tool to access command line Credential service 22 * @brief command line tool to access command line Credential service
23 * @author Adnan Husain 23 * @author Martin Schanzenbach
24 */ 24 */
25#include "platform.h" 25#include "platform.h"
26#include <gnunet_util_lib.h> 26#include <gnunet_util_lib.h>
@@ -158,13 +158,6 @@ do_timeout (void *cls)
158 GNUNET_SCHEDULER_shutdown (); 158 GNUNET_SCHEDULER_shutdown ();
159} 159}
160 160
161/**
162 * Function called with the result of a Credential lookup.
163 *
164 * @param cls the 'const char *' name that was resolved
165 * @param cd_count number of records returned
166 * @param cd array of @a cd_count records with the results
167 */
168static void 161static void
169handle_collect_result (void *cls, 162handle_collect_result (void *cls,
170 unsigned int d_count, 163 unsigned int d_count,
@@ -192,13 +185,6 @@ handle_collect_result (void *cls,
192} 185}
193 186
194 187
195/**
196 * Function called with the result of a Credential lookup.
197 *
198 * @param cls the 'const char *' name that was resolved
199 * @param cd_count number of records returned
200 * @param cd array of @a cd_count records with the results
201 */
202static void 188static void
203handle_verify_result (void *cls, 189handle_verify_result (void *cls,
204 unsigned int d_count, 190 unsigned int d_count,
@@ -385,12 +371,14 @@ run (void *cls,
385 fprintf (stderr, 371 fprintf (stderr,
386 _("Failed to connect to CREDENTIAL\n")); 372 _("Failed to connect to CREDENTIAL\n"));
387 GNUNET_SCHEDULER_shutdown (); 373 GNUNET_SCHEDULER_shutdown ();
374 return;
388 } 375 }
389 if (NULL == issuer_attr) 376 if (NULL == issuer_attr)
390 { 377 {
391 fprintf (stderr, 378 fprintf (stderr,
392 _("You must provide issuer the attribute\n")); 379 _("You must provide issuer the attribute\n"));
393 GNUNET_SCHEDULER_shutdown (); 380 GNUNET_SCHEDULER_shutdown ();
381 return;
394 } 382 }
395 383
396 if (NULL == ego_name) 384 if (NULL == ego_name)
@@ -446,6 +434,7 @@ run (void *cls,
446 _("Issuer public key `%s' is not well-formed\n"), 434 _("Issuer public key `%s' is not well-formed\n"),
447 issuer_key); 435 issuer_key);
448 GNUNET_SCHEDULER_shutdown (); 436 GNUNET_SCHEDULER_shutdown ();
437 return;
449 } 438 }
450 credential = GNUNET_CREDENTIAL_connect (cfg); 439 credential = GNUNET_CREDENTIAL_connect (cfg);
451 440
@@ -454,12 +443,14 @@ run (void *cls,
454 fprintf (stderr, 443 fprintf (stderr,
455 _("Failed to connect to CREDENTIAL\n")); 444 _("Failed to connect to CREDENTIAL\n"));
456 GNUNET_SCHEDULER_shutdown (); 445 GNUNET_SCHEDULER_shutdown ();
446 return;
457 } 447 }
458 if (NULL == issuer_attr || NULL == subject_credential) 448 if (NULL == issuer_attr || NULL == subject_credential)
459 { 449 {
460 fprintf (stderr, 450 fprintf (stderr,
461 _("You must provide issuer and subject attributes\n")); 451 _("You must provide issuer and subject attributes\n"));
462 GNUNET_SCHEDULER_shutdown (); 452 GNUNET_SCHEDULER_shutdown ();
453 return;
463 } 454 }
464 455
465 //Subject credentials are comma separated 456 //Subject credentials are comma separated
@@ -471,6 +462,7 @@ run (void *cls,
471 "Invalid subject credentials\n"); 462 "Invalid subject credentials\n");
472 GNUNET_free (tmp); 463 GNUNET_free (tmp);
473 GNUNET_SCHEDULER_shutdown (); 464 GNUNET_SCHEDULER_shutdown ();
465 return;
474 } 466 }
475 int count = 1; 467 int count = 1;
476 int i; 468 int i;
@@ -504,6 +496,7 @@ run (void *cls,
504 { 496 {
505 GNUNET_free ((char*)credentials[i].issuer_attribute); 497 GNUNET_free ((char*)credentials[i].issuer_attribute);
506 } 498 }
499 GNUNET_free (tmp);
507 } else if (GNUNET_YES == create_cred) { 500 } else if (GNUNET_YES == create_cred) {
508 if (NULL == ego_name) 501 if (NULL == ego_name)
509 { 502 {
diff --git a/src/credential/gnunet-service-credential.c b/src/credential/gnunet-service-credential.c
index be75e485e..a2c339363 100644
--- a/src/credential/gnunet-service-credential.c
+++ b/src/credential/gnunet-service-credential.c
@@ -18,9 +18,9 @@
18 Boston, MA 02110-1301, USA. 18 Boston, MA 02110-1301, USA.
19*/ 19*/
20/** 20/**
21 * @file gns/gnunet-service-credential.c 21 * @file credential/gnunet-service-credential.c
22 * @brief GNU Credential Service (main service) 22 * @brief GNUnet Credential Service (main service)
23 * @author Adnan Husain 23 * @author Martin Schanzenbach
24 */ 24 */
25#include "platform.h" 25#include "platform.h"
26#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
@@ -377,16 +377,11 @@ cleanup_delegation_set (struct DelegationSetQueueEntry *ds_entry)
377 } 377 }
378 GNUNET_free (dq_entry); 378 GNUNET_free (dq_entry);
379 } 379 }
380 if (NULL != ds_entry->issuer_key) 380 GNUNET_free_non_null (ds_entry->issuer_key);
381 GNUNET_free (ds_entry->issuer_key); 381 GNUNET_free_non_null (ds_entry->lookup_attribute);
382 if (NULL != ds_entry->lookup_attribute) 382 GNUNET_free_non_null (ds_entry->issuer_attribute);
383 GNUNET_free (ds_entry->lookup_attribute); 383 GNUNET_free_non_null (ds_entry->unresolved_attribute_delegation);
384 if (NULL != ds_entry->issuer_attribute) 384 GNUNET_free_non_null (ds_entry->attr_trailer);
385 GNUNET_free (ds_entry->issuer_attribute);
386 if (NULL != ds_entry->unresolved_attribute_delegation)
387 GNUNET_free (ds_entry->unresolved_attribute_delegation);
388 if (NULL != ds_entry->attr_trailer)
389 GNUNET_free (ds_entry->attr_trailer);
390 if (NULL != ds_entry->lookup_request) 385 if (NULL != ds_entry->lookup_request)
391 { 386 {
392 GNUNET_GNS_lookup_cancel (ds_entry->lookup_request); 387 GNUNET_GNS_lookup_cancel (ds_entry->lookup_request);
@@ -394,10 +389,8 @@ cleanup_delegation_set (struct DelegationSetQueueEntry *ds_entry)
394 } 389 }
395 if (NULL != ds_entry->delegation_chain_entry) 390 if (NULL != ds_entry->delegation_chain_entry)
396 { 391 {
397 if (NULL != ds_entry->delegation_chain_entry->subject_attribute) 392 GNUNET_free_non_null (ds_entry->delegation_chain_entry->subject_attribute);
398 GNUNET_free (ds_entry->delegation_chain_entry->subject_attribute); 393 GNUNET_free_non_null (ds_entry->delegation_chain_entry->issuer_attribute);
399 if (NULL != ds_entry->delegation_chain_entry->issuer_attribute)
400 GNUNET_free (ds_entry->delegation_chain_entry->issuer_attribute);
401 GNUNET_free (ds_entry->delegation_chain_entry); 394 GNUNET_free (ds_entry->delegation_chain_entry);
402 } 395 }
403 GNUNET_free (ds_entry); 396 GNUNET_free (ds_entry);
@@ -415,8 +408,7 @@ cleanup_handle (struct VerifyRequestHandle *vrh)
415 vrh->lookup_request = NULL; 408 vrh->lookup_request = NULL;
416 } 409 }
417 cleanup_delegation_set (vrh->root_set); 410 cleanup_delegation_set (vrh->root_set);
418 if (NULL != vrh->issuer_attribute) 411 GNUNET_free_non_null (vrh->issuer_attribute);
419 GNUNET_free (vrh->issuer_attribute);
420 for (cr_entry = vrh->cred_chain_head; 412 for (cr_entry = vrh->cred_chain_head;
421 NULL != vrh->cred_chain_head; 413 NULL != vrh->cred_chain_head;
422 cr_entry = vrh->cred_chain_head) 414 cr_entry = vrh->cred_chain_head)
@@ -424,19 +416,12 @@ cleanup_handle (struct VerifyRequestHandle *vrh)
424 GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head, 416 GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head,
425 vrh->cred_chain_tail, 417 vrh->cred_chain_tail,
426 cr_entry); 418 cr_entry);
427 if (NULL != cr_entry->credential); 419 GNUNET_free_non_null (cr_entry->credential);
428 GNUNET_free (cr_entry->credential);
429 GNUNET_free (cr_entry); 420 GNUNET_free (cr_entry);
430 } 421 }
431 GNUNET_free (vrh); 422 GNUNET_free (vrh);
432} 423}
433 424
434/**
435 * Task run during shutdown.
436 *
437 * @param cls unused
438 * @param tc unused
439 */
440static void 425static void
441shutdown_task (void *cls) 426shutdown_task (void *cls)
442{ 427{
@@ -475,11 +460,6 @@ shutdown_task (void *cls)
475 460
476 461
477 462
478/**
479 * Send.
480 *
481 * @param handle the handle to the request
482 */
483static void 463static void
484send_lookup_response (struct VerifyRequestHandle *vrh) 464send_lookup_response (struct VerifyRequestHandle *vrh)
485{ 465{
@@ -491,12 +471,11 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
491 struct CredentialRecordEntry *cd; 471 struct CredentialRecordEntry *cd;
492 struct CredentialRecordEntry *tmp; 472 struct CredentialRecordEntry *tmp;
493 size_t size; 473 size_t size;
494 int i;
495 474
496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
497 "Sending response\n"); 476 "Sending response\n");
498 dce = vrh->delegation_chain_head; 477 dce = vrh->delegation_chain_head;
499 for (i=0;i<vrh->delegation_chain_size;i++) 478 for (uint32_t i=0;i<vrh->delegation_chain_size;i++)
500 { 479 {
501 dd[i].issuer_key = dce->issuer_key; 480 dd[i].issuer_key = dce->issuer_key;
502 dd[i].subject_key = dce->subject_key; 481 dd[i].subject_key = dce->subject_key;
@@ -537,7 +516,7 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
537 * Append at the end of rmsg 516 * Append at the end of rmsg
538 */ 517 */
539 cd = vrh->cred_chain_head; 518 cd = vrh->cred_chain_head;
540 for (i=0;i<vrh->cred_chain_size;i++) 519 for (uint32_t i=0;i<vrh->cred_chain_size;i++)
541 { 520 {
542 cred[i].issuer_key = cd->credential->issuer_key; 521 cred[i].issuer_key = cd->credential->issuer_key;
543 cred[i].subject_key = cd->credential->subject_key; 522 cred[i].subject_key = cd->credential->subject_key;
@@ -598,8 +577,6 @@ backward_resolution (void* cls,
598 struct DelegationQueueEntry *dq_entry; 577 struct DelegationQueueEntry *dq_entry;
599 char *expanded_attr; 578 char *expanded_attr;
600 char *lookup_attribute; 579 char *lookup_attribute;
601 int i;
602 int j;
603 580
604 581
605 current_set = cls; 582 current_set = cls;
@@ -610,7 +587,7 @@ backward_resolution (void* cls,
610 "Got %d attrs\n", rd_count); 587 "Got %d attrs\n", rd_count);
611 588
612 // Each OR 589 // Each OR
613 for (i=0; i < rd_count; i++) 590 for (uint32_t i=0; i < rd_count; i++)
614 { 591 {
615 if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type) 592 if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type)
616 continue; 593 continue;
@@ -637,7 +614,7 @@ backward_resolution (void* cls,
637 current_set->queue_entries_tail, 614 current_set->queue_entries_tail,
638 dq_entry); 615 dq_entry);
639 // Each AND 616 // Each AND
640 for (j=0; j<ntohl(sets->set_count); j++) 617 for (uint32_t j=0; j<ntohl(sets->set_count); j++)
641 { 618 {
642 ds_entry = GNUNET_new (struct DelegationSetQueueEntry); 619 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
643 if (NULL != current_set->attr_trailer) 620 if (NULL != current_set->attr_trailer)
@@ -745,6 +722,12 @@ backward_resolution (void* cls,
745 strcpy (issuer_attribute_name, 722 strcpy (issuer_attribute_name,
746 ds_entry->unresolved_attribute_delegation); 723 ds_entry->unresolved_attribute_delegation);
747 char *next_attr = strtok (issuer_attribute_name, "."); 724 char *next_attr = strtok (issuer_attribute_name, ".");
725 if (NULL == next_attr)
726 {
727 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
728 "Failed to parse next attribute\n");
729 continue;
730 }
748 GNUNET_asprintf (&lookup_attribute, 731 GNUNET_asprintf (&lookup_attribute,
749 "%s.gnu", 732 "%s.gnu",
750 next_attr); 733 next_attr);
@@ -793,8 +776,6 @@ backward_resolution (void* cls,
793 * Result from GNS lookup. 776 * Result from GNS lookup.
794 * 777 *
795 * @param cls the closure (our client lookup handle) 778 * @param cls the closure (our client lookup handle)
796 * @param rd_count the number of records in @a rd
797 * @param rd the record data
798 */ 779 */
799static void 780static void
800delegation_chain_resolution_start (void* cls) 781delegation_chain_resolution_start (void* cls)
@@ -831,7 +812,7 @@ delegation_chain_resolution_start (void* cls)
831 * Check for attributes from the issuer and follow the chain 812 * Check for attributes from the issuer and follow the chain
832 * till you get the required subject's attributes 813 * till you get the required subject's attributes
833 */ 814 */
834 char issuer_attribute_name[strlen (vrh->issuer_attribute)]; 815 char issuer_attribute_name[strlen (vrh->issuer_attribute) + strlen (".gnu") + 1];
835 strcpy (issuer_attribute_name, 816 strcpy (issuer_attribute_name,
836 vrh->issuer_attribute); 817 vrh->issuer_attribute);
837 strcpy (issuer_attribute_name + strlen (vrh->issuer_attribute), 818 strcpy (issuer_attribute_name + strlen (vrh->issuer_attribute),
@@ -858,13 +839,6 @@ delegation_chain_resolution_start (void* cls)
858 ds_entry); 839 ds_entry);
859} 840}
860 841
861/**
862 * Checks a #GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY message
863 *
864 * @param cls client sending the message
865 * @param v_msg message of type `struct VerifyMessage`
866 * @return #GNUNET_OK if @a v_msg is well-formed
867 */
868static int 842static int
869check_verify (void *cls, 843check_verify (void *cls,
870 const struct VerifyMessage *v_msg) 844 const struct VerifyMessage *v_msg)
@@ -893,13 +867,6 @@ check_verify (void *cls,
893 return GNUNET_OK; 867 return GNUNET_OK;
894} 868}
895 869
896/**
897 * Handle Credential verification requests from client
898 *
899 * @param cls the closure
900 * @param client the client
901 * @param message the message
902 */
903static void 870static void
904handle_verify (void *cls, 871handle_verify (void *cls,
905 const struct VerifyMessage *v_msg) 872 const struct VerifyMessage *v_msg)
@@ -909,7 +876,6 @@ handle_verify (void *cls,
909 struct CredentialRecordEntry *cr_entry; 876 struct CredentialRecordEntry *cr_entry;
910 uint32_t credentials_count; 877 uint32_t credentials_count;
911 uint32_t credential_data_size; 878 uint32_t credential_data_size;
912 int i;
913 char attr[GNUNET_CREDENTIAL_MAX_LENGTH + 1]; 879 char attr[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
914 char issuer_attribute[GNUNET_CREDENTIAL_MAX_LENGTH + 1]; 880 char issuer_attribute[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
915 char *attrptr = attr; 881 char *attrptr = attr;
@@ -929,7 +895,7 @@ handle_verify (void *cls,
929 vrh->issuer_key = v_msg->issuer_key; 895 vrh->issuer_key = v_msg->issuer_key;
930 vrh->subject_key = v_msg->subject_key; 896 vrh->subject_key = v_msg->subject_key;
931 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute); 897 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute);
932 if (NULL == issuer_attribute) 898 if (0 == strlen (issuer_attribute))
933 { 899 {
934 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 900 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
935 "No issuer attribute provided!\n"); 901 "No issuer attribute provided!\n");
@@ -958,7 +924,7 @@ handle_verify (void *cls,
958 return; 924 return;
959 } 925 }
960 926
961 for (i=0;i<credentials_count;i++) { 927 for (uint32_t i=0;i<credentials_count;i++) {
962 cr_entry = GNUNET_new (struct CredentialRecordEntry); 928 cr_entry = GNUNET_new (struct CredentialRecordEntry);
963 cr_entry->credential = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) + 929 cr_entry->credential = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) +
964 credentials[i].issuer_attribute_len); 930 credentials[i].issuer_attribute_len);
@@ -979,9 +945,6 @@ handle_verify (void *cls,
979 945
980} 946}
981 947
982/**
983 * We encountered an error while collecting
984 */
985static void 948static void
986handle_cred_collection_error_cb (void *cls) 949handle_cred_collection_error_cb (void *cls)
987{ 950{
@@ -1001,9 +964,6 @@ collect_next (void *cls)
1001 GNUNET_NAMESTORE_zone_iterator_next (vrh->cred_collection_iter); 964 GNUNET_NAMESTORE_zone_iterator_next (vrh->cred_collection_iter);
1002} 965}
1003 966
1004/**
1005 * Store credential
1006 */
1007static void 967static void
1008handle_cred_collection_cb (void *cls, 968handle_cred_collection_cb (void *cls,
1009 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, 969 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
@@ -1015,10 +975,9 @@ handle_cred_collection_cb (void *cls,
1015 struct GNUNET_CREDENTIAL_Credential *crd; 975 struct GNUNET_CREDENTIAL_Credential *crd;
1016 struct CredentialRecordEntry *cr_entry; 976 struct CredentialRecordEntry *cr_entry;
1017 int cred_record_count; 977 int cred_record_count;
1018 int i;
1019 978
1020 cred_record_count = 0; 979 cred_record_count = 0;
1021 for (i=0; i < rd_count; i++) 980 for (uint32_t i=0; i < rd_count; i++)
1022 { 981 {
1023 if (GNUNET_GNSRECORD_TYPE_CREDENTIAL != rd[i].record_type) 982 if (GNUNET_GNSRECORD_TYPE_CREDENTIAL != rd[i].record_type)
1024 continue; 983 continue;
@@ -1042,9 +1001,6 @@ handle_cred_collection_cb (void *cls,
1042 vrh); 1001 vrh);
1043} 1002}
1044 1003
1045/**
1046 * We encountered an error while collecting
1047 */
1048static void 1004static void
1049handle_cred_collection_finished_cb (void *cls) 1005handle_cred_collection_finished_cb (void *cls)
1050{ 1006{
@@ -1055,13 +1011,6 @@ handle_cred_collection_finished_cb (void *cls)
1055 delegation_chain_resolution_start (vrh); 1011 delegation_chain_resolution_start (vrh);
1056} 1012}
1057 1013
1058/**
1059 * Handle Credential collection requests from client
1060 *
1061 * @param cls the closure
1062 * @param client the client
1063 * @param message the message
1064 */
1065static void 1014static void
1066handle_collect (void *cls, 1015handle_collect (void *cls,
1067 const struct CollectMessage *c_msg) 1016 const struct CollectMessage *c_msg)
@@ -1090,7 +1039,7 @@ handle_collect (void *cls,
1090 &vrh->subject_key); 1039 &vrh->subject_key);
1091 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute); 1040 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute);
1092 1041
1093 if (NULL == issuer_attribute) 1042 if (0 == strlen (issuer_attribute))
1094 { 1043 {
1095 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1044 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1096 "No issuer attribute provided!\n"); 1045 "No issuer attribute provided!\n");
@@ -1113,13 +1062,6 @@ handle_collect (void *cls,
1113} 1062}
1114 1063
1115 1064
1116/**
1117 * Checks a #GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT message
1118 *
1119 * @param cls client sending the message
1120 * @param v_msg message of type `struct CollectMessage`
1121 * @return #GNUNET_OK if @a v_msg is well-formed
1122 */
1123static int 1065static int
1124check_collect (void *cls, 1066check_collect (void *cls,
1125 const struct CollectMessage *c_msg) 1067 const struct CollectMessage *c_msg)
@@ -1140,7 +1082,7 @@ check_collect (void *cls,
1140 } 1082 }
1141 attr = (const char *) &c_msg[1]; 1083 attr = (const char *) &c_msg[1];
1142 1084
1143 if ( ('\0' != attr[ntohs(c_msg->header.size) - sizeof (struct CollectMessage) - 1]) || 1085 if ( ('\0' != attr[msg_size - sizeof (struct CollectMessage) - 1]) ||
1144 (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH) ) 1086 (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH) )
1145 { 1087 {
1146 GNUNET_break (0); 1088 GNUNET_break (0);
@@ -1149,12 +1091,6 @@ check_collect (void *cls,
1149 return GNUNET_OK; 1091 return GNUNET_OK;
1150} 1092}
1151 1093
1152/**
1153 * One of our clients disconnected, clean up after it.
1154 *
1155 * @param cls NULL
1156 * @param client the client that disconnected
1157 */
1158static void 1094static void
1159client_disconnect_cb (void *cls, 1095client_disconnect_cb (void *cls,
1160 struct GNUNET_SERVICE_Client *client, 1096 struct GNUNET_SERVICE_Client *client,
@@ -1165,14 +1101,6 @@ client_disconnect_cb (void *cls,
1165 client); 1101 client);
1166} 1102}
1167 1103
1168/**
1169 * Add a client to our list of active clients.
1170 *
1171 * @param cls NULL
1172 * @param client client to add
1173 * @param mq message queue for @a client
1174 * @return this client
1175 */
1176static void * 1104static void *
1177client_connect_cb (void *cls, 1105client_connect_cb (void *cls,
1178 struct GNUNET_SERVICE_Client *client, 1106 struct GNUNET_SERVICE_Client *client,
@@ -1188,8 +1116,8 @@ client_connect_cb (void *cls,
1188 * Process Credential requests. 1116 * Process Credential requests.
1189 * 1117 *
1190 * @param cls closure 1118 * @param cls closure
1191 * @param server the initialized server
1192 * @param c configuration to use 1119 * @param c configuration to use
1120 * @param handle service handle
1193 */ 1121 */
1194static void 1122static void
1195run (void *cls, 1123run (void *cls,
diff --git a/src/credential/plugin_gnsrecord_credential.c b/src/credential/plugin_gnsrecord_credential.c
index 72d6b53f5..ffb2857dc 100644
--- a/src/credential/plugin_gnsrecord_credential.c
+++ b/src/credential/plugin_gnsrecord_credential.c
@@ -21,7 +21,7 @@
21/** 21/**
22 * @file credential/plugin_gnsrecord_credential.c 22 * @file credential/plugin_gnsrecord_credential.c
23 * @brief gnsrecord plugin to provide the API for CREDENTIAL records 23 * @brief gnsrecord plugin to provide the API for CREDENTIAL records
24 * @author Adnan Husain 24 * @author Martin Schanzenbach
25 */ 25 */
26 26
27#include "platform.h" 27#include "platform.h"
@@ -199,6 +199,13 @@ credential_string_to_value (void *cls,
199 GNUNET_free (tmp_str); 199 GNUNET_free (tmp_str);
200 tmp_str = GNUNET_strdup (s); 200 tmp_str = GNUNET_strdup (s);
201 token = strtok (tmp_str, ","); 201 token = strtok (tmp_str, ",");
202 if (NULL == token)
203 {
204 GNUNET_free (tmp_str);
205 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
206 "Malformed string %s\n", s);
207 return GNUNET_SYSERR;
208 }
202 struct GNUNET_CREDENTIAL_DelegationSet set[entries]; 209 struct GNUNET_CREDENTIAL_DelegationSet set[entries];
203 for (i=0;i<entries;i++) 210 for (i=0;i<entries;i++)
204 { 211 {
@@ -219,7 +226,10 @@ credential_string_to_value (void *cls,
219 set); 226 set);
220 227
221 if (-1 == tmp_data_size) 228 if (-1 == tmp_data_size)
229 {
230 GNUNET_free (tmp_str);
222 return GNUNET_SYSERR; 231 return GNUNET_SYSERR;
232 }
223 *data_size += tmp_data_size; 233 *data_size += tmp_data_size;
224 *data = sets = GNUNET_malloc (*data_size); 234 *data = sets = GNUNET_malloc (*data_size);
225 GNUNET_CREDENTIAL_delegation_set_serialize (entries, 235 GNUNET_CREDENTIAL_delegation_set_serialize (entries,
diff --git a/src/credential/plugin_rest_credential.c b/src/credential/plugin_rest_credential.c
index 48d48fba0..2e43139de 100644
--- a/src/credential/plugin_rest_credential.c
+++ b/src/credential/plugin_rest_credential.c
@@ -19,7 +19,7 @@
19 */ 19 */
20/** 20/**
21 * @author Martin Schanzenbach 21 * @author Martin Schanzenbach
22 * @file gns/plugin_rest_credential.c 22 * @file credential/plugin_rest_credential.c
23 * @brief GNUnet CREDENTIAL REST plugin 23 * @brief GNUnet CREDENTIAL REST plugin
24 * 24 *
25 */ 25 */
@@ -194,12 +194,6 @@ cleanup_handle (struct RequestHandle *handle)
194} 194}
195 195
196 196
197/**
198 * Task run on shutdown. Cleans up everything.
199 *
200 * @param cls unused
201 * @param tc scheduler context
202 */
203static void 197static void
204do_error (void *cls) 198do_error (void *cls)
205{ 199{
@@ -213,7 +207,8 @@ do_error (void *cls)
213 207
214/** 208/**
215 * Attribute delegation to JSON 209 * Attribute delegation to JSON
216 * @param attr the attribute 210 *
211 * @param delegation_chain_entry the DSE
217 * @return JSON, NULL if failed 212 * @return JSON, NULL if failed
218 */ 213 */
219static json_t* 214static json_t*
@@ -257,6 +252,7 @@ attribute_delegation_to_json (struct GNUNET_CREDENTIAL_Delegation *delegation_ch
257 252
258/** 253/**
259 * JSONAPI resource to Credential 254 * JSONAPI resource to Credential
255 *
260 * @param res the JSONAPI resource 256 * @param res the JSONAPI resource
261 * @return the resulting credential, NULL if failed 257 * @return the resulting credential, NULL if failed
262 */ 258 */
@@ -327,6 +323,7 @@ json_to_credential (json_t *res)
327 323
328/** 324/**
329 * Credential to JSON 325 * Credential to JSON
326 *
330 * @param cred the credential 327 * @param cred the credential
331 * @return the resulting json, NULL if failed 328 * @return the resulting json, NULL if failed
332 */ 329 */
@@ -373,13 +370,6 @@ credential_to_json (struct GNUNET_CREDENTIAL_Credential *cred)
373 return cred_obj; 370 return cred_obj;
374} 371}
375 372
376/**
377 * Function called with the result of a Credential lookup.
378 *
379 * @param cls the 'const char *' name that was resolved
380 * @param cd_count number of records returned
381 * @param cd array of @a cd_count records with the results
382 */
383static void 373static void
384handle_collect_response (void *cls, 374handle_collect_response (void *cls,
385 unsigned int d_count, 375 unsigned int d_count,
@@ -470,13 +460,6 @@ subject_ego_lookup (void *cls,
470 460
471 461
472 462
473/**
474 * Function called with the result of a Credential lookup.
475 *
476 * @param cls the 'const char *' name that was resolved
477 * @param cd_count number of records returned
478 * @param cd array of @a cd_count records with the results
479 */
480static void 463static void
481handle_verify_response (void *cls, 464handle_verify_response (void *cls,
482 unsigned int d_count, 465 unsigned int d_count,
@@ -634,7 +617,6 @@ collect_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
634 { 617 {
635 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 618 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
636 "Missing subject\n"); 619 "Missing subject\n");
637 GNUNET_free (entity_attr);
638 GNUNET_SCHEDULER_add_now (&do_error, handle); 620 GNUNET_SCHEDULER_add_now (&do_error, handle);
639 return; 621 return;
640 } 622 }
@@ -644,7 +626,6 @@ collect_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
644 { 626 {
645 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 627 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
646 "Malformed subject\n"); 628 "Malformed subject\n");
647 GNUNET_free (entity_attr);
648 GNUNET_SCHEDULER_add_now (&do_error, handle); 629 GNUNET_SCHEDULER_add_now (&do_error, handle);
649 return; 630 return;
650 } 631 }
@@ -745,7 +726,6 @@ verify_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
745 { 726 {
746 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 727 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
747 "Missing subject key\n"); 728 "Missing subject key\n");
748 GNUNET_free (entity_attr);
749 GNUNET_SCHEDULER_add_now (&do_error, handle); 729 GNUNET_SCHEDULER_add_now (&do_error, handle);
750 return; 730 return;
751 } 731 }
@@ -755,7 +735,6 @@ verify_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
755 { 735 {
756 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 736 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
757 "Malformed subject\n"); 737 "Malformed subject\n");
758 GNUNET_free (entity_attr);
759 GNUNET_SCHEDULER_add_now (&do_error, handle); 738 GNUNET_SCHEDULER_add_now (&do_error, handle);
760 return; 739 return;
761 } 740 }
@@ -765,7 +744,6 @@ verify_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
765 &handle->subject_key)) { 744 &handle->subject_key)) {
766 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 745 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
767 "Malformed subject key\n"); 746 "Malformed subject key\n");
768 GNUNET_free (entity_attr);
769 GNUNET_SCHEDULER_add_now (&do_error, handle); 747 GNUNET_SCHEDULER_add_now (&do_error, handle);
770 return; 748 return;
771 } 749 }
@@ -875,6 +853,7 @@ send_cred_response (struct RequestHandle *handle,
875 { 853 {
876 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 854 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
877 "Subject malformed\n"); 855 "Subject malformed\n");
856 GNUNET_free (issuer);
878 return; 857 return;
879 } 858 }
880 GNUNET_asprintf (&id, 859 GNUNET_asprintf (&id,
@@ -886,6 +865,8 @@ send_cred_response (struct RequestHandle *handle,
886 { 865 {
887 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 866 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
888 "Subject malformed\n"); 867 "Subject malformed\n");
868 GNUNET_free (id);
869 GNUNET_free (issuer);
889 return; 870 return;
890 } 871 }
891 GNUNET_STRINGS_base64_encode ((char*)&cred->signature, 872 GNUNET_STRINGS_base64_encode ((char*)&cred->signature,
@@ -970,6 +951,14 @@ get_cred_issuer_cb (void *cls,
970 } 951 }
971 expiration_str = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map, 952 expiration_str = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map,
972 &key); 953 &key);
954 if ( NULL == expiration_str )
955 {
956 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
957 "Expiration malformed\n");
958 GNUNET_SCHEDULER_add_now (&do_error, handle);
959 return;
960 }
961
973 if (GNUNET_OK == GNUNET_STRINGS_fancy_time_to_relative (expiration_str, 962 if (GNUNET_OK == GNUNET_STRINGS_fancy_time_to_relative (expiration_str,
974 &etime_rel)) 963 &etime_rel))
975 { 964 {
@@ -1062,11 +1051,6 @@ issue_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
1062 handle); 1051 handle);
1063} 1052}
1064 1053
1065/**
1066 * Handle rest request
1067 *
1068 * @param handle the lookup handle
1069 */
1070static void 1054static void
1071options_cont (struct GNUNET_REST_RequestHandle *con_handle, 1055options_cont (struct GNUNET_REST_RequestHandle *con_handle,
1072 const char* url, 1056 const char* url,
@@ -1087,17 +1071,6 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle,
1087} 1071}
1088 1072
1089 1073
1090/**
1091 * Function processing the REST call
1092 *
1093 * @param method HTTP method
1094 * @param url URL of the HTTP request
1095 * @param data body of the HTTP request (optional)
1096 * @param data_size length of the body
1097 * @param proc callback function for the result
1098 * @param proc_cls closure for callback function
1099 * @return GNUNET_OK if request accepted
1100 */
1101static void 1074static void
1102rest_credential_process_request(struct GNUNET_REST_RequestHandle *conndata_handle, 1075rest_credential_process_request(struct GNUNET_REST_RequestHandle *conndata_handle,
1103 GNUNET_REST_ResultProcessor proc, 1076 GNUNET_REST_ResultProcessor proc,
diff --git a/src/credential/test_credential_verify_simple.sh b/src/credential/test_credential_verify_simple.sh
index c4fd8c7a3..bcb3f9877 100755
--- a/src/credential/test_credential_verify_simple.sh
+++ b/src/credential/test_credential_verify_simple.sh
@@ -31,17 +31,19 @@ CRED=`$DO_TIMEOUT gnunet-credential --issue --ego=testissuer --subject=$SUBJECT_
31TEST_CREDENTIAL="t1" 31TEST_CREDENTIAL="t1"
32gnunet-namestore -p -z testsubject -a -n $TEST_CREDENTIAL -t CRED -V "$CRED" -e 5m -c test_credential_lookup.conf 32gnunet-namestore -p -z testsubject -a -n $TEST_CREDENTIAL -t CRED -V "$CRED" -e 5m -c test_credential_lookup.conf
33 33
34CREDS=`$DO_TIMEOUT gnunet-credential --collect --issuer=$ISSUER_KEY --attribute=$TEST_ATTR --ego=testsubject -c test_credential_lookup.conf | paste -d, -s`
35
36
34#TODO2 Add -z swich like in gnunet-gns 37#TODO2 Add -z swich like in gnunet-gns
35#RES_CRED=`$DO_TIMEOUT gnunet-credential --verify --issuer=$ISSUER_KEY --attribute="$TEST_ATTR" --subject=$SUBJECT_KEY --credential=$TEST_CREDENTIAL -c test_credential_lookup.conf` 38#RES_CRED=`$DO_TIMEOUT gnunet-credential --verify --issuer=$ISSUER_KEY --attribute="$TEST_ATTR" --subject=$SUBJECT_KEY --credential=$TEST_CREDENTIAL -c test_credential_lookup.conf`
36RES_CRED=`gnunet-credential --verify --issuer=$ISSUER_KEY --attribute=$TEST_ATTR --subject=$SUBJECT_KEY --credential=$TEST_CREDENTIAL -c test_credential_lookup.conf` 39RES_CRED=`gnunet-credential --verify --issuer=$ISSUER_KEY --attribute=$TEST_ATTR --subject=$SUBJECT_KEY --credential="$CREDS" -c test_credential_lookup.conf`
37 40
38#TODO cleanup properly 41#TODO cleanup properly
39gnunet-namestore -z testsubject -d -n $TEST_CREDENTIAL -t CRED -e never -c test_credential_lookup.conf 42gnunet-namestore -z testsubject -d -n $TEST_CREDENTIAL -t CRED -e never -c test_credential_lookup.conf
40gnunet-identity -D testsubject -c test_credential_lookup.conf 43gnunet-identity -D testsubject -c test_credential_lookup.conf
41gnunet-arm -e -c test_credential_lookup.conf 44gnunet-arm -e -c test_credential_lookup.conf
42echo $RES_CRED
43#TODO3 proper test 45#TODO3 proper test
44if [ "$RES_CRED" == "Successful." ] 46if [ "$RES_CRED" != "Failed." ]
45then 47then
46 exit 0 48 exit 0
47else 49else
diff --git a/src/curl/curl.c b/src/curl/curl.c
index 6087cbddb..0a9fc5ffb 100644
--- a/src/curl/curl.c
+++ b/src/curl/curl.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2014, 2015, 2016 GNUnet e.V. 3 Copyright (C) 2014, 2015, 2016, 2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify it under the 5 GNUnet is free software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the Free Software 6 terms of the GNU General Public License as published by the Free Software
@@ -466,6 +466,7 @@ GNUNET_CURL_perform (struct GNUNET_CURL_Context *ctx)
466 CURLINFO_PRIVATE, 466 CURLINFO_PRIVATE,
467 (char **) &job)); 467 (char **) &job));
468 GNUNET_assert (job->ctx == ctx); 468 GNUNET_assert (job->ctx == ctx);
469 response_code = 0;
469 j = download_get_result (&job->db, 470 j = download_get_result (&job->db,
470 job->easy_handle, 471 job->easy_handle,
471 &response_code); 472 &response_code);
diff --git a/src/datacache/plugin_datacache_postgres.c b/src/datacache/plugin_datacache_postgres.c
index 2fe6498a5..2c233c4c2 100644
--- a/src/datacache/plugin_datacache_postgres.c
+++ b/src/datacache/plugin_datacache_postgres.c
@@ -538,6 +538,14 @@ extract_result_cb (void *cls,
538 GNUNET_PQ_result_spec_end 538 GNUNET_PQ_result_spec_end
539 }; 539 };
540 540
541 if (GNUNET_YES !=
542 GNUNET_PQ_extract_result (result,
543 rs,
544 i))
545 {
546 GNUNET_break (0);
547 return;
548 }
541 if (0 != (path_len % sizeof (struct GNUNET_PeerIdentity))) 549 if (0 != (path_len % sizeof (struct GNUNET_PeerIdentity)))
542 { 550 {
543 GNUNET_break (0); 551 GNUNET_break (0);
diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am
index 4a78ea4c7..d60ff62d6 100644
--- a/src/dht/Makefile.am
+++ b/src/dht/Makefile.am
@@ -197,6 +197,7 @@ test_dht_monitor_LDADD = \
197 197
198EXTRA_DIST = \ 198EXTRA_DIST = \
199 $(check_SCRIPTS) \ 199 $(check_SCRIPTS) \
200 gnunet-service-dht_clients.c \
200 test_dht_api_data.conf \ 201 test_dht_api_data.conf \
201 test_dht_api_peer1.conf \ 202 test_dht_api_peer1.conf \
202 test_dht_monitor.conf \ 203 test_dht_monitor.conf \
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index f2b922dc4..829c53aea 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -55,7 +55,6 @@ static struct GNUNET_TRANSPORT_HelloGetHandle *ghh;
55struct GNUNET_TIME_Relative hello_expiration; 55struct GNUNET_TIME_Relative hello_expiration;
56 56
57 57
58/* Code shared between different DHT implementations */
59#include "gnunet-service-dht_clients.c" 58#include "gnunet-service-dht_clients.c"
60 59
61 60
diff --git a/src/dns/dnsparser.c b/src/dns/dnsparser.c
index 30d9245ff..1fe6f595f 100644
--- a/src/dns/dnsparser.c
+++ b/src/dns/dnsparser.c
@@ -1170,7 +1170,10 @@ GNUNET_DNSPARSER_pack (const struct GNUNET_DNSPARSER_Packet *p,
1170 trc = GNUNET_NO; 1170 trc = GNUNET_NO;
1171 for (i=0;i<p->num_queries;i++) 1171 for (i=0;i<p->num_queries;i++)
1172 { 1172 {
1173 ret = GNUNET_DNSPARSER_builder_add_query (tmp, sizeof (tmp), &off, &p->queries[i]); 1173 ret = GNUNET_DNSPARSER_builder_add_query (tmp,
1174 sizeof (tmp),
1175 &off,
1176 &p->queries[i]);
1174 if (GNUNET_SYSERR == ret) 1177 if (GNUNET_SYSERR == ret)
1175 return GNUNET_SYSERR; 1178 return GNUNET_SYSERR;
1176 if (GNUNET_NO == ret) 1179 if (GNUNET_NO == ret)
@@ -1182,7 +1185,10 @@ GNUNET_DNSPARSER_pack (const struct GNUNET_DNSPARSER_Packet *p,
1182 } 1185 }
1183 for (i=0;i<p->num_answers;i++) 1186 for (i=0;i<p->num_answers;i++)
1184 { 1187 {
1185 ret = add_record (tmp, sizeof (tmp), &off, &p->answers[i]); 1188 ret = add_record (tmp,
1189 sizeof (tmp),
1190 &off,
1191 &p->answers[i]);
1186 if (GNUNET_SYSERR == ret) 1192 if (GNUNET_SYSERR == ret)
1187 return GNUNET_SYSERR; 1193 return GNUNET_SYSERR;
1188 if (GNUNET_NO == ret) 1194 if (GNUNET_NO == ret)
@@ -1194,7 +1200,10 @@ GNUNET_DNSPARSER_pack (const struct GNUNET_DNSPARSER_Packet *p,
1194 } 1200 }
1195 for (i=0;i<p->num_authority_records;i++) 1201 for (i=0;i<p->num_authority_records;i++)
1196 { 1202 {
1197 ret = add_record (tmp, sizeof (tmp), &off, &p->authority_records[i]); 1203 ret = add_record (tmp,
1204 sizeof (tmp),
1205 &off,
1206 &p->authority_records[i]);
1198 if (GNUNET_SYSERR == ret) 1207 if (GNUNET_SYSERR == ret)
1199 return GNUNET_SYSERR; 1208 return GNUNET_SYSERR;
1200 if (GNUNET_NO == ret) 1209 if (GNUNET_NO == ret)
@@ -1206,7 +1215,10 @@ GNUNET_DNSPARSER_pack (const struct GNUNET_DNSPARSER_Packet *p,
1206 } 1215 }
1207 for (i=0;i<p->num_additional_records;i++) 1216 for (i=0;i<p->num_additional_records;i++)
1208 { 1217 {
1209 ret = add_record (tmp, sizeof (tmp), &off, &p->additional_records[i]); 1218 ret = add_record (tmp,
1219 sizeof (tmp),
1220 &off,
1221 &p->additional_records[i]);
1210 if (GNUNET_SYSERR == ret) 1222 if (GNUNET_SYSERR == ret)
1211 return GNUNET_SYSERR; 1223 return GNUNET_SYSERR;
1212 if (GNUNET_NO == ret) 1224 if (GNUNET_NO == ret)
@@ -1219,11 +1231,15 @@ GNUNET_DNSPARSER_pack (const struct GNUNET_DNSPARSER_Packet *p,
1219 1231
1220 if (GNUNET_YES == trc) 1232 if (GNUNET_YES == trc)
1221 dns.flags.message_truncated = 1; 1233 dns.flags.message_truncated = 1;
1222 GNUNET_memcpy (tmp, &dns, sizeof (struct GNUNET_TUN_DnsHeader)); 1234 GNUNET_memcpy (tmp,
1235 &dns,
1236 sizeof (struct GNUNET_TUN_DnsHeader));
1223 1237
1224 *buf = GNUNET_malloc (off); 1238 *buf = GNUNET_malloc (off);
1225 *buf_length = off; 1239 *buf_length = off;
1226 GNUNET_memcpy (*buf, tmp, off); 1240 GNUNET_memcpy (*buf,
1241 tmp,
1242 off);
1227 if (GNUNET_YES == trc) 1243 if (GNUNET_YES == trc)
1228 return GNUNET_NO; 1244 return GNUNET_NO;
1229 return GNUNET_OK; 1245 return GNUNET_OK;
diff --git a/src/fs/fs_dirmetascan.c b/src/fs/fs_dirmetascan.c
index 7b9f178fd..e904b9092 100644
--- a/src/fs/fs_dirmetascan.c
+++ b/src/fs/fs_dirmetascan.c
@@ -211,9 +211,9 @@ expand_tree (struct GNUNET_FS_ShareTreeItem *parent,
211 chld->short_filename[slen-1] = '\0'; 211 chld->short_filename[slen-1] = '\0';
212 chld->is_directory = is_directory; 212 chld->is_directory = is_directory;
213 if (NULL != parent) 213 if (NULL != parent)
214 GNUNET_CONTAINER_DLL_insert (parent->children_head, 214 GNUNET_CONTAINER_DLL_insert (parent->children_head,
215 parent->children_tail, 215 parent->children_tail,
216 chld); 216 chld);
217 return chld; 217 return chld;
218} 218}
219 219
@@ -246,6 +246,9 @@ finish_scan (void *cls)
246 * 246 *
247 * @param cls the closure (directory scanner object) 247 * @param cls the closure (directory scanner object)
248 * @param msg message from the helper process 248 * @param msg message from the helper process
249 * @return #GNUNET_OK on success,
250 * #GNUNET_NO to stop further processing (no error)
251 * #GNUNET_SYSERR to stop further processing with error
249 */ 252 */
250static int 253static int
251process_helper_msgs (void *cls, 254process_helper_msgs (void *cls,
@@ -256,7 +259,8 @@ process_helper_msgs (void *cls,
256 size_t left; 259 size_t left;
257 260
258#if 0 261#if 0
259 fprintf (stderr, "DMS parses %u-byte message of type %u\n", 262 fprintf (stderr,
263 "DMS parses %u-byte message of type %u\n",
260 (unsigned int) ntohs (msg->size), 264 (unsigned int) ntohs (msg->size),
261 (unsigned int) ntohs (msg->type)); 265 (unsigned int) ntohs (msg->type));
262#endif 266#endif
@@ -274,11 +278,18 @@ process_helper_msgs (void *cls,
274 filename, GNUNET_NO, 278 filename, GNUNET_NO,
275 GNUNET_FS_DIRSCANNER_FILE_START); 279 GNUNET_FS_DIRSCANNER_FILE_START);
276 if (NULL == ds->toplevel) 280 if (NULL == ds->toplevel)
281 {
277 ds->toplevel = expand_tree (ds->pos, 282 ds->toplevel = expand_tree (ds->pos,
278 filename, GNUNET_NO); 283 filename,
284 GNUNET_NO);
285 }
279 else 286 else
287 {
288 GNUNET_assert (NULL != ds->pos);
280 (void) expand_tree (ds->pos, 289 (void) expand_tree (ds->pos,
281 filename, GNUNET_NO); 290 filename,
291 GNUNET_NO);
292 }
282 return GNUNET_OK; 293 return GNUNET_OK;
283 case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY: 294 case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY:
284 if (filename[left-1] != '\0') 295 if (filename[left-1] != '\0')
@@ -300,7 +311,8 @@ process_helper_msgs (void *cls,
300 filename, GNUNET_YES, 311 filename, GNUNET_YES,
301 GNUNET_FS_DIRSCANNER_FILE_START); 312 GNUNET_FS_DIRSCANNER_FILE_START);
302 ds->pos = expand_tree (ds->pos, 313 ds->pos = expand_tree (ds->pos,
303 filename, GNUNET_YES); 314 filename,
315 GNUNET_YES);
304 if (NULL == ds->toplevel) 316 if (NULL == ds->toplevel)
305 ds->toplevel = ds->pos; 317 ds->toplevel = ds->pos;
306 return GNUNET_OK; 318 return GNUNET_OK;
@@ -357,11 +369,13 @@ process_helper_msgs (void *cls,
357 break; 369 break;
358 } 370 }
359 ds->progress_callback (ds->progress_callback_cls, 371 ds->progress_callback (ds->progress_callback_cls,
360 filename, GNUNET_YES, 372 filename,
373 GNUNET_YES,
361 GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED); 374 GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED);
362 if (0 < left) 375 if (0 < left)
363 { 376 {
364 ds->pos->meta = GNUNET_CONTAINER_meta_data_deserialize (end, left); 377 ds->pos->meta = GNUNET_CONTAINER_meta_data_deserialize (end,
378 left);
365 if (NULL == ds->pos->meta) 379 if (NULL == ds->pos->meta)
366 { 380 {
367 GNUNET_break (0); 381 GNUNET_break (0);
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c
index ce852f2d0..c2a3d4c5d 100644
--- a/src/fs/fs_download.c
+++ b/src/fs/fs_download.c
@@ -37,7 +37,8 @@ static int
37is_recursive_download (struct GNUNET_FS_DownloadContext *dc) 37is_recursive_download (struct GNUNET_FS_DownloadContext *dc)
38{ 38{
39 return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) && 39 return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) &&
40 ( (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (dc->meta)) || 40 ( (GNUNET_YES ==
41 GNUNET_FS_meta_data_test_for_directory (dc->meta)) ||
41 ( (NULL == dc->meta) && 42 ( (NULL == dc->meta) &&
42 ( (NULL == dc->filename) || 43 ( (NULL == dc->filename) ||
43 ( (strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && 44 ( (strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c
index 8c6f5edcf..83aae2fc5 100644
--- a/src/fs/fs_search.c
+++ b/src/fs/fs_search.c
@@ -568,7 +568,13 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc,
568 568
569 /* check if new */ 569 /* check if new */
570 GNUNET_assert (NULL != sc); 570 GNUNET_assert (NULL != sc);
571 GNUNET_FS_uri_to_key (uri, &key); 571 if (GNUNET_OK !=
572 GNUNET_FS_uri_to_key (uri,
573 &key))
574 {
575 GNUNET_break_op (0);
576 return;
577 }
572 if (GNUNET_SYSERR == 578 if (GNUNET_SYSERR ==
573 GNUNET_CONTAINER_multihashmap_get_multiple (ent->results, 579 GNUNET_CONTAINER_multihashmap_get_multiple (ent->results,
574 &key, 580 &key,
@@ -680,8 +686,15 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc,
680 686
681 /* check if new */ 687 /* check if new */
682 GNUNET_assert (NULL != sc); 688 GNUNET_assert (NULL != sc);
683 GNUNET_FS_uri_to_key (uri, &key); 689 if (GNUNET_OK !=
684 GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key, &uri->data.chk.chk.query, 690 GNUNET_FS_uri_to_key (uri,
691 &key))
692 {
693 GNUNET_break (0);
694 return;
695 }
696 GNUNET_CRYPTO_hash_xor (&uri->data.chk.chk.key,
697 &uri->data.chk.chk.query,
685 &key); 698 &key);
686 if (GNUNET_SYSERR == 699 if (GNUNET_SYSERR ==
687 GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, &key, 700 GNUNET_CONTAINER_multihashmap_get_multiple (sc->master_result_map, &key,
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c
index 11968b750..b90c75981 100644
--- a/src/fs/fs_uri.c
+++ b/src/fs/fs_uri.c
@@ -96,8 +96,9 @@
96 * 96 *
97 * @param uri uri to convert to a unique key 97 * @param uri uri to convert to a unique key
98 * @param key where to store the unique key 98 * @param key where to store the unique key
99 * @return #GNUNET_OK on success
99 */ 100 */
100void 101int
101GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, 102GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
102 struct GNUNET_HashCode *key) 103 struct GNUNET_HashCode *key)
103{ 104{
@@ -105,25 +106,35 @@ GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
105 { 106 {
106 case GNUNET_FS_URI_CHK: 107 case GNUNET_FS_URI_CHK:
107 *key = uri->data.chk.chk.query; 108 *key = uri->data.chk.chk.query;
108 return; 109 return GNUNET_OK;
109 case GNUNET_FS_URI_SKS: 110 case GNUNET_FS_URI_SKS:
110 GNUNET_CRYPTO_hash (uri->data.sks.identifier, 111 GNUNET_CRYPTO_hash (uri->data.sks.identifier,
111 strlen (uri->data.sks.identifier), key); 112 strlen (uri->data.sks.identifier),
112 break; 113 key);
114 return GNUNET_OK;
113 case GNUNET_FS_URI_KSK: 115 case GNUNET_FS_URI_KSK:
114 if (uri->data.ksk.keywordCount > 0) 116 if (uri->data.ksk.keywordCount > 0)
117 {
115 GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0], 118 GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0],
116 strlen (uri->data.ksk.keywords[0]), key); 119 strlen (uri->data.ksk.keywords[0]),
120 key);
121 return GNUNET_OK;
122 }
123 else
124 {
125 memset (key, 0, sizeof (struct GNUNET_HashCode));
126 return GNUNET_SYSERR;
127 }
117 break; 128 break;
118 case GNUNET_FS_URI_LOC: 129 case GNUNET_FS_URI_LOC:
119 GNUNET_CRYPTO_hash (&uri->data.loc.fi, 130 GNUNET_CRYPTO_hash (&uri->data.loc.fi,
120 sizeof (struct FileIdentifier) + 131 sizeof (struct FileIdentifier) +
121 sizeof (struct GNUNET_PeerIdentity), 132 sizeof (struct GNUNET_PeerIdentity),
122 key); 133 key);
123 break; 134 return GNUNET_OK;
124 default: 135 default:
125 memset (key, 0, sizeof (struct GNUNET_HashCode)); 136 memset (key, 0, sizeof (struct GNUNET_HashCode));
126 break; 137 return GNUNET_SYSERR;
127 } 138 }
128} 139}
129 140
diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c
index 83c1eb505..27266a18a 100644
--- a/src/fs/gnunet-download.c
+++ b/src/fs/gnunet-download.c
@@ -124,7 +124,8 @@ display_bar (unsigned long long x,
124 * field in the `struct GNUNET_FS_ProgressInfo` 124 * field in the `struct GNUNET_FS_ProgressInfo`
125 */ 125 */
126static void * 126static void *
127progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) 127progress_cb (void *cls,
128 const struct GNUNET_FS_ProgressInfo *info)
128{ 129{
129 char *s; 130 char *s;
130 const char *s2; 131 const char *s2;
@@ -134,7 +135,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
134 { 135 {
135 case GNUNET_FS_STATUS_DOWNLOAD_START: 136 case GNUNET_FS_STATUS_DOWNLOAD_START:
136 if (verbose > 1) 137 if (verbose > 1)
137 FPRINTF (stderr, _("Starting download `%s'.\n"), 138 FPRINTF (stderr,
139 _("Starting download `%s'.\n"),
138 info->value.download.filename); 140 info->value.download.filename);
139 break; 141 break;
140 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: 142 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
@@ -146,8 +148,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
146 == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) 148 == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
147 s2 = _("<unknown time>"); 149 s2 = _("<unknown time>");
148 else 150 else
149 s2 = GNUNET_STRINGS_relative_time_to_string ( 151 s2 = GNUNET_STRINGS_relative_time_to_string (info->value.download.specifics.progress.block_download_duration,
150 info->value.download.specifics.progress.block_download_duration,
151 GNUNET_YES); 152 GNUNET_YES);
152 t = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed * 153 t = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed *
153 1000LL / 154 1000LL /
@@ -157,7 +158,10 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
157 _("Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"), 158 _("Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"),
158 info->value.download.filename, 159 info->value.download.filename,
159 (unsigned long long) info->value.download.completed, 160 (unsigned long long) info->value.download.completed,
160 (unsigned long long) info->value.download.size, s, t, s2); 161 (unsigned long long) info->value.download.size,
162 s,
163 t,
164 s2);
161 GNUNET_free (s); 165 GNUNET_free (s);
162 GNUNET_free (t); 166 GNUNET_free (t);
163 } 167 }
@@ -173,7 +177,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
173 if (0 != isatty (1)) 177 if (0 != isatty (1))
174 fprintf (stdout, "\n"); 178 fprintf (stdout, "\n");
175#else 179#else
176 if (FILE_TYPE_CHAR == GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) 180 if (FILE_TYPE_CHAR ==
181 GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)))
177 fprintf (stdout, "\n"); 182 fprintf (stdout, "\n");
178#endif 183#endif
179 FPRINTF (stderr, _("Error downloading: %s.\n"), 184 FPRINTF (stderr, _("Error downloading: %s.\n"),
@@ -188,10 +193,12 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
188 if (0 != isatty (1)) 193 if (0 != isatty (1))
189 fprintf (stdout, "\n"); 194 fprintf (stdout, "\n");
190#else 195#else
191 if (FILE_TYPE_CHAR == GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) 196 if (FILE_TYPE_CHAR ==
197 GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)))
192 fprintf (stdout, "\n"); 198 fprintf (stdout, "\n");
193#endif 199#endif
194 FPRINTF (stdout, _("Downloading `%s' done (%s/s).\n"), 200 FPRINTF (stdout,
201 _("Downloading `%s' done (%s/s).\n"),
195 info->value.download.filename, s); 202 info->value.download.filename, s);
196 GNUNET_free (s); 203 GNUNET_free (s);
197 if (info->value.download.dc == dc) 204 if (info->value.download.dc == dc)
@@ -205,7 +212,9 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
205 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: 212 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
206 break; 213 break;
207 default: 214 default:
208 FPRINTF (stderr, _("Unexpected status: %d\n"), info->status); 215 FPRINTF (stderr,
216 _("Unexpected status: %d\n"),
217 info->status);
209 break; 218 break;
210 } 219 }
211 return NULL; 220 return NULL;
@@ -221,7 +230,9 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
221 * @param c configuration 230 * @param c configuration
222 */ 231 */
223static void 232static void
224run (void *cls, char *const *args, const char *cfgfile, 233run (void *cls,
234 char *const *args,
235 const char *cfgfile,
225 const struct GNUNET_CONFIGURATION_Handle *c) 236 const struct GNUNET_CONFIGURATION_Handle *c)
226{ 237{
227 struct GNUNET_FS_Uri *uri; 238 struct GNUNET_FS_Uri *uri;
@@ -230,41 +241,55 @@ run (void *cls, char *const *args, const char *cfgfile,
230 241
231 if (NULL == args[0]) 242 if (NULL == args[0])
232 { 243 {
233 FPRINTF (stderr, "%s", _("You need to specify a URI argument.\n")); 244 FPRINTF (stderr,
245 "%s",
246 _("You need to specify a URI argument.\n"));
234 return; 247 return;
235 } 248 }
236 uri = GNUNET_FS_uri_parse (args[0], &emsg); 249 uri = GNUNET_FS_uri_parse (args[0], &emsg);
237 if (NULL == uri) 250 if (NULL == uri)
238 { 251 {
239 FPRINTF (stderr, _("Failed to parse URI: %s\n"), emsg); 252 FPRINTF (stderr,
253 _("Failed to parse URI: %s\n"),
254 emsg);
240 GNUNET_free (emsg); 255 GNUNET_free (emsg);
241 ret = 1; 256 ret = 1;
242 return; 257 return;
243 } 258 }
244 if ((!GNUNET_FS_uri_test_chk (uri)) && (!GNUNET_FS_uri_test_loc (uri))) 259 if ( (! GNUNET_FS_uri_test_chk (uri)) &&
260 (! GNUNET_FS_uri_test_loc (uri)))
245 { 261 {
246 FPRINTF (stderr, "%s", _("Only CHK or LOC URIs supported.\n")); 262 FPRINTF (stderr,
263 "%s",
264 _("Only CHK or LOC URIs supported.\n"));
247 ret = 1; 265 ret = 1;
248 GNUNET_FS_uri_destroy (uri); 266 GNUNET_FS_uri_destroy (uri);
249 return; 267 return;
250 } 268 }
251 if (NULL == filename) 269 if (NULL == filename)
252 { 270 {
253 FPRINTF (stderr, "%s", _("Target filename must be specified.\n")); 271 FPRINTF (stderr,
272 "%s",
273 _("Target filename must be specified.\n"));
254 ret = 1; 274 ret = 1;
255 GNUNET_FS_uri_destroy (uri); 275 GNUNET_FS_uri_destroy (uri);
256 return; 276 return;
257 } 277 }
258 cfg = c; 278 cfg = c;
259 ctx = 279 ctx = GNUNET_FS_start (cfg,
260 GNUNET_FS_start (cfg, "gnunet-download", &progress_cb, NULL, 280 "gnunet-download",
261 GNUNET_FS_FLAGS_NONE, 281 &progress_cb, NULL,
262 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, parallelism, 282 GNUNET_FS_FLAGS_NONE,
263 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, 283 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM,
264 request_parallelism, GNUNET_FS_OPTIONS_END); 284 parallelism,
285 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM,
286 request_parallelism,
287 GNUNET_FS_OPTIONS_END);
265 if (NULL == ctx) 288 if (NULL == ctx)
266 { 289 {
267 FPRINTF (stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); 290 FPRINTF (stderr,
291 _("Could not initialize `%s' subsystem.\n"),
292 "FS");
268 GNUNET_FS_uri_destroy (uri); 293 GNUNET_FS_uri_destroy (uri);
269 ret = 1; 294 ret = 1;
270 return; 295 return;
@@ -274,9 +299,17 @@ run (void *cls, char *const *args, const char *cfgfile,
274 options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE; 299 options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE;
275 if (local_only) 300 if (local_only)
276 options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY; 301 options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY;
277 dc = GNUNET_FS_download_start (ctx, uri, NULL, filename, NULL, 0, 302 dc = GNUNET_FS_download_start (ctx,
303 uri,
304 NULL,
305 filename,
306 NULL,
307 0,
278 GNUNET_FS_uri_chk_get_file_size (uri), 308 GNUNET_FS_uri_chk_get_file_size (uri),
279 anonymity, options, NULL, NULL); 309 anonymity,
310 options,
311 NULL,
312 NULL);
280 GNUNET_FS_uri_destroy (uri); 313 GNUNET_FS_uri_destroy (uri);
281 if (dc == NULL) 314 if (dc == NULL)
282 { 315 {
@@ -301,60 +334,58 @@ main (int argc, char *const *argv)
301{ 334{
302 struct GNUNET_GETOPT_CommandLineOption options[] = { 335 struct GNUNET_GETOPT_CommandLineOption options[] = {
303 GNUNET_GETOPT_option_uint ('a', 336 GNUNET_GETOPT_option_uint ('a',
304 "anonymity", 337 "anonymity",
305 "LEVEL", 338 "LEVEL",
306 gettext_noop ("set the desired LEVEL of receiver-anonymity"), 339 gettext_noop ("set the desired LEVEL of receiver-anonymity"),
307 &anonymity), 340 &anonymity),
308 341
309 GNUNET_GETOPT_option_flag ('D', 342 GNUNET_GETOPT_option_flag ('D',
310 "delete-incomplete", 343 "delete-incomplete",
311 gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"), 344 gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"),
312 &delete_incomplete), 345 &delete_incomplete),
313 346
314 GNUNET_GETOPT_option_flag ('n', 347 GNUNET_GETOPT_option_flag ('n',
315 "no-network", 348 "no-network",
316 gettext_noop ("only search the local peer (no P2P network search)"), 349 gettext_noop ("only search the local peer (no P2P network search)"),
317 &local_only), 350 &local_only),
318
319 GNUNET_GETOPT_option_string ('o', 351 GNUNET_GETOPT_option_string ('o',
320 "output", 352 "output",
321 "FILENAME", 353 "FILENAME",
322 gettext_noop ("write the file to FILENAME"), 354 gettext_noop ("write the file to FILENAME"),
323 &filename), 355 &filename),
324
325 GNUNET_GETOPT_option_uint ('p', 356 GNUNET_GETOPT_option_uint ('p',
326 "parallelism", 357 "parallelism",
327 "DOWNLOADS", 358 "DOWNLOADS",
328 gettext_noop ("set the maximum number of parallel downloads that is allowed"), 359 gettext_noop ("set the maximum number of parallel downloads that is allowed"),
329 &parallelism), 360 &parallelism),
330
331 GNUNET_GETOPT_option_uint ('r', 361 GNUNET_GETOPT_option_uint ('r',
332 "request-parallelism", 362 "request-parallelism",
333 "REQUESTS", 363 "REQUESTS",
334 gettext_noop ("set the maximum number of parallel requests for blocks that is allowed"), 364 gettext_noop ("set the maximum number of parallel requests for blocks that is allowed"),
335 &request_parallelism), 365 &request_parallelism),
336
337 GNUNET_GETOPT_option_flag ('R', 366 GNUNET_GETOPT_option_flag ('R',
338 "recursive", 367 "recursive",
339 gettext_noop ("download a GNUnet directory recursively"), 368 gettext_noop ("download a GNUnet directory recursively"),
340 &do_recursive), 369 &do_recursive),
341
342 GNUNET_GETOPT_option_increment_uint ('V', 370 GNUNET_GETOPT_option_increment_uint ('V',
343 "verbose", 371 "verbose",
344 gettext_noop ("be verbose (print progress information)"), 372 gettext_noop ("be verbose (print progress information)"),
345 &verbose), 373 &verbose),
346
347 GNUNET_GETOPT_OPTION_END 374 GNUNET_GETOPT_OPTION_END
348 }; 375 };
349 376
350 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 377 if (GNUNET_OK !=
378 GNUNET_STRINGS_get_utf8_args (argc, argv,
379 &argc, &argv))
351 return 2; 380 return 2;
352 381
353 ret = (GNUNET_OK == 382 ret = (GNUNET_OK ==
354 GNUNET_PROGRAM_run (argc, argv, "gnunet-download [OPTIONS] URI", 383 GNUNET_PROGRAM_run (argc, argv,
384 "gnunet-download [OPTIONS] URI",
355 gettext_noop 385 gettext_noop
356 ("Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"), 386 ("Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"),
357 options, &run, NULL)) ? ret : 1; 387 options,
388 &run, NULL)) ? ret : 1;
358 GNUNET_free ((void*) argv); 389 GNUNET_free ((void*) argv);
359 return ret; 390 return ret;
360} 391}
diff --git a/src/fs/test_fs_download_persistence.c b/src/fs/test_fs_download_persistence.c
index 76a1ea911..8f27e82af 100644
--- a/src/fs/test_fs_download_persistence.c
+++ b/src/fs/test_fs_download_persistence.c
@@ -179,7 +179,6 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
179 GNUNET_FS_DOWNLOAD_OPTION_NONE, "download", NULL); 179 GNUNET_FS_DOWNLOAD_OPTION_NONE, "download", NULL);
180 break; 180 break;
181 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 181 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
182 consider_restart (event->status);
183 printf ("Download complete, %llu kbps.\n", 182 printf ("Download complete, %llu kbps.\n",
184 (unsigned long long) (FILESIZE * 1000000LL / 183 (unsigned long long) (FILESIZE * 1000000LL /
185 (1 + 184 (1 +
diff --git a/src/fs/test_fs_publish_persistence.c b/src/fs/test_fs_publish_persistence.c
index be9006d42..103ca01b8 100644
--- a/src/fs/test_fs_publish_persistence.c
+++ b/src/fs/test_fs_publish_persistence.c
@@ -134,7 +134,6 @@ progress_cb (void *cls,
134 switch (event->status) 134 switch (event->status)
135 { 135 {
136 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 136 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
137 consider_restart (event->status);
138 ret = event->value.publish.cctx; 137 ret = event->value.publish.cctx;
139 printf ("Publish complete, %llu kbps.\n", 138 printf ("Publish complete, %llu kbps.\n",
140 (unsigned long long) (FILESIZE * 1000000LL / 139 (unsigned long long) (FILESIZE * 1000000LL /
diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c
index 424677d14..2f0de030d 100644
--- a/src/gns/gnunet-dns2gns.c
+++ b/src/gns/gnunet-dns2gns.c
@@ -533,14 +533,21 @@ read_dns4 (void *cls)
533 } 533 }
534 { 534 {
535 char buf[size + 1]; 535 char buf[size + 1];
536 ssize_t sret;
536 537
537 addrlen = sizeof (v4); 538 addrlen = sizeof (v4);
538 GNUNET_break (size == 539 sret = GNUNET_NETWORK_socket_recvfrom (listen_socket4,
539 GNUNET_NETWORK_socket_recvfrom (listen_socket4, 540 buf,
540 buf, 541 size + 1,
541 size + 1, 542 (struct sockaddr *) &v4,
542 (struct sockaddr *) &v4, 543 &addrlen);
543 &addrlen)); 544 if (0 > sret)
545 {
546 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
547 "recvfrom");
548 return;
549 }
550 GNUNET_break (size == (size_t) sret);
544 handle_request (listen_socket4, 551 handle_request (listen_socket4,
545 &v4, 552 &v4,
546 addrlen, 553 addrlen,
@@ -579,16 +586,26 @@ read_dns6 (void *cls)
579 } 586 }
580 { 587 {
581 char buf[size]; 588 char buf[size];
589 ssize_t sret;
582 590
583 addrlen = sizeof (v6); 591 addrlen = sizeof (v6);
584 GNUNET_break (size == 592 sret = GNUNET_NETWORK_socket_recvfrom (listen_socket6,
585 GNUNET_NETWORK_socket_recvfrom (listen_socket6, 593 buf,
586 buf, 594 size,
587 size, 595 (struct sockaddr *) &v6,
588 (struct sockaddr *) &v6, 596 &addrlen);
589 &addrlen)); 597 if (0 > sret)
590 handle_request (listen_socket6, &v6, addrlen, 598 {
591 buf, size); 599 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
600 "recvfrom");
601 return;
602 }
603 GNUNET_break (size == (size_t) sret);
604 handle_request (listen_socket6,
605 &v6,
606 addrlen,
607 buf,
608 size);
592 } 609 }
593} 610}
594 611
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index c58190599..5bf443267 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -327,7 +327,7 @@ struct GNS_ResolverHandle
327 /** 327 /**
328 * ID of a task associated with the resolution process. 328 * ID of a task associated with the resolution process.
329 */ 329 */
330 struct GNUNET_SCHEDULER_Task * task_id; 330 struct GNUNET_SCHEDULER_Task *task_id;
331 331
332 /** 332 /**
333 * The name to resolve 333 * The name to resolve
@@ -658,6 +658,8 @@ resolver_lookup_get_next_label (struct GNS_ResolverHandle *rh)
658 } 658 }
659 rh->protocol = pe->p_proto; 659 rh->protocol = pe->p_proto;
660 rh->service = se->s_port; 660 rh->service = se->s_port;
661 GNUNET_free (proto_name);
662 GNUNET_free (srv_name);
661 } 663 }
662 return ret; 664 return ret;
663} 665}
@@ -806,10 +808,10 @@ recursive_resolution (void *cls);
806 * Begin the resolution process from 'name', starting with 808 * Begin the resolution process from 'name', starting with
807 * the identification of the zone specified by 'name'. 809 * the identification of the zone specified by 'name'.
808 * 810 *
809 * @param rh resolution to perform 811 * @param cls closure with `struct GNS_ResolverHandle *rh`
810 */ 812 */
811static void 813static void
812start_resolver_lookup (struct GNS_ResolverHandle *rh); 814start_resolver_lookup (void *cls);
813 815
814 816
815/** 817/**
@@ -833,6 +835,7 @@ dns_result_parser (void *cls,
833 unsigned int rd_count; 835 unsigned int rd_count;
834 unsigned int i; 836 unsigned int i;
835 837
838 (void) rs;
836 rh->dns_request = NULL; 839 rh->dns_request = NULL;
837 GNUNET_SCHEDULER_cancel (rh->task_id); 840 GNUNET_SCHEDULER_cancel (rh->task_id);
838 rh->task_id = NULL; 841 rh->task_id = NULL;
@@ -857,7 +860,8 @@ dns_result_parser (void *cls,
857 GNUNET_free (rh->name); 860 GNUNET_free (rh->name);
858 rh->name = GNUNET_strdup (p->answers[0].data.hostname); 861 rh->name = GNUNET_strdup (p->answers[0].data.hostname);
859 rh->name_resolution_pos = strlen (rh->name); 862 rh->name_resolution_pos = strlen (rh->name);
860 start_resolver_lookup (rh); 863 rh->task_id = GNUNET_SCHEDULER_add_now (&start_resolver_lookup,
864 rh);
861 GNUNET_DNSPARSER_free_packet (p); 865 GNUNET_DNSPARSER_free_packet (p);
862 return; 866 return;
863 } 867 }
@@ -1017,6 +1021,7 @@ recursive_dns_resolution (struct GNS_ResolverHandle *rh)
1017 struct GNUNET_DNSPARSER_Packet *p; 1021 struct GNUNET_DNSPARSER_Packet *p;
1018 char *dns_request; 1022 char *dns_request;
1019 size_t dns_request_length; 1023 size_t dns_request_length;
1024 int ret;
1020 1025
1021 ac = rh->ac_tail; 1026 ac = rh->ac_tail;
1022 GNUNET_assert (NULL != ac); 1027 GNUNET_assert (NULL != ac);
@@ -1049,11 +1054,16 @@ recursive_dns_resolution (struct GNS_ResolverHandle *rh)
1049 UINT16_MAX); 1054 UINT16_MAX);
1050 p->flags.opcode = GNUNET_TUN_DNS_OPCODE_QUERY; 1055 p->flags.opcode = GNUNET_TUN_DNS_OPCODE_QUERY;
1051 p->flags.recursion_desired = 1; 1056 p->flags.recursion_desired = 1;
1052 if (GNUNET_OK != 1057 ret = GNUNET_DNSPARSER_pack (p,
1053 GNUNET_DNSPARSER_pack (p, 1024, &dns_request, &dns_request_length)) 1058 1024,
1059 &dns_request,
1060 &dns_request_length);
1061 if (GNUNET_OK != ret)
1054 { 1062 {
1055 GNUNET_break (0); 1063 GNUNET_break (0);
1056 rh->proc (rh->proc_cls, 0, NULL); 1064 rh->proc (rh->proc_cls,
1065 0,
1066 NULL);
1057 GNS_resolver_lookup_cancel (rh); 1067 GNS_resolver_lookup_cancel (rh);
1058 } 1068 }
1059 else 1069 else
@@ -1069,7 +1079,8 @@ recursive_dns_resolution (struct GNS_ResolverHandle *rh)
1069 &fail_resolution, 1079 &fail_resolution,
1070 rh); 1080 rh);
1071 } 1081 }
1072 GNUNET_free (dns_request); 1082 if (GNUNET_SYSERR != ret)
1083 GNUNET_free (dns_request);
1073 GNUNET_DNSPARSER_free_packet (p); 1084 GNUNET_DNSPARSER_free_packet (p);
1074} 1085}
1075 1086
@@ -1132,7 +1143,8 @@ handle_gns_cname_result (struct GNS_ResolverHandle *rh,
1132 GNUNET_free (rh->name); 1143 GNUNET_free (rh->name);
1133 rh->name = GNUNET_strdup (cname); 1144 rh->name = GNUNET_strdup (cname);
1134 rh->name_resolution_pos = strlen (rh->name); 1145 rh->name_resolution_pos = strlen (rh->name);
1135 start_resolver_lookup (rh); 1146 rh->task_id = GNUNET_SCHEDULER_add_now (&start_resolver_lookup,
1147 rh);
1136} 1148}
1137 1149
1138 1150
@@ -1460,10 +1472,10 @@ handle_gns_resolution_result (void *cls,
1460 vpn_ctx->rd_data = GNUNET_malloc (vpn_ctx->rd_data_size); 1472 vpn_ctx->rd_data = GNUNET_malloc (vpn_ctx->rd_data_size);
1461 vpn_ctx->rd_count = rd_count; 1473 vpn_ctx->rd_count = rd_count;
1462 GNUNET_assert (vpn_ctx->rd_data_size == 1474 GNUNET_assert (vpn_ctx->rd_data_size ==
1463 GNUNET_GNSRECORD_records_serialize (rd_count, 1475 (size_t) GNUNET_GNSRECORD_records_serialize (rd_count,
1464 rd, 1476 rd,
1465 vpn_ctx->rd_data_size, 1477 vpn_ctx->rd_data_size,
1466 vpn_ctx->rd_data)); 1478 vpn_ctx->rd_data));
1467 vpn_ctx->vpn_request = GNUNET_VPN_redirect_to_peer (vpn_handle, 1479 vpn_ctx->vpn_request = GNUNET_VPN_redirect_to_peer (vpn_handle,
1468 af, 1480 af,
1469 ntohs (vpn->proto), 1481 ntohs (vpn->proto),
@@ -1830,7 +1842,9 @@ handle_gns_resolution_result (void *cls,
1830 g2dc->rh->options = GNUNET_GNS_LO_DEFAULT; 1842 g2dc->rh->options = GNUNET_GNS_LO_DEFAULT;
1831 g2dc->rh->loop_limiter = rh->loop_limiter + 1; 1843 g2dc->rh->loop_limiter = rh->loop_limiter + 1;
1832 rh->g2dc = g2dc; 1844 rh->g2dc = g2dc;
1833 start_resolver_lookup (g2dc->rh); 1845 g2dc->rh->task_id
1846 = GNUNET_SCHEDULER_add_now (&start_resolver_lookup,
1847 g2dc->rh);
1834 return; 1848 return;
1835 } 1849 }
1836 case GNUNET_DNSPARSER_TYPE_CNAME: 1850 case GNUNET_DNSPARSER_TYPE_CNAME:
@@ -1884,7 +1898,7 @@ namecache_cache_continuation (void *cls,
1884 struct CacheOps *co = cls; 1898 struct CacheOps *co = cls;
1885 1899
1886 co->namecache_qe_cache = NULL; 1900 co->namecache_qe_cache = NULL;
1887 if (NULL != emsg) 1901 if (GNUNET_OK != success)
1888 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1902 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1889 _("Failed to cache GNS resolution: %s\n"), 1903 _("Failed to cache GNS resolution: %s\n"),
1890 emsg); 1904 emsg);
@@ -1921,13 +1935,21 @@ handle_dht_response (void *cls,
1921 const struct GNUNET_PeerIdentity *put_path, 1935 const struct GNUNET_PeerIdentity *put_path,
1922 unsigned int put_path_length, 1936 unsigned int put_path_length,
1923 enum GNUNET_BLOCK_Type type, 1937 enum GNUNET_BLOCK_Type type,
1924 size_t size, const void *data) 1938 size_t size,
1939 const void *data)
1925{ 1940{
1926 struct GNS_ResolverHandle *rh = cls; 1941 struct GNS_ResolverHandle *rh = cls;
1927 struct AuthorityChain *ac = rh->ac_tail; 1942 struct AuthorityChain *ac = rh->ac_tail;
1928 const struct GNUNET_GNSRECORD_Block *block; 1943 const struct GNUNET_GNSRECORD_Block *block;
1929 struct CacheOps *co; 1944 struct CacheOps *co;
1930 1945
1946 (void) exp;
1947 (void) key;
1948 (void) get_path;
1949 (void) get_path_length;
1950 (void) put_path;
1951 (void) put_path_length;
1952 (void) type;
1931 GNUNET_DHT_get_stop (rh->get_handle); 1953 GNUNET_DHT_get_stop (rh->get_handle);
1932 rh->get_handle = NULL; 1954 rh->get_handle = NULL;
1933 GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node); 1955 GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
@@ -2230,16 +2252,18 @@ recursive_resolution (void *cls)
2230 * Begin the resolution process from 'name', starting with 2252 * Begin the resolution process from 'name', starting with
2231 * the identification of the zone specified by 'name'. 2253 * the identification of the zone specified by 'name'.
2232 * 2254 *
2233 * @param rh resolution to perform 2255 * @param cls the `struct GNS_ResolverHandle`
2234 */ 2256 */
2235static void 2257static void
2236start_resolver_lookup (struct GNS_ResolverHandle *rh) 2258start_resolver_lookup (void *cls)
2237{ 2259{
2260 struct GNS_ResolverHandle *rh = cls;
2238 struct AuthorityChain *ac; 2261 struct AuthorityChain *ac;
2239 char *y; 2262 char *y;
2240 struct in_addr v4; 2263 struct in_addr v4;
2241 struct in6_addr v6; 2264 struct in6_addr v6;
2242 2265
2266 rh->task_id = NULL;
2243 if (1 == inet_pton (AF_INET, 2267 if (1 == inet_pton (AF_INET,
2244 rh->name, 2268 rh->name,
2245 &v4)) 2269 &v4))
@@ -2360,7 +2384,8 @@ GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
2360 uint32_t record_type, 2384 uint32_t record_type,
2361 const char *name, 2385 const char *name,
2362 enum GNUNET_GNS_LocalOptions options, 2386 enum GNUNET_GNS_LocalOptions options,
2363 GNS_ResultProcessor proc, void *proc_cls) 2387 GNS_ResultProcessor proc,
2388 void *proc_cls)
2364{ 2389{
2365 struct GNS_ResolverHandle *rh; 2390 struct GNS_ResolverHandle *rh;
2366 2391
@@ -2378,7 +2403,8 @@ GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
2378 rh->record_type = record_type; 2403 rh->record_type = record_type;
2379 rh->name = GNUNET_strdup (name); 2404 rh->name = GNUNET_strdup (name);
2380 rh->name_resolution_pos = strlen (name); 2405 rh->name_resolution_pos = strlen (name);
2381 start_resolver_lookup (rh); 2406 rh->task_id = GNUNET_SCHEDULER_add_now (&start_resolver_lookup,
2407 rh);
2382 return rh; 2408 return rh;
2383} 2409}
2384 2410
diff --git a/src/hello/hello.c b/src/hello/hello.c
index 27580275f..690a0961a 100644
--- a/src/hello/hello.c
+++ b/src/hello/hello.c
@@ -271,7 +271,10 @@ GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg,
271 msize = GNUNET_HELLO_size (msg); 271 msize = GNUNET_HELLO_size (msg);
272 if ((msize < sizeof (struct GNUNET_HELLO_Message)) || 272 if ((msize < sizeof (struct GNUNET_HELLO_Message)) ||
273 (ntohs (msg->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) 273 (ntohs (msg->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
274 {
275 GNUNET_break_op (0);
274 return NULL; 276 return NULL;
277 }
275 ret = NULL; 278 ret = NULL;
276 if (return_modified) 279 if (return_modified)
277 { 280 {
@@ -285,6 +288,10 @@ GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg,
285 wpos = 0; 288 wpos = 0;
286 woff = (NULL != ret) ? (char *) &ret[1] : NULL; 289 woff = (NULL != ret) ? (char *) &ret[1] : NULL;
287 address.peer.public_key = msg->publicKey; 290 address.peer.public_key = msg->publicKey;
291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
292 "HELLO has %u bytes of address data\n",
293 (unsigned int) insize);
294
288 while (insize > 0) 295 while (insize > 0)
289 { 296 {
290 esize = get_hello_address_size (inptr, 297 esize = get_hello_address_size (inptr,
diff --git a/src/identity-attribute/identity_attribute.c b/src/identity-attribute/identity_attribute.c
index a8aae6ced..cf50d058e 100644
--- a/src/identity-attribute/identity_attribute.c
+++ b/src/identity-attribute/identity_attribute.c
@@ -19,7 +19,7 @@
19 */ 19 */
20 20
21/** 21/**
22 * @file identity-provider/identity_attribute.c 22 * @file identity-attribute/identity_attribute.c
23 * @brief helper library to manage identity attributes 23 * @brief helper library to manage identity attributes
24 * @author Martin Schanzenbach 24 * @author Martin Schanzenbach
25 */ 25 */
@@ -206,7 +206,7 @@ GNUNET_IDENTITY_ATTRIBUTE_value_to_string (uint32_t type,
206/** 206/**
207 * Create a new attribute. 207 * Create a new attribute.
208 * 208 *
209 * @param name the attribute name 209 * @param attr_name the attribute name
210 * @param type the attribute type 210 * @param type the attribute type
211 * @param data the attribute value 211 * @param data the attribute value
212 * @param data_size the attribute value size 212 * @param data_size the attribute value size
@@ -214,7 +214,7 @@ GNUNET_IDENTITY_ATTRIBUTE_value_to_string (uint32_t type,
214 */ 214 */
215struct GNUNET_IDENTITY_ATTRIBUTE_Claim * 215struct GNUNET_IDENTITY_ATTRIBUTE_Claim *
216GNUNET_IDENTITY_ATTRIBUTE_claim_new (const char* attr_name, 216GNUNET_IDENTITY_ATTRIBUTE_claim_new (const char* attr_name,
217 uint32_t attr_type, 217 uint32_t type,
218 const void* data, 218 const void* data,
219 size_t data_size) 219 size_t data_size)
220{ 220{
@@ -224,7 +224,7 @@ GNUNET_IDENTITY_ATTRIBUTE_claim_new (const char* attr_name,
224 attr = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_ATTRIBUTE_Claim) + 224 attr = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_ATTRIBUTE_Claim) +
225 strlen (attr_name) + 1 + 225 strlen (attr_name) + 1 +
226 data_size); 226 data_size);
227 attr->type = attr_type; 227 attr->type = type;
228 attr->data_size = data_size; 228 attr->data_size = data_size;
229 attr->version = 0; 229 attr->version = 0;
230 write_ptr = (char*)&attr[1]; 230 write_ptr = (char*)&attr[1];
diff --git a/src/identity-attribute/identity_attribute.h b/src/identity-attribute/identity_attribute.h
index 046321807..8dfc17521 100644
--- a/src/identity-attribute/identity_attribute.h
+++ b/src/identity-attribute/identity_attribute.h
@@ -19,8 +19,8 @@
19 */ 19 */
20/** 20/**
21 * @author Martin Schanzenbach 21 * @author Martin Schanzenbach
22 * @file identity-provider/identity_attribute.h 22 * @file identity-attribute/identity_attribute.h
23 * @brief GNUnet Identity Provider library 23 * @brief GNUnet Identity attributes
24 * 24 *
25 */ 25 */
26#ifndef IDENTITY_ATTRIBUTE_H 26#ifndef IDENTITY_ATTRIBUTE_H
diff --git a/src/identity-attribute/plugin_identity_attribute_gnuid.c b/src/identity-attribute/plugin_identity_attribute_gnuid.c
index 0ff44d199..006b45ea2 100644
--- a/src/identity-attribute/plugin_identity_attribute_gnuid.c
+++ b/src/identity-attribute/plugin_identity_attribute_gnuid.c
@@ -19,7 +19,7 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file identity-provider/plugin_identity_attribute_gnuid.c 22 * @file identity-attribute/plugin_identity_attribute_gnuid.c
23 * @brief identity attribute plugin to provide the API for fundamental 23 * @brief identity attribute plugin to provide the API for fundamental
24 * attribute types. 24 * attribute types.
25 * 25 *
diff --git a/src/identity-provider/Makefile.am b/src/identity-provider/Makefile.am
index 5c5ddaa57..adf6af3b3 100644
--- a/src/identity-provider/Makefile.am
+++ b/src/identity-provider/Makefile.am
@@ -70,6 +70,7 @@ gnunet_service_identity_provider_LDADD = \
70 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 70 $(top_builddir)/src/namestore/libgnunetnamestore.la \
71 $(top_builddir)/src/identity/libgnunetidentity.la \ 71 $(top_builddir)/src/identity/libgnunetidentity.la \
72 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 72 $(top_builddir)/src/statistics/libgnunetstatistics.la \
73 $(top_builddir)/src/abe/libgnunetabe.la \
73 $(top_builddir)/src/credential/libgnunetcredential.la \ 74 $(top_builddir)/src/credential/libgnunetcredential.la \
74 $(top_builddir)/src/identity-attribute/libgnunetidentityattribute.la \ 75 $(top_builddir)/src/identity-attribute/libgnunetidentityattribute.la \
75 libgnunetidentityprovider.la \ 76 libgnunetidentityprovider.la \
diff --git a/src/identity-provider/gnunet-idp.c b/src/identity-provider/gnunet-idp.c
index 62f07842b..995dd5775 100644
--- a/src/identity-provider/gnunet-idp.c
+++ b/src/identity-provider/gnunet-idp.c
@@ -432,8 +432,7 @@ main(int argc, char *const argv[])
432 &type_str), 432 &type_str),
433 GNUNET_GETOPT_OPTION_END 433 GNUNET_GETOPT_OPTION_END
434 }; 434 };
435 GNUNET_PROGRAM_run (argc, argv, "ct", 435 return (GNUNET_OK == GNUNET_PROGRAM_run (argc, argv, "ct",
436 "ct", options, 436 "ct", options,
437 &run, NULL); 437 &run, NULL));
438 return ret;
439} 438}
diff --git a/src/identity-provider/gnunet-service-identity-provider.c b/src/identity-provider/gnunet-service-identity-provider.c
index a5c178aa5..265719d58 100644
--- a/src/identity-provider/gnunet-service-identity-provider.c
+++ b/src/identity-provider/gnunet-service-identity-provider.c
@@ -30,6 +30,7 @@
30#include "gnunet_identity_service.h" 30#include "gnunet_identity_service.h"
31#include "gnunet_gnsrecord_lib.h" 31#include "gnunet_gnsrecord_lib.h"
32#include "gnunet_namestore_service.h" 32#include "gnunet_namestore_service.h"
33#include "gnunet_abe_lib.h"
33#include "gnunet_credential_service.h" 34#include "gnunet_credential_service.h"
34#include "gnunet_statistics_service.h" 35#include "gnunet_statistics_service.h"
35#include "gnunet_gns_service.h" 36#include "gnunet_gns_service.h"
@@ -94,11 +95,6 @@ static struct GNUNET_GNS_Handle *gns_handle;
94static struct GNUNET_CREDENTIAL_Handle *credential_handle; 95static struct GNUNET_CREDENTIAL_Handle *credential_handle;
95 96
96/** 97/**
97 * Stats handle
98 */
99static struct GNUNET_STATISTICS_Handle *stats_handle;
100
101/**
102 * Namestore qe 98 * Namestore qe
103 */ 99 */
104static struct GNUNET_NAMESTORE_QueueEntry *ns_qe; 100static struct GNUNET_NAMESTORE_QueueEntry *ns_qe;
@@ -205,7 +201,7 @@ struct TicketIteration
205 */ 201 */
206typedef void 202typedef void
207(*AbeBootstrapResult) (void *cls, 203(*AbeBootstrapResult) (void *cls,
208 struct GNUNET_CRYPTO_AbeMasterKey *abe_key); 204 struct GNUNET_ABE_AbeMasterKey *abe_key);
209 205
210 206
211struct AbeBootstrapHandle 207struct AbeBootstrapHandle
@@ -233,7 +229,7 @@ struct AbeBootstrapHandle
233 /** 229 /**
234 * The issuer egos ABE master key 230 * The issuer egos ABE master key
235 */ 231 */
236 struct GNUNET_CRYPTO_AbeMasterKey *abe_key; 232 struct GNUNET_ABE_AbeMasterKey *abe_key;
237}; 233};
238 234
239/** 235/**
@@ -264,7 +260,7 @@ struct AttributeIterator
264 /** 260 /**
265 * The issuer egos ABE master key 261 * The issuer egos ABE master key
266 */ 262 */
267 struct GNUNET_CRYPTO_AbeMasterKey *abe_key; 263 struct GNUNET_ABE_AbeMasterKey *abe_key;
268 264
269 /** 265 /**
270 * Namestore iterator 266 * Namestore iterator
@@ -355,7 +351,7 @@ struct AttributeStoreHandle
355 /** 351 /**
356 * The issuer egos ABE master key 352 * The issuer egos ABE master key
357 */ 353 */
358 struct GNUNET_CRYPTO_AbeMasterKey *abe_key; 354 struct GNUNET_ABE_AbeMasterKey *abe_key;
359 355
360 /** 356 /**
361 * QueueEntry 357 * QueueEntry
@@ -423,7 +419,7 @@ struct ConsumeTicketHandle
423 /** 419 /**
424 * The ABE key 420 * The ABE key
425 */ 421 */
426 struct GNUNET_CRYPTO_AbeKey *key; 422 struct GNUNET_ABE_AbeKey *key;
427 423
428 /** 424 /**
429 * Attributes 425 * Attributes
@@ -520,7 +516,7 @@ struct TicketRevocationHandle
520 /** 516 /**
521 * The ABE master key 517 * The ABE master key
522 */ 518 */
523 struct GNUNET_CRYPTO_AbeMasterKey *abe_key; 519 struct GNUNET_ABE_AbeMasterKey *abe_key;
524 520
525 /** 521 /**
526 * Offset 522 * Offset
@@ -634,12 +630,8 @@ cleanup()
634 GNUNET_NAMESTORE_cancel (ns_qe); 630 GNUNET_NAMESTORE_cancel (ns_qe);
635 if (NULL != ns_handle) 631 if (NULL != ns_handle)
636 GNUNET_NAMESTORE_disconnect (ns_handle); 632 GNUNET_NAMESTORE_disconnect (ns_handle);
637 if (NULL != stats_handle) 633 GNUNET_free_non_null (token);
638 GNUNET_STATISTICS_destroy (stats_handle, GNUNET_NO); 634 GNUNET_free_non_null (label);
639 if (NULL != token)
640 GNUNET_free (token);
641 if (NULL != label)
642 GNUNET_free (label);
643 635
644} 636}
645 637
@@ -647,7 +639,6 @@ cleanup()
647 * Shutdown task 639 * Shutdown task
648 * 640 *
649 * @param cls NULL 641 * @param cls NULL
650 * @param tc task context
651 */ 642 */
652static void 643static void
653do_shutdown (void *cls) 644do_shutdown (void *cls)
@@ -690,7 +681,7 @@ bootstrap_store_task (void *cls)
690 struct GNUNET_GNSRECORD_Data rd[1]; 681 struct GNUNET_GNSRECORD_Data rd[1];
691 char *key; 682 char *key;
692 683
693 rd[0].data_size = GNUNET_CRYPTO_cpabe_serialize_master_key (abh->abe_key, 684 rd[0].data_size = GNUNET_ABE_cpabe_serialize_master_key (abh->abe_key,
694 (void**)&key); 685 (void**)&key);
695 rd[0].data = key; 686 rd[0].data = key;
696 rd[0].record_type = GNUNET_GNSRECORD_TYPE_ABE_MASTER; 687 rd[0].record_type = GNUNET_GNSRECORD_TYPE_ABE_MASTER;
@@ -713,7 +704,6 @@ static void
713bootstrap_abe_error (void *cls) 704bootstrap_abe_error (void *cls)
714{ 705{
715 struct AbeBootstrapHandle *abh = cls; 706 struct AbeBootstrapHandle *abh = cls;
716 GNUNET_free (abh);
717 abh->proc (abh->proc_cls, NULL); 707 abh->proc (abh->proc_cls, NULL);
718 GNUNET_free (abh); 708 GNUNET_free (abh);
719} 709}
@@ -730,13 +720,12 @@ bootstrap_abe_result (void *cls,
730 const struct GNUNET_GNSRECORD_Data *rd) 720 const struct GNUNET_GNSRECORD_Data *rd)
731{ 721{
732 struct AbeBootstrapHandle *abh = cls; 722 struct AbeBootstrapHandle *abh = cls;
733 struct GNUNET_CRYPTO_AbeMasterKey *abe_key; 723 struct GNUNET_ABE_AbeMasterKey *abe_key;
734 int i;
735 724
736 for (i=0;i<rd_count;i++) { 725 for (uint32_t i=0;i<rd_count;i++) {
737 if (GNUNET_GNSRECORD_TYPE_ABE_MASTER != rd[i].record_type) 726 if (GNUNET_GNSRECORD_TYPE_ABE_MASTER != rd[i].record_type)
738 continue; 727 continue;
739 abe_key = GNUNET_CRYPTO_cpabe_deserialize_master_key (rd[i].data, 728 abe_key = GNUNET_ABE_cpabe_deserialize_master_key (rd[i].data,
740 rd[i].data_size); 729 rd[i].data_size);
741 abh->proc (abh->proc_cls, abe_key); 730 abh->proc (abh->proc_cls, abe_key);
742 GNUNET_free (abh); 731 GNUNET_free (abh);
@@ -744,7 +733,7 @@ bootstrap_abe_result (void *cls,
744 } 733 }
745 734
746 //No ABE master found, bootstrapping... 735 //No ABE master found, bootstrapping...
747 abh->abe_key = GNUNET_CRYPTO_cpabe_create_master_key (); 736 abh->abe_key = GNUNET_ABE_cpabe_create_master_key ();
748 GNUNET_SCHEDULER_add_now (&bootstrap_store_task, abh); 737 GNUNET_SCHEDULER_add_now (&bootstrap_store_task, abh);
749} 738}
750 739
@@ -767,7 +756,7 @@ bootstrap_abe (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
767 abh->identity = *identity; 756 abh->identity = *identity;
768 if (GNUNET_YES == recreate) 757 if (GNUNET_YES == recreate)
769 { 758 {
770 abh->abe_key = GNUNET_CRYPTO_cpabe_create_master_key (); 759 abh->abe_key = GNUNET_ABE_cpabe_create_master_key ();
771 GNUNET_SCHEDULER_add_now (&bootstrap_store_task, abh); 760 GNUNET_SCHEDULER_add_now (&bootstrap_store_task, abh);
772 } else { 761 } else {
773 abh->ns_qe = GNUNET_NAMESTORE_records_lookup (ns_handle, 762 abh->ns_qe = GNUNET_NAMESTORE_records_lookup (ns_handle,
@@ -874,7 +863,7 @@ store_ticket_issue_cont (void *cls,
874int 863int
875serialize_abe_keyinfo2 (const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, 864serialize_abe_keyinfo2 (const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket,
876 const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs, 865 const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs,
877 const struct GNUNET_CRYPTO_AbeKey *rp_key, 866 const struct GNUNET_ABE_AbeKey *rp_key,
878 struct GNUNET_CRYPTO_EcdhePrivateKey **ecdh_privkey, 867 struct GNUNET_CRYPTO_EcdhePrivateKey **ecdh_privkey,
879 char **result) 868 char **result)
880{ 869{
@@ -892,7 +881,7 @@ serialize_abe_keyinfo2 (const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket,
892 struct GNUNET_HashCode new_key_hash; 881 struct GNUNET_HashCode new_key_hash;
893 ssize_t enc_size; 882 ssize_t enc_size;
894 883
895 size = GNUNET_CRYPTO_cpabe_serialize_key (rp_key, 884 size = GNUNET_ABE_cpabe_serialize_key (rp_key,
896 (void**)&serialized_key); 885 (void**)&serialized_key);
897 attrs_str_len = 0; 886 attrs_str_len = 0;
898 for (le = attrs->list_head; NULL != le; le = le->next) { 887 for (le = attrs->list_head; NULL != le; le = le->next) {
@@ -951,19 +940,19 @@ serialize_abe_keyinfo2 (const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket,
951 940
952static void 941static void
953issue_ticket_after_abe_bootstrap (void *cls, 942issue_ticket_after_abe_bootstrap (void *cls,
954 struct GNUNET_CRYPTO_AbeMasterKey *abe_key) 943 struct GNUNET_ABE_AbeMasterKey *abe_key)
955{ 944{
956 struct TicketIssueHandle *ih = cls; 945 struct TicketIssueHandle *ih = cls;
957 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; 946 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le;
958 struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey; 947 struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey;
959 struct GNUNET_GNSRECORD_Data code_record[1]; 948 struct GNUNET_GNSRECORD_Data code_record[1];
960 struct GNUNET_CRYPTO_AbeKey *rp_key; 949 struct GNUNET_ABE_AbeKey *rp_key;
961 char *code_record_data; 950 char *code_record_data;
962 char **attrs; 951 char **attrs;
963 char *label; 952 char *label;
964 char *policy; 953 char *policy;
965 int attrs_len; 954 int attrs_len;
966 int i; 955 uint32_t i;
967 size_t code_record_len; 956 size_t code_record_len;
968 957
969 //Create new ABE key for RP 958 //Create new ABE key for RP
@@ -983,7 +972,7 @@ issue_ticket_after_abe_bootstrap (void *cls,
983 i++; 972 i++;
984 } 973 }
985 attrs[i] = NULL; 974 attrs[i] = NULL;
986 rp_key = GNUNET_CRYPTO_cpabe_create_key (abe_key, 975 rp_key = GNUNET_ABE_cpabe_create_key (abe_key,
987 attrs); 976 attrs);
988 977
989 //TODO review this wireformat 978 //TODO review this wireformat
@@ -1014,19 +1003,12 @@ issue_ticket_after_abe_bootstrap (void *cls,
1014 GNUNET_free (label); 1003 GNUNET_free (label);
1015 GNUNET_free (attrs); 1004 GNUNET_free (attrs);
1016 GNUNET_free (code_record_data); 1005 GNUNET_free (code_record_data);
1017 GNUNET_CRYPTO_cpabe_delete_key (rp_key, 1006 GNUNET_ABE_cpabe_delete_key (rp_key,
1018 GNUNET_YES); 1007 GNUNET_YES);
1019 GNUNET_CRYPTO_cpabe_delete_master_key (abe_key); 1008 GNUNET_ABE_cpabe_delete_master_key (abe_key);
1020} 1009}
1021 1010
1022 1011
1023/**
1024 * Checks a ticket issue message
1025 *
1026 * @param cls client sending the message
1027 * @param im message of type `struct TicketIssueMessage`
1028 * @return #GNUNET_OK if @a im is well-formed
1029 */
1030static int 1012static int
1031check_issue_ticket_message(void *cls, 1013check_issue_ticket_message(void *cls,
1032 const struct IssueTicketMessage *im) 1014 const struct IssueTicketMessage *im)
@@ -1043,14 +1025,6 @@ check_issue_ticket_message(void *cls,
1043} 1025}
1044 1026
1045 1027
1046/**
1047 *
1048 * Handler for ticket issue message
1049 *
1050 * @param cls unused
1051 * @param client who sent the message
1052 * @param message the message
1053 */
1054static void 1028static void
1055handle_issue_ticket_message (void *cls, 1029handle_issue_ticket_message (void *cls,
1056 const struct IssueTicketMessage *im) 1030 const struct IssueTicketMessage *im)
@@ -1082,26 +1056,31 @@ handle_issue_ticket_message (void *cls,
1082 1056
1083/** 1057/**
1084 * Cleanup revoke handle 1058 * Cleanup revoke handle
1059 *
1060 * @param rh the ticket revocation handle
1085 */ 1061 */
1086static void 1062static void
1087cleanup_revoke_ticket_handle (struct TicketRevocationHandle *handle) 1063cleanup_revoke_ticket_handle (struct TicketRevocationHandle *rh)
1088{ 1064{
1089 if (NULL != handle->attrs) 1065 if (NULL != rh->attrs)
1090 GNUNET_IDENTITY_ATTRIBUTE_list_destroy (handle->attrs); 1066 GNUNET_IDENTITY_ATTRIBUTE_list_destroy (rh->attrs);
1091 if (NULL != handle->rvk_attrs) 1067 if (NULL != rh->rvk_attrs)
1092 GNUNET_IDENTITY_ATTRIBUTE_list_destroy (handle->rvk_attrs); 1068 GNUNET_IDENTITY_ATTRIBUTE_list_destroy (rh->rvk_attrs);
1093 if (NULL != handle->abe_key) 1069 if (NULL != rh->abe_key)
1094 GNUNET_CRYPTO_cpabe_delete_master_key (handle->abe_key); 1070 GNUNET_ABE_cpabe_delete_master_key (rh->abe_key);
1095 if (NULL != handle->ns_qe) 1071 if (NULL != rh->ns_qe)
1096 GNUNET_NAMESTORE_cancel (handle->ns_qe); 1072 GNUNET_NAMESTORE_cancel (rh->ns_qe);
1097 if (NULL != handle->ns_it) 1073 if (NULL != rh->ns_it)
1098 GNUNET_NAMESTORE_zone_iteration_stop (handle->ns_it); 1074 GNUNET_NAMESTORE_zone_iteration_stop (rh->ns_it);
1099 GNUNET_free (handle); 1075 GNUNET_free (rh);
1100} 1076}
1101 1077
1102 1078
1103/** 1079/**
1104 * Send revocation result 1080 * Send revocation result
1081 *
1082 * @param rh ticket revocation handle
1083 * @param success GNUNET_OK if successful result
1105 */ 1084 */
1106static void 1085static void
1107send_revocation_finished (struct TicketRevocationHandle *rh, 1086send_revocation_finished (struct TicketRevocationHandle *rh,
@@ -1183,13 +1162,13 @@ ticket_reissue_proc (void *cls,
1183 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le_rollover; 1162 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le_rollover;
1184 struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey; 1163 struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey;
1185 struct GNUNET_GNSRECORD_Data code_record[1]; 1164 struct GNUNET_GNSRECORD_Data code_record[1];
1186 struct GNUNET_CRYPTO_AbeKey *rp_key; 1165 struct GNUNET_ABE_AbeKey *rp_key;
1187 char *code_record_data; 1166 char *code_record_data;
1188 char **attr_arr; 1167 char **attr_arr;
1189 char *label; 1168 char *label;
1190 char *policy; 1169 char *policy;
1191 int attrs_len; 1170 int attrs_len;
1192 int i; 1171 uint32_t i;
1193 int reissue_ticket; 1172 int reissue_ticket;
1194 size_t code_record_len; 1173 size_t code_record_len;
1195 1174
@@ -1263,7 +1242,7 @@ ticket_reissue_proc (void *cls,
1263 i++; 1242 i++;
1264 } 1243 }
1265 attr_arr[i] = NULL; 1244 attr_arr[i] = NULL;
1266 rp_key = GNUNET_CRYPTO_cpabe_create_key (rh->abe_key, 1245 rp_key = GNUNET_ABE_cpabe_create_key (rh->abe_key,
1267 attr_arr); 1246 attr_arr);
1268 1247
1269 //TODO review this wireformat 1248 //TODO review this wireformat
@@ -1294,7 +1273,7 @@ ticket_reissue_proc (void *cls,
1294 GNUNET_free (label); 1273 GNUNET_free (label);
1295 GNUNET_free (attr_arr); 1274 GNUNET_free (attr_arr);
1296 GNUNET_free (code_record_data); 1275 GNUNET_free (code_record_data);
1297 GNUNET_CRYPTO_cpabe_delete_key (rp_key, GNUNET_YES); 1276 GNUNET_ABE_cpabe_delete_key (rp_key, GNUNET_YES);
1298} 1277}
1299 1278
1300 1279
@@ -1362,13 +1341,24 @@ reenc_next_attribute (struct TicketRevocationHandle *rh)
1362 /** 1341 /**
1363 * Encrypt the attribute value and store in namestore 1342 * Encrypt the attribute value and store in namestore
1364 */ 1343 */
1365 enc_size = GNUNET_CRYPTO_cpabe_encrypt (buf, 1344 enc_size = GNUNET_ABE_cpabe_encrypt (buf,
1366 buf_size, 1345 buf_size,
1367 policy, //Policy 1346 policy, //Policy
1368 rh->abe_key, 1347 rh->abe_key,
1369 (void**)&enc_buf); 1348 (void**)&enc_buf);
1370 GNUNET_free (buf); 1349 GNUNET_free (buf);
1350 if (GNUNET_SYSERR == enc_size)
1351 {
1352 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1353 "Unable to re-encrypt with policy %s\n",
1354 policy);
1355 GNUNET_free (policy);
1356 send_revocation_finished (rh, GNUNET_SYSERR);
1357 cleanup_revoke_ticket_handle (rh);
1358 return;
1359 }
1371 GNUNET_free (policy); 1360 GNUNET_free (policy);
1361
1372 rd[0].data_size = enc_size + sizeof (uint32_t); 1362 rd[0].data_size = enc_size + sizeof (uint32_t);
1373 rd_buf = GNUNET_malloc (rd[0].data_size); 1363 rd_buf = GNUNET_malloc (rd[0].data_size);
1374 attr_ver = htonl (rh->attrs->list_head->claim->version); 1364 attr_ver = htonl (rh->attrs->list_head->claim->version);
@@ -1463,7 +1453,7 @@ process_attributes_to_update (void *cls,
1463 1453
1464static void 1454static void
1465get_ticket_after_abe_bootstrap (void *cls, 1455get_ticket_after_abe_bootstrap (void *cls,
1466 struct GNUNET_CRYPTO_AbeMasterKey *abe_key) 1456 struct GNUNET_ABE_AbeMasterKey *abe_key)
1467{ 1457{
1468 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1469 "Finished ABE bootstrap\n"); 1459 "Finished ABE bootstrap\n");
@@ -1475,13 +1465,6 @@ get_ticket_after_abe_bootstrap (void *cls,
1475 rh); 1465 rh);
1476} 1466}
1477 1467
1478/**
1479 * Checks a ticket revocation message
1480 *
1481 * @param cls client sending the message
1482 * @param im message of type `struct RevokeTicketMessage`
1483 * @return #GNUNET_OK if @a im is well-formed
1484 */
1485static int 1468static int
1486check_revoke_ticket_message(void *cls, 1469check_revoke_ticket_message(void *cls,
1487 const struct RevokeTicketMessage *im) 1470 const struct RevokeTicketMessage *im)
@@ -1496,14 +1479,7 @@ check_revoke_ticket_message(void *cls,
1496 } 1479 }
1497 return GNUNET_OK; 1480 return GNUNET_OK;
1498} 1481}
1499/** 1482
1500 *
1501 * Handler for ticket revocation message
1502 *
1503 * @param cls unused
1504 * @param client who sent the message
1505 * @param message the message
1506 */
1507static void 1483static void
1508handle_revoke_ticket_message (void *cls, 1484handle_revoke_ticket_message (void *cls,
1509 const struct RevokeTicketMessage *rm) 1485 const struct RevokeTicketMessage *rm)
@@ -1534,8 +1510,8 @@ static void
1534cleanup_consume_ticket_handle (struct ConsumeTicketHandle *handle) 1510cleanup_consume_ticket_handle (struct ConsumeTicketHandle *handle)
1535{ 1511{
1536 if (NULL != handle->key) 1512 if (NULL != handle->key)
1537 GNUNET_CRYPTO_cpabe_delete_key (handle->key, 1513 GNUNET_ABE_cpabe_delete_key (handle->key,
1538 GNUNET_YES); 1514 GNUNET_YES);
1539 if (NULL != handle->attrs) 1515 if (NULL != handle->attrs)
1540 GNUNET_IDENTITY_ATTRIBUTE_list_destroy (handle->attrs); 1516 GNUNET_IDENTITY_ATTRIBUTE_list_destroy (handle->attrs);
1541 GNUNET_free (handle); 1517 GNUNET_free (handle);
@@ -1543,13 +1519,6 @@ cleanup_consume_ticket_handle (struct ConsumeTicketHandle *handle)
1543 1519
1544 1520
1545 1521
1546/**
1547 * Checks a ticket consume message
1548 *
1549 * @param cls client sending the message
1550 * @param im message of type `struct ConsumeTicketMessage`
1551 * @return #GNUNET_OK if @a im is well-formed
1552 */
1553static int 1522static int
1554check_consume_ticket_message(void *cls, 1523check_consume_ticket_message(void *cls,
1555 const struct ConsumeTicketMessage *cm) 1524 const struct ConsumeTicketMessage *cm)
@@ -1587,11 +1556,11 @@ process_parallel_lookup2 (void *cls, uint32_t rd_count,
1587 parallel_lookup); 1556 parallel_lookup);
1588 GNUNET_free (parallel_lookup->label); 1557 GNUNET_free (parallel_lookup->label);
1589 1558
1590 GNUNET_STATISTICS_update (stats_handle, 1559 GNUNET_STATISTICS_update (stats,
1591 "attribute_lookup_time_total", 1560 "attribute_lookup_time_total",
1592 GNUNET_TIME_absolute_get_duration (parallel_lookup->lookup_start_time).rel_value_us, 1561 GNUNET_TIME_absolute_get_duration (parallel_lookup->lookup_start_time).rel_value_us,
1593 GNUNET_YES); 1562 GNUNET_YES);
1594 GNUNET_STATISTICS_update (stats_handle, 1563 GNUNET_STATISTICS_update (stats,
1595 "attribute_lookups_count", 1564 "attribute_lookups_count",
1596 1, 1565 1,
1597 GNUNET_YES); 1566 GNUNET_YES);
@@ -1603,24 +1572,24 @@ process_parallel_lookup2 (void *cls, uint32_t rd_count,
1603 if (rd->record_type == GNUNET_GNSRECORD_TYPE_ID_ATTR) 1572 if (rd->record_type == GNUNET_GNSRECORD_TYPE_ID_ATTR)
1604 { 1573 {
1605 decrypt_duration = GNUNET_TIME_absolute_get (); 1574 decrypt_duration = GNUNET_TIME_absolute_get ();
1606 attr_len = GNUNET_CRYPTO_cpabe_decrypt (rd->data + sizeof (uint32_t), 1575 attr_len = GNUNET_ABE_cpabe_decrypt (rd->data + sizeof (uint32_t),
1607 rd->data_size - sizeof (uint32_t), 1576 rd->data_size - sizeof (uint32_t),
1608 handle->key, 1577 handle->key,
1609 (void**)&data); 1578 (void**)&data);
1610 if (GNUNET_SYSERR != attr_len) 1579 if (GNUNET_SYSERR != attr_len)
1611 { 1580 {
1612 GNUNET_STATISTICS_update (stats_handle, 1581 GNUNET_STATISTICS_update (stats,
1613 "abe_decrypt_time_total", 1582 "abe_decrypt_time_total",
1614 GNUNET_TIME_absolute_get_duration (decrypt_duration).rel_value_us, 1583 GNUNET_TIME_absolute_get_duration (decrypt_duration).rel_value_us,
1615 GNUNET_YES); 1584 GNUNET_YES);
1616 GNUNET_STATISTICS_update (stats_handle, 1585 GNUNET_STATISTICS_update (stats,
1617 "abe_decrypt_count", 1586 "abe_decrypt_count",
1618 1, 1587 1,
1619 GNUNET_YES); 1588 GNUNET_YES);
1620 1589
1621 attr_le = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry); 1590 attr_le = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry);
1622 attr_le->claim = GNUNET_IDENTITY_ATTRIBUTE_deserialize (data, 1591 attr_le->claim = GNUNET_IDENTITY_ATTRIBUTE_deserialize (data,
1623 attr_len); 1592 attr_len);
1624 attr_le->claim->version = ntohl(*(uint32_t*)rd->data); 1593 attr_le->claim->version = ntohl(*(uint32_t*)rd->data);
1625 GNUNET_CONTAINER_DLL_insert (handle->attrs->list_head, 1594 GNUNET_CONTAINER_DLL_insert (handle->attrs->list_head,
1626 handle->attrs->list_tail, 1595 handle->attrs->list_tail,
@@ -1652,7 +1621,7 @@ process_parallel_lookup2 (void *cls, uint32_t rd_count,
1652 crm->identity = handle->ticket.identity; 1621 crm->identity = handle->ticket.identity;
1653 data_tmp = (char *) &crm[1]; 1622 data_tmp = (char *) &crm[1];
1654 GNUNET_IDENTITY_ATTRIBUTE_list_serialize (handle->attrs, 1623 GNUNET_IDENTITY_ATTRIBUTE_list_serialize (handle->attrs,
1655 data_tmp); 1624 data_tmp);
1656 GNUNET_MQ_send (handle->client->mq, env); 1625 GNUNET_MQ_send (handle->client->mq, env);
1657 cleanup_consume_ticket_handle (handle); 1626 cleanup_consume_ticket_handle (handle);
1658} 1627}
@@ -1734,20 +1703,20 @@ process_consume_abe_key (void *cls, uint32_t rd_count,
1734 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1703 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1735 "Decrypted bytes: %zd Expected bytes: %zd\n", 1704 "Decrypted bytes: %zd Expected bytes: %zd\n",
1736 size, rd->data_size - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); 1705 size, rd->data_size - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey));
1737 GNUNET_STATISTICS_update (stats_handle, 1706 GNUNET_STATISTICS_update (stats,
1738 "abe_key_lookup_time_total", 1707 "abe_key_lookup_time_total",
1739 GNUNET_TIME_absolute_get_duration (handle->lookup_start_time).rel_value_us, 1708 GNUNET_TIME_absolute_get_duration (handle->lookup_start_time).rel_value_us,
1740 GNUNET_YES); 1709 GNUNET_YES);
1741 GNUNET_STATISTICS_update (stats_handle, 1710 GNUNET_STATISTICS_update (stats,
1742 "abe_key_lookups_count", 1711 "abe_key_lookups_count",
1743 1, 1712 1,
1744 GNUNET_YES); 1713 GNUNET_YES);
1745 scopes = GNUNET_strdup (buf); 1714 scopes = GNUNET_strdup (buf);
1746 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1715 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1747 "Scopes %s\n", scopes); 1716 "Scopes %s\n", scopes);
1748 handle->key = GNUNET_CRYPTO_cpabe_deserialize_key ((void*)(buf + strlen (scopes) + 1), 1717 handle->key = GNUNET_ABE_cpabe_deserialize_key ((void*)(buf + strlen (scopes) + 1),
1749 rd->data_size - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) 1718 rd->data_size - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)
1750 - strlen (scopes) - 1); 1719 - strlen (scopes) - 1);
1751 1720
1752 for (scope = strtok (scopes, ","); NULL != scope; scope = strtok (NULL, ",")) 1721 for (scope = strtok (scopes, ","); NULL != scope; scope = strtok (NULL, ","))
1753 { 1722 {
@@ -1781,14 +1750,6 @@ process_consume_abe_key (void *cls, uint32_t rd_count,
1781} 1750}
1782 1751
1783 1752
1784/**
1785 *
1786 * Handler for ticket issue message
1787 *
1788 * @param cls unused
1789 * @param client who sent the message
1790 * @param message the message
1791 */
1792static void 1753static void
1793handle_consume_ticket_message (void *cls, 1754handle_consume_ticket_message (void *cls,
1794 const struct ConsumeTicketMessage *cm) 1755 const struct ConsumeTicketMessage *cm)
@@ -1833,7 +1794,7 @@ cleanup_as_handle (struct AttributeStoreHandle *handle)
1833 if (NULL != handle->claim) 1794 if (NULL != handle->claim)
1834 GNUNET_free (handle->claim); 1795 GNUNET_free (handle->claim);
1835 if (NULL != handle->abe_key) 1796 if (NULL != handle->abe_key)
1836 GNUNET_CRYPTO_cpabe_delete_master_key (handle->abe_key); 1797 GNUNET_ABE_cpabe_delete_master_key (handle->abe_key);
1837 GNUNET_free (handle); 1798 GNUNET_free (handle);
1838} 1799}
1839 1800
@@ -1886,7 +1847,7 @@ attr_store_task (void *cls)
1886 buf = GNUNET_malloc (buf_size); 1847 buf = GNUNET_malloc (buf_size);
1887 1848
1888 GNUNET_IDENTITY_ATTRIBUTE_serialize (as_handle->claim, 1849 GNUNET_IDENTITY_ATTRIBUTE_serialize (as_handle->claim,
1889 buf); 1850 buf);
1890 1851
1891 GNUNET_asprintf (&policy, 1852 GNUNET_asprintf (&policy,
1892 "%s_%lu", 1853 "%s_%lu",
@@ -1897,11 +1858,22 @@ attr_store_task (void *cls)
1897 /** 1858 /**
1898 * Encrypt the attribute value and store in namestore 1859 * Encrypt the attribute value and store in namestore
1899 */ 1860 */
1900 enc_size = GNUNET_CRYPTO_cpabe_encrypt (buf, 1861 enc_size = GNUNET_ABE_cpabe_encrypt (buf,
1901 buf_size, 1862 buf_size,
1902 policy, //Policy 1863 policy, //Policy
1903 as_handle->abe_key, 1864 as_handle->abe_key,
1904 (void**)&enc_buf); 1865 (void**)&enc_buf);
1866 if (GNUNET_SYSERR == enc_size)
1867 {
1868 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1869 "Failed to encrypt with policy %s\n",
1870 policy);
1871 cleanup_as_handle (as_handle);
1872 GNUNET_free (buf);
1873 GNUNET_free (policy);
1874 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1875 return;
1876 }
1905 GNUNET_free (buf); 1877 GNUNET_free (buf);
1906 GNUNET_free (policy); 1878 GNUNET_free (policy);
1907 rd[0].data_size = enc_size + sizeof (uint32_t); 1879 rd[0].data_size = enc_size + sizeof (uint32_t);
@@ -1931,7 +1903,7 @@ attr_store_task (void *cls)
1931 1903
1932static void 1904static void
1933store_after_abe_bootstrap (void *cls, 1905store_after_abe_bootstrap (void *cls,
1934 struct GNUNET_CRYPTO_AbeMasterKey *abe_key) 1906 struct GNUNET_ABE_AbeMasterKey *abe_key)
1935{ 1907{
1936 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1908 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1937 "Finished ABE bootstrap\n"); 1909 "Finished ABE bootstrap\n");
@@ -1940,13 +1912,6 @@ store_after_abe_bootstrap (void *cls,
1940 GNUNET_SCHEDULER_add_now (&attr_store_task, ash); 1912 GNUNET_SCHEDULER_add_now (&attr_store_task, ash);
1941} 1913}
1942 1914
1943/**
1944 * Checks a store message
1945 *
1946 * @param cls client sending the message
1947 * @param sam message of type `struct AttributeStoreMessage`
1948 * @return #GNUNET_OK if @a im is well-formed
1949 */
1950static int 1915static int
1951check_attribute_store_message(void *cls, 1916check_attribute_store_message(void *cls,
1952 const struct AttributeStoreMessage *sam) 1917 const struct AttributeStoreMessage *sam)
@@ -1963,14 +1928,6 @@ check_attribute_store_message(void *cls,
1963} 1928}
1964 1929
1965 1930
1966/**
1967 *
1968 * Handler for store message
1969 *
1970 * @param cls unused
1971 * @param client who sent the message
1972 * @param message the message
1973 */
1974static void 1931static void
1975handle_attribute_store_message (void *cls, 1932handle_attribute_store_message (void *cls,
1976 const struct AttributeStoreMessage *sam) 1933 const struct AttributeStoreMessage *sam)
@@ -1985,7 +1942,7 @@ handle_attribute_store_message (void *cls,
1985 1942
1986 as_handle = GNUNET_new (struct AttributeStoreHandle); 1943 as_handle = GNUNET_new (struct AttributeStoreHandle);
1987 as_handle->claim = GNUNET_IDENTITY_ATTRIBUTE_deserialize ((char*)&sam[1], 1944 as_handle->claim = GNUNET_IDENTITY_ATTRIBUTE_deserialize ((char*)&sam[1],
1988 data_len); 1945 data_len);
1989 1946
1990 as_handle->r_id = ntohl (sam->id); 1947 as_handle->r_id = ntohl (sam->id);
1991 as_handle->identity = sam->identity; 1948 as_handle->identity = sam->identity;
@@ -2001,7 +1958,7 @@ static void
2001cleanup_iter_handle (struct AttributeIterator *ai) 1958cleanup_iter_handle (struct AttributeIterator *ai)
2002{ 1959{
2003 if (NULL != ai->abe_key) 1960 if (NULL != ai->abe_key)
2004 GNUNET_CRYPTO_cpabe_delete_master_key (ai->abe_key); 1961 GNUNET_ABE_cpabe_delete_master_key (ai->abe_key);
2005 GNUNET_CONTAINER_DLL_remove (ai->client->op_head, 1962 GNUNET_CONTAINER_DLL_remove (ai->client->op_head,
2006 ai->client->op_tail, 1963 ai->client->op_tail,
2007 ai); 1964 ai);
@@ -2043,7 +2000,7 @@ attr_iter_cb (void *cls,
2043{ 2000{
2044 struct AttributeIterator *ai = cls; 2001 struct AttributeIterator *ai = cls;
2045 struct AttributeResultMessage *arm; 2002 struct AttributeResultMessage *arm;
2046 struct GNUNET_CRYPTO_AbeKey *key; 2003 struct GNUNET_ABE_AbeKey *key;
2047 struct GNUNET_MQ_Envelope *env; 2004 struct GNUNET_MQ_Envelope *env;
2048 ssize_t msg_extra_len; 2005 ssize_t msg_extra_len;
2049 char* attr_ser; 2006 char* attr_ser;
@@ -2067,15 +2024,19 @@ attr_iter_cb (void *cls,
2067 label, attr_ver); 2024 label, attr_ver);
2068 attrs[0] = policy; 2025 attrs[0] = policy;
2069 attrs[1] = 0; 2026 attrs[1] = 0;
2070 key = GNUNET_CRYPTO_cpabe_create_key (ai->abe_key, 2027 key = GNUNET_ABE_cpabe_create_key (ai->abe_key,
2071 attrs); 2028 attrs);
2072 msg_extra_len = GNUNET_CRYPTO_cpabe_decrypt (rd->data+sizeof (uint32_t), 2029 msg_extra_len = GNUNET_ABE_cpabe_decrypt (rd->data+sizeof (uint32_t),
2073 rd->data_size-sizeof (uint32_t), 2030 rd->data_size-sizeof (uint32_t),
2074 key, 2031 key,
2075 (void**)&attr_ser); 2032 (void**)&attr_ser);
2076 2033 if (GNUNET_SYSERR == msg_extra_len) {
2077 GNUNET_CRYPTO_cpabe_delete_key (key, 2034 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it);
2078 GNUNET_YES); 2035 return;
2036 }
2037
2038 GNUNET_ABE_cpabe_delete_key (key,
2039 GNUNET_YES);
2079 //GNUNET_free (policy); 2040 //GNUNET_free (policy);
2080 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2081 "Found attribute: %s\n", label); 2042 "Found attribute: %s\n", label);
@@ -2092,14 +2053,14 @@ attr_iter_cb (void *cls,
2092 msg_extra_len); 2053 msg_extra_len);
2093 GNUNET_MQ_send (ai->client->mq, env); 2054 GNUNET_MQ_send (ai->client->mq, env);
2094 GNUNET_free (attr_ser); 2055 GNUNET_free (attr_ser);
2095 GNUNET_CRYPTO_cpabe_delete_master_key (ai->abe_key); 2056 GNUNET_ABE_cpabe_delete_master_key (ai->abe_key);
2096 ai->abe_key = NULL; 2057 ai->abe_key = NULL;
2097} 2058}
2098 2059
2099 2060
2100void 2061void
2101iterate_after_abe_bootstrap (void *cls, 2062iterate_after_abe_bootstrap (void *cls,
2102 struct GNUNET_CRYPTO_AbeMasterKey *abe_key) 2063 struct GNUNET_ABE_AbeMasterKey *abe_key)
2103{ 2064{
2104 struct AttributeIterator *ai = cls; 2065 struct AttributeIterator *ai = cls;
2105 ai->abe_key = abe_key; 2066 ai->abe_key = abe_key;
@@ -2115,7 +2076,7 @@ iterate_after_abe_bootstrap (void *cls,
2115 2076
2116void 2077void
2117iterate_next_after_abe_bootstrap (void *cls, 2078iterate_next_after_abe_bootstrap (void *cls,
2118 struct GNUNET_CRYPTO_AbeMasterKey *abe_key) 2079 struct GNUNET_ABE_AbeMasterKey *abe_key)
2119{ 2080{
2120 struct AttributeIterator *ai = cls; 2081 struct AttributeIterator *ai = cls;
2121 ai->abe_key = abe_key; 2082 ai->abe_key = abe_key;
@@ -2124,12 +2085,6 @@ iterate_next_after_abe_bootstrap (void *cls,
2124 2085
2125 2086
2126 2087
2127/**
2128 * Handles a #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ITERATION_START message
2129 *
2130 * @param cls the client sending the message
2131 * @param zis_msg message from the client
2132 */
2133static void 2088static void
2134handle_iteration_start (void *cls, 2089handle_iteration_start (void *cls,
2135 const struct AttributeIterationStartMessage *ais_msg) 2090 const struct AttributeIterationStartMessage *ais_msg)
@@ -2152,12 +2107,6 @@ handle_iteration_start (void *cls,
2152} 2107}
2153 2108
2154 2109
2155/**
2156 * Handles a #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ITERATION_STOP message
2157 *
2158 * @param cls the client sending the message
2159 * @param ais_msg message from the client
2160 */
2161static void 2110static void
2162handle_iteration_stop (void *cls, 2111handle_iteration_stop (void *cls,
2163 const struct AttributeIterationStopMessage *ais_msg) 2112 const struct AttributeIterationStopMessage *ais_msg)
@@ -2187,12 +2136,6 @@ handle_iteration_stop (void *cls,
2187} 2136}
2188 2137
2189 2138
2190/**
2191 * Handles a #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_ITERATION_NEXT message
2192 *
2193 * @param cls the client sending the message
2194 * @param message message from the client
2195 */
2196static void 2139static void
2197handle_iteration_next (void *cls, 2140handle_iteration_next (void *cls,
2198 const struct AttributeIterationNextMessage *ais_msg) 2141 const struct AttributeIterationNextMessage *ais_msg)
@@ -2350,12 +2293,6 @@ run_ticket_iteration_round (struct TicketIteration *ti)
2350 cleanup_ticket_iter_handle (ti); 2293 cleanup_ticket_iter_handle (ti);
2351} 2294}
2352 2295
2353/**
2354 * Handles a #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_START message
2355 *
2356 * @param cls the client sending the message
2357 * @param tis_msg message from the client
2358 */
2359static void 2296static void
2360handle_ticket_iteration_start (void *cls, 2297handle_ticket_iteration_start (void *cls,
2361 const struct TicketIterationStartMessage *tis_msg) 2298 const struct TicketIterationStartMessage *tis_msg)
@@ -2380,12 +2317,6 @@ handle_ticket_iteration_start (void *cls,
2380} 2317}
2381 2318
2382 2319
2383/**
2384 * Handles a #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_STOP message
2385 *
2386 * @param cls the client sending the message
2387 * @param tis_msg message from the client
2388 */
2389static void 2320static void
2390handle_ticket_iteration_stop (void *cls, 2321handle_ticket_iteration_stop (void *cls,
2391 const struct TicketIterationStopMessage *tis_msg) 2322 const struct TicketIterationStopMessage *tis_msg)
@@ -2415,12 +2346,6 @@ handle_ticket_iteration_stop (void *cls,
2415} 2346}
2416 2347
2417 2348
2418/**
2419 * Handles a #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_NEXT message
2420 *
2421 * @param cls the client sending the message
2422 * @param message message from the client
2423 */
2424static void 2349static void
2425handle_ticket_iteration_next (void *cls, 2350handle_ticket_iteration_next (void *cls,
2426 const struct TicketIterationNextMessage *tis_msg) 2351 const struct TicketIterationNextMessage *tis_msg)
@@ -2452,9 +2377,8 @@ handle_ticket_iteration_next (void *cls,
2452 * Main function that will be run 2377 * Main function that will be run
2453 * 2378 *
2454 * @param cls closure 2379 * @param cls closure
2455 * @param args remaining command-line arguments 2380 * @param c the configuration used
2456 * @param cfgfile name of the configuration file used (for saving, can be NULL) 2381 * @param server the service handle
2457 * @param c configuration
2458 */ 2382 */
2459static void 2383static void
2460run (void *cls, 2384run (void *cls,
@@ -2486,8 +2410,6 @@ run (void *cls,
2486 identity_handle = GNUNET_IDENTITY_connect (cfg, 2410 identity_handle = GNUNET_IDENTITY_connect (cfg,
2487 NULL, 2411 NULL,
2488 NULL); 2412 NULL);
2489 stats_handle = GNUNET_STATISTICS_create ("identity-provider",
2490 cfg);
2491 /* Loading DB plugin */ 2413 /* Loading DB plugin */
2492 if (GNUNET_OK != 2414 if (GNUNET_OK !=
2493 GNUNET_CONFIGURATION_get_value_string (cfg, 2415 GNUNET_CONFIGURATION_get_value_string (cfg,
diff --git a/src/identity-provider/identity_provider.h b/src/identity-provider/identity_provider.h
index be9fdc6f5..b1fe6e1fd 100644
--- a/src/identity-provider/identity_provider.h
+++ b/src/identity-provider/identity_provider.h
@@ -248,7 +248,7 @@ struct TicketIterationStopMessage
248struct IssueTicketMessage 248struct IssueTicketMessage
249{ 249{
250 /** 250 /**
251 * Type will be #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ISSUE 251 * Type will be #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ISSUE_TICKET
252 */ 252 */
253 struct GNUNET_MessageHeader header; 253 struct GNUNET_MessageHeader header;
254 254
@@ -281,7 +281,7 @@ struct IssueTicketMessage
281struct RevokeTicketMessage 281struct RevokeTicketMessage
282{ 282{
283 /** 283 /**
284 * Type will be #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ISSUE 284 * Type will be #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET
285 */ 285 */
286 struct GNUNET_MessageHeader header; 286 struct GNUNET_MessageHeader header;
287 287
@@ -309,7 +309,7 @@ struct RevokeTicketMessage
309struct RevokeTicketResultMessage 309struct RevokeTicketResultMessage
310{ 310{
311 /** 311 /**
312 * Type will be #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ISSUE 312 * Type will be #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET_RESULT
313 */ 313 */
314 struct GNUNET_MessageHeader header; 314 struct GNUNET_MessageHeader header;
315 315
@@ -348,7 +348,7 @@ struct TicketResultMessage
348struct ConsumeTicketMessage 348struct ConsumeTicketMessage
349{ 349{
350 /** 350 /**
351 * Type will be #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ISSUE 351 * Type will be #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET
352 */ 352 */
353 struct GNUNET_MessageHeader header; 353 struct GNUNET_MessageHeader header;
354 354
diff --git a/src/identity-provider/identity_provider_api.c b/src/identity-provider/identity_provider_api.c
index 6fc8d228a..38c11841c 100644
--- a/src/identity-provider/identity_provider_api.c
+++ b/src/identity-provider/identity_provider_api.c
@@ -317,14 +317,13 @@ struct GNUNET_IDENTITY_PROVIDER_Handle
317 317
318}; 318};
319 319
320
321/** 320/**
322 * Try again to connect to the service. 321 * Try again to connect to the service.
323 * 322 *
324 * @param cls handle to the service. 323 * @param h handle to the identity provider service.
325 */ 324 */
326static void 325static void
327reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *handle); 326reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h);
328 327
329/** 328/**
330 * Reconnect 329 * Reconnect
@@ -344,7 +343,7 @@ reconnect_task (void *cls)
344/** 343/**
345 * Disconnect from service and then reconnect. 344 * Disconnect from service and then reconnect.
346 * 345 *
347 * @param handle our handle 346 * @param handle our service
348 */ 347 */
349static void 348static void
350force_reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *handle) 349force_reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *handle)
@@ -515,13 +514,16 @@ handle_consume_ticket_result (void *cls,
515 GNUNET_IDENTITY_ATTRIBUTE_list_destroy (attrs); 514 GNUNET_IDENTITY_ATTRIBUTE_list_destroy (attrs);
516 } 515 }
517 } 516 }
518 op->ar_cb (op->cls, 517 if (NULL != op)
519 NULL, 518 {
520 NULL); 519 op->ar_cb (op->cls,
521 GNUNET_CONTAINER_DLL_remove (h->op_head, 520 NULL,
522 h->op_tail, 521 NULL);
523 op); 522 GNUNET_CONTAINER_DLL_remove (h->op_head,
524 GNUNET_free (op); 523 h->op_tail,
524 op);
525 GNUNET_free (op);
526 }
525 return; 527 return;
526 } 528 }
527 GNUNET_assert (0); 529 GNUNET_assert (0);
@@ -775,7 +777,7 @@ handle_revoke_ticket_result (void *cls,
775/** 777/**
776 * Try again to connect to the service. 778 * Try again to connect to the service.
777 * 779 *
778 * @param cls handle to the identity provider service. 780 * @param h handle to the identity provider service.
779 */ 781 */
780static void 782static void
781reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h) 783reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h)
@@ -895,8 +897,7 @@ GNUNET_IDENTITY_PROVIDER_disconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h)
895 * 897 *
896 * @param h handle to the identity provider 898 * @param h handle to the identity provider
897 * @param pkey private key of the identity 899 * @param pkey private key of the identity
898 * @param name the attribute name 900 * @param attr the attribute value
899 * @param value the attribute value
900 * @param cont continuation to call when done 901 * @param cont continuation to call when done
901 * @param cont_cls closure for @a cont 902 * @param cont_cls closure for @a cont
902 * @return handle to abort the request 903 * @return handle to abort the request
@@ -928,7 +929,7 @@ GNUNET_IDENTITY_PROVIDER_attribute_store (struct GNUNET_IDENTITY_PROVIDER_Handle
928 sam->id = htonl (op->r_id); 929 sam->id = htonl (op->r_id);
929 930
930 GNUNET_IDENTITY_ATTRIBUTE_serialize (attr, 931 GNUNET_IDENTITY_ATTRIBUTE_serialize (attr,
931 (char*)&sam[1]); 932 (char*)&sam[1]);
932 933
933 sam->attr_len = htons (attr_len); 934 sam->attr_len = htons (attr_len);
934 if (NULL != h->mq) 935 if (NULL != h->mq)
@@ -1061,7 +1062,7 @@ GNUNET_IDENTITY_PROVIDER_get_attributes_stop (struct GNUNET_IDENTITY_PROVIDER_At
1061 * @param h the identity provider to use 1062 * @param h the identity provider to use
1062 * @param iss the issuing identity 1063 * @param iss the issuing identity
1063 * @param rp the subject of the ticket (the relying party) 1064 * @param rp the subject of the ticket (the relying party)
1064 * @param attr the attributes that the relying party is given access to 1065 * @param attrs the attributes that the relying party is given access to
1065 * @param cb the callback 1066 * @param cb the callback
1066 * @param cb_cls the callback closure 1067 * @param cb_cls the callback closure
1067 * @return handle to abort the operation 1068 * @return handle to abort the operation
@@ -1095,7 +1096,7 @@ GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *h
1095 tim->id = htonl (op->r_id); 1096 tim->id = htonl (op->r_id);
1096 1097
1097 GNUNET_IDENTITY_ATTRIBUTE_list_serialize (attrs, 1098 GNUNET_IDENTITY_ATTRIBUTE_list_serialize (attrs,
1098 (char*)&tim[1]); 1099 (char*)&tim[1]);
1099 1100
1100 tim->attr_len = htons (attr_len); 1101 tim->attr_len = htons (attr_len);
1101 if (NULL != h->mq) 1102 if (NULL != h->mq)
@@ -1108,7 +1109,7 @@ GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *h
1108 * Consumes an issued ticket. The ticket is persisted 1109 * Consumes an issued ticket. The ticket is persisted
1109 * and used to retrieve identity information from the issuer 1110 * and used to retrieve identity information from the issuer
1110 * 1111 *
1111 * @param id the identity provider to use 1112 * @param h the identity provider to use
1112 * @param identity the identity that is the subject of the issued ticket (the relying party) 1113 * @param identity the identity that is the subject of the issued ticket (the relying party)
1113 * @param ticket the issued ticket to consume 1114 * @param ticket the issued ticket to consume
1114 * @param cb the callback to call 1115 * @param cb the callback to call
@@ -1218,7 +1219,7 @@ GNUNET_IDENTITY_PROVIDER_ticket_iteration_start (struct GNUNET_IDENTITY_PROVIDER
1218 * Lists all tickets that have been issued to remote 1219 * Lists all tickets that have been issued to remote
1219 * identites (relying parties) 1220 * identites (relying parties)
1220 * 1221 *
1221 * @param id the identity provider to use 1222 * @param h the identity provider to use
1222 * @param identity the issuing identity 1223 * @param identity the issuing identity
1223 * @param error_cb function to call on error (i.e. disconnect), 1224 * @param error_cb function to call on error (i.e. disconnect),
1224 * the handle is afterwards invalid 1225 * the handle is afterwards invalid
@@ -1324,7 +1325,7 @@ GNUNET_IDENTITY_PROVIDER_ticket_iteration_stop (struct GNUNET_IDENTITY_PROVIDER_
1324 * Revoked an issued ticket. The relying party will be unable to retrieve 1325 * Revoked an issued ticket. The relying party will be unable to retrieve
1325 * updated attributes. 1326 * updated attributes.
1326 * 1327 *
1327 * @param id the identity provider to use 1328 * @param h the identity provider to use
1328 * @param identity the issuing identity 1329 * @param identity the issuing identity
1329 * @param ticket the ticket to revoke 1330 * @param ticket the ticket to revoke
1330 * @param cb the callback 1331 * @param cb the callback
diff --git a/src/identity-provider/plugin_gnsrecord_identity_provider.c b/src/identity-provider/plugin_gnsrecord_identity_provider.c
index ad5a95dc7..6ed0b0852 100644
--- a/src/identity-provider/plugin_gnsrecord_identity_provider.c
+++ b/src/identity-provider/plugin_gnsrecord_identity_provider.c
@@ -19,9 +19,9 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file identity/plugin_gnsrecord_identity.c 22 * @file identity-provider/plugin_gnsrecord_identity_provider.c
23 * @brief gnsrecord plugin to provide the API for identity records 23 * @brief gnsrecord plugin to provide the API for identity records
24 * @author Christian Grothoff 24 * @author Martin Schanzenbach
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
diff --git a/src/identity-provider/plugin_identity_provider_sqlite.c b/src/identity-provider/plugin_identity_provider_sqlite.c
index 594e4788d..0071528b9 100644
--- a/src/identity-provider/plugin_identity_provider_sqlite.c
+++ b/src/identity-provider/plugin_identity_provider_sqlite.c
@@ -368,6 +368,7 @@ database_shutdown (struct Plugin *plugin)
368 * 368 *
369 * @param cls closure (internal context for the plugin) 369 * @param cls closure (internal context for the plugin)
370 * @param ticket the ticket to persist 370 * @param ticket the ticket to persist
371 * @param attrs the attributes associated with the ticket
371 * @return #GNUNET_OK on success, else #GNUNET_SYSERR 372 * @return #GNUNET_OK on success, else #GNUNET_SYSERR
372 */ 373 */
373static int 374static int
@@ -581,8 +582,7 @@ get_ticket_and_call_iterator (struct Plugin *plugin,
581 * Lookup tickets in the datastore. 582 * Lookup tickets in the datastore.
582 * 583 *
583 * @param cls closure (internal context for the plugin) 584 * @param cls closure (internal context for the plugin)
584 * @param zone private key of the zone 585 * @param ticket the ticket to retrieve attributes for
585 * @param label name of the record in the zone
586 * @param iter function to call with the result 586 * @param iter function to call with the result
587 * @param iter_cls closure for @a iter 587 * @param iter_cls closure for @a iter
588 * @return #GNUNET_OK on success, else #GNUNET_SYSERR 588 * @return #GNUNET_OK on success, else #GNUNET_SYSERR
diff --git a/src/identity-provider/plugin_rest_identity_provider.c b/src/identity-provider/plugin_rest_identity_provider.c
index 68644777f..1aa1f818d 100644
--- a/src/identity-provider/plugin_rest_identity_provider.c
+++ b/src/identity-provider/plugin_rest_identity_provider.c
@@ -1540,17 +1540,6 @@ list_ego (void *cls,
1540 1540
1541} 1541}
1542 1542
1543/**
1544 * Function processing the REST call
1545 *
1546 * @param method HTTP method
1547 * @param url URL of the HTTP request
1548 * @param data body of the HTTP request (optional)
1549 * @param data_size length of the body
1550 * @param proc callback function for the result
1551 * @param proc_cls closure for callback function
1552 * @return GNUNET_OK if request accepted
1553 */
1554static void 1543static void
1555rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle, 1544rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
1556 GNUNET_REST_ResultProcessor proc, 1545 GNUNET_REST_ResultProcessor proc,
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c
index 5f34d0f1b..33804143d 100644
--- a/src/identity/plugin_rest_identity.c
+++ b/src/identity/plugin_rest_identity.c
@@ -593,6 +593,7 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con,
593 struct GNUNET_JSONAPI_Resource *json_res; 593 struct GNUNET_JSONAPI_Resource *json_res;
594 struct RequestHandle *handle = cls; 594 struct RequestHandle *handle = cls;
595 struct EgoEntry *ego_entry; 595 struct EgoEntry *ego_entry;
596 struct EgoEntry *ego_entry_tmp;
596 struct MHD_Response *resp; 597 struct MHD_Response *resp;
597 json_t *subsys_json; 598 json_t *subsys_json;
598 json_t *name_json; 599 json_t *name_json;
@@ -684,12 +685,12 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con,
684 if ((NULL != name_json) && json_is_string (name_json)) 685 if ((NULL != name_json) && json_is_string (name_json))
685 { 686 {
686 newname = json_string_value (name_json); 687 newname = json_string_value (name_json);
687 for (ego_entry = handle->ego_head; 688 for (ego_entry_tmp = handle->ego_head;
688 NULL != ego_entry; 689 NULL != ego_entry_tmp;
689 ego_entry = ego_entry->next) 690 ego_entry_tmp = ego_entry_tmp->next)
690 { 691 {
691 if (0 == strcasecmp (newname, ego_entry->identifier) && 692 if (0 == strcasecmp (newname, ego_entry_tmp->identifier) &&
692 0 != strcasecmp (keystring, ego_entry->keystring)) 693 0 != strcasecmp (keystring, ego_entry_tmp->keystring))
693 { 694 {
694 //Ego with same name not allowed 695 //Ego with same name not allowed
695 GNUNET_JSONAPI_document_delete (json_obj); 696 GNUNET_JSONAPI_document_delete (json_obj);
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index e5abec416..08e9dd156 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -33,6 +33,7 @@ gnunetinclude_HEADERS = \
33 gnunet_bandwidth_lib.h \ 33 gnunet_bandwidth_lib.h \
34 gnunet_bio_lib.h \ 34 gnunet_bio_lib.h \
35 gnunet_block_lib.h \ 35 gnunet_block_lib.h \
36 gnunet_block_group_lib.h \
36 gnunet_block_plugin.h \ 37 gnunet_block_plugin.h \
37 gnunet_client_lib.h \ 38 gnunet_client_lib.h \
38 gnunet_common.h \ 39 gnunet_common.h \
@@ -65,7 +66,10 @@ gnunetinclude_HEADERS = \
65 gnunet_hello_lib.h \ 66 gnunet_hello_lib.h \
66 gnunet_helper_lib.h \ 67 gnunet_helper_lib.h \
67 gnunet_identity_service.h \ 68 gnunet_identity_service.h \
69 gnunet_identity_provider_service.h \
68 gnunet_json_lib.h \ 70 gnunet_json_lib.h \
71 gnunet_jsonapi_lib.h \
72 gnunet_jsonapi_util.h \
69 gnunet_load_lib.h \ 73 gnunet_load_lib.h \
70 gnunet_cadet_service.h \ 74 gnunet_cadet_service.h \
71 gnunet_microphone_lib.h \ 75 gnunet_microphone_lib.h \
@@ -102,6 +106,8 @@ gnunetinclude_HEADERS = \
102 gnunet_protocols.h \ 106 gnunet_protocols.h \
103 gnunet_resolver_service.h \ 107 gnunet_resolver_service.h \
104 gnunet_regex_service.h \ 108 gnunet_regex_service.h \
109 gnunet_rest_lib.h \
110 gnunet_rest_plugin.h \
105 gnunet_revocation_service.h \ 111 gnunet_revocation_service.h \
106 gnunet_scalarproduct_service.h \ 112 gnunet_scalarproduct_service.h \
107 gnunet_scheduler_lib.h \ 113 gnunet_scheduler_lib.h \
@@ -111,6 +117,7 @@ gnunetinclude_HEADERS = \
111 gnunet_signal_lib.h \ 117 gnunet_signal_lib.h \
112 gnunet_signatures.h \ 118 gnunet_signatures.h \
113 gnunet_social_service.h \ 119 gnunet_social_service.h \
120 gnunet_socks.h \
114 gnunet_speaker_lib.h \ 121 gnunet_speaker_lib.h \
115 gnunet_sq_lib.h \ 122 gnunet_sq_lib.h \
116 gnunet_statistics_service.h \ 123 gnunet_statistics_service.h \
diff --git a/src/include/gnunet_abe_lib.h b/src/include/gnunet_abe_lib.h
new file mode 100644
index 000000000..f73ea2431
--- /dev/null
+++ b/src/include/gnunet_abe_lib.h
@@ -0,0 +1,193 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001-2018 GNUnet e.V.
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21/**
22 * @file include/gnunet_abe_lib.h
23 * @brief Attribute-Based Encryption primitives for GNUnet
24 *
25 * @author Martin Schanzenbach
26 *
27 * @defgroup abe ABE Crypto library: Attribute-Based Encryption operations
28 *
29 */
30#ifndef GNUNET_ABE_LIB_H
31#define GNUNET_ABE_LIB_H
32
33#ifdef __cplusplus
34extern "C"
35{
36#if 0 /* keep Emacsens' auto-indent happy */
37}
38#endif
39#endif
40
41#include "gnunet_common.h"
42#include <gcrypt.h>
43
44/**
45 * @brief type for ABE master keys
46 */
47struct GNUNET_CRYPTO_AbeMasterKey;
48
49/**
50 * @brief type for ABE keys
51 */
52struct GNUNET_CRYPTO_AbeKey;
53
54
55
56/**
57 * @ingroup abe
58 * Create a new CP-ABE master key. Caller must free return value.
59 *
60 * @return fresh private key; free using #GNUNET_ABE_cpabe_delete_master_key
61 */
62struct GNUNET_ABE_AbeMasterKey *
63GNUNET_ABE_cpabe_create_master_key (void);
64
65/**
66 * @ingroup abe
67 * Delete a CP-ABE master key.
68 *
69 * @param key the master key
70 * @return fresh private key; free using #GNUNET_free
71 */
72void
73GNUNET_ABE_cpabe_delete_master_key (struct GNUNET_ABE_AbeMasterKey *key);
74
75/**
76 * @ingroup abe
77 * Create a new CP-ABE key. Caller must free return value.
78 *
79 * @param key the master key
80 * @param attrs the attributes to append to the key
81 * @return fresh private key; free using #GNUNET_ABE_cpabe_delete_key
82 */
83struct GNUNET_ABE_AbeKey *
84GNUNET_ABE_cpabe_create_key (struct GNUNET_ABE_AbeMasterKey *key,
85 char **attrs);
86
87/**
88 * @ingroup abe
89 * Delete a CP-ABE key.
90 *
91 * @param key the key to delete
92 * @param delete_pub GNUNE_YES if the public key should also be freed (bug in gabe)
93 * @return fresh private key; free using #GNUNET_free
94 */
95void
96GNUNET_ABE_cpabe_delete_key (struct GNUNET_ABE_AbeKey *key,
97 int delete_pub);
98
99
100/**
101 * @ingroup abe
102 * Encrypt a block using sessionkey.
103 *
104 * @param block the block to encrypt
105 * @param size the size of the @a block
106 * @param policy the ABE policy
107 * @param key the key used to encrypt
108 * @param result the result buffer. Will be allocated. Free using #GNUNET_free
109 * @return the size of the encrypted block, -1 for errors
110 */
111ssize_t
112GNUNET_ABE_cpabe_encrypt (const void *block,
113 size_t size,
114 const char *policy,
115 const struct GNUNET_ABE_AbeMasterKey *key,
116 void **result);
117
118/**
119 * @ingroup abe
120 * Decrypt a block using the ABE key.
121 *
122 * @param block the block to encrypt
123 * @param size the size of the @a block
124 * @param key the key used to decrypt
125 * @param result the result buffer. Will be allocated. Free using #GNUNET_free
126 * @return the size of the encrypted block, -1 for errors
127 */
128ssize_t
129GNUNET_ABE_cpabe_decrypt (const void *block,
130 size_t size,
131 const struct GNUNET_ABE_AbeKey *key,
132 void **result);
133
134/**
135 * @ingroup abe
136 * Serialize an ABE key.
137 *
138 * @param key the key to serialize
139 * @param result the result buffer. Will be allocated. Free using #GNUNET_free
140 * @return the size of the encrypted block, -1 for errors
141 */
142ssize_t
143GNUNET_ABE_cpabe_serialize_key (const struct GNUNET_ABE_AbeKey *key,
144 void **result);
145
146/**
147 * @ingroup abe
148 * Deserialize a serialized ABE key.
149 *
150 * @param data the data to deserialize
151 * @param len the length of the data.
152 * @return the ABE key. NULL of unsuccessful
153 */
154struct GNUNET_ABE_AbeKey*
155GNUNET_ABE_cpabe_deserialize_key (const void *data,
156 size_t len);
157
158/**
159 * @ingroup abe
160 * Serialize an ABE master key.
161 *
162 * @param key the key to serialize
163 * @param result the result buffer. Will be allocated. Free using #GNUNET_free
164 * @return the size of the encrypted block, -1 for errors
165 */
166ssize_t
167GNUNET_ABE_cpabe_serialize_master_key (const struct GNUNET_ABE_AbeMasterKey *key,
168 void **result);
169
170/**
171 * @ingroup abe
172 * Deserialize an ABE master key.
173 *
174 * @param data the data to deserialize
175 * @param len the length of the data.
176 * @return the ABE key. NULL of unsuccessful
177 */
178struct GNUNET_ABE_AbeMasterKey*
179GNUNET_ABE_cpabe_deserialize_master_key (const void *data,
180 size_t len);
181
182
183#if 0 /* keep Emacsens' auto-indent happy */
184{
185#endif
186#ifdef __cplusplus
187}
188#endif
189
190
191/* ifndef GNUNET_ABE_LIB_H */
192#endif
193/* end of gnunet_abe_lib.h */
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index d7f7b76ff..7d23e6f9b 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -988,7 +988,8 @@ GNUNET_ntoh_double (double d);
988 * arr is important since size is the number of elements and 988 * arr is important since size is the number of elements and
989 * not the size in bytes 989 * not the size in bytes
990 * @param size the number of elements in the existing vector (number 990 * @param size the number of elements in the existing vector (number
991 * of elements to copy over) 991 * of elements to copy over), will be updated with the new
992 * array size
992 * @param tsize the target size for the resulting vector, use 0 to 993 * @param tsize the target size for the resulting vector, use 0 to
993 * free the vector (then, arr will be NULL afterwards). 994 * free the vector (then, arr will be NULL afterwards).
994 */ 995 */
@@ -996,8 +997,16 @@ GNUNET_ntoh_double (double d);
996 997
997/** 998/**
998 * @ingroup memory 999 * @ingroup memory
999 * Append an element to a list (growing the 1000 * Append an element to a list (growing the list by one).
1000 * list by one). 1001 *
1002 * @param arr base-pointer of the vector, may be NULL if size is 0;
1003 * will be updated to reflect the new address. The TYPE of
1004 * arr is important since size is the number of elements and
1005 * not the size in bytes
1006 * @param size the number of elements in the existing vector (number
1007 * of elements to copy over), will be updated with the new
1008 * array size
1009 * @param element the element that will be appended to the array
1001 */ 1010 */
1002#define GNUNET_array_append(arr,size,element) do { GNUNET_array_grow(arr,size,size+1); arr[size-1] = element; } while(0) 1011#define GNUNET_array_append(arr,size,element) do { GNUNET_array_grow(arr,size,size+1); arr[size-1] = element; } while(0)
1003 1012
diff --git a/src/include/gnunet_credential_service.h b/src/include/gnunet_credential_service.h
index 67c2f2b4c..7d6f9e973 100644
--- a/src/include/gnunet_credential_service.h
+++ b/src/include/gnunet_credential_service.h
@@ -20,7 +20,6 @@
20 20
21/** 21/**
22 * @author Martin Schanzenbach 22 * @author Martin Schanzenbach
23 * @author Adnan Husain
24 * 23 *
25 * @file 24 * @file
26 * API to the Credential service 25 * API to the Credential service
@@ -274,7 +273,8 @@ typedef void (*GNUNET_CREDENTIAL_RemoveDelegateResultProcessor) (void *cls,
274 * @param issuer_key the issuer public key 273 * @param issuer_key the issuer public key
275 * @param issuer_attribute the issuer attribute 274 * @param issuer_attribute the issuer attribute
276 * @param subject_key the subject public key 275 * @param subject_key the subject public key
277 * @param subject_attribute the attribute claimed by the subject 276 * @param credential_count number of credentials
277 * @param credentials the subject credentials
278 * @param proc function to call on result 278 * @param proc function to call on result
279 * @param proc_cls closure for processor 279 * @param proc_cls closure for processor
280 * @return handle to the queued request 280 * @return handle to the queued request
@@ -305,6 +305,8 @@ GNUNET_CREDENTIAL_collect (struct GNUNET_CREDENTIAL_Handle *handle,
305 * @param attribute the name of the attribute to delegate 305 * @param attribute the name of the attribute to delegate
306 * @param subject the subject of the delegation 306 * @param subject the subject of the delegation
307 * @param delegated_attribute the name of the attribute that is delegated to 307 * @param delegated_attribute the name of the attribute that is delegated to
308 * @param proc the result callback
309 * @param proc_cls the result closure context
308 * @return handle to the queued request 310 * @return handle to the queued request
309 */ 311 */
310struct GNUNET_CREDENTIAL_Request * 312struct GNUNET_CREDENTIAL_Request *
@@ -322,6 +324,8 @@ GNUNET_CREDENTIAL_add_delegation (struct GNUNET_CREDENTIAL_Handle *handle,
322 * @param handle handle to the Credential service 324 * @param handle handle to the Credential service
323 * @param issuer the ego that was used to delegate the attribute 325 * @param issuer the ego that was used to delegate the attribute
324 * @param attribute the name of the attribute that is delegated 326 * @param attribute the name of the attribute that is delegated
327 * @param proc the callback
328 * @param proc_cls callback closure
325 * @return handle to the queued request 329 * @return handle to the queued request
326 */ 330 */
327struct GNUNET_CREDENTIAL_Request * 331struct GNUNET_CREDENTIAL_Request *
@@ -336,7 +340,6 @@ GNUNET_CREDENTIAL_remove_delegation (struct GNUNET_CREDENTIAL_Handle *handle,
336/** 340/**
337 * Issue an attribute to a subject 341 * Issue an attribute to a subject
338 * 342 *
339 * @param handle handle to the Credential service
340 * @param issuer the ego that should be used to issue the attribute 343 * @param issuer the ego that should be used to issue the attribute
341 * @param subject the subject of the attribute 344 * @param subject the subject of the attribute
342 * @param attribute the name of the attribute 345 * @param attribute the name of the attribute
@@ -344,32 +347,12 @@ GNUNET_CREDENTIAL_remove_delegation (struct GNUNET_CREDENTIAL_Handle *handle,
344 * @return handle to the queued request 347 * @return handle to the queued request
345 */ 348 */
346struct GNUNET_CREDENTIAL_Credential* 349struct GNUNET_CREDENTIAL_Credential*
347GNUNET_CREDENTIAL_credential_issue ( 350GNUNET_CREDENTIAL_credential_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
348 const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
349 struct GNUNET_CRYPTO_EcdsaPublicKey *subject, 351 struct GNUNET_CRYPTO_EcdsaPublicKey *subject,
350 const char *attribute, 352 const char *attribute,
351 struct GNUNET_TIME_Absolute *expiration); 353 struct GNUNET_TIME_Absolute *expiration);
352 354
353 355
354/**
355 * Remove a credential
356 *
357 * @param handle handle to the Credential service
358 * @param issuer the identity that issued the credential
359 * @param subject the subject of the credential
360 * @param credential the name of the credential
361 * @return handle to the queued request
362 */
363/**
364 struct GNUNET_CREDENTIAL_IssueRequest *
365 GNUNET_CREDENTIAL_remove (struct GNUNET_CREDENTIAL_Handle *handle,
366 struct GNUNET_IDENTITY_Ego *issuer,
367 struct GNUNET_IDENTITY_Ego *subject,
368 const char *credential,
369 GNUNET_CREDENTIAL_IssueResultProcessor proc,
370 void *proc_cls);
371 */
372
373 356
374/** 357/**
375 * Cancel pending lookup request 358 * Cancel pending lookup request
@@ -377,7 +360,7 @@ GNUNET_CREDENTIAL_credential_issue (
377 * @param lr the lookup request to cancel 360 * @param lr the lookup request to cancel
378 */ 361 */
379void 362void
380GNUNET_CREDENTIAL_request_cancel (struct GNUNET_CREDENTIAL_Request *vr); 363GNUNET_CREDENTIAL_request_cancel (struct GNUNET_CREDENTIAL_Request *lr);
381 364
382 365
383#if 0 /* keep Emacsens' auto-indent happy */ 366#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index 2fd67ae1b..e886a561c 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -395,11 +395,6 @@ struct GNUNET_CRYPTO_PaillierCiphertext
395 unsigned char bits[GNUNET_CRYPTO_PAILLIER_BITS * 2 / 8]; 395 unsigned char bits[GNUNET_CRYPTO_PAILLIER_BITS * 2 / 8];
396}; 396};
397 397
398/**
399 * @brief type for ABE master keys
400 */
401struct GNUNET_CRYPTO_AbeMasterKey;
402
403 398
404/* **************** Functions and Macros ************* */ 399/* **************** Functions and Macros ************* */
405 400
@@ -2142,83 +2137,6 @@ GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash,
2142 const struct GNUNET_CRYPTO_RsaPublicKey *public_key); 2137 const struct GNUNET_CRYPTO_RsaPublicKey *public_key);
2143 2138
2144 2139
2145/**
2146 * @ingroup crypto
2147 * Create a new CP-ABE master key. Caller must free return value.
2148 *
2149 * @return fresh private key; free using #GNUNET_free
2150 */
2151struct GNUNET_CRYPTO_AbeMasterKey *
2152GNUNET_CRYPTO_cpabe_create_master_key (void);
2153void
2154GNUNET_CRYPTO_cpabe_delete_master_key (struct GNUNET_CRYPTO_AbeMasterKey *key);
2155
2156/**
2157 * @ingroup crypto
2158 * Create a new CP-ABE key. Caller must free return value.
2159 *
2160 * @return fresh private key; free using #GNUNET_free
2161 */
2162struct GNUNET_CRYPTO_AbeKey *
2163GNUNET_CRYPTO_cpabe_create_key (struct GNUNET_CRYPTO_AbeMasterKey *msk,
2164 char **attrs);
2165void
2166GNUNET_CRYPTO_cpabe_delete_key (struct GNUNET_CRYPTO_AbeKey *key,
2167 int delete_pub);
2168
2169
2170/**
2171 * @ingroup crypto
2172 * Encrypt a block using sessionkey.
2173 *
2174 * @param block the block to encrypt
2175 * @param size the size of the @a block
2176 * @param sessionkey the key used to encrypt
2177 * @param iv the initialization vector to use, use INITVALUE
2178 * for streams.
2179 * @return the size of the encrypted block, -1 for errors
2180 */
2181ssize_t
2182GNUNET_CRYPTO_cpabe_encrypt (const void *block,
2183 size_t size,
2184 const char *policy,
2185 const struct GNUNET_CRYPTO_AbeMasterKey *key,
2186 void **result);
2187
2188/**
2189 * @ingroup crypto
2190 * Encrypt a block using sessionkey.
2191 *
2192 * @param block the block to encrypt
2193 * @param size the size of the @a block
2194 * @param sessionkey the key used to encrypt
2195 * @param iv the initialization vector to use, use INITVALUE
2196 * for streams.
2197 * @return the size of the encrypted block, -1 for errors
2198 */
2199ssize_t
2200GNUNET_CRYPTO_cpabe_decrypt (const void *block,
2201 size_t size,
2202 const struct GNUNET_CRYPTO_AbeKey *key,
2203 void **result);
2204
2205ssize_t
2206GNUNET_CRYPTO_cpabe_serialize_key (const struct GNUNET_CRYPTO_AbeKey *key,
2207 void **result);
2208
2209struct GNUNET_CRYPTO_AbeKey*
2210GNUNET_CRYPTO_cpabe_deserialize_key (const void *data,
2211 size_t len);
2212
2213ssize_t
2214GNUNET_CRYPTO_cpabe_serialize_master_key (const struct GNUNET_CRYPTO_AbeMasterKey *key,
2215 void **result);
2216
2217struct GNUNET_CRYPTO_AbeMasterKey*
2218GNUNET_CRYPTO_cpabe_deserialize_master_key (const void *data,
2219 size_t len);
2220
2221
2222#if 0 /* keep Emacsens' auto-indent happy */ 2140#if 0 /* keep Emacsens' auto-indent happy */
2223{ 2141{
2224#endif 2142#endif
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h
index ac418072e..cbad374b5 100644
--- a/src/include/gnunet_fs_service.h
+++ b/src/include/gnunet_fs_service.h
@@ -109,8 +109,9 @@ typedef int
109 * 109 *
110 * @param uri uri to convert to a unique key 110 * @param uri uri to convert to a unique key
111 * @param key wherer to store the unique key 111 * @param key wherer to store the unique key
112 * @return #GNUNET_OK on success
112 */ 113 */
113void 114int
114GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, 115GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
115 struct GNUNET_HashCode *key); 116 struct GNUNET_HashCode *key);
116 117
diff --git a/src/include/gnunet_identity_attribute_lib.h b/src/include/gnunet_identity_attribute_lib.h
index a6c9e1f1c..316b0bf95 100644
--- a/src/include/gnunet_identity_attribute_lib.h
+++ b/src/include/gnunet_identity_attribute_lib.h
@@ -122,7 +122,7 @@ struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry
122/** 122/**
123 * Create a new attribute claim. 123 * Create a new attribute claim.
124 * 124 *
125 * @param name the attribute name 125 * @param attr_name the attribute name
126 * @param type the attribute type 126 * @param type the attribute type
127 * @param data the attribute value 127 * @param data the attribute value
128 * @param data_size the attribute value size 128 * @param data_size the attribute value size
diff --git a/src/include/gnunet_identity_provider_service.h b/src/include/gnunet_identity_provider_service.h
index 6bc05d0f4..be935e898 100644
--- a/src/include/gnunet_identity_provider_service.h
+++ b/src/include/gnunet_identity_provider_service.h
@@ -131,6 +131,7 @@ GNUNET_IDENTITY_PROVIDER_attribute_store (struct GNUNET_IDENTITY_PROVIDER_Handle
131 * Process an attribute that was stored in the idp. 131 * Process an attribute that was stored in the idp.
132 * 132 *
133 * @param cls closure 133 * @param cls closure
134 * @param identity the identity
134 * @param attr the attribute 135 * @param attr the attribute
135 */ 136 */
136typedef void 137typedef void
@@ -211,19 +212,19 @@ typedef void
211 212
212/** 213/**
213 * Issues a ticket to another identity. The identity may use 214 * Issues a ticket to another identity. The identity may use
214 * @GNUNET_IDENTITY_PROVIDER_authorization_ticket_consume to consume the ticket 215 * GNUNET_IDENTITY_PROVIDER_ticket_consume to consume the ticket
215 * and retrieve the attributes specified in the AttributeList. 216 * and retrieve the attributes specified in the AttributeList.
216 * 217 *
217 * @param id the identity provider to use 218 * @param h the identity provider to use
218 * @param iss the issuing identity 219 * @param iss the issuing identity
219 * @param rp the subject of the ticket (the relying party) 220 * @param rp the subject of the ticket (the relying party)
220 * @param attr the attributes that the relying party is given access to 221 * @param attrs the attributes that the relying party is given access to
221 * @param cb the callback 222 * @param cb the callback
222 * @param cb_cls the callback closure 223 * @param cb_cls the callback closure
223 * @return handle to abort the operation 224 * @return handle to abort the operation
224 */ 225 */
225struct GNUNET_IDENTITY_PROVIDER_Operation * 226struct GNUNET_IDENTITY_PROVIDER_Operation *
226GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *id, 227GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
227 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss, 228 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss,
228 const struct GNUNET_CRYPTO_EcdsaPublicKey *rp, 229 const struct GNUNET_CRYPTO_EcdsaPublicKey *rp,
229 const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs, 230 const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs,
@@ -234,7 +235,7 @@ GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *i
234 * Revoked an issued ticket. The relying party will be unable to retrieve 235 * Revoked an issued ticket. The relying party will be unable to retrieve
235 * updated attributes. 236 * updated attributes.
236 * 237 *
237 * @param id the identity provider to use 238 * @param h the identity provider to use
238 * @param identity the issuing identity 239 * @param identity the issuing identity
239 * @param ticket the ticket to revoke 240 * @param ticket the ticket to revoke
240 * @param cb the callback 241 * @param cb the callback
@@ -242,7 +243,7 @@ GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *i
242 * @return handle to abort the operation 243 * @return handle to abort the operation
243 */ 244 */
244struct GNUNET_IDENTITY_PROVIDER_Operation * 245struct GNUNET_IDENTITY_PROVIDER_Operation *
245GNUNET_IDENTITY_PROVIDER_ticket_revoke (struct GNUNET_IDENTITY_PROVIDER_Handle *id, 246GNUNET_IDENTITY_PROVIDER_ticket_revoke (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
246 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, 247 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
247 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, 248 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket,
248 GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus cb, 249 GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus cb,
@@ -254,7 +255,7 @@ GNUNET_IDENTITY_PROVIDER_ticket_revoke (struct GNUNET_IDENTITY_PROVIDER_Handle *
254 * Consumes an issued ticket. The ticket is persisted 255 * Consumes an issued ticket. The ticket is persisted
255 * and used to retrieve identity information from the issuer 256 * and used to retrieve identity information from the issuer
256 * 257 *
257 * @param id the identity provider to use 258 * @param h the identity provider to use
258 * @param identity the identity that is the subject of the issued ticket (the audience) 259 * @param identity the identity that is the subject of the issued ticket (the audience)
259 * @param ticket the issued ticket to consume 260 * @param ticket the issued ticket to consume
260 * @param cb the callback to call 261 * @param cb the callback to call
@@ -262,7 +263,7 @@ GNUNET_IDENTITY_PROVIDER_ticket_revoke (struct GNUNET_IDENTITY_PROVIDER_Handle *
262 * @return handle to abort the operation 263 * @return handle to abort the operation
263 */ 264 */
264struct GNUNET_IDENTITY_PROVIDER_Operation * 265struct GNUNET_IDENTITY_PROVIDER_Operation *
265GNUNET_IDENTITY_PROVIDER_ticket_consume (struct GNUNET_IDENTITY_PROVIDER_Handle *id, 266GNUNET_IDENTITY_PROVIDER_ticket_consume (struct GNUNET_IDENTITY_PROVIDER_Handle *h,
266 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, 267 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
267 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, 268 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket,
268 GNUNET_IDENTITY_PROVIDER_AttributeResult cb, 269 GNUNET_IDENTITY_PROVIDER_AttributeResult cb,
@@ -299,7 +300,7 @@ GNUNET_IDENTITY_PROVIDER_ticket_iteration_start (struct GNUNET_IDENTITY_PROVIDER
299 * Lists all tickets that have been issued to remote 300 * Lists all tickets that have been issued to remote
300 * identites (relying parties) 301 * identites (relying parties)
301 * 302 *
302 * @param id the identity provider to use 303 * @param h the identity provider to use
303 * @param identity the issuing identity 304 * @param identity the issuing identity
304 * @param error_cb function to call on error (i.e. disconnect), 305 * @param error_cb function to call on error (i.e. disconnect),
305 * the handle is afterwards invalid 306 * the handle is afterwards invalid
diff --git a/src/include/gnunet_mst_lib.h b/src/include/gnunet_mst_lib.h
index 7a1ca7a55..fe6524eb3 100644
--- a/src/include/gnunet_mst_lib.h
+++ b/src/include/gnunet_mst_lib.h
@@ -61,7 +61,9 @@ struct GNUNET_MessageStreamTokenizer;
61 * 61 *
62 * @param cls closure 62 * @param cls closure
63 * @param message the actual message 63 * @param message the actual message
64 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing 64 * @return #GNUNET_OK on success,
65 * #GNUNET_NO to stop further processing due to disconnect (no error)
66 * #GNUNET_SYSERR to stop further processing due to error
65 */ 67 */
66typedef int 68typedef int
67(*GNUNET_MessageTokenizerCallback) (void *cls, 69(*GNUNET_MessageTokenizerCallback) (void *cls,
diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h
index d9d3d90e7..2c344749f 100644
--- a/src/include/gnunet_network_lib.h
+++ b/src/include/gnunet_network_lib.h
@@ -53,7 +53,7 @@ struct GNUNET_NETWORK_FDSet
53{ 53{
54 54
55 /** 55 /**
56 * Maximum number of any socket socket descriptor in the set (plus one) 56 * Maximum number of any socket descriptor in the set (plus one)
57 */ 57 */
58 int nsds; 58 int nsds;
59 59
@@ -464,7 +464,7 @@ GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to,
464 * @return POSIX file descriptor 464 * @return POSIX file descriptor
465 */ 465 */
466int 466int
467GNUNET_NETWORK_get_fd (struct GNUNET_NETWORK_Handle *desc); 467GNUNET_NETWORK_get_fd (const struct GNUNET_NETWORK_Handle *desc);
468 468
469 469
470/** 470/**
@@ -474,7 +474,7 @@ GNUNET_NETWORK_get_fd (struct GNUNET_NETWORK_Handle *desc);
474 * @return POSIX file descriptor 474 * @return POSIX file descriptor
475 */ 475 */
476struct sockaddr* 476struct sockaddr*
477GNUNET_NETWORK_get_addr (struct GNUNET_NETWORK_Handle *desc); 477GNUNET_NETWORK_get_addr (const struct GNUNET_NETWORK_Handle *desc);
478 478
479 479
480/** 480/**
@@ -484,7 +484,7 @@ GNUNET_NETWORK_get_addr (struct GNUNET_NETWORK_Handle *desc);
484 * @return socklen_t for sockaddr 484 * @return socklen_t for sockaddr
485 */ 485 */
486socklen_t 486socklen_t
487GNUNET_NETWORK_get_addrlen (struct GNUNET_NETWORK_Handle *desc); 487GNUNET_NETWORK_get_addrlen (const struct GNUNET_NETWORK_Handle *desc);
488 488
489 489
490/** 490/**
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 6710d749f..436adc5a4 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -2067,7 +2067,11 @@ extern "C"
2067/** S->C: slave join acknowledgement */ 2067/** S->C: slave join acknowledgement */
2068#define GNUNET_MESSAGE_TYPE_PSYC_SLAVE_JOIN_ACK 684 2068#define GNUNET_MESSAGE_TYPE_PSYC_SLAVE_JOIN_ACK 684
2069 2069
2070/* 685-686 */ 2070/** C->S: request to part from a channel */
2071#define GNUNET_MESSAGE_TYPE_PSYC_PART_REQUEST 685
2072
2073/** S->C: acknowledgement that a slave of master parted from a channel */
2074#define GNUNET_MESSAGE_TYPE_PSYC_PART_ACK 686
2071 2075
2072/** M->S->C: incoming join request from multicast */ 2076/** M->S->C: incoming join request from multicast */
2073#define GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST 687 2077#define GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST 687
@@ -2258,6 +2262,7 @@ extern "C"
2258 */ 2262 */
2259#define GNUNET_MESSAGE_TYPE_MULTICAST_PART_ACK 755 2263#define GNUNET_MESSAGE_TYPE_MULTICAST_PART_ACK 755
2260 2264
2265// FIXME: this is never used!
2261/** 2266/**
2262 * Group terminated. 2267 * Group terminated.
2263 */ 2268 */
@@ -2398,35 +2403,38 @@ extern "C"
2398/** C->S: request to leave a place */ 2403/** C->S: request to leave a place */
2399#define GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE 848 2404#define GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE 848
2400 2405
2406/** S->C: place leave acknowledgement */
2407#define GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE_ACK 849
2408
2401/** C->S: add place to GNS zone */ 2409/** C->S: add place to GNS zone */
2402#define GNUNET_MESSAGE_TYPE_SOCIAL_ZONE_ADD_PLACE 849 2410#define GNUNET_MESSAGE_TYPE_SOCIAL_ZONE_ADD_PLACE 850
2403 2411
2404/** C->S: add nym to GNS zone */ 2412/** C->S: add nym to GNS zone */
2405#define GNUNET_MESSAGE_TYPE_SOCIAL_ZONE_ADD_NYM 850 2413#define GNUNET_MESSAGE_TYPE_SOCIAL_ZONE_ADD_NYM 851
2406 2414
2407/** C->S: connect application */ 2415/** C->S: connect application */
2408#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_CONNECT 851 2416#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_CONNECT 852
2409 2417
2410/** C->S: detach a place from application */ 2418/** C->S: detach a place from application */
2411#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_DETACH 852 2419#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_DETACH 853
2412 2420
2413/** S->C: notify about an existing ego */ 2421/** S->C: notify about an existing ego */
2414#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO 853 2422#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO 854
2415 2423
2416/** S->C: end of ego list */ 2424/** S->C: end of ego list */
2417#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO_END 854 2425#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO_END 855
2418 2426
2419/** S->C: notify about an existing place */ 2427/** S->C: notify about an existing place */
2420#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE 855 2428#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE 856
2421 2429
2422/** S->C: end of place list */ 2430/** S->C: end of place list */
2423#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE_END 856 2431#define GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE_END 857
2424 2432
2425/** C->S: set message processing flags */ 2433/** C->S: set message processing flags */
2426#define GNUNET_MESSAGE_TYPE_SOCIAL_MSG_PROC_SET 860 2434#define GNUNET_MESSAGE_TYPE_SOCIAL_MSG_PROC_SET 858
2427 2435
2428/** C->S: clear message processing flags */ 2436/** C->S: clear message processing flags */
2429#define GNUNET_MESSAGE_TYPE_SOCIAL_MSG_PROC_CLEAR 861 2437#define GNUNET_MESSAGE_TYPE_SOCIAL_MSG_PROC_CLEAR 859
2430 2438
2431/******************************************************************************* 2439/*******************************************************************************
2432 * X-VINE DHT messages 2440 * X-VINE DHT messages
diff --git a/src/include/gnunet_rest_lib.h b/src/include/gnunet_rest_lib.h
index 5bf04636b..41b85401d 100644
--- a/src/include/gnunet_rest_lib.h
+++ b/src/include/gnunet_rest_lib.h
@@ -32,7 +32,7 @@
32#define GNUNET_REST_LIB_H 32#define GNUNET_REST_LIB_H
33 33
34#include "gnunet_util_lib.h" 34#include "gnunet_util_lib.h"
35#include "microhttpd.h" 35#include <microhttpd.h>
36 36
37#define GNUNET_REST_HANDLER_END {NULL, NULL, NULL} 37#define GNUNET_REST_HANDLER_END {NULL, NULL, NULL}
38 38
@@ -113,7 +113,7 @@ typedef void (*GNUNET_REST_ResultProcessor) (void *cls,
113 * 113 *
114 * @param url URL to check 114 * @param url URL to check
115 * @param namespace namespace to check against 115 * @param namespace namespace to check against
116 * @retun GNUNET_YES if namespace matches 116 * @return GNUNET_YES if namespace matches
117 */ 117 */
118int 118int
119GNUNET_REST_namespace_match (const char *url, const char *namespace); 119GNUNET_REST_namespace_match (const char *url, const char *namespace);
@@ -122,7 +122,7 @@ GNUNET_REST_namespace_match (const char *url, const char *namespace);
122 * Create REST MHD response 122 * Create REST MHD response
123 * 123 *
124 * @param data result 124 * @param data result
125 * @retun MHD response 125 * @return MHD response
126 */ 126 */
127 struct MHD_Response* 127 struct MHD_Response*
128GNUNET_REST_create_response (const char *data); 128GNUNET_REST_create_response (const char *data);
diff --git a/src/include/gnunet_rest_plugin.h b/src/include/gnunet_rest_plugin.h
index ecd5f66f1..424dbb1fc 100644
--- a/src/include/gnunet_rest_plugin.h
+++ b/src/include/gnunet_rest_plugin.h
@@ -57,7 +57,7 @@ struct GNUNET_REST_Plugin
57 57
58 /** 58 /**
59 * Plugin name. Used as the namespace for the API. 59 * Plugin name. Used as the namespace for the API.
60 * e.g. http://hostname:port/<name> 60 * e.g. http://hostname:port/name
61 */ 61 */
62 char *name; 62 char *name;
63 63
diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h
index a855ab8ab..d2805a685 100644
--- a/src/include/gnunet_scheduler_lib.h
+++ b/src/include/gnunet_scheduler_lib.h
@@ -152,14 +152,14 @@ struct GNUNET_SCHEDULER_FdInfo
152 * NULL if this is about a file handle or if no network 152 * NULL if this is about a file handle or if no network
153 * handle was given to the scheduler originally. 153 * handle was given to the scheduler originally.
154 */ 154 */
155 struct GNUNET_NETWORK_Handle *fd; 155 const struct GNUNET_NETWORK_Handle *fd;
156 156
157 /** 157 /**
158 * GNUnet file handle the event is about, matches @a sock, 158 * GNUnet file handle the event is about, matches @a sock,
159 * NULL if this is about a network socket or if no network 159 * NULL if this is about a network socket or if no network
160 * handle was given to the scheduler originally. 160 * handle was given to the scheduler originally.
161 */ 161 */
162 struct GNUNET_DISK_FileHandle *fh; 162 const struct GNUNET_DISK_FileHandle *fh;
163 163
164 /** 164 /**
165 * Type of the event that was generated related to @e sock. 165 * Type of the event that was generated related to @e sock.
@@ -216,17 +216,18 @@ struct GNUNET_SCHEDULER_TaskContext
216 216
217/** 217/**
218 * Function used by event-loop implementations to signal the scheduler 218 * Function used by event-loop implementations to signal the scheduler
219 * that a particular @a task is ready due to an event of type @a et. 219 * that a particular @a task is ready due to an event specified in the
220 * et field of @a fdi.
220 * 221 *
221 * This function will then queue the task to notify the application 222 * This function will then queue the task to notify the application
222 * that the task is ready (with the respective priority). 223 * that the task is ready (with the respective priority).
223 * 224 *
224 * @param task the task that is ready 225 * @param task the task that is ready
225 * @param et information about why the task is ready 226 * @param fdi information about the related FD
226 */ 227 */
227void 228void
228GNUNET_SCHEDULER_task_ready (struct GNUNET_SCHEDULER_Task *task, 229GNUNET_SCHEDULER_task_ready (struct GNUNET_SCHEDULER_Task *task,
229 enum GNUNET_SCHEDULER_EventType et); 230 struct GNUNET_SCHEDULER_FdInfo *fdi);
230 231
231 232
232/** 233/**
@@ -241,15 +242,16 @@ struct GNUNET_SCHEDULER_Handle;
241 * there are tasks left to run just to give other tasks a chance as 242 * there are tasks left to run just to give other tasks a chance as
242 * well. If we return #GNUNET_YES, the driver should call this 243 * well. If we return #GNUNET_YES, the driver should call this
243 * function again as soon as possible, while if we return #GNUNET_NO 244 * function again as soon as possible, while if we return #GNUNET_NO
244 * it must block until the operating system has more work as the 245 * it must block until either the operating system has more work (the
245 * scheduler has no more work to do right now. 246 * scheduler has no more work to do right now) or the timeout set by
247 * the scheduler (using the set_wakeup callback) is reached.
246 * 248 *
247 * @param sh scheduler handle that was given to the `loop` 249 * @param sh scheduler handle that was given to the `loop`
248 * @return #GNUNET_OK if there are more tasks that are ready, 250 * @return #GNUNET_OK if there are more tasks that are ready,
249 * and thus we would like to run more (yield to avoid 251 * and thus we would like to run more (yield to avoid
250 * blocking other activities for too long) 252 * blocking other activities for too long)
251 * #GNUNET_NO if we are done running tasks (yield to block) 253 * #GNUNET_NO if we are done running tasks (yield to block)
252 * #GNUNET_SYSERR on error 254 * #GNUNET_SYSERR on error, e.g. no tasks were ready
253 */ 255 */
254int 256int
255GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh); 257GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh);
@@ -268,8 +270,11 @@ struct GNUNET_SCHEDULER_Driver
268 void *cls; 270 void *cls;
269 271
270 /** 272 /**
271 * Add a @a task to be run if the conditions given 273 * Add a @a task to be run if the conditions specified in the
272 * in @a fdi are satisfied. 274 * et field of the given @a fdi are satisfied. The et field will
275 * be cleared after this call and the driver is expected to set
276 * the type of the actual event before passing @a fdi to
277 * #GNUNET_SCHEDULER_task_ready.
273 * 278 *
274 * @param cls closure 279 * @param cls closure
275 * @param task task to add 280 * @param task task to add
@@ -280,21 +285,21 @@ struct GNUNET_SCHEDULER_Driver
280 int 285 int
281 (*add)(void *cls, 286 (*add)(void *cls,
282 struct GNUNET_SCHEDULER_Task *task, 287 struct GNUNET_SCHEDULER_Task *task,
283 struct GNUNET_SCHEDULER_FdInfo *fdi); 288 struct GNUNET_SCHEDULER_FdInfo *fdi);
284 289
285 /** 290 /**
286 * Delete a @a task from the set of tasks to be run. 291 * Delete a @a task from the set of tasks to be run. A task may
292 * comprise multiple FdInfo entries previously added with the add
293 * function. The driver is expected to delete them all.
287 * 294 *
288 * @param cls closure 295 * @param cls closure
289 * @param task task to delete 296 * @param task task to delete
290 * @param fdi conditions to watch for (must match @e add call)
291 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 297 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
292 * (i.e. @a task or @a fdi do not match prior @e add call) 298 * (i.e. @a task does not match prior @e add call)
293 */ 299 */
294 int 300 int
295 (*del)(void *cls, 301 (*del)(void *cls,
296 struct GNUNET_SCHEDULER_Task *task, 302 struct GNUNET_SCHEDULER_Task *task);
297 const struct GNUNET_SCHEDULER_FdInfo *fdi);
298 303
299 /** 304 /**
300 * Set time at which we definitively want to get a wakeup call. 305 * Set time at which we definitively want to get a wakeup call.
@@ -309,7 +314,10 @@ struct GNUNET_SCHEDULER_Driver
309 /** 314 /**
310 * Event loop's "main" function, to be called from 315 * Event loop's "main" function, to be called from
311 * #GNUNET_SCHEDULER_run_with_driver() to actually 316 * #GNUNET_SCHEDULER_run_with_driver() to actually
312 * launch the loop. 317 * launch the loop. The loop should run as long as
318 * tasks (added by the add callback) are available
319 * OR the wakeup time (added by the set_wakeup
320 * callback) is not FOREVER.
313 * 321 *
314 * @param cls closure 322 * @param cls closure
315 * @param sh scheduler handle to pass to 323 * @param sh scheduler handle to pass to
@@ -359,7 +367,7 @@ GNUNET_SCHEDULER_run_with_driver (const struct GNUNET_SCHEDULER_Driver *driver,
359 * 367 *
360 * @return NULL on error 368 * @return NULL on error
361 */ 369 */
362const struct GNUNET_SCHEDULER_Driver * 370struct GNUNET_SCHEDULER_Driver *
363GNUNET_SCHEDULER_driver_select (void); 371GNUNET_SCHEDULER_driver_select (void);
364 372
365 373
diff --git a/src/include/gnunet_service_lib.h b/src/include/gnunet_service_lib.h
index aacafe956..dda827c95 100644
--- a/src/include/gnunet_service_lib.h
+++ b/src/include/gnunet_service_lib.h
@@ -366,11 +366,16 @@ GNUNET_SERVICE_client_disable_continue_warning (struct GNUNET_SERVICE_Client *c)
366/** 366/**
367 * Ask the server to disconnect from the given client. This is the 367 * Ask the server to disconnect from the given client. This is the
368 * same as returning #GNUNET_SYSERR within the check procedure when 368 * same as returning #GNUNET_SYSERR within the check procedure when
369 * handling a message, wexcept that it allows dropping of a client even 369 * handling a message, except that it allows dropping of a client even
370 * when not handling a message from that client. The `disconnect_cb` 370 * when not handling a message from that client. The `disconnect_cb`
371 * will be called on @a c even if the application closes the connection 371 * will be called on @a c even if the application closes the connection
372 * using this function. 372 * using this function.
373 * 373 *
374 * This function should be called (outside of util's internal logic)
375 * if (and usually only if) the client has violated the
376 * protocol. Otherwise, we should leave it to the client to disconnect
377 * from the service.
378 *
374 * @param c client to disconnect now 379 * @param c client to disconnect now
375 */ 380 */
376void 381void
diff --git a/src/include/gnunet_set_service.h b/src/include/gnunet_set_service.h
index a2999aebc..0c14aa945 100644
--- a/src/include/gnunet_set_service.h
+++ b/src/include/gnunet_set_service.h
@@ -530,6 +530,7 @@ GNUNET_SET_iterate (struct GNUNET_SET_Handle *set,
530 GNUNET_SET_ElementIterator iter, 530 GNUNET_SET_ElementIterator iter,
531 void *iter_cls); 531 void *iter_cls);
532 532
533
533/** 534/**
534 * Stop iteration over all elements in the given set. Can only 535 * Stop iteration over all elements in the given set. Can only
535 * be called before the iteration has "naturally" completed its 536 * be called before the iteration has "naturally" completed its
@@ -540,6 +541,7 @@ GNUNET_SET_iterate (struct GNUNET_SET_Handle *set,
540void 541void
541GNUNET_SET_iterate_cancel (struct GNUNET_SET_Handle *set); 542GNUNET_SET_iterate_cancel (struct GNUNET_SET_Handle *set);
542 543
544
543/** 545/**
544 * Create a copy of an element. The copy 546 * Create a copy of an element. The copy
545 * must be GNUNET_free-d by the caller. 547 * must be GNUNET_free-d by the caller.
@@ -550,6 +552,7 @@ GNUNET_SET_iterate_cancel (struct GNUNET_SET_Handle *set);
550struct GNUNET_SET_Element * 552struct GNUNET_SET_Element *
551GNUNET_SET_element_dup (const struct GNUNET_SET_Element *element); 553GNUNET_SET_element_dup (const struct GNUNET_SET_Element *element);
552 554
555
553/** 556/**
554 * Hash a set element. 557 * Hash a set element.
555 * 558 *
diff --git a/src/jsonapi/Makefile.am b/src/jsonapi/Makefile.am
index 3cf3a4cd2..054d3c550 100644
--- a/src/jsonapi/Makefile.am
+++ b/src/jsonapi/Makefile.am
@@ -24,7 +24,7 @@ libgnunetjsonapi_la_LDFLAGS = \
24 -version-info 0:0:0 \ 24 -version-info 0:0:0 \
25 -no-undefined 25 -no-undefined
26libgnunetjsonapi_la_SOURCES = \ 26libgnunetjsonapi_la_SOURCES = \
27 jsonapi_document.c \ 27 jsonapi_document.c jsonapi_objects.h \
28 jsonapi_resource.c \ 28 jsonapi_resource.c \
29 jsonapi_error.c \ 29 jsonapi_error.c \
30 jsonapi_relationship.c 30 jsonapi_relationship.c
diff --git a/src/jsonapi/test_jsonapi.c b/src/jsonapi/test_jsonapi.c
index 379dab9af..36c7b5c6c 100644
--- a/src/jsonapi/test_jsonapi.c
+++ b/src/jsonapi/test_jsonapi.c
@@ -1,18 +1,18 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 (C) 2015, 2016 GNUnet e.V. 3 (C) 2015, 2016 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify it under the 5 GNUnet is free software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the Free Software 6 terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 3, or (at your option) any later version. 7 Foundation; either version 3, or (at your option) any later version.
8 8
9 GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY 9 GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 12
13 You should have received a copy of the GNU General Public License along with 13 You should have received a copy of the GNU General Public License along with
14 GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> 14 GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
15*/ 15 */
16 16
17/** 17/**
18 * @file json/test_jsonapi.c 18 * @file json/test_jsonapi.c
@@ -24,7 +24,7 @@
24#include "gnunet_jsonapi_lib.h" 24#include "gnunet_jsonapi_lib.h"
25#include "gnunet_json_lib.h" 25#include "gnunet_json_lib.h"
26 26
27#define TEST_JSONAPI_DOCUMENT "{\"data\":{\"id\":\"1\",\"type\":\"bar\",\"attributes\":{\"foo\":\"bar\"}}}" 27#define TEST_JSONAPI_DOCUMENT "{\"data\":[{\"id\":\"1\",\"type\":\"bar\",\"attributes\":{\"foo\":\"bar\"}}]}"
28 28
29#define TEST_JSONAPI_DOCUMENT_ERR "{\"errors\":[{\"id\":\"1\",\"status\":\"403\",\"code\":\"23\", \"title\":\"Error\", \"detail\":\"Error details\"}]}" 29#define TEST_JSONAPI_DOCUMENT_ERR "{\"errors\":[{\"id\":\"1\",\"status\":\"403\",\"code\":\"23\", \"title\":\"Error\", \"detail\":\"Error details\"}]}"
30 30
@@ -74,7 +74,8 @@ test_document ()
74 json_t *doc_json; 74 json_t *doc_json;
75 json_t *data_js; 75 json_t *data_js;
76 json_error_t err; 76 json_error_t err;
77 77 int ret;
78
78 obj = GNUNET_JSONAPI_document_new (); 79 obj = GNUNET_JSONAPI_document_new ();
79 res = GNUNET_JSONAPI_resource_new ("bar", 80 res = GNUNET_JSONAPI_resource_new ("bar",
80 "1"); 81 "1");
@@ -94,11 +95,11 @@ test_document ()
94 JSON_DECODE_ANY, 95 JSON_DECODE_ANY,
95 &err); 96 &err);
96 GNUNET_assert (NULL != data_js); 97 GNUNET_assert (NULL != data_js);
97 GNUNET_assert (0 != json_equal (data_js, doc_json)); 98 ret = json_equal (data_js, doc_json) ? 0 : 1;
98 GNUNET_JSONAPI_document_delete (obj); 99 GNUNET_JSONAPI_document_delete (obj);
99 json_decref (data_js); 100 json_decref (data_js);
100 json_decref (doc_json); 101 json_decref (doc_json);
101 return 0; 102 return ret;
102} 103}
103 104
104static int 105static int
@@ -106,6 +107,7 @@ test_serialize ()
106{ 107{
107 struct GNUNET_JSONAPI_Document *obj; 108 struct GNUNET_JSONAPI_Document *obj;
108 char* tmp_data; 109 char* tmp_data;
110 int ret;
109 json_t* data_js; 111 json_t* data_js;
110 json_t* tmp_data_js; 112 json_t* tmp_data_js;
111 json_error_t err; 113 json_error_t err;
@@ -125,11 +127,11 @@ test_serialize ()
125 GNUNET_JSON_parse_free (jsonapispec); 127 GNUNET_JSON_parse_free (jsonapispec);
126 tmp_data_js = json_loads (tmp_data, JSON_DECODE_ANY, &err); 128 tmp_data_js = json_loads (tmp_data, JSON_DECODE_ANY, &err);
127 GNUNET_assert (NULL != tmp_data_js); 129 GNUNET_assert (NULL != tmp_data_js);
128 GNUNET_assert (0 != json_equal (tmp_data_js, data_js)); 130 ret = (1 == json_equal (tmp_data_js, data_js)) ? 0 : 1;
129 json_decref (data_js); 131 json_decref (data_js);
130 json_decref (tmp_data_js); 132 json_decref (tmp_data_js);
131 GNUNET_free (tmp_data); 133 GNUNET_free (tmp_data);
132 return 0; 134 return ret;
133} 135}
134 136
135/** 137/**
diff --git a/src/multicast/Makefile.am b/src/multicast/Makefile.am
index 13212bca3..48185e1a4 100644
--- a/src/multicast/Makefile.am
+++ b/src/multicast/Makefile.am
@@ -19,7 +19,7 @@ endif
19lib_LTLIBRARIES = libgnunetmulticast.la 19lib_LTLIBRARIES = libgnunetmulticast.la
20 20
21libgnunetmulticast_la_SOURCES = \ 21libgnunetmulticast_la_SOURCES = \
22 multicast_api.c 22 multicast_api.c multicast.h
23libgnunetmulticast_la_LIBADD = \ 23libgnunetmulticast_la_LIBADD = \
24 $(top_builddir)/src/util/libgnunetutil.la \ 24 $(top_builddir)/src/util/libgnunetutil.la \
25 $(GN_LIBINTL) $(XLIB) 25 $(GN_LIBINTL) $(XLIB)
diff --git a/src/multicast/gnunet-service-multicast.c b/src/multicast/gnunet-service-multicast.c
index 2f4dc8a14..d01227e2c 100644
--- a/src/multicast/gnunet-service-multicast.c
+++ b/src/multicast/gnunet-service-multicast.c
@@ -137,6 +137,7 @@ struct Channel
137 */ 137 */
138 struct GNUNET_CADET_Channel *channel; 138 struct GNUNET_CADET_Channel *channel;
139 139
140 // FIXME: not used
140 /** 141 /**
141 * CADET transmission handle. 142 * CADET transmission handle.
142 */ 143 */
@@ -228,7 +229,7 @@ struct Group
228 /** 229 /**
229 * Is the client disconnected? #GNUNET_YES or #GNUNET_NO 230 * Is the client disconnected? #GNUNET_YES or #GNUNET_NO
230 */ 231 */
231 uint8_t disconnected; 232 uint8_t is_disconnected;
232 233
233 /** 234 /**
234 * Is this an origin (#GNUNET_YES), or member (#GNUNET_NO)? 235 * Is this an origin (#GNUNET_YES), or member (#GNUNET_NO)?
@@ -365,6 +366,8 @@ client_send_join_decision (struct Member *mem,
365static void 366static void
366shutdown_task (void *cls) 367shutdown_task (void *cls)
367{ 368{
369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
370 "shutting down\n");
368 if (NULL != cadet) 371 if (NULL != cadet)
369 { 372 {
370 GNUNET_CADET_disconnect (cadet); 373 GNUNET_CADET_disconnect (cadet);
@@ -420,6 +423,11 @@ cleanup_member (struct Member *mem)
420 GNUNET_free (mem->join_dcsn); 423 GNUNET_free (mem->join_dcsn);
421 mem->join_dcsn = NULL; 424 mem->join_dcsn = NULL;
422 } 425 }
426 if (NULL != mem->origin_channel)
427 {
428 GNUNET_CADET_channel_destroy (mem->origin_channel->channel);
429 mem->origin_channel = NULL;
430 }
423 GNUNET_CONTAINER_multihashmap_remove (members, &grp->pub_key_hash, mem); 431 GNUNET_CONTAINER_multihashmap_remove (members, &grp->pub_key_hash, mem);
424 GNUNET_free (mem); 432 GNUNET_free (mem);
425} 433}
@@ -553,36 +561,47 @@ client_send (struct GNUNET_SERVICE_Client *client,
553 * Send message to all clients connected to the group. 561 * Send message to all clients connected to the group.
554 */ 562 */
555static void 563static void
556client_send_group (const struct Group *grp, 564client_send_group_keep_envelope (const struct Group *grp,
557 const struct GNUNET_MessageHeader *msg) 565 struct GNUNET_MQ_Envelope *env)
558{ 566{
559 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 567 struct ClientList *cli = grp->clients_head;
560 "%p Sending message to all clients of the group.\n", grp);
561 568
562 struct ClientList *cl = grp->clients_head; 569 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
563 while (NULL != cl) 570 "%p Sending message to all clients of the group.\n",
571 grp);
572 while (NULL != cli)
564 { 573 {
565 struct GNUNET_MQ_Envelope * 574 GNUNET_MQ_send_copy (GNUNET_SERVICE_client_get_mq (cli->client),
566 env = GNUNET_MQ_msg_copy (msg); 575 env);
567 576 cli = cli->next;
568 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cl->client),
569 env);
570 cl = cl->next;
571 } 577 }
572} 578}
573 579
574 580
575/** 581/**
582 * Send message to all clients connected to the group and
583 * takes care of freeing @env.
584 */
585static void
586client_send_group (const struct Group *grp,
587 struct GNUNET_MQ_Envelope *env)
588{
589 client_send_group_keep_envelope (grp, env);
590 GNUNET_MQ_discard (env);
591}
592
593
594/**
576 * Iterator callback for sending a message to origin clients. 595 * Iterator callback for sending a message to origin clients.
577 */ 596 */
578static int 597static int
579client_send_origin_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash, 598client_send_origin_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash,
580 void *origin) 599 void *origin)
581{ 600{
582 const struct GNUNET_MessageHeader *msg = cls; 601 struct GNUNET_MQ_Envelope *env = cls;
583 struct Member *orig = origin; 602 struct Member *orig = origin;
584 603
585 client_send_group (&orig->group, msg); 604 client_send_group_keep_envelope (&orig->group, env);
586 return GNUNET_YES; 605 return GNUNET_YES;
587} 606}
588 607
@@ -594,12 +613,12 @@ static int
594client_send_member_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash, 613client_send_member_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash,
595 void *member) 614 void *member)
596{ 615{
597 const struct GNUNET_MessageHeader *msg = cls; 616 struct GNUNET_MQ_Envelope *env = cls;
598 struct Member *mem = member; 617 struct Member *mem = member;
599 618
600 if (NULL != mem->join_dcsn) 619 if (NULL != mem->join_dcsn)
601 { /* Only send message to admitted members */ 620 { /* Only send message to admitted members */
602 client_send_group (&mem->group, msg); 621 client_send_group_keep_envelope (&mem->group, env);
603 } 622 }
604 return GNUNET_YES; 623 return GNUNET_YES;
605} 624}
@@ -615,15 +634,16 @@ client_send_member_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash,
615 */ 634 */
616static int 635static int
617client_send_all (struct GNUNET_HashCode *pub_key_hash, 636client_send_all (struct GNUNET_HashCode *pub_key_hash,
618 const struct GNUNET_MessageHeader *msg) 637 struct GNUNET_MQ_Envelope *env)
619{ 638{
620 int n = 0; 639 int n = 0;
621 n += GNUNET_CONTAINER_multihashmap_get_multiple (origins, pub_key_hash, 640 n += GNUNET_CONTAINER_multihashmap_get_multiple (origins, pub_key_hash,
622 client_send_origin_cb, 641 client_send_origin_cb,
623 (void *) msg); 642 (void *) env);
624 n += GNUNET_CONTAINER_multihashmap_get_multiple (members, pub_key_hash, 643 n += GNUNET_CONTAINER_multihashmap_get_multiple (members, pub_key_hash,
625 client_send_member_cb, 644 client_send_member_cb,
626 (void *) msg); 645 (void *) env);
646 GNUNET_MQ_discard (env);
627 return n; 647 return n;
628} 648}
629 649
@@ -636,14 +656,15 @@ client_send_all (struct GNUNET_HashCode *pub_key_hash,
636 */ 656 */
637static int 657static int
638client_send_random (struct GNUNET_HashCode *pub_key_hash, 658client_send_random (struct GNUNET_HashCode *pub_key_hash,
639 const struct GNUNET_MessageHeader *msg) 659 struct GNUNET_MQ_Envelope *env)
640{ 660{
641 int n = 0; 661 int n = 0;
642 n = GNUNET_CONTAINER_multihashmap_get_random (origins, client_send_origin_cb, 662 n = GNUNET_CONTAINER_multihashmap_get_random (origins, client_send_origin_cb,
643 (void *) msg); 663 (void *) env);
644 if (n <= 0) 664 if (n <= 0)
645 n = GNUNET_CONTAINER_multihashmap_get_random (members, client_send_member_cb, 665 n = GNUNET_CONTAINER_multihashmap_get_random (members, client_send_member_cb,
646 (void *) msg); 666 (void *) env);
667 GNUNET_MQ_discard (env);
647 return n; 668 return n;
648} 669}
649 670
@@ -658,12 +679,12 @@ client_send_random (struct GNUNET_HashCode *pub_key_hash,
658 */ 679 */
659static int 680static int
660client_send_origin (struct GNUNET_HashCode *pub_key_hash, 681client_send_origin (struct GNUNET_HashCode *pub_key_hash,
661 const struct GNUNET_MessageHeader *msg) 682 struct GNUNET_MQ_Envelope *env)
662{ 683{
663 int n = 0; 684 int n = 0;
664 n += GNUNET_CONTAINER_multihashmap_get_multiple (origins, pub_key_hash, 685 n += GNUNET_CONTAINER_multihashmap_get_multiple (origins, pub_key_hash,
665 client_send_origin_cb, 686 client_send_origin_cb,
666 (void *) msg); 687 (void *) env);
667 return n; 688 return n;
668} 689}
669 690
@@ -677,17 +698,12 @@ client_send_origin (struct GNUNET_HashCode *pub_key_hash,
677static void 698static void
678client_send_ack (struct GNUNET_HashCode *pub_key_hash) 699client_send_ack (struct GNUNET_HashCode *pub_key_hash)
679{ 700{
701 struct GNUNET_MQ_Envelope *env;
702
680 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 703 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
681 "Sending message ACK to client.\n"); 704 "Sending message ACK to client.\n");
682 705 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_MULTICAST_FRAGMENT_ACK);
683 static struct GNUNET_MessageHeader *msg = NULL; 706 client_send_all (pub_key_hash, env);
684 if (NULL == msg)
685 {
686 msg = GNUNET_malloc (sizeof (*msg));
687 msg->type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_FRAGMENT_ACK);
688 msg->size = htons (sizeof (*msg));
689 }
690 client_send_all (pub_key_hash, msg);
691} 707}
692 708
693 709
@@ -983,7 +999,8 @@ handle_cadet_join_request (void *cls,
983 chn->peer = req->peer; 999 chn->peer = req->peer;
984 chn->join_status = JOIN_WAITING; 1000 chn->join_status = JOIN_WAITING;
985 1001
986 client_send_all (&group_pub_hash, &req->header); 1002 client_send_all (&group_pub_hash,
1003 GNUNET_MQ_msg_copy (&req->header));
987} 1004}
988 1005
989 1006
@@ -1102,7 +1119,8 @@ handle_cadet_message (void *cls,
1102{ 1119{
1103 struct Channel *chn = cls; 1120 struct Channel *chn = cls;
1104 GNUNET_CADET_receive_done (chn->channel); 1121 GNUNET_CADET_receive_done (chn->channel);
1105 client_send_all (&chn->group_pub_hash, &msg->header); 1122 client_send_all (&chn->group_pub_hash,
1123 GNUNET_MQ_msg_copy (&msg->header));
1106} 1124}
1107 1125
1108 1126
@@ -1153,30 +1171,32 @@ handle_cadet_request (void *cls,
1153{ 1171{
1154 struct Channel *chn = cls; 1172 struct Channel *chn = cls;
1155 GNUNET_CADET_receive_done (chn->channel); 1173 GNUNET_CADET_receive_done (chn->channel);
1156 client_send_origin (&chn->group_pub_hash, &req->header); 1174 client_send_origin (&chn->group_pub_hash,
1175 GNUNET_MQ_msg_copy (&req->header));
1157} 1176}
1158 1177
1159 1178
1160static int 1179// FIXME: do checks in handle_cadet_replay_request
1161check_cadet_replay_request (void *cls, 1180//static int
1162 const struct MulticastReplayRequestMessage *req) 1181//check_cadet_replay_request (void *cls,
1163{ 1182// const struct MulticastReplayRequestMessage *req)
1164 uint16_t size = ntohs (req->header.size); 1183//{
1165 if (size < sizeof (*req)) 1184// uint16_t size = ntohs (req->header.size);
1166 { 1185// if (size < sizeof (*req))
1167 GNUNET_break_op (0); 1186// {
1168 return GNUNET_SYSERR; 1187// GNUNET_break_op (0);
1169 } 1188// return GNUNET_SYSERR;
1170 1189// }
1171 struct Channel *chn = cls; 1190//
1172 if (NULL == chn) 1191// struct Channel *chn = cls;
1173 { 1192// if (NULL == chn)
1174 GNUNET_break_op (0); 1193// {
1175 return GNUNET_SYSERR; 1194// GNUNET_break_op (0);
1176 } 1195// return GNUNET_SYSERR;
1177 1196// }
1178 return GNUNET_OK; 1197//
1179} 1198// return GNUNET_OK;
1199//}
1180 1200
1181 1201
1182/** 1202/**
@@ -1187,6 +1207,7 @@ handle_cadet_replay_request (void *cls,
1187 const struct MulticastReplayRequestMessage *req) 1207 const struct MulticastReplayRequestMessage *req)
1188{ 1208{
1189 struct Channel *chn = cls; 1209 struct Channel *chn = cls;
1210
1190 GNUNET_CADET_receive_done (chn->channel); 1211 GNUNET_CADET_receive_done (chn->channel);
1191 1212
1192 struct MulticastReplayRequestMessage rep = *req; 1213 struct MulticastReplayRequestMessage rep = *req;
@@ -1203,12 +1224,16 @@ handle_cadet_replay_request (void *cls,
1203 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 1224 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1204 } 1225 }
1205 struct GNUNET_HashCode key_hash; 1226 struct GNUNET_HashCode key_hash;
1206 replay_key_hash (rep.fragment_id, rep.message_id, rep.fragment_offset, 1227 replay_key_hash (rep.fragment_id,
1207 rep.flags, &key_hash); 1228 rep.message_id,
1229 rep.fragment_offset,
1230 rep.flags,
1231 &key_hash);
1208 GNUNET_CONTAINER_multihashmap_put (grp_replay_req, &key_hash, chn, 1232 GNUNET_CONTAINER_multihashmap_put (grp_replay_req, &key_hash, chn,
1209 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1233 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1210 1234
1211 client_send_random (&chn->group_pub_hash, &rep.header); 1235 client_send_random (&chn->group_pub_hash,
1236 GNUNET_MQ_msg_copy (&rep.header));
1212} 1237}
1213 1238
1214 1239
@@ -1290,10 +1315,10 @@ cadet_channel_create (struct Group *grp, struct GNUNET_PeerIdentity *peer)
1290 struct MulticastJoinDecisionMessageHeader, 1315 struct MulticastJoinDecisionMessageHeader,
1291 chn), 1316 chn),
1292 1317
1293 GNUNET_MQ_hd_var_size (cadet_replay_request, 1318 GNUNET_MQ_hd_fixed_size (cadet_replay_request,
1294 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST, 1319 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST,
1295 struct MulticastReplayRequestMessage, 1320 struct MulticastReplayRequestMessage,
1296 chn), 1321 chn),
1297 1322
1298 GNUNET_MQ_hd_var_size (cadet_replay_response, 1323 GNUNET_MQ_hd_var_size (cadet_replay_response,
1299 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_RESPONSE, 1324 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_RESPONSE,
@@ -1357,6 +1382,7 @@ handle_client_origin_start (void *cls,
1357 grp->is_origin = GNUNET_YES; 1382 grp->is_origin = GNUNET_YES;
1358 grp->pub_key = pub_key; 1383 grp->pub_key = pub_key;
1359 grp->pub_key_hash = pub_key_hash; 1384 grp->pub_key_hash = pub_key_hash;
1385 grp->is_disconnected = GNUNET_NO;
1360 1386
1361 GNUNET_CONTAINER_multihashmap_put (origins, &grp->pub_key_hash, orig, 1387 GNUNET_CONTAINER_multihashmap_put (origins, &grp->pub_key_hash, orig,
1362 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 1388 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
@@ -1379,10 +1405,10 @@ handle_client_origin_start (void *cls,
1379 struct MulticastJoinRequestMessage, 1405 struct MulticastJoinRequestMessage,
1380 grp), 1406 grp),
1381 1407
1382 GNUNET_MQ_hd_var_size (cadet_replay_request, 1408 GNUNET_MQ_hd_fixed_size (cadet_replay_request,
1383 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST, 1409 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST,
1384 struct MulticastReplayRequestMessage, 1410 struct MulticastReplayRequestMessage,
1385 grp), 1411 grp),
1386 1412
1387 GNUNET_MQ_hd_var_size (cadet_replay_response, 1413 GNUNET_MQ_hd_var_size (cadet_replay_response,
1388 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_RESPONSE, 1414 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_RESPONSE,
@@ -1484,6 +1510,7 @@ handle_client_member_join (void *cls,
1484 grp->is_origin = GNUNET_NO; 1510 grp->is_origin = GNUNET_NO;
1485 grp->pub_key = msg->group_pub_key; 1511 grp->pub_key = msg->group_pub_key;
1486 grp->pub_key_hash = pub_key_hash; 1512 grp->pub_key_hash = pub_key_hash;
1513 grp->is_disconnected = GNUNET_NO;
1487 group_set_cadet_port_hash (grp); 1514 group_set_cadet_port_hash (grp);
1488 1515
1489 if (NULL == grp_mem) 1516 if (NULL == grp_mem)
@@ -1494,7 +1521,8 @@ handle_client_member_join (void *cls,
1494 } 1521 }
1495 GNUNET_CONTAINER_multihashmap_put (grp_mem, &mem->pub_key_hash, mem, 1522 GNUNET_CONTAINER_multihashmap_put (grp_mem, &mem->pub_key_hash, mem,
1496 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 1523 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1497 1524
1525 // FIXME: should the members hash map have option UNIQUE_FAST?
1498 GNUNET_CONTAINER_multihashmap_put (members, &grp->pub_key_hash, mem, 1526 GNUNET_CONTAINER_multihashmap_put (members, &grp->pub_key_hash, mem,
1499 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1527 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1500 } 1528 }
@@ -1509,10 +1537,11 @@ handle_client_member_join (void *cls,
1509 1537
1510 char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&mem->pub_key); 1538 char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&mem->pub_key);
1511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1539 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1512 "Client connected to group %s as member %s (%s).\n", 1540 "Client connected to group %s as member %s (%s). size = %d\n",
1513 GNUNET_h2s (&grp->pub_key_hash), 1541 GNUNET_h2s (&grp->pub_key_hash),
1514 GNUNET_h2s2 (&mem->pub_key_hash), 1542 GNUNET_h2s2 (&mem->pub_key_hash),
1515 str); 1543 str,
1544 GNUNET_CONTAINER_multihashmap_size (members));
1516 GNUNET_free (str); 1545 GNUNET_free (str);
1517 1546
1518 if (NULL != mem->join_dcsn) 1547 if (NULL != mem->join_dcsn)
@@ -1567,7 +1596,9 @@ handle_client_member_join (void *cls,
1567 GNUNET_free (mem->join_req); 1596 GNUNET_free (mem->join_req);
1568 mem->join_req = req; 1597 mem->join_req = req;
1569 1598
1570 if (0 == client_send_origin (&grp->pub_key_hash, &mem->join_req->header)) 1599 if (0 ==
1600 client_send_origin (&grp->pub_key_hash,
1601 GNUNET_MQ_msg_copy (&mem->join_req->header)))
1571 { /* No local origins, send to remote origin */ 1602 { /* No local origins, send to remote origin */
1572 cadet_send_join_request (mem); 1603 cadet_send_join_request (mem);
1573 } 1604 }
@@ -1580,7 +1611,7 @@ static void
1580client_send_join_decision (struct Member *mem, 1611client_send_join_decision (struct Member *mem,
1581 const struct MulticastJoinDecisionMessageHeader *hdcsn) 1612 const struct MulticastJoinDecisionMessageHeader *hdcsn)
1582{ 1613{
1583 client_send_group (&mem->group, &hdcsn->header); 1614 client_send_group (&mem->group, GNUNET_MQ_msg_copy (&hdcsn->header));
1584 1615
1585 const struct MulticastJoinDecisionMessage * 1616 const struct MulticastJoinDecisionMessage *
1586 dcsn = (const struct MulticastJoinDecisionMessage *) &hdcsn[1]; 1617 dcsn = (const struct MulticastJoinDecisionMessage *) &hdcsn[1];
@@ -1621,8 +1652,9 @@ handle_client_join_decision (void *cls,
1621 GNUNET_SERVICE_client_drop (client); 1652 GNUNET_SERVICE_client_drop (client);
1622 return; 1653 return;
1623 } 1654 }
1655 GNUNET_assert (GNUNET_NO == grp->is_disconnected);
1624 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1625 "%p Got join decision from client for group %s..\n", 1657 "%p got join decision from client for group %s..\n",
1626 grp, GNUNET_h2s (&grp->pub_key_hash)); 1658 grp, GNUNET_h2s (&grp->pub_key_hash));
1627 1659
1628 struct GNUNET_CONTAINER_MultiHashMap * 1660 struct GNUNET_CONTAINER_MultiHashMap *
@@ -1652,6 +1684,32 @@ handle_client_join_decision (void *cls,
1652} 1684}
1653 1685
1654 1686
1687static void
1688handle_client_part_request (void *cls,
1689 const struct GNUNET_MessageHeader *msg)
1690{
1691 struct Client *c = cls;
1692 struct GNUNET_SERVICE_Client *client = c->client;
1693 struct Group *grp = c->group;
1694 struct GNUNET_MQ_Envelope *env;
1695
1696 if (NULL == grp)
1697 {
1698 GNUNET_break (0);
1699 GNUNET_SERVICE_client_drop (client);
1700 return;
1701 }
1702 GNUNET_assert (GNUNET_NO == grp->is_disconnected);
1703 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1704 "%p got part request from client for group %s.\n",
1705 grp, GNUNET_h2s (&grp->pub_key_hash));
1706 grp->is_disconnected = GNUNET_YES;
1707 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_MULTICAST_PART_ACK);
1708 client_send_group (grp, env);
1709 GNUNET_SERVICE_client_continue (client);
1710}
1711
1712
1655static int 1713static int
1656check_client_multicast_message (void *cls, 1714check_client_multicast_message (void *cls,
1657 const struct GNUNET_MULTICAST_MessageHeader *msg) 1715 const struct GNUNET_MULTICAST_MessageHeader *msg)
@@ -1667,6 +1725,7 @@ static void
1667handle_client_multicast_message (void *cls, 1725handle_client_multicast_message (void *cls,
1668 const struct GNUNET_MULTICAST_MessageHeader *msg) 1726 const struct GNUNET_MULTICAST_MessageHeader *msg)
1669{ 1727{
1728 // FIXME: what if GNUNET_YES == grp->is_disconnected? Do we allow sending messages?
1670 struct Client *c = cls; 1729 struct Client *c = cls;
1671 struct GNUNET_SERVICE_Client *client = c->client; 1730 struct GNUNET_SERVICE_Client *client = c->client;
1672 struct Group *grp = c->group; 1731 struct Group *grp = c->group;
@@ -1680,6 +1739,7 @@ handle_client_multicast_message (void *cls,
1680 GNUNET_assert (GNUNET_YES == grp->is_origin); 1739 GNUNET_assert (GNUNET_YES == grp->is_origin);
1681 struct Origin *orig = grp->origin; 1740 struct Origin *orig = grp->origin;
1682 1741
1742 // FIXME: use GNUNET_MQ_msg_copy
1683 /* FIXME: yucky, should use separate message structs for P2P and CS! */ 1743 /* FIXME: yucky, should use separate message structs for P2P and CS! */
1684 struct GNUNET_MULTICAST_MessageHeader * 1744 struct GNUNET_MULTICAST_MessageHeader *
1685 out = (struct GNUNET_MULTICAST_MessageHeader *) GNUNET_copy_message (&msg->header); 1745 out = (struct GNUNET_MULTICAST_MessageHeader *) GNUNET_copy_message (&msg->header);
@@ -1696,7 +1756,7 @@ handle_client_multicast_message (void *cls,
1696 GNUNET_assert (0); 1756 GNUNET_assert (0);
1697 } 1757 }
1698 1758
1699 client_send_all (&grp->pub_key_hash, &out->header); 1759 client_send_all (&grp->pub_key_hash, GNUNET_MQ_msg_copy (&out->header));
1700 cadet_send_children (&grp->pub_key_hash, &out->header); 1760 cadet_send_children (&grp->pub_key_hash, &out->header);
1701 client_send_ack (&grp->pub_key_hash); 1761 client_send_ack (&grp->pub_key_hash);
1702 GNUNET_free (out); 1762 GNUNET_free (out);
@@ -1730,6 +1790,7 @@ handle_client_multicast_request (void *cls,
1730 GNUNET_SERVICE_client_drop (client); 1790 GNUNET_SERVICE_client_drop (client);
1731 return; 1791 return;
1732 } 1792 }
1793 GNUNET_assert (GNUNET_NO == grp->is_disconnected);
1733 GNUNET_assert (GNUNET_NO == grp->is_origin); 1794 GNUNET_assert (GNUNET_NO == grp->is_origin);
1734 struct Member *mem = grp->member; 1795 struct Member *mem = grp->member;
1735 1796
@@ -1751,7 +1812,9 @@ handle_client_multicast_request (void *cls,
1751 } 1812 }
1752 1813
1753 uint8_t send_ack = GNUNET_YES; 1814 uint8_t send_ack = GNUNET_YES;
1754 if (0 == client_send_origin (&grp->pub_key_hash, &out->header)) 1815 if (0 ==
1816 client_send_origin (&grp->pub_key_hash,
1817 GNUNET_MQ_msg_copy (&out->header)))
1755 { /* No local origins, send to remote origin */ 1818 { /* No local origins, send to remote origin */
1756 if (NULL != mem->origin_channel) 1819 if (NULL != mem->origin_channel)
1757 { 1820 {
@@ -1792,6 +1855,7 @@ handle_client_replay_request (void *cls,
1792 GNUNET_SERVICE_client_drop (client); 1855 GNUNET_SERVICE_client_drop (client);
1793 return; 1856 return;
1794 } 1857 }
1858 GNUNET_assert (GNUNET_NO == grp->is_disconnected);
1795 GNUNET_assert (GNUNET_NO == grp->is_origin); 1859 GNUNET_assert (GNUNET_NO == grp->is_origin);
1796 struct Member *mem = grp->member; 1860 struct Member *mem = grp->member;
1797 1861
@@ -1812,7 +1876,9 @@ handle_client_replay_request (void *cls,
1812 GNUNET_CONTAINER_multihashmap_put (grp_replay_req, &key_hash, client, 1876 GNUNET_CONTAINER_multihashmap_put (grp_replay_req, &key_hash, client,
1813 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1877 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1814 1878
1815 if (0 == client_send_origin (&grp->pub_key_hash, &rep->header)) 1879 if (0 ==
1880 client_send_origin (&grp->pub_key_hash,
1881 GNUNET_MQ_msg_copy (&rep->header)))
1816 { /* No local origin, replay from remote members / origin. */ 1882 { /* No local origin, replay from remote members / origin. */
1817 if (NULL != mem->origin_channel) 1883 if (NULL != mem->origin_channel)
1818 { 1884 {
@@ -1821,6 +1887,7 @@ handle_client_replay_request (void *cls,
1821 else 1887 else
1822 { 1888 {
1823 /* FIXME: not yet connected to origin */ 1889 /* FIXME: not yet connected to origin */
1890 GNUNET_assert (0);
1824 GNUNET_SERVICE_client_drop (client); 1891 GNUNET_SERVICE_client_drop (client);
1825 return; 1892 return;
1826 } 1893 }
@@ -1880,6 +1947,7 @@ handle_client_replay_response_end (void *cls,
1880 GNUNET_SERVICE_client_drop (client); 1947 GNUNET_SERVICE_client_drop (client);
1881 return; 1948 return;
1882 } 1949 }
1950 GNUNET_assert (GNUNET_NO == grp->is_disconnected);
1883 1951
1884 struct GNUNET_HashCode key_hash; 1952 struct GNUNET_HashCode key_hash;
1885 replay_key_hash (res->fragment_id, res->message_id, res->fragment_offset, 1953 replay_key_hash (res->fragment_id, res->message_id, res->fragment_offset,
@@ -1939,6 +2007,7 @@ handle_client_replay_response (void *cls,
1939 GNUNET_SERVICE_client_drop (client); 2007 GNUNET_SERVICE_client_drop (client);
1940 return; 2008 return;
1941 } 2009 }
2010 GNUNET_assert (GNUNET_NO == grp->is_disconnected);
1942 2011
1943 const struct GNUNET_MessageHeader *msg = &res->header; 2012 const struct GNUNET_MessageHeader *msg = &res->header;
1944 if (GNUNET_MULTICAST_REC_OK == res->error_code) 2013 if (GNUNET_MULTICAST_REC_OK == res->error_code)
@@ -2033,9 +2102,14 @@ client_notify_disconnect (void *cls,
2033 grp, (GNUNET_YES == grp->is_origin) ? "origin" : "member", 2102 grp, (GNUNET_YES == grp->is_origin) ? "origin" : "member",
2034 GNUNET_h2s (&grp->pub_key_hash)); 2103 GNUNET_h2s (&grp->pub_key_hash));
2035 2104
2105 // FIXME (due to protocol change): here we must not remove all clients,
2106 // only the one we were notified about!
2036 struct ClientList *cl = grp->clients_head; 2107 struct ClientList *cl = grp->clients_head;
2037 while (NULL != cl) 2108 while (NULL != cl)
2038 { 2109 {
2110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2111 "iterating clients for group %p\n",
2112 grp);
2039 if (cl->client == client) 2113 if (cl->client == client)
2040 { 2114 {
2041 GNUNET_CONTAINER_DLL_remove (grp->clients_head, grp->clients_tail, cl); 2115 GNUNET_CONTAINER_DLL_remove (grp->clients_head, grp->clients_tail, cl);
@@ -2049,16 +2123,7 @@ client_notify_disconnect (void *cls,
2049 2123
2050 if (NULL == grp->clients_head) 2124 if (NULL == grp->clients_head)
2051 { /* Last client disconnected. */ 2125 { /* Last client disconnected. */
2052#if FIXME 2126 cleanup_group (grp);
2053 if (NULL != grp->tmit_head)
2054 { /* Send pending messages via CADET before cleanup. */
2055 transmit_message (grp);
2056 }
2057 else
2058#endif
2059 {
2060 cleanup_group (grp);
2061 }
2062 } 2127 }
2063} 2128}
2064 2129
@@ -2103,9 +2168,9 @@ run (void *cls,
2103GNUNET_SERVICE_MAIN 2168GNUNET_SERVICE_MAIN
2104("multicast", 2169("multicast",
2105 GNUNET_SERVICE_OPTION_NONE, 2170 GNUNET_SERVICE_OPTION_NONE,
2106 run, 2171 &run,
2107 client_notify_connect, 2172 &client_notify_connect,
2108 client_notify_disconnect, 2173 &client_notify_disconnect,
2109 NULL, 2174 NULL,
2110 GNUNET_MQ_hd_fixed_size (client_origin_start, 2175 GNUNET_MQ_hd_fixed_size (client_origin_start,
2111 GNUNET_MESSAGE_TYPE_MULTICAST_ORIGIN_START, 2176 GNUNET_MESSAGE_TYPE_MULTICAST_ORIGIN_START,
@@ -2119,6 +2184,10 @@ GNUNET_SERVICE_MAIN
2119 GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION, 2184 GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION,
2120 struct MulticastJoinDecisionMessageHeader, 2185 struct MulticastJoinDecisionMessageHeader,
2121 NULL), 2186 NULL),
2187 GNUNET_MQ_hd_fixed_size (client_part_request,
2188 GNUNET_MESSAGE_TYPE_MULTICAST_PART_REQUEST,
2189 struct GNUNET_MessageHeader,
2190 NULL),
2122 GNUNET_MQ_hd_var_size (client_multicast_message, 2191 GNUNET_MQ_hd_var_size (client_multicast_message,
2123 GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE, 2192 GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE,
2124 struct GNUNET_MULTICAST_MessageHeader, 2193 struct GNUNET_MULTICAST_MessageHeader,
diff --git a/src/multicast/multicast_api.c b/src/multicast/multicast_api.c
index a8b1dee40..3c911f48a 100644
--- a/src/multicast/multicast_api.c
+++ b/src/multicast/multicast_api.c
@@ -542,31 +542,12 @@ group_cleanup (struct GNUNET_MULTICAST_Group *grp)
542 542
543 543
544static void 544static void
545group_disconnect (struct GNUNET_MULTICAST_Group *grp, 545handle_group_part_ack (void *cls,
546 GNUNET_ContinuationCallback cb, 546 const struct GNUNET_MessageHeader *msg)
547 void *cls)
548{ 547{
549 grp->is_disconnecting = GNUNET_YES; 548 struct GNUNET_MULTICAST_Group *grp = cls;
550 grp->disconnect_cb = cb;
551 grp->disconnect_cls = cls;
552 549
553 if (NULL != grp->mq) 550 group_cleanup (grp);
554 {
555 struct GNUNET_MQ_Envelope *last = GNUNET_MQ_get_last_envelope (grp->mq);
556 if (NULL != last)
557 {
558 GNUNET_MQ_notify_sent (last,
559 (GNUNET_SCHEDULER_TaskCallback) group_cleanup, grp);
560 }
561 else
562 {
563 group_cleanup (grp);
564 }
565 }
566 else
567 {
568 group_cleanup (grp);
569 }
570} 551}
571 552
572 553
@@ -779,6 +760,10 @@ origin_connect (struct GNUNET_MULTICAST_Origin *orig)
779 GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST, 760 GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST,
780 struct MulticastJoinRequestMessage, 761 struct MulticastJoinRequestMessage,
781 grp), 762 grp),
763 GNUNET_MQ_hd_fixed_size (group_part_ack,
764 GNUNET_MESSAGE_TYPE_MULTICAST_PART_ACK,
765 struct GNUNET_MessageHeader,
766 grp),
782 GNUNET_MQ_hd_fixed_size (group_replay_request, 767 GNUNET_MQ_hd_fixed_size (group_replay_request,
783 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST, 768 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST,
784 struct MulticastReplayRequestMessage, 769 struct MulticastReplayRequestMessage,
@@ -879,8 +864,13 @@ GNUNET_MULTICAST_origin_stop (struct GNUNET_MULTICAST_Origin *orig,
879 void *stop_cls) 864 void *stop_cls)
880{ 865{
881 struct GNUNET_MULTICAST_Group *grp = &orig->grp; 866 struct GNUNET_MULTICAST_Group *grp = &orig->grp;
867 struct GNUNET_MQ_Envelope *env;
882 868
883 group_disconnect (grp, stop_cb, stop_cls); 869 grp->is_disconnecting = GNUNET_YES;
870 grp->disconnect_cb = stop_cb;
871 grp->disconnect_cls = stop_cls;
872 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_MULTICAST_PART_REQUEST);
873 GNUNET_MQ_send (grp->mq, env);
884} 874}
885 875
886 876
@@ -1065,6 +1055,10 @@ member_connect (struct GNUNET_MULTICAST_Member *mem)
1065 GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION, 1055 GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION,
1066 struct MulticastJoinDecisionMessageHeader, 1056 struct MulticastJoinDecisionMessageHeader,
1067 mem), 1057 mem),
1058 GNUNET_MQ_hd_fixed_size (group_part_ack,
1059 GNUNET_MESSAGE_TYPE_MULTICAST_PART_ACK,
1060 struct GNUNET_MessageHeader,
1061 grp),
1068 GNUNET_MQ_hd_fixed_size (group_replay_request, 1062 GNUNET_MQ_hd_fixed_size (group_replay_request,
1069 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST, 1063 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST,
1070 struct MulticastReplayRequestMessage, 1064 struct MulticastReplayRequestMessage,
@@ -1198,16 +1192,19 @@ GNUNET_MULTICAST_member_part (struct GNUNET_MULTICAST_Member *mem,
1198 GNUNET_ContinuationCallback part_cb, 1192 GNUNET_ContinuationCallback part_cb,
1199 void *part_cls) 1193 void *part_cls)
1200{ 1194{
1201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%p Member parting.\n", mem);
1202 struct GNUNET_MULTICAST_Group *grp = &mem->grp; 1195 struct GNUNET_MULTICAST_Group *grp = &mem->grp;
1196 struct GNUNET_MQ_Envelope *env;
1203 1197
1204 mem->join_dcsn_cb = NULL; 1198 mem->join_dcsn_cb = NULL;
1205 grp->join_req_cb = NULL; 1199 grp->join_req_cb = NULL;
1206 grp->message_cb = NULL; 1200 grp->message_cb = NULL;
1207 grp->replay_msg_cb = NULL; 1201 grp->replay_msg_cb = NULL;
1208 grp->replay_frag_cb = NULL; 1202 grp->replay_frag_cb = NULL;
1209 1203 grp->is_disconnecting = GNUNET_YES;
1210 group_disconnect (grp, part_cb, part_cls); 1204 grp->disconnect_cb = part_cb;
1205 grp->disconnect_cls = part_cls;
1206 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_MULTICAST_PART_REQUEST);
1207 GNUNET_MQ_send (grp->mq, env);
1211} 1208}
1212 1209
1213 1210
diff --git a/src/multicast/test_multicast_multipeer.c b/src/multicast/test_multicast_multipeer.c
index 5f4493993..7df1a8213 100644
--- a/src/multicast/test_multicast_multipeer.c
+++ b/src/multicast/test_multicast_multipeer.c
@@ -35,9 +35,10 @@
35 35
36#define PEERS_REQUESTED 12 36#define PEERS_REQUESTED 12
37 37
38struct multicast_peer 38struct MulticastPeerContext
39{ 39{
40 int peer; /* peer number */ 40 int peer; /* peer number */
41 struct GNUNET_CRYPTO_EcdsaPrivateKey *key;
41 const struct GNUNET_PeerIdentity *id; 42 const struct GNUNET_PeerIdentity *id;
42 struct GNUNET_TESTBED_Operation *op; /* not yet in use */ 43 struct GNUNET_TESTBED_Operation *op; /* not yet in use */
43 struct GNUNET_TESTBED_Operation *pi_op; /* not yet in use */ 44 struct GNUNET_TESTBED_Operation *pi_op; /* not yet in use */
@@ -61,7 +62,7 @@ static void service_connect (void *cls,
61 void *ca_result, 62 void *ca_result,
62 const char *emsg); 63 const char *emsg);
63 64
64static struct multicast_peer **mc_peers; 65static struct MulticastPeerContext **multicast_peers;
65static struct GNUNET_TESTBED_Peer **peers; 66static struct GNUNET_TESTBED_Peer **peers;
66 67
67// FIXME: refactor 68// FIXME: refactor
@@ -69,18 +70,14 @@ static struct GNUNET_TESTBED_Operation *op[PEERS_REQUESTED];
69static struct GNUNET_TESTBED_Operation *pi_op[PEERS_REQUESTED]; 70static struct GNUNET_TESTBED_Operation *pi_op[PEERS_REQUESTED];
70 71
71static struct GNUNET_MULTICAST_Origin *origin; 72static struct GNUNET_MULTICAST_Origin *origin;
72static struct GNUNET_MULTICAST_Member *member[PEERS_REQUESTED]; /* first element always empty */ 73static struct GNUNET_MULTICAST_Member *members[PEERS_REQUESTED]; /* first element always empty */
73 74
74static struct GNUNET_SCHEDULER_Task *timeout_tid; 75static struct GNUNET_SCHEDULER_Task *timeout_tid;
75 76
76static struct GNUNET_CRYPTO_EddsaPrivateKey group_key; 77//static struct GNUNET_CRYPTO_EddsaPrivateKey *group_key;
77static struct GNUNET_CRYPTO_EddsaPublicKey group_pub_key; 78static struct GNUNET_CRYPTO_EddsaPublicKey group_pub_key;
78static struct GNUNET_HashCode group_pub_key_hash; 79static struct GNUNET_HashCode group_pub_key_hash;
79 80
80static struct GNUNET_CRYPTO_EcdsaPrivateKey *member_key[PEERS_REQUESTED];
81static struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key[PEERS_REQUESTED];
82
83
84/** 81/**
85 * Global result for testcase. 82 * Global result for testcase.
86 */ 83 */
@@ -93,6 +90,8 @@ static int result;
93static void 90static void
94shutdown_task (void *cls) 91shutdown_task (void *cls)
95{ 92{
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
94 "shutdown_task!\n");
96 for (int i=0;i<PEERS_REQUESTED;i++) 95 for (int i=0;i<PEERS_REQUESTED;i++)
97 { 96 {
98 if (NULL != op[i]) 97 if (NULL != op[i])
@@ -107,14 +106,16 @@ shutdown_task (void *cls)
107 } 106 }
108 } 107 }
109 108
110 if (NULL != mc_peers) 109 if (NULL != multicast_peers)
111 { 110 {
112 for (int i=0; i < PEERS_REQUESTED; i++) 111 for (int i=0; i < PEERS_REQUESTED; i++)
113 { 112 {
114 GNUNET_free (mc_peers[i]); 113 GNUNET_free (multicast_peers[i]->key);
115 mc_peers[i] = NULL; 114 GNUNET_free (multicast_peers[i]);
115 multicast_peers[i] = NULL;
116 } 116 }
117 GNUNET_free (mc_peers); 117 GNUNET_free (multicast_peers);
118 multicast_peers = NULL;
118 } 119 }
119 120
120 if (NULL != timeout_tid) 121 if (NULL != timeout_tid)
@@ -141,11 +142,11 @@ member_join_request (void *cls,
141 const struct GNUNET_MessageHeader *join_msg, 142 const struct GNUNET_MessageHeader *join_msg,
142 struct GNUNET_MULTICAST_JoinHandle *jh) 143 struct GNUNET_MULTICAST_JoinHandle *jh)
143{ 144{
144 struct multicast_peer *mc_peer = (struct multicast_peer*)cls; 145 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
145 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 146 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
146 "Peer #%u (%s) sent a join request.\n", 147 "Peer #%u (%s) sent a join request.\n",
147 mc_peer->peer, 148 mc_peer->peer,
148 GNUNET_i2s (mc_peers[mc_peer->peer]->id)); 149 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
149} 150}
150 151
151 152
@@ -154,7 +155,7 @@ notify (void *cls,
154 size_t *data_size, 155 size_t *data_size,
155 void *data) 156 void *data)
156{ 157{
157 struct multicast_peer *mc_peer = (struct multicast_peer*)cls; 158 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
158 159
159 struct pingpong_msg *pp_msg = GNUNET_new (struct pingpong_msg); 160 struct pingpong_msg *pp_msg = GNUNET_new (struct pingpong_msg);
160 pp_msg->peer = mc_peer->peer; 161 pp_msg->peer = mc_peer->peer;
@@ -178,18 +179,18 @@ member_join_decision (void *cls,
178 const struct GNUNET_PeerIdentity *relays, 179 const struct GNUNET_PeerIdentity *relays,
179 const struct GNUNET_MessageHeader *join_msg) 180 const struct GNUNET_MessageHeader *join_msg)
180{ 181{
181 struct multicast_peer *mc_peer = (struct multicast_peer*)cls; 182 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
182 struct GNUNET_MULTICAST_MemberTransmitHandle *req; 183 struct GNUNET_MULTICAST_MemberTransmitHandle *req;
183 184
184 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 185 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
185 "Peer #%u (%s) received a decision from origin: %s\n", 186 "Peer #%u (%s) received a decision from origin: %s\n",
186 mc_peer->peer, 187 mc_peer->peer,
187 GNUNET_i2s (mc_peers[mc_peer->peer]->id), 188 GNUNET_i2s (multicast_peers[mc_peer->peer]->id),
188 (GNUNET_YES == is_admitted)?"accepted":"rejected"); 189 (GNUNET_YES == is_admitted)?"accepted":"rejected");
189 190
190 if (GNUNET_YES == is_admitted) 191 if (GNUNET_YES == is_admitted)
191 { 192 {
192 req = GNUNET_MULTICAST_member_to_origin (member[mc_peer->peer], 193 req = GNUNET_MULTICAST_member_to_origin (members[mc_peer->peer],
193 0, 194 0,
194 notify, 195 notify,
195 cls); 196 cls);
@@ -215,10 +216,32 @@ member_replay_msg ()
215 216
216 217
217static void 218static void
219origin_disconnected_cb (void *cls)
220{
221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
222 "Origin disconnected. Shutting down.\n");
223 result = GNUNET_YES;
224 GNUNET_SCHEDULER_shutdown ();
225}
226
227
228static void
229member_disconnected_cb (void *cls)
230{
231 for (int i = 1; i < PEERS_REQUESTED; ++i)
232 if (GNUNET_NO == multicast_peers[i]->test_ok)
233 return;
234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
235 "All member disconnected. Stopping origin.\n");
236 GNUNET_MULTICAST_origin_stop (origin, origin_disconnected_cb, cls);
237}
238
239
240static void
218member_message (void *cls, 241member_message (void *cls,
219 const struct GNUNET_MULTICAST_MessageHeader *msg) 242 const struct GNUNET_MULTICAST_MessageHeader *msg)
220{ 243{
221 struct multicast_peer *mc_peer = (struct multicast_peer*)cls; 244 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
222 struct pingpong_msg *pp_msg = (struct pingpong_msg*) &(msg[1]); 245 struct pingpong_msg *pp_msg = (struct pingpong_msg*) &(msg[1]);
223 246
224 if (PONG == pp_msg->msg && mc_peer->peer == pp_msg->peer) 247 if (PONG == pp_msg->msg && mc_peer->peer == pp_msg->peer)
@@ -226,18 +249,15 @@ member_message (void *cls,
226 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 249 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
227 "peer #%i (%s) receives a pong\n", 250 "peer #%i (%s) receives a pong\n",
228 mc_peer->peer, 251 mc_peer->peer,
229 GNUNET_i2s (mc_peers[mc_peer->peer]->id)); 252 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
230
231 mc_peer->test_ok = GNUNET_OK; 253 mc_peer->test_ok = GNUNET_OK;
232 } 254 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
233 255 "peer #%u (%s) parting from multicast group\n",
234 // Test for completeness of received PONGs 256 mc_peer->peer,
235 for (int i=1; i<PEERS_REQUESTED; i++) 257 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
236 if (GNUNET_NO == mc_peers[i]->test_ok)
237 return;
238 258
239 result = GNUNET_YES; 259 GNUNET_MULTICAST_member_part (members[mc_peer->peer], member_disconnected_cb, cls);
240 GNUNET_SCHEDULER_shutdown(); 260 }
241} 261}
242 262
243 263
@@ -349,81 +369,53 @@ origin_message (void *cls,
349 369
350 370
351static void 371static void
352multicast_da (void *cls, 372multicast_disconnect (void *cls,
353 void *op_result) 373 void *op_result)
354{ 374{
355 struct multicast_peer *mc_peer = (struct multicast_peer*)cls;
356 375
357 if (0 == mc_peer->peer)
358 {
359 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
360 "Origin closes multicast group\n");
361
362 GNUNET_MULTICAST_origin_stop (origin, NULL, cls);
363 }
364 else
365 {
366 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
367 "peer #%u (%s) parting from multicast group\n",
368 mc_peer->peer,
369 GNUNET_i2s (mc_peers[mc_peer->peer]->id));
370
371 GNUNET_MULTICAST_member_part (member[mc_peer->peer], NULL, cls);
372 }
373} 376}
374 377
375 378
376static void * 379static void *
377multicast_ca (void *cls, 380multicast_connect (void *cls,
378 const struct GNUNET_CONFIGURATION_Handle *cfg) 381 const struct GNUNET_CONFIGURATION_Handle *cfg)
379{ 382{
380 struct multicast_peer *mc_peer = (struct multicast_peer*)cls; 383 struct MulticastPeerContext *multicast_peer = cls;
381 struct GNUNET_MessageHeader *join_msg; 384 struct GNUNET_MessageHeader *join_msg;
382 char data[64]; 385 char data[64];
383 386
384 if (0 == mc_peer->peer) 387 multicast_peer->key = GNUNET_CRYPTO_ecdsa_key_create ();
388 if (0 == multicast_peer->peer)
385 { 389 {
386 struct GNUNET_CRYPTO_EddsaPrivateKey *key = GNUNET_CRYPTO_eddsa_key_create (); 390 GNUNET_CRYPTO_eddsa_key_get_public (multicast_peer->key, &group_pub_key);
387 GNUNET_CRYPTO_eddsa_key_get_public (key, &group_pub_key);
388 GNUNET_CRYPTO_hash (&group_pub_key, sizeof (group_pub_key), &group_pub_key_hash); 391 GNUNET_CRYPTO_hash (&group_pub_key, sizeof (group_pub_key), &group_pub_key_hash);
389
390 group_key = *key;
391
392 origin = GNUNET_MULTICAST_origin_start (cfg, 392 origin = GNUNET_MULTICAST_origin_start (cfg,
393 &group_key, 393 multicast_peer->key,
394 0, 394 0,
395 origin_join_request, 395 origin_join_request,
396 origin_replay_frag, 396 origin_replay_frag,
397 origin_replay_msg, 397 origin_replay_msg,
398 origin_request, 398 origin_request,
399 origin_message, 399 origin_message,
400 cls); 400 cls);
401 401 if (NULL == origin)
402 if (NULL == origin) { 402 {
403 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 403 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
404 "Peer #%u could not create a multicast group", 404 "Peer #%u could not create a multicast group",
405 mc_peer->peer); 405 multicast_peer->peer);
406 return NULL; 406 return NULL;
407 } 407 }
408
409 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 408 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
410 "Peer #%u connected as origin to group %s\n", 409 "Peer #%u connected as origin to group %s\n",
411 mc_peer->peer, 410 multicast_peer->peer,
412 GNUNET_h2s (&group_pub_key_hash)); 411 GNUNET_h2s (&group_pub_key_hash));
413
414 return origin; 412 return origin;
415 } 413 }
416 else 414 else
417 { 415 {
418 // Get members keys
419 member_pub_key[mc_peer->peer] = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
420 member_key[mc_peer->peer] = GNUNET_CRYPTO_ecdsa_key_create ();
421 GNUNET_CRYPTO_ecdsa_key_get_public (member_key[mc_peer->peer],
422 member_pub_key[mc_peer->peer]);
423
424 sprintf(data, "Hi, I am peer #%u (%s). Can I enter?", 416 sprintf(data, "Hi, I am peer #%u (%s). Can I enter?",
425 mc_peer->peer, 417 multicast_peer->peer,
426 GNUNET_i2s (mc_peers[mc_peer->peer]->id)); 418 GNUNET_i2s (multicast_peers[multicast_peer->peer]->id));
427 uint8_t data_size = strlen (data) + 1; 419 uint8_t data_size = strlen (data) + 1;
428 join_msg = GNUNET_malloc (sizeof (join_msg) + data_size); 420 join_msg = GNUNET_malloc (sizeof (join_msg) + data_size);
429 join_msg->size = htons (sizeof (join_msg) + data_size); 421 join_msg->size = htons (sizeof (join_msg) + data_size);
@@ -432,24 +424,25 @@ multicast_ca (void *cls,
432 424
433 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 425 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
434 "Peer #%u (%s) tries to join multicast group %s\n", 426 "Peer #%u (%s) tries to join multicast group %s\n",
435 mc_peer->peer, 427 multicast_peer->peer,
436 GNUNET_i2s (mc_peers[mc_peer->peer]->id), 428 GNUNET_i2s (multicast_peers[multicast_peer->peer]->id),
437 GNUNET_h2s (&group_pub_key_hash)); 429 GNUNET_h2s (&group_pub_key_hash));
438 430
439 member[mc_peer->peer] = GNUNET_MULTICAST_member_join (cfg, 431 members[multicast_peer->peer] =
440 &group_pub_key, 432 GNUNET_MULTICAST_member_join (cfg,
441 member_key[mc_peer->peer], 433 &group_pub_key,
442 mc_peers[0]->id, 434 multicast_peer->key,
443 0, 435 multicast_peers[0]->id,
444 NULL, 436 0,
445 join_msg, /* join message */ 437 NULL,
446 member_join_request, 438 join_msg, /* join message */
447 member_join_decision, 439 member_join_request,
448 member_replay_frag, 440 member_join_decision,
449 member_replay_msg, 441 member_replay_frag,
450 member_message, 442 member_replay_msg,
451 cls); 443 member_message,
452 return member[mc_peer->peer]; 444 cls);
445 return members[multicast_peer->peer];
453 } 446 }
454} 447}
455 448
@@ -460,7 +453,7 @@ peer_information_cb (void *cls,
460 const struct GNUNET_TESTBED_PeerInformation *pinfo, 453 const struct GNUNET_TESTBED_PeerInformation *pinfo,
461 const char *emsg) 454 const char *emsg)
462{ 455{
463 struct multicast_peer *mc_peer = (struct multicast_peer*)cls; 456 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
464 457
465 if (NULL == pinfo) { 458 if (NULL == pinfo) {
466 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "got no peer information\n"); 459 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "got no peer information\n");
@@ -468,7 +461,7 @@ peer_information_cb (void *cls,
468 GNUNET_SCHEDULER_shutdown (); 461 GNUNET_SCHEDULER_shutdown ();
469 } 462 }
470 463
471 mc_peers[mc_peer->peer]->id = pinfo->result.id; 464 multicast_peers[mc_peer->peer]->id = pinfo->result.id;
472 465
473 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 466 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
474 "Got peer information of %s (%s)\n", 467 "Got peer information of %s (%s)\n",
@@ -478,22 +471,28 @@ peer_information_cb (void *cls,
478 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 471 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
479 "Create peer #%u (%s)\n", 472 "Create peer #%u (%s)\n",
480 mc_peer->peer, 473 mc_peer->peer,
481 GNUNET_i2s (mc_peers[mc_peer->peer]->id)); 474 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
482 475
483 if (0 != mc_peer->peer) 476 if (0 != mc_peer->peer)
484 { 477 {
485 /* connect to multicast service of members */ 478 /* connect to multicast service of members */
486 op[mc_peer->peer] = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */ 479 op[mc_peer->peer] =
487 peers[mc_peer->peer], /* The peer whose service to connect to */ 480 GNUNET_TESTBED_service_connect (/* Closure for operation */
488 "multicast", /* The name of the service */ 481 NULL,
489 service_connect, /* callback to call after a handle to service 482 /* The peer whose service to connect to */
490 is opened */ 483 peers[mc_peer->peer],
491 cls, /* closure for the above callback */ 484 /* The name of the service */
492 multicast_ca, /* callback to call with peer's configuration; 485 "multicast",
493 this should open the needed service connection */ 486 /* called after a handle to service is opened */
494 multicast_da, /* callback to be called when closing the 487 service_connect,
495 opened service connection */ 488 /* closure for the above callback */
496 cls); /* closure for the above two callbacks */ 489 cls,
490 /* called when opening the service connection */
491 multicast_connect,
492 /* called when closing the service connection */
493 multicast_disconnect,
494 /* closure for the above two callbacks */
495 cls);
497 } 496 }
498} 497}
499 498
@@ -504,14 +503,14 @@ service_connect (void *cls,
504 void *ca_result, 503 void *ca_result,
505 const char *emsg) 504 const char *emsg)
506{ 505{
507 struct multicast_peer *mc_peer = (struct multicast_peer*)cls; 506 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
508 507
509 if (NULL == ca_result) 508 if (NULL == ca_result)
510 { 509 {
511 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 510 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
512 "Connection adapter not created for peer #%u (%s)\n", 511 "Connection adapter not created for peer #%u (%s)\n",
513 mc_peer->peer, 512 mc_peer->peer,
514 GNUNET_i2s (mc_peers[mc_peer->peer]->id)); 513 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
515 514
516 result = GNUNET_SYSERR; 515 result = GNUNET_SYSERR;
517 GNUNET_SCHEDULER_shutdown(); 516 GNUNET_SCHEDULER_shutdown();
@@ -525,7 +524,7 @@ service_connect (void *cls,
525 pi_op[i] = GNUNET_TESTBED_peer_get_information (peers[i], 524 pi_op[i] = GNUNET_TESTBED_peer_get_information (peers[i],
526 GNUNET_TESTBED_PIT_IDENTITY, 525 GNUNET_TESTBED_PIT_IDENTITY,
527 peer_information_cb, 526 peer_information_cb,
528 mc_peers[i]); 527 multicast_peers[i]);
529 } 528 }
530 } 529 }
531} 530}
@@ -549,50 +548,51 @@ service_connect (void *cls,
549 * @param links_failed number of links testbed was unable to establish 548 * @param links_failed number of links testbed was unable to establish
550 */ static void 549 */ static void
551testbed_master (void *cls, 550testbed_master (void *cls,
552 struct GNUNET_TESTBED_RunHandle *h, 551 struct GNUNET_TESTBED_RunHandle *h,
553 unsigned int num_peers, 552 unsigned int num_peers,
554 struct GNUNET_TESTBED_Peer **p, 553 struct GNUNET_TESTBED_Peer **p,
555 unsigned int links_succeeded, 554 unsigned int links_succeeded,
556 unsigned int links_failed) 555 unsigned int links_failed)
557{ 556{
558 /* Testbed is ready with peers running and connected in a pre-defined overlay 557 /* Testbed is ready with peers running and connected in a pre-defined overlay
559 topology (FIXME) */ 558 topology (FIXME) */
560
561 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
562 "Connected to testbed_master()\n");
563
564 peers = p; 559 peers = p;
565 560 multicast_peers = GNUNET_new_array (PEERS_REQUESTED, struct MulticastPeerContext*);
566 mc_peers = GNUNET_new_array (PEERS_REQUESTED, struct multicast_peer*);
567 561
568 // Create test contexts for members 562 // Create test contexts for members
569 for (int i = 0; i<PEERS_REQUESTED; i++) 563 for (int i = 0; i<PEERS_REQUESTED; i++)
570 { 564 {
571 mc_peers[i] = GNUNET_new (struct multicast_peer); 565 multicast_peers[i] = GNUNET_new (struct MulticastPeerContext);
572 mc_peers[i]->peer = i; 566 multicast_peers[i]->peer = i;
573 mc_peers[i]->test_ok = GNUNET_NO; 567 multicast_peers[i]->test_ok = GNUNET_NO;
574 } 568 }
575
576 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 569 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
577 "Create origin peer\n"); 570 "Create origin peer\n");
578 571 op[0] =
579 op[0] = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */ 572 GNUNET_TESTBED_service_connect (/* Closure for operation */
580 peers[0], /* The peer whose service to connect to */ 573 NULL,
581 "multicast", /* The name of the service */ 574 /* The peer whose service to connect to */
582 service_connect, /* callback to call after a handle to service 575 peers[0],
583 is opened */ 576 /* The name of the service */
584 mc_peers[0], /* closure for the above callback */ 577 "multicast",
585 multicast_ca, /* callback to call with peer's configuration; 578 /* called after a handle to service is opened */
586 this should open the needed service connection */ 579 service_connect,
587 multicast_da, /* callback to be called when closing the 580 /* closure for the above callback */
588 opened service connection */ 581 multicast_peers[0],
589 mc_peers[0]); /* closure for the above two callbacks */ 582 /* called when opening the service connection */
590 583 multicast_connect,
591 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); /* Schedule a new task on shutdown */ 584 /* called when closing the service connection */
592 585 multicast_disconnect,
586 /* closure for the above two callbacks */
587 multicast_peers[0]);
588 /* Schedule a new task on shutdown */
589 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
593 /* Schedule the shutdown task with a delay of a few Seconds */ 590 /* Schedule the shutdown task with a delay of a few Seconds */
594 timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 400), 591 timeout_tid =
595 &timeout_task, NULL); 592 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
593 (GNUNET_TIME_UNIT_SECONDS, 400),
594 &timeout_task,
595 NULL);
596} 596}
597 597
598 598
@@ -616,15 +616,21 @@ main (int argc, char *argv[])
616 } 616 }
617 617
618 result = GNUNET_SYSERR; 618 result = GNUNET_SYSERR;
619 ret = GNUNET_TESTBED_test_run 619 ret =
620 ("test-multicast-multipeer", /* test case name */ 620 GNUNET_TESTBED_test_run ("test-multicast-multipeer",
621 config_file, /* template configuration */ 621 config_file,
622 PEERS_REQUESTED, /* number of peers to start */ 622 /* number of peers to start */
623 0LL, /* Event mask - set to 0 for no event notifications */ 623 PEERS_REQUESTED,
624 NULL, /* Controller event callback */ 624 /* Event mask - set to 0 for no event notifications */
625 NULL, /* Closure for controller event callback */ 625 0LL,
626 testbed_master, /* continuation callback to be called when testbed setup is complete */ 626 /* Controller event callback */
627 NULL); /* Closure for the test_master callback */ 627 NULL,
628 /* Closure for controller event callback */
629 NULL,
630 /* called when testbed setup is complete */
631 testbed_master,
632 /* Closure for the test_master callback */
633 NULL);
628 if ( (GNUNET_OK != ret) || (GNUNET_OK != result) ) 634 if ( (GNUNET_OK != ret) || (GNUNET_OK != result) )
629 return 1; 635 return 1;
630 return 0; 636 return 0;
diff --git a/src/nat/gnunet-nat.c b/src/nat/gnunet-nat.c
index b3cf2e946..72f343627 100644
--- a/src/nat/gnunet-nat.c
+++ b/src/nat/gnunet-nat.c
@@ -377,10 +377,16 @@ run (void *cls,
377 ls = GNUNET_NETWORK_socket_create (af, 377 ls = GNUNET_NETWORK_socket_create (af,
378 SOCK_DGRAM, 378 SOCK_DGRAM,
379 IPPROTO_UDP); 379 IPPROTO_UDP);
380 if (NULL == ls)
381 {
382 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
383 "Failed to create socket\n");
384 goto fail_and_shutdown;
385 }
380 if (GNUNET_OK != 386 if (GNUNET_OK !=
381 GNUNET_NETWORK_socket_bind (ls, 387 GNUNET_NETWORK_socket_bind (ls,
382 local_sa, 388 local_sa,
383 local_len)) 389 local_len))
384 { 390 {
385 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 391 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
386 "Failed to bind to %s: %s\n", 392 "Failed to bind to %s: %s\n",
diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c
index 4a10022e3..b665812e5 100644
--- a/src/nse/gnunet-nse-profiler.c
+++ b/src/nse/gnunet-nse-profiler.c
@@ -374,13 +374,14 @@ nse_disconnect_adapter (void *cls,
374 */ 374 */
375static int 375static int
376stat_iterator (void *cls, 376stat_iterator (void *cls,
377 const char *subsystem, 377 const char *subsystem,
378 const char *name, 378 const char *name,
379 uint64_t value, int is_persistent) 379 uint64_t value,
380 int is_persistent)
380{ 381{
381 char *output_buffer; 382 char *output_buffer;
382 struct GNUNET_TIME_Absolute now; 383 struct GNUNET_TIME_Absolute now;
383 size_t size; 384 int size;
384 unsigned int flag; 385 unsigned int flag;
385 386
386 GNUNET_assert (NULL != data_file); 387 GNUNET_assert (NULL != data_file);
@@ -390,8 +391,14 @@ stat_iterator (void *cls,
390 flag = 1; 391 flag = 1;
391 size = GNUNET_asprintf (&output_buffer, "%llu %llu %u\n", 392 size = GNUNET_asprintf (&output_buffer, "%llu %llu %u\n",
392 now.abs_value_us / 1000LL / 1000LL, 393 now.abs_value_us / 1000LL / 1000LL,
393 value, flag); 394 value, flag);
394 if (size != GNUNET_DISK_file_write (data_file, output_buffer, size)) 395 if (0 > size)
396 {
397 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Error formatting output buffer.\n");
398 GNUNET_free (output_buffer);
399 return GNUNET_SYSERR;
400 }
401 if (size != GNUNET_DISK_file_write (data_file, output_buffer, (size_t) size))
395 { 402 {
396 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); 403 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
397 GNUNET_free (output_buffer); 404 GNUNET_free (output_buffer);
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index 731c24bf1..6b39149be 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -198,6 +198,8 @@ count_addresses (void *cls,
198{ 198{
199 unsigned int *cnt = cls; 199 unsigned int *cnt = cls;
200 200
201 (void) address;
202 (void) expiration;
201 (*cnt)++; 203 (*cnt)++;
202 return GNUNET_OK; 204 return GNUNET_OK;
203} 205}
@@ -290,7 +292,7 @@ read_host_file (const char *fn,
290 const struct GNUNET_HELLO_Message *hello; 292 const struct GNUNET_HELLO_Message *hello;
291 struct GNUNET_HELLO_Message *hello_clean; 293 struct GNUNET_HELLO_Message *hello_clean;
292 size_t read_pos; 294 size_t read_pos;
293 int size_hello; 295 uint16_t size_hello;
294 296
295 r->friend_only_hello = NULL; 297 r->friend_only_hello = NULL;
296 r->hello = NULL; 298 r->hello = NULL;
@@ -304,7 +306,8 @@ read_host_file (const char *fn,
304 "Read %d bytes from `%s'\n", 306 "Read %d bytes from `%s'\n",
305 (int) size_total, 307 (int) size_total,
306 fn); 308 fn);
307 if (size_total < sizeof (struct GNUNET_MessageHeader)) 309 if ( (size_total < 0) ||
310 (((size_t) size_total) < sizeof (struct GNUNET_MessageHeader)) )
308 { 311 {
309 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 312 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
310 _("Failed to parse HELLO in file `%s': %s\n"), 313 _("Failed to parse HELLO in file `%s': %s\n"),
@@ -320,12 +323,12 @@ read_host_file (const char *fn,
320 } 323 }
321 324
322 read_pos = 0; 325 read_pos = 0;
323 while (read_pos < size_total) 326 while (read_pos < (size_t) size_total)
324 { 327 {
325 hello = (const struct GNUNET_HELLO_Message *) &buffer[read_pos]; 328 hello = (const struct GNUNET_HELLO_Message *) &buffer[read_pos];
326 size_hello = GNUNET_HELLO_size (hello); 329 size_hello = GNUNET_HELLO_size (hello);
327 if ( (0 == size_hello) || 330 if ( (0 == size_hello) ||
328 (size_total - read_pos < size_hello) ) 331 (((size_t) size_total) - read_pos < size_hello) )
329 { 332 {
330 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 333 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
331 _("Failed to parse HELLO in file `%s'\n"), 334 _("Failed to parse HELLO in file `%s'\n"),
@@ -559,11 +562,11 @@ hosts_directory_scan_callback (void *cls,
559 if (GNUNET_OK != 562 if (GNUNET_OK !=
560 GNUNET_HELLO_get_id (r.friend_only_hello, 563 GNUNET_HELLO_get_id (r.friend_only_hello,
561 &id_friend)) 564 &id_friend))
565 {
562 if (GNUNET_YES == dsc->remove_files) 566 if (GNUNET_YES == dsc->remove_files)
563 {
564 remove_garbage (fullname); 567 remove_garbage (fullname);
565 return GNUNET_OK; 568 return GNUNET_OK;
566 } 569 }
567 id = id_friend; 570 id = id_friend;
568 } 571 }
569 if (NULL != r.hello) 572 if (NULL != r.hello)
@@ -571,11 +574,11 @@ hosts_directory_scan_callback (void *cls,
571 if (GNUNET_OK != 574 if (GNUNET_OK !=
572 GNUNET_HELLO_get_id (r.hello, 575 GNUNET_HELLO_get_id (r.hello,
573 &id_public)) 576 &id_public))
577 {
574 if (GNUNET_YES == dsc->remove_files) 578 if (GNUNET_YES == dsc->remove_files)
575 {
576 remove_garbage (fullname); 579 remove_garbage (fullname);
577 return GNUNET_OK; 580 return GNUNET_OK;
578 } 581 }
579 id = id_public; 582 id = id_public;
580 } 583 }
581 584
@@ -640,6 +643,7 @@ cron_scan_directory_data_hosts (void *cls)
640 static unsigned int retries; 643 static unsigned int retries;
641 struct DirScanContext dsc; 644 struct DirScanContext dsc;
642 645
646 (void) cls;
643 cron_scan = NULL; 647 cron_scan = NULL;
644 if (GNUNET_SYSERR == 648 if (GNUNET_SYSERR ==
645 GNUNET_DISK_directory_create (networkIdDirectory)) 649 GNUNET_DISK_directory_create (networkIdDirectory))
@@ -730,7 +734,7 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
730 int friend_hello_type; 734 int friend_hello_type;
731 int store_hello; 735 int store_hello;
732 int store_friend_hello; 736 int store_friend_hello;
733 int pos; 737 unsigned int pos;
734 char *buffer; 738 char *buffer;
735 739
736 host = GNUNET_CONTAINER_multipeermap_get (hostmap, peer); 740 host = GNUNET_CONTAINER_multipeermap_get (hostmap, peer);
@@ -849,8 +853,8 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
849 if (GNUNET_YES == store_friend_hello) 853 if (GNUNET_YES == store_friend_hello)
850 { 854 {
851 GNUNET_memcpy (&buffer[pos], 855 GNUNET_memcpy (&buffer[pos],
852 host->friend_only_hello, 856 host->friend_only_hello,
853 GNUNET_HELLO_size (host->friend_only_hello)); 857 GNUNET_HELLO_size (host->friend_only_hello));
854 pos += GNUNET_HELLO_size (host->friend_only_hello); 858 pos += GNUNET_HELLO_size (host->friend_only_hello);
855 } 859 }
856 GNUNET_assert (pos == size); 860 GNUNET_assert (pos == size);
@@ -987,13 +991,32 @@ discard_hosts_helper (void *cls,
987 int write_pos; 991 int write_pos;
988 unsigned int cnt; 992 unsigned int cnt;
989 char *writebuffer; 993 char *writebuffer;
994 uint64_t fsize;
995
996 if (GNUNET_OK !=
997 GNUNET_DISK_file_size (fn,
998 &fsize,
999 GNUNET_YES,
1000 GNUNET_YES))
1001 {
1002 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
1003 GNUNET_ERROR_TYPE_BULK,
1004 "fstat",
1005 fn);
1006 return GNUNET_OK;
1007 }
1008 read_size = GNUNET_DISK_fn_read (fn,
1009 buffer,
1010 sizeof (buffer));
990 1011
991 read_size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); 1012 if ( (read_size < (int) sizeof (struct GNUNET_MessageHeader)) ||
992 if (read_size < (int) sizeof (struct GNUNET_MessageHeader)) 1013 (fsize > GNUNET_MAX_MESSAGE_SIZE) )
993 { 1014 {
994 if (0 != UNLINK (fn)) 1015 if (0 != UNLINK (fn))
995 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | 1016 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
996 GNUNET_ERROR_TYPE_BULK, "unlink", fn); 1017 GNUNET_ERROR_TYPE_BULK,
1018 "unlink",
1019 fn);
997 return GNUNET_OK; 1020 return GNUNET_OK;
998 } 1021 }
999 1022
@@ -1070,6 +1093,7 @@ cron_clean_data_hosts (void *cls)
1070{ 1093{
1071 struct GNUNET_TIME_Absolute now; 1094 struct GNUNET_TIME_Absolute now;
1072 1095
1096 (void) cls;
1073 cron_clean = NULL; 1097 cron_clean = NULL;
1074 now = GNUNET_TIME_absolute_get (); 1098 now = GNUNET_TIME_absolute_get ();
1075 GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, 1099 GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
@@ -1097,6 +1121,7 @@ check_hello (void *cls,
1097{ 1121{
1098 struct GNUNET_PeerIdentity pid; 1122 struct GNUNET_PeerIdentity pid;
1099 1123
1124 (void) cls;
1100 if (GNUNET_OK != 1125 if (GNUNET_OK !=
1101 GNUNET_HELLO_get_id (hello, 1126 GNUNET_HELLO_get_id (hello,
1102 &pid)) 1127 &pid))
@@ -1121,12 +1146,12 @@ handle_hello (void *cls,
1121 struct GNUNET_SERVICE_Client *client = cls; 1146 struct GNUNET_SERVICE_Client *client = cls;
1122 struct GNUNET_PeerIdentity pid; 1147 struct GNUNET_PeerIdentity pid;
1123 1148
1124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1125 "HELLO message received for peer `%s'\n",
1126 GNUNET_i2s (&pid));
1127 GNUNET_assert (GNUNET_OK == 1149 GNUNET_assert (GNUNET_OK ==
1128 GNUNET_HELLO_get_id (hello, 1150 GNUNET_HELLO_get_id (hello,
1129 &pid)); 1151 &pid));
1152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1153 "HELLO message received for peer `%s'\n",
1154 GNUNET_i2s (&pid));
1130 add_host_to_known_hosts (&pid); 1155 add_host_to_known_hosts (&pid);
1131 update_hello (&pid, 1156 update_hello (&pid,
1132 hello); 1157 hello);
@@ -1248,6 +1273,8 @@ client_connect_cb (void *cls,
1248 struct GNUNET_SERVICE_Client *client, 1273 struct GNUNET_SERVICE_Client *client,
1249 struct GNUNET_MQ_Handle *mq) 1274 struct GNUNET_MQ_Handle *mq)
1250{ 1275{
1276 (void) cls;
1277 (void) mq;
1251 return client; 1278 return client;
1252} 1279}
1253 1280
@@ -1264,6 +1291,7 @@ client_disconnect_cb (void *cls,
1264 struct GNUNET_SERVICE_Client *client, 1291 struct GNUNET_SERVICE_Client *client,
1265 void *app_ctx) 1292 void *app_ctx)
1266{ 1293{
1294 (void) cls;
1267 GNUNET_assert (app_ctx == client); 1295 GNUNET_assert (app_ctx == client);
1268} 1296}
1269 1297
@@ -1283,6 +1311,8 @@ free_host_entry (void *cls,
1283{ 1311{
1284 struct HostEntry *he = value; 1312 struct HostEntry *he = value;
1285 1313
1314 (void) cls;
1315 (void) key;
1286 GNUNET_free_non_null (he->hello); 1316 GNUNET_free_non_null (he->hello);
1287 GNUNET_free_non_null (he->friend_only_hello); 1317 GNUNET_free_non_null (he->friend_only_hello);
1288 GNUNET_free (he); 1318 GNUNET_free (he);
@@ -1298,6 +1328,7 @@ free_host_entry (void *cls,
1298static void 1328static void
1299shutdown_task (void *cls) 1329shutdown_task (void *cls)
1300{ 1330{
1331 (void) cls;
1301 GNUNET_notification_context_destroy (notify_list); 1332 GNUNET_notification_context_destroy (notify_list);
1302 notify_list = NULL; 1333 notify_list = NULL;
1303 GNUNET_notification_context_destroy (notify_friend_only_list); 1334 GNUNET_notification_context_destroy (notify_friend_only_list);
@@ -1349,6 +1380,8 @@ run (void *cls,
1349 int noio; 1380 int noio;
1350 int use_included; 1381 int use_included;
1351 1382
1383 (void) cls;
1384 (void) service;
1352 hostmap 1385 hostmap
1353 = GNUNET_CONTAINER_multipeermap_create (1024, 1386 = GNUNET_CONTAINER_multipeermap_create (1024,
1354 GNUNET_YES); 1387 GNUNET_YES);
diff --git a/src/psyc/gnunet-service-psyc.c b/src/psyc/gnunet-service-psyc.c
index 73a3ae4ee..cf161435a 100644
--- a/src/psyc/gnunet-service-psyc.c
+++ b/src/psyc/gnunet-service-psyc.c
@@ -279,7 +279,7 @@ struct Channel
279 * Is the client disconnected? 279 * Is the client disconnected?
280 * #GNUNET_YES or #GNUNET_NO 280 * #GNUNET_YES or #GNUNET_NO
281 */ 281 */
282 uint8_t is_disconnected; 282 uint8_t is_disconnecting;
283 283
284 /** 284 /**
285 * Is this a channel master (#GNUNET_YES), or slave (#GNUNET_NO)? 285 * Is this a channel master (#GNUNET_YES), or slave (#GNUNET_NO)?
@@ -508,8 +508,6 @@ cleanup_master (struct Master *mst)
508{ 508{
509 struct Channel *chn = &mst->channel; 509 struct Channel *chn = &mst->channel;
510 510
511 if (NULL != mst->origin)
512 GNUNET_MULTICAST_origin_stop (mst->origin, NULL, NULL); // FIXME
513 GNUNET_CONTAINER_multihashmap_destroy (mst->join_reqs); 511 GNUNET_CONTAINER_multihashmap_destroy (mst->join_reqs);
514 GNUNET_CONTAINER_multihashmap_remove (masters, &chn->pub_key_hash, mst); 512 GNUNET_CONTAINER_multihashmap_remove (masters, &chn->pub_key_hash, mst);
515} 513}
@@ -546,11 +544,6 @@ cleanup_slave (struct Slave *slv)
546 GNUNET_free (slv->relays); 544 GNUNET_free (slv->relays);
547 slv->relays = NULL; 545 slv->relays = NULL;
548 } 546 }
549 if (NULL != slv->member)
550 {
551 GNUNET_MULTICAST_member_part (slv->member, NULL, NULL); // FIXME
552 slv->member = NULL;
553 }
554 GNUNET_CONTAINER_multihashmap_remove (slaves, &chn->pub_key_hash, slv); 547 GNUNET_CONTAINER_multihashmap_remove (slaves, &chn->pub_key_hash, slv);
555} 548}
556 549
@@ -603,15 +596,16 @@ client_notify_disconnect (void *cls,
603 if (NULL == chn) 596 if (NULL == chn)
604 { 597 {
605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 598 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
606 "%p User context is NULL in client_disconnect()\n", 599 "%p User context is NULL in client_notify_disconnect ()\n",
607 chn); 600 chn);
608 GNUNET_break (0); 601 GNUNET_break (0);
609 return; 602 return;
610 } 603 }
611 604
612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
613 "%p Client (%s) disconnected from channel %s\n", 606 "%p Client %p (%s) disconnected from channel %s\n",
614 chn, 607 chn,
608 client,
615 (GNUNET_YES == chn->is_master) ? "master" : "slave", 609 (GNUNET_YES == chn->is_master) ? "master" : "slave",
616 GNUNET_h2s (&chn->pub_key_hash)); 610 GNUNET_h2s (&chn->pub_key_hash));
617 611
@@ -645,15 +639,8 @@ client_notify_disconnect (void *cls,
645 chn, 639 chn,
646 (GNUNET_YES == chn->is_master) ? "master" : "slave", 640 (GNUNET_YES == chn->is_master) ? "master" : "slave",
647 GNUNET_h2s (&chn->pub_key_hash)); 641 GNUNET_h2s (&chn->pub_key_hash));
648 chn->is_disconnected = GNUNET_YES; 642 chn->is_disconnecting = GNUNET_YES;
649 if (NULL != chn->tmit_head) 643 cleanup_channel (chn);
650 { /* Send pending messages to multicast before cleanup. */
651 transmit_message (chn);
652 }
653 else
654 {
655 cleanup_channel (chn);
656 }
657 } 644 }
658} 645}
659 646
@@ -688,7 +675,7 @@ client_send_msg (const struct Channel *chn,
688 const struct GNUNET_MessageHeader *msg) 675 const struct GNUNET_MessageHeader *msg)
689{ 676{
690 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 677 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
691 "%p Sending message to clients.\n", 678 "Sending message to clients of channel %p.\n",
692 chn); 679 chn);
693 680
694 struct ClientList *cli = chn->clients_head; 681 struct ClientList *cli = chn->clients_head;
@@ -699,7 +686,6 @@ client_send_msg (const struct Channel *chn,
699 686
700 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cli->client), 687 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cli->client),
701 env); 688 env);
702
703 cli = cli->next; 689 cli = cli->next;
704 } 690 }
705} 691}
@@ -734,7 +720,7 @@ client_send_result (struct GNUNET_SERVICE_Client *client, uint64_t op_id,
734 GNUNET_memcpy (&res[1], data, data_size); 720 GNUNET_memcpy (&res[1], data, data_size);
735 721
736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
737 "%p Sending result to client for operation #%" PRIu64 ": %" PRId64 " (size: %u)\n", 723 "%p Sending result to client for OP ID %" PRIu64 ": %" PRId64 " (size: %u)\n",
738 client, 724 client,
739 GNUNET_ntohll (op_id), 725 GNUNET_ntohll (op_id),
740 result_code, 726 result_code,
@@ -1202,12 +1188,12 @@ fragment_queue_insert (struct Channel *chn,
1202 else if (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD == first_ptype 1188 else if (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD == first_ptype
1203 || frag_offset == fragq->header_size) 1189 || frag_offset == fragq->header_size)
1204 { /* header is now complete */ 1190 { /* header is now complete */
1205 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1206 "%p Header of message %" PRIu64 " is complete.\n", 1192 "%p Header of message %" PRIu64 " is complete.\n",
1207 chn, 1193 chn,
1208 GNUNET_ntohll (mmsg->message_id)); 1194 GNUNET_ntohll (mmsg->message_id));
1209 1195
1210 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1211 "%p Adding message %" PRIu64 " to queue.\n", 1197 "%p Adding message %" PRIu64 " to queue.\n",
1212 chn, 1198 chn,
1213 GNUNET_ntohll (mmsg->message_id)); 1199 GNUNET_ntohll (mmsg->message_id));
@@ -1215,7 +1201,7 @@ fragment_queue_insert (struct Channel *chn,
1215 } 1201 }
1216 else 1202 else
1217 { 1203 {
1218 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1219 "%p Header of message %" PRIu64 " is NOT complete yet: %" PRIu64 " != %" PRIu64 "\n", 1205 "%p Header of message %" PRIu64 " is NOT complete yet: %" PRIu64 " != %" PRIu64 "\n",
1220 chn, 1206 chn,
1221 GNUNET_ntohll (mmsg->message_id), 1207 GNUNET_ntohll (mmsg->message_id),
@@ -1230,7 +1216,7 @@ fragment_queue_insert (struct Channel *chn,
1230 if (frag_offset == fragq->size) 1216 if (frag_offset == fragq->size)
1231 fragq->state = MSG_FRAG_STATE_END; 1217 fragq->state = MSG_FRAG_STATE_END;
1232 else 1218 else
1233 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1234 "%p Message %" PRIu64 " is NOT complete yet: %" PRIu64 " != %" PRIu64 "\n", 1220 "%p Message %" PRIu64 " is NOT complete yet: %" PRIu64 " != %" PRIu64 "\n",
1235 chn, 1221 chn,
1236 GNUNET_ntohll (mmsg->message_id), 1222 GNUNET_ntohll (mmsg->message_id),
@@ -1285,7 +1271,7 @@ static void
1285fragment_queue_run (struct Channel *chn, uint64_t msg_id, 1271fragment_queue_run (struct Channel *chn, uint64_t msg_id,
1286 struct FragmentQueue *fragq, uint8_t drop) 1272 struct FragmentQueue *fragq, uint8_t drop)
1287{ 1273{
1288 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1289 "%p Running message fragment queue for message %" PRIu64 " (state: %u).\n", 1275 "%p Running message fragment queue for message %" PRIu64 " (state: %u).\n",
1290 chn, 1276 chn,
1291 msg_id, 1277 msg_id,
@@ -1413,7 +1399,7 @@ store_recv_state_modify_result (void *cls, int64_t result,
1413static uint64_t 1399static uint64_t
1414message_queue_run (struct Channel *chn) 1400message_queue_run (struct Channel *chn)
1415{ 1401{
1416 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1402 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1417 "%p Running message queue.\n", chn); 1403 "%p Running message queue.\n", chn);
1418 uint64_t n = 0; 1404 uint64_t n = 0;
1419 uint64_t msg_id; 1405 uint64_t msg_id;
@@ -1421,7 +1407,7 @@ message_queue_run (struct Channel *chn)
1421 while (GNUNET_YES == GNUNET_CONTAINER_heap_peek2 (chn->recv_msgs, NULL, 1407 while (GNUNET_YES == GNUNET_CONTAINER_heap_peek2 (chn->recv_msgs, NULL,
1422 &msg_id)) 1408 &msg_id))
1423 { 1409 {
1424 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1425 "%p Processing message %" PRIu64 " in queue.\n", chn, msg_id); 1411 "%p Processing message %" PRIu64 " in queue.\n", chn, msg_id);
1426 struct GNUNET_HashCode msg_id_hash; 1412 struct GNUNET_HashCode msg_id_hash;
1427 hash_key_from_hll (&msg_id_hash, msg_id); 1413 hash_key_from_hll (&msg_id_hash, msg_id);
@@ -1431,7 +1417,7 @@ message_queue_run (struct Channel *chn)
1431 1417
1432 if (NULL == fragq || fragq->state <= MSG_FRAG_STATE_HEADER) 1418 if (NULL == fragq || fragq->state <= MSG_FRAG_STATE_HEADER)
1433 { 1419 {
1434 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1435 "%p No fragq (%p) or header not complete.\n", 1421 "%p No fragq (%p) or header not complete.\n",
1436 chn, fragq); 1422 chn, fragq);
1437 break; 1423 break;
@@ -1453,7 +1439,7 @@ message_queue_run (struct Channel *chn)
1453 && (chn->max_message_id != msg_id - 1 1439 && (chn->max_message_id != msg_id - 1
1454 && chn->max_message_id != msg_id)) 1440 && chn->max_message_id != msg_id))
1455 { 1441 {
1456 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1442 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1457 "%p Out of order message. " 1443 "%p Out of order message. "
1458 "(%" PRIu64 " != %" PRIu64 " - 1)\n", 1444 "(%" PRIu64 " != %" PRIu64 " - 1)\n",
1459 chn, chn->max_message_id, msg_id); 1445 chn, chn->max_message_id, msg_id);
@@ -1469,7 +1455,7 @@ message_queue_run (struct Channel *chn)
1469 { 1455 {
1470 if (msg_id - fragq->state_delta != chn->max_state_message_id) 1456 if (msg_id - fragq->state_delta != chn->max_state_message_id)
1471 { 1457 {
1472 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1473 "%p Out of order stateful message. " 1459 "%p Out of order stateful message. "
1474 "(%" PRIu64 " - %" PRIu64 " != %" PRIu64 ")\n", 1460 "(%" PRIu64 " - %" PRIu64 " != %" PRIu64 ")\n",
1475 chn, msg_id, fragq->state_delta, chn->max_state_message_id); 1461 chn, msg_id, fragq->state_delta, chn->max_state_message_id);
@@ -1515,8 +1501,6 @@ message_queue_run (struct Channel *chn)
1515static uint64_t 1501static uint64_t
1516message_queue_drop (struct Channel *chn) 1502message_queue_drop (struct Channel *chn)
1517{ 1503{
1518 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1519 "%p Dropping message queue.\n", chn);
1520 uint64_t n = 0; 1504 uint64_t n = 0;
1521 uint64_t msg_id; 1505 uint64_t msg_id;
1522 while (GNUNET_YES == GNUNET_CONTAINER_heap_peek2 (chn->recv_msgs, NULL, 1506 while (GNUNET_YES == GNUNET_CONTAINER_heap_peek2 (chn->recv_msgs, NULL,
@@ -1703,7 +1687,7 @@ store_recv_slave_counters (void *cls, int result, uint64_t max_fragment_id,
1703 res.result_code = htonl (result); 1687 res.result_code = htonl (result);
1704 res.max_message_id = GNUNET_htonll (max_message_id); 1688 res.max_message_id = GNUNET_htonll (max_message_id);
1705 1689
1706 if (GNUNET_OK == result || GNUNET_NO == result) 1690 if (GNUNET_YES == result || GNUNET_NO == result)
1707 { 1691 {
1708 chn->max_message_id = max_message_id; 1692 chn->max_message_id = max_message_id;
1709 chn->max_state_message_id = max_state_message_id; 1693 chn->max_state_message_id = max_state_message_id;
@@ -1831,6 +1815,9 @@ handle_client_slave_join (void *cls,
1831 struct GNUNET_CRYPTO_EcdsaPublicKey slv_pub_key; 1815 struct GNUNET_CRYPTO_EcdsaPublicKey slv_pub_key;
1832 struct GNUNET_HashCode pub_key_hash, slv_pub_hash; 1816 struct GNUNET_HashCode pub_key_hash, slv_pub_hash;
1833 1817
1818 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1819 "got join request from client %p\n",
1820 client);
1834 GNUNET_CRYPTO_ecdsa_key_get_public (&req->slave_key, &slv_pub_key); 1821 GNUNET_CRYPTO_ecdsa_key_get_public (&req->slave_key, &slv_pub_key);
1835 GNUNET_CRYPTO_hash (&slv_pub_key, sizeof (slv_pub_key), &slv_pub_hash); 1822 GNUNET_CRYPTO_hash (&slv_pub_key, sizeof (slv_pub_key), &slv_pub_hash);
1836 GNUNET_CRYPTO_hash (&req->channel_pub_key, sizeof (req->channel_pub_key), &pub_key_hash); 1823 GNUNET_CRYPTO_hash (&req->channel_pub_key, sizeof (req->channel_pub_key), &pub_key_hash);
@@ -1905,7 +1892,7 @@ handle_client_slave_join (void *cls,
1905 GNUNET_CONTAINER_multihashmap_put (slaves, &chn->pub_key_hash, chn, 1892 GNUNET_CONTAINER_multihashmap_put (slaves, &chn->pub_key_hash, chn,
1906 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1893 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1907 chn->store_op = GNUNET_PSYCSTORE_counters_get (store, &chn->pub_key, 1894 chn->store_op = GNUNET_PSYCSTORE_counters_get (store, &chn->pub_key,
1908 &store_recv_slave_counters, slv); 1895 &store_recv_slave_counters, slv);
1909 } 1896 }
1910 else 1897 else
1911 { 1898 {
@@ -1952,8 +1939,9 @@ handle_client_slave_join (void *cls,
1952 } 1939 }
1953 1940
1954 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1941 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1955 "%p Client connected as slave to channel %s.\n", 1942 "Client %p connected as slave to channel %s.\n",
1956 slv, GNUNET_h2s (&chn->pub_key_hash)); 1943 client,
1944 GNUNET_h2s (&chn->pub_key_hash));
1957 1945
1958 struct ClientList *cli = GNUNET_malloc (sizeof (*cli)); 1946 struct ClientList *cli = GNUNET_malloc (sizeof (*cli));
1959 cli->client = client; 1947 cli->client = client;
@@ -2037,6 +2025,49 @@ handle_client_join_decision (void *cls,
2037} 2025}
2038 2026
2039 2027
2028static void
2029channel_part_cb (void *cls)
2030{
2031 struct GNUNET_SERVICE_Client *client = cls;
2032 struct GNUNET_MQ_Envelope *env;
2033
2034 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_PSYC_PART_ACK);
2035 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
2036 env);
2037}
2038
2039
2040static void
2041handle_client_part_request (void *cls,
2042 const struct GNUNET_MessageHeader *msg)
2043{
2044 struct Client *c = cls;
2045
2046 c->channel->is_disconnecting = GNUNET_YES;
2047 if (GNUNET_YES == c->channel->is_master)
2048 {
2049 struct Master *mst = (struct Master *) c->channel;
2050
2051 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2052 "Got part request from master %p\n",
2053 mst);
2054 GNUNET_assert (NULL != mst->origin);
2055 GNUNET_MULTICAST_origin_stop (mst->origin, channel_part_cb, c->client);
2056 }
2057 else
2058 {
2059 struct Slave *slv = (struct Slave *) c->channel;
2060
2061 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2062 "Got part request from slave %p\n",
2063 slv);
2064 GNUNET_assert (NULL != slv->member);
2065 GNUNET_MULTICAST_member_part (slv->member, channel_part_cb, c->client);
2066 }
2067 GNUNET_SERVICE_client_continue (c->client);
2068}
2069
2070
2040/** 2071/**
2041 * Send acknowledgement to a client. 2072 * Send acknowledgement to a client.
2042 * 2073 *
@@ -2096,7 +2127,7 @@ transmit_notify (void *cls, size_t *data_size, void *data)
2096 { 2127 {
2097 GNUNET_SCHEDULER_add_now (&schedule_transmit_message, chn); 2128 GNUNET_SCHEDULER_add_now (&schedule_transmit_message, chn);
2098 } 2129 }
2099 else if (GNUNET_YES == chn->is_disconnected 2130 else if (GNUNET_YES == chn->is_disconnecting
2100 && tmit_msg->last_ptype < GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END) 2131 && tmit_msg->last_ptype < GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END)
2101 { 2132 {
2102 /* FIXME: handle partial message (when still in_transmit) */ 2133 /* FIXME: handle partial message (when still in_transmit) */
@@ -2208,12 +2239,10 @@ transmit_message (struct Channel *chn)
2208static void 2239static void
2209master_queue_message (struct Master *mst, struct TransmitMessage *tmit_msg) 2240master_queue_message (struct Master *mst, struct TransmitMessage *tmit_msg)
2210{ 2241{
2211 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%p master_queue_message()\n", mst);
2212
2213 if (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD == tmit_msg->first_ptype) 2242 if (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD == tmit_msg->first_ptype)
2214 { 2243 {
2215 tmit_msg->id = ++mst->max_message_id; 2244 tmit_msg->id = ++mst->max_message_id;
2216 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2217 "%p master_queue_message: message_id=%" PRIu64 "\n", 2246 "%p master_queue_message: message_id=%" PRIu64 "\n",
2218 mst, tmit_msg->id); 2247 mst, tmit_msg->id);
2219 struct GNUNET_PSYC_MessageMethod *pmeth 2248 struct GNUNET_PSYC_MessageMethod *pmeth
@@ -2225,7 +2254,7 @@ master_queue_message (struct Master *mst, struct TransmitMessage *tmit_msg)
2225 } 2254 }
2226 else if (pmeth->flags & GNUNET_PSYC_MASTER_TRANSMIT_STATE_MODIFY) 2255 else if (pmeth->flags & GNUNET_PSYC_MASTER_TRANSMIT_STATE_MODIFY)
2227 { 2256 {
2228 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2229 "%p master_queue_message: state_delta=%" PRIu64 "\n", 2258 "%p master_queue_message: state_delta=%" PRIu64 "\n",
2230 mst, tmit_msg->id - mst->max_state_message_id); 2259 mst, tmit_msg->id - mst->max_state_message_id);
2231 pmeth->state_delta = GNUNET_htonll (tmit_msg->id 2260 pmeth->state_delta = GNUNET_htonll (tmit_msg->id
@@ -2234,7 +2263,7 @@ master_queue_message (struct Master *mst, struct TransmitMessage *tmit_msg)
2234 } 2263 }
2235 else 2264 else
2236 { 2265 {
2237 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2238 "%p master_queue_message: state not modified\n", mst); 2267 "%p master_queue_message: state not modified\n", mst);
2239 pmeth->state_delta = GNUNET_htonll (GNUNET_PSYC_STATE_NOT_MODIFIED); 2268 pmeth->state_delta = GNUNET_htonll (GNUNET_PSYC_STATE_NOT_MODIFIED);
2240 } 2269 }
@@ -2359,7 +2388,9 @@ handle_client_psyc_message (void *cls,
2359 if (GNUNET_YES != chn->is_ready) 2388 if (GNUNET_YES != chn->is_ready)
2360 { 2389 {
2361 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2390 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2362 "%p Channel is not ready yet, disconnecting client.\n", chn); 2391 "%p Channel is not ready yet, disconnecting client %p.\n",
2392 chn,
2393 client);
2363 GNUNET_break (0); 2394 GNUNET_break (0);
2364 GNUNET_SERVICE_client_drop (client); 2395 GNUNET_SERVICE_client_drop (client);
2365 return; 2396 return;
@@ -2789,9 +2820,9 @@ run (void *cls,
2789GNUNET_SERVICE_MAIN 2820GNUNET_SERVICE_MAIN
2790("psyc", 2821("psyc",
2791 GNUNET_SERVICE_OPTION_NONE, 2822 GNUNET_SERVICE_OPTION_NONE,
2792 run, 2823 &run,
2793 client_notify_connect, 2824 &client_notify_connect,
2794 client_notify_disconnect, 2825 &client_notify_disconnect,
2795 NULL, 2826 NULL,
2796 GNUNET_MQ_hd_fixed_size (client_master_start, 2827 GNUNET_MQ_hd_fixed_size (client_master_start,
2797 GNUNET_MESSAGE_TYPE_PSYC_MASTER_START, 2828 GNUNET_MESSAGE_TYPE_PSYC_MASTER_START,
@@ -2805,6 +2836,10 @@ GNUNET_SERVICE_MAIN
2805 GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION, 2836 GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION,
2806 struct GNUNET_PSYC_JoinDecisionMessage, 2837 struct GNUNET_PSYC_JoinDecisionMessage,
2807 NULL), 2838 NULL),
2839 GNUNET_MQ_hd_fixed_size (client_part_request,
2840 GNUNET_MESSAGE_TYPE_PSYC_PART_REQUEST,
2841 struct GNUNET_MessageHeader,
2842 NULL),
2808 GNUNET_MQ_hd_var_size (client_psyc_message, 2843 GNUNET_MQ_hd_var_size (client_psyc_message,
2809 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE, 2844 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE,
2810 struct GNUNET_MessageHeader, 2845 struct GNUNET_MessageHeader,
diff --git a/src/psyc/psyc_api.c b/src/psyc/psyc_api.c
index c93d8b383..d8f4c98bc 100644
--- a/src/psyc/psyc_api.c
+++ b/src/psyc/psyc_api.c
@@ -260,6 +260,10 @@ handle_channel_result (void *cls,
260 GNUNET_OP_result (chn->op, GNUNET_ntohll (res->op_id), 260 GNUNET_OP_result (chn->op, GNUNET_ntohll (res->op_id),
261 GNUNET_ntohll (res->result_code), 261 GNUNET_ntohll (res->result_code),
262 data, data_size, NULL); 262 data, data_size, NULL);
263
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
265 "handle_channel_result: Received result message with OP ID %" PRIu64 "\n",
266 GNUNET_ntohll (res->op_id));
263} 267}
264 268
265 269
@@ -555,6 +559,9 @@ handle_slave_join_decision (void *cls,
555static void 559static void
556channel_cleanup (struct GNUNET_PSYC_Channel *chn) 560channel_cleanup (struct GNUNET_PSYC_Channel *chn)
557{ 561{
562 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
563 "cleaning up channel %p\n",
564 chn);
558 if (NULL != chn->tmit) 565 if (NULL != chn->tmit)
559 { 566 {
560 GNUNET_PSYC_transmit_destroy (chn->tmit); 567 GNUNET_PSYC_transmit_destroy (chn->tmit);
@@ -562,6 +569,7 @@ channel_cleanup (struct GNUNET_PSYC_Channel *chn)
562 } 569 }
563 if (NULL != chn->recv) 570 if (NULL != chn->recv)
564 { 571 {
572
565 GNUNET_PSYC_receive_destroy (chn->recv); 573 GNUNET_PSYC_receive_destroy (chn->recv);
566 chn->recv = NULL; 574 chn->recv = NULL;
567 } 575 }
@@ -585,30 +593,12 @@ channel_cleanup (struct GNUNET_PSYC_Channel *chn)
585 593
586 594
587static void 595static void
588channel_disconnect (struct GNUNET_PSYC_Channel *chn, 596handle_channel_part_ack (void *cls,
589 GNUNET_ContinuationCallback cb, 597 const struct GNUNET_MessageHeader *msg)
590 void *cls)
591{ 598{
592 chn->is_disconnecting = GNUNET_YES; 599 struct GNUNET_PSYC_Channel *chn = cls;
593 chn->disconnect_cb = cb;
594 chn->disconnect_cls = cls;
595 600
596 if (NULL != chn->mq) 601 channel_cleanup (chn);
597 {
598 struct GNUNET_MQ_Envelope *env = GNUNET_MQ_get_last_envelope (chn->mq);
599 if (NULL != env)
600 {
601 GNUNET_MQ_notify_sent (env, (GNUNET_SCHEDULER_TaskCallback) channel_cleanup, chn);
602 }
603 else
604 {
605 channel_cleanup (chn);
606 }
607 }
608 else
609 {
610 channel_cleanup (chn);
611 }
612} 602}
613 603
614 604
@@ -671,6 +661,10 @@ master_connect (struct GNUNET_PSYC_Master *mst)
671 GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST, 661 GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST,
672 struct GNUNET_PSYC_JoinRequestMessage, 662 struct GNUNET_PSYC_JoinRequestMessage,
673 mst), 663 mst),
664 GNUNET_MQ_hd_fixed_size (channel_part_ack,
665 GNUNET_MESSAGE_TYPE_PSYC_PART_ACK,
666 struct GNUNET_MessageHeader,
667 chn),
674 GNUNET_MQ_hd_var_size (channel_message, 668 GNUNET_MQ_hd_var_size (channel_message,
675 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE, 669 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE,
676 struct GNUNET_PSYC_MessageHeader, 670 struct GNUNET_PSYC_MessageHeader,
@@ -694,8 +688,11 @@ master_connect (struct GNUNET_PSYC_Master *mst)
694 GNUNET_MQ_handler_end () 688 GNUNET_MQ_handler_end ()
695 }; 689 };
696 690
697 chn->mq = GNUNET_CLIENT_connect (chn->cfg, "psyc", 691 chn->mq = GNUNET_CLIENT_connect (chn->cfg,
698 handlers, master_disconnected, mst); 692 "psyc",
693 handlers,
694 &master_disconnected,
695 mst);
699 GNUNET_assert (NULL != chn->mq); 696 GNUNET_assert (NULL != chn->mq);
700 chn->tmit = GNUNET_PSYC_transmit_create (chn->mq); 697 chn->tmit = GNUNET_PSYC_transmit_create (chn->mq);
701 698
@@ -780,10 +777,13 @@ GNUNET_PSYC_master_stop (struct GNUNET_PSYC_Master *mst,
780 void *stop_cls) 777 void *stop_cls)
781{ 778{
782 struct GNUNET_PSYC_Channel *chn = &mst->chn; 779 struct GNUNET_PSYC_Channel *chn = &mst->chn;
780 struct GNUNET_MQ_Envelope *env;
783 781
784 /* FIXME: send msg to service */ 782 chn->is_disconnecting = GNUNET_YES;
785 783 chn->disconnect_cb = stop_cb;
786 channel_disconnect (chn, stop_cb, stop_cls); 784 chn->disconnect_cls = stop_cls;
785 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_PSYC_PART_REQUEST);
786 GNUNET_MQ_send (chn->mq, env);
787} 787}
788 788
789 789
@@ -931,7 +931,8 @@ slave_reconnect (void *cls)
931 * Reconnect after backoff period. 931 * Reconnect after backoff period.
932 */ 932 */
933static void 933static void
934slave_disconnected (void *cls, enum GNUNET_MQ_Error error) 934slave_disconnected (void *cls,
935 enum GNUNET_MQ_Error error)
935{ 936{
936 struct GNUNET_PSYC_Slave *slv = cls; 937 struct GNUNET_PSYC_Slave *slv = cls;
937 struct GNUNET_PSYC_Channel *chn = &slv->chn; 938 struct GNUNET_PSYC_Channel *chn = &slv->chn;
@@ -950,7 +951,7 @@ slave_disconnected (void *cls, enum GNUNET_MQ_Error error)
950 chn->mq = NULL; 951 chn->mq = NULL;
951 } 952 }
952 chn->reconnect_task = GNUNET_SCHEDULER_add_delayed (chn->reconnect_delay, 953 chn->reconnect_task = GNUNET_SCHEDULER_add_delayed (chn->reconnect_delay,
953 slave_reconnect, 954 &slave_reconnect,
954 slv); 955 slv);
955 chn->reconnect_delay = GNUNET_TIME_STD_BACKOFF (chn->reconnect_delay); 956 chn->reconnect_delay = GNUNET_TIME_STD_BACKOFF (chn->reconnect_delay);
956} 957}
@@ -970,6 +971,10 @@ slave_connect (struct GNUNET_PSYC_Slave *slv)
970 GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION, 971 GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION,
971 struct GNUNET_PSYC_JoinDecisionMessage, 972 struct GNUNET_PSYC_JoinDecisionMessage,
972 slv), 973 slv),
974 GNUNET_MQ_hd_fixed_size (channel_part_ack,
975 GNUNET_MESSAGE_TYPE_PSYC_PART_ACK,
976 struct GNUNET_MessageHeader,
977 chn),
973 GNUNET_MQ_hd_var_size (channel_message, 978 GNUNET_MQ_hd_var_size (channel_message,
974 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE, 979 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE,
975 struct GNUNET_PSYC_MessageHeader, 980 struct GNUNET_PSYC_MessageHeader,
@@ -993,9 +998,19 @@ slave_connect (struct GNUNET_PSYC_Slave *slv)
993 GNUNET_MQ_handler_end () 998 GNUNET_MQ_handler_end ()
994 }; 999 };
995 1000
996 chn->mq = GNUNET_CLIENT_connect (chn->cfg, "psyc", 1001 chn->mq = GNUNET_CLIENT_connect (chn->cfg,
997 handlers, slave_disconnected, slv); 1002 "psyc",
998 GNUNET_assert (NULL != chn->mq); 1003 handlers,
1004 &slave_disconnected,
1005 slv);
1006 if (NULL == chn->mq)
1007 {
1008 chn->reconnect_task = GNUNET_SCHEDULER_add_delayed (chn->reconnect_delay,
1009 &slave_reconnect,
1010 slv);
1011 chn->reconnect_delay = GNUNET_TIME_STD_BACKOFF (chn->reconnect_delay);
1012 return;
1013 }
999 chn->tmit = GNUNET_PSYC_transmit_create (chn->mq); 1014 chn->tmit = GNUNET_PSYC_transmit_create (chn->mq);
1000 1015
1001 GNUNET_MQ_send_copy (chn->mq, chn->connect_env); 1016 GNUNET_MQ_send_copy (chn->mq, chn->connect_env);
@@ -1107,10 +1122,13 @@ GNUNET_PSYC_slave_part (struct GNUNET_PSYC_Slave *slv,
1107 void *part_cls) 1122 void *part_cls)
1108{ 1123{
1109 struct GNUNET_PSYC_Channel *chn = &slv->chn; 1124 struct GNUNET_PSYC_Channel *chn = &slv->chn;
1125 struct GNUNET_MQ_Envelope *env;
1110 1126
1111 /* FIXME: send msg to service */ 1127 chn->is_disconnecting = GNUNET_YES;
1112 1128 chn->disconnect_cb = part_cb;
1113 channel_disconnect (chn, part_cb, part_cls); 1129 chn->disconnect_cls = part_cls;
1130 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_PSYC_PART_REQUEST);
1131 GNUNET_MQ_send (chn->mq, env);
1114} 1132}
1115 1133
1116 1134
@@ -1233,6 +1251,9 @@ GNUNET_PSYC_channel_slave_add (struct GNUNET_PSYC_Channel *chn,
1233 req->did_join = GNUNET_YES; 1251 req->did_join = GNUNET_YES;
1234 req->op_id = GNUNET_htonll (GNUNET_OP_add (chn->op, result_cb, cls, NULL)); 1252 req->op_id = GNUNET_htonll (GNUNET_OP_add (chn->op, result_cb, cls, NULL));
1235 1253
1254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1255 "GNUNET_PSYC_channel_slave_add, OP ID: %" PRIu64 "\n",
1256 GNUNET_ntohll (req->op_id));
1236 GNUNET_MQ_send (chn->mq, env); 1257 GNUNET_MQ_send (chn->mq, env);
1237} 1258}
1238 1259
@@ -1283,6 +1304,9 @@ GNUNET_PSYC_channel_slave_remove (struct GNUNET_PSYC_Channel *chn,
1283 req->did_join = GNUNET_NO; 1304 req->did_join = GNUNET_NO;
1284 req->op_id = GNUNET_htonll (GNUNET_OP_add (chn->op, result_cb, cls, NULL)); 1305 req->op_id = GNUNET_htonll (GNUNET_OP_add (chn->op, result_cb, cls, NULL));
1285 1306
1307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1308 "GNUNET_PSYC_channel_slave_remove, OP ID: %" PRIu64 "\n",
1309 GNUNET_ntohll (req->op_id));
1286 GNUNET_MQ_send (chn->mq, env); 1310 GNUNET_MQ_send (chn->mq, env);
1287} 1311}
1288 1312
@@ -1321,6 +1345,10 @@ channel_history_replay (struct GNUNET_PSYC_Channel *chn,
1321 req->message_limit = GNUNET_htonll (message_limit); 1345 req->message_limit = GNUNET_htonll (message_limit);
1322 req->flags = htonl (flags); 1346 req->flags = htonl (flags);
1323 req->op_id = GNUNET_htonll (hist->op_id); 1347 req->op_id = GNUNET_htonll (hist->op_id);
1348
1349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1350 "channel_history_replay, OP ID: %" PRIu64 "\n",
1351 GNUNET_ntohll (req->op_id));
1324 GNUNET_memcpy (&req[1], method_prefix, method_size); 1352 GNUNET_memcpy (&req[1], method_prefix, method_size);
1325 1353
1326 GNUNET_MQ_send (chn->mq, env); 1354 GNUNET_MQ_send (chn->mq, env);
@@ -1459,6 +1487,11 @@ channel_state_get (struct GNUNET_PSYC_Channel *chn,
1459 struct GNUNET_MQ_Envelope * 1487 struct GNUNET_MQ_Envelope *
1460 env = GNUNET_MQ_msg_extra (req, name_size, type); 1488 env = GNUNET_MQ_msg_extra (req, name_size, type);
1461 req->op_id = GNUNET_htonll (sr->op_id); 1489 req->op_id = GNUNET_htonll (sr->op_id);
1490
1491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1492 "channel_state_get, OP ID: %" PRIu64 "\n",
1493 GNUNET_ntohll (req->op_id));
1494
1462 GNUNET_memcpy (&req[1], name, name_size); 1495 GNUNET_memcpy (&req[1], name, name_size);
1463 1496
1464 GNUNET_MQ_send (chn->mq, env); 1497 GNUNET_MQ_send (chn->mq, env);
diff --git a/src/psyc/test_psyc.c b/src/psyc/test_psyc.c
index 03a1890b1..370befb9d 100644
--- a/src/psyc/test_psyc.c
+++ b/src/psyc/test_psyc.c
@@ -755,15 +755,22 @@ slave_add ()
755 755
756 756
757static void 757static void
758schedule_second_slave_join (void *cls)
759{
760 slave_join (TEST_SLAVE_JOIN_ACCEPT);
761}
762
763
764static void
758first_slave_parted (void *cls) 765first_slave_parted (void *cls)
759{ 766{
760 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "First slave parted.\n"); 767 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "First slave parted.\n");
761 slave_join (TEST_SLAVE_JOIN_ACCEPT); 768 GNUNET_SCHEDULER_add_now (&schedule_second_slave_join, NULL);
762} 769}
763 770
764 771
765static void 772static void
766schedule_slave_part (void *cls) 773schedule_first_slave_part (void *cls)
767{ 774{
768 GNUNET_PSYC_slave_part (slv, GNUNET_NO, &first_slave_parted, NULL); 775 GNUNET_PSYC_slave_part (slv, GNUNET_NO, &first_slave_parted, NULL);
769} 776}
@@ -783,7 +790,7 @@ join_decision_cb (void *cls,
783 case TEST_SLAVE_JOIN_REJECT: 790 case TEST_SLAVE_JOIN_REJECT:
784 GNUNET_assert (0 == is_admitted); 791 GNUNET_assert (0 == is_admitted);
785 GNUNET_assert (1 == join_req_count); 792 GNUNET_assert (1 == join_req_count);
786 GNUNET_SCHEDULER_add_now (&schedule_slave_part, NULL); 793 GNUNET_SCHEDULER_add_now (&schedule_first_slave_part, NULL);
787 break; 794 break;
788 795
789 case TEST_SLAVE_JOIN_ACCEPT: 796 case TEST_SLAVE_JOIN_ACCEPT:
@@ -844,11 +851,18 @@ slave_join (int t)
844 struct GNUNET_PSYC_Message * 851 struct GNUNET_PSYC_Message *
845 join_msg = GNUNET_PSYC_message_create ("_request_join", env, "some data", 9); 852 join_msg = GNUNET_PSYC_message_create ("_request_join", env, "some data", 9);
846 853
847 slv = GNUNET_PSYC_slave_join (cfg, &channel_pub_key, slave_key, 854 slv = GNUNET_PSYC_slave_join (cfg,
855 &channel_pub_key,
856 slave_key,
848 GNUNET_PSYC_SLAVE_JOIN_NONE, 857 GNUNET_PSYC_SLAVE_JOIN_NONE,
849 &origin, 0, NULL, 858 &origin,
850 &slave_message_cb, &slave_message_part_cb, 859 0,
851 &slave_connect_cb, &join_decision_cb, NULL, 860 NULL,
861 &slave_message_cb,
862 &slave_message_part_cb,
863 &slave_connect_cb,
864 &join_decision_cb,
865 NULL,
852 join_msg); 866 join_msg);
853 GNUNET_free (join_msg); 867 GNUNET_free (join_msg);
854 slv_chn = GNUNET_PSYC_slave_get_channel (slv); 868 slv_chn = GNUNET_PSYC_slave_get_channel (slv);
diff --git a/src/psyc/test_psyc.conf b/src/psyc/test_psyc.conf
index e69de29bb..e00a614d2 100644
--- a/src/psyc/test_psyc.conf
+++ b/src/psyc/test_psyc.conf
@@ -0,0 +1,16 @@
1@INLINE@ ../../contrib/no_forcestart.conf
2
3[PATHS]
4GNUNET_TEST_HOME = /tmp/gnunet-test-psyc/
5
6[transport]
7PLUGINS = tcp
8
9[nat]
10DISABLEV6 = YES
11ENABLE_UPNP = NO
12BEHIND_NAT = NO
13ALLOW_NAT = NO
14INTERNAL_ADDRESS = 127.0.0.1
15EXTERNAL_ADDRESS = 127.0.0.1
16
diff --git a/src/psycstore/psycstore_api.c b/src/psycstore/psycstore_api.c
index d79daa357..5a4865dce 100644
--- a/src/psycstore/psycstore_api.c
+++ b/src/psycstore/psycstore_api.c
@@ -148,14 +148,14 @@ handle_result_code (void *cls, const struct OperationResult *opres)
148 str, size - sizeof (*opres), (void **) &op)) 148 str, size - sizeof (*opres), (void **) &op))
149 { 149 {
150 LOG (GNUNET_ERROR_TYPE_DEBUG, 150 LOG (GNUNET_ERROR_TYPE_DEBUG,
151 "handle_result_code: Received result message with operation ID: %" PRIu64 "\n", 151 "handle_result_code: Received result message with OP ID: %" PRIu64 "\n",
152 GNUNET_ntohll (opres->op_id)); 152 GNUNET_ntohll (opres->op_id));
153 GNUNET_free (op); 153 GNUNET_free (op);
154 } 154 }
155 else 155 else
156 { 156 {
157 LOG (GNUNET_ERROR_TYPE_DEBUG, 157 LOG (GNUNET_ERROR_TYPE_DEBUG,
158 "handle_result_code: No callback registered for operation with ID %" PRIu64 ".\n", 158 "handle_result_code: No callback registered for OP ID %" PRIu64 ".\n",
159 GNUNET_ntohll (opres->op_id)); 159 GNUNET_ntohll (opres->op_id));
160 } 160 }
161 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS; 161 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
@@ -187,7 +187,7 @@ handle_result_counters (void *cls, const struct CountersResult *cres)
187 else 187 else
188 { 188 {
189 LOG (GNUNET_ERROR_TYPE_DEBUG, 189 LOG (GNUNET_ERROR_TYPE_DEBUG,
190 "handle_result_counters: No callback registered for operation with ID %" PRIu64 ".\n", 190 "handle_result_counters: No callback registered for OP ID %" PRIu64 ".\n",
191 GNUNET_ntohll (cres->op_id)); 191 GNUNET_ntohll (cres->op_id));
192 } 192 }
193 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS; 193 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
@@ -233,7 +233,7 @@ handle_result_fragment (void *cls, const struct FragmentResult *fres)
233 else 233 else
234 { 234 {
235 LOG (GNUNET_ERROR_TYPE_DEBUG, 235 LOG (GNUNET_ERROR_TYPE_DEBUG,
236 "handle_result_fragment: No callback registered for operation with ID %" PRIu64 ".\n", 236 "handle_result_fragment: No callback registered for OP ID %" PRIu64 ".\n",
237 GNUNET_ntohll (fres->op_id)); 237 GNUNET_ntohll (fres->op_id));
238 } 238 }
239 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS; 239 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
@@ -282,7 +282,7 @@ handle_result_state (void *cls, const struct StateResult *sres)
282 else 282 else
283 { 283 {
284 LOG (GNUNET_ERROR_TYPE_DEBUG, 284 LOG (GNUNET_ERROR_TYPE_DEBUG,
285 "handle_result_state: No callback registered for operation with ID %" PRIu64 ".\n", 285 "handle_result_state: No callback registered for OP ID %" PRIu64 ".\n",
286 GNUNET_ntohll (sres->op_id)); 286 GNUNET_ntohll (sres->op_id));
287 } 287 }
288 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS; 288 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
@@ -362,6 +362,9 @@ do_connect (struct GNUNET_PSYCSTORE_Handle *h)
362static void 362static void
363reconnect (void *cls) 363reconnect (void *cls)
364{ 364{
365 struct GNUNET_PSYCSTORE_Handle *h = cls;
366
367 h->reconnect_task = NULL;
365 do_connect (cls); 368 do_connect (cls);
366} 369}
367 370
diff --git a/src/regex/regex_internal_dht.c b/src/regex/regex_internal_dht.c
index b80dabca0..828bb1648 100644
--- a/src/regex/regex_internal_dht.c
+++ b/src/regex/regex_internal_dht.c
@@ -154,23 +154,30 @@ regex_iterator (void *cls,
154 NULL, NULL); 154 NULL, NULL);
155 } 155 }
156 block = REGEX_BLOCK_create (proof, 156 block = REGEX_BLOCK_create (proof,
157 num_edges, edges, 157 num_edges,
158 edges,
158 accepting, 159 accepting,
159 &size); 160 &size);
160 (void) 161 if (NULL == block)
161 GNUNET_DHT_put (h->dht, key, 162 return;
162 DHT_REPLICATION, 163 (void) GNUNET_DHT_put (h->dht,
163 DHT_OPT, 164 key,
164 GNUNET_BLOCK_TYPE_REGEX, 165 DHT_REPLICATION,
165 size, block, 166 DHT_OPT,
166 GNUNET_TIME_relative_to_absolute (DHT_TTL), 167 GNUNET_BLOCK_TYPE_REGEX,
167 NULL, NULL); 168 size,
169 block,
170 GNUNET_TIME_relative_to_absolute (DHT_TTL),
171 NULL,
172 NULL);
168 GNUNET_STATISTICS_update (h->stats, 173 GNUNET_STATISTICS_update (h->stats,
169 "# regex blocks stored", 174 "# regex blocks stored",
170 1, GNUNET_NO); 175 1,
176 GNUNET_NO);
171 GNUNET_STATISTICS_update (h->stats, 177 GNUNET_STATISTICS_update (h->stats,
172 "# regex block bytes stored", 178 "# regex block bytes stored",
173 size, GNUNET_NO); 179 size,
180 GNUNET_NO);
174 GNUNET_free (block); 181 GNUNET_free (block);
175} 182}
176 183
diff --git a/src/regex/regex_test_lib.c b/src/regex/regex_test_lib.c
index f4025f652..814380246 100644
--- a/src/regex/regex_test_lib.c
+++ b/src/regex/regex_test_lib.c
@@ -99,8 +99,7 @@ c2i (char c, int size)
99static void 99static void
100space (int n) 100space (int n)
101{ 101{
102 int i; 102 for (int i = 0; i < n; i++)
103 for (i = 0; i < n; i++)
104 fprintf (stderr, "| "); 103 fprintf (stderr, "| ");
105} 104}
106 105
@@ -114,8 +113,7 @@ space (int n)
114static void 113static void
115debugctx (struct RegexCombineCtx *ctx, int level) 114debugctx (struct RegexCombineCtx *ctx, int level)
116{ 115{
117 return; 116#if DEBUG_REGEX
118 unsigned int i;
119 if (NULL != ctx->s) 117 if (NULL != ctx->s)
120 { 118 {
121 space (level - 1); 119 space (level - 1);
@@ -123,7 +121,7 @@ debugctx (struct RegexCombineCtx *ctx, int level)
123 } 121 }
124 else 122 else
125 fprintf (stderr, "ROOT (base %u)\n", ctx->size); 123 fprintf (stderr, "ROOT (base %u)\n", ctx->size);
126 for (i = 0; i < ctx->size; i++) 124 for (unsigned int i = 0; i < ctx->size; i++)
127 { 125 {
128 if (NULL != ctx->children[i]) 126 if (NULL != ctx->children[i])
129 { 127 {
@@ -132,6 +130,7 @@ debugctx (struct RegexCombineCtx *ctx, int level)
132 } 130 }
133 } 131 }
134 fflush(stderr); 132 fflush(stderr);
133#endif
135} 134}
136 135
137 136
@@ -142,7 +141,8 @@ debugctx (struct RegexCombineCtx *ctx, int level)
142 * @param regex Regex to add. 141 * @param regex Regex to add.
143 */ 142 */
144static void 143static void
145regex_add (struct RegexCombineCtx *ctx, const char *regex); 144regex_add (struct RegexCombineCtx *ctx,
145 const char *regex);
146 146
147 147
148/** 148/**
@@ -164,14 +164,18 @@ new_regex_ctx (unsigned int alphabet_size)
164 return ctx; 164 return ctx;
165} 165}
166 166
167
167static void 168static void
168move_children (struct RegexCombineCtx *dst, const struct RegexCombineCtx *src) 169move_children (struct RegexCombineCtx *dst,
170 const struct RegexCombineCtx *src)
169{ 171{
170 size_t array_size; 172 size_t array_size;
171 173
172 array_size = sizeof(struct RegexCombineCtx *) * src->size; 174 array_size = sizeof(struct RegexCombineCtx *) * src->size;
173 memcpy (dst->children, src->children, array_size); 175 memcpy (dst->children,
174 for (int i = 0; i < src->size; i++) 176 src->children,
177 array_size);
178 for (unsigned int i = 0; i < src->size; i++)
175 { 179 {
176 src->children[i] = NULL; 180 src->children[i] = NULL;
177 } 181 }
@@ -402,6 +406,7 @@ regex_split (struct RegexCombineCtx *ctx,
402 tmp = ctx->children; 406 tmp = ctx->children;
403 ctx->children = GNUNET_malloc (sizeof(*tmp) * ctx->size); 407 ctx->children = GNUNET_malloc (sizeof(*tmp) * ctx->size);
404 regex_add_multiple (ctx, suffix, tmp); 408 regex_add_multiple (ctx, suffix, tmp);
409 GNUNET_free (suffix);
405 GNUNET_free (tmp); 410 GNUNET_free (tmp);
406 return; 411 return;
407 } 412 }
diff --git a/src/rest/Makefile.am b/src/rest/Makefile.am
index c0feb9122..ebfb98024 100644
--- a/src/rest/Makefile.am
+++ b/src/rest/Makefile.am
@@ -26,6 +26,8 @@ lib_LTLIBRARIES = \
26libexec_PROGRAMS = \ 26libexec_PROGRAMS = \
27 gnunet-rest-server 27 gnunet-rest-server
28 28
29EXTRA_DIST = \
30 rest.conf
29 31
30gnunet_rest_server_SOURCES = \ 32gnunet_rest_server_SOURCES = \
31 gnunet-rest-server.c 33 gnunet-rest-server.c
diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c
index 8281e9a16..23f654141 100644
--- a/src/revocation/gnunet-service-revocation.c
+++ b/src/revocation/gnunet-service-revocation.c
@@ -759,7 +759,11 @@ handle_revocation_union_request (void *cls,
759 { 759 {
760 peer_entry = new_peer_entry (other_peer); 760 peer_entry = new_peer_entry (other_peer);
761 } 761 }
762 GNUNET_assert (NULL == peer_entry->so); 762 if (NULL != peer_entry->so)
763 {
764 GNUNET_break_op (0);
765 return;
766 }
763 peer_entry->so = GNUNET_SET_accept (request, 767 peer_entry->so = GNUNET_SET_accept (request,
764 GNUNET_SET_RESULT_ADDED, 768 GNUNET_SET_RESULT_ADDED,
765 (struct GNUNET_SET_Option[]) {{ 0 }}, 769 (struct GNUNET_SET_Option[]) {{ 0 }},
@@ -769,8 +773,7 @@ handle_revocation_union_request (void *cls,
769 GNUNET_SET_commit (peer_entry->so, 773 GNUNET_SET_commit (peer_entry->so,
770 revocation_set)) 774 revocation_set))
771 { 775 {
772 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 776 GNUNET_break (0);
773 _("SET service crashed, terminating revocation service\n"));
774 GNUNET_SCHEDULER_shutdown (); 777 GNUNET_SCHEDULER_shutdown ();
775 return; 778 return;
776 } 779 }
diff --git a/src/rps/.gitignore b/src/rps/.gitignore
index 0d460e62c..cb14f5b09 100644
--- a/src/rps/.gitignore
+++ b/src/rps/.gitignore
@@ -1,3 +1,15 @@
1gnunet-service-rps 1gnunet-service-rps
2gnunet-rps 2gnunet-rps
3gnunet-rps-profiler 3gnunet-rps-profiler
4test_rps_malicious_1
5test_rps_malicious_2
6test_rps_malicious_3
7test_rps_req_cancel
8test_rps_seed_big
9test_rps_seed_request
10test_rps_single_req
11test_service_rps_custommap
12test_service_rps_sampler_elem
13test_service_rps_view
14test_rps_churn
15test_service_rps_peers
diff --git a/src/rps/Makefile.am b/src/rps/Makefile.am
index e6c8cd929..de3469254 100644
--- a/src/rps/Makefile.am
+++ b/src/rps/Makefile.am
@@ -49,7 +49,6 @@ endif
49gnunet_service_rps_SOURCES = \ 49gnunet_service_rps_SOURCES = \
50 gnunet-service-rps_sampler_elem.h gnunet-service-rps_sampler_elem.c \ 50 gnunet-service-rps_sampler_elem.h gnunet-service-rps_sampler_elem.c \
51 gnunet-service-rps_sampler.h gnunet-service-rps_sampler.c \ 51 gnunet-service-rps_sampler.h gnunet-service-rps_sampler.c \
52 gnunet-service-rps_peers.h gnunet-service-rps_peers.c \
53 gnunet-service-rps_custommap.h gnunet-service-rps_custommap.c \ 52 gnunet-service-rps_custommap.h gnunet-service-rps_custommap.c \
54 gnunet-service-rps_view.h gnunet-service-rps_view.c \ 53 gnunet-service-rps_view.h gnunet-service-rps_view.c \
55 rps-test_util.h rps-test_util.c \ 54 rps-test_util.h rps-test_util.c \
@@ -73,7 +72,6 @@ if HAVE_TESTING
73check_PROGRAMS = \ 72check_PROGRAMS = \
74 test_service_rps_view \ 73 test_service_rps_view \
75 test_service_rps_custommap \ 74 test_service_rps_custommap \
76 test_service_rps_peers \
77 test_service_rps_sampler_elem \ 75 test_service_rps_sampler_elem \
78 test_rps_malicious_1 \ 76 test_rps_malicious_1 \
79 test_rps_malicious_2 \ 77 test_rps_malicious_2 \
@@ -81,7 +79,8 @@ check_PROGRAMS = \
81 test_rps_seed_request \ 79 test_rps_seed_request \
82 test_rps_single_req \ 80 test_rps_single_req \
83 test_rps_req_cancel \ 81 test_rps_req_cancel \
84 test_rps_seed_big 82 test_rps_seed_big \
83 test_rps_churn
85endif 84endif
86 85
87ld_rps_test_lib = \ 86ld_rps_test_lib = \
@@ -105,13 +104,6 @@ test_service_rps_view_SOURCES = \
105 test_service_rps_view.c 104 test_service_rps_view.c
106test_service_rps_view_LDADD = $(top_builddir)/src/util/libgnunetutil.la 105test_service_rps_view_LDADD = $(top_builddir)/src/util/libgnunetutil.la
107 106
108test_service_rps_peers_SOURCES = \
109 gnunet-service-rps_peers.h gnunet-service-rps_peers.c \
110 test_service_rps_peers.c
111test_service_rps_peers_LDADD = \
112 $(top_builddir)/src/util/libgnunetutil.la \
113 $(top_builddir)/src/cadet/libgnunetcadet.la
114
115test_service_rps_custommap_SOURCES = \ 107test_service_rps_custommap_SOURCES = \
116 gnunet-service-rps_custommap.h gnunet-service-rps_custommap.c \ 108 gnunet-service-rps_custommap.h gnunet-service-rps_custommap.c \
117 test_service_rps_custommap.c 109 test_service_rps_custommap.c
@@ -145,6 +137,9 @@ test_rps_req_cancel_LDADD = $(ld_rps_test_lib)
145test_rps_seed_big_SOURCES = $(rps_test_src) 137test_rps_seed_big_SOURCES = $(rps_test_src)
146test_rps_seed_big_LDADD = $(ld_rps_test_lib) 138test_rps_seed_big_LDADD = $(ld_rps_test_lib)
147 139
140test_rps_churn_SOURCES = $(rps_test_src)
141test_rps_churn_LDADD = $(ld_rps_test_lib)
142
148gnunet_rps_profiler_SOURCES = $(rps_test_src) 143gnunet_rps_profiler_SOURCES = $(rps_test_src)
149gnunet_rps_profiler_LDADD = $(ld_rps_test_lib) 144gnunet_rps_profiler_LDADD = $(ld_rps_test_lib)
150 145
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 0a4543b30..ec70075cf 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -33,7 +33,6 @@
33#include "rps-test_util.h" 33#include "rps-test_util.h"
34#include "gnunet-service-rps_sampler.h" 34#include "gnunet-service-rps_sampler.h"
35#include "gnunet-service-rps_custommap.h" 35#include "gnunet-service-rps_custommap.h"
36#include "gnunet-service-rps_peers.h"
37#include "gnunet-service-rps_view.h" 36#include "gnunet-service-rps_view.h"
38 37
39#include <math.h> 38#include <math.h>
@@ -66,6 +65,1728 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
66static struct GNUNET_PeerIdentity own_identity; 65static struct GNUNET_PeerIdentity own_identity;
67 66
68 67
68
69/***********************************************************************
70 * Old gnunet-service-rps_peers.c
71***********************************************************************/
72
73/**
74 * Set a peer flag of given peer context.
75 */
76#define set_peer_flag(peer_ctx, mask) ((peer_ctx->peer_flags) |= (mask))
77
78/**
79 * Get peer flag of given peer context.
80 */
81#define check_peer_flag_set(peer_ctx, mask)\
82 ((peer_ctx->peer_flags) & (mask) ? GNUNET_YES : GNUNET_NO)
83
84/**
85 * Unset flag of given peer context.
86 */
87#define unset_peer_flag(peer_ctx, mask) ((peer_ctx->peer_flags) &= ~(mask))
88
89/**
90 * Set a channel flag of given channel context.
91 */
92#define set_channel_flag(channel_flags, mask) ((*channel_flags) |= (mask))
93
94/**
95 * Get channel flag of given channel context.
96 */
97#define check_channel_flag_set(channel_flags, mask)\
98 ((*channel_flags) & (mask) ? GNUNET_YES : GNUNET_NO)
99
100/**
101 * Unset flag of given channel context.
102 */
103#define unset_channel_flag(channel_flags, mask) ((*channel_flags) &= ~(mask))
104
105
106
107/**
108 * Pending operation on peer consisting of callback and closure
109 *
110 * When an operation cannot be executed right now this struct is used to store
111 * the callback and closure for later execution.
112 */
113struct PeerPendingOp
114{
115 /**
116 * Callback
117 */
118 PeerOp op;
119
120 /**
121 * Closure
122 */
123 void *op_cls;
124};
125
126/**
127 * List containing all messages that are yet to be send
128 *
129 * This is used to keep track of all messages that have not been sent yet. When
130 * a peer is to be removed the pending messages can be removed properly.
131 */
132struct PendingMessage
133{
134 /**
135 * DLL next, prev
136 */
137 struct PendingMessage *next;
138 struct PendingMessage *prev;
139
140 /**
141 * The envelope to the corresponding message
142 */
143 struct GNUNET_MQ_Envelope *ev;
144
145 /**
146 * The corresponding context
147 */
148 struct PeerContext *peer_ctx;
149
150 /**
151 * The message type
152 */
153 const char *type;
154};
155
156/**
157 * Struct used to keep track of other peer's status
158 *
159 * This is stored in a multipeermap.
160 * It contains information such as cadet channels, a message queue for sending,
161 * status about the channels, the pending operations on this peer and some flags
162 * about the status of the peer itself. (live, valid, ...)
163 */
164struct PeerContext
165{
166 /**
167 * Message queue open to client
168 */
169 struct GNUNET_MQ_Handle *mq;
170
171 /**
172 * Channel open to client.
173 */
174 struct GNUNET_CADET_Channel *send_channel;
175
176 /**
177 * Flags to the sending channel
178 */
179 uint32_t *send_channel_flags;
180
181 /**
182 * Channel open from client.
183 */
184 struct GNUNET_CADET_Channel *recv_channel; // unneeded?
185
186 /**
187 * Flags to the receiving channel
188 */
189 uint32_t *recv_channel_flags;
190
191 /**
192 * Array of pending operations on this peer.
193 */
194 struct PeerPendingOp *pending_ops;
195
196 /**
197 * Handle to the callback given to cadet_ntfy_tmt_rdy()
198 *
199 * To be canceled on shutdown.
200 */
201 struct PendingMessage *liveliness_check_pending;
202
203 /**
204 * Number of pending operations.
205 */
206 unsigned int num_pending_ops;
207
208 /**
209 * Identity of the peer
210 */
211 struct GNUNET_PeerIdentity peer_id;
212
213 /**
214 * Flags indicating status of peer
215 */
216 uint32_t peer_flags;
217
218 /**
219 * Last time we received something from that peer.
220 */
221 struct GNUNET_TIME_Absolute last_message_recv;
222
223 /**
224 * Last time we received a keepalive message.
225 */
226 struct GNUNET_TIME_Absolute last_keepalive;
227
228 /**
229 * DLL with all messages that are yet to be sent
230 */
231 struct PendingMessage *pending_messages_head;
232 struct PendingMessage *pending_messages_tail;
233
234 /**
235 * This is pobably followed by 'statistical' data (when we first saw
236 * him, how did we get his ID, how many pushes (in a timeinterval),
237 * ...)
238 */
239};
240
241/**
242 * @brief Closure to #valid_peer_iterator
243 */
244struct PeersIteratorCls
245{
246 /**
247 * Iterator function
248 */
249 PeersIterator iterator;
250
251 /**
252 * Closure to iterator
253 */
254 void *cls;
255};
256
257/**
258 * @brief Hashmap of valid peers.
259 */
260static struct GNUNET_CONTAINER_MultiPeerMap *valid_peers;
261
262/**
263 * @brief Maximum number of valid peers to keep.
264 * TODO read from config
265 */
266static uint32_t num_valid_peers_max = UINT32_MAX;
267
268/**
269 * @brief Filename of the file that stores the valid peers persistently.
270 */
271static char *filename_valid_peers;
272
273/**
274 * Set of all peers to keep track of them.
275 */
276static struct GNUNET_CONTAINER_MultiPeerMap *peer_map;
277
278/**
279 * Cadet handle.
280 */
281static struct GNUNET_CADET_Handle *cadet_handle;
282
283
284
285/**
286 * @brief Get the #PeerContext associated with a peer
287 *
288 * @param peer the peer id
289 *
290 * @return the #PeerContext
291 */
292static struct PeerContext *
293get_peer_ctx (const struct GNUNET_PeerIdentity *peer)
294{
295 struct PeerContext *ctx;
296 int ret;
297
298 ret = GNUNET_CONTAINER_multipeermap_contains (peer_map, peer);
299 GNUNET_assert (GNUNET_YES == ret);
300 ctx = GNUNET_CONTAINER_multipeermap_get (peer_map, peer);
301 GNUNET_assert (NULL != ctx);
302 return ctx;
303}
304
305int
306Peers_check_peer_known (const struct GNUNET_PeerIdentity *peer);
307
308/**
309 * @brief Create a new #PeerContext and insert it into the peer map
310 *
311 * @param peer the peer to create the #PeerContext for
312 *
313 * @return the #PeerContext
314 */
315static struct PeerContext *
316create_peer_ctx (const struct GNUNET_PeerIdentity *peer)
317{
318 struct PeerContext *ctx;
319 int ret;
320
321 GNUNET_assert (GNUNET_NO == Peers_check_peer_known (peer));
322
323 ctx = GNUNET_new (struct PeerContext);
324 ctx->peer_id = *peer;
325 ctx->send_channel_flags = GNUNET_new (uint32_t);
326 ctx->recv_channel_flags = GNUNET_new (uint32_t);
327 ret = GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx,
328 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
329 GNUNET_assert (GNUNET_OK == ret);
330 return ctx;
331}
332
333
334/**
335 * @brief Create or get a #PeerContext
336 *
337 * @param peer the peer to get the associated context to
338 *
339 * @return the context
340 */
341static struct PeerContext *
342create_or_get_peer_ctx (const struct GNUNET_PeerIdentity *peer)
343{
344 if (GNUNET_NO == Peers_check_peer_known (peer))
345 {
346 return create_peer_ctx (peer);
347 }
348 return get_peer_ctx (peer);
349}
350
351void
352Peers_unset_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags);
353
354void
355Peers_set_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags);
356
357/**
358 * @brief Check whether we have a connection to this @a peer
359 *
360 * Also sets the #Peers_ONLINE flag accordingly
361 *
362 * @param peer the peer in question
363 *
364 * @return #GNUNET_YES if we are connected
365 * #GNUNET_NO otherwise
366 */
367int
368Peers_check_connected (const struct GNUNET_PeerIdentity *peer)
369{
370 const struct PeerContext *peer_ctx;
371
372 /* If we don't know about this peer we don't know whether it's online */
373 if (GNUNET_NO == Peers_check_peer_known (peer))
374 {
375 return GNUNET_NO;
376 }
377 /* Get the context */
378 peer_ctx = get_peer_ctx (peer);
379 /* If we have no channel to this peer we don't know whether it's online */
380 if ( (NULL == peer_ctx->send_channel) &&
381 (NULL == peer_ctx->recv_channel) )
382 {
383 Peers_unset_peer_flag (peer, Peers_ONLINE);
384 return GNUNET_NO;
385 }
386 /* Otherwise (if we have a channel, we know that it's online */
387 Peers_set_peer_flag (peer, Peers_ONLINE);
388 return GNUNET_YES;
389}
390
391
392/**
393 * @brief The closure to #get_rand_peer_iterator.
394 */
395struct GetRandPeerIteratorCls
396{
397 /**
398 * @brief The index of the peer to return.
399 * Will be decreased until 0.
400 * Then current peer is returned.
401 */
402 uint32_t index;
403
404 /**
405 * @brief Pointer to peer to return.
406 */
407 const struct GNUNET_PeerIdentity *peer;
408};
409
410
411/**
412 * @brief Iterator function for #get_random_peer_from_peermap.
413 *
414 * Implements #GNUNET_CONTAINER_PeerMapIterator.
415 * Decreases the index until the index is null.
416 * Then returns the current peer.
417 *
418 * @param cls the #GetRandPeerIteratorCls containing index and peer
419 * @param peer current peer
420 * @param value unused
421 *
422 * @return #GNUNET_YES if we should continue to
423 * iterate,
424 * #GNUNET_NO if not.
425 */
426static int
427get_rand_peer_iterator (void *cls,
428 const struct GNUNET_PeerIdentity *peer,
429 void *value)
430{
431 struct GetRandPeerIteratorCls *iterator_cls = cls;
432 if (0 >= iterator_cls->index)
433 {
434 iterator_cls->peer = peer;
435 return GNUNET_NO;
436 }
437 iterator_cls->index--;
438 return GNUNET_YES;
439}
440
441
442/**
443 * @brief Get a random peer from @a peer_map
444 *
445 * @param peer_map the peer_map to get the peer from
446 *
447 * @return a random peer
448 */
449static const struct GNUNET_PeerIdentity *
450get_random_peer_from_peermap (const struct
451 GNUNET_CONTAINER_MultiPeerMap *peer_map)
452{
453 struct GetRandPeerIteratorCls *iterator_cls;
454 const struct GNUNET_PeerIdentity *ret;
455
456 iterator_cls = GNUNET_new (struct GetRandPeerIteratorCls);
457 iterator_cls->index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
458 GNUNET_CONTAINER_multipeermap_size (peer_map));
459 (void) GNUNET_CONTAINER_multipeermap_iterate (valid_peers,
460 get_rand_peer_iterator,
461 iterator_cls);
462 ret = iterator_cls->peer;
463 GNUNET_free (iterator_cls);
464 return ret;
465}
466
467
468/**
469 * @brief Add a given @a peer to valid peers.
470 *
471 * If valid peers are already #num_valid_peers_max, delete a peer previously.
472 *
473 * @param peer the peer that is added to the valid peers.
474 *
475 * @return #GNUNET_YES if no other peer had to be removed
476 * #GNUNET_NO otherwise
477 */
478static int
479add_valid_peer (const struct GNUNET_PeerIdentity *peer)
480{
481 const struct GNUNET_PeerIdentity *rand_peer;
482 int ret;
483
484 ret = GNUNET_YES;
485 while (GNUNET_CONTAINER_multipeermap_size (valid_peers) >= num_valid_peers_max)
486 {
487 rand_peer = get_random_peer_from_peermap (valid_peers);
488 GNUNET_CONTAINER_multipeermap_remove_all (valid_peers, rand_peer);
489 ret = GNUNET_NO;
490 }
491 (void) GNUNET_CONTAINER_multipeermap_put (valid_peers, peer, NULL,
492 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
493 return ret;
494}
495
496
497/**
498 * @brief Set the peer flag to living and
499 * call the pending operations on this peer.
500 *
501 * Also adds peer to #valid_peers.
502 *
503 * @param peer_ctx the #PeerContext of the peer to set live
504 */
505static void
506set_peer_live (struct PeerContext *peer_ctx)
507{
508 struct GNUNET_PeerIdentity *peer;
509 unsigned int i;
510
511 peer = &peer_ctx->peer_id;
512 LOG (GNUNET_ERROR_TYPE_DEBUG,
513 "Peer %s is live and valid, calling %i pending operations on it\n",
514 GNUNET_i2s (peer),
515 peer_ctx->num_pending_ops);
516
517 if (NULL != peer_ctx->liveliness_check_pending)
518 {
519 LOG (GNUNET_ERROR_TYPE_DEBUG,
520 "Removing pending liveliness check for peer %s\n",
521 GNUNET_i2s (&peer_ctx->peer_id));
522 // TODO wait until cadet sets mq->cancel_impl
523 //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev);
524 GNUNET_free (peer_ctx->liveliness_check_pending);
525 peer_ctx->liveliness_check_pending = NULL;
526 }
527
528 (void) add_valid_peer (peer);
529 set_peer_flag (peer_ctx, Peers_ONLINE);
530
531 /* Call pending operations */
532 for (i = 0; i < peer_ctx->num_pending_ops; i++)
533 {
534 peer_ctx->pending_ops[i].op (peer_ctx->pending_ops[i].op_cls, peer);
535 }
536 GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0);
537}
538
539static void
540cleanup_destroyed_channel (void *cls,
541 const struct GNUNET_CADET_Channel *channel);
542
543/* Declaration of handlers */
544static void
545handle_peer_check (void *cls,
546 const struct GNUNET_MessageHeader *msg);
547
548static void
549handle_peer_push (void *cls,
550 const struct GNUNET_MessageHeader *msg);
551
552static void
553handle_peer_pull_request (void *cls,
554 const struct GNUNET_MessageHeader *msg);
555
556static int
557check_peer_pull_reply (void *cls,
558 const struct GNUNET_RPS_P2P_PullReplyMessage *msg);
559
560static void
561handle_peer_pull_reply (void *cls,
562 const struct GNUNET_RPS_P2P_PullReplyMessage *msg);
563
564/* End declaration of handlers */
565
566
567/**
568 * @brief Get the channel of a peer. If not existing, create.
569 *
570 * @param peer the peer id
571 * @return the #GNUNET_CADET_Channel used to send data to @a peer
572 */
573struct GNUNET_CADET_Channel *
574get_channel (const struct GNUNET_PeerIdentity *peer)
575{
576 struct PeerContext *peer_ctx;
577 struct GNUNET_HashCode port;
578 /* There exists a copy-paste-clone in run() */
579 struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
580 GNUNET_MQ_hd_fixed_size (peer_check,
581 GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE,
582 struct GNUNET_MessageHeader,
583 NULL),
584 GNUNET_MQ_hd_fixed_size (peer_push,
585 GNUNET_MESSAGE_TYPE_RPS_PP_PUSH,
586 struct GNUNET_MessageHeader,
587 NULL),
588 GNUNET_MQ_hd_fixed_size (peer_pull_request,
589 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST,
590 struct GNUNET_MessageHeader,
591 NULL),
592 GNUNET_MQ_hd_var_size (peer_pull_reply,
593 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY,
594 struct GNUNET_RPS_P2P_PullReplyMessage,
595 NULL),
596 GNUNET_MQ_handler_end ()
597 };
598
599
600 peer_ctx = get_peer_ctx (peer);
601 if (NULL == peer_ctx->send_channel)
602 {
603 LOG (GNUNET_ERROR_TYPE_DEBUG,
604 "Trying to establish channel to peer %s\n",
605 GNUNET_i2s (peer));
606 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_RPS,
607 strlen (GNUNET_APPLICATION_PORT_RPS),
608 &port);
609 peer_ctx->send_channel =
610 GNUNET_CADET_channel_create (cadet_handle,
611 (struct GNUNET_PeerIdentity *) peer, /* context */
612 peer,
613 &port,
614 GNUNET_CADET_OPTION_RELIABLE,
615 NULL, /* WindowSize handler */
616 cleanup_destroyed_channel, /* Disconnect handler */
617 cadet_handlers);
618 }
619 GNUNET_assert (NULL != peer_ctx->send_channel);
620 return peer_ctx->send_channel;
621}
622
623
624/**
625 * Get the message queue (#GNUNET_MQ_Handle) of a specific peer.
626 *
627 * If we already have a message queue open to this client,
628 * simply return it, otherways create one.
629 *
630 * @param peer the peer to get the mq to
631 * @return the #GNUNET_MQ_Handle
632 */
633static struct GNUNET_MQ_Handle *
634get_mq (const struct GNUNET_PeerIdentity *peer)
635{
636 struct PeerContext *peer_ctx;
637
638 peer_ctx = get_peer_ctx (peer);
639
640 if (NULL == peer_ctx->mq)
641 {
642 (void) get_channel (peer);
643 peer_ctx->mq = GNUNET_CADET_get_mq (peer_ctx->send_channel);
644 }
645 return peer_ctx->mq;
646}
647
648
649/**
650 * @brief This is called in response to the first message we sent as a
651 * liveliness check.
652 *
653 * @param cls #PeerContext of peer with pending liveliness check
654 */
655static void
656mq_liveliness_check_successful (void *cls)
657{
658 struct PeerContext *peer_ctx = cls;
659
660 if (NULL != peer_ctx->liveliness_check_pending)
661 {
662 LOG (GNUNET_ERROR_TYPE_DEBUG,
663 "Liveliness check for peer %s was successfull\n",
664 GNUNET_i2s (&peer_ctx->peer_id));
665 GNUNET_free (peer_ctx->liveliness_check_pending);
666 peer_ctx->liveliness_check_pending = NULL;
667 set_peer_live (peer_ctx);
668 }
669}
670
671/**
672 * Issue a check whether peer is live
673 *
674 * @param peer_ctx the context of the peer
675 */
676static void
677check_peer_live (struct PeerContext *peer_ctx)
678{
679 LOG (GNUNET_ERROR_TYPE_DEBUG,
680 "Get informed about peer %s getting live\n",
681 GNUNET_i2s (&peer_ctx->peer_id));
682
683 struct GNUNET_MQ_Handle *mq;
684 struct GNUNET_MQ_Envelope *ev;
685
686 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE);
687 peer_ctx->liveliness_check_pending = GNUNET_new (struct PendingMessage);
688 peer_ctx->liveliness_check_pending->ev = ev;
689 peer_ctx->liveliness_check_pending->peer_ctx = peer_ctx;
690 peer_ctx->liveliness_check_pending->type = "Check liveliness";
691 mq = get_mq (&peer_ctx->peer_id);
692 GNUNET_MQ_notify_sent (ev,
693 mq_liveliness_check_successful,
694 peer_ctx);
695 GNUNET_MQ_send (mq, ev);
696}
697
698/**
699 * @brief Add an envelope to a message passed to mq to list of pending messages
700 *
701 * @param peer peer the message was sent to
702 * @param ev envelope to the message
703 * @param type type of the message to be sent
704 * @return pointer to pending message
705 */
706static struct PendingMessage *
707insert_pending_message (const struct GNUNET_PeerIdentity *peer,
708 struct GNUNET_MQ_Envelope *ev,
709 const char *type)
710{
711 struct PendingMessage *pending_msg;
712 struct PeerContext *peer_ctx;
713
714 peer_ctx = get_peer_ctx (peer);
715 pending_msg = GNUNET_new (struct PendingMessage);
716 pending_msg->ev = ev;
717 pending_msg->peer_ctx = peer_ctx;
718 pending_msg->type = type;
719 GNUNET_CONTAINER_DLL_insert (peer_ctx->pending_messages_head,
720 peer_ctx->pending_messages_tail,
721 pending_msg);
722 return pending_msg;
723}
724
725
726/**
727 * @brief Remove a pending message from the respective DLL
728 *
729 * @param pending_msg the pending message to remove
730 * @param cancel cancel the pending message, too
731 */
732static void
733remove_pending_message (struct PendingMessage *pending_msg, int cancel)
734{
735 struct PeerContext *peer_ctx;
736
737 peer_ctx = pending_msg->peer_ctx;
738 GNUNET_assert (NULL != peer_ctx);
739 GNUNET_CONTAINER_DLL_remove (peer_ctx->pending_messages_head,
740 peer_ctx->pending_messages_tail,
741 pending_msg);
742 // TODO wait for the cadet implementation of message cancellation
743 //if (GNUNET_YES == cancel)
744 //{
745 // GNUNET_MQ_send_cancel (pending_msg->ev);
746 //}
747 GNUNET_free (pending_msg);
748}
749
750
751/**
752 * @brief Check whether function of type #PeerOp was already scheduled
753 *
754 * The array with pending operations will probably never grow really big, so
755 * iterating over it should be ok.
756 *
757 * @param peer the peer to check
758 * @param peer_op the operation (#PeerOp) on the peer
759 *
760 * @return #GNUNET_YES if this operation is scheduled on that peer
761 * #GNUNET_NO otherwise
762 */
763static int
764check_operation_scheduled (const struct GNUNET_PeerIdentity *peer,
765 const PeerOp peer_op)
766{
767 const struct PeerContext *peer_ctx;
768 unsigned int i;
769
770 peer_ctx = get_peer_ctx (peer);
771 for (i = 0; i < peer_ctx->num_pending_ops; i++)
772 if (peer_op == peer_ctx->pending_ops[i].op)
773 return GNUNET_YES;
774 return GNUNET_NO;
775}
776
777int
778Peers_remove_peer (const struct GNUNET_PeerIdentity *peer);
779
780/**
781 * Iterator over hash map entries. Deletes all contexts of peers.
782 *
783 * @param cls closure
784 * @param key current public key
785 * @param value value in the hash map
786 * @return #GNUNET_YES if we should continue to iterate,
787 * #GNUNET_NO if not.
788 */
789static int
790peermap_clear_iterator (void *cls,
791 const struct GNUNET_PeerIdentity *key,
792 void *value)
793{
794 Peers_remove_peer (key);
795 return GNUNET_YES;
796}
797
798
799/**
800 * @brief This is called once a message is sent.
801 *
802 * Removes the pending message
803 *
804 * @param cls type of the message that was sent
805 */
806static void
807mq_notify_sent_cb (void *cls)
808{
809 struct PendingMessage *pending_msg = (struct PendingMessage *) cls;
810 LOG (GNUNET_ERROR_TYPE_DEBUG,
811 "%s was sent.\n",
812 pending_msg->type);
813 /* Do not cancle message */
814 remove_pending_message (pending_msg, GNUNET_NO);
815}
816
817
818/**
819 * @brief Iterator function for #store_valid_peers.
820 *
821 * Implements #GNUNET_CONTAINER_PeerMapIterator.
822 * Writes single peer to disk.
823 *
824 * @param cls the file handle to write to.
825 * @param peer current peer
826 * @param value unused
827 *
828 * @return #GNUNET_YES if we should continue to
829 * iterate,
830 * #GNUNET_NO if not.
831 */
832static int
833store_peer_presistently_iterator (void *cls,
834 const struct GNUNET_PeerIdentity *peer,
835 void *value)
836{
837 const struct GNUNET_DISK_FileHandle *fh = cls;
838 char peer_string[128];
839 int size;
840 ssize_t ret;
841
842 if (NULL == peer)
843 {
844 return GNUNET_YES;
845 }
846 size = GNUNET_snprintf (peer_string,
847 sizeof (peer_string),
848 "%s\n",
849 GNUNET_i2s_full (peer));
850 GNUNET_assert (53 == size);
851 ret = GNUNET_DISK_file_write (fh,
852 peer_string,
853 size);
854 GNUNET_assert (size == ret);
855 return GNUNET_YES;
856}
857
858
859/**
860 * @brief Store the peers currently in #valid_peers to disk.
861 */
862static void
863store_valid_peers ()
864{
865 struct GNUNET_DISK_FileHandle *fh;
866 uint32_t number_written_peers;
867 int ret;
868
869 if (0 == strncmp ("DISABLE", filename_valid_peers, 7))
870 {
871 return;
872 }
873
874 ret = GNUNET_DISK_directory_create_for_file (filename_valid_peers);
875 if (GNUNET_SYSERR == ret)
876 {
877 LOG (GNUNET_ERROR_TYPE_WARNING,
878 "Not able to create directory for file `%s'\n",
879 filename_valid_peers);
880 GNUNET_break (0);
881 }
882 else if (GNUNET_NO == ret)
883 {
884 LOG (GNUNET_ERROR_TYPE_WARNING,
885 "Directory for file `%s' exists but is not writable for us\n",
886 filename_valid_peers);
887 GNUNET_break (0);
888 }
889 fh = GNUNET_DISK_file_open (filename_valid_peers,
890 GNUNET_DISK_OPEN_WRITE |
891 GNUNET_DISK_OPEN_CREATE,
892 GNUNET_DISK_PERM_USER_READ |
893 GNUNET_DISK_PERM_USER_WRITE);
894 if (NULL == fh)
895 {
896 LOG (GNUNET_ERROR_TYPE_WARNING,
897 "Not able to write valid peers to file `%s'\n",
898 filename_valid_peers);
899 return;
900 }
901 LOG (GNUNET_ERROR_TYPE_DEBUG,
902 "Writing %u valid peers to disk\n",
903 GNUNET_CONTAINER_multipeermap_size (valid_peers));
904 number_written_peers =
905 GNUNET_CONTAINER_multipeermap_iterate (valid_peers,
906 store_peer_presistently_iterator,
907 fh);
908 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
909 GNUNET_assert (number_written_peers ==
910 GNUNET_CONTAINER_multipeermap_size (valid_peers));
911}
912
913
914/**
915 * @brief Convert string representation of peer id to peer id.
916 *
917 * Counterpart to #GNUNET_i2s_full.
918 *
919 * @param string_repr The string representation of the peer id
920 *
921 * @return The peer id
922 */
923static const struct GNUNET_PeerIdentity *
924s2i_full (const char *string_repr)
925{
926 struct GNUNET_PeerIdentity *peer;
927 size_t len;
928 int ret;
929
930 peer = GNUNET_new (struct GNUNET_PeerIdentity);
931 len = strlen (string_repr);
932 if (52 > len)
933 {
934 LOG (GNUNET_ERROR_TYPE_WARNING,
935 "Not able to convert string representation of PeerID to PeerID\n"
936 "Sting representation: %s (len %lu) - too short\n",
937 string_repr,
938 len);
939 GNUNET_break (0);
940 }
941 else if (52 < len)
942 {
943 len = 52;
944 }
945 ret = GNUNET_CRYPTO_eddsa_public_key_from_string (string_repr,
946 len,
947 &peer->public_key);
948 if (GNUNET_OK != ret)
949 {
950 LOG (GNUNET_ERROR_TYPE_WARNING,
951 "Not able to convert string representation of PeerID to PeerID\n"
952 "Sting representation: %s\n",
953 string_repr);
954 GNUNET_break (0);
955 }
956 return peer;
957}
958
959
960/**
961 * @brief Restore the peers on disk to #valid_peers.
962 */
963static void
964restore_valid_peers ()
965{
966 off_t file_size;
967 uint32_t num_peers;
968 struct GNUNET_DISK_FileHandle *fh;
969 char *buf;
970 ssize_t size_read;
971 char *iter_buf;
972 char *str_repr;
973 const struct GNUNET_PeerIdentity *peer;
974
975 if (0 == strncmp ("DISABLE", filename_valid_peers, 7))
976 {
977 return;
978 }
979
980 if (GNUNET_OK != GNUNET_DISK_file_test (filename_valid_peers))
981 {
982 return;
983 }
984 fh = GNUNET_DISK_file_open (filename_valid_peers,
985 GNUNET_DISK_OPEN_READ,
986 GNUNET_DISK_PERM_NONE);
987 GNUNET_assert (NULL != fh);
988 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_handle_size (fh, &file_size));
989 num_peers = file_size / 53;
990 buf = GNUNET_malloc (file_size);
991 size_read = GNUNET_DISK_file_read (fh, buf, file_size);
992 GNUNET_assert (size_read == file_size);
993 LOG (GNUNET_ERROR_TYPE_DEBUG,
994 "Restoring %" PRIu32 " peers from file `%s'\n",
995 num_peers,
996 filename_valid_peers);
997 for (iter_buf = buf; iter_buf < buf + file_size - 1; iter_buf += 53)
998 {
999 str_repr = GNUNET_strndup (iter_buf, 53);
1000 peer = s2i_full (str_repr);
1001 GNUNET_free (str_repr);
1002 add_valid_peer (peer);
1003 LOG (GNUNET_ERROR_TYPE_DEBUG,
1004 "Restored valid peer %s from disk\n",
1005 GNUNET_i2s_full (peer));
1006 }
1007 iter_buf = NULL;
1008 GNUNET_free (buf);
1009 LOG (GNUNET_ERROR_TYPE_DEBUG,
1010 "num_peers: %" PRIu32 ", _size (valid_peers): %u\n",
1011 num_peers,
1012 GNUNET_CONTAINER_multipeermap_size (valid_peers));
1013 if (num_peers != GNUNET_CONTAINER_multipeermap_size (valid_peers))
1014 {
1015 LOG (GNUNET_ERROR_TYPE_WARNING,
1016 "Number of restored peers does not match file size. Have probably duplicates.\n");
1017 }
1018 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
1019 LOG (GNUNET_ERROR_TYPE_DEBUG,
1020 "Restored %u valid peers from disk\n",
1021 GNUNET_CONTAINER_multipeermap_size (valid_peers));
1022}
1023
1024
1025/**
1026 * @brief Initialise storage of peers
1027 *
1028 * @param fn_valid_peers filename of the file used to store valid peer ids
1029 * @param cadet_h cadet handle
1030 * @param disconnect_handler Disconnect handler
1031 * @param own_id own peer identity
1032 */
1033void
1034Peers_initialise (char* fn_valid_peers,
1035 struct GNUNET_CADET_Handle *cadet_h,
1036 GNUNET_CADET_DisconnectEventHandler disconnect_handler,
1037 const struct GNUNET_PeerIdentity *own_id)
1038{
1039 filename_valid_peers = GNUNET_strdup (fn_valid_peers);
1040 cadet_handle = cadet_h;
1041 own_identity = *own_id;
1042 peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO);
1043 valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO);
1044 restore_valid_peers ();
1045}
1046
1047
1048/**
1049 * @brief Delete storage of peers that was created with #Peers_initialise ()
1050 */
1051void
1052Peers_terminate ()
1053{
1054 if (GNUNET_SYSERR ==
1055 GNUNET_CONTAINER_multipeermap_iterate (peer_map,
1056 peermap_clear_iterator,
1057 NULL))
1058 {
1059 LOG (GNUNET_ERROR_TYPE_WARNING,
1060 "Iteration destroying peers was aborted.\n");
1061 }
1062 GNUNET_CONTAINER_multipeermap_destroy (peer_map);
1063 store_valid_peers ();
1064 GNUNET_free (filename_valid_peers);
1065 GNUNET_CONTAINER_multipeermap_destroy (valid_peers);
1066}
1067
1068
1069/**
1070 * Iterator over #valid_peers hash map entries.
1071 *
1072 * @param cls closure - unused
1073 * @param peer current peer id
1074 * @param value value in the hash map - unused
1075 * @return #GNUNET_YES if we should continue to
1076 * iterate,
1077 * #GNUNET_NO if not.
1078 */
1079static int
1080valid_peer_iterator (void *cls,
1081 const struct GNUNET_PeerIdentity *peer,
1082 void *value)
1083{
1084 struct PeersIteratorCls *it_cls = cls;
1085
1086 return it_cls->iterator (it_cls->cls,
1087 peer);
1088}
1089
1090
1091/**
1092 * @brief Get all currently known, valid peer ids.
1093 *
1094 * @param it function to call on each peer id
1095 * @param it_cls extra argument to @a it
1096 * @return the number of key value pairs processed,
1097 * #GNUNET_SYSERR if it aborted iteration
1098 */
1099int
1100Peers_get_valid_peers (PeersIterator iterator,
1101 void *it_cls)
1102{
1103 struct PeersIteratorCls *cls;
1104 int ret;
1105
1106 cls = GNUNET_new (struct PeersIteratorCls);
1107 cls->iterator = iterator;
1108 cls->cls = it_cls;
1109 ret = GNUNET_CONTAINER_multipeermap_iterate (valid_peers,
1110 valid_peer_iterator,
1111 cls);
1112 GNUNET_free (cls);
1113 return ret;
1114}
1115
1116
1117/**
1118 * @brief Add peer to known peers.
1119 *
1120 * This function is called on new peer_ids from 'external' sources
1121 * (client seed, cadet get_peers(), ...)
1122 *
1123 * @param peer the new #GNUNET_PeerIdentity
1124 *
1125 * @return #GNUNET_YES if peer was inserted
1126 * #GNUNET_NO otherwise (if peer was already known or
1127 * peer was #own_identity)
1128 */
1129int
1130Peers_insert_peer (const struct GNUNET_PeerIdentity *peer)
1131{
1132 if ( (GNUNET_YES == Peers_check_peer_known (peer)) ||
1133 (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, &own_identity)) )
1134 {
1135 return GNUNET_NO; /* We already know this peer - nothing to do */
1136 }
1137 (void) create_peer_ctx (peer);
1138 return GNUNET_YES;
1139}
1140
1141int
1142Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags);
1143
1144/**
1145 * @brief Try connecting to a peer to see whether it is online
1146 *
1147 * If not known yet, insert into known peers
1148 *
1149 * @param peer the peer whose liveliness is to be checked
1150 * @return #GNUNET_YES if peer had to be inserted
1151 * #GNUNET_NO otherwise (if peer was already known or
1152 * peer was #own_identity)
1153 */
1154int
1155Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer)
1156{
1157 struct PeerContext *peer_ctx;
1158 int ret;
1159
1160 if (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, &own_identity))
1161 {
1162 return GNUNET_NO;
1163 }
1164 ret = Peers_insert_peer (peer);
1165 peer_ctx = get_peer_ctx (peer);
1166 if (GNUNET_NO == Peers_check_peer_flag (peer, Peers_ONLINE))
1167 {
1168 check_peer_live (peer_ctx);
1169 }
1170 return ret;
1171}
1172
1173
1174/**
1175 * @brief Check if peer is removable.
1176 *
1177 * Check if
1178 * - a recv channel exists
1179 * - there are pending messages
1180 * - there is no pending pull reply
1181 *
1182 * @param peer the peer in question
1183 * @return #GNUNET_YES if peer is removable
1184 * #GNUNET_NO if peer is NOT removable
1185 * #GNUNET_SYSERR if peer is not known
1186 */
1187int
1188Peers_check_removable (const struct GNUNET_PeerIdentity *peer)
1189{
1190 struct PeerContext *peer_ctx;
1191
1192 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer))
1193 {
1194 return GNUNET_SYSERR;
1195 }
1196
1197 peer_ctx = get_peer_ctx (peer);
1198 if ( (NULL != peer_ctx->recv_channel) ||
1199 (NULL != peer_ctx->pending_messages_head) ||
1200 (GNUNET_NO == check_peer_flag_set (peer_ctx, Peers_PULL_REPLY_PENDING)) )
1201 {
1202 return GNUNET_NO;
1203 }
1204 return GNUNET_YES;
1205}
1206
1207uint32_t *
1208Peers_get_channel_flag (const struct GNUNET_PeerIdentity *peer,
1209 enum Peers_ChannelRole role);
1210
1211int
1212Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags);
1213
1214/**
1215 * @brief Remove peer
1216 *
1217 * @param peer the peer to clean
1218 * @return #GNUNET_YES if peer was removed
1219 * #GNUNET_NO otherwise
1220 */
1221int
1222Peers_remove_peer (const struct GNUNET_PeerIdentity *peer)
1223{
1224 struct PeerContext *peer_ctx;
1225 uint32_t *channel_flag;
1226
1227 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer))
1228 {
1229 return GNUNET_NO;
1230 }
1231
1232 peer_ctx = get_peer_ctx (peer);
1233 set_peer_flag (peer_ctx, Peers_TO_DESTROY);
1234 LOG (GNUNET_ERROR_TYPE_DEBUG,
1235 "Going to remove peer %s\n",
1236 GNUNET_i2s (&peer_ctx->peer_id));
1237 Peers_unset_peer_flag (peer, Peers_ONLINE);
1238
1239 GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0);
1240 while (NULL != peer_ctx->pending_messages_head)
1241 {
1242 LOG (GNUNET_ERROR_TYPE_DEBUG,
1243 "Removing unsent %s\n",
1244 peer_ctx->pending_messages_head->type);
1245 /* Cancle pending message, too */
1246 remove_pending_message (peer_ctx->pending_messages_head, GNUNET_YES);
1247 }
1248 /* If we are still waiting for notification whether this peer is live
1249 * cancel the according task */
1250 if (NULL != peer_ctx->liveliness_check_pending)
1251 {
1252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1253 "Removing pending liveliness check for peer %s\n",
1254 GNUNET_i2s (&peer_ctx->peer_id));
1255 // TODO wait until cadet sets mq->cancel_impl
1256 //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev);
1257 GNUNET_free (peer_ctx->liveliness_check_pending);
1258 peer_ctx->liveliness_check_pending = NULL;
1259 }
1260 channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_SENDING);
1261 if (NULL != peer_ctx->send_channel &&
1262 GNUNET_YES != Peers_check_channel_flag (channel_flag, Peers_CHANNEL_DESTROING))
1263 {
1264 LOG (GNUNET_ERROR_TYPE_DEBUG,
1265 "Destroying send channel\n");
1266 GNUNET_CADET_channel_destroy (peer_ctx->send_channel);
1267 peer_ctx->send_channel = NULL;
1268 }
1269 channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_RECEIVING);
1270 if (NULL != peer_ctx->recv_channel &&
1271 GNUNET_YES != Peers_check_channel_flag (channel_flag, Peers_CHANNEL_DESTROING))
1272 {
1273 LOG (GNUNET_ERROR_TYPE_DEBUG,
1274 "Destroying recv channel\n");
1275 GNUNET_CADET_channel_destroy (peer_ctx->recv_channel);
1276 peer_ctx->recv_channel = NULL;
1277 }
1278
1279 GNUNET_free (peer_ctx->send_channel_flags);
1280 GNUNET_free (peer_ctx->recv_channel_flags);
1281
1282 if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_remove_all (peer_map, &peer_ctx->peer_id))
1283 {
1284 LOG (GNUNET_ERROR_TYPE_WARNING, "removing peer from peer_map failed\n");
1285 }
1286 GNUNET_free (peer_ctx);
1287 return GNUNET_YES;
1288}
1289
1290
1291/**
1292 * @brief set flags on a given peer.
1293 *
1294 * @param peer the peer to set flags on
1295 * @param flags the flags
1296 */
1297void
1298Peers_set_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags)
1299{
1300 struct PeerContext *peer_ctx;
1301
1302 peer_ctx = get_peer_ctx (peer);
1303 set_peer_flag (peer_ctx, flags);
1304}
1305
1306
1307/**
1308 * @brief unset flags on a given peer.
1309 *
1310 * @param peer the peer to unset flags on
1311 * @param flags the flags
1312 */
1313void
1314Peers_unset_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags)
1315{
1316 struct PeerContext *peer_ctx;
1317
1318 peer_ctx = get_peer_ctx (peer);
1319 unset_peer_flag (peer_ctx, flags);
1320}
1321
1322
1323/**
1324 * @brief Check whether flags on a peer are set.
1325 *
1326 * @param peer the peer to check the flag of
1327 * @param flags the flags to check
1328 *
1329 * @return #GNUNET_SYSERR if peer is not known
1330 * #GNUNET_YES if all given flags are set
1331 * #GNUNET_NO otherwise
1332 */
1333int
1334Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags)
1335{
1336 struct PeerContext *peer_ctx;
1337
1338 if (GNUNET_NO == Peers_check_peer_known (peer))
1339 {
1340 return GNUNET_SYSERR;
1341 }
1342 peer_ctx = get_peer_ctx (peer);
1343 return check_peer_flag_set (peer_ctx, flags);
1344}
1345
1346
1347/**
1348 * @brief set flags on a given channel.
1349 *
1350 * @param channel the channel to set flags on
1351 * @param flags the flags
1352 */
1353void
1354Peers_set_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags)
1355{
1356 set_channel_flag (channel_flags, flags);
1357}
1358
1359
1360/**
1361 * @brief unset flags on a given channel.
1362 *
1363 * @param channel the channel to unset flags on
1364 * @param flags the flags
1365 */
1366void
1367Peers_unset_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags)
1368{
1369 unset_channel_flag (channel_flags, flags);
1370}
1371
1372
1373/**
1374 * @brief Check whether flags on a channel are set.
1375 *
1376 * @param channel the channel to check the flag of
1377 * @param flags the flags to check
1378 *
1379 * @return #GNUNET_YES if all given flags are set
1380 * #GNUNET_NO otherwise
1381 */
1382int
1383Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags)
1384{
1385 return check_channel_flag_set (channel_flags, flags);
1386}
1387
1388/**
1389 * @brief Get the flags for the channel in @a role for @a peer.
1390 *
1391 * @param peer Peer to get the channel flags for.
1392 * @param role Role of channel to get flags for
1393 *
1394 * @return The flags.
1395 */
1396uint32_t *
1397Peers_get_channel_flag (const struct GNUNET_PeerIdentity *peer,
1398 enum Peers_ChannelRole role)
1399{
1400 const struct PeerContext *peer_ctx;
1401
1402 peer_ctx = get_peer_ctx (peer);
1403 if (Peers_CHANNEL_ROLE_SENDING == role)
1404 {
1405 return peer_ctx->send_channel_flags;
1406 }
1407 else if (Peers_CHANNEL_ROLE_RECEIVING == role)
1408 {
1409 return peer_ctx->recv_channel_flags;
1410 }
1411 else
1412 {
1413 GNUNET_assert (0);
1414 }
1415}
1416
1417/**
1418 * @brief Check whether we have information about the given peer.
1419 *
1420 * FIXME probably deprecated. Make this the new _online.
1421 *
1422 * @param peer peer in question
1423 *
1424 * @return #GNUNET_YES if peer is known
1425 * #GNUNET_NO if peer is not knwon
1426 */
1427int
1428Peers_check_peer_known (const struct GNUNET_PeerIdentity *peer)
1429{
1430 return GNUNET_CONTAINER_multipeermap_contains (peer_map, peer);
1431}
1432
1433
1434/**
1435 * @brief Check whether @a peer is actually a peer.
1436 *
1437 * A valid peer is a peer that we know exists eg. we were connected to once.
1438 *
1439 * @param peer peer in question
1440 *
1441 * @return #GNUNET_YES if peer is valid
1442 * #GNUNET_NO if peer is not valid
1443 */
1444int
1445Peers_check_peer_valid (const struct GNUNET_PeerIdentity *peer)
1446{
1447 return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer);
1448}
1449
1450
1451/**
1452 * @brief Indicate that we want to send to the other peer
1453 *
1454 * This establishes a sending channel
1455 *
1456 * @param peer the peer to establish channel to
1457 */
1458void
1459Peers_indicate_sending_intention (const struct GNUNET_PeerIdentity *peer)
1460{
1461 GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer));
1462 (void) get_channel (peer);
1463}
1464
1465
1466/**
1467 * @brief Check whether other peer has the intention to send/opened channel
1468 * towars us
1469 *
1470 * @param peer the peer in question
1471 *
1472 * @return #GNUNET_YES if peer has the intention to send
1473 * #GNUNET_NO otherwise
1474 */
1475int
1476Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer)
1477{
1478 const struct PeerContext *peer_ctx;
1479
1480 peer_ctx = get_peer_ctx (peer);
1481 if (NULL != peer_ctx->recv_channel)
1482 {
1483 return GNUNET_YES;
1484 }
1485 return GNUNET_NO;
1486}
1487
1488
1489/**
1490 * Handle the channel a peer opens to us.
1491 *
1492 * @param cls The closure
1493 * @param channel The channel the peer wants to establish
1494 * @param initiator The peer's peer ID
1495 *
1496 * @return initial channel context for the channel
1497 * (can be NULL -- that's not an error)
1498 */
1499void *
1500Peers_handle_inbound_channel (void *cls,
1501 struct GNUNET_CADET_Channel *channel,
1502 const struct GNUNET_PeerIdentity *initiator)
1503{
1504 struct PeerContext *peer_ctx;
1505
1506 LOG (GNUNET_ERROR_TYPE_DEBUG,
1507 "New channel was established to us (Peer %s).\n",
1508 GNUNET_i2s (initiator));
1509 GNUNET_assert (NULL != channel); /* according to cadet API */
1510 /* Make sure we 'know' about this peer */
1511 peer_ctx = create_or_get_peer_ctx (initiator);
1512 set_peer_live (peer_ctx);
1513 /* We only accept one incoming channel per peer */
1514 if (GNUNET_YES == Peers_check_peer_send_intention (initiator))
1515 {
1516 set_channel_flag (peer_ctx->recv_channel_flags,
1517 Peers_CHANNEL_ESTABLISHED_TWICE);
1518 GNUNET_CADET_channel_destroy (channel);
1519 /* return the channel context */
1520 return &peer_ctx->peer_id;
1521 }
1522 peer_ctx->recv_channel = channel;
1523 return &peer_ctx->peer_id;
1524}
1525
1526
1527/**
1528 * @brief Check whether a sending channel towards the given peer exists
1529 *
1530 * @param peer the peer to check for
1531 *
1532 * @return #GNUNET_YES if a sending channel towards that peer exists
1533 * #GNUNET_NO otherwise
1534 */
1535int
1536Peers_check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer)
1537{
1538 struct PeerContext *peer_ctx;
1539
1540 if (GNUNET_NO == Peers_check_peer_known (peer))
1541 { /* If no such peer exists, there is no channel */
1542 return GNUNET_NO;
1543 }
1544 peer_ctx = get_peer_ctx (peer);
1545 if (NULL == peer_ctx->send_channel)
1546 {
1547 return GNUNET_NO;
1548 }
1549 return GNUNET_YES;
1550}
1551
1552
1553/**
1554 * @brief check whether the given channel is the sending channel of the given
1555 * peer
1556 *
1557 * @param peer the peer in question
1558 * @param channel the channel to check for
1559 * @param role either #Peers_CHANNEL_ROLE_SENDING, or
1560 * #Peers_CHANNEL_ROLE_RECEIVING
1561 *
1562 * @return #GNUNET_YES if the given chennel is the sending channel of the peer
1563 * #GNUNET_NO otherwise
1564 */
1565int
1566Peers_check_channel_role (const struct GNUNET_PeerIdentity *peer,
1567 const struct GNUNET_CADET_Channel *channel,
1568 enum Peers_ChannelRole role)
1569{
1570 const struct PeerContext *peer_ctx;
1571
1572 if (GNUNET_NO == Peers_check_peer_known (peer))
1573 {
1574 return GNUNET_NO;
1575 }
1576 peer_ctx = get_peer_ctx (peer);
1577 if ( (Peers_CHANNEL_ROLE_SENDING == role) &&
1578 (channel == peer_ctx->send_channel) )
1579 {
1580 return GNUNET_YES;
1581 }
1582 if ( (Peers_CHANNEL_ROLE_RECEIVING == role) &&
1583 (channel == peer_ctx->recv_channel) )
1584 {
1585 return GNUNET_YES;
1586 }
1587 return GNUNET_NO;
1588}
1589
1590
1591/**
1592 * @brief Destroy the send channel of a peer e.g. stop indicating a sending
1593 * intention to another peer
1594 *
1595 * If there is also no channel to receive messages from that peer, remove it
1596 * from the peermap.
1597 * TODO really?
1598 *
1599 * @peer the peer identity of the peer whose sending channel to destroy
1600 * @return #GNUNET_YES if channel was destroyed
1601 * #GNUNET_NO otherwise
1602 */
1603int
1604Peers_destroy_sending_channel (const struct GNUNET_PeerIdentity *peer)
1605{
1606 struct PeerContext *peer_ctx;
1607
1608 if (GNUNET_NO == Peers_check_peer_known (peer))
1609 {
1610 return GNUNET_NO;
1611 }
1612 peer_ctx = get_peer_ctx (peer);
1613 if (NULL != peer_ctx->send_channel)
1614 {
1615 set_channel_flag (peer_ctx->send_channel_flags, Peers_CHANNEL_CLEAN);
1616 GNUNET_CADET_channel_destroy (peer_ctx->send_channel);
1617 peer_ctx->send_channel = NULL;
1618 (void) Peers_check_connected (peer);
1619 return GNUNET_YES;
1620 }
1621 return GNUNET_NO;
1622}
1623
1624/**
1625 * This is called when a channel is destroyed.
1626 *
1627 * @param cls The closure
1628 * @param channel The channel being closed
1629 * @param channel_ctx The context associated with this channel
1630 */
1631void
1632Peers_cleanup_destroyed_channel (void *cls,
1633 const struct GNUNET_CADET_Channel *channel)
1634{
1635 struct GNUNET_PeerIdentity *peer = cls;
1636 struct PeerContext *peer_ctx;
1637
1638 if (GNUNET_NO == Peers_check_peer_known (peer))
1639 {/* We don't want to implicitly create a context that we're about to kill */
1640 LOG (GNUNET_ERROR_TYPE_DEBUG,
1641 "channel (%s) without associated context was destroyed\n",
1642 GNUNET_i2s (peer));
1643 return;
1644 }
1645 peer_ctx = get_peer_ctx (peer);
1646
1647 /* If our peer issued the destruction of the channel, the #Peers_TO_DESTROY
1648 * flag will be set. In this case simply make sure that the channels are
1649 * cleaned. */
1650 /* FIXME This distinction seems to be redundant */
1651 if (Peers_check_peer_flag (peer, Peers_TO_DESTROY))
1652 {/* We initiatad the destruction of this particular peer */
1653 if (channel == peer_ctx->send_channel)
1654 peer_ctx->send_channel = NULL;
1655 else if (channel == peer_ctx->recv_channel)
1656 peer_ctx->recv_channel = NULL;
1657
1658 if (NULL != peer_ctx->send_channel)
1659 {
1660 GNUNET_CADET_channel_destroy (peer_ctx->send_channel);
1661 peer_ctx->send_channel = NULL;
1662 }
1663 if (NULL != peer_ctx->recv_channel)
1664 {
1665 GNUNET_CADET_channel_destroy (peer_ctx->recv_channel);
1666 peer_ctx->recv_channel = NULL;
1667 }
1668 /* Set the #Peers_ONLINE flag accordingly */
1669 (void) Peers_check_connected (peer);
1670 return;
1671 }
1672
1673 else
1674 { /* We did not initiate the destruction of this peer */
1675 if (channel == peer_ctx->send_channel)
1676 { /* Something (but us) killd the channel - clean up peer */
1677 LOG (GNUNET_ERROR_TYPE_DEBUG,
1678 "send channel (%s) was destroyed - cleaning up\n",
1679 GNUNET_i2s (peer));
1680 peer_ctx->send_channel = NULL;
1681 }
1682 else if (channel == peer_ctx->recv_channel)
1683 { /* Other peer doesn't want to send us messages anymore */
1684 LOG (GNUNET_ERROR_TYPE_DEBUG,
1685 "Peer %s destroyed recv channel - cleaning up channel\n",
1686 GNUNET_i2s (peer));
1687 peer_ctx->recv_channel = NULL;
1688 }
1689 else
1690 {
1691 LOG (GNUNET_ERROR_TYPE_WARNING,
1692 "unknown channel (%s) was destroyed\n",
1693 GNUNET_i2s (peer));
1694 }
1695 }
1696 (void) Peers_check_connected (peer);
1697}
1698
1699/**
1700 * @brief Send a message to another peer.
1701 *
1702 * Keeps track about pending messages so they can be properly removed when the
1703 * peer is destroyed.
1704 *
1705 * @param peer receeiver of the message
1706 * @param ev envelope of the message
1707 * @param type type of the message
1708 */
1709void
1710Peers_send_message (const struct GNUNET_PeerIdentity *peer,
1711 struct GNUNET_MQ_Envelope *ev,
1712 const char *type)
1713{
1714 struct PendingMessage *pending_msg;
1715 struct GNUNET_MQ_Handle *mq;
1716
1717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1718 "Sending message to %s of type %s\n",
1719 GNUNET_i2s (peer),
1720 type);
1721 pending_msg = insert_pending_message (peer, ev, type);
1722 mq = get_mq (peer);
1723 GNUNET_MQ_notify_sent (ev,
1724 mq_notify_sent_cb,
1725 pending_msg);
1726 GNUNET_MQ_send (mq, ev);
1727}
1728
1729/**
1730 * @brief Schedule a operation on given peer
1731 *
1732 * Avoids scheduling an operation twice.
1733 *
1734 * @param peer the peer we want to schedule the operation for once it gets live
1735 *
1736 * @return #GNUNET_YES if the operation was scheduled
1737 * #GNUNET_NO otherwise
1738 */
1739int
1740Peers_schedule_operation (const struct GNUNET_PeerIdentity *peer,
1741 const PeerOp peer_op)
1742{
1743 struct PeerPendingOp pending_op;
1744 struct PeerContext *peer_ctx;
1745
1746 if (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, &own_identity))
1747 {
1748 return GNUNET_NO;
1749 }
1750 GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer));
1751
1752 //TODO if LIVE/ONLINE execute immediately
1753
1754 if (GNUNET_NO == check_operation_scheduled (peer, peer_op))
1755 {
1756 peer_ctx = get_peer_ctx (peer);
1757 pending_op.op = peer_op;
1758 pending_op.op_cls = NULL;
1759 GNUNET_array_append (peer_ctx->pending_ops,
1760 peer_ctx->num_pending_ops,
1761 pending_op);
1762 return GNUNET_YES;
1763 }
1764 return GNUNET_NO;
1765}
1766
1767/**
1768 * @brief Get the recv_channel of @a peer.
1769 * Needed to correctly handle (call #GNUNET_CADET_receive_done()) incoming
1770 * messages.
1771 *
1772 * @param peer The peer to get the recv_channel from.
1773 *
1774 * @return The recv_channel.
1775 */
1776struct GNUNET_CADET_Channel *
1777Peers_get_recv_channel (const struct GNUNET_PeerIdentity *peer)
1778{
1779 struct PeerContext *peer_ctx;
1780
1781 GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer));
1782 peer_ctx = get_peer_ctx (peer);
1783 return peer_ctx->recv_channel;
1784}
1785/***********************************************************************
1786 * /Old gnunet-service-rps_peers.c
1787***********************************************************************/
1788
1789
69/*********************************************************************** 1790/***********************************************************************
70 * Housekeeping with clients 1791 * Housekeeping with clients
71***********************************************************************/ 1792***********************************************************************/
@@ -847,6 +2568,7 @@ cleanup_destroyed_channel (void *cls,
847{ 2568{
848 struct GNUNET_PeerIdentity *peer = cls; 2569 struct GNUNET_PeerIdentity *peer = cls;
849 uint32_t *channel_flag; 2570 uint32_t *channel_flag;
2571 struct PeerContext *peer_ctx;
850 2572
851 if (GNUNET_NO == Peers_check_peer_known (peer)) 2573 if (GNUNET_NO == Peers_check_peer_known (peer))
852 { /* We don't know a context to that peer */ 2574 { /* We don't know a context to that peer */
@@ -856,6 +2578,15 @@ cleanup_destroyed_channel (void *cls,
856 return; 2578 return;
857 } 2579 }
858 2580
2581 peer_ctx = get_peer_ctx (peer);
2582 if (GNUNET_YES == Peers_check_channel_role (peer, channel, Peers_CHANNEL_ROLE_RECEIVING))
2583 {
2584 set_channel_flag (peer_ctx->recv_channel_flags, Peers_CHANNEL_DESTROING);
2585 } else if (GNUNET_YES == Peers_check_channel_role (peer, channel, Peers_CHANNEL_ROLE_SENDING))
2586 {
2587 set_channel_flag (peer_ctx->send_channel_flags, Peers_CHANNEL_DESTROING);
2588 }
2589
859 if (GNUNET_YES == Peers_check_peer_flag (peer, Peers_TO_DESTROY)) 2590 if (GNUNET_YES == Peers_check_peer_flag (peer, Peers_TO_DESTROY))
860 { /* We are in the middle of removing that peer from our knowledge. In this 2591 { /* We are in the middle of removing that peer from our knowledge. In this
861 case simply make sure that the channels are cleaned. */ 2592 case simply make sure that the channels are cleaned. */
@@ -1121,7 +2852,6 @@ handle_client_request_cancel (void *cls,
1121 (rep_cls->id != ntohl (msg->id)) ) 2852 (rep_cls->id != ntohl (msg->id)) )
1122 rep_cls = rep_cls->next; 2853 rep_cls = rep_cls->next;
1123 GNUNET_assert (rep_cls->id == ntohl (msg->id)); 2854 GNUNET_assert (rep_cls->id == ntohl (msg->id));
1124 RPS_sampler_request_cancel (rep_cls->req_handle);
1125 destroy_reply_cls (rep_cls); 2855 destroy_reply_cls (rep_cls);
1126 GNUNET_SERVICE_client_continue (cli_ctx->client); 2856 GNUNET_SERVICE_client_continue (cli_ctx->client);
1127} 2857}
@@ -1239,24 +2969,24 @@ handle_peer_push (void *cls,
1239 (3 == mal_type) ) 2969 (3 == mal_type) )
1240 { /* Try to maximise representation */ 2970 { /* Try to maximise representation */
1241 tmp_att_peer = GNUNET_new (struct AttackedPeer); 2971 tmp_att_peer = GNUNET_new (struct AttackedPeer);
1242 GNUNET_memcpy (&tmp_att_peer->peer_id, peer, sizeof (struct GNUNET_PeerIdentity)); 2972 tmp_att_peer->peer_id = *peer;
1243 if (NULL == att_peer_set) 2973 if (NULL == att_peer_set)
1244 att_peer_set = GNUNET_CONTAINER_multipeermap_create (1, GNUNET_NO); 2974 att_peer_set = GNUNET_CONTAINER_multipeermap_create (1, GNUNET_NO);
1245 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set, 2975 if (GNUNET_NO ==
1246 peer)) 2976 GNUNET_CONTAINER_multipeermap_contains (att_peer_set,
2977 peer))
1247 { 2978 {
1248 GNUNET_CONTAINER_DLL_insert (att_peers_head, 2979 GNUNET_CONTAINER_DLL_insert (att_peers_head,
1249 att_peers_tail, 2980 att_peers_tail,
1250 tmp_att_peer); 2981 tmp_att_peer);
1251 add_peer_array_to_set (peer, 1, att_peer_set); 2982 add_peer_array_to_set (peer, 1, att_peer_set);
1252 } 2983 }
1253 GNUNET_CADET_receive_done (Peers_get_recv_channel (peer));
1254 } 2984 }
1255 2985
1256 2986
1257 else if (2 == mal_type) 2987 else if (2 == mal_type)
1258 { /* We attack one single well-known peer - simply ignore */ 2988 {
1259 GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); 2989 /* We attack one single well-known peer - simply ignore */
1260 } 2990 }
1261 #endif /* ENABLE_MALICIOUS */ 2991 #endif /* ENABLE_MALICIOUS */
1262 2992
@@ -1289,7 +3019,6 @@ handle_peer_pull_request (void *cls,
1289 || 3 == mal_type) 3019 || 3 == mal_type)
1290 { /* Try to maximise representation */ 3020 { /* Try to maximise representation */
1291 send_pull_reply (peer, mal_peers, num_mal_peers); 3021 send_pull_reply (peer, mal_peers, num_mal_peers);
1292 GNUNET_CADET_receive_done (Peers_get_recv_channel (peer));
1293 } 3022 }
1294 3023
1295 else if (2 == mal_type) 3024 else if (2 == mal_type)
@@ -1298,7 +3027,6 @@ handle_peer_pull_request (void *cls,
1298 { 3027 {
1299 send_pull_reply (peer, mal_peers, num_mal_peers); 3028 send_pull_reply (peer, mal_peers, num_mal_peers);
1300 } 3029 }
1301 GNUNET_CADET_receive_done (Peers_get_recv_channel (peer));
1302 } 3030 }
1303 #endif /* ENABLE_MALICIOUS */ 3031 #endif /* ENABLE_MALICIOUS */
1304 3032
@@ -1360,7 +3088,7 @@ static void
1360handle_peer_pull_reply (void *cls, 3088handle_peer_pull_reply (void *cls,
1361 const struct GNUNET_RPS_P2P_PullReplyMessage *msg) 3089 const struct GNUNET_RPS_P2P_PullReplyMessage *msg)
1362{ 3090{
1363 struct GNUNET_PeerIdentity *peers; 3091 const struct GNUNET_PeerIdentity *peers;
1364 struct GNUNET_PeerIdentity *sender = cls; 3092 struct GNUNET_PeerIdentity *sender = cls;
1365 uint32_t i; 3093 uint32_t i;
1366#ifdef ENABLE_MALICIOUS 3094#ifdef ENABLE_MALICIOUS
@@ -1373,12 +3101,11 @@ handle_peer_pull_reply (void *cls,
1373 // We shouldn't even receive pull replies as we're not sending 3101 // We shouldn't even receive pull replies as we're not sending
1374 if (2 == mal_type) 3102 if (2 == mal_type)
1375 { 3103 {
1376 GNUNET_CADET_receive_done (Peers_get_recv_channel (sender));
1377 } 3104 }
1378 #endif /* ENABLE_MALICIOUS */ 3105 #endif /* ENABLE_MALICIOUS */
1379 3106
1380 /* Do actual logic */ 3107 /* Do actual logic */
1381 peers = (struct GNUNET_PeerIdentity *) &msg[1]; 3108 peers = (const struct GNUNET_PeerIdentity *) &msg[1];
1382 3109
1383 LOG (GNUNET_ERROR_TYPE_DEBUG, 3110 LOG (GNUNET_ERROR_TYPE_DEBUG,
1384 "PULL REPLY received, got following %u peers:\n", 3111 "PULL REPLY received, got following %u peers:\n",
@@ -2132,7 +3859,6 @@ shutdown_task (void *cls)
2132 reply_cls); 3859 reply_cls);
2133 GNUNET_free (reply_cls); 3860 GNUNET_free (reply_cls);
2134 } 3861 }
2135 GNUNET_MQ_destroy (client_ctx->mq);
2136 GNUNET_CONTAINER_DLL_remove (cli_ctx_head, cli_ctx_tail, client_ctx); 3862 GNUNET_CONTAINER_DLL_remove (cli_ctx_head, cli_ctx_tail, client_ctx);
2137 GNUNET_free (client_ctx); 3863 GNUNET_free (client_ctx);
2138 } 3864 }
@@ -2150,6 +3876,7 @@ shutdown_task (void *cls)
2150 GNUNET_NSE_disconnect (nse); 3876 GNUNET_NSE_disconnect (nse);
2151 RPS_sampler_destroy (prot_sampler); 3877 RPS_sampler_destroy (prot_sampler);
2152 RPS_sampler_destroy (client_sampler); 3878 RPS_sampler_destroy (client_sampler);
3879 GNUNET_CADET_close_port (cadet_port);
2153 GNUNET_CADET_disconnect (cadet_handle); 3880 GNUNET_CADET_disconnect (cadet_handle);
2154 View_destroy (); 3881 View_destroy ();
2155 CustomPeerMap_destroy (push_map); 3882 CustomPeerMap_destroy (push_map);
@@ -2240,26 +3967,6 @@ run (void *cls,
2240 const struct GNUNET_CONFIGURATION_Handle *c, 3967 const struct GNUNET_CONFIGURATION_Handle *c,
2241 struct GNUNET_SERVICE_Handle *service) 3968 struct GNUNET_SERVICE_Handle *service)
2242{ 3969{
2243 struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
2244 GNUNET_MQ_hd_fixed_size (peer_check,
2245 GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE,
2246 struct GNUNET_MessageHeader,
2247 NULL),
2248 GNUNET_MQ_hd_fixed_size (peer_push,
2249 GNUNET_MESSAGE_TYPE_RPS_PP_PUSH,
2250 struct GNUNET_MessageHeader,
2251 NULL),
2252 GNUNET_MQ_hd_fixed_size (peer_pull_request,
2253 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST,
2254 struct GNUNET_MessageHeader,
2255 NULL),
2256 GNUNET_MQ_hd_var_size (peer_pull_reply,
2257 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY,
2258 struct GNUNET_RPS_P2P_PullReplyMessage,
2259 NULL),
2260 GNUNET_MQ_handler_end ()
2261 };
2262
2263 int size; 3970 int size;
2264 int out_size; 3971 int out_size;
2265 char* fn_valid_peers; 3972 char* fn_valid_peers;
@@ -2349,6 +4056,27 @@ run (void *cls,
2349 4056
2350 4057
2351 /* Initialise cadet */ 4058 /* Initialise cadet */
4059 /* There exists a copy-paste-clone in get_channel() */
4060 struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
4061 GNUNET_MQ_hd_fixed_size (peer_check,
4062 GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE,
4063 struct GNUNET_MessageHeader,
4064 NULL),
4065 GNUNET_MQ_hd_fixed_size (peer_push,
4066 GNUNET_MESSAGE_TYPE_RPS_PP_PUSH,
4067 struct GNUNET_MessageHeader,
4068 NULL),
4069 GNUNET_MQ_hd_fixed_size (peer_pull_request,
4070 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST,
4071 struct GNUNET_MessageHeader,
4072 NULL),
4073 GNUNET_MQ_hd_var_size (peer_pull_reply,
4074 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY,
4075 struct GNUNET_RPS_P2P_PullReplyMessage,
4076 NULL),
4077 GNUNET_MQ_handler_end ()
4078 };
4079
2352 cadet_handle = GNUNET_CADET_connect (cfg); 4080 cadet_handle = GNUNET_CADET_connect (cfg);
2353 GNUNET_assert (NULL != cadet_handle); 4081 GNUNET_assert (NULL != cadet_handle);
2354 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_RPS, 4082 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_RPS,
@@ -2365,7 +4093,7 @@ run (void *cls,
2365 4093
2366 peerinfo_handle = GNUNET_PEERINFO_connect (cfg); 4094 peerinfo_handle = GNUNET_PEERINFO_connect (cfg);
2367 Peers_initialise (fn_valid_peers, cadet_handle, cleanup_destroyed_channel, 4095 Peers_initialise (fn_valid_peers, cadet_handle, cleanup_destroyed_channel,
2368 cadet_handlers, &own_identity); 4096 &own_identity);
2369 GNUNET_free (fn_valid_peers); 4097 GNUNET_free (fn_valid_peers);
2370 4098
2371 /* Initialise sampler */ 4099 /* Initialise sampler */
diff --git a/src/rps/gnunet-service-rps_peers.c b/src/rps/gnunet-service-rps_peers.c
deleted file mode 100644
index 58aa84ccf..000000000
--- a/src/rps/gnunet-service-rps_peers.c
+++ /dev/null
@@ -1,1694 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21/**
22 * @file rps/gnunet-service-rps_peers.c
23 * @brief utilities for managing (information about) peers
24 * @author Julius Bünger
25 */
26#include "platform.h"
27#include "gnunet_applications.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_cadet_service.h"
30#include <inttypes.h>
31#include "rps.h"
32#include "gnunet-service-rps_peers.h"
33
34
35
36#define LOG(kind, ...) GNUNET_log_from(kind,"rps-peers",__VA_ARGS__)
37
38
39/**
40 * Set a peer flag of given peer context.
41 */
42#define set_peer_flag(peer_ctx, mask) ((peer_ctx->peer_flags) |= (mask))
43
44/**
45 * Get peer flag of given peer context.
46 */
47#define check_peer_flag_set(peer_ctx, mask)\
48 ((peer_ctx->peer_flags) & (mask) ? GNUNET_YES : GNUNET_NO)
49
50/**
51 * Unset flag of given peer context.
52 */
53#define unset_peer_flag(peer_ctx, mask) ((peer_ctx->peer_flags) &= ~(mask))
54
55/**
56 * Set a channel flag of given channel context.
57 */
58#define set_channel_flag(channel_flags, mask) ((*channel_flags) |= (mask))
59
60/**
61 * Get channel flag of given channel context.
62 */
63#define check_channel_flag_set(channel_flags, mask)\
64 ((*channel_flags) & (mask) ? GNUNET_YES : GNUNET_NO)
65
66/**
67 * Unset flag of given channel context.
68 */
69#define unset_channel_flag(channel_flags, mask) ((*channel_flags) &= ~(mask))
70
71
72
73/**
74 * Pending operation on peer consisting of callback and closure
75 *
76 * When an operation cannot be executed right now this struct is used to store
77 * the callback and closure for later execution.
78 */
79struct PeerPendingOp
80{
81 /**
82 * Callback
83 */
84 PeerOp op;
85
86 /**
87 * Closure
88 */
89 void *op_cls;
90};
91
92/**
93 * List containing all messages that are yet to be send
94 *
95 * This is used to keep track of all messages that have not been sent yet. When
96 * a peer is to be removed the pending messages can be removed properly.
97 */
98struct PendingMessage
99{
100 /**
101 * DLL next, prev
102 */
103 struct PendingMessage *next;
104 struct PendingMessage *prev;
105
106 /**
107 * The envelope to the corresponding message
108 */
109 struct GNUNET_MQ_Envelope *ev;
110
111 /**
112 * The corresponding context
113 */
114 struct PeerContext *peer_ctx;
115
116 /**
117 * The message type
118 */
119 const char *type;
120};
121
122/**
123 * Struct used to keep track of other peer's status
124 *
125 * This is stored in a multipeermap.
126 * It contains information such as cadet channels, a message queue for sending,
127 * status about the channels, the pending operations on this peer and some flags
128 * about the status of the peer itself. (live, valid, ...)
129 */
130struct PeerContext
131{
132 /**
133 * Message queue open to client
134 */
135 struct GNUNET_MQ_Handle *mq;
136
137 /**
138 * Channel open to client.
139 */
140 struct GNUNET_CADET_Channel *send_channel;
141
142 /**
143 * Flags to the sending channel
144 */
145 uint32_t *send_channel_flags;
146
147 /**
148 * Channel open from client.
149 */
150 struct GNUNET_CADET_Channel *recv_channel; // unneeded?
151
152 /**
153 * Flags to the receiving channel
154 */
155 uint32_t *recv_channel_flags;
156
157 /**
158 * Array of pending operations on this peer.
159 */
160 struct PeerPendingOp *pending_ops;
161
162 /**
163 * Handle to the callback given to cadet_ntfy_tmt_rdy()
164 *
165 * To be canceled on shutdown.
166 */
167 struct PendingMessage *liveliness_check_pending;
168
169 /**
170 * Number of pending operations.
171 */
172 unsigned int num_pending_ops;
173
174 /**
175 * Identity of the peer
176 */
177 struct GNUNET_PeerIdentity peer_id;
178
179 /**
180 * Flags indicating status of peer
181 */
182 uint32_t peer_flags;
183
184 /**
185 * Last time we received something from that peer.
186 */
187 struct GNUNET_TIME_Absolute last_message_recv;
188
189 /**
190 * Last time we received a keepalive message.
191 */
192 struct GNUNET_TIME_Absolute last_keepalive;
193
194 /**
195 * DLL with all messages that are yet to be sent
196 */
197 struct PendingMessage *pending_messages_head;
198 struct PendingMessage *pending_messages_tail;
199
200 /**
201 * This is pobably followed by 'statistical' data (when we first saw
202 * him, how did we get his ID, how many pushes (in a timeinterval),
203 * ...)
204 */
205};
206
207/**
208 * @brief Closure to #valid_peer_iterator
209 */
210struct PeersIteratorCls
211{
212 /**
213 * Iterator function
214 */
215 PeersIterator iterator;
216
217 /**
218 * Closure to iterator
219 */
220 void *cls;
221};
222
223/**
224 * @brief Hashmap of valid peers.
225 */
226static struct GNUNET_CONTAINER_MultiPeerMap *valid_peers;
227
228/**
229 * @brief Maximum number of valid peers to keep.
230 * TODO read from config
231 */
232static uint32_t num_valid_peers_max = UINT32_MAX;
233
234/**
235 * @brief Filename of the file that stores the valid peers persistently.
236 */
237static char *filename_valid_peers;
238
239/**
240 * Set of all peers to keep track of them.
241 */
242static struct GNUNET_CONTAINER_MultiPeerMap *peer_map;
243
244/**
245 * Own #GNUNET_PeerIdentity.
246 */
247static const struct GNUNET_PeerIdentity *own_identity;
248
249/**
250 * Cadet handle.
251 */
252static struct GNUNET_CADET_Handle *cadet_handle;
253
254/**
255 * @brief Disconnect handler
256 */
257static GNUNET_CADET_DisconnectEventHandler cleanup_destroyed_channel;
258
259/**
260 * @brief cadet handlers
261 */
262static const struct GNUNET_MQ_MessageHandler *cadet_handlers;
263
264
265
266/**
267 * @brief Get the #PeerContext associated with a peer
268 *
269 * @param peer the peer id
270 *
271 * @return the #PeerContext
272 */
273static struct PeerContext *
274get_peer_ctx (const struct GNUNET_PeerIdentity *peer)
275{
276 struct PeerContext *ctx;
277 int ret;
278
279 ret = GNUNET_CONTAINER_multipeermap_contains (peer_map, peer);
280 GNUNET_assert (GNUNET_YES == ret);
281 ctx = GNUNET_CONTAINER_multipeermap_get (peer_map, peer);
282 GNUNET_assert (NULL != ctx);
283 return ctx;
284}
285
286
287/**
288 * @brief Create a new #PeerContext and insert it into the peer map
289 *
290 * @param peer the peer to create the #PeerContext for
291 *
292 * @return the #PeerContext
293 */
294static struct PeerContext *
295create_peer_ctx (const struct GNUNET_PeerIdentity *peer)
296{
297 struct PeerContext *ctx;
298 int ret;
299
300 GNUNET_assert (GNUNET_NO == Peers_check_peer_known (peer));
301
302 ctx = GNUNET_new (struct PeerContext);
303 ctx->peer_id = *peer;
304 ctx->send_channel_flags = GNUNET_new (uint32_t);
305 ctx->recv_channel_flags = GNUNET_new (uint32_t);
306 ret = GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx,
307 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
308 GNUNET_assert (GNUNET_OK == ret);
309 return ctx;
310}
311
312
313/**
314 * @brief Create or get a #PeerContext
315 *
316 * @param peer the peer to get the associated context to
317 *
318 * @return the context
319 */
320static struct PeerContext *
321create_or_get_peer_ctx (const struct GNUNET_PeerIdentity *peer)
322{
323 if (GNUNET_NO == Peers_check_peer_known (peer))
324 {
325 return create_peer_ctx (peer);
326 }
327 return get_peer_ctx (peer);
328}
329
330
331/**
332 * @brief Check whether we have a connection to this @a peer
333 *
334 * Also sets the #Peers_ONLINE flag accordingly
335 *
336 * @param peer the peer in question
337 *
338 * @return #GNUNET_YES if we are connected
339 * #GNUNET_NO otherwise
340 */
341int
342Peers_check_connected (const struct GNUNET_PeerIdentity *peer)
343{
344 const struct PeerContext *peer_ctx;
345
346 /* If we don't know about this peer we don't know whether it's online */
347 if (GNUNET_NO == Peers_check_peer_known (peer))
348 {
349 return GNUNET_NO;
350 }
351 /* Get the context */
352 peer_ctx = get_peer_ctx (peer);
353 /* If we have no channel to this peer we don't know whether it's online */
354 if ( (NULL == peer_ctx->send_channel) &&
355 (NULL == peer_ctx->recv_channel) )
356 {
357 Peers_unset_peer_flag (peer, Peers_ONLINE);
358 return GNUNET_NO;
359 }
360 /* Otherwise (if we have a channel, we know that it's online */
361 Peers_set_peer_flag (peer, Peers_ONLINE);
362 return GNUNET_YES;
363}
364
365
366/**
367 * @brief The closure to #get_rand_peer_iterator.
368 */
369struct GetRandPeerIteratorCls
370{
371 /**
372 * @brief The index of the peer to return.
373 * Will be decreased until 0.
374 * Then current peer is returned.
375 */
376 uint32_t index;
377
378 /**
379 * @brief Pointer to peer to return.
380 */
381 const struct GNUNET_PeerIdentity *peer;
382};
383
384
385/**
386 * @brief Iterator function for #get_random_peer_from_peermap.
387 *
388 * Implements #GNUNET_CONTAINER_PeerMapIterator.
389 * Decreases the index until the index is null.
390 * Then returns the current peer.
391 *
392 * @param cls the #GetRandPeerIteratorCls containing index and peer
393 * @param peer current peer
394 * @param value unused
395 *
396 * @return #GNUNET_YES if we should continue to
397 * iterate,
398 * #GNUNET_NO if not.
399 */
400static int
401get_rand_peer_iterator (void *cls,
402 const struct GNUNET_PeerIdentity *peer,
403 void *value)
404{
405 struct GetRandPeerIteratorCls *iterator_cls = cls;
406 if (0 >= iterator_cls->index)
407 {
408 iterator_cls->peer = peer;
409 return GNUNET_NO;
410 }
411 iterator_cls->index--;
412 return GNUNET_YES;
413}
414
415
416/**
417 * @brief Get a random peer from @a peer_map
418 *
419 * @param peer_map the peer_map to get the peer from
420 *
421 * @return a random peer
422 */
423static const struct GNUNET_PeerIdentity *
424get_random_peer_from_peermap (const struct
425 GNUNET_CONTAINER_MultiPeerMap *peer_map)
426{
427 struct GetRandPeerIteratorCls *iterator_cls;
428 const struct GNUNET_PeerIdentity *ret;
429
430 iterator_cls = GNUNET_new (struct GetRandPeerIteratorCls);
431 iterator_cls->index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
432 GNUNET_CONTAINER_multipeermap_size (peer_map));
433 (void) GNUNET_CONTAINER_multipeermap_iterate (valid_peers,
434 get_rand_peer_iterator,
435 iterator_cls);
436 ret = iterator_cls->peer;
437 GNUNET_free (iterator_cls);
438 return ret;
439}
440
441
442/**
443 * @brief Add a given @a peer to valid peers.
444 *
445 * If valid peers are already #num_valid_peers_max, delete a peer previously.
446 *
447 * @param peer the peer that is added to the valid peers.
448 *
449 * @return #GNUNET_YES if no other peer had to be removed
450 * #GNUNET_NO otherwise
451 */
452static int
453add_valid_peer (const struct GNUNET_PeerIdentity *peer)
454{
455 const struct GNUNET_PeerIdentity *rand_peer;
456 int ret;
457
458 ret = GNUNET_YES;
459 while (GNUNET_CONTAINER_multipeermap_size (valid_peers) >= num_valid_peers_max)
460 {
461 rand_peer = get_random_peer_from_peermap (valid_peers);
462 GNUNET_CONTAINER_multipeermap_remove_all (valid_peers, rand_peer);
463 ret = GNUNET_NO;
464 }
465 (void) GNUNET_CONTAINER_multipeermap_put (valid_peers, peer, NULL,
466 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
467 return ret;
468}
469
470
471/**
472 * @brief Set the peer flag to living and
473 * call the pending operations on this peer.
474 *
475 * Also adds peer to #valid_peers.
476 *
477 * @param peer_ctx the #PeerContext of the peer to set live
478 */
479static void
480set_peer_live (struct PeerContext *peer_ctx)
481{
482 struct GNUNET_PeerIdentity *peer;
483 unsigned int i;
484
485 peer = &peer_ctx->peer_id;
486 LOG (GNUNET_ERROR_TYPE_DEBUG,
487 "Peer %s is live and valid, calling %i pending operations on it\n",
488 GNUNET_i2s (peer),
489 peer_ctx->num_pending_ops);
490
491 if (NULL != peer_ctx->liveliness_check_pending)
492 {
493 LOG (GNUNET_ERROR_TYPE_DEBUG,
494 "Removing pending liveliness check for peer %s\n",
495 GNUNET_i2s (&peer_ctx->peer_id));
496 // TODO wait until cadet sets mq->cancel_impl
497 //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev);
498 GNUNET_free (peer_ctx->liveliness_check_pending);
499 peer_ctx->liveliness_check_pending = NULL;
500 }
501
502 (void) add_valid_peer (peer);
503 set_peer_flag (peer_ctx, Peers_ONLINE);
504
505 /* Call pending operations */
506 for (i = 0; i < peer_ctx->num_pending_ops; i++)
507 {
508 peer_ctx->pending_ops[i].op (peer_ctx->pending_ops[i].op_cls, peer);
509 }
510 GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0);
511}
512
513
514/**
515 * @brief Get the channel of a peer. If not existing, create.
516 *
517 * @param peer the peer id
518 * @return the #GNUNET_CADET_Channel used to send data to @a peer
519 */
520struct GNUNET_CADET_Channel *
521get_channel (const struct GNUNET_PeerIdentity *peer)
522{
523 struct PeerContext *peer_ctx;
524 struct GNUNET_HashCode port;
525
526 peer_ctx = get_peer_ctx (peer);
527 if (NULL == peer_ctx->send_channel)
528 {
529 LOG (GNUNET_ERROR_TYPE_DEBUG,
530 "Trying to establish channel to peer %s\n",
531 GNUNET_i2s (peer));
532 GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_RPS,
533 strlen (GNUNET_APPLICATION_PORT_RPS),
534 &port);
535 peer_ctx->send_channel =
536 GNUNET_CADET_channel_create (cadet_handle,
537 (struct GNUNET_PeerIdentity *) peer, /* context */
538 peer,
539 &port,
540 GNUNET_CADET_OPTION_RELIABLE,
541 NULL, /* WindowSize handler */
542 cleanup_destroyed_channel, /* Disconnect handler */
543 cadet_handlers);
544 }
545 GNUNET_assert (NULL != peer_ctx->send_channel);
546 return peer_ctx->send_channel;
547}
548
549
550/**
551 * Get the message queue (#GNUNET_MQ_Handle) of a specific peer.
552 *
553 * If we already have a message queue open to this client,
554 * simply return it, otherways create one.
555 *
556 * @param peer the peer to get the mq to
557 * @return the #GNUNET_MQ_Handle
558 */
559static struct GNUNET_MQ_Handle *
560get_mq (const struct GNUNET_PeerIdentity *peer)
561{
562 struct PeerContext *peer_ctx;
563
564 peer_ctx = get_peer_ctx (peer);
565
566 if (NULL == peer_ctx->mq)
567 {
568 (void) get_channel (peer);
569 peer_ctx->mq = GNUNET_CADET_get_mq (peer_ctx->send_channel);
570 }
571 return peer_ctx->mq;
572}
573
574
575/**
576 * @brief This is called in response to the first message we sent as a
577 * liveliness check.
578 *
579 * @param cls #PeerContext of peer with pending liveliness check
580 */
581static void
582mq_liveliness_check_successful (void *cls)
583{
584 struct PeerContext *peer_ctx = cls;
585
586 if (NULL != peer_ctx->liveliness_check_pending)
587 {
588 LOG (GNUNET_ERROR_TYPE_DEBUG,
589 "Liveliness check for peer %s was successfull\n",
590 GNUNET_i2s (&peer_ctx->peer_id));
591 GNUNET_free (peer_ctx->liveliness_check_pending);
592 peer_ctx->liveliness_check_pending = NULL;
593 set_peer_live (peer_ctx);
594 }
595}
596
597/**
598 * Issue a check whether peer is live
599 *
600 * @param peer_ctx the context of the peer
601 */
602static void
603check_peer_live (struct PeerContext *peer_ctx)
604{
605 LOG (GNUNET_ERROR_TYPE_DEBUG,
606 "Get informed about peer %s getting live\n",
607 GNUNET_i2s (&peer_ctx->peer_id));
608
609 struct GNUNET_MQ_Handle *mq;
610 struct GNUNET_MQ_Envelope *ev;
611
612 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE);
613 peer_ctx->liveliness_check_pending = GNUNET_new (struct PendingMessage);
614 peer_ctx->liveliness_check_pending->ev = ev;
615 peer_ctx->liveliness_check_pending->peer_ctx = peer_ctx;
616 peer_ctx->liveliness_check_pending->type = "Check liveliness";
617 mq = get_mq (&peer_ctx->peer_id);
618 GNUNET_MQ_notify_sent (ev,
619 mq_liveliness_check_successful,
620 peer_ctx);
621 GNUNET_MQ_send (mq, ev);
622}
623
624/**
625 * @brief Add an envelope to a message passed to mq to list of pending messages
626 *
627 * @param peer peer the message was sent to
628 * @param ev envelope to the message
629 * @param type type of the message to be sent
630 * @return pointer to pending message
631 */
632static struct PendingMessage *
633insert_pending_message (const struct GNUNET_PeerIdentity *peer,
634 struct GNUNET_MQ_Envelope *ev,
635 const char *type)
636{
637 struct PendingMessage *pending_msg;
638 struct PeerContext *peer_ctx;
639
640 peer_ctx = get_peer_ctx (peer);
641 pending_msg = GNUNET_new (struct PendingMessage);
642 pending_msg->ev = ev;
643 pending_msg->peer_ctx = peer_ctx;
644 pending_msg->type = type;
645 GNUNET_CONTAINER_DLL_insert (peer_ctx->pending_messages_head,
646 peer_ctx->pending_messages_tail,
647 pending_msg);
648 return pending_msg;
649}
650
651
652/**
653 * @brief Remove a pending message from the respective DLL
654 *
655 * @param pending_msg the pending message to remove
656 */
657static void
658remove_pending_message (struct PendingMessage *pending_msg)
659{
660 struct PeerContext *peer_ctx;
661
662 peer_ctx = pending_msg->peer_ctx;
663 GNUNET_CONTAINER_DLL_remove (peer_ctx->pending_messages_head,
664 peer_ctx->pending_messages_tail,
665 pending_msg);
666 GNUNET_MQ_send_cancel (peer_ctx->pending_messages_head->ev);
667 GNUNET_free (pending_msg);
668}
669
670
671/**
672 * @brief Check whether function of type #PeerOp was already scheduled
673 *
674 * The array with pending operations will probably never grow really big, so
675 * iterating over it should be ok.
676 *
677 * @param peer the peer to check
678 * @param peer_op the operation (#PeerOp) on the peer
679 *
680 * @return #GNUNET_YES if this operation is scheduled on that peer
681 * #GNUNET_NO otherwise
682 */
683static int
684check_operation_scheduled (const struct GNUNET_PeerIdentity *peer,
685 const PeerOp peer_op)
686{
687 const struct PeerContext *peer_ctx;
688 unsigned int i;
689
690 peer_ctx = get_peer_ctx (peer);
691 for (i = 0; i < peer_ctx->num_pending_ops; i++)
692 if (peer_op == peer_ctx->pending_ops[i].op)
693 return GNUNET_YES;
694 return GNUNET_NO;
695}
696
697
698/**
699 * Iterator over hash map entries. Deletes all contexts of peers.
700 *
701 * @param cls closure
702 * @param key current public key
703 * @param value value in the hash map
704 * @return #GNUNET_YES if we should continue to iterate,
705 * #GNUNET_NO if not.
706 */
707static int
708peermap_clear_iterator (void *cls,
709 const struct GNUNET_PeerIdentity *key,
710 void *value)
711{
712 Peers_remove_peer (key);
713 return GNUNET_YES;
714}
715
716
717/**
718 * @brief This is called once a message is sent.
719 *
720 * Removes the pending message
721 *
722 * @param cls type of the message that was sent
723 */
724static void
725mq_notify_sent_cb (void *cls)
726{
727 struct PendingMessage *pending_msg = (struct PendingMessage *) cls;
728 LOG (GNUNET_ERROR_TYPE_DEBUG,
729 "%s was sent.\n",
730 pending_msg->type);
731 remove_pending_message (pending_msg);
732}
733
734
735/**
736 * @brief Iterator function for #store_valid_peers.
737 *
738 * Implements #GNUNET_CONTAINER_PeerMapIterator.
739 * Writes single peer to disk.
740 *
741 * @param cls the file handle to write to.
742 * @param peer current peer
743 * @param value unused
744 *
745 * @return #GNUNET_YES if we should continue to
746 * iterate,
747 * #GNUNET_NO if not.
748 */
749static int
750store_peer_presistently_iterator (void *cls,
751 const struct GNUNET_PeerIdentity *peer,
752 void *value)
753{
754 const struct GNUNET_DISK_FileHandle *fh = cls;
755 char peer_string[128];
756 int size;
757 ssize_t ret;
758
759 if (NULL == peer)
760 {
761 return GNUNET_YES;
762 }
763 size = GNUNET_snprintf (peer_string,
764 sizeof (peer_string),
765 "%s\n",
766 GNUNET_i2s_full (peer));
767 GNUNET_assert (53 == size);
768 ret = GNUNET_DISK_file_write (fh,
769 peer_string,
770 size);
771 GNUNET_assert (size == ret);
772 return GNUNET_YES;
773}
774
775
776/**
777 * @brief Store the peers currently in #valid_peers to disk.
778 */
779static void
780store_valid_peers ()
781{
782 struct GNUNET_DISK_FileHandle *fh;
783 uint32_t number_written_peers;
784 int ret;
785
786 if (0 == strncmp ("DISABLE", filename_valid_peers, 7))
787 {
788 return;
789 }
790
791 ret = GNUNET_DISK_directory_create_for_file (filename_valid_peers);
792 if (GNUNET_SYSERR == ret)
793 {
794 LOG (GNUNET_ERROR_TYPE_WARNING,
795 "Not able to create directory for file `%s'\n",
796 filename_valid_peers);
797 GNUNET_break (0);
798 }
799 else if (GNUNET_NO == ret)
800 {
801 LOG (GNUNET_ERROR_TYPE_WARNING,
802 "Directory for file `%s' exists but is not writable for us\n",
803 filename_valid_peers);
804 GNUNET_break (0);
805 }
806 fh = GNUNET_DISK_file_open (filename_valid_peers,
807 GNUNET_DISK_OPEN_WRITE |
808 GNUNET_DISK_OPEN_CREATE,
809 GNUNET_DISK_PERM_USER_READ |
810 GNUNET_DISK_PERM_USER_WRITE);
811 if (NULL == fh)
812 {
813 LOG (GNUNET_ERROR_TYPE_WARNING,
814 "Not able to write valid peers to file `%s'\n",
815 filename_valid_peers);
816 return;
817 }
818 LOG (GNUNET_ERROR_TYPE_DEBUG,
819 "Writing %u valid peers to disk\n",
820 GNUNET_CONTAINER_multipeermap_size (valid_peers));
821 number_written_peers =
822 GNUNET_CONTAINER_multipeermap_iterate (valid_peers,
823 store_peer_presistently_iterator,
824 fh);
825 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
826 GNUNET_assert (number_written_peers ==
827 GNUNET_CONTAINER_multipeermap_size (valid_peers));
828}
829
830
831/**
832 * @brief Convert string representation of peer id to peer id.
833 *
834 * Counterpart to #GNUNET_i2s_full.
835 *
836 * @param string_repr The string representation of the peer id
837 *
838 * @return The peer id
839 */
840static const struct GNUNET_PeerIdentity *
841s2i_full (const char *string_repr)
842{
843 struct GNUNET_PeerIdentity *peer;
844 size_t len;
845 int ret;
846
847 peer = GNUNET_new (struct GNUNET_PeerIdentity);
848 len = strlen (string_repr);
849 if (52 > len)
850 {
851 LOG (GNUNET_ERROR_TYPE_WARNING,
852 "Not able to convert string representation of PeerID to PeerID\n"
853 "Sting representation: %s (len %u) - too short\n",
854 string_repr,
855 len);
856 GNUNET_break (0);
857 }
858 else if (52 < len)
859 {
860 len = 52;
861 }
862 ret = GNUNET_CRYPTO_eddsa_public_key_from_string (string_repr,
863 len,
864 &peer->public_key);
865 if (GNUNET_OK != ret)
866 {
867 LOG (GNUNET_ERROR_TYPE_WARNING,
868 "Not able to convert string representation of PeerID to PeerID\n"
869 "Sting representation: %s\n",
870 string_repr);
871 GNUNET_break (0);
872 }
873 return peer;
874}
875
876
877/**
878 * @brief Restore the peers on disk to #valid_peers.
879 */
880static void
881restore_valid_peers ()
882{
883 off_t file_size;
884 uint32_t num_peers;
885 struct GNUNET_DISK_FileHandle *fh;
886 char *buf;
887 ssize_t size_read;
888 char *iter_buf;
889 char *str_repr;
890 const struct GNUNET_PeerIdentity *peer;
891
892 if (0 == strncmp ("DISABLE", filename_valid_peers, 7))
893 {
894 return;
895 }
896
897 if (GNUNET_OK != GNUNET_DISK_file_test (filename_valid_peers))
898 {
899 return;
900 }
901 fh = GNUNET_DISK_file_open (filename_valid_peers,
902 GNUNET_DISK_OPEN_READ,
903 GNUNET_DISK_PERM_NONE);
904 GNUNET_assert (NULL != fh);
905 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_handle_size (fh, &file_size));
906 num_peers = file_size / 53;
907 buf = GNUNET_malloc (file_size);
908 size_read = GNUNET_DISK_file_read (fh, buf, file_size);
909 GNUNET_assert (size_read == file_size);
910 LOG (GNUNET_ERROR_TYPE_DEBUG,
911 "Restoring %" PRIu32 " peers from file `%s'\n",
912 num_peers,
913 filename_valid_peers);
914 for (iter_buf = buf; iter_buf < buf + file_size - 1; iter_buf += 53)
915 {
916 str_repr = GNUNET_strndup (iter_buf, 53);
917 peer = s2i_full (str_repr);
918 GNUNET_free (str_repr);
919 add_valid_peer (peer);
920 LOG (GNUNET_ERROR_TYPE_DEBUG,
921 "Restored valid peer %s from disk\n",
922 GNUNET_i2s_full (peer));
923 }
924 iter_buf = NULL;
925 GNUNET_free (buf);
926 LOG (GNUNET_ERROR_TYPE_DEBUG,
927 "num_peers: %" PRIu32 ", _size (valid_peers): %u\n",
928 num_peers,
929 GNUNET_CONTAINER_multipeermap_size (valid_peers));
930 if (num_peers != GNUNET_CONTAINER_multipeermap_size (valid_peers))
931 {
932 LOG (GNUNET_ERROR_TYPE_WARNING,
933 "Number of restored peers does not match file size. Have probably duplicates.\n");
934 }
935 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
936 LOG (GNUNET_ERROR_TYPE_DEBUG,
937 "Restored %u valid peers from disk\n",
938 GNUNET_CONTAINER_multipeermap_size (valid_peers));
939}
940
941
942/**
943 * @brief Initialise storage of peers
944 *
945 * @param fn_valid_peers filename of the file used to store valid peer ids
946 * @param cadet_h cadet handle
947 * @param disconnect_handler Disconnect handler
948 * @param c_handlers cadet handlers
949 * @param own_id own peer identity
950 */
951void
952Peers_initialise (char* fn_valid_peers,
953 struct GNUNET_CADET_Handle *cadet_h,
954 GNUNET_CADET_DisconnectEventHandler disconnect_handler,
955 const struct GNUNET_MQ_MessageHandler *c_handlers,
956 const struct GNUNET_PeerIdentity *own_id)
957{
958 filename_valid_peers = GNUNET_strdup (fn_valid_peers);
959 cadet_handle = cadet_h;
960 cleanup_destroyed_channel = disconnect_handler;
961 cadet_handlers = c_handlers;
962 own_identity = own_id;
963 peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO);
964 valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO);
965 restore_valid_peers ();
966}
967
968
969/**
970 * @brief Delete storage of peers that was created with #Peers_initialise ()
971 */
972void
973Peers_terminate ()
974{
975 if (GNUNET_SYSERR ==
976 GNUNET_CONTAINER_multipeermap_iterate (peer_map,
977 peermap_clear_iterator,
978 NULL))
979 {
980 LOG (GNUNET_ERROR_TYPE_WARNING,
981 "Iteration destroying peers was aborted.\n");
982 }
983 GNUNET_CONTAINER_multipeermap_destroy (peer_map);
984 store_valid_peers ();
985 GNUNET_free (filename_valid_peers);
986 GNUNET_CONTAINER_multipeermap_destroy (valid_peers);
987}
988
989
990/**
991 * Iterator over #valid_peers hash map entries.
992 *
993 * @param cls closure - unused
994 * @param peer current peer id
995 * @param value value in the hash map - unused
996 * @return #GNUNET_YES if we should continue to
997 * iterate,
998 * #GNUNET_NO if not.
999 */
1000static int
1001valid_peer_iterator (void *cls,
1002 const struct GNUNET_PeerIdentity *peer,
1003 void *value)
1004{
1005 struct PeersIteratorCls *it_cls = cls;
1006
1007 return it_cls->iterator (it_cls->cls,
1008 peer);
1009}
1010
1011
1012/**
1013 * @brief Get all currently known, valid peer ids.
1014 *
1015 * @param it function to call on each peer id
1016 * @param it_cls extra argument to @a it
1017 * @return the number of key value pairs processed,
1018 * #GNUNET_SYSERR if it aborted iteration
1019 */
1020int
1021Peers_get_valid_peers (PeersIterator iterator,
1022 void *it_cls)
1023{
1024 struct PeersIteratorCls *cls;
1025 int ret;
1026
1027 cls = GNUNET_new (struct PeersIteratorCls);
1028 cls->iterator = iterator;
1029 cls->cls = it_cls;
1030 ret = GNUNET_CONTAINER_multipeermap_iterate (valid_peers,
1031 valid_peer_iterator,
1032 cls);
1033 GNUNET_free (cls);
1034 return ret;
1035}
1036
1037
1038/**
1039 * @brief Add peer to known peers.
1040 *
1041 * This function is called on new peer_ids from 'external' sources
1042 * (client seed, cadet get_peers(), ...)
1043 *
1044 * @param peer the new #GNUNET_PeerIdentity
1045 *
1046 * @return #GNUNET_YES if peer was inserted
1047 * #GNUNET_NO otherwise (if peer was already known or
1048 * peer was #own_identity)
1049 */
1050int
1051Peers_insert_peer (const struct GNUNET_PeerIdentity *peer)
1052{
1053 if ( (GNUNET_YES == Peers_check_peer_known (peer)) ||
1054 (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, own_identity)) )
1055 {
1056 return GNUNET_NO; /* We already know this peer - nothing to do */
1057 }
1058 (void) create_peer_ctx (peer);
1059 return GNUNET_YES;
1060}
1061
1062
1063/**
1064 * @brief Try connecting to a peer to see whether it is online
1065 *
1066 * If not known yet, insert into known peers
1067 *
1068 * @param peer the peer whose liveliness is to be checked
1069 * @return #GNUNET_YES if peer had to be inserted
1070 * #GNUNET_NO otherwise (if peer was already known or
1071 * peer was #own_identity)
1072 */
1073int
1074Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer)
1075{
1076 struct PeerContext *peer_ctx;
1077 int ret;
1078
1079 if (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, own_identity))
1080 {
1081 return GNUNET_NO;
1082 }
1083 ret = Peers_insert_peer (peer);
1084 peer_ctx = get_peer_ctx (peer);
1085 if (GNUNET_NO == Peers_check_peer_flag (peer, Peers_ONLINE))
1086 {
1087 check_peer_live (peer_ctx);
1088 }
1089 return ret;
1090}
1091
1092
1093/**
1094 * @brief Check if peer is removable.
1095 *
1096 * Check if
1097 * - a recv channel exists
1098 * - there are pending messages
1099 * - there is no pending pull reply
1100 *
1101 * @param peer the peer in question
1102 * @return #GNUNET_YES if peer is removable
1103 * #GNUNET_NO if peer is NOT removable
1104 * #GNUNET_SYSERR if peer is not known
1105 */
1106int
1107Peers_check_removable (const struct GNUNET_PeerIdentity *peer)
1108{
1109 struct PeerContext *peer_ctx;
1110
1111 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer))
1112 {
1113 return GNUNET_SYSERR;
1114 }
1115
1116 peer_ctx = get_peer_ctx (peer);
1117 if ( (NULL != peer_ctx->recv_channel) ||
1118 (NULL != peer_ctx->pending_messages_head) ||
1119 (GNUNET_NO == check_peer_flag_set (peer_ctx, Peers_PULL_REPLY_PENDING)) )
1120 {
1121 return GNUNET_NO;
1122 }
1123 return GNUNET_YES;
1124}
1125
1126
1127/**
1128 * @brief Remove peer
1129 *
1130 * @param peer the peer to clean
1131 * @return #GNUNET_YES if peer was removed
1132 * #GNUNET_NO otherwise
1133 */
1134int
1135Peers_remove_peer (const struct GNUNET_PeerIdentity *peer)
1136{
1137 struct PeerContext *peer_ctx;
1138
1139 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer))
1140 {
1141 return GNUNET_NO;
1142 }
1143
1144 peer_ctx = get_peer_ctx (peer);
1145 set_peer_flag (peer_ctx, Peers_TO_DESTROY);
1146 LOG (GNUNET_ERROR_TYPE_DEBUG,
1147 "Going to remove peer %s\n",
1148 GNUNET_i2s (&peer_ctx->peer_id));
1149 Peers_unset_peer_flag (peer, Peers_ONLINE);
1150
1151 GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0);
1152 while (NULL != peer_ctx->pending_messages_head)
1153 {
1154 LOG (GNUNET_ERROR_TYPE_DEBUG,
1155 "Removing unsent %s\n",
1156 peer_ctx->pending_messages_head->type);
1157 remove_pending_message (peer_ctx->pending_messages_head);
1158 }
1159 /* If we are still waiting for notification whether this peer is live
1160 * cancel the according task */
1161 if (NULL != peer_ctx->liveliness_check_pending)
1162 {
1163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1164 "Removing pending liveliness check for peer %s\n",
1165 GNUNET_i2s (&peer_ctx->peer_id));
1166 // TODO wait until cadet sets mq->cancel_impl
1167 //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev);
1168 GNUNET_free (peer_ctx->liveliness_check_pending);
1169 peer_ctx->liveliness_check_pending = NULL;
1170 }
1171 if (NULL != peer_ctx->send_channel)
1172 {
1173 LOG (GNUNET_ERROR_TYPE_DEBUG,
1174 "Destroying send channel\n");
1175 GNUNET_CADET_channel_destroy (peer_ctx->send_channel);
1176 peer_ctx->send_channel = NULL;
1177 }
1178 if (NULL != peer_ctx->recv_channel)
1179 {
1180 LOG (GNUNET_ERROR_TYPE_DEBUG,
1181 "Destroying recv channel\n");
1182 GNUNET_CADET_channel_destroy (peer_ctx->recv_channel);
1183 peer_ctx->recv_channel = NULL;
1184 }
1185 if (NULL != peer_ctx->mq)
1186 {
1187 GNUNET_MQ_destroy (peer_ctx->mq);
1188 peer_ctx->mq = NULL;
1189 }
1190
1191 GNUNET_free (peer_ctx->send_channel_flags);
1192 GNUNET_free (peer_ctx->recv_channel_flags);
1193
1194 if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_remove_all (peer_map, &peer_ctx->peer_id))
1195 {
1196 LOG (GNUNET_ERROR_TYPE_WARNING, "removing peer from peer_map failed\n");
1197 }
1198 GNUNET_free (peer_ctx);
1199 return GNUNET_YES;
1200}
1201
1202
1203/**
1204 * @brief set flags on a given peer.
1205 *
1206 * @param peer the peer to set flags on
1207 * @param flags the flags
1208 */
1209void
1210Peers_set_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags)
1211{
1212 struct PeerContext *peer_ctx;
1213
1214 peer_ctx = get_peer_ctx (peer);
1215 set_peer_flag (peer_ctx, flags);
1216}
1217
1218
1219/**
1220 * @brief unset flags on a given peer.
1221 *
1222 * @param peer the peer to unset flags on
1223 * @param flags the flags
1224 */
1225void
1226Peers_unset_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags)
1227{
1228 struct PeerContext *peer_ctx;
1229
1230 peer_ctx = get_peer_ctx (peer);
1231 unset_peer_flag (peer_ctx, flags);
1232}
1233
1234
1235/**
1236 * @brief Check whether flags on a peer are set.
1237 *
1238 * @param peer the peer to check the flag of
1239 * @param flags the flags to check
1240 *
1241 * @return #GNUNET_SYSERR if peer is not known
1242 * #GNUNET_YES if all given flags are set
1243 * #GNUNET_NO otherwise
1244 */
1245int
1246Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags)
1247{
1248 struct PeerContext *peer_ctx;
1249
1250 if (GNUNET_NO == Peers_check_peer_known (peer))
1251 {
1252 return GNUNET_SYSERR;
1253 }
1254 peer_ctx = get_peer_ctx (peer);
1255 return check_peer_flag_set (peer_ctx, flags);
1256}
1257
1258
1259/**
1260 * @brief set flags on a given channel.
1261 *
1262 * @param channel the channel to set flags on
1263 * @param flags the flags
1264 */
1265void
1266Peers_set_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags)
1267{
1268 set_channel_flag (channel_flags, flags);
1269}
1270
1271
1272/**
1273 * @brief unset flags on a given channel.
1274 *
1275 * @param channel the channel to unset flags on
1276 * @param flags the flags
1277 */
1278void
1279Peers_unset_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags)
1280{
1281 unset_channel_flag (channel_flags, flags);
1282}
1283
1284
1285/**
1286 * @brief Check whether flags on a channel are set.
1287 *
1288 * @param channel the channel to check the flag of
1289 * @param flags the flags to check
1290 *
1291 * @return #GNUNET_YES if all given flags are set
1292 * #GNUNET_NO otherwise
1293 */
1294int
1295Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags)
1296{
1297 return check_channel_flag_set (channel_flags, flags);
1298}
1299
1300/**
1301 * @brief Get the flags for the channel in @a role for @a peer.
1302 *
1303 * @param peer Peer to get the channel flags for.
1304 * @param role Role of channel to get flags for
1305 *
1306 * @return The flags.
1307 */
1308uint32_t *
1309Peers_get_channel_flag (const struct GNUNET_PeerIdentity *peer,
1310 enum Peers_ChannelRole role)
1311{
1312 const struct PeerContext *peer_ctx;
1313
1314 peer_ctx = get_peer_ctx (peer);
1315 if (Peers_CHANNEL_ROLE_SENDING == role)
1316 {
1317 return peer_ctx->send_channel_flags;
1318 }
1319 else if (Peers_CHANNEL_ROLE_RECEIVING == role)
1320 {
1321 return peer_ctx->recv_channel_flags;
1322 }
1323 else
1324 {
1325 GNUNET_assert (0);
1326 }
1327}
1328
1329/**
1330 * @brief Check whether we have information about the given peer.
1331 *
1332 * FIXME probably deprecated. Make this the new _online.
1333 *
1334 * @param peer peer in question
1335 *
1336 * @return #GNUNET_YES if peer is known
1337 * #GNUNET_NO if peer is not knwon
1338 */
1339int
1340Peers_check_peer_known (const struct GNUNET_PeerIdentity *peer)
1341{
1342 return GNUNET_CONTAINER_multipeermap_contains (peer_map, peer);
1343}
1344
1345
1346/**
1347 * @brief Check whether @a peer is actually a peer.
1348 *
1349 * A valid peer is a peer that we know exists eg. we were connected to once.
1350 *
1351 * @param peer peer in question
1352 *
1353 * @return #GNUNET_YES if peer is valid
1354 * #GNUNET_NO if peer is not valid
1355 */
1356int
1357Peers_check_peer_valid (const struct GNUNET_PeerIdentity *peer)
1358{
1359 return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer);
1360}
1361
1362
1363/**
1364 * @brief Indicate that we want to send to the other peer
1365 *
1366 * This establishes a sending channel
1367 *
1368 * @param peer the peer to establish channel to
1369 */
1370void
1371Peers_indicate_sending_intention (const struct GNUNET_PeerIdentity *peer)
1372{
1373 GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer));
1374 (void) get_channel (peer);
1375}
1376
1377
1378/**
1379 * @brief Check whether other peer has the intention to send/opened channel
1380 * towars us
1381 *
1382 * @param peer the peer in question
1383 *
1384 * @return #GNUNET_YES if peer has the intention to send
1385 * #GNUNET_NO otherwise
1386 */
1387int
1388Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer)
1389{
1390 const struct PeerContext *peer_ctx;
1391
1392 peer_ctx = get_peer_ctx (peer);
1393 if (NULL != peer_ctx->recv_channel)
1394 {
1395 return GNUNET_YES;
1396 }
1397 return GNUNET_NO;
1398}
1399
1400
1401/**
1402 * Handle the channel a peer opens to us.
1403 *
1404 * @param cls The closure
1405 * @param channel The channel the peer wants to establish
1406 * @param initiator The peer's peer ID
1407 *
1408 * @return initial channel context for the channel
1409 * (can be NULL -- that's not an error)
1410 */
1411void *
1412Peers_handle_inbound_channel (void *cls,
1413 struct GNUNET_CADET_Channel *channel,
1414 const struct GNUNET_PeerIdentity *initiator)
1415{
1416 struct PeerContext *peer_ctx;
1417
1418 LOG (GNUNET_ERROR_TYPE_DEBUG,
1419 "New channel was established to us (Peer %s).\n",
1420 GNUNET_i2s (initiator));
1421 GNUNET_assert (NULL != channel); /* according to cadet API */
1422 /* Make sure we 'know' about this peer */
1423 peer_ctx = create_or_get_peer_ctx (initiator);
1424 set_peer_live (peer_ctx);
1425 /* We only accept one incoming channel per peer */
1426 if (GNUNET_YES == Peers_check_peer_send_intention (initiator))
1427 {
1428 set_channel_flag (peer_ctx->recv_channel_flags,
1429 Peers_CHANNEL_ESTABLISHED_TWICE);
1430 GNUNET_CADET_channel_destroy (channel);
1431 /* return the channel context */
1432 return &peer_ctx->peer_id;
1433 }
1434 peer_ctx->recv_channel = channel;
1435 return &peer_ctx->peer_id;
1436}
1437
1438
1439/**
1440 * @brief Check whether a sending channel towards the given peer exists
1441 *
1442 * @param peer the peer to check for
1443 *
1444 * @return #GNUNET_YES if a sending channel towards that peer exists
1445 * #GNUNET_NO otherwise
1446 */
1447int
1448Peers_check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer)
1449{
1450 struct PeerContext *peer_ctx;
1451
1452 if (GNUNET_NO == Peers_check_peer_known (peer))
1453 { /* If no such peer exists, there is no channel */
1454 return GNUNET_NO;
1455 }
1456 peer_ctx = get_peer_ctx (peer);
1457 if (NULL == peer_ctx->send_channel)
1458 {
1459 return GNUNET_NO;
1460 }
1461 return GNUNET_YES;
1462}
1463
1464
1465/**
1466 * @brief check whether the given channel is the sending channel of the given
1467 * peer
1468 *
1469 * @param peer the peer in question
1470 * @param channel the channel to check for
1471 * @param role either #Peers_CHANNEL_ROLE_SENDING, or
1472 * #Peers_CHANNEL_ROLE_RECEIVING
1473 *
1474 * @return #GNUNET_YES if the given chennel is the sending channel of the peer
1475 * #GNUNET_NO otherwise
1476 */
1477int
1478Peers_check_channel_role (const struct GNUNET_PeerIdentity *peer,
1479 const struct GNUNET_CADET_Channel *channel,
1480 enum Peers_ChannelRole role)
1481{
1482 const struct PeerContext *peer_ctx;
1483
1484 if (GNUNET_NO == Peers_check_peer_known (peer))
1485 {
1486 return GNUNET_NO;
1487 }
1488 peer_ctx = get_peer_ctx (peer);
1489 if ( (Peers_CHANNEL_ROLE_SENDING == role) &&
1490 (channel == peer_ctx->send_channel) )
1491 {
1492 return GNUNET_YES;
1493 }
1494 if ( (Peers_CHANNEL_ROLE_RECEIVING == role) &&
1495 (channel == peer_ctx->recv_channel) )
1496 {
1497 return GNUNET_YES;
1498 }
1499 return GNUNET_NO;
1500}
1501
1502
1503/**
1504 * @brief Destroy the send channel of a peer e.g. stop indicating a sending
1505 * intention to another peer
1506 *
1507 * If there is also no channel to receive messages from that peer, remove it
1508 * from the peermap.
1509 * TODO really?
1510 *
1511 * @peer the peer identity of the peer whose sending channel to destroy
1512 * @return #GNUNET_YES if channel was destroyed
1513 * #GNUNET_NO otherwise
1514 */
1515int
1516Peers_destroy_sending_channel (const struct GNUNET_PeerIdentity *peer)
1517{
1518 struct PeerContext *peer_ctx;
1519
1520 if (GNUNET_NO == Peers_check_peer_known (peer))
1521 {
1522 return GNUNET_NO;
1523 }
1524 peer_ctx = get_peer_ctx (peer);
1525 if (NULL != peer_ctx->send_channel)
1526 {
1527 set_channel_flag (peer_ctx->send_channel_flags, Peers_CHANNEL_CLEAN);
1528 GNUNET_CADET_channel_destroy (peer_ctx->send_channel);
1529 peer_ctx->send_channel = NULL;
1530 (void) Peers_check_connected (peer);
1531 return GNUNET_YES;
1532 }
1533 return GNUNET_NO;
1534}
1535
1536/**
1537 * This is called when a channel is destroyed.
1538 *
1539 * @param cls The closure
1540 * @param channel The channel being closed
1541 * @param channel_ctx The context associated with this channel
1542 */
1543void
1544Peers_cleanup_destroyed_channel (void *cls,
1545 const struct GNUNET_CADET_Channel *channel)
1546{
1547 struct GNUNET_PeerIdentity *peer = cls;
1548 struct PeerContext *peer_ctx;
1549
1550 if (GNUNET_NO == Peers_check_peer_known (peer))
1551 {/* We don't want to implicitly create a context that we're about to kill */
1552 LOG (GNUNET_ERROR_TYPE_DEBUG,
1553 "channel (%s) without associated context was destroyed\n",
1554 GNUNET_i2s (peer));
1555 return;
1556 }
1557 peer_ctx = get_peer_ctx (peer);
1558
1559 /* If our peer issued the destruction of the channel, the #Peers_TO_DESTROY
1560 * flag will be set. In this case simply make sure that the channels are
1561 * cleaned. */
1562 /* FIXME This distinction seems to be redundant */
1563 if (Peers_check_peer_flag (peer, Peers_TO_DESTROY))
1564 {/* We initiatad the destruction of this particular peer */
1565 if (channel == peer_ctx->send_channel)
1566 peer_ctx->send_channel = NULL;
1567 else if (channel == peer_ctx->recv_channel)
1568 peer_ctx->recv_channel = NULL;
1569
1570 if (NULL != peer_ctx->send_channel)
1571 {
1572 GNUNET_CADET_channel_destroy (peer_ctx->send_channel);
1573 peer_ctx->send_channel = NULL;
1574 }
1575 if (NULL != peer_ctx->recv_channel)
1576 {
1577 GNUNET_CADET_channel_destroy (peer_ctx->recv_channel);
1578 peer_ctx->recv_channel = NULL;
1579 }
1580 /* Set the #Peers_ONLINE flag accordingly */
1581 (void) Peers_check_connected (peer);
1582 return;
1583 }
1584
1585 else
1586 { /* We did not initiate the destruction of this peer */
1587 if (channel == peer_ctx->send_channel)
1588 { /* Something (but us) killd the channel - clean up peer */
1589 LOG (GNUNET_ERROR_TYPE_DEBUG,
1590 "send channel (%s) was destroyed - cleaning up\n",
1591 GNUNET_i2s (peer));
1592 peer_ctx->send_channel = NULL;
1593 }
1594 else if (channel == peer_ctx->recv_channel)
1595 { /* Other peer doesn't want to send us messages anymore */
1596 LOG (GNUNET_ERROR_TYPE_DEBUG,
1597 "Peer %s destroyed recv channel - cleaning up channel\n",
1598 GNUNET_i2s (peer));
1599 peer_ctx->recv_channel = NULL;
1600 }
1601 else
1602 {
1603 LOG (GNUNET_ERROR_TYPE_WARNING,
1604 "unknown channel (%s) was destroyed\n",
1605 GNUNET_i2s (peer));
1606 }
1607 }
1608 (void) Peers_check_connected (peer);
1609}
1610
1611/**
1612 * @brief Send a message to another peer.
1613 *
1614 * Keeps track about pending messages so they can be properly removed when the
1615 * peer is destroyed.
1616 *
1617 * @param peer receeiver of the message
1618 * @param ev envelope of the message
1619 * @param type type of the message
1620 */
1621void
1622Peers_send_message (const struct GNUNET_PeerIdentity *peer,
1623 struct GNUNET_MQ_Envelope *ev,
1624 const char *type)
1625{
1626 struct PendingMessage *pending_msg;
1627 struct GNUNET_MQ_Handle *mq;
1628
1629 pending_msg = insert_pending_message (peer, ev, type);
1630 mq = get_mq (peer);
1631 GNUNET_MQ_notify_sent (ev,
1632 mq_notify_sent_cb,
1633 pending_msg);
1634 GNUNET_MQ_send (mq, ev);
1635}
1636
1637/**
1638 * @brief Schedule a operation on given peer
1639 *
1640 * Avoids scheduling an operation twice.
1641 *
1642 * @param peer the peer we want to schedule the operation for once it gets live
1643 *
1644 * @return #GNUNET_YES if the operation was scheduled
1645 * #GNUNET_NO otherwise
1646 */
1647int
1648Peers_schedule_operation (const struct GNUNET_PeerIdentity *peer,
1649 const PeerOp peer_op)
1650{
1651 struct PeerPendingOp pending_op;
1652 struct PeerContext *peer_ctx;
1653
1654 if (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, own_identity))
1655 {
1656 return GNUNET_NO;
1657 }
1658 GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer));
1659
1660 //TODO if LIVE/ONLINE execute immediately
1661
1662 if (GNUNET_NO == check_operation_scheduled (peer, peer_op))
1663 {
1664 peer_ctx = get_peer_ctx (peer);
1665 pending_op.op = peer_op;
1666 pending_op.op_cls = NULL;
1667 GNUNET_array_append (peer_ctx->pending_ops,
1668 peer_ctx->num_pending_ops,
1669 pending_op);
1670 return GNUNET_YES;
1671 }
1672 return GNUNET_NO;
1673}
1674
1675/**
1676 * @brief Get the recv_channel of @a peer.
1677 * Needed to correctly handle (call #GNUNET_CADET_receive_done()) incoming
1678 * messages.
1679 *
1680 * @param peer The peer to get the recv_channel from.
1681 *
1682 * @return The recv_channel.
1683 */
1684struct GNUNET_CADET_Channel *
1685Peers_get_recv_channel (const struct GNUNET_PeerIdentity *peer)
1686{
1687 struct PeerContext *peer_ctx;
1688
1689 GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer));
1690 peer_ctx = get_peer_ctx (peer);
1691 return peer_ctx->recv_channel;
1692}
1693
1694/* end of gnunet-service-rps_peers.c */
diff --git a/src/rps/gnunet-service-rps_peers.h b/src/rps/gnunet-service-rps_peers.h
deleted file mode 100644
index 15970a7ce..000000000
--- a/src/rps/gnunet-service-rps_peers.h
+++ /dev/null
@@ -1,437 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21/**
22 * @file rps/gnunet-service-rps_peers.h
23 * @brief utilities for managing (information about) peers
24 * @author Julius Bünger
25 */
26#include "gnunet_util_lib.h"
27#include <inttypes.h>
28#include "gnunet_cadet_service.h"
29
30
31/**
32 * Different flags indicating the status of another peer.
33 */
34enum Peers_PeerFlags
35{
36 /**
37 * If we are waiting for a reply from that peer (sent a pull request).
38 */
39 Peers_PULL_REPLY_PENDING = 0x01,
40
41 /* IN_OTHER_GOSSIP_LIST = 0x02, unneeded? */
42 /* IN_OWN_SAMPLER_LIST = 0x04, unneeded? */
43 /* IN_OWN_GOSSIP_LIST = 0x08, unneeded? */
44
45 /**
46 * We set this bit when we know the peer is online.
47 */
48 Peers_ONLINE = 0x20,
49
50 /**
51 * We set this bit when we are going to destroy the channel to this peer.
52 * When cleanup_channel is called, we know that we wanted to destroy it.
53 * Otherwise the channel to the other peer was destroyed.
54 */
55 Peers_TO_DESTROY = 0x40,
56};
57
58/**
59 * Keep track of the status of a channel.
60 *
61 * This is needed in order to know what to do with a channel when it's
62 * destroyed.
63 */
64enum Peers_ChannelFlags
65{
66 /**
67 * We destroyed the channel because the other peer established a second one.
68 */
69 Peers_CHANNEL_ESTABLISHED_TWICE = 0x1,
70
71 /**
72 * The channel was removed because it was not needed any more. This should be
73 * the sending channel.
74 */
75 Peers_CHANNEL_CLEAN = 0x2,
76};
77
78/**
79 * @brief The role of a channel. Sending or receiving.
80 */
81enum Peers_ChannelRole
82{
83 /**
84 * Channel is used for sending
85 */
86 Peers_CHANNEL_ROLE_SENDING = 0x01,
87
88 /**
89 * Channel is used for receiving
90 */
91 Peers_CHANNEL_ROLE_RECEIVING = 0x02,
92};
93
94/**
95 * @brief Functions of this type can be used to be stored at a peer for later execution.
96 *
97 * @param cls closure
98 * @param peer peer to execute function on
99 */
100typedef void (* PeerOp) (void *cls, const struct GNUNET_PeerIdentity *peer);
101
102/**
103 * @brief Iterator over valid peers.
104 *
105 * @param cls closure
106 * @param peer current public peer id
107 * @return #GNUNET_YES if we should continue to
108 * iterate,
109 * #GNUNET_NO if not.
110 */
111typedef int
112(*PeersIterator) (void *cls,
113 const struct GNUNET_PeerIdentity *peer);
114
115/**
116 * @brief Initialise storage of peers
117 *
118 * @param fn_valid_peers filename of the file used to store valid peer ids
119 * @param cadet_h cadet handle
120 * @param disconnect_handler Disconnect handler
121 * @param c_handlers cadet handlers
122 * @param own_id own peer identity
123 */
124void
125Peers_initialise (char* fn_valid_peers,
126 struct GNUNET_CADET_Handle *cadet_h,
127 GNUNET_CADET_DisconnectEventHandler disconnect_handler,
128 const struct GNUNET_MQ_MessageHandler *c_handlers,
129 const struct GNUNET_PeerIdentity *own_id);
130
131/**
132 * @brief Delete storage of peers that was created with #Peers_initialise ()
133 */
134void
135Peers_terminate ();
136
137
138/**
139 * @brief Get all currently known, valid peer ids.
140 *
141 * @param it function to call on each peer id
142 * @param it_cls extra argument to @a it
143 * @return the number of key value pairs processed,
144 * #GNUNET_SYSERR if it aborted iteration
145 */
146int
147Peers_get_valid_peers (PeersIterator iterator,
148 void *it_cls);
149
150/**
151 * @brief Add peer to known peers.
152 *
153 * This function is called on new peer_ids from 'external' sources
154 * (client seed, cadet get_peers(), ...)
155 *
156 * @param peer the new #GNUNET_PeerIdentity
157 *
158 * @return #GNUNET_YES if peer was inserted
159 * #GNUNET_NO otherwise (if peer was already known or
160 * peer was #own_identity)
161 */
162int
163Peers_insert_peer (const struct GNUNET_PeerIdentity *peer);
164
165/**
166 * @brief Try connecting to a peer to see whether it is online
167 *
168 * If not known yet, insert into known peers
169 *
170 * @param peer the peer whose liveliness is to be checked
171 * @return #GNUNET_YES if peer had to be inserted
172 * #GNUNET_NO otherwise (if peer was already known or
173 * peer was #own_identity)
174 */
175int
176Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer);
177
178/**
179 * @brief Check if peer is removable.
180 *
181 * Check if
182 * - a recv channel exists
183 * - there are pending messages
184 * - there is no pending pull reply
185 *
186 * @param peer the peer in question
187 * @return #GNUNET_YES if peer is removable
188 * #GNUNET_NO if peer is NOT removable
189 * #GNUNET_SYSERR if peer is not known
190 */
191int
192Peers_check_removable (const struct GNUNET_PeerIdentity *peer);
193
194/**
195 * @brief Remove peer
196 *
197 * @param peer the peer to clean
198 * @return #GNUNET_YES if peer was removed
199 * #GNUNET_NO otherwise
200 */
201int
202Peers_remove_peer (const struct GNUNET_PeerIdentity *peer);
203
204/**
205 * @brief set flags on a given peer.
206 *
207 * @param peer the peer to set flags on
208 * @param flags the flags
209 */
210void
211Peers_set_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags);
212
213/**
214 * @brief unset flags on a given peer.
215 *
216 * @param peer the peer to unset flags on
217 * @param flags the flags
218 */
219void
220Peers_unset_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags);
221
222/**
223 * @brief Check whether flags on a peer are set.
224 *
225 * @param peer the peer to check the flag of
226 * @param flags the flags to check
227 *
228 * @return #GNUNET_YES if all given flags are set
229 * ##GNUNET_NO otherwise
230 */
231int
232Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags);
233
234
235/**
236 * @brief set flags on a given channel.
237 *
238 * @param channel the channel to set flags on
239 * @param flags the flags
240 */
241void
242Peers_set_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags);
243
244/**
245 * @brief unset flags on a given channel.
246 *
247 * @param channel the channel to unset flags on
248 * @param flags the flags
249 */
250void
251Peers_unset_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags);
252
253/**
254 * @brief Check whether flags on a channel are set.
255 *
256 * @param channel the channel to check the flag of
257 * @param flags the flags to check
258 *
259 * @return #GNUNET_YES if all given flags are set
260 * #GNUNET_NO otherwise
261 */
262int
263Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags);
264
265/**
266 * @brief Get the flags for the channel in @a role for @a peer.
267 *
268 * @param peer Peer to get the channel flags for.
269 * @param role Role of channel to get flags for
270 *
271 * @return The flags.
272 */
273uint32_t *
274Peers_get_channel_flag (const struct GNUNET_PeerIdentity *peer,
275 enum Peers_ChannelRole role);
276
277/**
278 * @brief Check whether we have information about the given peer.
279 *
280 * FIXME probably deprecated. Make this the new _online.
281 *
282 * @param peer peer in question
283 *
284 * @return #GNUNET_YES if peer is known
285 * #GNUNET_NO if peer is not knwon
286 */
287int
288Peers_check_peer_known (const struct GNUNET_PeerIdentity *peer);
289
290/**
291 * @brief Check whether @a peer is actually a peer.
292 *
293 * A valid peer is a peer that we know exists eg. we were connected to once.
294 *
295 * @param peer peer in question
296 *
297 * @return #GNUNET_YES if peer is valid
298 * #GNUNET_NO if peer is not valid
299 */
300int
301Peers_check_peer_valid (const struct GNUNET_PeerIdentity *peer);
302
303/**
304 * @brief Indicate that we want to send to the other peer
305 *
306 * This establishes a sending channel
307 *
308 * @param peer the peer to establish channel to
309 */
310void
311Peers_indicate_sending_intention (const struct GNUNET_PeerIdentity *peer);
312
313/**
314 * @brief Check whether other peer has the intention to send/opened channel
315 * towars us
316 *
317 * @param peer the peer in question
318 *
319 * @return #GNUNET_YES if peer has the intention to send
320 * #GNUNET_NO otherwise
321 */
322int
323Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer);
324
325/**
326 * Handle the channel a peer opens to us.
327 *
328 * @param cls The closure
329 * @param channel The channel the peer wants to establish
330 * @param initiator The peer's peer ID
331 *
332 * @return initial channel context for the channel
333 * (can be NULL -- that's not an error)
334 */
335void *
336Peers_handle_inbound_channel (void *cls,
337 struct GNUNET_CADET_Channel *channel,
338 const struct GNUNET_PeerIdentity *initiator);
339
340/**
341 * @brief Check whether a sending channel towards the given peer exists
342 *
343 * @param peer the peer to check for
344 *
345 * @return #GNUNET_YES if a sending channel towards that peer exists
346 * #GNUNET_NO otherwise
347 */
348int
349Peers_check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer);
350
351/**
352 * @brief check whether the given channel is the sending channel of the given
353 * peer
354 *
355 * @param peer the peer in question
356 * @param channel the channel to check for
357 * @param role either #Peers_CHANNEL_ROLE_SENDING, or
358 * #Peers_CHANNEL_ROLE_RECEIVING
359 *
360 * @return #GNUNET_YES if the given chennel is the sending channel of the peer
361 * #GNUNET_NO otherwise
362 */
363int
364Peers_check_channel_role (const struct GNUNET_PeerIdentity *peer,
365 const struct GNUNET_CADET_Channel *channel,
366 enum Peers_ChannelRole role);
367
368/**
369 * @brief Destroy the send channel of a peer e.g. stop indicating a sending
370 * intention to another peer
371 *
372 * If there is also no channel to receive messages from that peer, remove it
373 * from the peermap.
374 *
375 * @peer the peer identity of the peer whose sending channel to destroy
376 * @return #GNUNET_YES if channel was destroyed
377 * #GNUNET_NO otherwise
378 */
379int
380Peers_destroy_sending_channel (const struct GNUNET_PeerIdentity *peer);
381
382/**
383 * This is called when a channel is destroyed.
384 *
385 * Removes peer completely from our knowledge if the send_channel was destroyed
386 * Otherwise simply delete the recv_channel
387 *
388 * @param cls The closure
389 * @param channel The channel being closed
390 * @param channel_ctx The context associated with this channel
391 */
392void
393Peers_cleanup_destroyed_channel (void *cls,
394 const struct GNUNET_CADET_Channel *channel);
395
396/**
397 * @brief Send a message to another peer.
398 *
399 * Keeps track about pending messages so they can be properly removed when the
400 * peer is destroyed.
401 *
402 * @param peer receeiver of the message
403 * @param ev envelope of the message
404 * @param type type of the message
405 */
406void
407Peers_send_message (const struct GNUNET_PeerIdentity *peer,
408 struct GNUNET_MQ_Envelope *ev,
409 const char *type);
410
411/**
412 * @brief Schedule a operation on given peer
413 *
414 * Avoids scheduling an operation twice.
415 *
416 * @param peer the peer we want to schedule the operation for once it gets live
417 *
418 * @return #GNUNET_YES if the operation was scheduled
419 * #GNUNET_NO otherwise
420 */
421int
422Peers_schedule_operation (const struct GNUNET_PeerIdentity *peer,
423 const PeerOp peer_op);
424
425/**
426 * @brief Get the recv_channel of @a peer.
427 * Needed to correctly handle (call #GNUNET_CADET_receive_done()) incoming
428 * messages.
429 *
430 * @param peer The peer to get the recv_channel from.
431 *
432 * @return The recv_channel.
433 */
434struct GNUNET_CADET_Channel *
435Peers_get_recv_channel (const struct GNUNET_PeerIdentity *peer);
436
437/* end of gnunet-service-rps_peers.h */
diff --git a/src/rps/rps.h b/src/rps/rps.h
index 3037e2190..f5cc2e8d1 100644
--- a/src/rps/rps.h
+++ b/src/rps/rps.h
@@ -175,4 +175,100 @@ struct GNUNET_RPS_CS_ActMaliciousMessage
175}; 175};
176#endif /* ENABLE_MALICIOUS */ 176#endif /* ENABLE_MALICIOUS */
177 177
178
179/***********************************************************************
180 * Defines from old gnunet-service-rps_peers.h
181***********************************************************************/
182
183/**
184 * Different flags indicating the status of another peer.
185 */
186enum Peers_PeerFlags
187{
188 /**
189 * If we are waiting for a reply from that peer (sent a pull request).
190 */
191 Peers_PULL_REPLY_PENDING = 0x01,
192
193 /* IN_OTHER_GOSSIP_LIST = 0x02, unneeded? */
194 /* IN_OWN_SAMPLER_LIST = 0x04, unneeded? */
195 /* IN_OWN_GOSSIP_LIST = 0x08, unneeded? */
196
197 /**
198 * We set this bit when we know the peer is online.
199 */
200 Peers_ONLINE = 0x20,
201
202 /**
203 * We set this bit when we are going to destroy the channel to this peer.
204 * When cleanup_channel is called, we know that we wanted to destroy it.
205 * Otherwise the channel to the other peer was destroyed.
206 */
207 Peers_TO_DESTROY = 0x40,
208};
209
210/**
211 * Keep track of the status of a channel.
212 *
213 * This is needed in order to know what to do with a channel when it's
214 * destroyed.
215 */
216enum Peers_ChannelFlags
217{
218 /**
219 * We destroyed the channel because the other peer established a second one.
220 */
221 Peers_CHANNEL_ESTABLISHED_TWICE = 0x1,
222
223 /**
224 * The channel was removed because it was not needed any more. This should be
225 * the sending channel.
226 */
227 Peers_CHANNEL_CLEAN = 0x2,
228
229 /**
230 * We destroyed the channel because the other peer established a second one.
231 */
232 Peers_CHANNEL_DESTROING = 0x4,
233};
234
235
236/**
237 * @brief The role of a channel. Sending or receiving.
238 */
239enum Peers_ChannelRole
240{
241 /**
242 * Channel is used for sending
243 */
244 Peers_CHANNEL_ROLE_SENDING = 0x01,
245
246 /**
247 * Channel is used for receiving
248 */
249 Peers_CHANNEL_ROLE_RECEIVING = 0x02,
250};
251
252/**
253 * @brief Functions of this type can be used to be stored at a peer for later execution.
254 *
255 * @param cls closure
256 * @param peer peer to execute function on
257 */
258typedef void (* PeerOp) (void *cls, const struct GNUNET_PeerIdentity *peer);
259
260/**
261 * @brief Iterator over valid peers.
262 *
263 * @param cls closure
264 * @param peer current public peer id
265 * @return #GNUNET_YES if we should continue to
266 * iterate,
267 * #GNUNET_NO if not.
268 */
269typedef int
270(*PeersIterator) (void *cls,
271 const struct GNUNET_PeerIdentity *peer);
272
273
178GNUNET_NETWORK_STRUCT_END 274GNUNET_NETWORK_STRUCT_END
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c
index acd3a165d..2cc1ac62e 100644
--- a/src/rps/test_rps.c
+++ b/src/rps/test_rps.c
@@ -18,7 +18,7 @@
18 Boston, MA 02110-1301, USA. 18 Boston, MA 02110-1301, USA.
19*/ 19*/
20/** 20/**
21 * @file rps/test_rps_multipeer.c 21 * @file rps/test_rps.c
22 * @brief Testcase for the random peer sampling service. Starts 22 * @brief Testcase for the random peer sampling service. Starts
23 * a peergroup with a given number of peers, then waits to 23 * a peergroup with a given number of peers, then waits to
24 * receive size pushes/pulls from each peer. Expects to wait 24 * receive size pushes/pulls from each peer. Expects to wait
@@ -62,6 +62,19 @@ static unsigned int mal_type = 0;
62 */ 62 */
63static struct GNUNET_TESTBED_Peer **testbed_peers; 63static struct GNUNET_TESTBED_Peer **testbed_peers;
64 64
65/**
66 * @brief Indicates whether peer should go off- or online
67 */
68enum PEER_ONLINE_DELTA {
69 /**
70 * @brief Indicates peer going online
71 */
72 PEER_GO_ONLINE = 1,
73 /**
74 * @brief Indicates peer going offline
75 */
76 PEER_GO_OFFLINE = -1,
77};
65 78
66/** 79/**
67 * Operation map entry 80 * Operation map entry
@@ -84,10 +97,10 @@ struct OpListEntry
84 struct GNUNET_TESTBED_Operation *op; 97 struct GNUNET_TESTBED_Operation *op;
85 98
86 /** 99 /**
87 * Depending on whether we start or stop NSE service at the peer set this to 1 100 * Depending on whether we start or stop RPS service at the peer, set this to
88 * or -1 101 * #PEER_GO_ONLINE (1) or #PEER_GO_OFFLINE (-1)
89 */ 102 */
90 int delta; 103 enum PEER_ONLINE_DELTA delta;
91 104
92 /** 105 /**
93 * Index of the regarding peer 106 * Index of the regarding peer
@@ -188,7 +201,7 @@ struct RPSPeer
188 int online; 201 int online;
189 202
190 /** 203 /**
191 * Number of Peer IDs to request 204 * Number of Peer IDs to request during the whole test
192 */ 205 */
193 unsigned int num_ids_to_request; 206 unsigned int num_ids_to_request;
194 207
@@ -218,6 +231,11 @@ struct RPSPeer
218 * Number of received PeerIDs 231 * Number of received PeerIDs
219 */ 232 */
220 unsigned int num_recv_ids; 233 unsigned int num_recv_ids;
234
235 /**
236 * Pending operation on that peer
237 */
238 const struct OpListEntry *entry_op_manage;
221}; 239};
222 240
223 241
@@ -259,6 +277,11 @@ static int ok;
259/** 277/**
260 * Identifier for the churn task that runs periodically 278 * Identifier for the churn task that runs periodically
261 */ 279 */
280static struct GNUNET_SCHEDULER_Task *shutdown_task;
281
282/**
283 * Identifier for the churn task that runs periodically
284 */
262static struct GNUNET_SCHEDULER_Task *churn_task; 285static struct GNUNET_SCHEDULER_Task *churn_task;
263 286
264/** 287/**
@@ -267,13 +290,21 @@ static struct GNUNET_SCHEDULER_Task *churn_task;
267typedef void (*InitPeer) (struct RPSPeer *rps_peer); 290typedef void (*InitPeer) (struct RPSPeer *rps_peer);
268 291
269/** 292/**
270 * Called directly after connecting to the service 293 * @brief Called directly after connecting to the service
294 *
295 * @param rps_peer Specific peer the function is called on
296 * @param h the handle to the rps service
271 */ 297 */
272typedef void (*PreTest) (void *cls, struct GNUNET_RPS_Handle *h); 298typedef void (*PreTest) (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h);
273 299
274/** 300/**
301 * @brief Executes functions to test the api/service for a given peer
302 *
275 * Called from within #rps_connect_complete_cb () 303 * Called from within #rps_connect_complete_cb ()
276 * Executes functions to test the api/service 304 * Implemented by #churn_test_cb, #profiler_cb, #mal_cb, #single_req_cb,
305 * #delay_req_cb, #seed_big_cb, #single_peer_seed_cb, #seed_cb, #req_cancel_cb
306 *
307 * @param rps_peer the peer the task runs on
277 */ 308 */
278typedef void (*MainTest) (struct RPSPeer *rps_peer); 309typedef void (*MainTest) (struct RPSPeer *rps_peer);
279 310
@@ -306,7 +337,7 @@ struct SingleTestRun
306 char *name; 337 char *name;
307 338
308 /** 339 /**
309 * Called to initialise peer 340 * Called with a single peer in order to initialise that peer
310 */ 341 */
311 InitPeer init_peer; 342 InitPeer init_peer;
312 343
@@ -316,7 +347,7 @@ struct SingleTestRun
316 PreTest pre_test; 347 PreTest pre_test;
317 348
318 /** 349 /**
319 * Function to execute the functions to be tested 350 * Main function for each peer
320 */ 351 */
321 MainTest main_test; 352 MainTest main_test;
322 353
@@ -344,6 +375,11 @@ struct SingleTestRun
344 * Number of Requests to make. 375 * Number of Requests to make.
345 */ 376 */
346 uint32_t num_requests; 377 uint32_t num_requests;
378
379 /**
380 * Run with churn
381 */
382 int have_churn;
347} cur_test_run; 383} cur_test_run;
348 384
349/** 385/**
@@ -497,6 +533,8 @@ shutdown_op (void *cls)
497{ 533{
498 unsigned int i; 534 unsigned int i;
499 535
536 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
537 "Shutdown task scheduled, going down.\n");
500 in_shutdown = GNUNET_YES; 538 in_shutdown = GNUNET_YES;
501 if (NULL != churn_task) 539 if (NULL != churn_task)
502 { 540 {
@@ -578,6 +616,11 @@ info_cb (void *cb_cls,
578{ 616{
579 struct OpListEntry *entry = (struct OpListEntry *) cb_cls; 617 struct OpListEntry *entry = (struct OpListEntry *) cb_cls;
580 618
619 if (GNUNET_YES == in_shutdown)
620 {
621 return;
622 }
623
581 if (NULL == pinfo || NULL != emsg) 624 if (NULL == pinfo || NULL != emsg)
582 { 625 {
583 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg); 626 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg);
@@ -627,6 +670,11 @@ rps_connect_complete_cb (void *cls,
627 struct RPSPeer *rps_peer = cls; 670 struct RPSPeer *rps_peer = cls;
628 struct GNUNET_RPS_Handle *rps = ca_result; 671 struct GNUNET_RPS_Handle *rps = ca_result;
629 672
673 if (GNUNET_YES == in_shutdown)
674 {
675 return;
676 }
677
630 rps_peer->rps_handle = rps; 678 rps_peer->rps_handle = rps;
631 rps_peer->online = GNUNET_YES; 679 rps_peer->online = GNUNET_YES;
632 num_peers_online++; 680 num_peers_online++;
@@ -755,7 +803,10 @@ default_reply_handle (void *cls,
755 803
756 if (0 == evaluate ()) 804 if (0 == evaluate ())
757 { 805 {
758 GNUNET_SCHEDULER_shutdown (); 806 GNUNET_assert (NULL != shutdown_task);
807 GNUNET_SCHEDULER_cancel (shutdown_task);
808 shutdown_task = GNUNET_SCHEDULER_add_now (&shutdown_op, NULL);
809 GNUNET_assert (NULL!= shutdown_task);
759 } 810 }
760} 811}
761 812
@@ -899,12 +950,20 @@ static void mal_init_peer (struct RPSPeer *rps_peer)
899 rps_peer->num_ids_to_request = 1; 950 rps_peer->num_ids_to_request = 1;
900} 951}
901 952
953
954/**
955 * @brief Set peers to (non-)malicious before execution
956 *
957 * Of signature #PreTest
958 *
959 * @param rps_peer the peer to set (non-) malicious
960 * @param h the handle to the service
961 */
902static void 962static void
903mal_pre (void *cls, struct GNUNET_RPS_Handle *h) 963mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
904{ 964{
905 #ifdef ENABLE_MALICIOUS 965 #ifdef ENABLE_MALICIOUS
906 uint32_t num_mal_peers; 966 uint32_t num_mal_peers;
907 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
908 967
909 GNUNET_assert ( (1 >= portion) && 968 GNUNET_assert ( (1 >= portion) &&
910 (0 < portion) ); 969 (0 < portion) );
@@ -929,6 +988,11 @@ mal_cb (struct RPSPeer *rps_peer)
929{ 988{
930 uint32_t num_mal_peers; 989 uint32_t num_mal_peers;
931 990
991 if (GNUNET_YES == in_shutdown)
992 {
993 return;
994 }
995
932 #ifdef ENABLE_MALICIOUS 996 #ifdef ENABLE_MALICIOUS
933 GNUNET_assert ( (1 >= portion) && 997 GNUNET_assert ( (1 >= portion) &&
934 (0 < portion) ); 998 (0 < portion) );
@@ -951,6 +1015,11 @@ mal_cb (struct RPSPeer *rps_peer)
951static void 1015static void
952single_req_cb (struct RPSPeer *rps_peer) 1016single_req_cb (struct RPSPeer *rps_peer)
953{ 1017{
1018 if (GNUNET_YES == in_shutdown)
1019 {
1020 return;
1021 }
1022
954 schedule_missing_requests (rps_peer); 1023 schedule_missing_requests (rps_peer);
955} 1024}
956 1025
@@ -960,6 +1029,11 @@ single_req_cb (struct RPSPeer *rps_peer)
960static void 1029static void
961delay_req_cb (struct RPSPeer *rps_peer) 1030delay_req_cb (struct RPSPeer *rps_peer)
962{ 1031{
1032 if (GNUNET_YES == in_shutdown)
1033 {
1034 return;
1035 }
1036
963 schedule_missing_requests (rps_peer); 1037 schedule_missing_requests (rps_peer);
964} 1038}
965 1039
@@ -969,6 +1043,11 @@ delay_req_cb (struct RPSPeer *rps_peer)
969static void 1043static void
970seed_cb (struct RPSPeer *rps_peer) 1044seed_cb (struct RPSPeer *rps_peer)
971{ 1045{
1046 if (GNUNET_YES == in_shutdown)
1047 {
1048 return;
1049 }
1050
972 GNUNET_SCHEDULER_add_delayed ( 1051 GNUNET_SCHEDULER_add_delayed (
973 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), 1052 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
974 seed_peers, rps_peer); 1053 seed_peers, rps_peer);
@@ -980,6 +1059,11 @@ seed_cb (struct RPSPeer *rps_peer)
980static void 1059static void
981seed_big_cb (struct RPSPeer *rps_peer) 1060seed_big_cb (struct RPSPeer *rps_peer)
982{ 1061{
1062 if (GNUNET_YES == in_shutdown)
1063 {
1064 return;
1065 }
1066
983 // TODO test seeding > GNUNET_MAX_MESSAGE_SIZE peers 1067 // TODO test seeding > GNUNET_MAX_MESSAGE_SIZE peers
984 GNUNET_SCHEDULER_add_delayed ( 1068 GNUNET_SCHEDULER_add_delayed (
985 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), 1069 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
@@ -1001,6 +1085,11 @@ single_peer_seed_cb (struct RPSPeer *rps_peer)
1001static void 1085static void
1002seed_req_cb (struct RPSPeer *rps_peer) 1086seed_req_cb (struct RPSPeer *rps_peer)
1003{ 1087{
1088 if (GNUNET_YES == in_shutdown)
1089 {
1090 return;
1091 }
1092
1004 GNUNET_SCHEDULER_add_delayed ( 1093 GNUNET_SCHEDULER_add_delayed (
1005 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), 1094 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
1006 seed_peers, rps_peer); 1095 seed_peers, rps_peer);
@@ -1015,6 +1104,11 @@ seed_req_cb (struct RPSPeer *rps_peer)
1015static void 1104static void
1016req_cancel_cb (struct RPSPeer *rps_peer) 1105req_cancel_cb (struct RPSPeer *rps_peer)
1017{ 1106{
1107 if (GNUNET_YES == in_shutdown)
1108 {
1109 return;
1110 }
1111
1018 schedule_missing_requests (rps_peer); 1112 schedule_missing_requests (rps_peer);
1019 GNUNET_SCHEDULER_add_delayed ( 1113 GNUNET_SCHEDULER_add_delayed (
1020 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1114 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
@@ -1023,6 +1117,49 @@ req_cancel_cb (struct RPSPeer *rps_peer)
1023} 1117}
1024 1118
1025/*********************************** 1119/***********************************
1120 * CHURN
1121***********************************/
1122
1123static void
1124churn (void *cls);
1125
1126/**
1127 * @brief Starts churn
1128 *
1129 * Has signature of #MainTest
1130 *
1131 * This is not implemented too nicely as this is called for each peer, but we
1132 * only need to call it once. (Yes we check that we only schedule the task
1133 * once.)
1134 *
1135 * @param rps_peer The peer it's called for
1136 */
1137static void
1138churn_test_cb (struct RPSPeer *rps_peer)
1139{
1140 if (GNUNET_YES == in_shutdown)
1141 {
1142 return;
1143 }
1144
1145 /* Start churn */
1146 if (GNUNET_YES == cur_test_run.have_churn && NULL == churn_task)
1147 {
1148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1149 "Starting churn task\n");
1150 churn_task = GNUNET_SCHEDULER_add_delayed (
1151 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
1152 churn,
1153 NULL);
1154 } else {
1155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1156 "Not starting churn task\n");
1157 }
1158
1159 schedule_missing_requests (rps_peer);
1160}
1161
1162/***********************************
1026 * PROFILER 1163 * PROFILER
1027***********************************/ 1164***********************************/
1028 1165
@@ -1041,6 +1178,11 @@ churn_cb (void *cls,
1041 // FIXME 1178 // FIXME
1042 struct OpListEntry *entry = cls; 1179 struct OpListEntry *entry = cls;
1043 1180
1181 if (GNUNET_YES == in_shutdown)
1182 {
1183 return;
1184 }
1185
1044 GNUNET_TESTBED_operation_done (entry->op); 1186 GNUNET_TESTBED_operation_done (entry->op);
1045 if (NULL != emsg) 1187 if (NULL != emsg)
1046 { 1188 {
@@ -1052,7 +1194,7 @@ churn_cb (void *cls,
1052 1194
1053 num_peers_online += entry->delta; 1195 num_peers_online += entry->delta;
1054 1196
1055 if (0 > entry->delta) 1197 if (PEER_GO_OFFLINE == entry->delta)
1056 { /* Peer hopefully just went offline */ 1198 { /* Peer hopefully just went offline */
1057 if (GNUNET_YES != rps_peers[entry->index].online) 1199 if (GNUNET_YES != rps_peers[entry->index].online)
1058 { 1200 {
@@ -1070,7 +1212,7 @@ churn_cb (void *cls,
1070 rps_peers[entry->index].online = GNUNET_NO; 1212 rps_peers[entry->index].online = GNUNET_NO;
1071 } 1213 }
1072 1214
1073 else if (0 < entry->delta) 1215 else if (PEER_GO_ONLINE < entry->delta)
1074 { /* Peer hopefully just went online */ 1216 { /* Peer hopefully just went online */
1075 if (GNUNET_NO != rps_peers[entry->index].online) 1217 if (GNUNET_NO != rps_peers[entry->index].online)
1076 { 1218 {
@@ -1093,20 +1235,44 @@ churn_cb (void *cls,
1093 } 1235 }
1094 rps_peers[entry->index].online = GNUNET_YES; 1236 rps_peers[entry->index].online = GNUNET_YES;
1095 } 1237 }
1238 else
1239 {
1240 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1241 "Invalid value for delta: %i\n", entry->delta);
1242 GNUNET_break (0);
1243 }
1096 1244
1097 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); 1245 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
1246 rps_peers[entry->index].entry_op_manage = NULL;
1098 GNUNET_free (entry); 1247 GNUNET_free (entry);
1099 //if (num_peers_in_round[current_round] == peers_running) 1248 //if (num_peers_in_round[current_round] == peers_running)
1100 // run_round (); 1249 // run_round ();
1101} 1250}
1102 1251
1252/**
1253 * @brief Set the rps-service up or down for a specific peer
1254 *
1255 * @param i index of action
1256 * @param j index of peer
1257 * @param delta (#PEER_ONLINE_DELTA) down (-1) or up (1)
1258 * @param prob_go_on_off the probability of the action
1259 */
1103static void 1260static void
1104manage_service_wrapper (unsigned int i, unsigned int j, int delta, 1261manage_service_wrapper (unsigned int i, unsigned int j,
1105 double prob_go_on_off) 1262 enum PEER_ONLINE_DELTA delta,
1263 double prob_go_on_off)
1106{ 1264{
1107 struct OpListEntry *entry; 1265 struct OpListEntry *entry;
1108 uint32_t prob; 1266 uint32_t prob;
1109 1267
1268 GNUNET_assert (GNUNET_YES == rps_peers[j].online);
1269
1270 /* make sure that management operation is not already scheduled */
1271 if (NULL != rps_peers[j].entry_op_manage)
1272 {
1273 return;
1274 }
1275
1110 prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1276 prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1111 UINT32_MAX); 1277 UINT32_MAX);
1112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1114,15 +1280,19 @@ manage_service_wrapper (unsigned int i, unsigned int j, int delta,
1114 i, 1280 i,
1115 j, 1281 j,
1116 GNUNET_i2s (rps_peers[j].peer_id), 1282 GNUNET_i2s (rps_peers[j].peer_id),
1117 (0 > delta) ? "online" : "offline"); 1283 (PEER_GO_ONLINE == delta) ? "online" : "offline");
1118 if (prob < prob_go_on_off * UINT32_MAX) 1284 if (prob < prob_go_on_off * UINT32_MAX)
1119 { 1285 {
1120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1121 "%s goes %s\n", 1287 "%s goes %s\n",
1122 GNUNET_i2s (rps_peers[j].peer_id), 1288 GNUNET_i2s (rps_peers[j].peer_id),
1123 (0 > delta) ? "offline" : "online"); 1289 (PEER_GO_OFFLINE == delta) ? "offline" : "online");
1290
1291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1292 "testbed_peers points to %p, peer 0 to %p\n",
1293 testbed_peers, testbed_peers[0]);
1124 1294
1125 if (0 > delta) 1295 if (PEER_GO_OFFLINE == delta)
1126 cancel_pending_req_rep (&rps_peers[j]); 1296 cancel_pending_req_rep (&rps_peers[j]);
1127 entry = make_oplist_entry (); 1297 entry = make_oplist_entry ();
1128 entry->delta = delta; 1298 entry->delta = delta;
@@ -1132,8 +1302,9 @@ manage_service_wrapper (unsigned int i, unsigned int j, int delta,
1132 "rps", 1302 "rps",
1133 &churn_cb, 1303 &churn_cb,
1134 entry, 1304 entry,
1135 (0 > delta) ? 0 : 1); 1305 (PEER_GO_OFFLINE == delta) ? 0 : 1);
1136 } 1306 }
1307 rps_peers[j].entry_op_manage = entry;
1137} 1308}
1138 1309
1139 1310
@@ -1148,6 +1319,15 @@ churn (void *cls)
1148 double portion_go_online; 1319 double portion_go_online;
1149 double portion_go_offline; 1320 double portion_go_offline;
1150 1321
1322 if (GNUNET_YES == in_shutdown)
1323 {
1324 return;
1325 }
1326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1327 "Churn function executing\n");
1328
1329 churn_task = NULL; /* Should be invalid by now */
1330
1151 /* Compute the probability for an online peer to go offline 1331 /* Compute the probability for an online peer to go offline
1152 * this round */ 1332 * this round */
1153 portion_online = num_peers_online * 1.0 / num_peers; 1333 portion_online = num_peers_online * 1.0 / num_peers;
@@ -1255,13 +1435,23 @@ profiler_reply_handle (void *cls,
1255static void 1435static void
1256profiler_cb (struct RPSPeer *rps_peer) 1436profiler_cb (struct RPSPeer *rps_peer)
1257{ 1437{
1438 if (GNUNET_YES == in_shutdown)
1439 {
1440 return;
1441 }
1442
1258 /* Start churn */ 1443 /* Start churn */
1259 if (NULL == churn_task) 1444 if (GNUNET_YES == cur_test_run.have_churn && NULL == churn_task)
1260 { 1445 {
1446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1447 "Starting churn task\n");
1261 churn_task = GNUNET_SCHEDULER_add_delayed ( 1448 churn_task = GNUNET_SCHEDULER_add_delayed (
1262 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), 1449 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
1263 churn, 1450 churn,
1264 NULL); 1451 NULL);
1452 } else {
1453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1454 "Not starting churn task\n");
1265 } 1455 }
1266 1456
1267 /* Only request peer ids at one peer. 1457 /* Only request peer ids at one peer.
@@ -1353,6 +1543,24 @@ run (void *cls,
1353 struct OpListEntry *entry; 1543 struct OpListEntry *entry;
1354 uint32_t num_mal_peers; 1544 uint32_t num_mal_peers;
1355 1545
1546 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n");
1547
1548 /* Check whether we timed out */
1549 if (n_peers != num_peers ||
1550 NULL == peers ||
1551 0 == links_succeeded)
1552 {
1553 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Going down due to args (eg. timeout)\n");
1554 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers);
1555 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n", num_peers);
1556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers);
1557 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n", links_succeeded);
1558 GNUNET_SCHEDULER_shutdown ();
1559 return;
1560 }
1561
1562
1563 /* Initialize peers */
1356 testbed_peers = peers; 1564 testbed_peers = peers;
1357 num_peers_online = 0; 1565 num_peers_online = 0;
1358 for (i = 0; i < num_peers; i++) 1566 for (i = 0; i < num_peers; i++)
@@ -1368,6 +1576,7 @@ run (void *cls,
1368 entry); 1576 entry);
1369 } 1577 }
1370 1578
1579 /* Bring peers up */
1371 num_mal_peers = round (portion * num_peers); 1580 num_mal_peers = round (portion * num_peers);
1372 GNUNET_assert (num_peers == n_peers); 1581 GNUNET_assert (num_peers == n_peers);
1373 for (i = 0; i < n_peers; i++) 1582 for (i = 0; i < n_peers; i++)
@@ -1390,7 +1599,7 @@ run (void *cls,
1390 1599
1391 if (NULL != churn_task) 1600 if (NULL != churn_task)
1392 GNUNET_SCHEDULER_cancel (churn_task); 1601 GNUNET_SCHEDULER_cancel (churn_task);
1393 GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL); 1602 shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL);
1394} 1603}
1395 1604
1396 1605
@@ -1412,6 +1621,7 @@ main (int argc, char *argv[])
1412 cur_test_run.pre_test = NULL; 1621 cur_test_run.pre_test = NULL;
1413 cur_test_run.reply_handle = default_reply_handle; 1622 cur_test_run.reply_handle = default_reply_handle;
1414 cur_test_run.eval_cb = default_eval_cb; 1623 cur_test_run.eval_cb = default_eval_cb;
1624 cur_test_run.have_churn = GNUNET_YES;
1415 churn_task = NULL; 1625 churn_task = NULL;
1416 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); 1626 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
1417 1627
@@ -1446,6 +1656,7 @@ main (int argc, char *argv[])
1446 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test single request\n"); 1656 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test single request\n");
1447 cur_test_run.name = "test-rps-single-req"; 1657 cur_test_run.name = "test-rps-single-req";
1448 cur_test_run.main_test = single_req_cb; 1658 cur_test_run.main_test = single_req_cb;
1659 cur_test_run.have_churn = GNUNET_NO;
1449 } 1660 }
1450 1661
1451 else if (strstr (argv[0], "_delayed_reqs") != NULL) 1662 else if (strstr (argv[0], "_delayed_reqs") != NULL)
@@ -1453,6 +1664,7 @@ main (int argc, char *argv[])
1453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test delayed requests\n"); 1664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test delayed requests\n");
1454 cur_test_run.name = "test-rps-delayed-reqs"; 1665 cur_test_run.name = "test-rps-delayed-reqs";
1455 cur_test_run.main_test = delay_req_cb; 1666 cur_test_run.main_test = delay_req_cb;
1667 cur_test_run.have_churn = GNUNET_NO;
1456 } 1668 }
1457 1669
1458 else if (strstr (argv[0], "_seed_big") != NULL) 1670 else if (strstr (argv[0], "_seed_big") != NULL)
@@ -1462,6 +1674,7 @@ main (int argc, char *argv[])
1462 cur_test_run.name = "test-rps-seed-big"; 1674 cur_test_run.name = "test-rps-seed-big";
1463 cur_test_run.main_test = seed_big_cb; 1675 cur_test_run.main_test = seed_big_cb;
1464 cur_test_run.eval_cb = no_eval; 1676 cur_test_run.eval_cb = no_eval;
1677 cur_test_run.have_churn = GNUNET_NO;
1465 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); 1678 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
1466 } 1679 }
1467 1680
@@ -1470,6 +1683,7 @@ main (int argc, char *argv[])
1470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on a single peer\n"); 1683 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on a single peer\n");
1471 cur_test_run.name = "test-rps-single-peer-seed"; 1684 cur_test_run.name = "test-rps-single-peer-seed";
1472 cur_test_run.main_test = single_peer_seed_cb; 1685 cur_test_run.main_test = single_peer_seed_cb;
1686 cur_test_run.have_churn = GNUNET_NO;
1473 } 1687 }
1474 1688
1475 else if (strstr (argv[0], "_seed_request") != NULL) 1689 else if (strstr (argv[0], "_seed_request") != NULL)
@@ -1477,6 +1691,7 @@ main (int argc, char *argv[])
1477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on multiple peers\n"); 1691 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on multiple peers\n");
1478 cur_test_run.name = "test-rps-seed-request"; 1692 cur_test_run.name = "test-rps-seed-request";
1479 cur_test_run.main_test = seed_req_cb; 1693 cur_test_run.main_test = seed_req_cb;
1694 cur_test_run.have_churn = GNUNET_NO;
1480 } 1695 }
1481 1696
1482 else if (strstr (argv[0], "_seed") != NULL) 1697 else if (strstr (argv[0], "_seed") != NULL)
@@ -1485,6 +1700,7 @@ main (int argc, char *argv[])
1485 cur_test_run.name = "test-rps-seed"; 1700 cur_test_run.name = "test-rps-seed";
1486 cur_test_run.main_test = seed_cb; 1701 cur_test_run.main_test = seed_cb;
1487 cur_test_run.eval_cb = no_eval; 1702 cur_test_run.eval_cb = no_eval;
1703 cur_test_run.have_churn = GNUNET_NO;
1488 } 1704 }
1489 1705
1490 else if (strstr (argv[0], "_req_cancel") != NULL) 1706 else if (strstr (argv[0], "_req_cancel") != NULL)
@@ -1494,6 +1710,20 @@ main (int argc, char *argv[])
1494 num_peers = 1; 1710 num_peers = 1;
1495 cur_test_run.main_test = req_cancel_cb; 1711 cur_test_run.main_test = req_cancel_cb;
1496 cur_test_run.eval_cb = no_eval; 1712 cur_test_run.eval_cb = no_eval;
1713 cur_test_run.have_churn = GNUNET_NO;
1714 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
1715 }
1716
1717 else if (strstr (argv[0], "_churn") != NULL)
1718 {
1719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test churn\n");
1720 cur_test_run.name = "test-rps-churn";
1721 num_peers = 5;
1722 cur_test_run.init_peer = default_init_peer;
1723 cur_test_run.main_test = churn_test_cb;
1724 cur_test_run.reply_handle = default_reply_handle;
1725 cur_test_run.eval_cb = default_eval_cb;
1726 cur_test_run.have_churn = GNUNET_YES;
1497 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); 1727 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
1498 } 1728 }
1499 1729
@@ -1510,6 +1740,7 @@ main (int argc, char *argv[])
1510 cur_test_run.eval_cb = profiler_eval; 1740 cur_test_run.eval_cb = profiler_eval;
1511 cur_test_run.request_interval = 2; 1741 cur_test_run.request_interval = 2;
1512 cur_test_run.num_requests = 5; 1742 cur_test_run.num_requests = 5;
1743 cur_test_run.have_churn = GNUNET_YES;
1513 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90); 1744 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90);
1514 1745
1515 /* 'Clean' directory */ 1746 /* 'Clean' directory */
@@ -1529,17 +1760,24 @@ main (int argc, char *argv[])
1529 with the malicious portion */ 1760 with the malicious portion */
1530 1761
1531 ok = 1; 1762 ok = 1;
1532 (void) GNUNET_TESTBED_test_run (cur_test_run.name, 1763 ret_value = GNUNET_TESTBED_test_run (cur_test_run.name,
1533 "test_rps.conf", 1764 "test_rps.conf",
1534 num_peers, 1765 num_peers,
1535 0, NULL, NULL, 1766 0, NULL, NULL,
1536 &run, NULL); 1767 &run, NULL);
1768 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1769 "_test_run returned.\n");
1770 if (GNUNET_OK != ret_value)
1771 {
1772 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1773 "Test did not run successfully!\n");
1774 }
1537 1775
1538 ret_value = cur_test_run.eval_cb(); 1776 ret_value = cur_test_run.eval_cb();
1539 GNUNET_free (rps_peers ); 1777 GNUNET_free (rps_peers);
1540 GNUNET_free (rps_peer_ids); 1778 GNUNET_free (rps_peer_ids);
1541 GNUNET_CONTAINER_multipeermap_destroy (peer_map); 1779 GNUNET_CONTAINER_multipeermap_destroy (peer_map);
1542 return ret_value; 1780 return ret_value;
1543} 1781}
1544 1782
1545/* end of test_rps_multipeer.c */ 1783/* end of test_rps.c */
diff --git a/src/rps/test_rps.conf b/src/rps/test_rps.conf
index 7da91ccf0..fce07c945 100644
--- a/src/rps/test_rps.conf
+++ b/src/rps/test_rps.conf
@@ -24,16 +24,16 @@ INITSIZE = 4
24[testbed] 24[testbed]
25HOSTNAME = localhost 25HOSTNAME = localhost
26 26
27OPERATION_TIMEOUT = 60 s 27# OPERATION_TIMEOUT = 60 s
28 28
29MAX_PARALLEL_TOPOLOGY_CONFIG_OPERATIONS = 1 29# MAX_PARALLEL_TOPOLOGY_CONFIG_OPERATIONS = 100
30#OVERLAY_TOPOLOGY = CLIQUE 30OVERLAY_TOPOLOGY = CLIQUE
31OVERLAY_TOPOLOGY = SMALL_WORLD 31#OVERLAY_TOPOLOGY = SMALL_WORLD
32#SCALE_FREE_TOPOLOGY_CAP = 32#SCALE_FREE_TOPOLOGY_CAP =
33 33
34OVERLAY_RANDOM_LINKS = 25 34# OVERLAY_RANDOM_LINKS = 25
35 35
36SETUP_TIMEOUT = 2 m 36# SETUP_TIMEOUT = 2 m
37 37
38[nse] 38[nse]
39WORKBITS = 0 39WORKBITS = 0
@@ -46,7 +46,27 @@ USE_LOCALADDR = YES
46RETURN_LOCAL_ADDRESSES = YES 46RETURN_LOCAL_ADDRESSES = YES
47 47
48[transport] 48[transport]
49PLUGINS = unix 49PLUGINS = udp
50
51[ats]
52# Network specific inbound/outbound quotas
53UNSPECIFIED_QUOTA_IN = unlimited
54UNSPECIFIED_QUOTA_OUT = unlimited
55# LOOPBACK
56LOOPBACK_QUOTA_IN = unlimited
57LOOPBACK_QUOTA_OUT = unlimited
58# LAN
59LAN_QUOTA_IN = unlimited
60LAN_QUOTA_OUT = unlimited
61#WAN
62WAN_QUOTA_OUT = unlimited
63WAN_QUOTA_IN = unlimited
64# WLAN
65WLAN_QUOTA_IN = unlimited
66WLAN_QUOTA_OUT = unlimited
67# BLUETOOTH
68BLUETOOTH_QUOTA_IN = unlimited
69BLUETOOTH_QUOTA_OUT = unlimited
50 70
51[dht] 71[dht]
52DISABLE_TRY_CONNECT = YES 72DISABLE_TRY_CONNECT = YES
@@ -69,6 +89,10 @@ NO_IO = YES
69FORCESTART = NO 89FORCESTART = NO
70AUTOSTART = NO 90AUTOSTART = NO
71 91
92[zonemaster]
93FORCESTART = NO
94AUTOSTART = NO
95
72[namecache] 96[namecache]
73FORCESTART = NO 97FORCESTART = NO
74AUTOSTART = NO 98AUTOSTART = NO
diff --git a/src/rps/test_service_rps_peers.c b/src/rps/test_service_rps_peers.c
deleted file mode 100644
index 9cd677fef..000000000
--- a/src/rps/test_service_rps_peers.c
+++ /dev/null
@@ -1,137 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20/**
21 * @file rps/test_service_rps_peers.c
22 * @brief testcase for gnunet-service-rps_peers.c
23 */
24#include <platform.h>
25#include "gnunet-service-rps_peers.h"
26
27#define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); Peers_terminate (); return 1; }
28#define CHECK(c) { if (! (c)) ABORT(); }
29
30#define FN_VALID_PEERS "DISABLE"
31
32/**
33 * @brief Dummy implementation of #PeerOp (Operation on peer)
34 *
35 * @param cls closure
36 * @param peer peer
37 */
38void peer_op (void *cls, const struct GNUNET_PeerIdentity *peer)
39{
40 GNUNET_assert (NULL != peer);
41}
42
43/**
44 * @brief Function that is called on a peer for later execution
45 *
46 * @param cls closure
47 * @param peer peer to execute function upon
48 */
49void
50peer_op (void *cls, const struct GNUNET_PeerIdentity *peer);
51
52static int
53check ()
54{
55 struct GNUNET_PeerIdentity k1;
56 struct GNUNET_PeerIdentity own_id;
57
58 memset (&k1, 0, sizeof (k1));
59 memset (&own_id, 1, sizeof (own_id));
60
61 /* Do nothing */
62 Peers_initialise (FN_VALID_PEERS, NULL, NULL, NULL, &own_id);
63 Peers_terminate ();
64
65
66 /* Create peer */
67 Peers_initialise (FN_VALID_PEERS, NULL, NULL, NULL, &own_id);
68 CHECK (GNUNET_YES == Peers_insert_peer (&k1));
69 Peers_terminate ();
70
71
72 /* Create peer */
73 Peers_initialise (FN_VALID_PEERS, NULL, NULL, NULL, &own_id);
74 CHECK (GNUNET_YES == Peers_insert_peer (&k1));
75 CHECK (GNUNET_YES == Peers_remove_peer (&k1));
76 Peers_terminate ();
77
78
79 /* Insertion and Removal */
80 Peers_initialise (FN_VALID_PEERS, NULL, NULL, NULL, &own_id);
81 CHECK (GNUNET_NO == Peers_check_peer_known (&k1));
82
83 CHECK (GNUNET_YES == Peers_insert_peer (&k1));
84 CHECK (GNUNET_NO == Peers_insert_peer (&k1));
85 CHECK (GNUNET_YES == Peers_check_peer_known (&k1));
86
87 CHECK (GNUNET_YES == Peers_remove_peer (&k1));
88 CHECK (GNUNET_NO == Peers_remove_peer (&k1));
89 CHECK (GNUNET_NO == Peers_check_peer_known (&k1));
90
91
92 /* Flags */
93 Peers_insert_peer (&k1);
94
95 CHECK (GNUNET_NO == Peers_check_peer_flag (&k1, Peers_PULL_REPLY_PENDING));
96 CHECK (GNUNET_NO == Peers_check_peer_flag (&k1, Peers_ONLINE));
97 CHECK (GNUNET_NO == Peers_check_peer_flag (&k1, Peers_TO_DESTROY));
98
99 CHECK (GNUNET_NO == Peers_check_peer_flag (&k1, Peers_ONLINE));
100
101 Peers_set_peer_flag (&k1, Peers_ONLINE);
102 CHECK (GNUNET_YES == Peers_check_peer_flag (&k1, Peers_ONLINE));
103 CHECK (GNUNET_NO == Peers_check_peer_flag (&k1, Peers_TO_DESTROY));
104 CHECK (GNUNET_YES == Peers_check_peer_flag (&k1, Peers_ONLINE));
105 CHECK (GNUNET_NO == Peers_check_peer_flag (&k1, Peers_TO_DESTROY));
106
107 /* Check send intention */
108 CHECK (GNUNET_NO == Peers_check_peer_send_intention (&k1));
109
110 /* Check existence of sending channel */
111 CHECK (GNUNET_NO == Peers_check_sending_channel_exists (&k1));
112
113 /* Check role of channels */
114 CHECK (GNUNET_YES == Peers_check_channel_role (&k1,
115 NULL,
116 Peers_CHANNEL_ROLE_SENDING));
117 CHECK (GNUNET_YES == Peers_check_channel_role (&k1,
118 NULL,
119 Peers_CHANNEL_ROLE_RECEIVING));
120
121 CHECK (GNUNET_YES == Peers_schedule_operation (&k1, peer_op));
122
123 Peers_terminate ();
124 return 0;
125}
126
127
128int
129main (int argc, char *argv[])
130{
131 GNUNET_log_setup ("test_service_rps_peers",
132 "WARNING",
133 NULL);
134 return check ();
135}
136
137/* end of test_service_rps_peers.c */
diff --git a/src/set/Makefile.am b/src/set/Makefile.am
index 14667d0ef..df17fa1ab 100644
--- a/src/set/Makefile.am
+++ b/src/set/Makefile.am
@@ -52,7 +52,7 @@ gnunet_set_ibf_profiler_LDADD = \
52gnunet_service_set_SOURCES = \ 52gnunet_service_set_SOURCES = \
53 gnunet-service-set.c gnunet-service-set.h \ 53 gnunet-service-set.c gnunet-service-set.h \
54 gnunet-service-set_union.c gnunet-service-set_union.h \ 54 gnunet-service-set_union.c gnunet-service-set_union.h \
55 gnunet-service-set_intersection.c \ 55 gnunet-service-set_intersection.c gnunet-service-set_intersection.h \
56 ibf.c ibf.h \ 56 ibf.c ibf.h \
57 gnunet-service-set_union_strata_estimator.c gnunet-service-set_union_strata_estimator.h \ 57 gnunet-service-set_union_strata_estimator.c gnunet-service-set_union_strata_estimator.h \
58 gnunet-service-set_protocol.h 58 gnunet-service-set_protocol.h
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c
index 730124495..219cc6235 100644
--- a/src/set/gnunet-service-set_union.c
+++ b/src/set/gnunet-service-set_union.c
@@ -364,7 +364,7 @@ fail_union_operation (struct Operation *op)
364 struct GNUNET_MQ_Envelope *ev; 364 struct GNUNET_MQ_Envelope *ev;
365 struct GNUNET_SET_ResultMessage *msg; 365 struct GNUNET_SET_ResultMessage *msg;
366 366
367 LOG (GNUNET_ERROR_TYPE_ERROR, 367 LOG (GNUNET_ERROR_TYPE_WARNING,
368 "union operation failed\n"); 368 "union operation failed\n");
369 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_RESULT); 369 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_RESULT);
370 msg->result_status = htons (GNUNET_SET_STATUS_FAILURE); 370 msg->result_status = htons (GNUNET_SET_STATUS_FAILURE);
@@ -389,10 +389,11 @@ get_ibf_key (const struct GNUNET_HashCode *src)
389 struct IBF_Key key; 389 struct IBF_Key key;
390 uint16_t salt = 0; 390 uint16_t salt = 0;
391 391
392 GNUNET_CRYPTO_kdf (&key, sizeof (key), 392 GNUNET_assert (GNUNET_OK ==
393 src, sizeof *src, 393 GNUNET_CRYPTO_kdf (&key, sizeof (key),
394 &salt, sizeof (salt), 394 src, sizeof *src,
395 NULL, 0); 395 &salt, sizeof (salt),
396 NULL, 0));
396 return key; 397 return key;
397} 398}
398 399
@@ -1404,7 +1405,7 @@ send_client_done (void *cls)
1404 } 1405 }
1405 1406
1406 if (PHASE_DONE != op->state->phase) { 1407 if (PHASE_DONE != op->state->phase) {
1407 LOG (GNUNET_ERROR_TYPE_ERROR, 1408 LOG (GNUNET_ERROR_TYPE_WARNING,
1408 "union operation failed\n"); 1409 "union operation failed\n");
1409 ev = GNUNET_MQ_msg (rm, GNUNET_MESSAGE_TYPE_SET_RESULT); 1410 ev = GNUNET_MQ_msg (rm, GNUNET_MESSAGE_TYPE_SET_RESULT);
1410 rm->result_status = htons (GNUNET_SET_STATUS_FAILURE); 1411 rm->result_status = htons (GNUNET_SET_STATUS_FAILURE);
diff --git a/src/set/set_api.c b/src/set/set_api.c
index 1d0d00b44..cefc6734a 100644
--- a/src/set/set_api.c
+++ b/src/set/set_api.c
@@ -695,6 +695,7 @@ GNUNET_SET_add_element (struct GNUNET_SET_Handle *set,
695 "adding element of type %u to set %p\n", 695 "adding element of type %u to set %p\n",
696 (unsigned int) element->element_type, 696 (unsigned int) element->element_type,
697 set); 697 set);
698 GNUNET_assert (NULL != set);
698 if (GNUNET_YES == set->invalid) 699 if (GNUNET_YES == set->invalid)
699 { 700 {
700 if (NULL != cont) 701 if (NULL != cont)
@@ -772,6 +773,7 @@ GNUNET_SET_destroy (struct GNUNET_SET_Handle *set)
772 /* destroying set while iterator is active is currently 773 /* destroying set while iterator is active is currently
773 not supported; we should expand the API to allow 774 not supported; we should expand the API to allow
774 clients to explicitly cancel the iteration! */ 775 clients to explicitly cancel the iteration! */
776 GNUNET_assert (NULL != set);
775 if ( (NULL != set->ops_head) || 777 if ( (NULL != set->ops_head) ||
776 (NULL != set->iterator) || 778 (NULL != set->iterator) ||
777 (GNUNET_SYSERR == set->destroy_requested) ) 779 (GNUNET_SYSERR == set->destroy_requested) )
@@ -1124,11 +1126,12 @@ GNUNET_SET_commit (struct GNUNET_SET_OperationHandle *oh,
1124{ 1126{
1125 if (NULL != oh->set) 1127 if (NULL != oh->set)
1126 { 1128 {
1127 /* Some other set was already commited for this 1129 /* Some other set was already committed for this
1128 * operation, there is a logic bug in the client of this API */ 1130 * operation, there is a logic bug in the client of this API */
1129 GNUNET_break (0); 1131 GNUNET_break (0);
1130 return GNUNET_OK; 1132 return GNUNET_OK;
1131 } 1133 }
1134 GNUNET_assert (NULL != set);
1132 if (GNUNET_YES == set->invalid) 1135 if (GNUNET_YES == set->invalid)
1133 return GNUNET_SYSERR; 1136 return GNUNET_SYSERR;
1134 LOG (GNUNET_ERROR_TYPE_DEBUG, 1137 LOG (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/social/gnunet-service-social.c b/src/social/gnunet-service-social.c
index dee68fdb8..31e3a3dc2 100644
--- a/src/social/gnunet-service-social.c
+++ b/src/social/gnunet-service-social.c
@@ -96,7 +96,7 @@ static struct GNUNET_CONTAINER_MultiHashMap *apps_places;
96 * Application subscriptions per place. 96 * Application subscriptions per place.
97 * H(place_pub_key) -> H(app_id) 97 * H(place_pub_key) -> H(app_id)
98 */ 98 */
99static struct GNUNET_CONTAINER_MultiHashMap *places_apps; 99//static struct GNUNET_CONTAINER_MultiHashMap *places_apps;
100 100
101/** 101/**
102 * Connected applications. 102 * Connected applications.
@@ -255,10 +255,10 @@ struct Place
255 uint8_t is_ready; 255 uint8_t is_ready;
256 256
257 /** 257 /**
258 * Is the client disconnected? 258 * Is the client disconnecting?
259 * #GNUNET_YES or #GNUNET_NO 259 * #GNUNET_YES or #GNUNET_NO
260 */ 260 */
261 uint8_t is_disconnected; 261 uint8_t is_disconnecting;
262 262
263 /** 263 /**
264 * Is this a host (#GNUNET_YES), or guest (#GNUNET_NO)? 264 * Is this a host (#GNUNET_YES), or guest (#GNUNET_NO)?
@@ -348,7 +348,7 @@ struct Guest
348 /** 348 /**
349 * Join request to be transmitted to the master on join. 349 * Join request to be transmitted to the master on join.
350 */ 350 */
351 struct GNUNET_MessageHeader *join_req; 351 struct GNUNET_MessageHeader *join_req; // FIXME: not used!
352 352
353 /** 353 /**
354 * Join decision received from PSYC. 354 * Join decision received from PSYC.
@@ -487,8 +487,6 @@ cleanup_host (struct Host *hst)
487{ 487{
488 struct Place *plc = &hst->place; 488 struct Place *plc = &hst->place;
489 489
490 if (NULL != hst->master)
491 GNUNET_PSYC_master_stop (hst->master, GNUNET_NO, NULL, NULL); // FIXME
492 GNUNET_CONTAINER_multihashmap_destroy (hst->join_reqs); 490 GNUNET_CONTAINER_multihashmap_destroy (hst->join_reqs);
493 GNUNET_CONTAINER_multihashmap_destroy (hst->relay_msgs); 491 GNUNET_CONTAINER_multihashmap_destroy (hst->relay_msgs);
494 GNUNET_CONTAINER_multihashmap_remove (hosts, &plc->pub_key_hash, plc); 492 GNUNET_CONTAINER_multihashmap_remove (hosts, &plc->pub_key_hash, plc);
@@ -505,23 +503,22 @@ cleanup_guest (struct Guest *gst)
505 struct GNUNET_CONTAINER_MultiHashMap * 503 struct GNUNET_CONTAINER_MultiHashMap *
506 plc_gst = GNUNET_CONTAINER_multihashmap_get (place_guests, 504 plc_gst = GNUNET_CONTAINER_multihashmap_get (place_guests,
507 &plc->pub_key_hash); 505 &plc->pub_key_hash);
508 GNUNET_assert (NULL != plc_gst); // FIXME 506 if (NULL != plc_gst)
509 GNUNET_CONTAINER_multihashmap_remove (plc_gst, &plc->ego_pub_hash, gst);
510
511 if (0 == GNUNET_CONTAINER_multihashmap_size (plc_gst))
512 { 507 {
513 GNUNET_CONTAINER_multihashmap_remove (place_guests, &plc->pub_key_hash, 508 GNUNET_CONTAINER_multihashmap_remove (plc_gst, &plc->ego_pub_hash, gst);
514 plc_gst); 509
515 GNUNET_CONTAINER_multihashmap_destroy (plc_gst); 510 if (0 == GNUNET_CONTAINER_multihashmap_size (plc_gst))
511 {
512 GNUNET_CONTAINER_multihashmap_remove (place_guests, &plc->pub_key_hash,
513 plc_gst);
514 GNUNET_CONTAINER_multihashmap_destroy (plc_gst);
515 }
516 } 516 }
517 GNUNET_CONTAINER_multihashmap_remove (guests, &plc->pub_key_hash, gst); 517 GNUNET_CONTAINER_multihashmap_remove (guests, &plc->pub_key_hash, gst);
518
519 if (NULL != gst->join_req) 518 if (NULL != gst->join_req)
520 GNUNET_free (gst->join_req); 519 GNUNET_free (gst->join_req);
521 if (NULL != gst->relays) 520 if (NULL != gst->relays)
522 GNUNET_free (gst->relays); 521 GNUNET_free (gst->relays);
523 if (NULL != gst->slave)
524 GNUNET_PSYC_slave_part (gst->slave, GNUNET_NO, NULL, NULL); // FIXME
525 GNUNET_CONTAINER_multihashmap_remove (guests, &plc->pub_key_hash, plc); 522 GNUNET_CONTAINER_multihashmap_remove (guests, &plc->pub_key_hash, plc);
526} 523}
527 524
@@ -537,8 +534,8 @@ cleanup_place (void *cls)
537 struct Place *plc = cls; 534 struct Place *plc = cls;
538 535
539 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
540 "%p Cleaning up place %s\n", 537 "cleaning up place %s\n",
541 plc, GNUNET_h2s (&plc->pub_key_hash)); 538 GNUNET_h2s (&plc->pub_key_hash));
542 539
543 (GNUNET_YES == plc->is_host) 540 (GNUNET_YES == plc->is_host)
544 ? cleanup_host ((struct Host *) plc) 541 ? cleanup_host ((struct Host *) plc)
@@ -583,12 +580,19 @@ client_notify_disconnect (void *cls,
583 { 580 {
584 if (cli->client == client) 581 if (cli->client == client)
585 { 582 {
586 GNUNET_CONTAINER_DLL_remove (plc->clients_head, plc->clients_tail, cli); 583 GNUNET_CONTAINER_DLL_remove (plc->clients_head,
584 plc->clients_tail,
585 cli);
587 GNUNET_free (cli); 586 GNUNET_free (cli);
588 break; 587 break;
589 } 588 }
590 cli = cli->next; 589 cli = cli->next;
591 } 590 }
591 if (GNUNET_YES == plc->is_disconnecting)
592 {
593 GNUNET_PSYC_slicer_destroy (plc->slicer);
594 GNUNET_free (plc);
595 }
592} 596}
593 597
594 598
@@ -605,46 +609,55 @@ client_notify_connect (void *cls,
605 struct GNUNET_SERVICE_Client *client, 609 struct GNUNET_SERVICE_Client *client,
606 struct GNUNET_MQ_Handle *mq) 610 struct GNUNET_MQ_Handle *mq)
607{ 611{
608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client connected: %p\n", client); 612 struct Client *c = GNUNET_new (struct Client);
609 613
610 struct Client *c = GNUNET_malloc (sizeof (*c)); 614 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
615 "Client %p connected with queue %p\n",
616 client,
617 mq);
611 c->client = client; 618 c->client = client;
612
613 return c; 619 return c;
614} 620}
615 621
616 622
617/** 623/**
618 * Send message to a client. 624 * Send message to all clients connected to a place and
619 */ 625 * takes care of freeing @env.
620static inline void
621client_send_msg (struct GNUNET_SERVICE_Client *client,
622 const struct GNUNET_MessageHeader *msg)
623{
624 struct GNUNET_MQ_Envelope *
625 env = GNUNET_MQ_msg_copy (msg);
626
627 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
628 env);
629}
630
631
632/**
633 * Send message to all clients connected to a place.
634 */ 626 */
635static void 627static void
636place_send_msg (const struct Place *plc, 628place_send_msg (const struct Place *plc,
637 const struct GNUNET_MessageHeader *msg) 629 struct GNUNET_MQ_Envelope *env)
638{ 630{
631 struct ClientListItem *cli = plc->clients_head;
632
639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 633 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
640 "%p Sending message to clients of place.\n", plc); 634 "%p Sending message to clients of place.\n", plc);
641
642 struct ClientListItem *cli = plc->clients_head;
643 while (NULL != cli) 635 while (NULL != cli)
644 { 636 {
645 client_send_msg (cli->client, msg); 637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
638 "Sending message to client %p\n",
639 cli);
640 GNUNET_MQ_send_copy (GNUNET_SERVICE_client_get_mq (cli->client),
641 env);
646 cli = cli->next; 642 cli = cli->next;
647 } 643 }
644 GNUNET_MQ_discard (env);
645}
646
647
648static void
649place_send_leave_ack (struct Place *plc)
650{
651 struct GNUNET_MQ_Envelope *env;
652
653 for (struct ClientListItem *cli = plc->clients_head;
654 NULL != cli;
655 cli = cli->next)
656 {
657 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE_ACK);
658 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cli->client),
659 env);
660 }
648} 661}
649 662
650 663
@@ -666,23 +679,21 @@ static void
666client_send_result (struct GNUNET_SERVICE_Client *client, uint64_t op_id, 679client_send_result (struct GNUNET_SERVICE_Client *client, uint64_t op_id,
667 int64_t result_code, const void *data, uint16_t data_size) 680 int64_t result_code, const void *data, uint16_t data_size)
668{ 681{
682 struct GNUNET_MQ_Envelope *env;
669 struct GNUNET_OperationResultMessage *res; 683 struct GNUNET_OperationResultMessage *res;
670 684
671 res = GNUNET_malloc (sizeof (*res) + data_size); 685 env = GNUNET_MQ_msg_extra (res,
672 res->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_RESULT_CODE); 686 data_size,
673 res->header.size = htons (sizeof (*res) + data_size); 687 GNUNET_MESSAGE_TYPE_PSYC_RESULT_CODE);
674 res->result_code = GNUNET_htonll (result_code); 688 res->result_code = GNUNET_htonll (result_code);
675 res->op_id = op_id; 689 res->op_id = op_id;
676 if (0 < data_size) 690 if (0 < data_size)
677 GNUNET_memcpy (&res[1], data, data_size); 691 GNUNET_memcpy (&res[1], data, data_size);
678
679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
680 "%p Sending result to client for operation #%" PRIu64 ": " 693 "%p Sending result to client for operation #%" PRIu64 ": "
681 "%" PRId64 " (size: %u)\n", 694 "%" PRId64 " (size: %u)\n",
682 client, GNUNET_ntohll (op_id), result_code, data_size); 695 client, GNUNET_ntohll (op_id), result_code, data_size);
683 696 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
684 client_send_msg (client, &res->header);
685 GNUNET_free (res);
686} 697}
687 698
688 699
@@ -690,19 +701,21 @@ static void
690client_send_host_enter_ack (struct GNUNET_SERVICE_Client *client, 701client_send_host_enter_ack (struct GNUNET_SERVICE_Client *client,
691 struct Host *hst, uint32_t result) 702 struct Host *hst, uint32_t result)
692{ 703{
704 struct GNUNET_MQ_Envelope *env;
705 struct HostEnterAck *hack;
693 struct Place *plc = &hst->place; 706 struct Place *plc = &hst->place;
694 707
695 struct HostEnterAck hack; 708 env = GNUNET_MQ_msg (hack,
696 hack.header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER_ACK); 709 GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER_ACK);
697 hack.header.size = htons (sizeof (hack)); 710 hack->result_code = htonl (result);
698 hack.result_code = htonl (result); 711 hack->max_message_id = GNUNET_htonll (plc->max_message_id);
699 hack.max_message_id = GNUNET_htonll (plc->max_message_id); 712 hack->place_pub_key = plc->pub_key;
700 hack.place_pub_key = plc->pub_key;
701 713
702 if (NULL != client) 714 if (NULL != client)
703 client_send_msg (client, &hack.header); 715 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
716 env);
704 else 717 else
705 place_send_msg (plc, &hack.header); 718 place_send_msg (plc, env);
706} 719}
707 720
708 721
@@ -736,7 +749,8 @@ psyc_recv_join_request (void *cls,
736 GNUNET_CRYPTO_hash (slave_key, sizeof (*slave_key), &slave_key_hash); 749 GNUNET_CRYPTO_hash (slave_key, sizeof (*slave_key), &slave_key_hash);
737 GNUNET_CONTAINER_multihashmap_put (hst->join_reqs, &slave_key_hash, jh, 750 GNUNET_CONTAINER_multihashmap_put (hst->join_reqs, &slave_key_hash, jh,
738 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 751 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
739 place_send_msg (&hst->place, &req->header); 752 place_send_msg (&hst->place,
753 GNUNET_MQ_msg_copy (&req->header));
740} 754}
741 755
742 756
@@ -746,18 +760,29 @@ psyc_recv_join_request (void *cls,
746static void 760static void
747psyc_slave_connected (void *cls, int result, uint64_t max_message_id) 761psyc_slave_connected (void *cls, int result, uint64_t max_message_id)
748{ 762{
763 struct GNUNET_PSYC_CountersResultMessage *res;
764 struct GNUNET_MQ_Envelope *env;
749 struct Guest *gst = cls; 765 struct Guest *gst = cls;
750 struct Place *plc = &gst->place; 766 struct Place *plc = &gst->place;
767
751 plc->max_message_id = max_message_id; 768 plc->max_message_id = max_message_id;
752 plc->is_ready = GNUNET_YES; 769 plc->is_ready = GNUNET_YES;
770 env = GNUNET_MQ_msg (res,
771 GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER_ACK);
772 res->result_code =
773 (result != GNUNET_SYSERR) ? htonl (GNUNET_OK) : htonl (GNUNET_SYSERR);
774 res->max_message_id = GNUNET_htonll (plc->max_message_id);
775 place_send_msg (plc, env);
776}
753 777
754 struct GNUNET_PSYC_CountersResultMessage res;
755 res.header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER_ACK);
756 res.header.size = htons (sizeof (res));
757 res.result_code = htonl (result);
758 res.max_message_id = GNUNET_htonll (plc->max_message_id);
759 778
760 place_send_msg (plc, &res.header); 779static void
780slave_parted_after_join_decision (void *cls)
781{
782 struct Guest *gst = cls;
783
784 GNUNET_assert (NULL != gst->join_dcsn);
785 place_send_msg (&gst->place, GNUNET_MQ_msg_copy (&gst->join_dcsn->header));
761} 786}
762 787
763 788
@@ -771,7 +796,21 @@ psyc_recv_join_dcsn (void *cls,
771 const struct GNUNET_PSYC_Message *join_msg) 796 const struct GNUNET_PSYC_Message *join_msg)
772{ 797{
773 struct Guest *gst = cls; 798 struct Guest *gst = cls;
774 place_send_msg (&gst->place, &dcsn->header); 799
800 gst->join_dcsn = GNUNET_malloc (dcsn->header.size);
801 GNUNET_memcpy (gst->join_dcsn,
802 dcsn,
803 dcsn->header.size);
804 if (GNUNET_NO == is_admitted)
805 {
806 GNUNET_PSYC_slave_part (gst->slave,
807 GNUNET_NO,
808 &slave_parted_after_join_decision,
809 gst);
810 gst->slave = NULL;
811 return;
812 }
813 place_send_msg (&gst->place, GNUNET_MQ_msg_copy (&gst->join_dcsn->header));
775} 814}
776 815
777 816
@@ -792,7 +831,7 @@ psyc_recv_message (void *cls,
792 831
793 GNUNET_PSYC_slicer_message (plc->slicer, msg); 832 GNUNET_PSYC_slicer_message (plc->slicer, msg);
794 833
795 place_send_msg (plc, &msg->header); 834 place_send_msg (plc, GNUNET_MQ_msg_copy (&msg->header));
796} 835}
797 836
798 837
@@ -1096,9 +1135,6 @@ place_init (struct Place *plc)
1096static int 1135static int
1097place_add (const struct PlaceEnterRequest *ereq) 1136place_add (const struct PlaceEnterRequest *ereq)
1098{ 1137{
1099 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1100 "Adding place to hashmap:\n");
1101
1102 struct EgoPlacePublicKey ego_place_pub_key = { 1138 struct EgoPlacePublicKey ego_place_pub_key = {
1103 .ego_pub_key = ereq->ego_pub_key, 1139 .ego_pub_key = ereq->ego_pub_key,
1104 .place_pub_key = ereq->place_pub_key, 1140 .place_pub_key = ereq->place_pub_key,
@@ -1173,7 +1209,9 @@ app_place_add (const char *app_id,
1173 return GNUNET_NO; 1209 return GNUNET_NO;
1174 1210
1175 if (GNUNET_SYSERR == place_add (ereq)) 1211 if (GNUNET_SYSERR == place_add (ereq))
1212 {
1176 return GNUNET_SYSERR; 1213 return GNUNET_SYSERR;
1214 }
1177 1215
1178 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (app_places, &ego_place_pub_hash, NULL, 1216 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (app_places, &ego_place_pub_hash, NULL,
1179 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) 1217 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
@@ -1181,32 +1219,6 @@ app_place_add (const char *app_id,
1181 GNUNET_break (0); 1219 GNUNET_break (0);
1182 return GNUNET_SYSERR; 1220 return GNUNET_SYSERR;
1183 } 1221 }
1184
1185 struct GNUNET_HashCode place_pub_hash;
1186 GNUNET_CRYPTO_hash (&ereq->place_pub_key, sizeof (ereq->place_pub_key), &place_pub_hash);
1187
1188 struct GNUNET_CONTAINER_MultiHashMap *
1189 place_apps = GNUNET_CONTAINER_multihashmap_get (places_apps, &place_pub_hash);
1190 if (NULL == place_apps)
1191 {
1192 place_apps = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
1193 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (places_apps, &place_pub_hash, place_apps,
1194 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
1195 {
1196 GNUNET_break (0);
1197 }
1198 }
1199
1200 size_t app_id_size = strlen (app_id) + 1;
1201 void *app_id_value = GNUNET_malloc (app_id_size);
1202 GNUNET_memcpy (app_id_value, app_id, app_id_size);
1203
1204 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (place_apps, &app_id_hash, app_id_value,
1205 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1206 {
1207 GNUNET_break (0);
1208 }
1209
1210 return GNUNET_OK; 1222 return GNUNET_OK;
1211} 1223}
1212 1224
@@ -1223,7 +1235,10 @@ static int
1223app_place_save (const char *app_id, 1235app_place_save (const char *app_id,
1224 const struct PlaceEnterRequest *ereq) 1236 const struct PlaceEnterRequest *ereq)
1225{ 1237{
1226 app_place_add (app_id, ereq); 1238 if (GNUNET_SYSERR == app_place_add (app_id, ereq))
1239 {
1240 GNUNET_assert (0);
1241 }
1227 1242
1228 if (NULL == dir_places) 1243 if (NULL == dir_places)
1229 return GNUNET_SYSERR; 1244 return GNUNET_SYSERR;
@@ -1304,18 +1319,6 @@ app_place_remove (const char *app_id,
1304 if (NULL != app_places) 1319 if (NULL != app_places)
1305 GNUNET_CONTAINER_multihashmap_remove (app_places, &place_pub_hash, NULL); 1320 GNUNET_CONTAINER_multihashmap_remove (app_places, &place_pub_hash, NULL);
1306 1321
1307 struct GNUNET_CONTAINER_MultiHashMap *
1308 place_apps = GNUNET_CONTAINER_multihashmap_get (places_apps, &place_pub_hash);
1309 if (NULL != place_apps)
1310 {
1311 void *app_id_value = GNUNET_CONTAINER_multihashmap_get (place_apps, &app_id_hash);
1312 if (NULL != app_id_value)
1313 {
1314 GNUNET_CONTAINER_multihashmap_remove (place_apps, &app_id_hash, app_id_value);
1315 GNUNET_free (app_id_value);
1316 }
1317 }
1318
1319 int ret = GNUNET_OK; 1322 int ret = GNUNET_OK;
1320 1323
1321 if (0 != unlink (app_place_filename)) 1324 if (0 != unlink (app_place_filename))
@@ -1389,24 +1392,150 @@ msg_proc_parse (const struct MsgProcRequest *mpreq,
1389 const char **method_prefix, 1392 const char **method_prefix,
1390 struct GNUNET_HashCode *method_hash) 1393 struct GNUNET_HashCode *method_hash)
1391{ 1394{
1392 uint8_t method_size = ntohs (mpreq->header.size) - sizeof (*mpreq); 1395 ssize_t method_size = ntohs (mpreq->header.size) - sizeof (*mpreq);
1393 uint16_t offset = GNUNET_STRINGS_buffer_tokenize ((const char *) &mpreq[1], 1396 uint16_t offset;
1394 method_size, 1, method_prefix);
1395 1397
1396 if (0 == offset || offset != method_size || *method_prefix == NULL) 1398 if (method_size < 0)
1397 { 1399 {
1398 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1400 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1399 "offset = %u, method_size = %u, method_name = %s\n", 1401 "MsgProcRequest has invalid size\n");
1400 offset, method_size, *method_prefix);
1401 return GNUNET_SYSERR; 1402 return GNUNET_SYSERR;
1402 } 1403 }
1403 1404
1404 GNUNET_CRYPTO_hash (*method_prefix, method_size, method_hash); 1405 offset = GNUNET_STRINGS_buffer_tokenize ((const char *) &mpreq[1],
1406 method_size,
1407 1,
1408 method_prefix);
1409 if (0 == offset || offset != method_size || *method_prefix == NULL)
1410 {
1411 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1412 "MsgProcRequest contains invalid method\n");
1413 return GNUNET_SYSERR;
1414 }
1415 GNUNET_CRYPTO_hash (*method_prefix, (size_t) method_size, method_hash);
1405 *flags = ntohl (mpreq->flags); 1416 *flags = ntohl (mpreq->flags);
1406 return GNUNET_OK; 1417 return GNUNET_OK;
1407} 1418}
1408 1419
1409 1420
1421void
1422app_notify_place (const struct GNUNET_MessageHeader *msg,
1423 struct GNUNET_SERVICE_Client *client)
1424{
1425 struct AppPlaceMessage *amsg;
1426 struct GNUNET_MQ_Envelope *env;
1427 uint16_t msg_size = ntohs (msg->size);
1428
1429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1430 "%p Sending place notification of type %u to client.\n",
1431 client, ntohs (msg->type));
1432 switch (ntohs (msg->type))
1433 {
1434 case GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER:
1435 {
1436 struct HostEnterRequest *hreq = (struct HostEnterRequest *) msg;
1437 if (msg_size < sizeof (struct HostEnterRequest))
1438 return;
1439 env = GNUNET_MQ_msg (amsg,
1440 GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE);
1441 // FIXME: also notify about not entered places
1442 amsg->place_state = GNUNET_SOCIAL_PLACE_STATE_ENTERED;
1443 amsg->is_host = GNUNET_YES;
1444 amsg->ego_pub_key = hreq->ego_pub_key;
1445 amsg->place_pub_key = hreq->place_pub_key;
1446 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1447 env);
1448 break;
1449 }
1450 case GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER:
1451 {
1452 if (msg_size < sizeof (struct GuestEnterRequest))
1453 return;
1454 struct GuestEnterRequest *greq = (struct GuestEnterRequest *) msg;
1455 env = GNUNET_MQ_msg (amsg,
1456 GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE);
1457 // FIXME: also notify about not entered places
1458 amsg->place_state = GNUNET_SOCIAL_PLACE_STATE_ENTERED;
1459 amsg->is_host = GNUNET_NO;
1460 amsg->ego_pub_key = greq->ego_pub_key;
1461 amsg->place_pub_key = greq->place_pub_key;
1462 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1463 env);
1464 break;
1465 }
1466 default:
1467 return;
1468 }
1469}
1470
1471
1472void
1473app_notify_place_end (struct GNUNET_SERVICE_Client *client)
1474{
1475 struct GNUNET_MQ_Envelope *env;
1476
1477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1478 "%p Sending end of place list notification to client\n",
1479 client);
1480 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE_END);
1481 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1482 env);
1483}
1484
1485
1486void
1487app_notify_ego (struct Ego *ego, struct GNUNET_SERVICE_Client *client)
1488{
1489 struct AppEgoMessage *emsg;
1490 struct GNUNET_MQ_Envelope *env;
1491 size_t name_size = strlen (ego->name) + 1;
1492
1493 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1494 "%p Sending ego notification to client: %s\n",
1495 client, ego->name);
1496 env = GNUNET_MQ_msg_extra (emsg,
1497 name_size,
1498 GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO);
1499 GNUNET_CRYPTO_ecdsa_key_get_public (&ego->key, &emsg->ego_pub_key);
1500 GNUNET_memcpy (&emsg[1], ego->name, name_size);
1501 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1502 env);
1503}
1504
1505
1506void
1507app_notify_ego_end (struct GNUNET_SERVICE_Client *client)
1508{
1509 struct GNUNET_MQ_Envelope *env;
1510
1511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1512 "%p Sending end of ego list notification to client\n",
1513 client);
1514 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO_END);
1515 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1516 env);
1517}
1518
1519
1520int
1521app_place_entry_notify (void *cls, const struct GNUNET_HashCode *key, void *value)
1522{
1523 struct GNUNET_MessageHeader *
1524 msg = GNUNET_CONTAINER_multihashmap_get (places, key);
1525 if (NULL != msg)
1526 app_notify_place (msg, cls);
1527 return GNUNET_YES;
1528}
1529
1530
1531int
1532ego_entry (void *cls, const struct GNUNET_HashCode *key, void *value)
1533{
1534 app_notify_ego (value, cls);
1535 return GNUNET_YES;
1536}
1537
1538
1410static int 1539static int
1411check_client_msg_proc_set (void *cls, 1540check_client_msg_proc_set (void *cls,
1412 const struct MsgProcRequest *mpreq) 1541 const struct MsgProcRequest *mpreq)
@@ -1518,9 +1647,8 @@ static void
1518handle_client_host_enter (void *cls, 1647handle_client_host_enter (void *cls,
1519 const struct HostEnterRequest *hr) 1648 const struct HostEnterRequest *hr)
1520{ 1649{
1521 struct Client *c = cls; 1650 struct Client *c = cls;
1522 struct GNUNET_SERVICE_Client *client = c->client; 1651 struct GNUNET_SERVICE_Client *client = c->client;
1523
1524 struct HostEnterRequest * 1652 struct HostEnterRequest *
1525 hreq = (struct HostEnterRequest *) GNUNET_copy_message (&hr->header); 1653 hreq = (struct HostEnterRequest *) GNUNET_copy_message (&hr->header);
1526 1654
@@ -1578,7 +1706,7 @@ handle_client_host_enter (void *cls,
1578 if (ret != GNUNET_SYSERR) 1706 if (ret != GNUNET_SYSERR)
1579 { 1707 {
1580 1708
1581 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1709 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1582 "%p Client connected as host to place %s.\n", 1710 "%p Client connected as host to place %s.\n",
1583 hst, GNUNET_h2s (&plc->pub_key_hash)); 1711 hst, GNUNET_h2s (&plc->pub_key_hash));
1584 1712
@@ -1586,6 +1714,7 @@ handle_client_host_enter (void *cls,
1586 cli->client = client; 1714 cli->client = client;
1587 GNUNET_CONTAINER_DLL_insert (plc->clients_head, plc->clients_tail, cli); 1715 GNUNET_CONTAINER_DLL_insert (plc->clients_head, plc->clients_tail, cli);
1588 c->place = plc; 1716 c->place = plc;
1717 app_notify_place (&hreq->header, client);
1589 } 1718 }
1590 1719
1591 GNUNET_CRYPTO_eddsa_key_clear (&hreq->place_key); 1720 GNUNET_CRYPTO_eddsa_key_clear (&hreq->place_key);
@@ -1622,8 +1751,12 @@ guest_enter (const struct GuestEnterRequest *greq, struct Guest **ret_gst)
1622 struct Ego *ego = GNUNET_CONTAINER_multihashmap_get (egos, &ego_pub_hash); 1751 struct Ego *ego = GNUNET_CONTAINER_multihashmap_get (egos, &ego_pub_hash);
1623 1752
1624 if (NULL == ego) 1753 if (NULL == ego)
1754 {
1625 return GNUNET_SYSERR; 1755 return GNUNET_SYSERR;
1756 }
1626 1757
1758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1759 "entering as guest\n");
1627 struct GNUNET_HashCode place_pub_hash; 1760 struct GNUNET_HashCode place_pub_hash;
1628 GNUNET_CRYPTO_hash (&greq->place_pub_key, sizeof (greq->place_pub_key), 1761 GNUNET_CRYPTO_hash (&greq->place_pub_key, sizeof (greq->place_pub_key),
1629 &place_pub_hash); 1762 &place_pub_hash);
@@ -1631,13 +1764,24 @@ guest_enter (const struct GuestEnterRequest *greq, struct Guest **ret_gst)
1631 struct GNUNET_CONTAINER_MultiHashMap * 1764 struct GNUNET_CONTAINER_MultiHashMap *
1632 plc_gst = GNUNET_CONTAINER_multihashmap_get (place_guests, &place_pub_hash); 1765 plc_gst = GNUNET_CONTAINER_multihashmap_get (place_guests, &place_pub_hash);
1633 struct Guest *gst = NULL; 1766 struct Guest *gst = NULL;
1767 int new_guest;
1634 1768
1635 if (NULL != plc_gst) 1769 if (NULL != plc_gst)
1636 gst = GNUNET_CONTAINER_multihashmap_get (plc_gst, &ego_pub_hash); 1770 gst = GNUNET_CONTAINER_multihashmap_get (plc_gst, &ego_pub_hash);
1637 1771
1638 if (NULL == gst || NULL == gst->slave) 1772 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1773 "plc_gst = %p, gst = %p\n",
1774 plc_gst,
1775 gst);
1776
1777 new_guest = GNUNET_NO;
1778 if (NULL == gst)
1639 { 1779 {
1640 gst = GNUNET_new (struct Guest); 1780 gst = GNUNET_new (struct Guest);
1781 new_guest = GNUNET_YES;
1782 }
1783 if (NULL == gst->slave)
1784 {
1641 gst->origin = greq->origin; 1785 gst->origin = greq->origin;
1642 gst->relay_count = ntohl (greq->relay_count); 1786 gst->relay_count = ntohl (greq->relay_count);
1643 1787
@@ -1711,10 +1855,14 @@ guest_enter (const struct GuestEnterRequest *greq, struct Guest **ret_gst)
1711 (void) GNUNET_CONTAINER_multihashmap_put (place_guests, &plc->pub_key_hash, plc_gst, 1855 (void) GNUNET_CONTAINER_multihashmap_put (place_guests, &plc->pub_key_hash, plc_gst,
1712 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 1856 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1713 } 1857 }
1714 (void) GNUNET_CONTAINER_multihashmap_put (plc_gst, &plc->ego_pub_hash, gst, 1858 if (GNUNET_YES == new_guest)
1715 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 1859 {
1716 (void) GNUNET_CONTAINER_multihashmap_put (guests, &plc->pub_key_hash, gst, 1860 (void) GNUNET_CONTAINER_multihashmap_put (plc_gst, &plc->ego_pub_hash, gst,
1861 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1862 (void) GNUNET_CONTAINER_multihashmap_put (guests, &plc->pub_key_hash, gst,
1717 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1863 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1864
1865 }
1718 gst->slave 1866 gst->slave
1719 = GNUNET_PSYC_slave_join (cfg, &plc->pub_key, &plc->ego_key, 1867 = GNUNET_PSYC_slave_join (cfg, &plc->pub_key, &plc->ego_key,
1720 gst->join_flags, &gst->origin, 1868 gst->join_flags, &gst->origin,
@@ -1724,9 +1872,13 @@ guest_enter (const struct GuestEnterRequest *greq, struct Guest **ret_gst)
1724 &psyc_recv_join_dcsn, 1872 &psyc_recv_join_dcsn,
1725 gst, join_msg); 1873 gst, join_msg);
1726 plc->channel = GNUNET_PSYC_slave_get_channel (gst->slave); 1874 plc->channel = GNUNET_PSYC_slave_get_channel (gst->slave);
1875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1876 "slave entered channel %p\n",
1877 plc->channel);
1727 ret = GNUNET_YES; 1878 ret = GNUNET_YES;
1728 } 1879 }
1729 1880
1881 // TODO: explain why free(gst) not necessary
1730 if (NULL != ret_gst) 1882 if (NULL != ret_gst)
1731 *ret_gst = gst; 1883 *ret_gst = gst;
1732 return ret; 1884 return ret;
@@ -1734,78 +1886,96 @@ guest_enter (const struct GuestEnterRequest *greq, struct Guest **ret_gst)
1734 1886
1735 1887
1736static int 1888static int
1737check_client_guest_enter (void *cls, 1889client_guest_enter (struct Client *c,
1738 const struct GuestEnterRequest *greq) 1890 const struct GuestEnterRequest *greq)
1739{ 1891{
1740 return GNUNET_OK; 1892 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1741} 1893 "client_guest_enter\n");
1742 1894 struct GNUNET_PSYC_CountersResultMessage *result_msg;
1743 1895 struct GNUNET_MQ_Envelope *env;
1744/**
1745 * Handle a connecting client entering a place as guest.
1746 */
1747static void
1748handle_client_guest_enter (void *cls,
1749 const struct GuestEnterRequest *greq)
1750{
1751 struct Client *c = cls;
1752 struct GNUNET_SERVICE_Client *client = c->client; 1896 struct GNUNET_SERVICE_Client *client = c->client;
1753
1754 uint16_t remaining = ntohs (greq->header.size) - sizeof (*greq); 1897 uint16_t remaining = ntohs (greq->header.size) - sizeof (*greq);
1755 const char *app_id = NULL; 1898 const char *app_id = NULL;
1756 uint16_t offset = GNUNET_STRINGS_buffer_tokenize ((const char *) &greq[1], 1899 uint16_t offset = GNUNET_STRINGS_buffer_tokenize ((const char *) &greq[1],
1757 remaining, 1, &app_id); 1900 remaining, 1, &app_id);
1758 if (0 == offset)
1759 {
1760 GNUNET_break (0);
1761 GNUNET_SERVICE_client_drop (client);
1762 return;
1763 }
1764
1765 struct Guest *gst = NULL; 1901 struct Guest *gst = NULL;
1766 struct Place *plc = NULL; 1902 struct Place *plc = NULL;
1767 1903
1904 if (0 == offset)
1905 {
1906 return GNUNET_SYSERR;
1907 }
1768 switch (guest_enter (greq, &gst)) 1908 switch (guest_enter (greq, &gst))
1769 { 1909 {
1770 case GNUNET_YES: 1910 case GNUNET_YES:
1911 {
1771 plc = c->place = &gst->place; 1912 plc = c->place = &gst->place;
1913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1914 "guest entered successfully to local place %s\n",
1915 GNUNET_h2s (&plc->pub_key_hash));
1772 plc->guest = gst; 1916 plc->guest = gst;
1773 app_place_save (app_id, (const struct PlaceEnterRequest *) greq); 1917 app_place_save (app_id, (const struct PlaceEnterRequest *) greq);
1918 app_notify_place (&greq->header, client);
1774 break; 1919 break;
1775 1920 }
1776 case GNUNET_NO: 1921 case GNUNET_NO:
1777 { 1922 {
1778 plc = c->place = &gst->place; 1923 plc = c->place = &gst->place;
1924 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1925 "guest re-entered successfully to local place %s\n",
1926 GNUNET_h2s (&plc->pub_key_hash));
1779 plc->guest = gst; 1927 plc->guest = gst;
1780 1928 env = GNUNET_MQ_msg (result_msg,
1781 struct GNUNET_PSYC_CountersResultMessage res; 1929 GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER_ACK);
1782 res.header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER_ACK); 1930 result_msg->result_code = htonl (GNUNET_OK);
1783 res.header.size = htons (sizeof (res)); 1931 result_msg->max_message_id = GNUNET_htonll (plc->max_message_id);
1784 res.result_code = htonl (GNUNET_OK); 1932 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1785 res.max_message_id = GNUNET_htonll (plc->max_message_id); 1933 env);
1786
1787 client_send_msg (client, &res.header);
1788 if (NULL != gst->join_dcsn) 1934 if (NULL != gst->join_dcsn)
1789 client_send_msg (client, &gst->join_dcsn->header); 1935 {
1790 1936 env = GNUNET_MQ_msg_copy (&gst->join_dcsn->header);
1937 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1938 env);
1939 }
1791 break; 1940 break;
1792 } 1941 }
1793 case GNUNET_SYSERR: 1942 case GNUNET_SYSERR:
1794 GNUNET_break (0); 1943 {
1795 GNUNET_SERVICE_client_drop (client); 1944 return GNUNET_SYSERR;
1796 return; 1945 }
1797 } 1946 }
1798
1799 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1800 "%p Client connected as guest to place %s.\n",
1801 gst, GNUNET_h2s (&plc->pub_key_hash));
1802 1947
1803 struct ClientListItem *cli = GNUNET_new (struct ClientListItem); 1948 struct ClientListItem *cli = GNUNET_new (struct ClientListItem);
1804 cli->client = client; 1949 cli->client = client;
1805 GNUNET_CONTAINER_DLL_insert (plc->clients_head, plc->clients_tail, cli); 1950 GNUNET_CONTAINER_DLL_insert (plc->clients_head, plc->clients_tail, cli);
1951 return GNUNET_OK;
1952}
1806 1953
1807 c->place = plc; 1954
1808 GNUNET_SERVICE_client_continue (client); 1955static int
1956check_client_guest_enter (void *cls,
1957 const struct GuestEnterRequest *greq)
1958{
1959 return GNUNET_OK;
1960}
1961
1962
1963/**
1964 * Handle a connecting client entering a place as guest.
1965 */
1966static void
1967handle_client_guest_enter (void *cls,
1968 const struct GuestEnterRequest *greq)
1969{
1970 struct Client *c = cls;
1971
1972 if (GNUNET_SYSERR == client_guest_enter (c, greq))
1973 {
1974 GNUNET_break (0);
1975 GNUNET_SERVICE_client_drop (c->client);
1976 return;
1977 }
1978 GNUNET_SERVICE_client_continue (c->client);
1809} 1979}
1810 1980
1811 1981
@@ -1830,7 +2000,7 @@ gns_result_guest_enter (void *cls, uint32_t rd_count,
1830{ 2000{
1831 struct GuestEnterByNameClosure *gcls = cls; 2001 struct GuestEnterByNameClosure *gcls = cls;
1832 struct Client *c = gcls->client; 2002 struct Client *c = gcls->client;
1833 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2003 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1834 "%p GNS result: %u records.\n", 2004 "%p GNS result: %u records.\n",
1835 c, rd_count); 2005 c, rd_count);
1836 2006
@@ -1882,7 +2052,7 @@ gns_result_guest_enter (void *cls, uint32_t rd_count,
1882 p += relay_size; 2052 p += relay_size;
1883 GNUNET_memcpy (p, gcls->join_msg, join_msg_size); 2053 GNUNET_memcpy (p, gcls->join_msg, join_msg_size);
1884 2054
1885 handle_client_guest_enter (c, greq); 2055 client_guest_enter (c, greq);
1886 2056
1887 GNUNET_free (gcls->app_id); 2057 GNUNET_free (gcls->app_id);
1888 if (NULL != gcls->password) 2058 if (NULL != gcls->password)
@@ -1960,118 +2130,7 @@ handle_client_guest_enter_by_name (void *cls,
1960 GNUNET_GNSRECORD_TYPE_PLACE, 2130 GNUNET_GNSRECORD_TYPE_PLACE,
1961 GNUNET_GNS_LO_DEFAULT, 2131 GNUNET_GNS_LO_DEFAULT,
1962 &gns_result_guest_enter, gcls); 2132 &gns_result_guest_enter, gcls);
1963} 2133 GNUNET_SERVICE_client_continue (client);
1964
1965
1966void
1967app_notify_place (struct GNUNET_MessageHeader *msg,
1968 struct GNUNET_SERVICE_Client *client)
1969{
1970 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1971 "%p Sending place notification of type %u to client.\n",
1972 client, ntohs (msg->type));
1973
1974 uint16_t msg_size = ntohs (msg->size);
1975 struct AppPlaceMessage amsg;
1976 amsg.header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE);
1977 amsg.header.size = htons (sizeof (amsg));
1978 // FIXME: also notify about not entered places
1979 amsg.place_state = GNUNET_SOCIAL_PLACE_STATE_ENTERED;
1980
1981 switch (ntohs (msg->type))
1982 {
1983 case GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER:
1984 if (msg_size < sizeof (struct HostEnterRequest))
1985 return;
1986 struct HostEnterRequest *hreq = (struct HostEnterRequest *) msg;
1987 amsg.is_host = GNUNET_YES;
1988 amsg.ego_pub_key = hreq->ego_pub_key;
1989 amsg.place_pub_key = hreq->place_pub_key;
1990 break;
1991
1992 case GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER:
1993 if (msg_size < sizeof (struct GuestEnterRequest))
1994 return;
1995 struct GuestEnterRequest *greq = (struct GuestEnterRequest *) msg;
1996 amsg.is_host = GNUNET_NO;
1997 amsg.ego_pub_key = greq->ego_pub_key;
1998 amsg.place_pub_key = greq->place_pub_key;
1999 break;
2000
2001 default:
2002 return;
2003 }
2004
2005 client_send_msg (client, &amsg.header);
2006}
2007
2008
2009void
2010app_notify_place_end (struct GNUNET_SERVICE_Client *client)
2011{
2012 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2013 "%p Sending end of place list notification to client\n",
2014 client);
2015
2016 struct GNUNET_MessageHeader msg;
2017 msg.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_APP_PLACE_END);
2018 msg.size = htons (sizeof (msg));
2019
2020 client_send_msg (client, &msg);
2021}
2022
2023
2024void
2025app_notify_ego (struct Ego *ego, struct GNUNET_SERVICE_Client *client)
2026{
2027 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2028 "%p Sending ego notification to client: %s\n",
2029 client, ego->name);
2030
2031 size_t name_size = strlen (ego->name) + 1;
2032 struct AppEgoMessage *emsg = GNUNET_malloc (sizeof (*emsg) + name_size);
2033 emsg->header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO);
2034 emsg->header.size = htons (sizeof (*emsg) + name_size);
2035
2036 GNUNET_CRYPTO_ecdsa_key_get_public (&ego->key, &emsg->ego_pub_key);
2037 GNUNET_memcpy (&emsg[1], ego->name, name_size);
2038
2039 client_send_msg (client, &emsg->header);
2040 GNUNET_free (emsg);
2041}
2042
2043
2044void
2045app_notify_ego_end (struct GNUNET_SERVICE_Client *client)
2046{
2047 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2048 "%p Sending end of ego list notification to client\n",
2049 client);
2050
2051 struct GNUNET_MessageHeader msg;
2052 msg.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_APP_EGO_END);
2053 msg.size = htons (sizeof (msg));
2054
2055 client_send_msg (client, &msg);
2056}
2057
2058
2059int
2060app_place_entry_notify (void *cls, const struct GNUNET_HashCode *key, void *value)
2061{
2062 struct GNUNET_MessageHeader *
2063 msg = GNUNET_CONTAINER_multihashmap_get (places, key);
2064 if (NULL != msg)
2065 app_notify_place (msg, cls);
2066 return GNUNET_YES;
2067}
2068
2069
2070int
2071ego_entry (void *cls, const struct GNUNET_HashCode *key, void *value)
2072{
2073 app_notify_ego (value, cls);
2074 return GNUNET_YES;
2075} 2134}
2076 2135
2077 2136
@@ -2092,20 +2151,34 @@ handle_client_app_connect (void *cls,
2092{ 2151{
2093 struct Client *c = cls; 2152 struct Client *c = cls;
2094 struct GNUNET_SERVICE_Client *client = c->client; 2153 struct GNUNET_SERVICE_Client *client = c->client;
2095 2154 ssize_t app_id_size = ntohs (creq->header.size) - sizeof (*creq);
2096 uint8_t app_id_size = ntohs (creq->header.size) - sizeof (*creq);
2097 const char *app_id = NULL; 2155 const char *app_id = NULL;
2098 uint16_t offset = GNUNET_STRINGS_buffer_tokenize ((const char *) &creq[1], 2156 uint16_t offset;
2099 app_id_size, 1, &app_id); 2157
2158 if (app_id_size < 0)
2159 {
2160 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2161 "AppConnectRequest has invalid size\n");
2162 GNUNET_break (0);
2163 GNUNET_SERVICE_client_drop (client);
2164 return;
2165 }
2166
2167 offset = GNUNET_STRINGS_buffer_tokenize ((const char *) &creq[1],
2168 (size_t) app_id_size,
2169 1,
2170 &app_id);
2100 if (0 == offset || offset != app_id_size) 2171 if (0 == offset || offset != app_id_size)
2101 { 2172 {
2173 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2174 "AppConnectRequest contains invalid app ID\n");
2102 GNUNET_break (0); 2175 GNUNET_break (0);
2103 GNUNET_SERVICE_client_drop (client); 2176 GNUNET_SERVICE_client_drop (client);
2104 return; 2177 return;
2105 } 2178 }
2106 2179
2107 struct GNUNET_HashCode app_id_hash; 2180 struct GNUNET_HashCode app_id_hash;
2108 GNUNET_CRYPTO_hash (app_id, app_id_size, &app_id_hash); 2181 GNUNET_CRYPTO_hash (app_id, (size_t) app_id_size, &app_id_hash);
2109 2182
2110 GNUNET_CONTAINER_multihashmap_iterate (egos, ego_entry, client); 2183 GNUNET_CONTAINER_multihashmap_iterate (egos, ego_entry, client);
2111 app_notify_ego_end (client); 2184 app_notify_ego_end (client);
@@ -2130,8 +2203,8 @@ handle_client_app_connect (void *cls,
2130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2131 "%p Application %s connected.\n", app, app_id); 2204 "%p Application %s connected.\n", app, app_id);
2132 2205
2133 c->app_id = GNUNET_malloc (app_id_size); 2206 c->app_id = GNUNET_malloc ((size_t) app_id_size);
2134 GNUNET_memcpy (c->app_id, app_id, app_id_size); 2207 GNUNET_memcpy (c->app_id, app_id, (size_t) app_id_size);
2135 2208
2136 GNUNET_SERVICE_client_continue (client); 2209 GNUNET_SERVICE_client_continue (client);
2137} 2210}
@@ -2154,13 +2227,15 @@ handle_client_app_detach (void *cls,
2154} 2227}
2155 2228
2156 2229
2157int 2230static void
2158app_places_entry_remove (void *cls, const struct GNUNET_HashCode *key, void *value) 2231place_leave_cb (void *cls)
2159{ 2232{
2160 struct Place *plc = cls; 2233 struct Place *plc = cls;
2161 const char *app_id = value; 2234
2162 app_place_remove (app_id, &plc->ego_pub_key, &plc->pub_key); 2235 place_send_leave_ack (plc);
2163 return GNUNET_YES; 2236 (GNUNET_YES == plc->is_host)
2237 ? cleanup_host ((struct Host *) plc)
2238 : cleanup_guest ((struct Guest *) plc);
2164} 2239}
2165 2240
2166 2241
@@ -2174,6 +2249,11 @@ handle_client_place_leave (void *cls,
2174 struct Client *c = cls; 2249 struct Client *c = cls;
2175 struct GNUNET_SERVICE_Client *client = c->client; 2250 struct GNUNET_SERVICE_Client *client = c->client;
2176 struct Place *plc = c->place; 2251 struct Place *plc = c->place;
2252
2253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2254 "got leave request from %s for place %s",
2255 plc->is_host? "host" : "slave",
2256 GNUNET_h2s (&plc->pub_key_hash));
2177 if (NULL == plc) 2257 if (NULL == plc)
2178 { 2258 {
2179 GNUNET_break (0); 2259 GNUNET_break (0);
@@ -2181,40 +2261,28 @@ handle_client_place_leave (void *cls,
2181 return; 2261 return;
2182 } 2262 }
2183 2263
2184 /* FIXME: remove all app subscriptions and leave this place */ 2264 if (GNUNET_YES != plc->is_disconnecting)
2185
2186 struct GNUNET_CONTAINER_MultiHashMap *
2187 place_apps = GNUNET_CONTAINER_multihashmap_get (places_apps, &plc->pub_key_hash);
2188 if (NULL != place_apps)
2189 { 2265 {
2190 GNUNET_CONTAINER_multihashmap_iterate (place_apps, app_places_entry_remove, plc); 2266 plc->is_disconnecting = GNUNET_YES;
2191 } 2267 if (plc->is_host)
2192 2268 {
2193 /* FIXME: disconnect from the network, but keep local connection for history access */ 2269 struct Host *host = plc->host;
2194 2270 GNUNET_assert (NULL != host);
2195 /* Disconnect all clients connected to the place */ 2271 GNUNET_PSYC_master_stop (host->master, GNUNET_NO, &place_leave_cb, plc);
2196 struct ClientListItem *cli = plc->clients_head, *next;
2197 while (NULL != cli)
2198 {
2199 GNUNET_CONTAINER_DLL_remove (plc->clients_head, plc->clients_tail, cli);
2200 GNUNET_SERVICE_client_drop (cli->client);
2201 next = cli->next;
2202 GNUNET_free (cli);
2203 cli = next;
2204 }
2205
2206 if (GNUNET_YES != plc->is_disconnected)
2207 {
2208 plc->is_disconnected = GNUNET_YES;
2209 if (NULL != plc->tmit_msgs_head)
2210 { /* Send pending messages to PSYC before cleanup. */
2211 psyc_transmit_message (plc);
2212 } 2272 }
2213 else 2273 else
2214 { 2274 {
2215 cleanup_place (plc); 2275 struct Guest *guest = plc->guest;
2276 GNUNET_assert (NULL != guest);
2277 GNUNET_PSYC_slave_part (guest->slave, GNUNET_NO, &place_leave_cb, plc);
2216 } 2278 }
2217 } 2279 }
2280 else
2281 {
2282 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2283 "got leave request but place is already leaving\n");
2284 }
2285 GNUNET_SERVICE_client_continue (client);
2218} 2286}
2219 2287
2220 2288
@@ -2273,6 +2341,9 @@ handle_client_join_decision (void *cls,
2273 ? (struct GNUNET_PSYC_Message *) &dcsn[1] 2341 ? (struct GNUNET_PSYC_Message *) &dcsn[1]
2274 : NULL; 2342 : NULL;
2275 2343
2344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2345 "jcls.msg = %p\n",
2346 jcls.msg);
2276 struct GNUNET_HashCode slave_pub_hash; 2347 struct GNUNET_HashCode slave_pub_hash;
2277 GNUNET_CRYPTO_hash (&dcsn->slave_pub_key, sizeof (dcsn->slave_pub_key), 2348 GNUNET_CRYPTO_hash (&dcsn->slave_pub_key, sizeof (dcsn->slave_pub_key),
2278 &slave_pub_hash); 2349 &slave_pub_hash);
@@ -2302,10 +2373,11 @@ handle_client_join_decision (void *cls,
2302static void 2373static void
2303send_message_ack (struct Place *plc, struct GNUNET_SERVICE_Client *client) 2374send_message_ack (struct Place *plc, struct GNUNET_SERVICE_Client *client)
2304{ 2375{
2305 struct GNUNET_MessageHeader res; 2376 struct GNUNET_MQ_Envelope *env;
2306 res.size = htons (sizeof (res)); 2377
2307 res.type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_ACK); 2378 env = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_ACK);
2308 client_send_msg (client, &res); 2379 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
2380 env);
2309} 2381}
2310 2382
2311 2383
@@ -2437,7 +2509,6 @@ psyc_transmit_notify_data (void *cls, uint16_t *data_size, void *data)
2437 { 2509 {
2438 *data_size = 0; 2510 *data_size = 0;
2439 tmit_msg = psyc_transmit_queue_next_msg (plc, tmit_msg); 2511 tmit_msg = psyc_transmit_queue_next_msg (plc, tmit_msg);
2440 plc->is_disconnected = GNUNET_YES;
2441 GNUNET_SERVICE_client_drop (tmit_frag->client); 2512 GNUNET_SERVICE_client_drop (tmit_frag->client);
2442 GNUNET_SCHEDULER_add_now (&cleanup_place, plc); 2513 GNUNET_SCHEDULER_add_now (&cleanup_place, plc);
2443 return ret; 2514 return ret;
@@ -2479,11 +2550,7 @@ psyc_transmit_notify_data (void *cls, uint16_t *data_size, void *data)
2479 { 2550 {
2480 psyc_transmit_message (plc); 2551 psyc_transmit_message (plc);
2481 } 2552 }
2482 else if (GNUNET_YES == plc->is_disconnected) 2553 /* FIXME: handle partial message (when still in_transmit) */
2483 {
2484 /* FIXME: handle partial message (when still in_transmit) */
2485 cleanup_place (plc);
2486 }
2487 } 2554 }
2488 return ret; 2555 return ret;
2489} 2556}
@@ -2597,7 +2664,6 @@ psyc_transmit_notify_mod (void *cls, uint16_t *data_size, void *data,
2597 *data_size = 0; 2664 *data_size = 0;
2598 ret = GNUNET_SYSERR; 2665 ret = GNUNET_SYSERR;
2599 tmit_msg = psyc_transmit_queue_next_msg (plc, tmit_msg); 2666 tmit_msg = psyc_transmit_queue_next_msg (plc, tmit_msg);
2600 plc->is_disconnected = GNUNET_YES;
2601 GNUNET_SERVICE_client_drop (tmit_frag->client); 2667 GNUNET_SERVICE_client_drop (tmit_frag->client);
2602 GNUNET_SCHEDULER_add_now (&cleanup_place, plc); 2668 GNUNET_SCHEDULER_add_now (&cleanup_place, plc);
2603 } 2669 }
@@ -2862,26 +2928,26 @@ psyc_transmit_queue_message (struct Place *plc,
2862} 2928}
2863 2929
2864 2930
2865/** 2931///**
2866 * Cancel transmission of current message to PSYC. 2932// * Cancel transmission of current message to PSYC.
2867 * 2933// *
2868 * @param plc Place to send to. 2934// * @param plc Place to send to.
2869 * @param client Client the message originates from. 2935// * @param client Client the message originates from.
2870 */ 2936// */
2871static void 2937//static void
2872psyc_transmit_cancel (struct Place *plc, struct GNUNET_SERVICE_Client *client) 2938//psyc_transmit_cancel (struct Place *plc, struct GNUNET_SERVICE_Client *client)
2873{ 2939//{
2874 uint16_t type = GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL; 2940// uint16_t type = GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL;
2875 2941//
2876 struct GNUNET_MessageHeader msg; 2942// struct GNUNET_MessageHeader msg;
2877 msg.size = htons (sizeof (msg)); 2943// msg.size = htons (sizeof (msg));
2878 msg.type = htons (type); 2944// msg.type = htons (type);
2879 2945//
2880 psyc_transmit_queue_message (plc, client, sizeof (msg), &msg, type, type, NULL); 2946// psyc_transmit_queue_message (plc, client, sizeof (msg), &msg, type, type, NULL);
2881 psyc_transmit_message (plc); 2947// psyc_transmit_message (plc);
2882 2948//
2883 /* FIXME: cleanup */ 2949// /* FIXME: cleanup */
2884} 2950//}
2885 2951
2886 2952
2887static int 2953static int
@@ -2902,17 +2968,19 @@ handle_client_psyc_message (void *cls,
2902 struct Client *c = cls; 2968 struct Client *c = cls;
2903 struct GNUNET_SERVICE_Client *client = c->client; 2969 struct GNUNET_SERVICE_Client *client = c->client;
2904 struct Place *plc = c->place; 2970 struct Place *plc = c->place;
2971 int ret;
2972
2905 if (NULL == plc) 2973 if (NULL == plc)
2906 { 2974 {
2975 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2976 "received PSYC message for non-existing client %p\n",
2977 client);
2907 GNUNET_break (0); 2978 GNUNET_break (0);
2908 GNUNET_SERVICE_client_drop (client); 2979 GNUNET_SERVICE_client_drop (client);
2909 return; 2980 return;
2910 } 2981 }
2911
2912 int ret = GNUNET_SYSERR;
2913
2914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2982 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2915 "%p Received message from client.\n", plc); 2983 "%p Received message of type %d from client.\n", plc, ntohs (msg->type));
2916 GNUNET_PSYC_log_message (GNUNET_ERROR_TYPE_DEBUG, msg); 2984 GNUNET_PSYC_log_message (GNUNET_ERROR_TYPE_DEBUG, msg);
2917 2985
2918 if (GNUNET_YES != plc->is_ready) 2986 if (GNUNET_YES != plc->is_ready)
@@ -2933,20 +3001,19 @@ handle_client_psyc_message (void *cls,
2933 "%p Received message with invalid payload size (%u) from client.\n", 3001 "%p Received message with invalid payload size (%u) from client.\n",
2934 plc, psize); 3002 plc, psize);
2935 GNUNET_break (0); 3003 GNUNET_break (0);
2936 psyc_transmit_cancel (plc, client);
2937 GNUNET_SERVICE_client_drop (client); 3004 GNUNET_SERVICE_client_drop (client);
2938 return; 3005 return;
2939 } 3006 }
2940 3007
2941 uint16_t first_ptype = 0, last_ptype = 0; 3008 uint16_t first_ptype = 0;
2942 if (GNUNET_SYSERR 3009 uint16_t last_ptype = 0;
2943 == GNUNET_PSYC_receive_check_parts (psize, (const char *) &msg[1], 3010 if (GNUNET_SYSERR ==
2944 &first_ptype, &last_ptype)) 3011 GNUNET_PSYC_receive_check_parts (psize, (const char *) &msg[1],
3012 &first_ptype, &last_ptype))
2945 { 3013 {
2946 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3014 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2947 "%p Received invalid message part from client.\n", plc); 3015 "%p Received invalid message part from client.\n", plc);
2948 GNUNET_break (0); 3016 GNUNET_break (0);
2949 psyc_transmit_cancel (plc, client);
2950 GNUNET_SERVICE_client_drop (client); 3017 GNUNET_SERVICE_client_drop (client);
2951 return; 3018 return;
2952 } 3019 }
@@ -2963,20 +3030,19 @@ handle_client_psyc_message (void *cls,
2963 c->tmit_msg = NULL; 3030 c->tmit_msg = NULL;
2964 ret = psyc_transmit_message (plc); 3031 ret = psyc_transmit_message (plc);
2965 } 3032 }
2966 3033 else
3034 {
3035 ret = GNUNET_SYSERR;
3036 }
2967 if (GNUNET_OK != ret) 3037 if (GNUNET_OK != ret)
2968 { 3038 {
2969 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3039 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2970 "%p Received invalid message part from client.\n", plc); 3040 "%p Received invalid message part from client.\n", plc);
2971 GNUNET_break (0); 3041 GNUNET_break (0);
2972 psyc_transmit_cancel (plc, client);
2973 ret = GNUNET_SYSERR;
2974 }
2975
2976 if (GNUNET_OK == ret)
2977 GNUNET_SERVICE_client_continue (client);
2978 else
2979 GNUNET_SERVICE_client_drop (client); 3042 GNUNET_SERVICE_client_drop (client);
3043 return;
3044 }
3045 GNUNET_SERVICE_client_continue (client);
2980} 3046}
2981 3047
2982 3048
@@ -3006,7 +3072,7 @@ psyc_recv_history_message (void *cls, const struct GNUNET_PSYC_MessageHeader *ms
3006 GNUNET_memcpy (&res[1], msg, size); 3072 GNUNET_memcpy (&res[1], msg, size);
3007 3073
3008 /** @todo FIXME: send only to requesting client */ 3074 /** @todo FIXME: send only to requesting client */
3009 place_send_msg (plc, &res->header); 3075 place_send_msg (plc, GNUNET_MQ_msg_copy (&res->header));
3010 3076
3011 GNUNET_free (res); 3077 GNUNET_free (res);
3012} 3078}
@@ -3108,29 +3174,24 @@ psyc_recv_state_var (void *cls,
3108 uint32_t value_size, 3174 uint32_t value_size,
3109 uint32_t full_value_size) 3175 uint32_t full_value_size)
3110{ 3176{
3177 struct GNUNET_OperationResultMessage *result_msg;
3178 struct GNUNET_MQ_Envelope *env;
3111 struct OperationClosure *opcls = cls; 3179 struct OperationClosure *opcls = cls;
3112 struct Client *c = opcls->client; 3180 struct Client *c = opcls->client;
3113 struct Place *plc = c->place; 3181 struct Place *plc = c->place;
3182 uint16_t size = ntohs (mod->size);
3114 3183
3115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3116 "%p Received state variable %s from PSYC\n", 3185 "%p Received state variable %s from PSYC\n",
3117 plc, name); 3186 plc, name);
3118 3187 env = GNUNET_MQ_msg_extra (result_msg,
3119 uint16_t size = ntohs (mod->size); 3188 size,
3120 3189 GNUNET_MESSAGE_TYPE_PSYC_STATE_RESULT);
3121 struct GNUNET_OperationResultMessage * 3190 result_msg->op_id = opcls->op_id;
3122 res = GNUNET_malloc (sizeof (*res) + size); 3191 result_msg->result_code = GNUNET_htonll (GNUNET_OK);
3123 res->header.size = htons (sizeof (*res) + size); 3192 GNUNET_memcpy (&result_msg[1], mod, size);
3124 res->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_STATE_RESULT);
3125 res->op_id = opcls->op_id;
3126 res->result_code = GNUNET_htonll (GNUNET_OK);
3127
3128 GNUNET_memcpy (&res[1], mod, size);
3129
3130 /** @todo FIXME: send only to requesting client */ 3193 /** @todo FIXME: send only to requesting client */
3131 place_send_msg (plc, &res->header); 3194 place_send_msg (plc, env);
3132
3133 GNUNET_free (res);
3134} 3195}
3135 3196
3136 3197
@@ -3184,7 +3245,7 @@ handle_client_state_get (void *cls,
3184 uint16_t size = ntohs (req->header.size); 3245 uint16_t size = ntohs (req->header.size);
3185 const char *name = (const char *) &req[1]; 3246 const char *name = (const char *) &req[1];
3186 3247
3187 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3188 "%p State get #%" PRIu64 ": %s\n", 3249 "%p State get #%" PRIu64 ": %s\n",
3189 plc, GNUNET_ntohll (req->op_id), name); 3250 plc, GNUNET_ntohll (req->op_id), name);
3190 3251
@@ -3382,7 +3443,7 @@ path_basename (const char *path)
3382 if (NULL != basename) 3443 if (NULL != basename)
3383 basename++; 3444 basename++;
3384 3445
3385 if (NULL == basename || '\0' == basename) 3446 if (NULL == basename || '\0' == *basename)
3386 return NULL; 3447 return NULL;
3387 3448
3388 return basename; 3449 return basename;
@@ -3468,7 +3529,10 @@ file_place_load (void *cls, const char *place_filename)
3468 return GNUNET_OK; 3529 return GNUNET_OK;
3469 } 3530 }
3470 3531
3471 app_place_add (plcls->app_id, ereq); 3532 if (GNUNET_SYSERR == app_place_add (plcls->app_id, ereq))
3533 {
3534 GNUNET_assert (0);
3535 }
3472 GNUNET_free (ereq); 3536 GNUNET_free (ereq);
3473 return GNUNET_OK; 3537 return GNUNET_OK;
3474} 3538}
@@ -3523,6 +3587,10 @@ identity_recv_ego (void *cls, struct GNUNET_IDENTITY_Ego *id_ego,
3523 if (NULL == id_ego) // end of initial list of egos 3587 if (NULL == id_ego) // end of initial list of egos
3524 return; 3588 return;
3525 3589
3590 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3591 "social service received ego %s\n",
3592 name);
3593
3526 struct GNUNET_CRYPTO_EcdsaPublicKey ego_pub_key; 3594 struct GNUNET_CRYPTO_EcdsaPublicKey ego_pub_key;
3527 GNUNET_IDENTITY_ego_get_public_key (id_ego, &ego_pub_key); 3595 GNUNET_IDENTITY_ego_get_public_key (id_ego, &ego_pub_key);
3528 3596
@@ -3571,6 +3639,9 @@ run (void *cls,
3571 const struct GNUNET_CONFIGURATION_Handle *c, 3639 const struct GNUNET_CONFIGURATION_Handle *c,
3572 struct GNUNET_SERVICE_Handle *svc) 3640 struct GNUNET_SERVICE_Handle *svc)
3573{ 3641{
3642 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3643 "starting social service\n");
3644
3574 cfg = c; 3645 cfg = c;
3575 service = svc; 3646 service = svc;
3576 GNUNET_CRYPTO_get_peer_identity (cfg, &this_peer); 3647 GNUNET_CRYPTO_get_peer_identity (cfg, &this_peer);
@@ -3583,7 +3654,7 @@ run (void *cls,
3583 apps = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); 3654 apps = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
3584 places = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_NO); 3655 places = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_NO);
3585 apps_places = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_NO); 3656 apps_places = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_NO);
3586 places_apps = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_NO); 3657 //places_apps = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_NO);
3587 3658
3588 id = GNUNET_IDENTITY_connect (cfg, &identity_recv_ego, NULL); 3659 id = GNUNET_IDENTITY_connect (cfg, &identity_recv_ego, NULL);
3589 gns = GNUNET_GNS_connect (cfg); 3660 gns = GNUNET_GNS_connect (cfg);
diff --git a/src/social/gnunet-social.c b/src/social/gnunet-social.c
index de680b11c..12c5bf2e1 100644
--- a/src/social/gnunet-social.c
+++ b/src/social/gnunet-social.c
@@ -283,7 +283,7 @@ exit_fail ()
283static void 283static void
284host_left (void *cls) 284host_left (void *cls)
285{ 285{
286 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 286 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
287 "The host has left the place.\n"); 287 "The host has left the place.\n");
288 exit_success (); 288 exit_success ();
289} 289}
@@ -309,7 +309,7 @@ host_leave ()
309static void 309static void
310guest_left (void *cls) 310guest_left (void *cls)
311{ 311{
312 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 312 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
313 "Guest has left the place.\n"); 313 "Guest has left the place.\n");
314} 314}
315 315
@@ -518,7 +518,7 @@ look_var (void *cls,
518 uint32_t value_size, 518 uint32_t value_size,
519 uint32_t full_value_size) 519 uint32_t full_value_size)
520{ 520{
521 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 521 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
522 "Received var: %s\n%.*s\n", 522 "Received var: %s\n%.*s\n",
523 name, value_size, (const char *) value); 523 name, value_size, (const char *) value);
524} 524}
@@ -558,7 +558,7 @@ slicer_recv_method (void *cls,
558 const char *method_name) 558 const char *method_name)
559{ 559{
560 method_received = method_name; 560 method_received = method_name;
561 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 561 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
562 "Received method for message ID %" PRIu64 ":\n" 562 "Received method for message ID %" PRIu64 ":\n"
563 "%s (flags: %x)\n", 563 "%s (flags: %x)\n",
564 message_id, method_name, ntohl (meth->flags)); 564 message_id, method_name, ntohl (meth->flags));
@@ -584,7 +584,7 @@ slicer_recv_modifier (void *cls,
584 uint16_t full_value_size) 584 uint16_t full_value_size)
585{ 585{
586#if 0 586#if 0
587 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 587 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
588 "Received modifier for message ID %" PRIu64 ":\n" 588 "Received modifier for message ID %" PRIu64 ":\n"
589 "%c%s: %.*s (size: %u)\n", 589 "%c%s: %.*s (size: %u)\n",
590 message_id, oper, name, value_size, (const char *) value, value_size); 590 message_id, oper, name, value_size, (const char *) value, value_size);
@@ -608,7 +608,7 @@ slicer_recv_data (void *cls,
608 uint16_t data_size) 608 uint16_t data_size)
609{ 609{
610#if 0 610#if 0
611 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 611 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
612 "Received data for message ID %" PRIu64 ":\n" 612 "Received data for message ID %" PRIu64 ":\n"
613 "%.*s\n", 613 "%.*s\n",
614 message_id, data_size, (const char *) data); 614 message_id, data_size, (const char *) data);
@@ -631,7 +631,7 @@ slicer_recv_eom (void *cls,
631 uint8_t is_cancelled) 631 uint8_t is_cancelled)
632{ 632{
633 printf(".\n"); 633 printf(".\n");
634 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 634 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
635 "Received end of message ID %" PRIu64 635 "Received end of message ID %" PRIu64
636 ", cancelled: %u\n", 636 ", cancelled: %u\n",
637 message_id, is_cancelled); 637 message_id, is_cancelled);
@@ -668,7 +668,7 @@ guest_recv_entry_decision (void *cls,
668 int is_admitted, 668 int is_admitted,
669 const struct GNUNET_PSYC_Message *entry_msg) 669 const struct GNUNET_PSYC_Message *entry_msg)
670{ 670{
671 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 671 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
672 "Guest received entry decision %d\n", 672 "Guest received entry decision %d\n",
673 is_admitted); 673 is_admitted);
674 674
@@ -683,7 +683,7 @@ guest_recv_entry_decision (void *cls,
683 GNUNET_PSYC_message_parse (pmsg, &method_name, env, &data, &data_size); 683 GNUNET_PSYC_message_parse (pmsg, &method_name, env, &data, &data_size);
684 GNUNET_free (pmsg); 684 GNUNET_free (pmsg);
685 685
686 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 686 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
687 "%s\n%.*s\n", 687 "%s\n%.*s\n",
688 method_name, data_size, (const char *) data); 688 method_name, data_size, (const char *) data);
689 } 689 }
@@ -704,7 +704,7 @@ guest_recv_local_enter (void *cls, int result,
704 uint64_t max_message_id) 704 uint64_t max_message_id)
705{ 705{
706 char *pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key); 706 char *pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key);
707 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 707 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
708 "Guest entered local place: %s, max_message_id: %" PRIu64 "\n", 708 "Guest entered local place: %s, max_message_id: %" PRIu64 "\n",
709 pub_str, max_message_id); 709 pub_str, max_message_id);
710 GNUNET_free (pub_str); 710 GNUNET_free (pub_str);
@@ -802,7 +802,7 @@ host_answer_door (void *cls,
802 char * 802 char *
803 nym_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key); 803 nym_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key);
804 804
805 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 805 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
806 "Entry request: %s\n", nym_str); 806 "Entry request: %s\n", nym_str);
807 GNUNET_free (nym_str); 807 GNUNET_free (nym_str);
808 808
@@ -840,7 +840,7 @@ host_farewell (void *cls,
840 char * 840 char *
841 nym_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key); 841 nym_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key);
842 842
843 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 843 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
844 "Farewell: %s\n", nym_str); 844 "Farewell: %s\n", nym_str);
845 GNUNET_free (nym_str); 845 GNUNET_free (nym_str);
846} 846}
@@ -856,7 +856,7 @@ host_entered (void *cls, int result,
856{ 856{
857 place_pub_key = *pub_key; 857 place_pub_key = *pub_key;
858 char *pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key); 858 char *pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key);
859 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 859 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
860 "Host entered: %s, max_message_id: %" PRIu64 "\n", 860 "Host entered: %s, max_message_id: %" PRIu64 "\n",
861 pub_str, max_message_id); 861 pub_str, max_message_id);
862 GNUNET_free (pub_str); 862 GNUNET_free (pub_str);
diff --git a/src/social/social_api.c b/src/social/social_api.c
index d57d16cfb..89843831b 100644
--- a/src/social/social_api.c
+++ b/src/social/social_api.c
@@ -183,6 +183,7 @@ struct GNUNET_SOCIAL_Place
183 */ 183 */
184 struct GNUNET_PSYC_Slicer *slicer; 184 struct GNUNET_PSYC_Slicer *slicer;
185 185
186 // FIXME: do we need is_disconnecing like on the psyc and multicast APIs?
186 /** 187 /**
187 * Function called after disconnected from the service. 188 * Function called after disconnected from the service.
188 */ 189 */
@@ -371,6 +372,68 @@ struct ZoneAddNymHandle
371}; 372};
372 373
373 374
375/*** CLEANUP / DISCONNECT ***/
376
377
378static void
379host_cleanup (struct GNUNET_SOCIAL_Host *hst)
380{
381 if (NULL != hst->slicer)
382 {
383 GNUNET_PSYC_slicer_destroy (hst->slicer);
384 hst->slicer = NULL;
385 }
386 GNUNET_free (hst);
387}
388
389
390static void
391guest_cleanup (struct GNUNET_SOCIAL_Guest *gst)
392{
393 GNUNET_free (gst);
394}
395
396
397static void
398place_cleanup (struct GNUNET_SOCIAL_Place *plc)
399{
400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
401 "cleaning up place %p\n",
402 plc);
403 if (NULL != plc->tmit)
404 {
405 GNUNET_PSYC_transmit_destroy (plc->tmit);
406 plc->tmit = NULL;
407 }
408 if (NULL != plc->connect_env)
409 {
410 GNUNET_MQ_discard (plc->connect_env);
411 plc->connect_env = NULL;
412 }
413 if (NULL != plc->mq)
414 {
415 GNUNET_MQ_destroy (plc->mq);
416 plc->mq = NULL;
417 }
418 if (NULL != plc->disconnect_cb)
419 {
420 plc->disconnect_cb (plc->disconnect_cls);
421 plc->disconnect_cb = NULL;
422 }
423
424 (GNUNET_YES == plc->is_host)
425 ? host_cleanup ((struct GNUNET_SOCIAL_Host *) plc)
426 : guest_cleanup ((struct GNUNET_SOCIAL_Guest *) plc);
427}
428
429
430static void
431place_disconnect (struct GNUNET_SOCIAL_Place *plc)
432{
433 place_cleanup (plc);
434}
435
436
374/*** NYM ***/ 437/*** NYM ***/
375 438
376static struct GNUNET_SOCIAL_Nym * 439static struct GNUNET_SOCIAL_Nym *
@@ -428,7 +491,7 @@ host_recv_notice_place_leave_method (void *cls,
428 491
429 struct GNUNET_SOCIAL_Nym *nym = nym_get_or_create (&msg->slave_pub_key); 492 struct GNUNET_SOCIAL_Nym *nym = nym_get_or_create (&msg->slave_pub_key);
430 493
431 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
432 "Host received method for message ID %" PRIu64 " from nym %s: %s\n", 495 "Host received method for message ID %" PRIu64 " from nym %s: %s\n",
433 message_id, GNUNET_h2s (&nym->pub_key_hash), method_name); 496 message_id, GNUNET_h2s (&nym->pub_key_hash), method_name);
434 497
@@ -436,7 +499,7 @@ host_recv_notice_place_leave_method (void *cls,
436 hst->notice_place_leave_env = GNUNET_PSYC_env_create (); 499 hst->notice_place_leave_env = GNUNET_PSYC_env_create ();
437 500
438 char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&hst->notice_place_leave_nym->pub_key); 501 char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&hst->notice_place_leave_nym->pub_key);
439 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
440 "_notice_place_leave: got method from nym %s (%s).\n", 503 "_notice_place_leave: got method from nym %s (%s).\n",
441 GNUNET_h2s (&hst->notice_place_leave_nym->pub_key_hash), str); 504 GNUNET_h2s (&hst->notice_place_leave_nym->pub_key_hash), str);
442 GNUNET_free (str); 505 GNUNET_free (str);
@@ -458,7 +521,7 @@ host_recv_notice_place_leave_modifier (void *cls,
458 if (NULL == hst->notice_place_leave_env) 521 if (NULL == hst->notice_place_leave_env)
459 return; 522 return;
460 523
461 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 524 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
462 "Host received modifier for _notice_place_leave message with ID %" PRIu64 ":\n" 525 "Host received modifier for _notice_place_leave message with ID %" PRIu64 ":\n"
463 "%c%s: %.*s\n", 526 "%c%s: %.*s\n",
464 message_id, oper, name, value_size, (const char *) value); 527 message_id, oper, name, value_size, (const char *) value);
@@ -485,7 +548,7 @@ host_recv_notice_place_leave_eom (void *cls,
485 return; 548 return;
486 549
487 char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&hst->notice_place_leave_nym->pub_key); 550 char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&hst->notice_place_leave_nym->pub_key);
488 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 551 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
489 "_notice_place_leave: got EOM from nym %s (%s).\n", 552 "_notice_place_leave: got EOM from nym %s (%s).\n",
490 GNUNET_h2s (&hst->notice_place_leave_nym->pub_key_hash), str); 553 GNUNET_h2s (&hst->notice_place_leave_nym->pub_key_hash), str);
491 GNUNET_free (str); 554 GNUNET_free (str);
@@ -1015,100 +1078,24 @@ handle_app_place_end (void *cls,
1015} 1078}
1016 1079
1017 1080
1018/*** CLEANUP / DISCONNECT ***/ 1081/**
1019 1082 * Handler for a #GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE_ACK message received
1020 1083 * from the social service.
1021static void 1084 *
1022host_cleanup (struct GNUNET_SOCIAL_Host *hst) 1085 * @param cls the place of type `struct GNUNET_SOCIAL_Place`
1023{ 1086 * @param msg the message received from the service
1024 if (NULL != hst->slicer) 1087 */
1025 {
1026 GNUNET_PSYC_slicer_destroy (hst->slicer);
1027 hst->slicer = NULL;
1028 }
1029 GNUNET_free (hst);
1030}
1031
1032
1033static void 1088static void
1034guest_cleanup (struct GNUNET_SOCIAL_Guest *gst) 1089handle_place_leave_ack (void *cls,
1090 const struct GNUNET_MessageHeader *msg)
1035{ 1091{
1036 GNUNET_free (gst); 1092 struct GNUNET_SOCIAL_Place *plc = cls;
1037}
1038
1039 1093
1040static void
1041place_cleanup (struct GNUNET_SOCIAL_Place *plc)
1042{
1043 struct GNUNET_HashCode place_pub_hash;
1044 GNUNET_CRYPTO_hash (&plc->pub_key, sizeof (plc->pub_key), &place_pub_hash);
1045 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1094 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1046 "%s place cleanup: %s\n", 1095 "%s left place %p\n",
1047 GNUNET_YES == plc->is_host ? "host" : "guest", 1096 plc->is_host ? "host" : "guest",
1048 GNUNET_h2s (&place_pub_hash)); 1097 plc);
1049 1098 place_disconnect (plc);
1050 if (NULL != plc->tmit)
1051 {
1052 GNUNET_PSYC_transmit_destroy (plc->tmit);
1053 plc->tmit = NULL;
1054 }
1055 if (NULL != plc->connect_env)
1056 {
1057 GNUNET_MQ_discard (plc->connect_env);
1058 plc->connect_env = NULL;
1059 }
1060 if (NULL != plc->mq)
1061 {
1062 GNUNET_MQ_destroy (plc->mq);
1063 plc->mq = NULL;
1064 }
1065 if (NULL != plc->disconnect_cb)
1066 {
1067 plc->disconnect_cb (plc->disconnect_cls);
1068 plc->disconnect_cb = NULL;
1069 }
1070
1071 (GNUNET_YES == plc->is_host)
1072 ? host_cleanup ((struct GNUNET_SOCIAL_Host *) plc)
1073 : guest_cleanup ((struct GNUNET_SOCIAL_Guest *) plc);
1074}
1075
1076
1077void
1078place_disconnect (struct GNUNET_SOCIAL_Place *plc,
1079 GNUNET_ContinuationCallback cb,
1080 void *cls)
1081{
1082 plc->disconnect_cb = cb;
1083 plc->disconnect_cls = cls;
1084
1085 if (NULL != plc->mq)
1086 {
1087 struct GNUNET_MQ_Envelope *env = GNUNET_MQ_get_last_envelope (plc->mq);
1088 if (NULL != env)
1089 {
1090 GNUNET_MQ_notify_sent (env, (GNUNET_SCHEDULER_TaskCallback) place_cleanup, plc);
1091 }
1092 else
1093 {
1094 place_cleanup (plc);
1095 }
1096 }
1097 else
1098 {
1099 place_cleanup (plc);
1100 }
1101}
1102
1103
1104void
1105place_leave (struct GNUNET_SOCIAL_Place *plc)
1106{
1107 struct GNUNET_MessageHeader *msg;
1108 struct GNUNET_MQ_Envelope *
1109 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE);
1110
1111 GNUNET_MQ_send (plc->mq, env);
1112} 1099}
1113 1100
1114 1101
@@ -1168,6 +1155,10 @@ host_connect (struct GNUNET_SOCIAL_Host *hst)
1168 GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER_ACK, 1155 GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER_ACK,
1169 struct HostEnterAck, 1156 struct HostEnterAck,
1170 hst), 1157 hst),
1158 GNUNET_MQ_hd_fixed_size (place_leave_ack,
1159 GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE_ACK,
1160 struct GNUNET_MessageHeader,
1161 plc),
1171 GNUNET_MQ_hd_var_size (host_enter_request, 1162 GNUNET_MQ_hd_var_size (host_enter_request,
1172 GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST, 1163 GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST,
1173 struct GNUNET_PSYC_JoinRequestMessage, 1164 struct GNUNET_PSYC_JoinRequestMessage,
@@ -1516,6 +1507,9 @@ GNUNET_SOCIAL_host_announce (struct GNUNET_SOCIAL_Host *hst,
1516 void *notify_data_cls, 1507 void *notify_data_cls,
1517 enum GNUNET_SOCIAL_AnnounceFlags flags) 1508 enum GNUNET_SOCIAL_AnnounceFlags flags)
1518{ 1509{
1510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1511 "PSYC_transmit_message for host, method: %s\n",
1512 method_name);
1519 if (GNUNET_OK == 1513 if (GNUNET_OK ==
1520 GNUNET_PSYC_transmit_message (hst->plc.tmit, method_name, env, 1514 GNUNET_PSYC_transmit_message (hst->plc.tmit, method_name, env,
1521 NULL, notify_data, notify_data_cls, flags)) 1515 NULL, notify_data, notify_data_cls, flags))
@@ -1580,7 +1574,11 @@ GNUNET_SOCIAL_host_disconnect (struct GNUNET_SOCIAL_Host *hst,
1580 GNUNET_ContinuationCallback disconnect_cb, 1574 GNUNET_ContinuationCallback disconnect_cb,
1581 void *cls) 1575 void *cls)
1582{ 1576{
1583 place_disconnect (&hst->plc, disconnect_cb, cls); 1577 struct GNUNET_SOCIAL_Place *plc = &hst->plc;
1578
1579 plc->disconnect_cb = disconnect_cb;
1580 plc->disconnect_cls = cls;
1581 place_disconnect (plc);
1584} 1582}
1585 1583
1586 1584
@@ -1607,10 +1605,15 @@ GNUNET_SOCIAL_host_leave (struct GNUNET_SOCIAL_Host *hst,
1607 GNUNET_ContinuationCallback disconnect_cb, 1605 GNUNET_ContinuationCallback disconnect_cb,
1608 void *cls) 1606 void *cls)
1609{ 1607{
1608 struct GNUNET_MQ_Envelope *envelope;
1609
1610 GNUNET_SOCIAL_host_announce (hst, "_notice_place_closing", env, NULL, NULL, 1610 GNUNET_SOCIAL_host_announce (hst, "_notice_place_closing", env, NULL, NULL,
1611 GNUNET_SOCIAL_ANNOUNCE_NONE); 1611 GNUNET_SOCIAL_ANNOUNCE_NONE);
1612 place_leave (&hst->plc); 1612 hst->plc.disconnect_cb = disconnect_cb;
1613 GNUNET_SOCIAL_host_disconnect (hst, disconnect_cb, cls); 1613 hst->plc.disconnect_cls = cls;
1614 envelope = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE);
1615 GNUNET_MQ_send (hst->plc.mq,
1616 envelope);
1614} 1617}
1615 1618
1616 1619
@@ -1670,6 +1673,10 @@ guest_connect (struct GNUNET_SOCIAL_Guest *gst)
1670 GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER_ACK, 1673 GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER_ACK,
1671 struct GNUNET_PSYC_CountersResultMessage, 1674 struct GNUNET_PSYC_CountersResultMessage,
1672 gst), 1675 gst),
1676 GNUNET_MQ_hd_fixed_size (place_leave_ack,
1677 GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE_ACK,
1678 struct GNUNET_MessageHeader,
1679 plc),
1673 GNUNET_MQ_hd_var_size (guest_enter_decision, 1680 GNUNET_MQ_hd_var_size (guest_enter_decision,
1674 GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION, 1681 GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION,
1675 struct GNUNET_PSYC_JoinDecisionMessage, 1682 struct GNUNET_PSYC_JoinDecisionMessage,
@@ -1896,6 +1903,64 @@ GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_SOCIAL_App *app,
1896} 1903}
1897 1904
1898 1905
1906struct ReconnectContext
1907{
1908 struct GNUNET_SOCIAL_Guest *guest;
1909 int *result;
1910 int64_t *max_message_id;
1911 GNUNET_SOCIAL_GuestEnterCallback enter_cb;
1912 void *enter_cls;
1913};
1914
1915
1916static void
1917guest_enter_reconnect_cb (void *cls,
1918 int result,
1919 const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
1920 uint64_t max_message_id)
1921{
1922 struct ReconnectContext *reconnect_ctx = cls;
1923
1924 GNUNET_assert (NULL != reconnect_ctx);
1925 reconnect_ctx->result = GNUNET_new (int);
1926 *(reconnect_ctx->result) = result;
1927 reconnect_ctx->max_message_id = GNUNET_new (int64_t);
1928 *(reconnect_ctx->max_message_id) = max_message_id;
1929}
1930
1931
1932static void
1933guest_entry_dcsn_reconnect_cb (void *cls,
1934 int is_admitted,
1935 const struct GNUNET_PSYC_Message *entry_resp)
1936{
1937 struct ReconnectContext *reconnect_ctx = cls;
1938 struct GNUNET_SOCIAL_Guest *gst = reconnect_ctx->guest;
1939
1940 GNUNET_assert (NULL != reconnect_ctx);
1941 GNUNET_assert (NULL != reconnect_ctx->result);
1942 GNUNET_assert (NULL != reconnect_ctx->max_message_id);
1943 if (GNUNET_YES != is_admitted)
1944 {
1945 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1946 "Guest was rejected after calling "
1947 "GNUNET_SOCIAL_guest_enter_reconnect ()\n");
1948 }
1949 else if (NULL != reconnect_ctx->enter_cb)
1950 {
1951 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1952 "guest reconnected!\n");
1953 reconnect_ctx->enter_cb (reconnect_ctx->enter_cls,
1954 *(reconnect_ctx->result),
1955 &gst->plc.pub_key,
1956 *(reconnect_ctx->max_message_id));
1957 }
1958 GNUNET_free (reconnect_ctx->result);
1959 GNUNET_free (reconnect_ctx->max_message_id);
1960 GNUNET_free (reconnect_ctx);
1961}
1962
1963
1899/** 1964/**
1900 * Reconnect to an already entered place as guest. 1965 * Reconnect to an already entered place as guest.
1901 * 1966 *
@@ -1906,8 +1971,8 @@ GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_SOCIAL_App *app,
1906 * Flags for the entry. 1971 * Flags for the entry.
1907 * @param slicer 1972 * @param slicer
1908 * Slicer to use for processing incoming requests from guests. 1973 * Slicer to use for processing incoming requests from guests.
1909 * @param local_enter_cb 1974 * @param enter_cb
1910 * Called upon connection established to the social service. 1975 * Called upon re-entering is complete.
1911 * @param entry_decision_cb 1976 * @param entry_decision_cb
1912 * Called upon receiving entry decision. 1977 * Called upon receiving entry decision.
1913 * 1978 *
@@ -1917,11 +1982,12 @@ struct GNUNET_SOCIAL_Guest *
1917GNUNET_SOCIAL_guest_enter_reconnect (struct GNUNET_SOCIAL_GuestConnection *gconn, 1982GNUNET_SOCIAL_guest_enter_reconnect (struct GNUNET_SOCIAL_GuestConnection *gconn,
1918 enum GNUNET_PSYC_SlaveJoinFlags flags, 1983 enum GNUNET_PSYC_SlaveJoinFlags flags,
1919 struct GNUNET_PSYC_Slicer *slicer, 1984 struct GNUNET_PSYC_Slicer *slicer,
1920 GNUNET_SOCIAL_GuestEnterCallback local_enter_cb, 1985 GNUNET_SOCIAL_GuestEnterCallback enter_cb,
1921 void *cls) 1986 void *cls)
1922{ 1987{
1923 struct GNUNET_SOCIAL_Guest *gst = GNUNET_malloc (sizeof (*gst)); 1988 struct GNUNET_SOCIAL_Guest *gst = GNUNET_malloc (sizeof (*gst));
1924 struct GNUNET_SOCIAL_Place *plc = &gst->plc; 1989 struct GNUNET_SOCIAL_Place *plc = &gst->plc;
1990 struct ReconnectContext *reconnect_ctx;
1925 1991
1926 uint16_t app_id_size = strlen (gconn->app->id) + 1; 1992 uint16_t app_id_size = strlen (gconn->app->id) + 1;
1927 struct GuestEnterRequest *greq; 1993 struct GuestEnterRequest *greq;
@@ -1940,10 +2006,15 @@ GNUNET_SOCIAL_guest_enter_reconnect (struct GNUNET_SOCIAL_GuestConnection *gconn
1940 plc->pub_key = gconn->plc_msg.place_pub_key; 2006 plc->pub_key = gconn->plc_msg.place_pub_key;
1941 plc->ego_pub_key = gconn->plc_msg.ego_pub_key; 2007 plc->ego_pub_key = gconn->plc_msg.ego_pub_key;
1942 2008
1943 plc->op = GNUNET_OP_create (); 2009 reconnect_ctx = GNUNET_new (struct ReconnectContext);
2010 reconnect_ctx->guest = gst;
2011 reconnect_ctx->enter_cb = enter_cb;
2012 reconnect_ctx->enter_cls = cls;
1944 2013
1945 gst->enter_cb = local_enter_cb; 2014 plc->op = GNUNET_OP_create ();
1946 gst->cb_cls = cls; 2015 gst->enter_cb = &guest_enter_reconnect_cb;
2016 gst->entry_dcsn_cb = &guest_entry_dcsn_reconnect_cb;
2017 gst->cb_cls = reconnect_ctx;
1947 2018
1948 guest_connect (gst); 2019 guest_connect (gst);
1949 return gst; 2020 return gst;
@@ -2028,7 +2099,11 @@ GNUNET_SOCIAL_guest_disconnect (struct GNUNET_SOCIAL_Guest *gst,
2028 GNUNET_ContinuationCallback disconnect_cb, 2099 GNUNET_ContinuationCallback disconnect_cb,
2029 void *cls) 2100 void *cls)
2030{ 2101{
2031 place_disconnect (&gst->plc, disconnect_cb, cls); 2102 struct GNUNET_SOCIAL_Place *plc = &gst->plc;
2103
2104 plc->disconnect_cb = disconnect_cb;
2105 plc->disconnect_cls = cls;
2106 place_disconnect (plc);
2032} 2107}
2033 2108
2034 2109
@@ -2054,10 +2129,15 @@ GNUNET_SOCIAL_guest_leave (struct GNUNET_SOCIAL_Guest *gst,
2054 GNUNET_ContinuationCallback disconnect_cb, 2129 GNUNET_ContinuationCallback disconnect_cb,
2055 void *cls) 2130 void *cls)
2056{ 2131{
2132 struct GNUNET_MQ_Envelope *envelope;
2133
2057 GNUNET_SOCIAL_guest_talk (gst, "_notice_place_leave", env, NULL, NULL, 2134 GNUNET_SOCIAL_guest_talk (gst, "_notice_place_leave", env, NULL, NULL,
2058 GNUNET_SOCIAL_TALK_NONE); 2135 GNUNET_SOCIAL_TALK_NONE);
2059 place_leave (&gst->plc); 2136 gst->plc.disconnect_cb = disconnect_cb;
2060 GNUNET_SOCIAL_guest_disconnect (gst, disconnect_cb, cls); 2137 gst->plc.disconnect_cls = cls;
2138 envelope = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE);
2139 GNUNET_MQ_send (gst->plc.mq,
2140 envelope);
2061} 2141}
2062 2142
2063 2143
diff --git a/src/social/test_social.c b/src/social/test_social.c
index 64ef10125..4d95cf005 100644
--- a/src/social/test_social.c
+++ b/src/social/test_social.c
@@ -129,22 +129,22 @@ enum
129 TEST_HOST_ANSWER_DOOR_REFUSE = 4, 129 TEST_HOST_ANSWER_DOOR_REFUSE = 4,
130 TEST_GUEST_RECV_ENTRY_DCSN_REFUSE = 5, 130 TEST_GUEST_RECV_ENTRY_DCSN_REFUSE = 5,
131 TEST_HOST_ANSWER_DOOR_ADMIT = 6, 131 TEST_HOST_ANSWER_DOOR_ADMIT = 6,
132 TEST_GUEST_RECV_ENTRY_DCSN_ADMIT = 9, 132 TEST_GUEST_RECV_ENTRY_DCSN_ADMIT = 7,
133 TEST_HOST_ANNOUNCE = 10, 133 TEST_HOST_ANNOUNCE = 8,
134 TEST_HOST_ANNOUNCE_END = 11, 134 TEST_HOST_ANNOUNCE_END = 9,
135 TEST_GUEST_TALK = 12, 135 TEST_GUEST_TALK = 10,
136 TEST_HOST_ANNOUNCE2 = 13, 136 TEST_HOST_ANNOUNCE2 = 11,
137 TEST_HOST_ANNOUNCE2_END = 14, 137 TEST_HOST_ANNOUNCE2_END = 12,
138 TEST_GUEST_HISTORY_REPLAY = 15, 138 TEST_GUEST_HISTORY_REPLAY = 13,
139 TEST_GUEST_HISTORY_REPLAY_LATEST = 16, 139 TEST_GUEST_HISTORY_REPLAY_LATEST = 14,
140 TEST_GUEST_LOOK_AT = 17, 140 TEST_GUEST_LOOK_AT = 15,
141 TEST_GUEST_LOOK_FOR = 18, 141 TEST_GUEST_LOOK_FOR = 16,
142 TEST_GUEST_LEAVE = 18, 142 TEST_GUEST_LEAVE = 17,
143 TEST_ZONE_ADD_PLACE = 20, 143 TEST_ZONE_ADD_PLACE = 18,
144 TEST_GUEST_ENTER_BY_NAME = 21, 144 TEST_GUEST_ENTER_BY_NAME = 19,
145 TEST_RECONNECT = 22, 145 TEST_RECONNECT = 20,
146 TEST_GUEST_LEAVE2 = 23, 146 TEST_GUEST_LEAVE2 = 21,
147 TEST_HOST_LEAVE = 24, 147 TEST_HOST_LEAVE = 22,
148} test; 148} test;
149 149
150 150
@@ -180,10 +180,28 @@ host_announce2 ();
180 180
181 181
182/** 182/**
183 * Clean up all resources used. 183 * Terminate the test case (failure).
184 *
185 * @param cls NULL
186 */
187static void
188end_badly (void *cls)
189{
190 end_badly_task = NULL;
191 GNUNET_SCHEDULER_shutdown ();
192 res = 2;
193 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
194 "Test FAILED.\n");
195}
196
197
198/**
199 * Terminate the test case (failure).
200 *
201 * @param cls NULL
184 */ 202 */
185static void 203static void
186cleanup () 204end_shutdown (void *cls)
187{ 205{
188 if (NULL != id) 206 if (NULL != id)
189 { 207 {
@@ -202,7 +220,11 @@ cleanup ()
202 GNUNET_PSYC_slicer_destroy (host_slicer); 220 GNUNET_PSYC_slicer_destroy (host_slicer);
203 host_slicer = NULL; 221 host_slicer = NULL;
204 } 222 }
205 223 if (NULL != end_badly_task)
224 {
225 GNUNET_SCHEDULER_cancel (end_badly_task);
226 end_badly_task = NULL;
227 }
206 if (NULL != gst) 228 if (NULL != gst)
207 { 229 {
208 GNUNET_SOCIAL_guest_leave (gst, NULL, NULL, NULL); 230 GNUNET_SOCIAL_guest_leave (gst, NULL, NULL, NULL);
@@ -216,21 +238,6 @@ cleanup ()
216 hst_plc = NULL; 238 hst_plc = NULL;
217 } 239 }
218 GNUNET_SOCIAL_app_disconnect (app, NULL, NULL); 240 GNUNET_SOCIAL_app_disconnect (app, NULL, NULL);
219 GNUNET_SCHEDULER_shutdown ();
220}
221
222
223/**
224 * Terminate the test case (failure).
225 *
226 * @param cls NULL
227 */
228static void
229end_badly (void *cls)
230{
231 res = 1;
232 cleanup ();
233 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test FAILED.\n");
234} 241}
235 242
236 243
@@ -242,9 +249,9 @@ end_badly (void *cls)
242static void 249static void
243end_normally (void *cls) 250end_normally (void *cls)
244{ 251{
252 GNUNET_SCHEDULER_shutdown ();
245 res = 0; 253 res = 0;
246 cleanup (); 254 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Test PASSED.\n");
247 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test PASSED.\n");
248} 255}
249 256
250 257
@@ -254,7 +261,7 @@ end_normally (void *cls)
254static void 261static void
255end () 262end ()
256{ 263{
257 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 264 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
258 "Test #%u: Ending tests.\n", test); 265 "Test #%u: Ending tests.\n", test);
259 266
260 if (end_badly_task != NULL) 267 if (end_badly_task != NULL)
@@ -271,7 +278,7 @@ transmit_resume (void *cls)
271{ 278{
272 struct TransmitClosure *tmit = cls; 279 struct TransmitClosure *tmit = cls;
273 280
274 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 281 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
275 "Test #%u: Transmission resumed.\n", test); 282 "Test #%u: Transmission resumed.\n", test);
276 if (NULL != tmit->host_ann) 283 if (NULL != tmit->host_ann)
277 GNUNET_SOCIAL_host_announce_resume (tmit->host_ann); 284 GNUNET_SOCIAL_host_announce_resume (tmit->host_ann);
@@ -296,7 +303,7 @@ notify_data (void *cls, uint16_t *data_size, void *data)
296 } 303 }
297 304
298 uint16_t size = strlen (tmit->data[tmit->n]); 305 uint16_t size = strlen (tmit->data[tmit->n]);
299 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 306 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
300 "Test #%u: Transmit notify data: %u bytes available, " 307 "Test #%u: Transmit notify data: %u bytes available, "
301 "processing fragment %u/%u (size %u).\n", 308 "processing fragment %u/%u (size %u).\n",
302 test, *data_size, tmit->n + 1, tmit->data_count, size); 309 test, *data_size, tmit->n + 1, tmit->data_count, size);
@@ -309,7 +316,7 @@ notify_data (void *cls, uint16_t *data_size, void *data)
309 316
310 if (GNUNET_YES != tmit->paused && 0 < tmit->data_delay[tmit->n]) 317 if (GNUNET_YES != tmit->paused && 0 < tmit->data_delay[tmit->n])
311 { 318 {
312 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 319 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
313 "Test #%u: Transmission paused.\n", test); 320 "Test #%u: Transmission paused.\n", test);
314 tmit->paused = GNUNET_YES; 321 tmit->paused = GNUNET_YES;
315 GNUNET_SCHEDULER_add_delayed ( 322 GNUNET_SCHEDULER_add_delayed (
@@ -331,7 +338,7 @@ notify_data (void *cls, uint16_t *data_size, void *data)
331static void 338static void
332host_left () 339host_left ()
333{ 340{
334 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 341 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
335 "Test #%u: The host has left the place.\n", test); 342 "Test #%u: The host has left the place.\n", test);
336 end (); 343 end ();
337} 344}
@@ -352,7 +359,7 @@ host_farewell2 (void *cls,
352 const struct GNUNET_SOCIAL_Nym *nym, 359 const struct GNUNET_SOCIAL_Nym *nym,
353 struct GNUNET_PSYC_Environment *env) 360 struct GNUNET_PSYC_Environment *env)
354{ 361{
355 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 362 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
356 "Nym left the place again.\n"); 363 "Nym left the place again.\n");
357 GNUNET_SCHEDULER_add_now (&schedule_host_leave, NULL); 364 GNUNET_SCHEDULER_add_now (&schedule_host_leave, NULL);
358} 365}
@@ -365,13 +372,14 @@ host_reconnected (void *cls, int result,
365{ 372{
366 place_pub_key = *home_pub_key; 373 place_pub_key = *home_pub_key;
367 GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash); 374 GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash);
368 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 375 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
369 "Test #%u: Host reconnected to place %s\n", 376 "Test #%u: Host reconnected to place %s\n",
370 test, GNUNET_h2s (&place_pub_hash)); 377 test, GNUNET_h2s (&place_pub_hash));
371 378
372 is_host_reconnected = GNUNET_YES; 379 is_host_reconnected = GNUNET_YES;
373 if (GNUNET_YES == is_guest_reconnected) 380 if (GNUNET_YES == is_guest_reconnected)
374 { 381 {
382 GNUNET_assert (NULL != gst);
375 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL); 383 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
376 } 384 }
377} 385}
@@ -382,7 +390,7 @@ guest_reconnected (void *cls, int result,
382 const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key, 390 const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
383 uint64_t max_message_id) 391 uint64_t max_message_id)
384{ 392{
385 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 393 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
386 "Test #%u: Guest reconnected to place: %d\n", 394 "Test #%u: Guest reconnected to place: %d\n",
387 test, result); 395 test, result);
388 GNUNET_assert (0 <= result); 396 GNUNET_assert (0 <= result);
@@ -390,6 +398,7 @@ guest_reconnected (void *cls, int result,
390 is_guest_reconnected = GNUNET_YES; 398 is_guest_reconnected = GNUNET_YES;
391 if (GNUNET_YES == is_host_reconnected) 399 if (GNUNET_YES == is_host_reconnected)
392 { 400 {
401 GNUNET_assert (NULL != gst);
393 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL); 402 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
394 } 403 }
395} 404}
@@ -398,7 +407,7 @@ guest_reconnected (void *cls, int result,
398static void 407static void
399app_connected (void *cls) 408app_connected (void *cls)
400{ 409{
401 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 410 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
402 "Test #%u: App connected: %p\n", test, cls); 411 "Test #%u: App connected: %p\n", test, cls);
403} 412}
404 413
@@ -411,21 +420,28 @@ app_recv_host (void *cls,
411 enum GNUNET_SOCIAL_AppPlaceState place_state) 420 enum GNUNET_SOCIAL_AppPlaceState place_state)
412{ 421{
413 struct GNUNET_HashCode host_pub_hash; 422 struct GNUNET_HashCode host_pub_hash;
414 GNUNET_CRYPTO_hash (host_pub_key, sizeof (*host_pub_key), &host_pub_hash);
415 423
416 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 424 GNUNET_CRYPTO_hash (host_pub_key,
425 sizeof (*host_pub_key),
426 &host_pub_hash);
427
428 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
417 "Test #%u: Got app host place notification: %s\n", 429 "Test #%u: Got app host place notification: %s\n",
418 test, GNUNET_h2s (&host_pub_hash)); 430 test,
431 GNUNET_h2s (&host_pub_hash));
419 432
420 if (test == TEST_RECONNECT) 433 if (test == TEST_RECONNECT)
421 { 434 {
422 if (0 == memcmp (&place_pub_key, host_pub_key, sizeof (*host_pub_key))) 435 if (0 == memcmp (&place_pub_key, host_pub_key, sizeof (*host_pub_key)))
423 { 436 {
424 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 437 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
425 "Test #%u: Reconnecting to host place: %s\n", 438 "Test #%u: Reconnecting to host place: %s\n",
426 test, GNUNET_h2s (&host_pub_hash)); 439 test, GNUNET_h2s (&host_pub_hash));
427 hst = GNUNET_SOCIAL_host_enter_reconnect (hconn, host_slicer, host_reconnected, 440 hst = GNUNET_SOCIAL_host_enter_reconnect (hconn, host_slicer,
428 host_answer_door, host_farewell2, NULL); 441 &host_reconnected,
442 &host_answer_door,
443 &host_farewell2,
444 NULL);
429 } 445 }
430 } 446 }
431} 447}
@@ -439,21 +455,30 @@ app_recv_guest (void *cls,
439 enum GNUNET_SOCIAL_AppPlaceState place_state) 455 enum GNUNET_SOCIAL_AppPlaceState place_state)
440{ 456{
441 struct GNUNET_HashCode guest_pub_hash; 457 struct GNUNET_HashCode guest_pub_hash;
442 GNUNET_CRYPTO_hash (guest_pub_key, sizeof (*guest_pub_key), &guest_pub_hash);
443 458
444 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 459 GNUNET_CRYPTO_hash (guest_pub_key,
460 sizeof (*guest_pub_key),
461 &guest_pub_hash);
462
463 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
445 "Test #%u: Got app guest place notification: %s\n", 464 "Test #%u: Got app guest place notification: %s\n",
446 test, GNUNET_h2s (&guest_pub_hash)); 465 test, GNUNET_h2s (&guest_pub_hash));
447 466
448 if (test == TEST_RECONNECT) 467 if (test == TEST_RECONNECT)
449 { 468 {
450 if (0 == memcmp (&place_pub_key, guest_pub_key, sizeof (*guest_pub_key))) 469 if (0 == memcmp (&place_pub_key,
470 guest_pub_key,
471 sizeof (*guest_pub_key)))
451 { 472 {
452 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 473 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
453 "Test #%u: Reconnecting to guest place: %s\n", 474 "Test #%u: Reconnecting to guest place: %s\n",
454 test, GNUNET_h2s (&guest_pub_hash)); 475 test, GNUNET_h2s (&guest_pub_hash));
455 gst = GNUNET_SOCIAL_guest_enter_reconnect (gconn, GNUNET_PSYC_SLAVE_JOIN_NONE, 476 gst = GNUNET_SOCIAL_guest_enter_reconnect (gconn,
456 guest_slicer, guest_reconnected, NULL); 477 GNUNET_PSYC_SLAVE_JOIN_NONE,
478 guest_slicer,
479 &guest_reconnected,
480 NULL);
481 GNUNET_assert (NULL != gst);
457 } 482 }
458 } 483 }
459} 484}
@@ -478,7 +503,7 @@ app_recv_ego (void *cls,
478 const char *name) 503 const char *name)
479{ 504{
480 char *ego_pub_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (ego_pub_key); 505 char *ego_pub_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (ego_pub_key);
481 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 506 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
482 "Test #%u: Got app ego notification: %p %s %s\n", 507 "Test #%u: Got app ego notification: %p %s %s\n",
483 test, ego, name, ego_pub_str); 508 test, ego, name, ego_pub_str);
484 GNUNET_free (ego_pub_str); 509 GNUNET_free (ego_pub_str);
@@ -487,15 +512,30 @@ app_recv_ego (void *cls,
487 { 512 {
488 host_ego = ego; 513 host_ego = ego;
489 host_pub_key = ego_pub_key; 514 host_pub_key = ego_pub_key;
490 GNUNET_assert (TEST_IDENTITIES_CREATE == test); 515 if (TEST_IDENTITIES_CREATE == test)
491 enter_if_ready (); 516 {
517 enter_if_ready ();
518 }
519 else
520 {
521 GNUNET_assert (TEST_RECONNECT == test);
522 }
492 } 523 }
493 else if (NULL != strstr (name, guest_name)) 524 else if (NULL != strstr (name, guest_name))
494 { 525 {
495 guest_ego = ego; 526 guest_ego = ego;
496 guest_pub_key = ego_pub_key; 527 guest_pub_key = ego_pub_key;
497 GNUNET_assert (TEST_IDENTITIES_CREATE == test); 528 if (TEST_IDENTITIES_CREATE == test)
498 enter_if_ready (); 529 {
530 enter_if_ready ();
531 }
532 else
533 {
534 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
535 "test = %d\n",
536 test);
537 GNUNET_assert (TEST_RECONNECT == test);
538 }
499 } 539 }
500} 540}
501 541
@@ -504,7 +544,6 @@ static void
504schedule_reconnect (void *cls) 544schedule_reconnect (void *cls)
505{ 545{
506 test = TEST_RECONNECT; 546 test = TEST_RECONNECT;
507
508 GNUNET_SOCIAL_host_disconnect (hst, NULL, NULL); 547 GNUNET_SOCIAL_host_disconnect (hst, NULL, NULL);
509 GNUNET_SOCIAL_guest_disconnect (gst, NULL, NULL); 548 GNUNET_SOCIAL_guest_disconnect (gst, NULL, NULL);
510 hst = NULL; 549 hst = NULL;
@@ -512,10 +551,10 @@ schedule_reconnect (void *cls)
512 551
513 GNUNET_SOCIAL_app_disconnect (app, NULL, NULL); 552 GNUNET_SOCIAL_app_disconnect (app, NULL, NULL);
514 app = GNUNET_SOCIAL_app_connect (cfg, app_id, 553 app = GNUNET_SOCIAL_app_connect (cfg, app_id,
515 app_recv_ego, 554 &app_recv_ego,
516 app_recv_host, 555 &app_recv_host,
517 app_recv_guest, 556 &app_recv_guest,
518 app_connected, 557 &app_connected,
519 NULL); 558 NULL);
520} 559}
521 560
@@ -524,7 +563,7 @@ static void
524host_recv_zone_add_place_result (void *cls, int64_t result, 563host_recv_zone_add_place_result (void *cls, int64_t result,
525 const void *data, uint16_t data_size) 564 const void *data, uint16_t data_size)
526{ 565{
527 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 566 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
528 "Test #%u: Zone add place result: %" PRId64 " (%.*s).\n", 567 "Test #%u: Zone add place result: %" PRId64 " (%.*s).\n",
529 test, result, data_size, (const char *) data); 568 test, result, data_size, (const char *) data);
530 GNUNET_assert (GNUNET_YES == result); 569 GNUNET_assert (GNUNET_YES == result);
@@ -538,7 +577,7 @@ static void
538zone_add_place () 577zone_add_place ()
539{ 578{
540 test = TEST_ZONE_ADD_PLACE; 579 test = TEST_ZONE_ADD_PLACE;
541 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 580 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
542 "Test #%u: Adding place to zone.\n", test); 581 "Test #%u: Adding place to zone.\n", test);
543 582
544 GNUNET_SOCIAL_zone_add_place (app, host_ego, "home", "let.me*in!", 583 GNUNET_SOCIAL_zone_add_place (app, host_ego, "home", "let.me*in!",
@@ -557,7 +596,7 @@ host_farewell (void *cls,
557 nym_key = GNUNET_SOCIAL_nym_get_pub_key (nym); 596 nym_key = GNUNET_SOCIAL_nym_get_pub_key (nym);
558 597
559 char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key); 598 char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key);
560 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 599 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
561 "Test #%u: Farewell: nym %s (%s) has left the place.\n", 600 "Test #%u: Farewell: nym %s (%s) has left the place.\n",
562 test, GNUNET_h2s (GNUNET_SOCIAL_nym_get_pub_key_hash (nym)), str); 601 test, GNUNET_h2s (GNUNET_SOCIAL_nym_get_pub_key_hash (nym)), str);
563 GNUNET_free (str); 602 GNUNET_free (str);
@@ -578,13 +617,13 @@ host_farewell (void *cls,
578static void 617static void
579guest_left (void *cls) 618guest_left (void *cls)
580{ 619{
581 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 620 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
582 "Test #%u: The guest has left the place.\n", test); 621 "Test #%u: The guest has left the place.\n", test);
583} 622}
584 623
585 624
586static void 625static void
587guest_leave() 626guest_leave ()
588{ 627{
589 if (test < TEST_RECONNECT) 628 if (test < TEST_RECONNECT)
590 test = TEST_GUEST_LEAVE; 629 test = TEST_GUEST_LEAVE;
@@ -615,11 +654,11 @@ guest_look_for_result (void *cls,
615 uint16_t data_size) 654 uint16_t data_size)
616{ 655{
617 struct ResultClosure *rcls = cls; 656 struct ResultClosure *rcls = cls;
618 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 657 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
619 "Test #%u: guest_look_for_result: %" PRId64 "\n", 658 "Test #%u: guest_look_for_result: %" PRId64 "\n",
620 test, result_code); 659 test, result_code);
621 GNUNET_assert (GNUNET_OK == result_code); 660 GNUNET_assert (GNUNET_OK == result_code);
622 GNUNET_assert (3 == rcls->n); 661 GNUNET_assert (6 == rcls->n);
623 GNUNET_free (rcls); 662 GNUNET_free (rcls);
624 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL); 663 GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
625} 664}
@@ -635,7 +674,7 @@ guest_look_for_var (void *cls,
635{ 674{
636 struct ResultClosure *rcls = cls; 675 struct ResultClosure *rcls = cls;
637 rcls->n++; 676 rcls->n++;
638 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 677 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
639 "Test #%u: guest_look_for_var: %s\n%.*s\n", 678 "Test #%u: guest_look_for_var: %s\n%.*s\n",
640 test, name, value_size, (const char *) value); 679 test, name, value_size, (const char *) value);
641} 680}
@@ -656,7 +695,7 @@ guest_look_at_result (void *cls, int64_t result_code,
656{ 695{
657 struct ResultClosure *rcls = cls; 696 struct ResultClosure *rcls = cls;
658 697
659 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 698 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
660 "Test #%u: guest_look_at_result: %" PRId64 "\n", 699 "Test #%u: guest_look_at_result: %" PRId64 "\n",
661 test, result_code); 700 test, result_code);
662 GNUNET_assert (GNUNET_OK == result_code); 701 GNUNET_assert (GNUNET_OK == result_code);
@@ -677,7 +716,7 @@ guest_look_at_var (void *cls,
677 struct ResultClosure *rcls = cls; 716 struct ResultClosure *rcls = cls;
678 rcls->n++; 717 rcls->n++;
679 718
680 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 719 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
681 "Test #%u: guest_look_at_var: %s\n%.*s\n", 720 "Test #%u: guest_look_at_var: %s\n%.*s\n",
682 test ,name, value_size, (const char *) value); 721 test ,name, value_size, (const char *) value);
683} 722}
@@ -696,7 +735,7 @@ static void
696guest_recv_history_replay_latest_result (void *cls, int64_t result, 735guest_recv_history_replay_latest_result (void *cls, int64_t result,
697 const void *data, uint16_t data_size) 736 const void *data, uint16_t data_size)
698{ 737{
699 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 738 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
700 "Test #%u: Guest received latest history replay result " 739 "Test #%u: Guest received latest history replay result "
701 "(%" PRIu32 " messages, %" PRId64 " fragments):\n" 740 "(%" PRIu32 " messages, %" PRId64 " fragments):\n"
702 "%.*s\n", 741 "%.*s\n",
@@ -725,7 +764,7 @@ static void
725guest_recv_history_replay_result (void *cls, int64_t result, 764guest_recv_history_replay_result (void *cls, int64_t result,
726 const void *data, uint16_t data_size) 765 const void *data, uint16_t data_size)
727{ 766{
728 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 767 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
729 "Test #%u: Guest received history replay result: %" PRId64 "\n" 768 "Test #%u: Guest received history replay result: %" PRId64 "\n"
730 "%.*s\n", 769 "%.*s\n",
731 test, result, data_size, (const char *) data); 770 test, result, data_size, (const char *) data);
@@ -756,7 +795,7 @@ guest_recv_method (void *cls,
756 uint64_t message_id, 795 uint64_t message_id,
757 const char *method_name) 796 const char *method_name)
758{ 797{
759 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 798 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
760 "Test #%u: Guest received method for message ID %" PRIu64 ":\n" 799 "Test #%u: Guest received method for message ID %" PRIu64 ":\n"
761 "%s (flags: %x)\n", 800 "%s (flags: %x)\n",
762 test, message_id, method_name, ntohl (meth->flags)); 801 test, message_id, method_name, ntohl (meth->flags));
@@ -775,7 +814,7 @@ guest_recv_modifier (void *cls,
775 uint16_t value_size, 814 uint16_t value_size,
776 uint16_t full_value_size) 815 uint16_t full_value_size)
777{ 816{
778 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 817 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
779 "Test #%u: Guest received modifier for message ID %" PRIu64 ":\n" 818 "Test #%u: Guest received modifier for message ID %" PRIu64 ":\n"
780 "%c%s: %.*s (size: %u)\n", 819 "%c%s: %.*s (size: %u)\n",
781 test, message_id, oper, name, value_size, (const char *) value, value_size); 820 test, message_id, oper, name, value_size, (const char *) value, value_size);
@@ -793,7 +832,7 @@ guest_recv_mod_foo_bar (void *cls,
793 uint16_t value_size, 832 uint16_t value_size,
794 uint16_t full_value_size) 833 uint16_t full_value_size)
795{ 834{
796 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 835 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
797 "Test #%u: Guest received modifier matching _foo_bar for message ID %" PRIu64 ":\n" 836 "Test #%u: Guest received modifier matching _foo_bar for message ID %" PRIu64 ":\n"
798 "%c%s: %.*s (size: %u)\n", 837 "%c%s: %.*s (size: %u)\n",
799 test, message_id, oper, name, value_size, (const char *) value, value_size); 838 test, message_id, oper, name, value_size, (const char *) value, value_size);
@@ -811,7 +850,7 @@ guest_recv_data (void *cls,
811 const void *data, 850 const void *data,
812 uint16_t data_size) 851 uint16_t data_size)
813{ 852{
814 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 853 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
815 "Test #%u: Guest received data for message ID %" PRIu64 ":\n" 854 "Test #%u: Guest received data for message ID %" PRIu64 ":\n"
816 "%.*s\n", 855 "%.*s\n",
817 test, message_id, data_size, (const char *) data); 856 test, message_id, data_size, (const char *) data);
@@ -826,7 +865,7 @@ guest_recv_eom (void *cls,
826 uint64_t message_id, 865 uint64_t message_id,
827 uint8_t is_cancelled) 866 uint8_t is_cancelled)
828{ 867{
829 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 868 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
830 "Test #%u: Guest received end of message ID %" PRIu64 869 "Test #%u: Guest received end of message ID %" PRIu64
831 ", cancelled: %u\n", 870 ", cancelled: %u\n",
832 test, message_id, is_cancelled); 871 test, message_id, is_cancelled);
@@ -868,7 +907,7 @@ host_recv_method (void *cls,
868 uint64_t message_id, 907 uint64_t message_id,
869 const char *method_name) 908 const char *method_name)
870{ 909{
871 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 910 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
872 "Test #%u: Host received method for message ID %" PRIu64 ":\n" 911 "Test #%u: Host received method for message ID %" PRIu64 ":\n"
873 "%s\n", 912 "%s\n",
874 test, message_id, method_name); 913 test, message_id, method_name);
@@ -887,7 +926,7 @@ host_recv_modifier (void *cls,
887 uint16_t value_size, 926 uint16_t value_size,
888 uint16_t full_value_size) 927 uint16_t full_value_size)
889{ 928{
890 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 929 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
891 "Test #%u: Host received modifier for message ID %" PRIu64 ":\n" 930 "Test #%u: Host received modifier for message ID %" PRIu64 ":\n"
892 "%c%s: %.*s\n", 931 "%c%s: %.*s\n",
893 test, message_id, oper, name, value_size, (const char *) value); 932 test, message_id, oper, name, value_size, (const char *) value);
@@ -902,7 +941,7 @@ host_recv_data (void *cls,
902 const void *data, 941 const void *data,
903 uint16_t data_size) 942 uint16_t data_size)
904{ 943{
905 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 944 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
906 "Test #%u: Host received data for message ID %" PRIu64 ":\n" 945 "Test #%u: Host received data for message ID %" PRIu64 ":\n"
907 "%.*s\n", 946 "%.*s\n",
908 test, message_id, data_size, (const char *) data); 947 test, message_id, data_size, (const char *) data);
@@ -916,7 +955,7 @@ host_recv_eom (void *cls,
916 uint64_t message_id, 955 uint64_t message_id,
917 uint8_t is_cancelled) 956 uint8_t is_cancelled)
918{ 957{
919 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 958 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
920 "Test #%u: Host received end of message ID %" PRIu64 959 "Test #%u: Host received end of message ID %" PRIu64
921 ", cancelled: %u\n", 960 ", cancelled: %u\n",
922 test, message_id, is_cancelled); 961 test, message_id, is_cancelled);
@@ -981,7 +1020,7 @@ host_announce ()
981{ 1020{
982 test = TEST_HOST_ANNOUNCE; 1021 test = TEST_HOST_ANNOUNCE;
983 1022
984 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1023 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
985 "Test #%u: Host announcement.\n", test); 1024 "Test #%u: Host announcement.\n", test);
986 1025
987 tmit = (struct TransmitClosure) {}; 1026 tmit = (struct TransmitClosure) {};
@@ -1015,7 +1054,7 @@ host_announce2 ()
1015 1054
1016 test = TEST_HOST_ANNOUNCE2; 1055 test = TEST_HOST_ANNOUNCE2;
1017 1056
1018 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1057 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1019 "Test #%u: Host announcement 2.\n", test); 1058 "Test #%u: Host announcement 2.\n", test);
1020 1059
1021 tmit = (struct TransmitClosure) {}; 1060 tmit = (struct TransmitClosure) {};
@@ -1025,7 +1064,7 @@ host_announce2 ()
1025 GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN, 1064 GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
1026 "_foo2_bar", DATA2ARG ("FOO BAR")); 1065 "_foo2_bar", DATA2ARG ("FOO BAR"));
1027 GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN, 1066 GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
1028 "_foo2_bar", DATA2ARG ("FOO BAR BAZ")); 1067 "_foo2_bar_baz", DATA2ARG ("FOO BAR BAZ"));
1029 tmit.data[0] = "AAA BBB CCC "; 1068 tmit.data[0] = "AAA BBB CCC ";
1030 tmit.data[1] = "ABC DEF GHI JKL.\n"; 1069 tmit.data[1] = "ABC DEF GHI JKL.\n";
1031 tmit.data[2] = "TESTING ONE TWO THREE.\n"; 1070 tmit.data[2] = "TESTING ONE TWO THREE.\n";
@@ -1043,7 +1082,7 @@ guest_recv_entry_decision (void *cls,
1043 int is_admitted, 1082 int is_admitted,
1044 const struct GNUNET_PSYC_Message *entry_msg) 1083 const struct GNUNET_PSYC_Message *entry_msg)
1045{ 1084{
1046 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1085 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1047 "Test #%u: Guest received entry decision (try %u): %d.\n", 1086 "Test #%u: Guest received entry decision (try %u): %d.\n",
1048 test, join_req_count, is_admitted); 1087 test, join_req_count, is_admitted);
1049 1088
@@ -1068,7 +1107,8 @@ guest_recv_entry_decision (void *cls,
1068 { 1107 {
1069 case TEST_GUEST_RECV_ENTRY_DCSN_REFUSE: 1108 case TEST_GUEST_RECV_ENTRY_DCSN_REFUSE:
1070 GNUNET_assert (GNUNET_NO == is_admitted); 1109 GNUNET_assert (GNUNET_NO == is_admitted);
1071 guest_enter (); 1110 test = TEST_HOST_ANSWER_DOOR_ADMIT;
1111 GNUNET_SOCIAL_guest_disconnect (gst, &guest_enter, NULL);
1072 break; 1112 break;
1073 1113
1074 case TEST_GUEST_RECV_ENTRY_DCSN_ADMIT: 1114 case TEST_GUEST_RECV_ENTRY_DCSN_ADMIT:
@@ -1097,7 +1137,7 @@ host_answer_door (void *cls,
1097{ 1137{
1098 join_req_count++; 1138 join_req_count++;
1099 1139
1100 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1140 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1101 "Test #%u: Host received entry request from guest (try %u).\n", 1141 "Test #%u: Host received entry request from guest (try %u).\n",
1102 (uint8_t) test, join_req_count); 1142 (uint8_t) test, join_req_count);
1103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1118,7 +1158,7 @@ host_answer_door (void *cls,
1118 // fall through 1158 // fall through
1119 1159
1120 case TEST_GUEST_ENTER_BY_NAME: 1160 case TEST_GUEST_ENTER_BY_NAME:
1121 join_resp = GNUNET_PSYC_message_create ("_notice_place_admit", env, 1161 join_resp = GNUNET_PSYC_message_create ("_notice_place_admit", env,
1122 DATA2ARG ("Welcome, nym!")); 1162 DATA2ARG ("Welcome, nym!"));
1123 GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, join_resp); 1163 GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, join_resp);
1124 break; 1164 break;
@@ -1135,18 +1175,18 @@ guest_recv_local_enter (void *cls, int result,
1135 const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key, 1175 const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
1136 uint64_t max_message_id) 1176 uint64_t max_message_id)
1137{ 1177{
1138 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1178 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1139 "Test #%u: Guest entered to local place: %d\n", 1179 "Test #%u: Guest entered local place: %d\n",
1140 test, result); 1180 test, result);
1141 GNUNET_assert (0 <= result); 1181 GNUNET_assert (GNUNET_OK == result);
1142} 1182}
1143 1183
1144 1184
1145static void 1185static void
1146guest_enter () 1186guest_enter ()
1147{ 1187{
1148 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1188 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1149 "Test #%u: Entering to place as guest.\n", test); 1189 "Test #%u: Entering place as guest.\n", test);
1150 1190
1151 struct GuestEnterMessage *emsg = &guest_enter_msg; 1191 struct GuestEnterMessage *emsg = &guest_enter_msg;
1152 1192
@@ -1177,8 +1217,8 @@ static void
1177guest_enter_by_name () 1217guest_enter_by_name ()
1178{ 1218{
1179 test = TEST_GUEST_ENTER_BY_NAME; 1219 test = TEST_GUEST_ENTER_BY_NAME;
1180 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1220 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1181 "Test #%u: Entering to place by name as guest.\n", test); 1221 "Test #%u: Entering place by name as guest.\n", test);
1182 1222
1183 struct GuestEnterMessage *emsg = &guest_enter_msg; 1223 struct GuestEnterMessage *emsg = &guest_enter_msg;
1184 1224
@@ -1222,7 +1262,7 @@ guest_init ()
1222 guest_recv_data, guest_recv_eom, NULL); 1262 guest_recv_data, guest_recv_eom, NULL);
1223 GNUNET_PSYC_slicer_modifier_add (guest_slicer, "_foo_bar", 1263 GNUNET_PSYC_slicer_modifier_add (guest_slicer, "_foo_bar",
1224 guest_recv_mod_foo_bar, &mod_foo_bar_rcls); 1264 guest_recv_mod_foo_bar, &mod_foo_bar_rcls);
1225 test = TEST_HOST_ANSWER_DOOR_ADMIT; 1265 test = TEST_HOST_ANSWER_DOOR_REFUSE;
1226 1266
1227 GNUNET_SOCIAL_zone_add_nym (app, guest_ego, "host", host_pub_key, 1267 GNUNET_SOCIAL_zone_add_nym (app, guest_ego, "host", host_pub_key,
1228 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES), 1268 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES),
@@ -1270,8 +1310,8 @@ host_entered (void *cls, int result,
1270{ 1310{
1271 place_pub_key = *home_pub_key; 1311 place_pub_key = *home_pub_key;
1272 GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash); 1312 GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash);
1273 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1313 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1274 "Test #%u: Host entered to place %s\n", 1314 "Test #%u: Host entered place %s\n",
1275 test, GNUNET_h2s (&place_pub_hash)); 1315 test, GNUNET_h2s (&place_pub_hash));
1276 guest_enter (); 1316 guest_enter ();
1277} 1317}
@@ -1285,8 +1325,8 @@ host_enter ()
1285 host_recv_method, host_recv_modifier, 1325 host_recv_method, host_recv_modifier,
1286 host_recv_data, host_recv_eom, NULL); 1326 host_recv_data, host_recv_eom, NULL);
1287 1327
1288 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1328 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1289 "Test #%u: Entering to place as host.\n", test); 1329 "Test #%u: Entering place as host.\n", test);
1290 test = TEST_HOST_ENTER; 1330 test = TEST_HOST_ENTER;
1291 hst = GNUNET_SOCIAL_host_enter (app, host_ego, 1331 hst = GNUNET_SOCIAL_host_enter (app, host_ego,
1292 GNUNET_PSYC_CHANNEL_PRIVATE, 1332 GNUNET_PSYC_CHANNEL_PRIVATE,
@@ -1306,6 +1346,8 @@ start_app_if_ready ()
1306 { 1346 {
1307 return; 1347 return;
1308 } 1348 }
1349 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1350 "starting app...\n");
1309 app = GNUNET_SOCIAL_app_connect (cfg, 1351 app = GNUNET_SOCIAL_app_connect (cfg,
1310 app_id, 1352 app_id,
1311 app_recv_ego, 1353 app_recv_ego,
@@ -1324,17 +1366,17 @@ identity_ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego,
1324 { 1366 {
1325 if (ego == identity_host_ego) 1367 if (ego == identity_host_ego)
1326 { 1368 {
1327 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1369 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1328 "Host ego deleted\n"); 1370 "Host ego deleted\n");
1329 } 1371 }
1330 else if (ego == identity_guest_ego) 1372 else if (ego == identity_guest_ego)
1331 { 1373 {
1332 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1374 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1333 "Guest ego deleted\n"); 1375 "Guest ego deleted\n");
1334 } 1376 }
1335 else if (0 == strcmp (name, host_name)) 1377 else if (0 == strcmp (name, host_name))
1336 { 1378 {
1337 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1379 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1338 "Created ego %s\n", 1380 "Created ego %s\n",
1339 name); 1381 name);
1340 identity_host_ego = ego; 1382 identity_host_ego = ego;
@@ -1342,7 +1384,7 @@ identity_ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego,
1342 } 1384 }
1343 else if (0 == strcmp (name, guest_name)) 1385 else if (0 == strcmp (name, guest_name))
1344 { 1386 {
1345 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1387 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1346 "Created guest ego %s\n", 1388 "Created guest ego %s\n",
1347 name); 1389 name);
1348 identity_guest_ego = ego; 1390 identity_guest_ego = ego;
@@ -1370,9 +1412,11 @@ run (void *cls,
1370#endif 1412#endif
1371{ 1413{
1372 cfg = c; 1414 cfg = c;
1415 res = 1;
1373 end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 1416 end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
1374 &end_badly, NULL); 1417 &end_badly, NULL);
1375 1418 GNUNET_SCHEDULER_add_shutdown (&end_shutdown,
1419 NULL);
1376 GNUNET_CRYPTO_get_peer_identity (cfg, &this_peer); 1420 GNUNET_CRYPTO_get_peer_identity (cfg, &this_peer);
1377 1421
1378 id = GNUNET_IDENTITY_connect (cfg, &identity_ego_cb, NULL); 1422 id = GNUNET_IDENTITY_connect (cfg, &identity_ego_cb, NULL);
diff --git a/src/social/test_social.conf b/src/social/test_social.conf
index e69de29bb..7cf858b1c 100644
--- a/src/social/test_social.conf
+++ b/src/social/test_social.conf
@@ -0,0 +1,19 @@
1@INLINE@ ../../contrib/no_forcestart.conf
2
3[PATHS]
4GNUNET_TEST_HOME = /tmp/gnunet-test-social/
5
6[social]
7FORCESTART = YES
8
9[transport]
10PLUGINS = tcp
11
12[nat]
13DISABLEV6 = YES
14ENABLE_UPNP = NO
15BEHIND_NAT = NO
16ALLOW_NAT = NO
17INTERNAL_ADDRESS = 127.0.0.1
18EXTERNAL_ADDRESS = 127.0.0.1
19
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c
index 0cb136b99..87e966a01 100644
--- a/src/statistics/gnunet-service-statistics.c
+++ b/src/statistics/gnunet-service-statistics.c
@@ -998,7 +998,9 @@ client_disconnect_cb (void *cls,
998 * 998 *
999 * @param cls NULL 999 * @param cls NULL
1000 * @param message the message found on disk 1000 * @param message the message found on disk
1001 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing 1001 * @return #GNUNET_OK on success,
1002 * #GNUNET_NO to stop further processing (no error)
1003 * #GNUNET_SYSERR to stop further processing with error
1002 */ 1004 */
1003static int 1005static int
1004inject_message (void *cls, 1006inject_message (void *cls,
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index 94b981eee..e858e44b4 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -45,7 +45,7 @@ gnunet_service_testbed_SOURCES = \
45 gnunet-service-testbed_oc.c \ 45 gnunet-service-testbed_oc.c \
46 gnunet-service-testbed_cpustatus.c \ 46 gnunet-service-testbed_cpustatus.c \
47 gnunet-service-testbed_meminfo.c gnunet-service-testbed_meminfo.h \ 47 gnunet-service-testbed_meminfo.c gnunet-service-testbed_meminfo.h \
48 gnunet-service-testbed_barriers.c \ 48 gnunet-service-testbed_barriers.c gnunet-service-testbed_barriers.h \
49 gnunet-service-testbed_connectionpool.c gnunet-service-testbed_connectionpool.h 49 gnunet-service-testbed_connectionpool.c gnunet-service-testbed_connectionpool.h
50gnunet_service_testbed_LDADD = $(XLIB) \ 50gnunet_service_testbed_LDADD = $(XLIB) \
51 $(top_builddir)/src/util/libgnunetutil.la \ 51 $(top_builddir)/src/util/libgnunetutil.la \
diff --git a/src/testbed/gnunet-daemon-testbed-blacklist.c b/src/testbed/gnunet-daemon-testbed-blacklist.c
index f2f96ee09..3ebe20258 100644
--- a/src/testbed/gnunet-daemon-testbed-blacklist.c
+++ b/src/testbed/gnunet-daemon-testbed-blacklist.c
@@ -190,7 +190,8 @@ run (void *cls,
190 char *fname; 190 char *fname;
191 191
192 if (GNUNET_OK != 192 if (GNUNET_OK !=
193 GNUNET_CONFIGURATION_get_value_filename (c, "PATHS", 193 GNUNET_CONFIGURATION_get_value_filename (c,
194 "PATHS",
194 "GNUNET_HOME", 195 "GNUNET_HOME",
195 &shome)) 196 &shome))
196 { 197 {
@@ -208,6 +209,7 @@ run (void *cls,
208 GNUNET_free (fname); 209 GNUNET_free (fname);
209 return; 210 return;
210 } 211 }
212 GNUNET_free (fname);
211 GNUNET_asprintf (&fname, 213 GNUNET_asprintf (&fname,
212 "%s/blacklist", 214 "%s/blacklist",
213 shome); 215 shome);
diff --git a/src/testbed/gnunet-daemon-testbed-underlay.c b/src/testbed/gnunet-daemon-testbed-underlay.c
index 0b6c44710..3605e0384 100644
--- a/src/testbed/gnunet-daemon-testbed-underlay.c
+++ b/src/testbed/gnunet-daemon-testbed-underlay.c
@@ -165,7 +165,8 @@ check_access (void *cls, const struct GNUNET_PeerIdentity * pid)
165 165
166 166
167static int 167static int
168get_identity (unsigned int offset, struct GNUNET_PeerIdentity *id) 168get_identity (unsigned int offset,
169 struct GNUNET_PeerIdentity *id)
169{ 170{
170 struct GNUNET_CRYPTO_EddsaPrivateKey private_key; 171 struct GNUNET_CRYPTO_EddsaPrivateKey private_key;
171 172
@@ -174,7 +175,8 @@ get_identity (unsigned int offset, struct GNUNET_PeerIdentity *id)
174 GNUNET_memcpy (&private_key, 175 GNUNET_memcpy (&private_key,
175 hostkeys_data + (offset * GNUNET_TESTING_HOSTKEYFILESIZE), 176 hostkeys_data + (offset * GNUNET_TESTING_HOSTKEYFILESIZE),
176 GNUNET_TESTING_HOSTKEYFILESIZE); 177 GNUNET_TESTING_HOSTKEYFILESIZE);
177 GNUNET_CRYPTO_eddsa_key_get_public (&private_key, &id->public_key); 178 GNUNET_CRYPTO_eddsa_key_get_public (&private_key,
179 &id->public_key);
178 return GNUNET_OK; 180 return GNUNET_OK;
179} 181}
180 182
diff --git a/src/testbed/gnunet-helper-testbed.c b/src/testbed/gnunet-helper-testbed.c
index 392f257dd..9601e7567 100644
--- a/src/testbed/gnunet-helper-testbed.c
+++ b/src/testbed/gnunet-helper-testbed.c
@@ -292,8 +292,9 @@ child_death_task (void *cls)
292 * 292 *
293 * @param cls identification of the client 293 * @param cls identification of the client
294 * @param message the actual message 294 * @param message the actual message
295 * 295 * @return #GNUNET_OK on success,
296 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing 296 * #GNUNET_NO to stop further processing (no error)
297 * #GNUNET_SYSERR to stop further processing with error
297 */ 298 */
298static int 299static int
299tokenizer_cb (void *cls, 300tokenizer_cb (void *cls,
@@ -359,7 +360,7 @@ tokenizer_cb (void *cls,
359 cfg = GNUNET_CONFIGURATION_create (); 360 cfg = GNUNET_CONFIGURATION_create ();
360 if (GNUNET_OK != 361 if (GNUNET_OK !=
361 GNUNET_CONFIGURATION_deserialize (cfg, 362 GNUNET_CONFIGURATION_deserialize (cfg,
362 config, 363 config,
363 ul_config_size, 364 ul_config_size,
364 NULL)) 365 NULL))
365 { 366 {
diff --git a/src/testbed/gnunet-service-testbed_oc.c b/src/testbed/gnunet-service-testbed_oc.c
index 09849797c..11c45a0f5 100644
--- a/src/testbed/gnunet-service-testbed_oc.c
+++ b/src/testbed/gnunet-service-testbed_oc.c
@@ -261,7 +261,7 @@ struct OverlayConnectContext
261 enum OverlayConnectContextType type; 261 enum OverlayConnectContextType type;
262 262
263 /** 263 /**
264 * The id of the second peer which is has to connect to the first peer 264 * The id of the second peer which has to connect to the first peer
265 */ 265 */
266 uint32_t other_peer_id; 266 uint32_t other_peer_id;
267}; 267};
@@ -930,10 +930,10 @@ send_hello (void *cls)
930 other_peer_str); 930 other_peer_str);
931 GNUNET_free (other_peer_str); 931 GNUNET_free (other_peer_str);
932 lp2c->ohh = 932 lp2c->ohh =
933 GNUNET_TRANSPORT_offer_hello (lp2c->tcc.cfg, 933 GNUNET_TRANSPORT_offer_hello (lp2c->tcc.cfg,
934 occ->hello, 934 occ->hello,
935 &occ_hello_sent_cb, 935 &occ_hello_sent_cb,
936 occ); 936 occ);
937 if (NULL == lp2c->ohh) 937 if (NULL == lp2c->ohh)
938 { 938 {
939 GNUNET_break (0); 939 GNUNET_break (0);
@@ -1001,6 +1001,11 @@ p2_transport_connect (struct OverlayConnectContext *occ)
1001{ 1001{
1002 struct Peer *peer2; 1002 struct Peer *peer2;
1003 1003
1004 /* HUH? Why to *obtain* HELLO? Seems we use this to *SEND* the
1005 HELLO! */
1006 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1007 "Connecting to transport of peer %s to obtain HELLO\n",
1008 GNUNET_i2s (&occ->other_peer_identity));
1004 GNUNET_assert (NULL == occ->emsg); 1009 GNUNET_assert (NULL == occ->emsg);
1005 GNUNET_assert (NULL != occ->hello); 1010 GNUNET_assert (NULL != occ->hello);
1006 GNUNET_assert (NULL == occ->ghh); 1011 GNUNET_assert (NULL == occ->ghh);
diff --git a/src/testbed/gnunet-testbed-profiler.c b/src/testbed/gnunet-testbed-profiler.c
index 9829bbf0d..0fa6d8172 100644
--- a/src/testbed/gnunet-testbed-profiler.c
+++ b/src/testbed/gnunet-testbed-profiler.c
@@ -175,9 +175,7 @@ controller_event_cb (void *cls,
175 { 175 {
176 printf ("\nAborting due to very high failure rate\n"); 176 printf ("\nAborting due to very high failure rate\n");
177 print_overlay_links_summary (); 177 print_overlay_links_summary ();
178 if (NULL != abort_task) 178 GNUNET_SCHEDULER_shutdown ();
179 GNUNET_SCHEDULER_cancel (abort_task);
180 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
181 return; 179 return;
182 } 180 }
183 } 181 }
@@ -260,11 +258,12 @@ run (void *cls, char *const *args, const char *cfgfile,
260 event_mask = 0; 258 event_mask = 0;
261 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); 259 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
262 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); 260 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
263 GNUNET_TESTBED_run (hosts_file, cfg, num_peers, event_mask, controller_event_cb, 261 GNUNET_TESTBED_run (hosts_file, cfg, num_peers, event_mask,
264 NULL, &test_run, NULL); 262 &controller_event_cb, NULL,
263 &test_run, NULL);
265 abort_task = 264 abort_task =
266 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_abort, 265 GNUNET_SCHEDULER_add_shutdown (&do_abort,
267 NULL); 266 NULL);
268} 267}
269 268
270 269
@@ -310,6 +309,8 @@ main (int argc, char *const *argv)
310 const char *binaryHelp = "gnunet-testbed-profiler [OPTIONS]"; 309 const char *binaryHelp = "gnunet-testbed-profiler [OPTIONS]";
311 int ret; 310 int ret;
312 311
312 unsetenv ("XDG_DATA_HOME");
313 unsetenv ("XDG_CONFIG_HOME");
313 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 314 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
314 return 2; 315 return 2;
315 result = GNUNET_SYSERR; 316 result = GNUNET_SYSERR;
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index d65da6bb6..e8c1f5d4a 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -295,7 +295,7 @@ noinst_LTLIBRARIES = \
295 libgnunet_plugin_transport_template.la 295 libgnunet_plugin_transport_template.la
296 296
297libgnunet_plugin_transport_tcp_la_SOURCES = \ 297libgnunet_plugin_transport_tcp_la_SOURCES = \
298 plugin_transport_tcp.c 298 plugin_transport_tcp.c
299libgnunet_plugin_transport_tcp_la_LIBADD = \ 299libgnunet_plugin_transport_tcp_la_LIBADD = \
300 $(top_builddir)/src/hello/libgnunethello.la \ 300 $(top_builddir)/src/hello/libgnunethello.la \
301 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 301 $(top_builddir)/src/statistics/libgnunetstatistics.la \
@@ -1330,7 +1330,6 @@ test_transport_api_monitor_peers_peer2.conf\
1330test_transport_api_monitor_validation_peer1.conf\ 1330test_transport_api_monitor_validation_peer1.conf\
1331test_transport_api_monitor_validation_peer2.conf\ 1331test_transport_api_monitor_validation_peer2.conf\
1332test_transport_defaults.conf\ 1332test_transport_defaults.conf\
1333test_transport_startonly.conf\
1334test_transport_api_disconnect_tcp_peer1.conf\ 1333test_transport_api_disconnect_tcp_peer1.conf\
1335test_transport_api_disconnect_tcp_peer2.conf\ 1334test_transport_api_disconnect_tcp_peer2.conf\
1336test_transport_api_timeout_http_peer1.conf\ 1335test_transport_api_timeout_http_peer1.conf\
@@ -1350,4 +1349,8 @@ test_transport_api_http_reverse_peer2.conf \
1350perf_tcp_peer1.conf \ 1349perf_tcp_peer1.conf \
1351perf_tcp_peer2.conf \ 1350perf_tcp_peer2.conf \
1352test_transport_api_slow_ats_peer1.conf \ 1351test_transport_api_slow_ats_peer1.conf \
1353test_transport_api_slow_ats_peer2.conf 1352test_transport_api_slow_ats_peer2.conf \
1353 tcp_connection_legacy.c \
1354 tcp_server_mst_legacy.c \
1355 tcp_server_legacy.c \
1356 tcp_service_legacy.c
diff --git a/src/transport/gnunet-helper-transport-wlan-dummy.c b/src/transport/gnunet-helper-transport-wlan-dummy.c
index 63ed9c4b7..f02d8bdd7 100644
--- a/src/transport/gnunet-helper-transport-wlan-dummy.c
+++ b/src/transport/gnunet-helper-transport-wlan-dummy.c
@@ -121,6 +121,9 @@ send_mac_to_plugin (char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac)
121 * 121 *
122 * @param cls the 'struct SendBuffer' to copy the converted message to 122 * @param cls the 'struct SendBuffer' to copy the converted message to
123 * @param hdr inbound message from the FIFO 123 * @param hdr inbound message from the FIFO
124 * @return #GNUNET_OK on success,
125 * #GNUNET_NO to stop further processing (no error)
126 * #GNUNET_SYSERR to stop further processing with error
124 */ 127 */
125static int 128static int
126stdin_send (void *cls, 129stdin_send (void *cls,
@@ -167,6 +170,9 @@ stdin_send (void *cls,
167 * 170 *
168 * @param cls the 'struct SendBuffer' to copy to 171 * @param cls the 'struct SendBuffer' to copy to
169 * @param hdr the message we received to copy to the buffer 172 * @param hdr the message we received to copy to the buffer
173 * @return #GNUNET_OK on success,
174 * #GNUNET_NO to stop further processing (no error)
175 * #GNUNET_SYSERR to stop further processing with error
170 */ 176 */
171static int 177static int
172file_in_send (void *cls, 178file_in_send (void *cls,
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index 6b354df98..124260c41 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -688,6 +688,8 @@ handle_client_hello (void *cls,
688{ 688{
689 struct TransportClient *tc = cls; 689 struct TransportClient *tc = cls;
690 690
691 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
692 "Received HELLO message\n");
691 GST_validation_handle_hello (message); 693 GST_validation_handle_hello (message);
692 GNUNET_SERVICE_client_continue (tc->client); 694 GNUNET_SERVICE_client_continue (tc->client);
693} 695}
@@ -2802,7 +2804,7 @@ run (void *cls,
2802 GNUNET_assert (NULL != GST_my_private_key); 2804 GNUNET_assert (NULL != GST_my_private_key);
2803 2805
2804 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2806 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2805 "My identity is `%4s'\n", 2807 "My identity is `%s'\n",
2806 GNUNET_i2s_full (&GST_my_identity)); 2808 GNUNET_i2s_full (&GST_my_identity));
2807 2809
2808 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 2810 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
diff --git a/src/transport/gnunet-service-transport_ats.c b/src/transport/gnunet-service-transport_ats.c
index c780f9a78..01e115bfc 100644
--- a/src/transport/gnunet-service-transport_ats.c
+++ b/src/transport/gnunet-service-transport_ats.c
@@ -337,14 +337,10 @@ GST_ats_block_address (const struct GNUNET_HELLO_Address *address,
337 return; /* our own, ignore! */ 337 return; /* our own, ignore! */
338 ai = find_ai (address, 338 ai = find_ai (address,
339 session); 339 session);
340 if (NULL == ai) 340 if (NULL == ai || NULL == ai->ar)
341 {
342 GNUNET_assert (0);
343 return;
344 }
345 if (NULL == ai->ar)
346 { 341 {
347 /* already blocked but this might be a blacklist check callback */ 342 /* The address is already gone/blocked, this can happen during a blacklist
343 * callback. */
348 return; 344 return;
349 } 345 }
350 ai->back_off = GNUNET_TIME_STD_BACKOFF (ai->back_off); 346 ai->back_off = GNUNET_TIME_STD_BACKOFF (ai->back_off);
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 19f5fd081..2bf07bcd7 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -616,6 +616,8 @@ neighbours_changed_notification (const struct GNUNET_PeerIdentity *peer,
616 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 616 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
617 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 617 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
618{ 618{
619 (void) bandwidth_in;
620 (void) bandwidth_out;
619 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
620 "Notifying about change for peer `%s' with address `%s' in state `%s' timing out at %s\n", 622 "Notifying about change for peer `%s' with address `%s' in state `%s' timing out at %s\n",
621 GNUNET_i2s (peer), 623 GNUNET_i2s (peer),
@@ -993,6 +995,10 @@ send_disconnect_cont (void *cls,
993{ 995{
994 struct NeighbourMapEntry *n; 996 struct NeighbourMapEntry *n;
995 997
998 (void) cls;
999 (void) result;
1000 (void) payload;
1001 (void) physical;
996 n = lookup_neighbour (target); 1002 n = lookup_neighbour (target);
997 if (NULL == n) 1003 if (NULL == n)
998 return; /* already gone */ 1004 return; /* already gone */
@@ -1131,10 +1137,12 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
1131 * our own receive rate and informs the neighbour about 1137 * our own receive rate and informs the neighbour about
1132 * the new quota. 1138 * the new quota.
1133 * 1139 *
1134 * @param n neighbour entry to change qutoa for 1140 * @param n neighbour entry to change quota for
1135 * @param quota new quota 1141 * @param quota new quota
1142 * @return #GNUNET_YES if @a n is still valid, #GNUNET_NO if
1143 * @a n was freed
1136 */ 1144 */
1137static void 1145static int
1138set_incoming_quota (struct NeighbourMapEntry *n, 1146set_incoming_quota (struct NeighbourMapEntry *n,
1139 struct GNUNET_BANDWIDTH_Value32NBO quota) 1147 struct GNUNET_BANDWIDTH_Value32NBO quota)
1140{ 1148{
@@ -1158,7 +1166,7 @@ set_incoming_quota (struct NeighbourMapEntry *n,
1158 GNUNET_TIME_UNIT_FOREVER_REL, 1166 GNUNET_TIME_UNIT_FOREVER_REL,
1159 GNUNET_NO, 1167 GNUNET_NO,
1160 NULL, NULL); 1168 NULL, NULL);
1161 return; 1169 return GNUNET_YES;
1162 } 1170 }
1163 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1171 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1164 "Disconnecting peer `%s' due to SET_QUOTA\n", 1172 "Disconnecting peer `%s' due to SET_QUOTA\n",
@@ -1168,6 +1176,7 @@ set_incoming_quota (struct NeighbourMapEntry *n,
1168 gettext_noop ("# disconnects due to quota of 0"), 1176 gettext_noop ("# disconnects due to quota of 0"),
1169 1, GNUNET_NO); 1177 1, GNUNET_NO);
1170 disconnect_neighbour (n); 1178 disconnect_neighbour (n);
1179 return GNUNET_NO;
1171} 1180}
1172 1181
1173 1182
@@ -1196,8 +1205,10 @@ set_primary_address (struct NeighbourMapEntry *n,
1196 if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__) 1205 if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__)
1197 { 1206 {
1198 n->primary_address.bandwidth_in = bandwidth_in; 1207 n->primary_address.bandwidth_in = bandwidth_in;
1199 set_incoming_quota (n, 1208 if (GNUNET_YES !=
1200 bandwidth_in); 1209 set_incoming_quota (n,
1210 bandwidth_in))
1211 return;
1201 } 1212 }
1202 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__) 1213 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__)
1203 { 1214 {
@@ -1237,8 +1248,10 @@ set_primary_address (struct NeighbourMapEntry *n,
1237 /* subsystems about address use */ 1248 /* subsystems about address use */
1238 GST_validation_set_address_use (n->primary_address.address, 1249 GST_validation_set_address_use (n->primary_address.address,
1239 GNUNET_YES); 1250 GNUNET_YES);
1240 set_incoming_quota (n, 1251 if (GNUNET_YES !=
1241 bandwidth_in); 1252 set_incoming_quota (n,
1253 bandwidth_in))
1254 return;
1242 send_outbound_quota_to_clients (n); 1255 send_outbound_quota_to_clients (n);
1243 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1256 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1244 "Neighbour `%s' switched to address `%s'\n", 1257 "Neighbour `%s' switched to address `%s'\n",
@@ -1805,6 +1818,9 @@ send_session_syn_cont (void *cls,
1805{ 1818{
1806 struct NeighbourMapEntry *n; 1819 struct NeighbourMapEntry *n;
1807 1820
1821 (void) cls;
1822 (void) size_payload;
1823 (void) size_on_wire;
1808 n = lookup_neighbour (target); 1824 n = lookup_neighbour (target);
1809 if (NULL == n) 1825 if (NULL == n)
1810 { 1826 {
@@ -1978,6 +1994,9 @@ send_session_syn_ack_cont (void *cls,
1978{ 1994{
1979 struct NeighbourMapEntry *n; 1995 struct NeighbourMapEntry *n;
1980 1996
1997 (void) cls;
1998 (void) size_payload;
1999 (void) size_on_wire;
1981 n = lookup_neighbour (target); 2000 n = lookup_neighbour (target);
1982 if (NULL == n) 2001 if (NULL == n)
1983 { 2002 {
@@ -2393,8 +2412,10 @@ try_run_fast_ats_update (const struct GNUNET_HELLO_Address *address,
2393 if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__) 2412 if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__)
2394 { 2413 {
2395 n->primary_address.bandwidth_in = bandwidth_in; 2414 n->primary_address.bandwidth_in = bandwidth_in;
2396 set_incoming_quota (n, 2415 if (GNUNET_YES !=
2397 bandwidth_in); 2416 set_incoming_quota (n,
2417 bandwidth_in))
2418 return GNUNET_NO;
2398 } 2419 }
2399 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__) 2420 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__)
2400 { 2421 {
@@ -2433,7 +2454,10 @@ switch_address_bl_check_cont (void *cls,
2433 goto cleanup; 2454 goto cleanup;
2434 2455
2435 papi = GST_plugins_find (address->transport_name); 2456 papi = GST_plugins_find (address->transport_name);
2436 GNUNET_assert (NULL != papi); 2457 if (NULL == papi) {
2458 /* This can happen during shutdown. */
2459 goto cleanup;
2460 }
2437 2461
2438 if (GNUNET_NO == result) 2462 if (GNUNET_NO == result)
2439 { 2463 {
@@ -2802,6 +2826,7 @@ send_utilization_data (void *cls,
2802 uint32_t bps_out; 2826 uint32_t bps_out;
2803 struct GNUNET_TIME_Relative delta; 2827 struct GNUNET_TIME_Relative delta;
2804 2828
2829 (void) cls;
2805 if ( (GNUNET_YES != test_connected (n)) || 2830 if ( (GNUNET_YES != test_connected (n)) ||
2806 (NULL == n->primary_address.address) ) 2831 (NULL == n->primary_address.address) )
2807 return GNUNET_OK; 2832 return GNUNET_OK;
@@ -2832,11 +2857,12 @@ send_utilization_data (void *cls,
2832/** 2857/**
2833 * Task transmitting utilization in a regular interval 2858 * Task transmitting utilization in a regular interval
2834 * 2859 *
2835 * @param cls the 'struct NeighbourMapEntry' for which we are running 2860 * @param cls the `struct NeighbourMapEntry` for which we are running
2836 */ 2861 */
2837static void 2862static void
2838utilization_transmission (void *cls) 2863utilization_transmission (void *cls)
2839{ 2864{
2865 (void) cls;
2840 util_transmission_tk = NULL; 2866 util_transmission_tk = NULL;
2841 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 2867 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
2842 &send_utilization_data, 2868 &send_utilization_data,
@@ -3092,6 +3118,7 @@ GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *messag
3092 struct GNUNET_TIME_Absolute ts; 3118 struct GNUNET_TIME_Absolute ts;
3093 struct NeighbourMapEntry *n; 3119 struct NeighbourMapEntry *n;
3094 3120
3121 (void) session;
3095 if (ntohs (message->size) != sizeof (struct TransportSynMessage)) 3122 if (ntohs (message->size) != sizeof (struct TransportSynMessage))
3096 { 3123 {
3097 GNUNET_break_op (0); 3124 GNUNET_break_op (0);
@@ -3365,6 +3392,7 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
3365{ 3392{
3366 struct NeighbourMapEntry *n; 3393 struct NeighbourMapEntry *n;
3367 3394
3395 (void) session;
3368 if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader)) 3396 if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader))
3369 { 3397 {
3370 GNUNET_break_op (0); 3398 GNUNET_break_op (0);
@@ -3638,6 +3666,7 @@ neighbours_iterate (void *cls,
3638 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; 3666 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
3639 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; 3667 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
3640 3668
3669 (void) key;
3641 if (NULL != n->primary_address.address) 3670 if (NULL != n->primary_address.address)
3642 { 3671 {
3643 bandwidth_in = n->primary_address.bandwidth_in; 3672 bandwidth_in = n->primary_address.bandwidth_in;
@@ -3730,6 +3759,7 @@ GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer)
3730void 3759void
3731GST_neighbours_start (unsigned int max_fds) 3760GST_neighbours_start (unsigned int max_fds)
3732{ 3761{
3762 (void) max_fds;
3733 neighbours = GNUNET_CONTAINER_multipeermap_create (NEIGHBOUR_TABLE_SIZE, 3763 neighbours = GNUNET_CONTAINER_multipeermap_create (NEIGHBOUR_TABLE_SIZE,
3734 GNUNET_NO); 3764 GNUNET_NO);
3735 util_transmission_tk = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL, 3765 util_transmission_tk = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL,
@@ -3753,6 +3783,8 @@ disconnect_all_neighbours (void *cls,
3753{ 3783{
3754 struct NeighbourMapEntry *n = value; 3784 struct NeighbourMapEntry *n = value;
3755 3785
3786 (void) cls;
3787 (void) key;
3756 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3788 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3757 "Disconnecting peer `%4s' during shutdown\n", 3789 "Disconnecting peer `%4s' during shutdown\n",
3758 GNUNET_i2s (&n->id)); 3790 GNUNET_i2s (&n->id));
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index 27c3c7041..cd5aeb5e2 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -1347,6 +1347,9 @@ GST_validation_handle_address (const struct GNUNET_HELLO_Address *address)
1347 if (NULL == papi) 1347 if (NULL == papi)
1348 { 1348 {
1349 /* This plugin is currently unvailable ... ignore */ 1349 /* This plugin is currently unvailable ... ignore */
1350 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1351 "No plugin available for %s\n",
1352 address->transport_name);
1350 return; 1353 return;
1351 } 1354 }
1352 ve = find_validation_entry (address); 1355 ve = find_validation_entry (address);
@@ -1358,6 +1361,13 @@ GST_validation_handle_address (const struct GNUNET_HELLO_Address *address)
1358 GNUNET_i2s (&ve->address->peer)); 1361 GNUNET_i2s (&ve->address->peer));
1359 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve); 1362 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
1360 } 1363 }
1364 else
1365 {
1366 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1367 "Validation already running for address `%s' of %s\n",
1368 GST_plugins_a2s (ve->address),
1369 GNUNET_i2s (&ve->address->peer));
1370 }
1361} 1371}
1362 1372
1363 1373
@@ -1657,6 +1667,9 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1657 sizeof (struct GNUNET_PeerIdentity))) 1667 sizeof (struct GNUNET_PeerIdentity)))
1658 { 1668 {
1659 /* got our own HELLO, how boring */ 1669 /* got our own HELLO, how boring */
1670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1671 "Validation received our own HELLO (%s), ignoring\n",
1672 GNUNET_i2s (&pid));
1660 return GNUNET_OK; 1673 return GNUNET_OK;
1661 } 1674 }
1662 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1675 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c
index d9fade44f..6a9c1b0ba 100644
--- a/src/transport/plugin_transport_http_server.c
+++ b/src/transport/plugin_transport_http_server.c
@@ -1651,7 +1651,7 @@ server_send_callback (void *cls,
1651 * 1651 *
1652 * @param cls current session as closure 1652 * @param cls current session as closure
1653 * @param message the message to be forwarded to transport service 1653 * @param message the message to be forwarded to transport service
1654 * @return #GNUNET_OK 1654 * @return #GNUNET_OK (all OK)
1655 */ 1655 */
1656static int 1656static int
1657server_receive_mst_cb (void *cls, 1657server_receive_mst_cb (void *cls,
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index a63013caa..8b00543c3 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -3172,8 +3172,6 @@ handle_tcp_welcome (void *cls,
3172 sizeof(struct GNUNET_PeerIdentity))) 3172 sizeof(struct GNUNET_PeerIdentity)))
3173 { 3173 {
3174 /* refuse connections from ourselves */ 3174 /* refuse connections from ourselves */
3175 GNUNET_SERVER_receive_done (client,
3176 GNUNET_SYSERR);
3177 if (GNUNET_OK == 3175 if (GNUNET_OK ==
3178 GNUNET_SERVER_client_get_address (client, 3176 GNUNET_SERVER_client_get_address (client,
3179 &vaddr, 3177 &vaddr,
@@ -3185,6 +3183,8 @@ handle_tcp_welcome (void *cls,
3185 GNUNET_a2s (vaddr, alen)); 3183 GNUNET_a2s (vaddr, alen));
3186 GNUNET_free (vaddr); 3184 GNUNET_free (vaddr);
3187 } 3185 }
3186 GNUNET_SERVER_receive_done (client,
3187 GNUNET_SYSERR);
3188 return; 3188 return;
3189 } 3189 }
3190 3190
@@ -3348,12 +3348,13 @@ handle_tcp_data (void *cls,
3348 if (NULL == session) 3348 if (NULL == session)
3349 { 3349 {
3350 /* No inbound session found */ 3350 /* No inbound session found */
3351 void *vaddr; 3351 void *vaddr = NULL;
3352 size_t alen; 3352 size_t alen;
3353 3353
3354 GNUNET_SERVER_client_get_address (client, 3354 GNUNET_assert (GNUNET_OK ==
3355 &vaddr, 3355 GNUNET_SERVER_client_get_address (client,
3356 &alen); 3356 &vaddr,
3357 &alen));
3357 LOG (GNUNET_ERROR_TYPE_ERROR, 3358 LOG (GNUNET_ERROR_TYPE_ERROR,
3358 "Received unexpected %u bytes of type %u from `%s'\n", 3359 "Received unexpected %u bytes of type %u from `%s'\n",
3359 (unsigned int) ntohs (message->size), 3360 (unsigned int) ntohs (message->size),
@@ -3369,7 +3370,7 @@ handle_tcp_data (void *cls,
3369 if (GNUNET_YES == session->expecting_welcome) 3370 if (GNUNET_YES == session->expecting_welcome)
3370 { 3371 {
3371 /* Session is expecting WELCOME message */ 3372 /* Session is expecting WELCOME message */
3372 void *vaddr; 3373 void *vaddr = NULL;
3373 size_t alen; 3374 size_t alen;
3374 3375
3375 GNUNET_SERVER_client_get_address (client, 3376 GNUNET_SERVER_client_get_address (client,
@@ -3389,7 +3390,7 @@ handle_tcp_data (void *cls,
3389 3390
3390 session->last_activity = GNUNET_TIME_absolute_get (); 3391 session->last_activity = GNUNET_TIME_absolute_get ();
3391 { 3392 {
3392 void *vaddr; 3393 void *vaddr = NULL;
3393 size_t alen; 3394 size_t alen;
3394 3395
3395 GNUNET_SERVER_client_get_address (client, 3396 GNUNET_SERVER_client_get_address (client,
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 1ff962544..0daac4443 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -1631,6 +1631,7 @@ enqueue (struct Plugin *plugin,
1631 if (GNUNET_YES == session->in_destroy) 1631 if (GNUNET_YES == session->in_destroy)
1632 { 1632 {
1633 GNUNET_break (0); 1633 GNUNET_break (0);
1634 GNUNET_free (udpw);
1634 return; 1635 return;
1635 } 1636 }
1636 if (plugin->bytes_in_buffer > INT64_MAX - udpw->msg_size) 1637 if (plugin->bytes_in_buffer > INT64_MAX - udpw->msg_size)
@@ -1913,8 +1914,8 @@ enqueue_fragment (void *cls,
1913 udpw->qc = &qc_fragment_sent; 1914 udpw->qc = &qc_fragment_sent;
1914 udpw->qc_cls = plugin; 1915 udpw->qc_cls = plugin;
1915 GNUNET_memcpy (udpw->msg_buf, 1916 GNUNET_memcpy (udpw->msg_buf,
1916 msg, 1917 msg,
1917 msg_len); 1918 msg_len);
1918 enqueue (plugin, 1919 enqueue (plugin,
1919 udpw); 1920 udpw);
1920 if (session->address->address_length == sizeof (struct IPv4UdpAddress)) 1921 if (session->address->address_length == sizeof (struct IPv4UdpAddress))
@@ -3838,9 +3839,9 @@ libgnunet_plugin_transport_udp_init (void *cls)
3838 unsigned long long port; 3839 unsigned long long port;
3839 unsigned long long aport; 3840 unsigned long long aport;
3840 unsigned long long udp_max_bps; 3841 unsigned long long udp_max_bps;
3841 unsigned long long enable_v6; 3842 int enable_v6;
3842 unsigned long long enable_broadcasting; 3843 int enable_broadcasting;
3843 unsigned long long enable_broadcasting_recv; 3844 int enable_broadcasting_recv;
3844 char *bind4_address; 3845 char *bind4_address;
3845 char *bind6_address; 3846 char *bind6_address;
3846 struct GNUNET_TIME_Relative interval; 3847 struct GNUNET_TIME_Relative interval;
diff --git a/src/transport/tcp_connection_legacy.c b/src/transport/tcp_connection_legacy.c
index 5b219a467..17157436d 100644
--- a/src/transport/tcp_connection_legacy.c
+++ b/src/transport/tcp_connection_legacy.c
@@ -1218,8 +1218,10 @@ RETRY:
1218 * @param timeout maximum amount of time to wait 1218 * @param timeout maximum amount of time to wait
1219 * @param receiver function to call with received data 1219 * @param receiver function to call with received data
1220 * @param receiver_cls closure for @a receiver 1220 * @param receiver_cls closure for @a receiver
1221 * @return #GNUNET_SYSERR if @a connection died (receiver was
1222 * called with error)
1221 */ 1223 */
1222void 1224int
1223GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection, 1225GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection,
1224 size_t max, 1226 size_t max,
1225 struct GNUNET_TIME_Relative timeout, 1227 struct GNUNET_TIME_Relative timeout,
@@ -1241,7 +1243,7 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection,
1241 connection->sock, 1243 connection->sock,
1242 &receive_ready, 1244 &receive_ready,
1243 connection); 1245 connection);
1244 return; 1246 return GNUNET_OK;
1245 } 1247 }
1246 if ((NULL == connection->dns_active) && 1248 if ((NULL == connection->dns_active) &&
1247 (NULL == connection->ap_head) && 1249 (NULL == connection->ap_head) &&
@@ -1252,8 +1254,9 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection,
1252 NULL, 0, 1254 NULL, 0,
1253 NULL, 0, 1255 NULL, 0,
1254 ETIMEDOUT); 1256 ETIMEDOUT);
1255 return; 1257 return GNUNET_SYSERR;
1256 } 1258 }
1259 return GNUNET_OK;
1257} 1260}
1258 1261
1259 1262
diff --git a/src/transport/tcp_server_legacy.c b/src/transport/tcp_server_legacy.c
index d0ce790fc..f75b41e8c 100644
--- a/src/transport/tcp_server_legacy.c
+++ b/src/transport/tcp_server_legacy.c
@@ -1044,11 +1044,13 @@ process_mst (struct GNUNET_SERVER_Client *client,
1044 "Server re-enters receive loop, timeout: %s.\n", 1044 "Server re-enters receive loop, timeout: %s.\n",
1045 GNUNET_STRINGS_relative_time_to_string (client->idle_timeout, GNUNET_YES)); 1045 GNUNET_STRINGS_relative_time_to_string (client->idle_timeout, GNUNET_YES));
1046 client->receive_pending = GNUNET_YES; 1046 client->receive_pending = GNUNET_YES;
1047 GNUNET_CONNECTION_receive (client->connection, 1047 if (GNUNET_OK !=
1048 GNUNET_MAX_MESSAGE_SIZE - 1, 1048 GNUNET_CONNECTION_receive (client->connection,
1049 client->idle_timeout, 1049 GNUNET_MAX_MESSAGE_SIZE - 1,
1050 &process_incoming, 1050 client->idle_timeout,
1051 client); 1051 &process_incoming,
1052 client))
1053 return;
1052 break; 1054 break;
1053 } 1055 }
1054 LOG (GNUNET_ERROR_TYPE_DEBUG, 1056 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1287,11 +1289,13 @@ GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server,
1287 for (n = server->connect_notify_list_head; NULL != n; n = n->next) 1289 for (n = server->connect_notify_list_head; NULL != n; n = n->next)
1288 n->callback (n->callback_cls, client); 1290 n->callback (n->callback_cls, client);
1289 client->receive_pending = GNUNET_YES; 1291 client->receive_pending = GNUNET_YES;
1290 GNUNET_CONNECTION_receive (client->connection, 1292 if (GNUNET_SYSERR ==
1291 GNUNET_MAX_MESSAGE_SIZE - 1, 1293 GNUNET_CONNECTION_receive (client->connection,
1292 client->idle_timeout, 1294 GNUNET_MAX_MESSAGE_SIZE - 1,
1293 &process_incoming, 1295 client->idle_timeout,
1294 client); 1296 &process_incoming,
1297 client))
1298 return NULL;
1295 return client; 1299 return client;
1296} 1300}
1297 1301
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index cc9ff4745..eb655157d 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -119,18 +119,6 @@ libgnunetutil_la_LIBADD = \
119 $(LTLIBINTL) \ 119 $(LTLIBINTL) \
120 -lltdl $(Z_LIBS) -lunistring $(XLIB) 120 -lltdl $(Z_LIBS) -lunistring $(XLIB)
121 121
122if HAVE_PBC
123if HAVE_ABE
124libgnunetutil_la_SOURCES += \
125 crypto_abe.c
126libgnunetutil_la_LIBADD += \
127 $(ABE_LIBADD) \
128 -lgabe \
129 -lpbc \
130 -lglib-2.0
131endif
132endif
133
134libgnunetutil_la_LDFLAGS = \ 122libgnunetutil_la_LDFLAGS = \
135 $(GN_LIB_LDFLAGS) \ 123 $(GN_LIB_LDFLAGS) \
136 -version-info 13:0:0 124 -version-info 13:0:0
@@ -564,17 +552,6 @@ test_speedup_SOURCES = \
564test_speedup_LDADD = \ 552test_speedup_LDADD = \
565 libgnunetutil.la 553 libgnunetutil.la
566 554
567if HAVE_PBC
568if HAVE_ABE
569test_crypto_abe_SOURCES = \
570 test_crypto_abe.c
571test_crypto_abe_LDADD = \
572 libgnunetutil.la
573check_PROGRAMS += \
574 test_crypto_abe
575endif
576endif
577
578perf_crypto_hash_SOURCES = \ 555perf_crypto_hash_SOURCES = \
579 perf_crypto_hash.c 556 perf_crypto_hash.c
580perf_crypto_hash_LDADD = \ 557perf_crypto_hash_LDADD = \
diff --git a/src/util/bio.c b/src/util/bio.c
index 08e30dc01..816917a22 100644
--- a/src/util/bio.c
+++ b/src/util/bio.c
@@ -162,15 +162,19 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
162 { 162 {
163 if (min > len - pos) 163 if (min > len - pos)
164 min = len - pos; 164 min = len - pos;
165 GNUNET_memcpy (&dst[pos], &h->buffer[h->pos], min); 165 GNUNET_memcpy (&dst[pos],
166 &h->buffer[h->pos],
167 min);
166 h->pos += min; 168 h->pos += min;
167 pos += min; 169 pos += min;
168 } 170 }
169 if (pos == len) 171 if (pos == len)
170 return GNUNET_OK; /* done! */ 172 return GNUNET_OK; /* done! */
171 GNUNET_assert (h->have == h->pos); 173 GNUNET_assert (((off_t) h->have) == h->pos);
172 /* fill buffer */ 174 /* fill buffer */
173 ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size); 175 ret = GNUNET_DISK_file_read (h->fd,
176 h->buffer,
177 h->size);
174 if (-1 == ret) 178 if (-1 == ret)
175 { 179 {
176 GNUNET_asprintf (&h->emsg, 180 GNUNET_asprintf (&h->emsg,
@@ -287,7 +291,9 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
287 char *buf; 291 char *buf;
288 struct GNUNET_CONTAINER_MetaData *meta; 292 struct GNUNET_CONTAINER_MetaData *meta;
289 293
290 if (GNUNET_BIO_read_int32 (h, (int32_t *) & size) != GNUNET_OK) 294 if (GNUNET_OK !=
295 GNUNET_BIO_read_int32 (h,
296 (int32_t *) & size))
291 return GNUNET_SYSERR; 297 return GNUNET_SYSERR;
292 if (size == 0) 298 if (size == 0)
293 { 299 {
@@ -298,20 +304,29 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
298 { 304 {
299 GNUNET_asprintf (&h->emsg, 305 GNUNET_asprintf (&h->emsg,
300 _("Serialized metadata `%s' larger than allowed (%u>%u)"), 306 _("Serialized metadata `%s' larger than allowed (%u>%u)"),
301 what, size, MAX_META_DATA); 307 what,
308 size,
309 MAX_META_DATA);
302 return GNUNET_SYSERR; 310 return GNUNET_SYSERR;
303 } 311 }
304 buf = GNUNET_malloc (size); 312 buf = GNUNET_malloc (size);
305 if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, size)) 313 if (GNUNET_OK !=
314 GNUNET_BIO_read (h,
315 what,
316 buf,
317 size))
306 { 318 {
307 GNUNET_free (buf); 319 GNUNET_free (buf);
308 return GNUNET_SYSERR; 320 return GNUNET_SYSERR;
309 } 321 }
310 meta = GNUNET_CONTAINER_meta_data_deserialize (buf, size); 322 meta = GNUNET_CONTAINER_meta_data_deserialize (buf,
311 if (meta == NULL) 323 size);
324 if (NULL == meta)
312 { 325 {
313 GNUNET_free (buf); 326 GNUNET_free (buf);
314 GNUNET_asprintf (&h->emsg, _("Metadata `%s' failed to deserialize"), what); 327 GNUNET_asprintf (&h->emsg,
328 _("Metadata `%s' failed to deserialize"),
329 what);
315 return GNUNET_SYSERR; 330 return GNUNET_SYSERR;
316 } 331 }
317 GNUNET_free (buf); 332 GNUNET_free (buf);
@@ -330,12 +345,19 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
330 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 345 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
331 */ 346 */
332int 347int
333GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, const char *file, 348GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
334 int line, int32_t * i) 349 const char *file,
350 int line,
351 int32_t * i)
335{ 352{
336 int32_t big; 353 int32_t big;
337 354
338 if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof (int32_t))) 355 if (GNUNET_OK !=
356 GNUNET_BIO_read_fn (h,
357 file,
358 line,
359 &big,
360 sizeof (int32_t)))
339 return GNUNET_SYSERR; 361 return GNUNET_SYSERR;
340 *i = ntohl (big); 362 *i = ntohl (big);
341 return GNUNET_OK; 363 return GNUNET_OK;
@@ -359,7 +381,12 @@ GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h,
359{ 381{
360 int64_t big; 382 int64_t big;
361 383
362 if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof (int64_t))) 384 if (GNUNET_OK !=
385 GNUNET_BIO_read_fn (h,
386 file,
387 line,
388 &big,
389 sizeof (int64_t)))
363 return GNUNET_SYSERR; 390 return GNUNET_SYSERR;
364 *i = GNUNET_ntohll (big); 391 *i = GNUNET_ntohll (big);
365 return GNUNET_OK; 392 return GNUNET_OK;
@@ -432,7 +459,8 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
432 int ret; 459 int ret;
433 460
434 ret = GNUNET_SYSERR; 461 ret = GNUNET_SYSERR;
435 if ( (NULL != h->fd) && (GNUNET_OK == (ret = GNUNET_BIO_flush (h))) ) 462 if ( (NULL != h->fd) &&
463 (GNUNET_OK == (ret = GNUNET_BIO_flush (h))) )
436 GNUNET_DISK_file_close (h->fd); 464 GNUNET_DISK_file_close (h->fd);
437 GNUNET_free (h); 465 GNUNET_free (h);
438 return ret; 466 return ret;
@@ -451,8 +479,10 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
451{ 479{
452 ssize_t ret; 480 ssize_t ret;
453 481
454 ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->have); 482 ret = GNUNET_DISK_file_write (h->fd,
455 if (ret != h->have) 483 h->buffer,
484 h->have);
485 if (ret != (ssize_t) h->have)
456 { 486 {
457 GNUNET_DISK_file_close (h->fd); 487 GNUNET_DISK_file_close (h->fd);
458 h->fd = NULL; 488 h->fd = NULL;
@@ -472,7 +502,8 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
472 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 502 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
473 */ 503 */
474int 504int
475GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer, 505GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
506 const void *buffer,
476 size_t n) 507 size_t n)
477{ 508{
478 const char *src = buffer; 509 const char *src = buffer;
@@ -488,7 +519,9 @@ GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer,
488 min = h->size - h->have; 519 min = h->size - h->have;
489 if (min > n - pos) 520 if (min > n - pos)
490 min = n - pos; 521 min = n - pos;
491 GNUNET_memcpy (&h->buffer[h->have], &src[pos], min); 522 GNUNET_memcpy (&h->buffer[h->have],
523 &src[pos],
524 min);
492 pos += min; 525 pos += min;
493 h->have += min; 526 h->have += min;
494 if (pos == n) 527 if (pos == n)
diff --git a/src/util/client.c b/src/util/client.c
index 3d74bff33..7a718fc8d 100644
--- a/src/util/client.c
+++ b/src/util/client.c
@@ -261,14 +261,27 @@ transmit_ready (void *cls)
261 pos = (const char *) cstate->msg; 261 pos = (const char *) cstate->msg;
262 len = ntohs (cstate->msg->size); 262 len = ntohs (cstate->msg->size);
263 GNUNET_assert (cstate->msg_off < len); 263 GNUNET_assert (cstate->msg_off < len);
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
265 "client: message of type %u trying to send with socket %p (MQ: %p\n",
266 ntohs(cstate->msg->type),
267 cstate->sock,
268 cstate->mq);
269
264 RETRY: 270 RETRY:
265 ret = GNUNET_NETWORK_socket_send (cstate->sock, 271 ret = GNUNET_NETWORK_socket_send (cstate->sock,
266 &pos[cstate->msg_off], 272 &pos[cstate->msg_off],
267 len - cstate->msg_off); 273 len - cstate->msg_off);
268 if (-1 == ret) 274 if (-1 == ret)
269 { 275 {
270 if (EINTR == errno) 276 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
277 "client: error during sending message of type %u\n",
278 ntohs(cstate->msg->type));
279 if (EINTR == errno){
280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
281 "client: retrying message of type %u\n",
282 ntohs(cstate->msg->type));
271 goto RETRY; 283 goto RETRY;
284 }
272 GNUNET_MQ_inject_error (cstate->mq, 285 GNUNET_MQ_inject_error (cstate->mq,
273 GNUNET_MQ_ERROR_WRITE); 286 GNUNET_MQ_ERROR_WRITE);
274 return; 287 return;
@@ -277,6 +290,9 @@ transmit_ready (void *cls)
277 cstate->msg_off += ret; 290 cstate->msg_off += ret;
278 if (cstate->msg_off < len) 291 if (cstate->msg_off < len)
279 { 292 {
293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
294 "client: rescheduling message of type %u\n",
295 ntohs(cstate->msg->type));
280 cstate->send_task 296 cstate->send_task
281 = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 297 = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
282 cstate->sock, 298 cstate->sock,
@@ -286,6 +302,9 @@ transmit_ready (void *cls)
286 GNUNET_MQ_impl_send_in_flight (cstate->mq); 302 GNUNET_MQ_impl_send_in_flight (cstate->mq);
287 return; 303 return;
288 } 304 }
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
306 "client: sending message of type %u successful\n",
307 ntohs(cstate->msg->type));
289 cstate->msg = NULL; 308 cstate->msg = NULL;
290 GNUNET_MQ_impl_send_continue (cstate->mq); 309 GNUNET_MQ_impl_send_continue (cstate->mq);
291} 310}
@@ -297,7 +316,9 @@ transmit_ready (void *cls)
297 * 316 *
298 * @param cls the `struct ClientState` 317 * @param cls the `struct ClientState`
299 * @param msg message we received. 318 * @param msg message we received.
300 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing 319 * @return #GNUNET_OK on success,
320 * #GNUNET_NO to stop further processing due to disconnect (no error)
321 * #GNUNET_SYSERR to stop further processing due to error
301 */ 322 */
302static int 323static int
303recv_message (void *cls, 324recv_message (void *cls,
@@ -306,7 +327,7 @@ recv_message (void *cls,
306 struct ClientState *cstate = cls; 327 struct ClientState *cstate = cls;
307 328
308 if (GNUNET_YES == cstate->in_destroy) 329 if (GNUNET_YES == cstate->in_destroy)
309 return GNUNET_SYSERR; 330 return GNUNET_NO;
310 LOG (GNUNET_ERROR_TYPE_DEBUG, 331 LOG (GNUNET_ERROR_TYPE_DEBUG,
311 "Received message of type %u and size %u from %s\n", 332 "Received message of type %u and size %u from %s\n",
312 ntohs (msg->type), 333 ntohs (msg->type),
@@ -315,7 +336,7 @@ recv_message (void *cls,
315 GNUNET_MQ_inject_message (cstate->mq, 336 GNUNET_MQ_inject_message (cstate->mq,
316 msg); 337 msg);
317 if (GNUNET_YES == cstate->in_destroy) 338 if (GNUNET_YES == cstate->in_destroy)
318 return GNUNET_SYSERR; 339 return GNUNET_NO;
319 return GNUNET_OK; 340 return GNUNET_OK;
320} 341}
321 342
@@ -356,6 +377,7 @@ connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq,
356{ 377{
357 struct ClientState *cstate = impl_state; 378 struct ClientState *cstate = impl_state;
358 379
380 (void) mq;
359 if (GNUNET_SYSERR == cstate->in_destroy) 381 if (GNUNET_SYSERR == cstate->in_destroy)
360 { 382 {
361 /* defer destruction */ 383 /* defer destruction */
@@ -371,8 +393,12 @@ connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq,
371 GNUNET_SCHEDULER_cancel (cstate->recv_task); 393 GNUNET_SCHEDULER_cancel (cstate->recv_task);
372 if (NULL != cstate->retry_task) 394 if (NULL != cstate->retry_task)
373 GNUNET_SCHEDULER_cancel (cstate->retry_task); 395 GNUNET_SCHEDULER_cancel (cstate->retry_task);
374 if (NULL != cstate->sock) 396 if (NULL != cstate->sock){
397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
398 "client: destroying socket: %p\n",
399 cstate->sock);
375 GNUNET_NETWORK_socket_close (cstate->sock); 400 GNUNET_NETWORK_socket_close (cstate->sock);
401 }
376 cancel_aps (cstate); 402 cancel_aps (cstate);
377 GNUNET_free (cstate->service_name); 403 GNUNET_free (cstate->service_name);
378 GNUNET_free_non_null (cstate->hostname); 404 GNUNET_free_non_null (cstate->hostname);
@@ -789,13 +815,18 @@ connection_client_send_impl (struct GNUNET_MQ_Handle *mq,
789{ 815{
790 struct ClientState *cstate = impl_state; 816 struct ClientState *cstate = impl_state;
791 817
818 (void) mq;
792 /* only one message at a time allowed */ 819 /* only one message at a time allowed */
793 GNUNET_assert (NULL == cstate->msg); 820 GNUNET_assert (NULL == cstate->msg);
794 GNUNET_assert (NULL == cstate->send_task); 821 GNUNET_assert (NULL == cstate->send_task);
795 cstate->msg = msg; 822 cstate->msg = msg;
796 cstate->msg_off = 0; 823 cstate->msg_off = 0;
797 if (NULL == cstate->sock) 824 if (NULL == cstate->sock){
825 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
826 "client: message of type %u waiting for socket\n",
827 ntohs(msg->type));
798 return; /* still waiting for connection */ 828 return; /* still waiting for connection */
829 }
799 cstate->send_task 830 cstate->send_task
800 = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 831 = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
801 cstate->sock, 832 cstate->sock,
@@ -816,6 +847,7 @@ connection_client_cancel_impl (struct GNUNET_MQ_Handle *mq,
816{ 847{
817 struct ClientState *cstate = impl_state; 848 struct ClientState *cstate = impl_state;
818 849
850 (void) mq;
819 GNUNET_assert (NULL != cstate->msg); 851 GNUNET_assert (NULL != cstate->msg);
820 GNUNET_assert (0 == cstate->msg_off); 852 GNUNET_assert (0 == cstate->msg_off);
821 cstate->msg = NULL; 853 cstate->msg = NULL;
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c
index 737584815..1c55d72b5 100644
--- a/src/util/common_allocation.c
+++ b/src/util/common_allocation.c
@@ -100,8 +100,11 @@ GNUNET_xmalloc_ (size_t size,
100 * @return allocated memory, never NULL 100 * @return allocated memory, never NULL
101 */ 101 */
102void ** 102void **
103GNUNET_xnew_array_2d_ (size_t n, size_t m, size_t elementSize, 103GNUNET_xnew_array_2d_ (size_t n,
104 const char *filename, int linenumber) 104 size_t m,
105 size_t elementSize,
106 const char *filename,
107 int linenumber)
105{ 108{
106 /* use char pointer internally to avoid void pointer arithmetic warnings */ 109 /* use char pointer internally to avoid void pointer arithmetic warnings */
107 char **ret = GNUNET_xmalloc_ (n * sizeof (void *) + /* 1. dim header */ 110 char **ret = GNUNET_xmalloc_ (n * sizeof (void *) + /* 1. dim header */
@@ -218,6 +221,8 @@ GNUNET_xmalloc_unchecked_ (size_t size,
218{ 221{
219 void *result; 222 void *result;
220 223
224 (void) filename;
225 (void) linenumber;
221#ifdef W32_MEM_LIMIT 226#ifdef W32_MEM_LIMIT
222 size += sizeof (size_t); 227 size += sizeof (size_t);
223 if (mem_used + size > W32_MEM_LIMIT) 228 if (mem_used + size > W32_MEM_LIMIT)
@@ -256,6 +261,9 @@ GNUNET_xrealloc_ (void *ptr,
256 const char *filename, 261 const char *filename,
257 int linenumber) 262 int linenumber)
258{ 263{
264 (void) filename;
265 (void) linenumber;
266
259#ifdef W32_MEM_LIMIT 267#ifdef W32_MEM_LIMIT
260 n += sizeof (size_t); 268 n += sizeof (size_t);
261 ptr = &((size_t *) ptr)[-1]; 269 ptr = &((size_t *) ptr)[-1];
@@ -264,7 +272,8 @@ GNUNET_xrealloc_ (void *ptr,
264 ptr = realloc (ptr, n); 272 ptr = realloc (ptr, n);
265 if ((NULL == ptr) && (n > 0)) 273 if ((NULL == ptr) && (n > 0))
266 { 274 {
267 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "realloc"); 275 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
276 "realloc");
268 GNUNET_assert (0); 277 GNUNET_assert (0);
269 } 278 }
270#ifdef W32_MEM_LIMIT 279#ifdef W32_MEM_LIMIT
@@ -466,8 +475,8 @@ GNUNET_xgrow_ (void **old,
466 */ 475 */
467int 476int
468GNUNET_asprintf (char **buf, 477GNUNET_asprintf (char **buf,
469 const char *format, 478 const char *format,
470 ...) 479 ...)
471{ 480{
472 int ret; 481 int ret;
473 va_list args; 482 va_list args;
@@ -475,6 +484,7 @@ GNUNET_asprintf (char **buf,
475 va_start (args, format); 484 va_start (args, format);
476 ret = VSNPRINTF (NULL, 0, format, args); 485 ret = VSNPRINTF (NULL, 0, format, args);
477 va_end (args); 486 va_end (args);
487 GNUNET_assert (ret >= 0);
478 *buf = GNUNET_malloc (ret + 1); 488 *buf = GNUNET_malloc (ret + 1);
479 va_start (args, format); 489 va_start (args, format);
480 ret = VSPRINTF (*buf, format, args); 490 ret = VSPRINTF (*buf, format, args);
@@ -501,9 +511,13 @@ GNUNET_snprintf (char *buf,
501 va_list args; 511 va_list args;
502 512
503 va_start (args, format); 513 va_start (args, format);
504 ret = VSNPRINTF (buf, size, format, args); 514 ret = VSNPRINTF (buf,
515 size,
516 format,
517 args);
505 va_end (args); 518 va_end (args);
506 GNUNET_assert (ret < size); 519 GNUNET_assert ( (ret >= 0) &&
520 (((size_t) ret) < size) );
507 return ret; 521 return ret;
508} 522}
509 523
@@ -523,7 +537,9 @@ GNUNET_copy_message (const struct GNUNET_MessageHeader *msg)
523 msize = ntohs (msg->size); 537 msize = ntohs (msg->size);
524 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); 538 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
525 ret = GNUNET_malloc (msize); 539 ret = GNUNET_malloc (msize);
526 GNUNET_memcpy (ret, msg, msize); 540 GNUNET_memcpy (ret,
541 msg,
542 msize);
527 return ret; 543 return ret;
528} 544}
529 545
diff --git a/src/util/common_logging.c b/src/util/common_logging.c
index 3e71fa476..ea5430191 100644
--- a/src/util/common_logging.c
+++ b/src/util/common_logging.c
@@ -976,20 +976,25 @@ mylog (enum GNUNET_ErrorType kind,
976 } 976 }
977 else 977 else
978 { 978 {
979 strftime (date2, 979 if (0 ==
980 DATE_STR_SIZE, 980 strftime (date2,
981 "%b %d %H:%M:%S-%%020llu", 981 DATE_STR_SIZE,
982 tmptr); 982 "%b %d %H:%M:%S-%%020llu",
983 snprintf (date, 983 tmptr))
984 sizeof (date), 984 abort ();
985 date2, 985 if (0 >
986 (long long) (pc.QuadPart / 986 snprintf (date,
987 (performance_frequency.QuadPart / 1000))); 987 sizeof (date),
988 date2,
989 (long long) (pc.QuadPart /
990 (performance_frequency.QuadPart / 1000))))
991 abort ();
988 } 992 }
989#else 993#else
990 struct timeval timeofday; 994 struct timeval timeofday;
991 995
992 gettimeofday (&timeofday, NULL); 996 gettimeofday (&timeofday,
997 NULL);
993 offset = GNUNET_TIME_get_offset (); 998 offset = GNUNET_TIME_get_offset ();
994 if (offset > 0) 999 if (offset > 0)
995 { 1000 {
@@ -1022,24 +1027,33 @@ mylog (enum GNUNET_ErrorType kind,
1022 } 1027 }
1023 else 1028 else
1024 { 1029 {
1025 strftime (date2, 1030 if (0 ==
1026 DATE_STR_SIZE, 1031 strftime (date2,
1027 "%b %d %H:%M:%S-%%06u", 1032 DATE_STR_SIZE,
1028 tmptr); 1033 "%b %d %H:%M:%S-%%06u",
1029 snprintf (date, 1034 tmptr))
1030 sizeof (date), 1035 abort ();
1031 date2, 1036 if (0 >
1032 timeofday.tv_usec); 1037 snprintf (date,
1038 sizeof (date),
1039 date2,
1040 timeofday.tv_usec))
1041 abort ();
1033 } 1042 }
1034#endif 1043#endif
1035 VSNPRINTF (buf, size, message, va); 1044 VSNPRINTF (buf,
1045 size,
1046 message,
1047 va);
1036#if ! (defined(GNUNET_CULL_LOGGING) || TALER_WALLET_ONLY) 1048#if ! (defined(GNUNET_CULL_LOGGING) || TALER_WALLET_ONLY)
1037 if (NULL != tmptr) 1049 if (NULL != tmptr)
1038 (void) setup_log_file (tmptr); 1050 (void) setup_log_file (tmptr);
1039#endif 1051#endif
1040 if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) && 1052 if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) &&
1041 (0 != last_bulk_time.abs_value_us) && 1053 (0 != last_bulk_time.abs_value_us) &&
1042 (0 == strncmp (buf, last_bulk, sizeof (last_bulk)))) 1054 (0 == strncmp (buf,
1055 last_bulk,
1056 sizeof (last_bulk))))
1043 { 1057 {
1044 last_bulk_repeat++; 1058 last_bulk_repeat++;
1045 if ( (GNUNET_TIME_absolute_get_duration (last_bulk_time).rel_value_us > 1059 if ( (GNUNET_TIME_absolute_get_duration (last_bulk_time).rel_value_us >
diff --git a/src/util/configuration.c b/src/util/configuration.c
index f63903b4e..25eeaf80f 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -324,6 +324,7 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
324 char *endsep; 324 char *endsep;
325 int dirty; 325 int dirty;
326 int ret; 326 int ret;
327 ssize_t sret;
327 328
328 fn = GNUNET_STRINGS_filename_expand (filename); 329 fn = GNUNET_STRINGS_filename_expand (filename);
329 LOG (GNUNET_ERROR_TYPE_DEBUG, 330 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -333,7 +334,10 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
333 return GNUNET_SYSERR; 334 return GNUNET_SYSERR;
334 dirty = cfg->dirty; /* back up value! */ 335 dirty = cfg->dirty; /* back up value! */
335 if (GNUNET_SYSERR == 336 if (GNUNET_SYSERR ==
336 GNUNET_DISK_file_size (fn, &fs64, GNUNET_YES, GNUNET_YES)) 337 GNUNET_DISK_file_size (fn,
338 &fs64,
339 GNUNET_YES,
340 GNUNET_YES))
337 { 341 {
338 LOG (GNUNET_ERROR_TYPE_WARNING, 342 LOG (GNUNET_ERROR_TYPE_WARNING,
339 "Error while determining the file size of `%s'\n", 343 "Error while determining the file size of `%s'\n",
@@ -349,7 +353,11 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
349 } 353 }
350 fs = fs64; 354 fs = fs64;
351 mem = GNUNET_malloc (fs); 355 mem = GNUNET_malloc (fs);
352 if (fs != GNUNET_DISK_fn_read (fn, mem, fs)) 356 sret = GNUNET_DISK_fn_read (fn,
357 mem,
358 fs);
359 if ( (sret < 0) ||
360 (fs != (size_t) sret) )
353 { 361 {
354 LOG (GNUNET_ERROR_TYPE_WARNING, 362 LOG (GNUNET_ERROR_TYPE_WARNING,
355 _("Error while reading file `%s'\n"), 363 _("Error while reading file `%s'\n"),
@@ -413,7 +421,6 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
413 size_t m_size; 421 size_t m_size;
414 size_t c_size; 422 size_t c_size;
415 423
416
417 /* Pass1 : calculate the buffer size required */ 424 /* Pass1 : calculate the buffer size required */
418 m_size = 0; 425 m_size = 0;
419 for (sec = cfg->sections; NULL != sec; sec = sec->next) 426 for (sec = cfg->sections; NULL != sec; sec = sec->next)
@@ -495,6 +502,7 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
495 char *fn; 502 char *fn;
496 char *cfg_buf; 503 char *cfg_buf;
497 size_t size; 504 size_t size;
505 ssize_t sret;
498 506
499 fn = GNUNET_STRINGS_filename_expand (filename); 507 fn = GNUNET_STRINGS_filename_expand (filename);
500 if (fn == NULL) 508 if (fn == NULL)
@@ -505,11 +513,13 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
505 return GNUNET_SYSERR; 513 return GNUNET_SYSERR;
506 } 514 }
507 cfg_buf = GNUNET_CONFIGURATION_serialize (cfg, &size); 515 cfg_buf = GNUNET_CONFIGURATION_serialize (cfg, &size);
508 if (size != GNUNET_DISK_fn_write (fn, cfg_buf, size, 516 sret = GNUNET_DISK_fn_write (fn, cfg_buf, size,
509 GNUNET_DISK_PERM_USER_READ 517 GNUNET_DISK_PERM_USER_READ
510 | GNUNET_DISK_PERM_USER_WRITE 518 | GNUNET_DISK_PERM_USER_WRITE
511 | GNUNET_DISK_PERM_GROUP_READ 519 | GNUNET_DISK_PERM_GROUP_READ
512 | GNUNET_DISK_PERM_GROUP_WRITE)) 520 | GNUNET_DISK_PERM_GROUP_WRITE);
521 if ( (sret < 0) ||
522 (size != (size_t) sret) )
513 { 523 {
514 GNUNET_free (fn); 524 GNUNET_free (fn);
515 GNUNET_free (cfg_buf); 525 GNUNET_free (cfg_buf);
@@ -858,13 +868,20 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
858 */ 868 */
859void 869void
860GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, 870GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
861 const char *section, const char *option, 871 const char *section,
872 const char *option,
862 unsigned long long number) 873 unsigned long long number)
863{ 874{
864 char s[64]; 875 char s[64];
865 876
866 GNUNET_snprintf (s, 64, "%llu", number); 877 GNUNET_snprintf (s,
867 GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s); 878 64,
879 "%llu",
880 number);
881 GNUNET_CONFIGURATION_set_value_string (cfg,
882 section,
883 option,
884 s);
868} 885}
869 886
870 887
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c
index aedca232d..95c05b9d7 100644
--- a/src/util/container_bloomfilter.c
+++ b/src/util/container_bloomfilter.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2003, 2004, 2006, 2008, 2011, 2012 GNUnet e.V. 3 Copyright (C) 2001, 2002, 2003, 2004, 2006, 2008, 2011, 2012, 2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -513,10 +513,11 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
513 GNUNET_free (bf); 513 GNUNET_free (bf);
514 return NULL; 514 return NULL;
515 } 515 }
516 if (fsize == 0) 516 if (0 == fsize)
517 { 517 {
518 /* found existing empty file, just overwrite */ 518 /* found existing empty file, just overwrite */
519 if (GNUNET_OK != make_empty_file (bf->fh, size * 4LL)) 519 if (GNUNET_OK !=
520 make_empty_file (bf->fh, size * 4LL))
520 { 521 {
521 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 522 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
522 "write"); 523 "write");
@@ -525,7 +526,7 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
525 return NULL; 526 return NULL;
526 } 527 }
527 } 528 }
528 else if (fsize != size * 4LL) 529 else if (fsize != ((off_t) size) * 4LL)
529 { 530 {
530 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 531 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
531 _("Size of file on disk is incorrect for this Bloom filter (want %llu, have %llu)\n"), 532 _("Size of file on disk is incorrect for this Bloom filter (want %llu, have %llu)\n"),
@@ -563,9 +564,9 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
563 bf->filename = GNUNET_strdup (filename); 564 bf->filename = GNUNET_strdup (filename);
564 /* Alloc block */ 565 /* Alloc block */
565 bf->bitArray = GNUNET_malloc_large (size); 566 bf->bitArray = GNUNET_malloc_large (size);
566 if (bf->bitArray == NULL) 567 if (NULL == bf->bitArray)
567 { 568 {
568 if (bf->fh != NULL) 569 if (NULL != bf->fh)
569 GNUNET_DISK_file_close (bf->fh); 570 GNUNET_DISK_file_close (bf->fh);
570 GNUNET_free (bf->filename); 571 GNUNET_free (bf->filename);
571 GNUNET_free (bf); 572 GNUNET_free (bf);
@@ -578,14 +579,18 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
578 /* Read from the file what bits we can */ 579 /* Read from the file what bits we can */
579 rbuff = GNUNET_malloc (BUFFSIZE); 580 rbuff = GNUNET_malloc (BUFFSIZE);
580 pos = 0; 581 pos = 0;
581 while (pos < size * 8LL) 582 while (pos < ((off_t) size) * 8LL)
582 { 583 {
583 int res; 584 int res;
584 585
585 res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE); 586 res = GNUNET_DISK_file_read (bf->fh,
587 rbuff,
588 BUFFSIZE);
586 if (res == -1) 589 if (res == -1)
587 { 590 {
588 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename); 591 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
592 "read",
593 bf->filename);
589 GNUNET_free (rbuff); 594 GNUNET_free (rbuff);
590 GNUNET_free (bf->filename); 595 GNUNET_free (bf->filename);
591 GNUNET_DISK_file_close (bf->fh); 596 GNUNET_DISK_file_close (bf->fh);
@@ -713,11 +718,11 @@ GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf)
713 * 718 *
714 * @param e the element 719 * @param e the element
715 * @param bf the filter 720 * @param bf the filter
716 * @return GNUNET_YES if the element is in the filter, GNUNET_NO if not 721 * @return #GNUNET_YES if the element is in the filter, #GNUNET_NO if not
717 */ 722 */
718int 723int
719GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter 724GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter *bf,
720 *bf, const struct GNUNET_HashCode * e) 725 const struct GNUNET_HashCode * e)
721{ 726{
722 int res; 727 int res;
723 728
@@ -757,7 +762,8 @@ GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf,
757 */ 762 */
758int 763int
759GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, 764GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
760 const char *data, size_t size) 765 const char *data,
766 size_t size)
761{ 767{
762 unsigned int i; 768 unsigned int i;
763 unsigned int n; 769 unsigned int n;
@@ -791,8 +797,7 @@ GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
791 */ 797 */
792int 798int
793GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, 799GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf,
794 const struct GNUNET_CONTAINER_BloomFilter 800 const struct GNUNET_CONTAINER_BloomFilter *to_or)
795 *to_or)
796{ 801{
797 unsigned int i; 802 unsigned int i;
798 unsigned int n; 803 unsigned int n;
@@ -828,13 +833,16 @@ GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf,
828 */ 833 */
829void 834void
830GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, 835GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf,
831 const struct GNUNET_HashCode * e) 836 const struct GNUNET_HashCode *e)
832{ 837{
833 if (NULL == bf) 838 if (NULL == bf)
834 return; 839 return;
835 if (bf->filename == NULL) 840 if (NULL == bf->filename)
836 return; 841 return;
837 iterateBits (bf, &decrementBitCallback, bf, e); 842 iterateBits (bf,
843 &decrementBitCallback,
844 bf,
845 e);
838} 846}
839 847
840/** 848/**
@@ -851,7 +859,8 @@ GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf,
851void 859void
852GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, 860GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
853 GNUNET_CONTAINER_HashCodeIterator iterator, 861 GNUNET_CONTAINER_HashCodeIterator iterator,
854 void *iterator_cls, size_t size, 862 void *iterator_cls,
863 size_t size,
855 unsigned int k) 864 unsigned int k)
856{ 865{
857 struct GNUNET_HashCode hc; 866 struct GNUNET_HashCode hc;
@@ -862,13 +871,16 @@ GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
862 while (i < size) 871 while (i < size)
863 i *= 2; 872 i *= 2;
864 size = i; /* make sure it's a power of 2 */ 873 size = i; /* make sure it's a power of 2 */
865 874 bf->addressesPerElement = k;
866 bf->bitArraySize = size; 875 bf->bitArraySize = size;
867 bf->bitArray = GNUNET_malloc (size); 876 bf->bitArray = GNUNET_malloc (size);
868 if (bf->filename != NULL) 877 if (NULL != bf->filename)
869 make_empty_file (bf->fh, bf->bitArraySize * 4LL); 878 make_empty_file (bf->fh,
870 while (GNUNET_YES == iterator (iterator_cls, &hc)) 879 bf->bitArraySize * 4LL);
871 GNUNET_CONTAINER_bloomfilter_add (bf, &hc); 880 while (GNUNET_YES == iterator (iterator_cls,
881 &hc))
882 GNUNET_CONTAINER_bloomfilter_add (bf,
883 &hc);
872} 884}
873 885
874/* end of container_bloomfilter.c */ 886/* end of container_bloomfilter.c */
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c
index 7845932ee..5d5e8a9ce 100644
--- a/src/util/crypto_ecc.c
+++ b/src/util/crypto_ecc.c
@@ -1242,7 +1242,7 @@ eddsa_d_to_a (gcry_mpi_t d)
1242 size_t rawmpilen; 1242 size_t rawmpilen;
1243 unsigned char digest[64]; /* 512-bit hash value */ 1243 unsigned char digest[64]; /* 512-bit hash value */
1244 gcry_buffer_t hvec[2]; 1244 gcry_buffer_t hvec[2];
1245 int b; 1245 unsigned int b;
1246 gcry_mpi_t a; 1246 gcry_mpi_t a;
1247 1247
1248 b = 256 / 8; /* number of bytes in `d` */ 1248 b = 256 / 8; /* number of bytes in `d` */
@@ -1257,7 +1257,7 @@ eddsa_d_to_a (gcry_mpi_t d)
1257 d)); 1257 d));
1258 hvec[0].data = digest; 1258 hvec[0].data = digest;
1259 hvec[0].off = 0; 1259 hvec[0].off = 0;
1260 hvec[0].len = b > rawmpilen? b - rawmpilen : 0; 1260 hvec[0].len = b > rawmpilen ? (b - rawmpilen) : 0;
1261 hvec[1].data = rawmpi; 1261 hvec[1].data = rawmpi;
1262 hvec[1].off = 0; 1262 hvec[1].off = 0;
1263 hvec[1].len = rawmpilen; 1263 hvec[1].len = rawmpilen;
diff --git a/src/util/crypto_ecc_dlog.c b/src/util/crypto_ecc_dlog.c
index 38e2088cc..91411368f 100644
--- a/src/util/crypto_ecc_dlog.c
+++ b/src/util/crypto_ecc_dlog.c
@@ -130,6 +130,7 @@ GNUNET_CRYPTO_ecc_bin_to_point (struct GNUNET_CRYPTO_EccDlogContext *edc,
130 gcry_ctx_t ctx; 130 gcry_ctx_t ctx;
131 gcry_mpi_point_t q; 131 gcry_mpi_point_t q;
132 132
133 (void) edc;
133 if (0 != gcry_sexp_build (&pub_sexpr, NULL, 134 if (0 != gcry_sexp_build (&pub_sexpr, NULL,
134 "(public-key(ecc(curve " CURVE ")(q %b)))", 135 "(public-key(ecc(curve " CURVE ")(q %b)))",
135 (int) sizeof (bin->q_y), 136 (int) sizeof (bin->q_y),
diff --git a/src/util/crypto_ecc_setup.c b/src/util/crypto_ecc_setup.c
index 64610ddd3..e7caf9ded 100644
--- a/src/util/crypto_ecc_setup.c
+++ b/src/util/crypto_ecc_setup.c
@@ -80,6 +80,7 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
80 unsigned int cnt; 80 unsigned int cnt;
81 int ec; 81 int ec;
82 uint64_t fs; 82 uint64_t fs;
83 ssize_t sret;
83 84
84 if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) 85 if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename))
85 return NULL; 86 return NULL;
@@ -193,7 +194,8 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
193 { 194 {
194 LOG (GNUNET_ERROR_TYPE_ERROR, 195 LOG (GNUNET_ERROR_TYPE_ERROR,
195 _("When trying to read key file `%s' I found %u bytes but I need at least %u.\n"), 196 _("When trying to read key file `%s' I found %u bytes but I need at least %u.\n"),
196 filename, (unsigned int) fs, 197 filename,
198 (unsigned int) fs,
197 (unsigned int) sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); 199 (unsigned int) sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
198 LOG (GNUNET_ERROR_TYPE_ERROR, 200 LOG (GNUNET_ERROR_TYPE_ERROR,
199 _("This may be ok if someone is currently generating a key.\n")); 201 _("This may be ok if someone is currently generating a key.\n"));
@@ -205,12 +207,20 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
205 } 207 }
206 fs = sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey); 208 fs = sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey);
207 priv = GNUNET_malloc (fs); 209 priv = GNUNET_malloc (fs);
208 GNUNET_assert (fs == GNUNET_DISK_file_read (fd, priv, fs)); 210 sret = GNUNET_DISK_file_read (fd,
211 priv,
212 fs);
213 GNUNET_assert ( (sret >= 0) &&
214 (fs == (size_t) sret) );
209 if (GNUNET_YES != 215 if (GNUNET_YES !=
210 GNUNET_DISK_file_unlock (fd, 0, 216 GNUNET_DISK_file_unlock (fd,
217 0,
211 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey))) 218 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)))
212 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); 219 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
213 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); 220 "fcntl",
221 filename);
222 GNUNET_assert (GNUNET_YES ==
223 GNUNET_DISK_file_close (fd));
214 return priv; 224 return priv;
215} 225}
216 226
@@ -237,8 +247,10 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
237 unsigned int cnt; 247 unsigned int cnt;
238 int ec; 248 int ec;
239 uint64_t fs; 249 uint64_t fs;
240 250 ssize_t sret;
241 if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) 251
252 if (GNUNET_SYSERR ==
253 GNUNET_DISK_directory_create_for_file (filename))
242 return NULL; 254 return NULL;
243 while (GNUNET_YES != GNUNET_DISK_file_test (filename)) 255 while (GNUNET_YES != GNUNET_DISK_file_test (filename))
244 { 256 {
@@ -255,19 +267,24 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
255 { 267 {
256 /* must exist but not be accessible, fail for good! */ 268 /* must exist but not be accessible, fail for good! */
257 if (0 != ACCESS (filename, R_OK)) 269 if (0 != ACCESS (filename, R_OK))
258 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename); 270 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
271 "access",
272 filename);
259 else 273 else
260 GNUNET_break (0); /* what is going on!? */ 274 GNUNET_break (0); /* what is going on!? */
261 return NULL; 275 return NULL;
262 } 276 }
263 continue; 277 continue;
264 } 278 }
265 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename); 279 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
280 "open",
281 filename);
266 return NULL; 282 return NULL;
267 } 283 }
268 cnt = 0; 284 cnt = 0;
269 while (GNUNET_YES != 285 while (GNUNET_YES !=
270 GNUNET_DISK_file_lock (fd, 0, 286 GNUNET_DISK_file_lock (fd,
287 0,
271 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 288 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
272 GNUNET_YES)) 289 GNUNET_YES))
273 { 290 {
@@ -276,7 +293,8 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
276 { 293 {
277 ec = errno; 294 ec = errno;
278 LOG (GNUNET_ERROR_TYPE_ERROR, 295 LOG (GNUNET_ERROR_TYPE_ERROR,
279 _("Could not acquire lock on file `%s': %s...\n"), filename, 296 _("Could not acquire lock on file `%s': %s...\n"),
297 filename,
280 STRERROR (ec)); 298 STRERROR (ec));
281 } 299 }
282 } 300 }
@@ -285,21 +303,29 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
285 priv = GNUNET_CRYPTO_ecdsa_key_create (); 303 priv = GNUNET_CRYPTO_ecdsa_key_create ();
286 GNUNET_assert (NULL != priv); 304 GNUNET_assert (NULL != priv);
287 GNUNET_assert (sizeof (*priv) == 305 GNUNET_assert (sizeof (*priv) ==
288 GNUNET_DISK_file_write (fd, priv, sizeof (*priv))); 306 GNUNET_DISK_file_write (fd,
307 priv,
308 sizeof (*priv)));
289 GNUNET_DISK_file_sync (fd); 309 GNUNET_DISK_file_sync (fd);
290 if (GNUNET_YES != 310 if (GNUNET_YES !=
291 GNUNET_DISK_file_unlock (fd, 0, 311 GNUNET_DISK_file_unlock (fd, 0,
292 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 312 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
293 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); 313 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
294 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); 314 "fcntl",
315 filename);
316 GNUNET_assert (GNUNET_YES ==
317 GNUNET_DISK_file_close (fd));
295 return priv; 318 return priv;
296 } 319 }
297 /* key file exists already, read it! */ 320 /* key file exists already, read it! */
298 fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 321 fd = GNUNET_DISK_file_open (filename,
322 GNUNET_DISK_OPEN_READ,
299 GNUNET_DISK_PERM_NONE); 323 GNUNET_DISK_PERM_NONE);
300 if (NULL == fd) 324 if (NULL == fd)
301 { 325 {
302 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename); 326 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
327 "open",
328 filename);
303 return NULL; 329 return NULL;
304 } 330 }
305 cnt = 0; 331 cnt = 0;
@@ -318,25 +344,34 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
318 filename, 344 filename,
319 STRERROR (ec)); 345 STRERROR (ec));
320 LOG (GNUNET_ERROR_TYPE_ERROR, 346 LOG (GNUNET_ERROR_TYPE_ERROR,
321 _ 347 _("This may be ok if someone is currently generating a private key.\n"));
322 ("This may be ok if someone is currently generating a private key.\n"));
323 } 348 }
324 short_wait (); 349 short_wait ();
325 continue; 350 continue;
326 } 351 }
327 if (GNUNET_YES != GNUNET_DISK_file_test (filename)) 352 if (GNUNET_YES !=
353 GNUNET_DISK_file_test (filename))
328 { 354 {
329 /* eh, what!? File we opened is now gone!? */ 355 /* eh, what!? File we opened is now gone!? */
330 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename); 356 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
357 "stat",
358 filename);
331 if (GNUNET_YES != 359 if (GNUNET_YES !=
332 GNUNET_DISK_file_unlock (fd, 0, 360 GNUNET_DISK_file_unlock (fd, 0,
333 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 361 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
334 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); 362 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
335 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); 363 "fcntl",
364 filename);
365 GNUNET_assert (GNUNET_OK ==
366 GNUNET_DISK_file_close (fd));
336 367
337 return NULL; 368 return NULL;
338 } 369 }
339 if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) 370 if (GNUNET_OK !=
371 GNUNET_DISK_file_size (filename,
372 &fs,
373 GNUNET_YES,
374 GNUNET_YES))
340 fs = 0; 375 fs = 0;
341 if (fs < sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)) 376 if (fs < sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))
342 { 377 {
@@ -345,7 +380,9 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
345 if (GNUNET_YES != 380 if (GNUNET_YES !=
346 GNUNET_DISK_file_unlock (fd, 0, 381 GNUNET_DISK_file_unlock (fd, 0,
347 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 382 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
348 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); 383 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
384 "fcntl",
385 filename);
349 if (0 == ++cnt % 10) 386 if (0 == ++cnt % 10)
350 { 387 {
351 LOG (GNUNET_ERROR_TYPE_ERROR, 388 LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -362,12 +399,19 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
362 } 399 }
363 fs = sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey); 400 fs = sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
364 priv = GNUNET_malloc (fs); 401 priv = GNUNET_malloc (fs);
365 GNUNET_assert (fs == GNUNET_DISK_file_read (fd, priv, fs)); 402 sret = GNUNET_DISK_file_read (fd,
403 priv,
404 fs);
405 GNUNET_assert ( (sret >= 0) &&
406 (fs == (size_t) sret) );
366 if (GNUNET_YES != 407 if (GNUNET_YES !=
367 GNUNET_DISK_file_unlock (fd, 0, 408 GNUNET_DISK_file_unlock (fd, 0,
368 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 409 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
369 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); 410 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
370 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); 411 "fcntl",
412 filename);
413 GNUNET_assert (GNUNET_YES ==
414 GNUNET_DISK_file_close (fd));
371 return priv; 415 return priv;
372} 416}
373 417
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index 20c7ca7ff..cce9cf82a 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -69,9 +69,9 @@ GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode *block,
69 char *np; 69 char *np;
70 70
71 np = GNUNET_STRINGS_data_to_string ((const unsigned char *) block, 71 np = GNUNET_STRINGS_data_to_string ((const unsigned char *) block,
72 sizeof (struct GNUNET_HashCode), 72 sizeof (struct GNUNET_HashCode),
73 (char*) result, 73 (char *) result,
74 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1); 74 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1);
75 GNUNET_assert (NULL != np); 75 GNUNET_assert (NULL != np);
76 *np = '\0'; 76 *np = '\0';
77} 77}
diff --git a/src/util/crypto_hash_file.c b/src/util/crypto_hash_file.c
index 3e5900200..cb632d02c 100644
--- a/src/util/crypto_hash_file.c
+++ b/src/util/crypto_hash_file.c
@@ -124,23 +124,29 @@ file_hash_task (void *cls)
124 struct GNUNET_CRYPTO_FileHashContext *fhc = cls; 124 struct GNUNET_CRYPTO_FileHashContext *fhc = cls;
125 struct GNUNET_HashCode *res; 125 struct GNUNET_HashCode *res;
126 size_t delta; 126 size_t delta;
127 ssize_t sret;
127 128
128 fhc->task = NULL; 129 fhc->task = NULL;
129 GNUNET_assert (fhc->offset <= fhc->fsize); 130 GNUNET_assert (fhc->offset <= fhc->fsize);
130 delta = fhc->bsize; 131 delta = fhc->bsize;
131 if (fhc->fsize - fhc->offset < delta) 132 if (fhc->fsize - fhc->offset < delta)
132 delta = fhc->fsize - fhc->offset; 133 delta = fhc->fsize - fhc->offset;
133 if (delta != GNUNET_DISK_file_read (fhc->fh, 134 sret = GNUNET_DISK_file_read (fhc->fh,
134 fhc->buffer, 135 fhc->buffer,
135 delta)) 136 delta);
137 if ( (sret < 0) ||
138 (delta != (size_t) sret) )
136 { 139 {
137 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 140 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
138 "read", 141 "read",
139 fhc->filename); 142 fhc->filename);
140 file_hash_finish (fhc, NULL); 143 file_hash_finish (fhc,
144 NULL);
141 return; 145 return;
142 } 146 }
143 gcry_md_write (fhc->md, fhc->buffer, delta); 147 gcry_md_write (fhc->md,
148 fhc->buffer,
149 delta);
144 fhc->offset += delta; 150 fhc->offset += delta;
145 if (fhc->offset == fhc->fsize) 151 if (fhc->offset == fhc->fsize)
146 { 152 {
diff --git a/src/util/disk.c b/src/util/disk.c
index d536ec897..8fd689070 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -1324,6 +1324,7 @@ static int
1324remove_helper (void *unused, 1324remove_helper (void *unused,
1325 const char *fn) 1325 const char *fn)
1326{ 1326{
1327 (void) unused;
1327 (void) GNUNET_DISK_directory_remove (fn); 1328 (void) GNUNET_DISK_directory_remove (fn);
1328 return GNUNET_OK; 1329 return GNUNET_OK;
1329} 1330}
@@ -1396,6 +1397,7 @@ GNUNET_DISK_file_copy (const char *src,
1396 uint64_t pos; 1397 uint64_t pos;
1397 uint64_t size; 1398 uint64_t size;
1398 size_t len; 1399 size_t len;
1400 ssize_t sret;
1399 struct GNUNET_DISK_FileHandle *in; 1401 struct GNUNET_DISK_FileHandle *in;
1400 struct GNUNET_DISK_FileHandle *out; 1402 struct GNUNET_DISK_FileHandle *out;
1401 1403
@@ -1425,9 +1427,17 @@ GNUNET_DISK_file_copy (const char *src,
1425 len = COPY_BLK_SIZE; 1427 len = COPY_BLK_SIZE;
1426 if (len > size - pos) 1428 if (len > size - pos)
1427 len = size - pos; 1429 len = size - pos;
1428 if (len != GNUNET_DISK_file_read (in, buf, len)) 1430 sret = GNUNET_DISK_file_read (in,
1431 buf,
1432 len);
1433 if ( (sret < 0) ||
1434 (len != (size_t) sret) )
1429 goto FAIL; 1435 goto FAIL;
1430 if (len != GNUNET_DISK_file_write (out, buf, len)) 1436 sret = GNUNET_DISK_file_write (out,
1437 buf,
1438 len);
1439 if ( (sret < 0) ||
1440 (len != (size_t) sret) )
1431 goto FAIL; 1441 goto FAIL;
1432 pos += len; 1442 pos += len;
1433 } 1443 }
@@ -1457,7 +1467,8 @@ GNUNET_DISK_filename_canonicalize (char *fn)
1457 { 1467 {
1458 c = *idx; 1468 c = *idx;
1459 1469
1460 if (c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' || c == '"' || 1470 if (c == '/' || c == '\\' || c == ':' ||
1471 c == '*' || c == '?' || c == '"' ||
1461 c == '<' || c == '>' || c == '|') 1472 c == '<' || c == '>' || c == '|')
1462 { 1473 {
1463 *idx = '_'; 1474 *idx = '_';
@@ -2236,18 +2247,24 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
2236 * @return handle to the new pipe, NULL on error 2247 * @return handle to the new pipe, NULL on error
2237 */ 2248 */
2238struct GNUNET_DISK_PipeHandle * 2249struct GNUNET_DISK_PipeHandle *
2239GNUNET_DISK_pipe (int blocking_read, int blocking_write, int inherit_read, int inherit_write) 2250GNUNET_DISK_pipe (int blocking_read,
2251 int blocking_write,
2252 int inherit_read,
2253 int inherit_write)
2240{ 2254{
2241#ifndef MINGW 2255#ifndef MINGW
2242 int fd[2]; 2256 int fd[2];
2243 int ret; 2257 int ret;
2244 int eno; 2258 int eno;
2245 2259
2260 (void) inherit_read;
2261 (void) inherit_write;
2246 ret = pipe (fd); 2262 ret = pipe (fd);
2247 if (ret == -1) 2263 if (ret == -1)
2248 { 2264 {
2249 eno = errno; 2265 eno = errno;
2250 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe"); 2266 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
2267 "pipe");
2251 errno = eno; 2268 errno = eno;
2252 return NULL; 2269 return NULL;
2253 } 2270 }
diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c
index c3d0e4c7c..c836c9055 100644
--- a/src/util/getopt_helpers.c
+++ b/src/util/getopt_helpers.c
@@ -46,6 +46,8 @@ print_version (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
46{ 46{
47 const char *version = scls; 47 const char *version = scls;
48 48
49 (void) option;
50 (void) value;
49 printf ("%s v%s\n", 51 printf ("%s v%s\n",
50 ctx->binaryName, 52 ctx->binaryName,
51 version); 53 version);
@@ -104,6 +106,8 @@ format_help (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
104 const struct GNUNET_GETOPT_CommandLineOption *opt; 106 const struct GNUNET_GETOPT_CommandLineOption *opt;
105 const struct GNUNET_OS_ProjectData *pd; 107 const struct GNUNET_OS_ProjectData *pd;
106 108
109 (void) option;
110 (void) value;
107 if (NULL != about) 111 if (NULL != about)
108 { 112 {
109 printf ("%s\n%s\n", ctx->binaryOptions, gettext (about)); 113 printf ("%s\n%s\n", ctx->binaryOptions, gettext (about));
@@ -112,7 +116,7 @@ format_help (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
112 } 116 }
113 i = 0; 117 i = 0;
114 opt = ctx->allOptions; 118 opt = ctx->allOptions;
115 while (opt[i].description != NULL) 119 while (NULL != opt[i].description)
116 { 120 {
117 if (opt[i].shortName == '\0') 121 if (opt[i].shortName == '\0')
118 printf (" "); 122 printf (" ");
@@ -120,7 +124,7 @@ format_help (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
120 printf (" -%c, ", opt[i].shortName); 124 printf (" -%c, ", opt[i].shortName);
121 printf ("--%s", opt[i].name); 125 printf ("--%s", opt[i].name);
122 slen = 8 + strlen (opt[i].name); 126 slen = 8 + strlen (opt[i].name);
123 if (opt[i].argumentHelp != NULL) 127 if (NULL != opt[i].argumentHelp)
124 { 128 {
125 printf ("=%s", opt[i].argumentHelp); 129 printf ("=%s", opt[i].argumentHelp);
126 slen += 1 + strlen (opt[i].argumentHelp); 130 slen += 1 + strlen (opt[i].argumentHelp);
@@ -144,7 +148,7 @@ format_help (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
144OUTER: 148OUTER:
145 while (ml - p > 78 - slen) 149 while (ml - p > 78 - slen)
146 { 150 {
147 for (j = p + 78 - slen; j > p; j--) 151 for (j = p + 78 - slen; j > (int) p; j--)
148 { 152 {
149 if (isspace ((unsigned char) trans[j])) 153 if (isspace ((unsigned char) trans[j]))
150 { 154 {
@@ -227,6 +231,9 @@ increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
227{ 231{
228 unsigned int *val = scls; 232 unsigned int *val = scls;
229 233
234 (void) ctx;
235 (void) option;
236 (void) value;
230 (*val)++; 237 (*val)++;
231 return GNUNET_OK; 238 return GNUNET_OK;
232} 239}
@@ -243,9 +250,9 @@ increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
243 */ 250 */
244struct GNUNET_GETOPT_CommandLineOption 251struct GNUNET_GETOPT_CommandLineOption
245GNUNET_GETOPT_option_increment_uint (char shortName, 252GNUNET_GETOPT_option_increment_uint (char shortName,
246 const char *name, 253 const char *name,
247 const char *description, 254 const char *description,
248 unsigned int *val) 255 unsigned int *val)
249{ 256{
250 struct GNUNET_GETOPT_CommandLineOption clo = { 257 struct GNUNET_GETOPT_CommandLineOption clo = {
251 .shortName = shortName, 258 .shortName = shortName,
@@ -302,6 +309,9 @@ set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
302{ 309{
303 int *val = scls; 310 int *val = scls;
304 311
312 (void) ctx;
313 (void) option;
314 (void) value;
305 *val = 1; 315 *val = 1;
306 return GNUNET_OK; 316 return GNUNET_OK;
307} 317}
@@ -319,9 +329,9 @@ set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
319 */ 329 */
320struct GNUNET_GETOPT_CommandLineOption 330struct GNUNET_GETOPT_CommandLineOption
321GNUNET_GETOPT_option_flag (char shortName, 331GNUNET_GETOPT_option_flag (char shortName,
322 const char *name, 332 const char *name,
323 const char *description, 333 const char *description,
324 int *val) 334 int *val)
325{ 335{
326 struct GNUNET_GETOPT_CommandLineOption clo = { 336 struct GNUNET_GETOPT_CommandLineOption clo = {
327 .shortName = shortName, 337 .shortName = shortName,
@@ -357,6 +367,8 @@ set_string (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
357{ 367{
358 char **val = scls; 368 char **val = scls;
359 369
370 (void) ctx;
371 (void) option;
360 GNUNET_assert (NULL != value); 372 GNUNET_assert (NULL != value);
361 GNUNET_free_non_null (*val); 373 GNUNET_free_non_null (*val);
362 *val = GNUNET_strdup (value); 374 *val = GNUNET_strdup (value);
@@ -436,6 +448,8 @@ set_filename (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
436{ 448{
437 char **val = scls; 449 char **val = scls;
438 450
451 (void) ctx;
452 (void) option;
439 GNUNET_assert (NULL != value); 453 GNUNET_assert (NULL != value);
440 GNUNET_free_non_null (*val); 454 GNUNET_free_non_null (*val);
441 *val = GNUNET_STRINGS_filename_expand (value); 455 *val = GNUNET_STRINGS_filename_expand (value);
@@ -454,10 +468,10 @@ set_filename (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
454 */ 468 */
455struct GNUNET_GETOPT_CommandLineOption 469struct GNUNET_GETOPT_CommandLineOption
456GNUNET_GETOPT_option_filename (char shortName, 470GNUNET_GETOPT_option_filename (char shortName,
457 const char *name, 471 const char *name,
458 const char *argumentHelp, 472 const char *argumentHelp,
459 const char *description, 473 const char *description,
460 char **str) 474 char **str)
461{ 475{
462 struct GNUNET_GETOPT_CommandLineOption clo = { 476 struct GNUNET_GETOPT_CommandLineOption clo = {
463 .shortName = shortName, 477 .shortName = shortName,
@@ -538,6 +552,7 @@ set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
538{ 552{
539 unsigned long long *val = scls; 553 unsigned long long *val = scls;
540 554
555 (void) ctx;
541 if (1 != SSCANF (value, 556 if (1 != SSCANF (value,
542 "%llu", 557 "%llu",
543 val)) 558 val))
@@ -562,10 +577,10 @@ set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
562 */ 577 */
563struct GNUNET_GETOPT_CommandLineOption 578struct GNUNET_GETOPT_CommandLineOption
564GNUNET_GETOPT_option_ulong (char shortName, 579GNUNET_GETOPT_option_ulong (char shortName,
565 const char *name, 580 const char *name,
566 const char *argumentHelp, 581 const char *argumentHelp,
567 const char *description, 582 const char *description,
568 unsigned long long *val) 583 unsigned long long *val)
569{ 584{
570 struct GNUNET_GETOPT_CommandLineOption clo = { 585 struct GNUNET_GETOPT_CommandLineOption clo = {
571 .shortName = shortName, 586 .shortName = shortName,
@@ -601,7 +616,8 @@ set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
601 const char *value) 616 const char *value)
602{ 617{
603 struct GNUNET_TIME_Relative *val = scls; 618 struct GNUNET_TIME_Relative *val = scls;
604 619
620 (void) ctx;
605 if (GNUNET_OK != 621 if (GNUNET_OK !=
606 GNUNET_STRINGS_fancy_time_to_relative (value, 622 GNUNET_STRINGS_fancy_time_to_relative (value,
607 val)) 623 val))
@@ -627,10 +643,10 @@ set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
627 */ 643 */
628struct GNUNET_GETOPT_CommandLineOption 644struct GNUNET_GETOPT_CommandLineOption
629GNUNET_GETOPT_option_relative_time (char shortName, 645GNUNET_GETOPT_option_relative_time (char shortName,
630 const char *name, 646 const char *name,
631 const char *argumentHelp, 647 const char *argumentHelp,
632 const char *description, 648 const char *description,
633 struct GNUNET_TIME_Relative *val) 649 struct GNUNET_TIME_Relative *val)
634{ 650{
635 struct GNUNET_GETOPT_CommandLineOption clo = { 651 struct GNUNET_GETOPT_CommandLineOption clo = {
636 .shortName = shortName, 652 .shortName = shortName,
@@ -667,6 +683,7 @@ set_absolute_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
667{ 683{
668 struct GNUNET_TIME_Absolute *val = scls; 684 struct GNUNET_TIME_Absolute *val = scls;
669 685
686 (void) ctx;
670 if (GNUNET_OK != 687 if (GNUNET_OK !=
671 GNUNET_STRINGS_fancy_time_to_absolute (value, 688 GNUNET_STRINGS_fancy_time_to_absolute (value,
672 val)) 689 val))
@@ -692,10 +709,10 @@ set_absolute_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
692 */ 709 */
693struct GNUNET_GETOPT_CommandLineOption 710struct GNUNET_GETOPT_CommandLineOption
694GNUNET_GETOPT_option_absolute_time (char shortName, 711GNUNET_GETOPT_option_absolute_time (char shortName,
695 const char *name, 712 const char *name,
696 const char *argumentHelp, 713 const char *argumentHelp,
697 const char *description, 714 const char *description,
698 struct GNUNET_TIME_Absolute *val) 715 struct GNUNET_TIME_Absolute *val)
699{ 716{
700 struct GNUNET_GETOPT_CommandLineOption clo = { 717 struct GNUNET_GETOPT_CommandLineOption clo = {
701 .shortName = shortName, 718 .shortName = shortName,
@@ -732,6 +749,7 @@ set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
732{ 749{
733 unsigned int *val = scls; 750 unsigned int *val = scls;
734 751
752 (void) ctx;
735 if (1 != SSCANF (value, 753 if (1 != SSCANF (value,
736 "%u", 754 "%u",
737 val)) 755 val))
@@ -756,10 +774,10 @@ set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
756 */ 774 */
757struct GNUNET_GETOPT_CommandLineOption 775struct GNUNET_GETOPT_CommandLineOption
758GNUNET_GETOPT_option_uint (char shortName, 776GNUNET_GETOPT_option_uint (char shortName,
759 const char *name, 777 const char *name,
760 const char *argumentHelp, 778 const char *argumentHelp,
761 const char *description, 779 const char *description,
762 unsigned int *val) 780 unsigned int *val)
763{ 781{
764 struct GNUNET_GETOPT_CommandLineOption clo = { 782 struct GNUNET_GETOPT_CommandLineOption clo = {
765 .shortName = shortName, 783 .shortName = shortName,
@@ -813,6 +831,7 @@ set_base32 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
813{ 831{
814 struct Base32Context *bc = scls; 832 struct Base32Context *bc = scls;
815 833
834 (void) ctx;
816 if (GNUNET_OK != 835 if (GNUNET_OK !=
817 GNUNET_STRINGS_string_to_data (value, 836 GNUNET_STRINGS_string_to_data (value,
818 strlen (value), 837 strlen (value),
diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c
index fb3b9ebf9..5f7d9fc0d 100644
--- a/src/util/gnunet-config.c
+++ b/src/util/gnunet-config.c
@@ -72,12 +72,17 @@ static int rewrite;
72 * @param value value of the option 72 * @param value value of the option
73 */ 73 */
74static void 74static void
75print_option (void *cls, const char *section, 75print_option (void *cls,
76 const char *section,
76 const char *option, 77 const char *option,
77 const char *value) 78 const char *value)
78{ 79{
80 (void) cls;
81 (void) section;
79 fprintf (stdout, 82 fprintf (stdout,
80 "%s = %s\n", option, value); 83 "%s = %s\n",
84 option,
85 value);
81} 86}
82 87
83 88
@@ -91,7 +96,10 @@ static void
91print_section_name (void *cls, 96print_section_name (void *cls,
92 const char *section) 97 const char *section)
93{ 98{
94 fprintf (stdout, "%s\n", section); 99 (void) cls;
100 fprintf (stdout,
101 "%s\n",
102 section);
95} 103}
96 104
97 105
@@ -112,6 +120,8 @@ run (void *cls,
112 struct GNUNET_CONFIGURATION_Handle *out = NULL; 120 struct GNUNET_CONFIGURATION_Handle *out = NULL;
113 struct GNUNET_CONFIGURATION_Handle *diff = NULL; 121 struct GNUNET_CONFIGURATION_Handle *diff = NULL;
114 122
123 (void) cls;
124 (void) args;
115 if (rewrite) 125 if (rewrite)
116 { 126 {
117 struct GNUNET_CONFIGURATION_Handle *def; 127 struct GNUNET_CONFIGURATION_Handle *def;
@@ -221,36 +231,37 @@ run (void *cls,
221 * @return 0 ok, 1 on error 231 * @return 0 ok, 1 on error
222 */ 232 */
223int 233int
224main (int argc, char *const *argv) 234main (int argc,
235 char *const *argv)
225{ 236{
226 struct GNUNET_GETOPT_CommandLineOption options[] = { 237 struct GNUNET_GETOPT_CommandLineOption options[] = {
227 GNUNET_GETOPT_option_flag ('f', 238 GNUNET_GETOPT_option_flag ('f',
228 "filename", 239 "filename",
229 gettext_noop ("obtain option of value as a filename (with $-expansion)"), 240 gettext_noop ("obtain option of value as a filename (with $-expansion)"),
230 &is_filename), 241 &is_filename),
231 GNUNET_GETOPT_option_string ('s', 242 GNUNET_GETOPT_option_string ('s',
232 "section", 243 "section",
233 "SECTION", 244 "SECTION",
234 gettext_noop ("name of the section to access"), 245 gettext_noop ("name of the section to access"),
235 &section), 246 &section),
236 GNUNET_GETOPT_option_string ('o', 247 GNUNET_GETOPT_option_string ('o',
237 "option", 248 "option",
238 "OPTION", 249 "OPTION",
239 gettext_noop ("name of the option to access"), 250 gettext_noop ("name of the option to access"),
240 &option), 251 &option),
241 GNUNET_GETOPT_option_string ('V', 252 GNUNET_GETOPT_option_string ('V',
242 "value", 253 "value",
243 "VALUE", 254 "VALUE",
244 gettext_noop ("value to set"), 255 gettext_noop ("value to set"),
245 &value), 256 &value),
246 GNUNET_GETOPT_option_flag ('S', 257 GNUNET_GETOPT_option_flag ('S',
247 "list-sections", 258 "list-sections",
248 gettext_noop ("print available configuration sections"), 259 gettext_noop ("print available configuration sections"),
249 &list_sections), 260 &list_sections),
250 GNUNET_GETOPT_option_flag ('w', 261 GNUNET_GETOPT_option_flag ('w',
251 "rewrite", 262 "rewrite",
252 gettext_noop ("write configuration file that only contains delta to defaults"), 263 gettext_noop ("write configuration file that only contains delta to defaults"),
253 &rewrite), 264 &rewrite),
254 GNUNET_GETOPT_OPTION_END 265 GNUNET_GETOPT_OPTION_END
255 }; 266 };
256 if (GNUNET_OK != 267 if (GNUNET_OK !=
diff --git a/src/util/gnunet-ecc.c b/src/util/gnunet-ecc.c
index 66a4bd3e9..59a100a8c 100644
--- a/src/util/gnunet-ecc.c
+++ b/src/util/gnunet-ecc.c
@@ -281,8 +281,10 @@ print_key (const char *filename)
281 uint64_t fs; 281 uint64_t fs;
282 unsigned int total_hostkeys; 282 unsigned int total_hostkeys;
283 unsigned int c; 283 unsigned int c;
284 ssize_t sret;
284 285
285 if (GNUNET_YES != GNUNET_DISK_file_test (filename)) 286 if (GNUNET_YES !=
287 GNUNET_DISK_file_test (filename))
286 { 288 {
287 fprintf (stderr, 289 fprintf (stderr,
288 _("Hostkeys file `%s' not found\n"), 290 _("Hostkeys file `%s' not found\n"),
@@ -291,7 +293,11 @@ print_key (const char *filename)
291 } 293 }
292 294
293 /* Check hostkey file size, read entire thing into memory */ 295 /* Check hostkey file size, read entire thing into memory */
294 if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) 296 if (GNUNET_OK !=
297 GNUNET_DISK_file_size (filename,
298 &fs,
299 GNUNET_YES,
300 GNUNET_YES))
295 fs = 0; 301 fs = 0;
296 if (0 == fs) 302 if (0 == fs)
297 { 303 {
@@ -307,15 +313,22 @@ print_key (const char *filename)
307 filename); 313 filename);
308 return; 314 return;
309 } 315 }
310 fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 316 fd = GNUNET_DISK_file_open (filename,
311 GNUNET_DISK_PERM_NONE); 317 GNUNET_DISK_OPEN_READ,
318 GNUNET_DISK_PERM_NONE);
312 if (NULL == fd) 319 if (NULL == fd)
313 { 320 {
314 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename); 321 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
322 "open",
323 filename);
315 return; 324 return;
316 } 325 }
317 hostkeys_data = GNUNET_malloc (fs); 326 hostkeys_data = GNUNET_malloc (fs);
318 if (fs != GNUNET_DISK_file_read (fd, hostkeys_data, fs)) 327 sret = GNUNET_DISK_file_read (fd,
328 hostkeys_data,
329 fs);
330 if ( (sret < 0) ||
331 (fs != (size_t) sret) )
319 { 332 {
320 fprintf (stderr, 333 fprintf (stderr,
321 _("Could not read hostkey file: %s\n"), 334 _("Could not read hostkey file: %s\n"),
@@ -351,15 +364,21 @@ print_key (const char *filename)
351/** 364/**
352 * Main function that will be run by the scheduler. 365 * Main function that will be run by the scheduler.
353 * 366 *
354 * @param cls closure 367 * @param cls closure, NULL
355 * @param args remaining command-line arguments 368 * @param args remaining command-line arguments
356 * @param cfgfile name of the configuration file used (for saving, can be NULL!) 369 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
357 * @param cfg configuration 370 * @param cfg configuration
358 */ 371 */
359static void 372static void
360run (void *cls, char *const *args, const char *cfgfile, 373run (void *cls,
374 char *const *args,
375 const char *cfgfile,
361 const struct GNUNET_CONFIGURATION_Handle *cfg) 376 const struct GNUNET_CONFIGURATION_Handle *cfg)
362{ 377{
378 (void) cls;
379 (void) cfgfile;
380 (void) cfg;
381
363 if (print_examples_flag) 382 if (print_examples_flag)
364 { 383 {
365 print_examples (); 384 print_examples ();
diff --git a/src/util/gnunet-resolver.c b/src/util/gnunet-resolver.c
index 7ffafee32..4954e0398 100644
--- a/src/util/gnunet-resolver.c
+++ b/src/util/gnunet-resolver.c
@@ -46,9 +46,12 @@ static void
46print_hostname (void *cls, 46print_hostname (void *cls,
47 const char *hostname) 47 const char *hostname)
48{ 48{
49 (void) cls;
49 if (NULL == hostname) 50 if (NULL == hostname)
50 return; 51 return;
51 FPRINTF (stdout, "%s\n", hostname); 52 FPRINTF (stdout,
53 "%s\n",
54 hostname);
52} 55}
53 56
54 57
@@ -60,11 +63,17 @@ print_hostname (void *cls,
60 * @param addrlen length of the address 63 * @param addrlen length of the address
61 */ 64 */
62static void 65static void
63print_sockaddr (void *cls, const struct sockaddr *addr, socklen_t addrlen) 66print_sockaddr (void *cls,
67 const struct sockaddr *addr,
68 socklen_t addrlen)
64{ 69{
70 (void) cls;
65 if (NULL == addr) 71 if (NULL == addr)
66 return; 72 return;
67 FPRINTF (stdout, "%s\n", GNUNET_a2s (addr, addrlen)); 73 FPRINTF (stdout,
74 "%s\n",
75 GNUNET_a2s (addr,
76 addrlen));
68} 77}
69 78
70 79
@@ -77,7 +86,9 @@ print_sockaddr (void *cls, const struct sockaddr *addr, socklen_t addrlen)
77 * @param cfg configuration 86 * @param cfg configuration
78 */ 87 */
79static void 88static void
80run (void *cls, char *const *args, const char *cfgfile, 89run (void *cls,
90 char *const *args,
91 const char *cfgfile,
81 const struct GNUNET_CONFIGURATION_Handle *cfg) 92 const struct GNUNET_CONFIGURATION_Handle *cfg)
82{ 93{
83 const struct sockaddr *sa; 94 const struct sockaddr *sa;
@@ -85,11 +96,18 @@ run (void *cls, char *const *args, const char *cfgfile,
85 struct sockaddr_in v4; 96 struct sockaddr_in v4;
86 struct sockaddr_in6 v6; 97 struct sockaddr_in6 v6;
87 98
88 if (args[0] == NULL) 99 (void) cls;
100 (void) cfgfile;
101 (void) cfg;
102 if (NULL == args[0])
89 return; 103 return;
90 if (! reverse) 104 if (! reverse)
91 { 105 {
92 GNUNET_RESOLVER_ip_get (args[0], AF_UNSPEC, GET_TIMEOUT, &print_sockaddr, NULL); 106 GNUNET_RESOLVER_ip_get (args[0],
107 AF_UNSPEC,
108 GET_TIMEOUT,
109 &print_sockaddr,
110 NULL);
93 return; 111 return;
94 } 112 }
95 113
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c
index d26bdd212..ccb592349 100644
--- a/src/util/gnunet-service-resolver.c
+++ b/src/util/gnunet-service-resolver.c
@@ -582,7 +582,7 @@ get_ip_from_hostname (struct GNUNET_SERVICE_Client *client,
582/** 582/**
583 * Verify well-formedness of GET-message. 583 * Verify well-formedness of GET-message.
584 * 584 *
585 * @param cls closure 585 * @param cls closure, unused
586 * @param get the actual message 586 * @param get the actual message
587 * @return #GNUNET_OK if @a get is well-formed 587 * @return #GNUNET_OK if @a get is well-formed
588 */ 588 */
@@ -594,6 +594,7 @@ check_get (void *cls,
594 int direction; 594 int direction;
595 int af; 595 int af;
596 596
597 (void) cls;
597 size = ntohs (get->header.size) - sizeof (*get); 598 size = ntohs (get->header.size) - sizeof (*get);
598 direction = ntohl (get->direction); 599 direction = ntohl (get->direction);
599 if (GNUNET_NO == direction) 600 if (GNUNET_NO == direction)
@@ -688,7 +689,7 @@ handle_get (void *cls,
688/** 689/**
689 * Callback called when a client connects to the service. 690 * Callback called when a client connects to the service.
690 * 691 *
691 * @param cls closure for the service 692 * @param cls closure for the service, unused
692 * @param c the new client that connected to the service 693 * @param c the new client that connected to the service
693 * @param mq the message queue used to send messages to the client 694 * @param mq the message queue used to send messages to the client
694 * @return @a c 695 * @return @a c
@@ -698,6 +699,9 @@ connect_cb (void *cls,
698 struct GNUNET_SERVICE_Client *c, 699 struct GNUNET_SERVICE_Client *c,
699 struct GNUNET_MQ_Handle *mq) 700 struct GNUNET_MQ_Handle *mq)
700{ 701{
702 (void) cls;
703 (void) mq;
704
701 return c; 705 return c;
702} 706}
703 707
@@ -714,6 +718,8 @@ disconnect_cb (void *cls,
714 struct GNUNET_SERVICE_Client *c, 718 struct GNUNET_SERVICE_Client *c,
715 void *internal_cls) 719 void *internal_cls)
716{ 720{
721 (void) cls;
722
717 GNUNET_assert (c == internal_cls); 723 GNUNET_assert (c == internal_cls);
718} 724}
719 725
diff --git a/src/util/mq.c b/src/util/mq.c
index 90b2aa968..8d71359ac 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -357,6 +357,12 @@ GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq,
357 } 357 }
358 GNUNET_assert (NULL == mq->envelope_head); 358 GNUNET_assert (NULL == mq->envelope_head);
359 mq->current_envelope = ev; 359 mq->current_envelope = ev;
360
361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
362 "mq: sending message of type %u, queue empty (MQ: %p)\n",
363 ntohs(ev->mh->type),
364 mq);
365
360 mq->send_impl (mq, 366 mq->send_impl (mq,
361 ev->mh, 367 ev->mh,
362 mq->impl_state); 368 mq->impl_state);
@@ -452,6 +458,11 @@ impl_send_continue (void *cls)
452 GNUNET_CONTAINER_DLL_remove (mq->envelope_head, 458 GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
453 mq->envelope_tail, 459 mq->envelope_tail,
454 mq->current_envelope); 460 mq->current_envelope);
461
462 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
463 "mq: sending message of type %u from queue\n",
464 ntohs(mq->current_envelope->mh->type));
465
455 mq->send_impl (mq, 466 mq->send_impl (mq,
456 mq->current_envelope->mh, 467 mq->current_envelope->mh,
457 mq->impl_state); 468 mq->impl_state);
@@ -840,6 +851,9 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq)
840 ev); 851 ev);
841 GNUNET_assert (0 < mq->queue_length); 852 GNUNET_assert (0 < mq->queue_length);
842 mq->queue_length--; 853 mq->queue_length--;
854 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
855 "MQ destroy drops message of type %u\n",
856 ntohs (ev->mh->type));
843 GNUNET_MQ_discard (ev); 857 GNUNET_MQ_discard (ev);
844 } 858 }
845 if (NULL != mq->current_envelope) 859 if (NULL != mq->current_envelope)
@@ -847,6 +861,9 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq)
847 /* we can only discard envelopes that 861 /* we can only discard envelopes that
848 * are not queued! */ 862 * are not queued! */
849 mq->current_envelope->parent_queue = NULL; 863 mq->current_envelope->parent_queue = NULL;
864 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
865 "MQ destroy drops current message of type %u\n",
866 ntohs (mq->current_envelope->mh->type));
850 GNUNET_MQ_discard (mq->current_envelope); 867 GNUNET_MQ_discard (mq->current_envelope);
851 mq->current_envelope = NULL; 868 mq->current_envelope = NULL;
852 GNUNET_assert (0 < mq->queue_length); 869 GNUNET_assert (0 < mq->queue_length);
@@ -928,6 +945,11 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev)
928 GNUNET_CONTAINER_DLL_remove (mq->envelope_head, 945 GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
929 mq->envelope_tail, 946 mq->envelope_tail,
930 mq->current_envelope); 947 mq->current_envelope);
948
949 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
950 "mq: sending canceled message of type %u queue\n",
951 ntohs(ev->mh->type));
952
931 mq->send_impl (mq, 953 mq->send_impl (mq,
932 mq->current_envelope->mh, 954 mq->current_envelope->mh,
933 mq->impl_state); 955 mq->impl_state);
diff --git a/src/util/mst.c b/src/util/mst.c
index 0d90c5d10..5e472965f 100644
--- a/src/util/mst.c
+++ b/src/util/mst.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2010, 2016 GNUnet e.V. 3 Copyright (C) 2010, 2016, 2017 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -126,6 +126,7 @@ GNUNET_MST_from_buffer (struct GNUNET_MessageStreamTokenizer *mst,
126 int need_align; 126 int need_align;
127 unsigned long offset; 127 unsigned long offset;
128 int ret; 128 int ret;
129 int cbret;
129 130
130 GNUNET_assert (mst->off <= mst->pos); 131 GNUNET_assert (mst->off <= mst->pos);
131 GNUNET_assert (mst->pos <= mst->curr_buf); 132 GNUNET_assert (mst->pos <= mst->curr_buf);
@@ -229,9 +230,17 @@ do_align:
229 if (one_shot == GNUNET_YES) 230 if (one_shot == GNUNET_YES)
230 one_shot = GNUNET_SYSERR; 231 one_shot = GNUNET_SYSERR;
231 mst->off += want; 232 mst->off += want;
232 if (GNUNET_SYSERR == mst->cb (mst->cb_cls, 233 if (GNUNET_OK !=
233 hdr)) 234 (cbret = mst->cb (mst->cb_cls,
235 hdr)))
236 {
237 if (GNUNET_SYSERR == cbret)
238 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
239 "Failure processing message of type %u and size %u\n",
240 ntohs (hdr->type),
241 ntohs (hdr->size));
234 return GNUNET_SYSERR; 242 return GNUNET_SYSERR;
243 }
235 if (mst->off == mst->pos) 244 if (mst->off == mst->pos)
236 { 245 {
237 /* reset to beginning of buffer, it's free right now! */ 246 /* reset to beginning of buffer, it's free right now! */
@@ -271,9 +280,17 @@ do_align:
271 } 280 }
272 if (one_shot == GNUNET_YES) 281 if (one_shot == GNUNET_YES)
273 one_shot = GNUNET_SYSERR; 282 one_shot = GNUNET_SYSERR;
274 if (GNUNET_SYSERR == mst->cb (mst->cb_cls, 283 if (GNUNET_OK !=
275 hdr)) 284 (cbret = mst->cb (mst->cb_cls,
285 hdr)))
286 {
287 if (GNUNET_SYSERR == cbret)
288 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
289 "Failure processing message of type %u and size %u\n",
290 ntohs (hdr->type),
291 ntohs (hdr->size));
276 return GNUNET_SYSERR; 292 return GNUNET_SYSERR;
293 }
277 buf += want; 294 buf += want;
278 size -= want; 295 size -= want;
279 } 296 }
diff --git a/src/util/network.c b/src/util/network.c
index 942288613..0cb1529a6 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -91,8 +91,8 @@ GNUNET_NETWORK_test_pf (int pf)
91 if (EAFNOSUPPORT == errno) 91 if (EAFNOSUPPORT == errno)
92 return GNUNET_NO; 92 return GNUNET_NO;
93 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 93 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
94 "Failed to create test socket: %s\n", 94 "Failed to create test socket: %s\n",
95 STRERROR (errno)); 95 STRERROR (errno));
96 return GNUNET_SYSERR; 96 return GNUNET_SYSERR;
97 } 97 }
98#if WINDOWS 98#if WINDOWS
@@ -128,21 +128,20 @@ GNUNET_NETWORK_shorten_unixpath (char *unixpath)
128 if (slen < upm) 128 if (slen < upm)
129 return unixpath; /* no shortening required */ 129 return unixpath; /* no shortening required */
130 GNUNET_CRYPTO_hash (unixpath, slen, &sh); 130 GNUNET_CRYPTO_hash (unixpath, slen, &sh);
131 while (16 + 131 while (16 + strlen (unixpath) >= upm)
132 strlen (unixpath) >= upm)
133 { 132 {
134 if (NULL == (end = strrchr (unixpath, '/'))) 133 if (NULL == (end = strrchr (unixpath, '/')))
135 { 134 {
136 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 135 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
137 _("Unable to shorten unix path `%s' while keeping name unique\n"), 136 _("Unable to shorten unix path `%s' while keeping name unique\n"),
138 unixpath); 137 unixpath);
139 GNUNET_free (unixpath); 138 GNUNET_free (unixpath);
140 return NULL; 139 return NULL;
141 } 140 }
142 *end = '\0'; 141 *end = '\0';
143 } 142 }
144 GNUNET_CRYPTO_hash_to_enc (&sh, &ae); 143 GNUNET_CRYPTO_hash_to_enc (&sh, &ae);
145 strncat (unixpath, (char*) ae.encoding, 16); 144 strncat (unixpath, (char *) ae.encoding, 16);
146 return unixpath; 145 return unixpath;
147} 146}
148 147
@@ -239,7 +238,6 @@ GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd,
239 int flags = fcntl (fd->fd, F_GETFL); 238 int flags = fcntl (fd->fd, F_GETFL);
240 239
241 if (flags == -1) 240 if (flags == -1)
242
243 { 241 {
244 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, 242 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
245 "fcntl"); 243 "fcntl");
@@ -311,7 +309,7 @@ socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle *h)
311 309
312 if (0 != 310 if (0 !=
313 setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, 311 setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE,
314 (const void *) &abs_value, 312 (const void *) &abs_value,
315 sizeof (abs_value))) 313 sizeof (abs_value)))
316 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); 314 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
317} 315}
@@ -342,8 +340,10 @@ socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h)
342 const char *abs_value = "1"; 340 const char *abs_value = "1";
343 341
344 if (0 != 342 if (0 !=
345 setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, 343 setsockopt (h->fd,
346 (const void *) abs_value, 344 IPPROTO_TCP,
345 TCP_NODELAY,
346 (const void *) abs_value,
347 sizeof (abs_value))) 347 sizeof (abs_value)))
348 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, 348 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
349 "setsockopt"); 349 "setsockopt");
@@ -365,7 +365,7 @@ socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h)
365 */ 365 */
366static int 366static int
367initialize_network_handle (struct GNUNET_NETWORK_Handle *h, 367initialize_network_handle (struct GNUNET_NETWORK_Handle *h,
368 int af, 368 int af,
369 int type) 369 int type)
370{ 370{
371 int eno; 371 int eno;
@@ -409,7 +409,7 @@ initialize_network_handle (struct GNUNET_NETWORK_Handle *h,
409#ifdef AF_UNIX 409#ifdef AF_UNIX
410 && (af != AF_UNIX) 410 && (af != AF_UNIX)
411#endif 411#endif
412 ) 412 )
413 socket_set_nodelay (h); 413 socket_set_nodelay (h);
414 return GNUNET_OK; 414 return GNUNET_OK;
415} 415}
@@ -426,7 +426,7 @@ initialize_network_handle (struct GNUNET_NETWORK_Handle *h,
426struct GNUNET_NETWORK_Handle * 426struct GNUNET_NETWORK_Handle *
427GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, 427GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
428 struct sockaddr *address, 428 struct sockaddr *address,
429 socklen_t *address_len) 429 socklen_t *address_len)
430{ 430{
431 struct GNUNET_NETWORK_Handle *ret; 431 struct GNUNET_NETWORK_Handle *ret;
432 int eno; 432 int eno;
@@ -443,7 +443,7 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
443 443
444 if (0 == gsn) 444 if (0 == gsn)
445 LOG (GNUNET_ERROR_TYPE_DEBUG, 445 LOG (GNUNET_ERROR_TYPE_DEBUG,
446 "Accepting connection on `%s'\n", 446 "Accepting connection on `%s'\n",
447 GNUNET_a2s ((const struct sockaddr *) &name, 447 GNUNET_a2s ((const struct sockaddr *) &name,
448 namelen)); 448 namelen));
449 } 449 }
@@ -491,9 +491,11 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
491 const int on = 1; 491 const int on = 1;
492 492
493 if (AF_INET6 == desc->af) 493 if (AF_INET6 == desc->af)
494 if (setsockopt (desc->fd, IPPROTO_IPV6, IPV6_V6ONLY, 494 if (setsockopt (desc->fd,
495 (const void *) &on, 495 IPPROTO_IPV6,
496 sizeof (on))) 496 IPV6_V6ONLY,
497 (const void *) &on,
498 sizeof (on)))
497 LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, 499 LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG,
498 "setsockopt"); 500 "setsockopt");
499 } 501 }
@@ -593,8 +595,8 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc)
593 if (0 != unlink (dirname)) 595 if (0 != unlink (dirname))
594 { 596 {
595 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 597 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
596 "unlink", 598 "unlink",
597 dirname); 599 dirname);
598 } 600 }
599 else 601 else
600 { 602 {
@@ -1209,8 +1211,8 @@ GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to,
1209 to->handles_size, 1211 to->handles_size,
1210 from->handles_pos * 2); 1212 from->handles_pos * 2);
1211 GNUNET_memcpy (to->handles, 1213 GNUNET_memcpy (to->handles,
1212 from->handles, 1214 from->handles,
1213 from->handles_pos * sizeof (struct GNUNET_NETWORK_Handle *)); 1215 from->handles_pos * sizeof (struct GNUNET_NETWORK_Handle *));
1214 to->handles_pos = from->handles_pos; 1216 to->handles_pos = from->handles_pos;
1215#endif 1217#endif
1216} 1218}
@@ -1223,7 +1225,7 @@ GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to,
1223 * @return POSIX file descriptor 1225 * @return POSIX file descriptor
1224 */ 1226 */
1225int 1227int
1226GNUNET_NETWORK_get_fd (struct GNUNET_NETWORK_Handle *desc) 1228GNUNET_NETWORK_get_fd (const struct GNUNET_NETWORK_Handle *desc)
1227{ 1229{
1228 return desc->fd; 1230 return desc->fd;
1229} 1231}
@@ -1236,7 +1238,7 @@ GNUNET_NETWORK_get_fd (struct GNUNET_NETWORK_Handle *desc)
1236 * @return sockaddr 1238 * @return sockaddr
1237 */ 1239 */
1238struct sockaddr* 1240struct sockaddr*
1239GNUNET_NETWORK_get_addr (struct GNUNET_NETWORK_Handle *desc) 1241GNUNET_NETWORK_get_addr (const struct GNUNET_NETWORK_Handle *desc)
1240{ 1242{
1241 return desc->addr; 1243 return desc->addr;
1242} 1244}
@@ -1249,7 +1251,7 @@ GNUNET_NETWORK_get_addr (struct GNUNET_NETWORK_Handle *desc)
1249 * @return socklen_t for sockaddr 1251 * @return socklen_t for sockaddr
1250 */ 1252 */
1251socklen_t 1253socklen_t
1252GNUNET_NETWORK_get_addrlen (struct GNUNET_NETWORK_Handle *desc) 1254GNUNET_NETWORK_get_addrlen (const struct GNUNET_NETWORK_Handle *desc)
1253{ 1255{
1254 return desc->addrlen; 1256 return desc->addrlen;
1255} 1257}
@@ -1326,9 +1328,10 @@ GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
1326#else 1328#else
1327 int fd; 1329 int fd;
1328 1330
1329 GNUNET_DISK_internal_file_handle_ (h, 1331 GNUNET_assert (GNUNET_OK ==
1330 &fd, 1332 GNUNET_DISK_internal_file_handle_ (h,
1331 sizeof (int)); 1333 &fd,
1334 sizeof (int)));
1332 FD_SET (fd, 1335 FD_SET (fd,
1333 &fds->sds); 1336 &fds->sds);
1334 fds->nsds = GNUNET_MAX (fd + 1, 1337 fds->nsds = GNUNET_MAX (fd + 1,
@@ -1706,7 +1709,7 @@ initialize_select_thread ()
1706 */ 1709 */
1707int 1710int
1708GNUNET_NETWORK_test_port_free (int ipproto, 1711GNUNET_NETWORK_test_port_free (int ipproto,
1709 uint16_t port) 1712 uint16_t port)
1710{ 1713{
1711 struct GNUNET_NETWORK_Handle *socket; 1714 struct GNUNET_NETWORK_Handle *socket;
1712 int bind_status; 1715 int bind_status;
@@ -1717,36 +1720,35 @@ GNUNET_NETWORK_test_port_free (int ipproto,
1717 struct addrinfo *ai; 1720 struct addrinfo *ai;
1718 1721
1719 GNUNET_snprintf (open_port_str, 1722 GNUNET_snprintf (open_port_str,
1720 sizeof (open_port_str), 1723 sizeof (open_port_str),
1721 "%u", 1724 "%u",
1722 (unsigned int) port); 1725 (unsigned int) port);
1723 socktype = (IPPROTO_TCP == ipproto) 1726 socktype = (IPPROTO_TCP == ipproto) ? SOCK_STREAM : SOCK_DGRAM;
1724 ? SOCK_STREAM
1725 : SOCK_DGRAM;
1726 ret = NULL; 1727 ret = NULL;
1727 memset (&hint, 0, sizeof (hint)); 1728 memset (&hint, 0, sizeof (hint));
1728 hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */ 1729 hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */
1729 hint.ai_socktype = socktype; 1730 hint.ai_socktype = socktype;
1730 hint.ai_protocol = ipproto; 1731 hint.ai_protocol = ipproto;
1731 hint.ai_addrlen = 0; 1732 hint.ai_addrlen = 0;
1732 hint.ai_addr = NULL; 1733 hint.ai_addr = NULL;
1733 hint.ai_canonname = NULL; 1734 hint.ai_canonname = NULL;
1734 hint.ai_next = NULL; 1735 hint.ai_next = NULL;
1735 hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */ 1736 hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */
1736 GNUNET_assert (0 == getaddrinfo (NULL, 1737 GNUNET_assert (0 == getaddrinfo (NULL,
1737 open_port_str, 1738 open_port_str,
1738 &hint, 1739 &hint,
1739 &ret)); 1740 &ret));
1741 bind_status = GNUNET_NO;
1740 for (ai = ret; NULL != ai; ai = ai->ai_next) 1742 for (ai = ret; NULL != ai; ai = ai->ai_next)
1741 { 1743 {
1742 socket = GNUNET_NETWORK_socket_create (ai->ai_family, 1744 socket = GNUNET_NETWORK_socket_create (ai->ai_family,
1743 ai->ai_socktype, 1745 ai->ai_socktype,
1744 ai->ai_protocol); 1746 ai->ai_protocol);
1745 if (NULL == socket) 1747 if (NULL == socket)
1746 continue; 1748 continue;
1747 bind_status = GNUNET_NETWORK_socket_bind (socket, 1749 bind_status = GNUNET_NETWORK_socket_bind (socket,
1748 ai->ai_addr, 1750 ai->ai_addr,
1749 ai->ai_addrlen); 1751 ai->ai_addrlen);
1750 GNUNET_NETWORK_socket_close (socket); 1752 GNUNET_NETWORK_socket_close (socket);
1751 if (GNUNET_OK != bind_status) 1753 if (GNUNET_OK != bind_status)
1752 break; 1754 break;
@@ -1806,7 +1808,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1806 (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.rel_value_us)); 1808 (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.rel_value_us));
1807 } 1809 }
1808 return select (nfds, 1810 return select (nfds,
1809 (NULL != rfds) ? &rfds->sds : NULL, 1811 (NULL != rfds) ? &rfds->sds : NULL,
1810 (NULL != wfds) ? &wfds->sds : NULL, 1812 (NULL != wfds) ? &wfds->sds : NULL,
1811 (NULL != efds) ? &efds->sds : NULL, 1813 (NULL != efds) ? &efds->sds : NULL,
1812 (timeout.rel_value_us == 1814 (timeout.rel_value_us ==
@@ -2176,7 +2178,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
2176 { 2178 {
2177 LOG (GNUNET_ERROR_TYPE_DEBUG, 2179 LOG (GNUNET_ERROR_TYPE_DEBUG,
2178 "Adding the socket event to the array as %d\n", 2180 "Adding the socket event to the array as %d\n",
2179 nhandles); 2181 nhandles);
2180 handle_array[nhandles++] = select_finished_event; 2182 handle_array[nhandles++] = select_finished_event;
2181 if (timeout.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) 2183 if (timeout.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
2182 { 2184 {
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index 1226c5966..2e35de681 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2006-2016 GNUnet e.V. 3 Copyright (C) 2006-2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -152,14 +152,21 @@ get_path_from_proc_exe ()
152 ssize_t size; 152 ssize_t size;
153 char *lep; 153 char *lep;
154 154
155 GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/exe", getpid ()); 155 GNUNET_snprintf (fn,
156 size = readlink (fn, lnk, sizeof (lnk) - 1); 156 sizeof (fn),
157 "/proc/%u/exe",
158 getpid ());
159 size = readlink (fn,
160 lnk,
161 sizeof (lnk) - 1);
157 if (size <= 0) 162 if (size <= 0)
158 { 163 {
159 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "readlink", fn); 164 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
165 "readlink",
166 fn);
160 return NULL; 167 return NULL;
161 } 168 }
162 GNUNET_assert (size < sizeof (lnk)); 169 GNUNET_assert ( ((size_t) size) < sizeof (lnk));
163 lnk[size] = '\0'; 170 lnk[size] = '\0';
164 while ((lnk[size] != '/') && (size > 0)) 171 while ((lnk[size] != '/') && (size > 0))
165 size--; 172 size--;
@@ -167,12 +174,13 @@ get_path_from_proc_exe ()
167 "/%s/libexec/", 174 "/%s/libexec/",
168 current_pd->project_dirname); 175 current_pd->project_dirname);
169 /* test for being in lib/gnunet/libexec/ or lib/MULTIARCH/gnunet/libexec */ 176 /* test for being in lib/gnunet/libexec/ or lib/MULTIARCH/gnunet/libexec */
170 if ( (size > strlen (lep)) && 177 if ( (((size_t) size) > strlen (lep)) &&
171 (0 == strcmp (lep, 178 (0 == strcmp (lep,
172 &lnk[size - strlen (lep)])) ) 179 &lnk[size - strlen (lep)])) )
173 size -= strlen (lep) - 1; 180 size -= strlen (lep) - 1;
174 GNUNET_free (lep); 181 GNUNET_free (lep);
175 if ((size < 4) || (lnk[size - 4] != '/')) 182 if ( (size < 4) ||
183 (lnk[size - 4] != '/') )
176 { 184 {
177 /* not installed in "/bin/" -- binary path probably useless */ 185 /* not installed in "/bin/" -- binary path probably useless */
178 return NULL; 186 return NULL;
@@ -903,6 +911,7 @@ GNUNET_OS_check_helper_binary (const char *binary,
903 if (check_suid) 911 if (check_suid)
904 { 912 {
905#ifndef MINGW 913#ifndef MINGW
914 (void) params;
906 if ( (0 != (statbuf.st_mode & S_ISUID)) && 915 if ( (0 != (statbuf.st_mode & S_ISUID)) &&
907 (0 == statbuf.st_uid) ) 916 (0 == statbuf.st_uid) )
908 { 917 {
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index 2c4f7ca09..98998b520 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -154,6 +154,7 @@ GNUNET_OS_install_parent_control_handler (void *cls)
154 struct GNUNET_DISK_FileHandle *control_pipe; 154 struct GNUNET_DISK_FileHandle *control_pipe;
155 uint64_t pipe_fd; 155 uint64_t pipe_fd;
156 156
157 (void) cls;
157 if (NULL != pch) 158 if (NULL != pch)
158 { 159 {
159 /* already done, we've been called twice... */ 160 /* already done, we've been called twice... */
diff --git a/src/util/peer.c b/src/util/peer.c
index b637dc229..b1c65fbcf 100644
--- a/src/util/peer.c
+++ b/src/util/peer.c
@@ -201,7 +201,8 @@ GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta)
201 return; 201 return;
202 GNUNET_assert (id < size); 202 GNUNET_assert (id < size);
203 GNUNET_assert (table[id]->rc > 0); 203 GNUNET_assert (table[id]->rc > 0);
204 GNUNET_assert ((delta >= 0) || (table[id]->rc >= -delta)); 204 GNUNET_assert ( (delta >= 0) ||
205 (table[id]->rc >= (unsigned int) (-delta)) );
205 table[id]->rc += delta; 206 table[id]->rc += delta;
206 if (0 == table[id]->rc) 207 if (0 == table[id]->rc)
207 { 208 {
diff --git a/src/util/program.c b/src/util/program.c
index 92a9750f3..9e3037b8b 100644
--- a/src/util/program.c
+++ b/src/util/program.c
@@ -69,6 +69,17 @@ struct CommandContext
69 69
70 70
71/** 71/**
72 * task run when the scheduler shuts down
73 */
74static void
75shutdown_task (void *cls)
76{
77 (void) cls;
78 GNUNET_SPEEDUP_stop_ ();
79}
80
81
82/**
72 * Initial task called by the scheduler for each 83 * Initial task called by the scheduler for each
73 * program. Runs the program-specific main task. 84 * program. Runs the program-specific main task.
74 */ 85 */
@@ -78,6 +89,7 @@ program_main (void *cls)
78 struct CommandContext *cc = cls; 89 struct CommandContext *cc = cls;
79 90
80 GNUNET_SPEEDUP_start_(cc->cfg); 91 GNUNET_SPEEDUP_start_(cc->cfg);
92 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
81 GNUNET_RESOLVER_connect (cc->cfg); 93 GNUNET_RESOLVER_connect (cc->cfg);
82 cc->task (cc->task_cls, cc->args, cc->cfgfile, cc->cfg); 94 cc->task (cc->task_cls, cc->args, cc->cfgfile, cc->cfg);
83} 95}
@@ -306,7 +318,6 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
306 } 318 }
307 ret = GNUNET_OK; 319 ret = GNUNET_OK;
308 cleanup: 320 cleanup:
309 GNUNET_SPEEDUP_stop_ ();
310 GNUNET_CONFIGURATION_destroy (cfg); 321 GNUNET_CONFIGURATION_destroy (cfg);
311 GNUNET_free_non_null (cc.cfgfile); 322 GNUNET_free_non_null (cc.cfgfile);
312 GNUNET_free (cfg_fn); 323 GNUNET_free (cfg_fn);
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c
index 11b8134d6..bd46b4fbb 100644
--- a/src/util/resolver_api.c
+++ b/src/util/resolver_api.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009-2016 GNUnet e.V. 3 Copyright (C) 2009-2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -214,7 +214,8 @@ check_config ()
214 for (unsigned int i = 0; 214 for (unsigned int i = 0;
215 NULL != loopback[i]; 215 NULL != loopback[i];
216 i++) 216 i++)
217 if (0 == strcasecmp (loopback[i], hostname)) 217 if (0 == strcasecmp (loopback[i],
218 hostname))
218 { 219 {
219 GNUNET_free (hostname); 220 GNUNET_free (hostname);
220 return GNUNET_OK; 221 return GNUNET_OK;
@@ -285,6 +286,7 @@ GNUNET_RESOLVER_disconnect ()
285static void 286static void
286shutdown_task (void *cls) 287shutdown_task (void *cls)
287{ 288{
289 (void) cls;
288 s_task = NULL; 290 s_task = NULL;
289 GNUNET_RESOLVER_disconnect (); 291 GNUNET_RESOLVER_disconnect ();
290 backoff = GNUNET_TIME_UNIT_MILLISECONDS; 292 backoff = GNUNET_TIME_UNIT_MILLISECONDS;
@@ -387,10 +389,12 @@ static void
387mq_error_handler (void *cls, 389mq_error_handler (void *cls,
388 enum GNUNET_MQ_Error error) 390 enum GNUNET_MQ_Error error)
389{ 391{
392 (void) cls;
390 GNUNET_MQ_destroy (mq); 393 GNUNET_MQ_destroy (mq);
391 mq = NULL; 394 mq = NULL;
392 LOG (GNUNET_ERROR_TYPE_DEBUG, 395 LOG (GNUNET_ERROR_TYPE_DEBUG,
393 "MQ error, reconnecting\n"); 396 "MQ error %d, reconnecting\n",
397 error);
394 reconnect (); 398 reconnect ();
395} 399}
396 400
@@ -414,10 +418,11 @@ process_requests ()
414 { 418 {
415 /* nothing to do, release socket really soon if there is nothing 419 /* nothing to do, release socket really soon if there is nothing
416 * else happening... */ 420 * else happening... */
417 s_task = 421 if (NULL == s_task)
418 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, 422 s_task =
419 &shutdown_task, 423 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
420 NULL); 424 &shutdown_task,
425 NULL);
421 return; 426 return;
422 } 427 }
423 if (GNUNET_NO != rh->was_transmitted) 428 if (GNUNET_NO != rh->was_transmitted)
@@ -448,6 +453,9 @@ static int
448check_response (void *cls, 453check_response (void *cls,
449 const struct GNUNET_MessageHeader *msg) 454 const struct GNUNET_MessageHeader *msg)
450{ 455{
456 (void) cls;
457 (void) msg;
458
451 /* implemented in #handle_response() for now */ 459 /* implemented in #handle_response() for now */
452 return GNUNET_OK; 460 return GNUNET_OK;
453} 461}
@@ -469,6 +477,7 @@ handle_response (void *cls,
469 uint16_t size; 477 uint16_t size;
470 char *nret; 478 char *nret;
471 479
480 (void) cls;
472 GNUNET_assert (NULL != rh); 481 GNUNET_assert (NULL != rh);
473 size = ntohs (msg->size); 482 size = ntohs (msg->size);
474 if (size == sizeof (struct GNUNET_MessageHeader)) 483 if (size == sizeof (struct GNUNET_MessageHeader))
@@ -742,6 +751,7 @@ reconnect_task (void *cls)
742 GNUNET_MQ_handler_end () 751 GNUNET_MQ_handler_end ()
743 }; 752 };
744 753
754 (void) cls;
745 r_task = NULL; 755 r_task = NULL;
746 if (NULL == req_head) 756 if (NULL == req_head)
747 return; /* no work pending */ 757 return; /* no work pending */
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index 540a60557..9d37231e7 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -89,12 +89,6 @@ struct GNUNET_SCHEDULER_Handle
89 * @deprecated 89 * @deprecated
90 */ 90 */
91 struct GNUNET_NETWORK_FDSet *ws; 91 struct GNUNET_NETWORK_FDSet *ws;
92
93 /**
94 * Driver we used for the event loop.
95 */
96 const struct GNUNET_SCHEDULER_Driver *driver;
97
98}; 92};
99 93
100 94
@@ -124,36 +118,40 @@ struct GNUNET_SCHEDULER_Task
124 void *callback_cls; 118 void *callback_cls;
125 119
126 /** 120 /**
127 * Handle to the scheduler's state. 121 * Information about which FDs are ready for this task (and why).
128 */ 122 */
129 const struct GNUNET_SCHEDULER_Handle *sh; 123 struct GNUNET_SCHEDULER_FdInfo *fds;
130 124
131 /** 125 /**
132 * Set of file descriptors this task is waiting 126 * Storage location used for @e fds if we want to avoid
133 * for for reading. Once ready, this is updated 127 * a separate malloc() call in the common case that this
134 * to reflect the set of file descriptors ready 128 * task is only about a single FD.
135 * for operation.
136 */ 129 */
137 struct GNUNET_NETWORK_FDSet *read_set; 130 struct GNUNET_SCHEDULER_FdInfo fdx;
138 131
139 /** 132 /**
140 * Set of file descriptors this task is waiting for for writing. 133 * Size of the @e fds array.
141 * Once ready, this is updated to reflect the set of file
142 * descriptors ready for operation.
143 */ 134 */
144 struct GNUNET_NETWORK_FDSet *write_set; 135 unsigned int fds_len;
145 136
146 /** 137 /**
147 * Information about which FDs are ready for this task (and why). 138 * if this task is related to multiple FDs this array contains
139 * all FdInfo structs that were marked as ready by calling
140 * #GNUNET_SCHEDULER_task_ready
148 */ 141 */
149 const struct GNUNET_SCHEDULER_FdInfo *fds; 142 struct GNUNET_SCHEDULER_FdInfo *ready_fds;
150 143
151 /** 144 /**
152 * Storage location used for @e fds if we want to avoid 145 * Size of the @e ready_fds array
153 * a separate malloc() call in the common case that this
154 * task is only about a single FD.
155 */ 146 */
156 struct GNUNET_SCHEDULER_FdInfo fdx; 147 unsigned int ready_fds_len;
148
149 /**
150 * Do we own the network and file handles referenced by the FdInfo
151 * structs in the fds array. This will only be GNUNET_YES if the
152 * task was created by the #GNUNET_SCHEDULER_add_select function.
153 */
154 int own_handles;
157 155
158 /** 156 /**
159 * Absolute timeout value for the task, or 157 * Absolute timeout value for the task, or
@@ -169,11 +167,6 @@ struct GNUNET_SCHEDULER_Task
169#endif 167#endif
170 168
171 /** 169 /**
172 * Size of the @e fds array.
173 */
174 unsigned int fds_len;
175
176 /**
177 * Why is the task ready? Set after task is added to ready queue. 170 * Why is the task ready? Set after task is added to ready queue.
178 * Initially set to zero. All reasons that have already been 171 * Initially set to zero. All reasons that have already been
179 * satisfied (i.e. read or write ready) will be set over time. 172 * satisfied (i.e. read or write ready) will be set over time.
@@ -224,11 +217,72 @@ struct GNUNET_SCHEDULER_Task
224 int num_backtrace_strings; 217 int num_backtrace_strings;
225#endif 218#endif
226 219
220};
221
222
223/**
224 * A struct representing an event the select driver is waiting for
225 */
226struct Scheduled
227{
228 struct Scheduled *prev;
229
230 struct Scheduled *next;
231
232 /**
233 * the task, the event is related to
234 */
235 struct GNUNET_SCHEDULER_Task *task;
236
237 /**
238 * information about the network socket / file descriptor where
239 * the event is expected to occur
240 */
241 struct GNUNET_SCHEDULER_FdInfo *fdi;
242
243 /**
244 * the event types (multiple event types can be ORed) the select
245 * driver is expected to wait for
246 */
247 enum GNUNET_SCHEDULER_EventType et;
248};
249
250
251/**
252 * Driver context used by GNUNET_SCHEDULER_run
253 */
254struct DriverContext
255{
256 /**
257 * the head of a DLL containing information about the events the
258 * select driver is waiting for
259 */
260 struct Scheduled *scheduled_head;
227 261
262 /**
263 * the tail of a DLL containing information about the events the
264 * select driver is waiting for
265 */
266 struct Scheduled *scheduled_tail;
267
268 /**
269 * the time until the select driver will wake up again (after
270 * calling select)
271 */
272 struct GNUNET_TIME_Relative timeout;
228}; 273};
229 274
230 275
231/** 276/**
277 * The driver used for the event loop. Will be handed over to
278 * the scheduler in #GNUNET_SCHEDULER_run_from_driver(), peristed
279 * there in this variable for later use in functions like
280 * #GNUNET_SCHEDULER_add_select(), #add_without_sets() and
281 * #GNUNET_SCHEDULER_cancel().
282 */
283static const struct GNUNET_SCHEDULER_Driver *scheduler_driver;
284
285/**
232 * Head of list of tasks waiting for an event. 286 * Head of list of tasks waiting for an event.
233 */ 287 */
234static struct GNUNET_SCHEDULER_Task *pending_head; 288static struct GNUNET_SCHEDULER_Task *pending_head;
@@ -330,6 +384,11 @@ static struct GNUNET_SCHEDULER_TaskContext tc;
330 */ 384 */
331static void *scheduler_select_cls; 385static void *scheduler_select_cls;
332 386
387/**
388 * Scheduler handle used for the driver functions
389 */
390static struct GNUNET_SCHEDULER_Handle sh;
391
333 392
334/** 393/**
335 * Sets the select function to use in the scheduler (scheduler_select). 394 * Sets the select function to use in the scheduler (scheduler_select).
@@ -364,115 +423,44 @@ check_priority (enum GNUNET_SCHEDULER_Priority p)
364 423
365 424
366/** 425/**
367 * Update all sets and timeout for select. 426 * chooses the nearest timeout from all pending tasks, to be used
368 * 427 * to tell the driver the next wakeup time (using its set_wakeup
369 * @param rs read-set, set to all FDs we would like to read (updated) 428 * callback)
370 * @param ws write-set, set to all FDs we would like to write (updated)
371 * @param timeout next timeout (updated)
372 */ 429 */
373static void 430struct GNUNET_TIME_Absolute
374update_sets (struct GNUNET_NETWORK_FDSet *rs, 431get_timeout ()
375 struct GNUNET_NETWORK_FDSet *ws,
376 struct GNUNET_TIME_Relative *timeout)
377{ 432{
378 struct GNUNET_SCHEDULER_Task *pos; 433 struct GNUNET_SCHEDULER_Task *pos;
379 struct GNUNET_TIME_Absolute now; 434 struct GNUNET_TIME_Absolute now;
380 struct GNUNET_TIME_Relative to; 435 struct GNUNET_TIME_Absolute timeout;
381 436
382 now = GNUNET_TIME_absolute_get ();
383 pos = pending_timeout_head; 437 pos = pending_timeout_head;
438 now = GNUNET_TIME_absolute_get ();
439 timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
384 if (NULL != pos) 440 if (NULL != pos)
385 { 441 {
386 to = GNUNET_TIME_absolute_get_difference (now, pos->timeout);
387 if (timeout->rel_value_us > to.rel_value_us)
388 *timeout = to;
389 if (0 != pos->reason) 442 if (0 != pos->reason)
390 *timeout = GNUNET_TIME_UNIT_ZERO; 443 {
444 timeout = now;
445 }
446 else
447 {
448 timeout = pos->timeout;
449 }
391 } 450 }
392 for (pos = pending_head; NULL != pos; pos = pos->next) 451 for (pos = pending_head; NULL != pos; pos = pos->next)
393 { 452 {
394 if (pos->timeout.abs_value_us != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) 453 if (0 != pos->reason)
395 { 454 {
396 to = GNUNET_TIME_absolute_get_difference (now, pos->timeout); 455 timeout = now;
397 if (timeout->rel_value_us > to.rel_value_us) 456 }
398 *timeout = to; 457 else if ((pos->timeout.abs_value_us != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) &&
458 (timeout.abs_value_us > pos->timeout.abs_value_us))
459 {
460 timeout = pos->timeout;
399 } 461 }
400 if (-1 != pos->read_fd)
401 GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd);
402 if (-1 != pos->write_fd)
403 GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd);
404 if (NULL != pos->read_set)
405 GNUNET_NETWORK_fdset_add (rs, pos->read_set);
406 if (NULL != pos->write_set)
407 GNUNET_NETWORK_fdset_add (ws, pos->write_set);
408 if (0 != pos->reason)
409 *timeout = GNUNET_TIME_UNIT_ZERO;
410 }
411}
412
413
414/**
415 * Check if the ready set overlaps with the set we want to have ready.
416 * If so, update the want set (set all FDs that are ready). If not,
417 * return #GNUNET_NO.
418 *
419 * @param ready set that is ready
420 * @param want set that we want to be ready
421 * @return #GNUNET_YES if there was some overlap
422 */
423static int
424set_overlaps (const struct GNUNET_NETWORK_FDSet *ready,
425 struct GNUNET_NETWORK_FDSet *want)
426{
427 if ((NULL == want) || (NULL == ready))
428 return GNUNET_NO;
429 if (GNUNET_NETWORK_fdset_overlap (ready, want))
430 {
431 /* copy all over (yes, there maybe unrelated bits,
432 * but this should not hurt well-written clients) */
433 GNUNET_NETWORK_fdset_copy (want, ready);
434 return GNUNET_YES;
435 } 462 }
436 return GNUNET_NO; 463 return timeout;
437}
438
439
440/**
441 * Check if the given task is eligible to run now.
442 * Also set the reason why it is eligible.
443 *
444 * @param task task to check if it is ready
445 * @param now the current time
446 * @param rs set of FDs ready for reading
447 * @param ws set of FDs ready for writing
448 * @return #GNUNET_YES if we can run it, #GNUNET_NO if not.
449 */
450static int
451is_ready (struct GNUNET_SCHEDULER_Task *task,
452 struct GNUNET_TIME_Absolute now,
453 const struct GNUNET_NETWORK_FDSet *rs,
454 const struct GNUNET_NETWORK_FDSet *ws)
455{
456 enum GNUNET_SCHEDULER_Reason reason;
457
458 reason = task->reason;
459 if (now.abs_value_us >= task->timeout.abs_value_us)
460 reason |= GNUNET_SCHEDULER_REASON_TIMEOUT;
461 if ((0 == (reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
462 (((task->read_fd != -1) &&
463 (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (rs, task->read_fd))) ||
464 (set_overlaps (rs, task->read_set))))
465 reason |= GNUNET_SCHEDULER_REASON_READ_READY;
466 if ((0 == (reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) &&
467 (((task->write_fd != -1) &&
468 (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (ws, task->write_fd)))
469 || (set_overlaps (ws, task->write_set))))
470 reason |= GNUNET_SCHEDULER_REASON_WRITE_READY;
471 if (0 == reason)
472 return GNUNET_NO; /* not ready */
473 reason |= GNUNET_SCHEDULER_REASON_PREREQ_DONE;
474 task->reason = reason;
475 return GNUNET_YES;
476} 464}
477 465
478 466
@@ -495,51 +483,6 @@ queue_ready_task (struct GNUNET_SCHEDULER_Task *task)
495 483
496 484
497/** 485/**
498 * Check which tasks are ready and move them
499 * to the respective ready queue.
500 *
501 * @param rs FDs ready for reading
502 * @param ws FDs ready for writing
503 */
504static void
505check_ready (const struct GNUNET_NETWORK_FDSet *rs,
506 const struct GNUNET_NETWORK_FDSet *ws)
507{
508 struct GNUNET_SCHEDULER_Task *pos;
509 struct GNUNET_SCHEDULER_Task *next;
510 struct GNUNET_TIME_Absolute now;
511
512 now = GNUNET_TIME_absolute_get ();
513 while (NULL != (pos = pending_timeout_head))
514 {
515 if (now.abs_value_us >= pos->timeout.abs_value_us)
516 pos->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT;
517 if (0 == pos->reason)
518 break;
519 GNUNET_CONTAINER_DLL_remove (pending_timeout_head,
520 pending_timeout_tail,
521 pos);
522 if (pending_timeout_last == pos)
523 pending_timeout_last = NULL;
524 queue_ready_task (pos);
525 }
526 pos = pending_head;
527 while (NULL != pos)
528 {
529 next = pos->next;
530 if (GNUNET_YES == is_ready (pos, now, rs, ws))
531 {
532 GNUNET_CONTAINER_DLL_remove (pending_head,
533 pending_tail,
534 pos);
535 queue_ready_task (pos);
536 }
537 pos = next;
538 }
539}
540
541
542/**
543 * Request the shutdown of a scheduler. Marks all tasks 486 * Request the shutdown of a scheduler. Marks all tasks
544 * awaiting shutdown as ready. Note that tasks 487 * awaiting shutdown as ready. Note that tasks
545 * scheduled with #GNUNET_SCHEDULER_add_shutdown() AFTER this call 488 * scheduled with #GNUNET_SCHEDULER_add_shutdown() AFTER this call
@@ -562,25 +505,6 @@ GNUNET_SCHEDULER_shutdown ()
562 505
563 506
564/** 507/**
565 * Destroy a task (release associated resources)
566 *
567 * @param t task to destroy
568 */
569static void
570destroy_task (struct GNUNET_SCHEDULER_Task *t)
571{
572 if (NULL != t->read_set)
573 GNUNET_NETWORK_fdset_destroy (t->read_set);
574 if (NULL != t->write_set)
575 GNUNET_NETWORK_fdset_destroy (t->write_set);
576#if EXECINFO
577 GNUNET_free (t->backtrace_strings);
578#endif
579 GNUNET_free (t);
580}
581
582
583/**
584 * Output stack trace of task @a t. 508 * Output stack trace of task @a t.
585 * 509 *
586 * @param t task to dump stack trace of 510 * @param t task to dump stack trace of
@@ -589,91 +513,62 @@ static void
589dump_backtrace (struct GNUNET_SCHEDULER_Task *t) 513dump_backtrace (struct GNUNET_SCHEDULER_Task *t)
590{ 514{
591#if EXECINFO 515#if EXECINFO
592 unsigned int i; 516 for (unsigned int i = 0; i < t->num_backtrace_strings; i++)
593 517 LOG (GNUNET_ERROR_TYPE_WARNING,
594 for (i = 0; i < t->num_backtrace_strings; i++)
595 LOG (GNUNET_ERROR_TYPE_DEBUG,
596 "Task %p trace %u: %s\n", 518 "Task %p trace %u: %s\n",
597 t, 519 t,
598 i, 520 i,
599 t->backtrace_strings[i]); 521 t->backtrace_strings[i]);
522#else
523 (void) t;
600#endif 524#endif
601} 525}
602 526
603 527
604/** 528/**
605 * Run at least one task in the highest-priority queue that is not 529 * Destroy a task (release associated resources)
606 * empty. Keep running tasks until we are either no longer running
607 * "URGENT" tasks or until we have at least one "pending" task (which
608 * may become ready, hence we should select on it). Naturally, if
609 * there are no more ready tasks, we also return.
610 * 530 *
611 * @param rs FDs ready for reading 531 * @param t task to destroy
612 * @param ws FDs ready for writing
613 */ 532 */
614static void 533static void
615run_ready (struct GNUNET_NETWORK_FDSet *rs, 534destroy_task (struct GNUNET_SCHEDULER_Task *t)
616 struct GNUNET_NETWORK_FDSet *ws)
617{ 535{
618 enum GNUNET_SCHEDULER_Priority p; 536 unsigned int i;
619 struct GNUNET_SCHEDULER_Task *pos;
620 537
621 max_priority_added = GNUNET_SCHEDULER_PRIORITY_KEEP; 538 LOG (GNUNET_ERROR_TYPE_DEBUG,
622 do 539 "destroying task %p\n",
540 t);
541
542 if (GNUNET_YES == t->own_handles)
623 { 543 {
624 if (0 == ready_count) 544 for (i = 0; i != t->fds_len; ++i)
625 return;
626 GNUNET_assert (NULL == ready_head[GNUNET_SCHEDULER_PRIORITY_KEEP]);
627 /* yes, p>0 is correct, 0 is "KEEP" which should
628 * always be an empty queue (see assertion)! */
629 for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--)
630 {
631 pos = ready_head[p];
632 if (NULL != pos)
633 break;
634 }
635 GNUNET_assert (NULL != pos); /* ready_count wrong? */
636 GNUNET_CONTAINER_DLL_remove (ready_head[p],
637 ready_tail[p],
638 pos);
639 ready_count--;
640 current_priority = pos->priority;
641 current_lifeness = pos->lifeness;
642 active_task = pos;
643#if PROFILE_DELAYS
644 if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value_us >
645 DELAY_THRESHOLD.rel_value_us)
646 { 545 {
647 LOG (GNUNET_ERROR_TYPE_DEBUG, 546 const struct GNUNET_NETWORK_Handle *fd = t->fds[i].fd;
648 "Task %p took %s to be scheduled\n", 547 const struct GNUNET_DISK_FileHandle *fh = t->fds[i].fh;
649 pos, 548 if (fd)
650 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (pos->start_time), 549 {
651 GNUNET_YES)); 550 GNUNET_NETWORK_socket_free_memory_only_ ((struct GNUNET_NETWORK_Handle *) fd);
551 }
552 if (fh)
553 {
554 // FIXME: on WIN32 this is not enough! A function
555 // GNUNET_DISK_file_free_memory_only would be nice
556 GNUNET_free ((void *) fh);
557 }
652 } 558 }
653#endif
654 tc.reason = pos->reason;
655 tc.read_ready = (NULL == pos->read_set) ? rs : pos->read_set;
656 if ((-1 != pos->read_fd) &&
657 (0 != (pos->reason & GNUNET_SCHEDULER_REASON_READ_READY)))
658 GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd);
659 tc.write_ready = (NULL == pos->write_set) ? ws : pos->write_set;
660 if ((-1 != pos->write_fd) &&
661 (0 != (pos->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)))
662 GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd);
663 if ((0 != (tc.reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) &&
664 (-1 != pos->write_fd) &&
665 (!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd)))
666 GNUNET_assert (0); // added to ready in previous select loop!
667 LOG (GNUNET_ERROR_TYPE_DEBUG,
668 "Running task: %p\n",
669 pos);
670 pos->callback (pos->callback_cls);
671 dump_backtrace (pos);
672 active_task = NULL;
673 destroy_task (pos);
674 tasks_run++;
675 } 559 }
676 while ((NULL == pending_head) || (p >= max_priority_added)); 560 if (t->fds_len > 1)
561 {
562 GNUNET_array_grow (t->fds, t->fds_len, 0);
563 }
564 if (t->ready_fds_len > 0)
565 {
566 GNUNET_array_grow (t->ready_fds, t->ready_fds_len, 0);
567 }
568#if EXECINFO
569 GNUNET_free (t->backtrace_strings);
570#endif
571 GNUNET_free (t);
677} 572}
678 573
679 574
@@ -700,22 +595,22 @@ sighandler_pipe ()
700#endif 595#endif
701 596
702 597
703/** 598///**
704 * Wait for a short time. 599// * Wait for a short time.
705 * Sleeps for @a ms ms (as that should be long enough for virtually all 600// * Sleeps for @a ms ms (as that should be long enough for virtually all
706 * modern systems to context switch and allow another process to do 601// * modern systems to context switch and allow another process to do
707 * some 'real' work). 602// * some 'real' work).
708 * 603// *
709 * @param ms how many ms to wait 604// * @param ms how many ms to wait
710 */ 605// */
711static void 606//static void
712short_wait (unsigned int ms) 607//short_wait (unsigned int ms)
713{ 608//{
714 struct GNUNET_TIME_Relative timeout; 609// struct GNUNET_TIME_Relative timeout;
715 610//
716 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, ms); 611// timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, ms);
717 (void) GNUNET_NETWORK_socket_select (NULL, NULL, NULL, timeout); 612// (void) GNUNET_NETWORK_socket_select (NULL, NULL, NULL, timeout);
718} 613//}
719 614
720 615
721/** 616/**
@@ -737,35 +632,31 @@ sighandler_shutdown ()
737} 632}
738 633
739 634
740/** 635void
741 * Check if the system is still alive. Trigger shutdown if we 636shutdown_if_no_lifeness ()
742 * have tasks, but none of them give us lifeness.
743 *
744 * @return #GNUNET_OK to continue the main loop,
745 * #GNUNET_NO to exit
746 */
747static int
748check_lifeness ()
749{ 637{
750 struct GNUNET_SCHEDULER_Task *t; 638 struct GNUNET_SCHEDULER_Task *t;
751 639
752 if (ready_count > 0) 640 if (ready_count > 0)
753 return GNUNET_OK; 641 return;
754 for (t = pending_head; NULL != t; t = t->next) 642 for (t = pending_head; NULL != t; t = t->next)
755 if (t->lifeness == GNUNET_YES) 643 if (GNUNET_YES == t->lifeness)
756 return GNUNET_OK; 644 return;
757 for (t = shutdown_head; NULL != t; t = t->next) 645 for (t = shutdown_head; NULL != t; t = t->next)
758 if (t->lifeness == GNUNET_YES) 646 if (GNUNET_YES == t->lifeness)
759 return GNUNET_OK; 647 return;
760 for (t = pending_timeout_head; NULL != t; t = t->next) 648 for (t = pending_timeout_head; NULL != t; t = t->next)
761 if (t->lifeness == GNUNET_YES) 649 if (GNUNET_YES == t->lifeness)
762 return GNUNET_OK; 650 return;
763 if (NULL != shutdown_head) 651 /* No lifeness! Cancel all pending tasks the driver knows about and shutdown */
652 t = pending_head;
653 while (NULL != t)
764 { 654 {
765 GNUNET_SCHEDULER_shutdown (); 655 struct GNUNET_SCHEDULER_Task *next = t->next;
766 return GNUNET_OK; 656 GNUNET_SCHEDULER_cancel (t);
657 t = next;
767 } 658 }
768 return GNUNET_NO; 659 GNUNET_SCHEDULER_shutdown ();
769} 660}
770 661
771 662
@@ -787,204 +678,17 @@ void
787GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task, 678GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task,
788 void *task_cls) 679 void *task_cls)
789{ 680{
790 GNUNET_SCHEDULER_run_with_optional_signals(GNUNET_YES, task, task_cls); 681 struct GNUNET_SCHEDULER_Driver *driver;
791} 682 struct DriverContext context = {.scheduled_head = NULL,
792 683 .scheduled_tail = NULL,
793void 684 .timeout = GNUNET_TIME_UNIT_FOREVER_REL};
794GNUNET_SCHEDULER_run_with_optional_signals (int install_signals, 685
795 GNUNET_SCHEDULER_TaskCallback task, 686 driver = GNUNET_SCHEDULER_driver_select ();
796 void *task_cls) 687 driver->cls = &context;
797{ 688
798 struct GNUNET_NETWORK_FDSet *rs; 689 GNUNET_SCHEDULER_run_with_driver (driver, task, task_cls);
799 struct GNUNET_NETWORK_FDSet *ws; 690
800 struct GNUNET_TIME_Relative timeout; 691 GNUNET_free (driver);
801 int ret;
802 struct GNUNET_SIGNAL_Context *shc_int;
803 struct GNUNET_SIGNAL_Context *shc_term;
804#if (SIGTERM != GNUNET_TERM_SIG)
805 struct GNUNET_SIGNAL_Context *shc_gterm;
806#endif
807
808#ifndef MINGW
809 struct GNUNET_SIGNAL_Context *shc_quit;
810 struct GNUNET_SIGNAL_Context *shc_hup;
811 struct GNUNET_SIGNAL_Context *shc_pipe;
812#endif
813 unsigned long long last_tr;
814 unsigned int busy_wait_warning;
815 const struct GNUNET_DISK_FileHandle *pr;
816 char c;
817
818 GNUNET_assert (NULL == active_task);
819 rs = GNUNET_NETWORK_fdset_create ();
820 ws = GNUNET_NETWORK_fdset_create ();
821 GNUNET_assert (NULL == shutdown_pipe_handle);
822 shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO,
823 GNUNET_NO,
824 GNUNET_NO,
825 GNUNET_NO);
826 GNUNET_assert (NULL != shutdown_pipe_handle);
827 pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle,
828 GNUNET_DISK_PIPE_END_READ);
829 GNUNET_assert (NULL != pr);
830 my_pid = getpid ();
831
832 if (GNUNET_YES == install_signals)
833 {
834 LOG (GNUNET_ERROR_TYPE_DEBUG,
835 "Registering signal handlers\n");
836 shc_int = GNUNET_SIGNAL_handler_install (SIGINT,
837 &sighandler_shutdown);
838 shc_term = GNUNET_SIGNAL_handler_install (SIGTERM,
839 &sighandler_shutdown);
840#if (SIGTERM != GNUNET_TERM_SIG)
841 shc_gterm = GNUNET_SIGNAL_handler_install (GNUNET_TERM_SIG,
842 &sighandler_shutdown);
843#endif
844#ifndef MINGW
845 shc_pipe = GNUNET_SIGNAL_handler_install (SIGPIPE,
846 &sighandler_pipe);
847 shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT,
848 &sighandler_shutdown);
849 shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP,
850 &sighandler_shutdown);
851#endif
852 }
853
854 current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT;
855 current_lifeness = GNUNET_YES;
856 GNUNET_SCHEDULER_add_with_reason_and_priority (task,
857 task_cls,
858 GNUNET_SCHEDULER_REASON_STARTUP,
859 GNUNET_SCHEDULER_PRIORITY_DEFAULT);
860 active_task = (void *) (long) -1; /* force passing of sanity check */
861 GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO,
862 &GNUNET_OS_install_parent_control_handler,
863 NULL);
864 active_task = NULL;
865 last_tr = 0;
866 busy_wait_warning = 0;
867 while (GNUNET_OK == check_lifeness ())
868 {
869 GNUNET_NETWORK_fdset_zero (rs);
870 GNUNET_NETWORK_fdset_zero (ws);
871 timeout = GNUNET_TIME_UNIT_FOREVER_REL;
872 update_sets (rs, ws, &timeout);
873 GNUNET_NETWORK_fdset_handle_set (rs, pr);
874 if (ready_count > 0)
875 {
876 /* no blocking, more work already ready! */
877 timeout = GNUNET_TIME_UNIT_ZERO;
878 }
879 if (NULL == scheduler_select)
880 ret = GNUNET_NETWORK_socket_select (rs,
881 ws,
882 NULL,
883 timeout);
884 else
885 ret = scheduler_select (scheduler_select_cls,
886 rs,
887 ws,
888 NULL,
889 timeout);
890 if (ret == GNUNET_SYSERR)
891 {
892 if (errno == EINTR)
893 continue;
894
895 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "select");
896#ifndef MINGW
897#if USE_LSOF
898 char lsof[512];
899
900 snprintf (lsof, sizeof (lsof), "lsof -p %d", getpid ());
901 (void) close (1);
902 (void) dup2 (2, 1);
903 if (0 != system (lsof))
904 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
905 "system");
906#endif
907#endif
908#if DEBUG_FDS
909 struct GNUNET_SCHEDULER_Task *t;
910
911 for (t = pending_head; NULL != t; t = t->next)
912 {
913 if (-1 != t->read_fd)
914 {
915 int flags = fcntl (t->read_fd, F_GETFD);
916 if ((flags == -1) && (errno == EBADF))
917 {
918 LOG (GNUNET_ERROR_TYPE_ERROR,
919 "Got invalid file descriptor %d!\n",
920 t->read_fd);
921 dump_backtrace (t);
922 }
923 }
924 if (-1 != t->write_fd)
925 {
926 int flags = fcntl (t->write_fd, F_GETFD);
927 if ((flags == -1) && (errno == EBADF))
928 {
929 LOG (GNUNET_ERROR_TYPE_ERROR,
930 "Got invalid file descriptor %d!\n",
931 t->write_fd);
932 dump_backtrace (t);
933 }
934 }
935 }
936#endif
937 GNUNET_assert (0);
938 break;
939 }
940
941 if ( (0 == ret) &&
942 (0 == timeout.rel_value_us) &&
943 (busy_wait_warning > 16) )
944 {
945 LOG (GNUNET_ERROR_TYPE_WARNING,
946 "Looks like we're busy waiting...\n");
947 short_wait (100); /* mitigate */
948 }
949 check_ready (rs, ws);
950 run_ready (rs, ws);
951 if (GNUNET_NETWORK_fdset_handle_isset (rs, pr))
952 {
953 /* consume the signal */
954 GNUNET_DISK_file_read (pr, &c, sizeof (c));
955 /* mark all active tasks as ready due to shutdown */
956 GNUNET_SCHEDULER_shutdown ();
957 }
958 if (last_tr == tasks_run)
959 {
960 short_wait (1);
961 busy_wait_warning++;
962 }
963 else
964 {
965 last_tr = tasks_run;
966 busy_wait_warning = 0;
967 }
968 }
969
970 if (GNUNET_YES == install_signals)
971 {
972 GNUNET_SIGNAL_handler_uninstall (shc_int);
973 GNUNET_SIGNAL_handler_uninstall (shc_term);
974#if (SIGTERM != GNUNET_TERM_SIG)
975 GNUNET_SIGNAL_handler_uninstall (shc_gterm);
976#endif
977#ifndef MINGW
978 GNUNET_SIGNAL_handler_uninstall (shc_pipe);
979 GNUNET_SIGNAL_handler_uninstall (shc_quit);
980 GNUNET_SIGNAL_handler_uninstall (shc_hup);
981#endif
982 }
983
984 GNUNET_DISK_pipe_close (shutdown_pipe_handle);
985 shutdown_pipe_handle = NULL;
986 GNUNET_NETWORK_fdset_destroy (rs);
987 GNUNET_NETWORK_fdset_destroy (ws);
988} 692}
989 693
990 694
@@ -1029,9 +733,168 @@ GNUNET_SCHEDULER_get_load (enum GNUNET_SCHEDULER_Priority p)
1029} 733}
1030 734
1031 735
736void
737init_fd_info (struct GNUNET_SCHEDULER_Task *t,
738 const struct GNUNET_NETWORK_Handle *const *read_nh,
739 unsigned int read_nh_len,
740 const struct GNUNET_NETWORK_Handle *const *write_nh,
741 unsigned int write_nh_len,
742 const struct GNUNET_DISK_FileHandle *const *read_fh,
743 unsigned int read_fh_len,
744 const struct GNUNET_DISK_FileHandle *const *write_fh,
745 unsigned int write_fh_len)
746{
747 // FIXME: if we have exactly two network handles / exactly two file handles
748 // and they are equal, we can make one FdInfo with both
749 // GNUNET_SCHEDULER_ET_IN and GNUNET_SCHEDULER_ET_OUT set.
750 struct GNUNET_SCHEDULER_FdInfo *fdi;
751
752 t->fds_len = read_nh_len + write_nh_len + read_fh_len + write_fh_len;
753 if (1 == t->fds_len)
754 {
755 fdi = &t->fdx;
756 t->fds = fdi;
757 if (1 == read_nh_len)
758 {
759 GNUNET_assert (NULL != read_nh);
760 GNUNET_assert (NULL != *read_nh);
761 fdi->fd = *read_nh;
762 fdi->et = GNUNET_SCHEDULER_ET_IN;
763 fdi->sock = GNUNET_NETWORK_get_fd (*read_nh);
764 t->read_fd = fdi->sock;
765 t->write_fd = -1;
766 }
767 else if (1 == write_nh_len)
768 {
769 GNUNET_assert (NULL != write_nh);
770 GNUNET_assert (NULL != *write_nh);
771 fdi->fd = *write_nh;
772 fdi->et = GNUNET_SCHEDULER_ET_OUT;
773 fdi->sock = GNUNET_NETWORK_get_fd (*write_nh);
774 t->read_fd = -1;
775 t->write_fd = fdi->sock;
776 }
777 else if (1 == read_fh_len)
778 {
779 GNUNET_assert (NULL != read_fh);
780 GNUNET_assert (NULL != *read_fh);
781 fdi->fh = *read_fh;
782 fdi->et = GNUNET_SCHEDULER_ET_IN;
783 fdi->sock = (*read_fh)->fd; // FIXME: does not work under WIN32
784 t->read_fd = fdi->sock;
785 t->write_fd = -1;
786 }
787 else
788 {
789 GNUNET_assert (NULL != write_fh);
790 GNUNET_assert (NULL != *write_fh);
791 fdi->fh = *write_fh;
792 fdi->et = GNUNET_SCHEDULER_ET_OUT;
793 fdi->sock = (*write_fh)->fd; // FIXME: does not work under WIN32
794 t->read_fd = -1;
795 t->write_fd = fdi->sock;
796 }
797 }
798 else
799 {
800 fdi = GNUNET_new_array (t->fds_len, struct GNUNET_SCHEDULER_FdInfo);
801 t->fds = fdi;
802 t->read_fd = -1;
803 t->write_fd = -1;
804 unsigned int i;
805 for (i = 0; i != read_nh_len; ++i)
806 {
807 fdi->fd = read_nh[i];
808 GNUNET_assert (NULL != fdi->fd);
809 fdi->et = GNUNET_SCHEDULER_ET_IN;
810 fdi->sock = GNUNET_NETWORK_get_fd (read_nh[i]);
811 ++fdi;
812 }
813 for (i = 0; i != write_nh_len; ++i)
814 {
815 fdi->fd = write_nh[i];
816 GNUNET_assert (NULL != fdi->fd);
817 fdi->et = GNUNET_SCHEDULER_ET_OUT;
818 fdi->sock = GNUNET_NETWORK_get_fd (write_nh[i]);
819 ++fdi;
820 }
821 for (i = 0; i != read_fh_len; ++i)
822 {
823 fdi->fh = read_fh[i];
824 GNUNET_assert (NULL != fdi->fh);
825 fdi->et = GNUNET_SCHEDULER_ET_IN;
826 fdi->sock = (read_fh[i])->fd; // FIXME: does not work under WIN32
827 ++fdi;
828 }
829 for (i = 0; i != write_fh_len; ++i)
830 {
831 fdi->fh = write_fh[i];
832 GNUNET_assert (NULL != fdi->fh);
833 fdi->et = GNUNET_SCHEDULER_ET_OUT;
834 fdi->sock = (write_fh[i])->fd; // FIXME: does not work under WIN32
835 ++fdi;
836 }
837 }
838}
839
840
841/**
842 * calls the given function @a func on each FdInfo related to @a t.
843 * Optionally updates the event type field in each FdInfo after calling
844 * @a func.
845 *
846 * @param t the task
847 * @param driver_func the function to call with each FdInfo contained in
848 * in @a t
849 * @param if_not_ready only call @a driver_func on FdInfos that are not
850 * ready
851 * @param et the event type to be set in each FdInfo after calling
852 * @a driver_func on it, or -1 if no updating not desired.
853 */
854static void
855driver_add_multiple (struct GNUNET_SCHEDULER_Task *t)
856{
857 struct GNUNET_SCHEDULER_FdInfo *fdi;
858 int success = GNUNET_YES;
859
860 for (unsigned int i = 0; i != t->fds_len; ++i)
861 {
862 fdi = &t->fds[i];
863 success = scheduler_driver->add (scheduler_driver->cls,
864 t,
865 fdi) && success;
866 fdi->et = GNUNET_SCHEDULER_ET_NONE;
867 }
868 if (GNUNET_YES != success)
869 {
870 LOG (GNUNET_ERROR_TYPE_ERROR,
871 "driver could not add task\n");
872 }
873}
874
875
876static void
877shutdown_cb (void *cls)
878{
879 char c;
880 const struct GNUNET_DISK_FileHandle *pr;
881
882 (void) cls;
883 pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle,
884 GNUNET_DISK_PIPE_END_READ);
885 GNUNET_assert (! GNUNET_DISK_handle_invalid (pr));
886 /* consume the signal */
887 GNUNET_DISK_file_read (pr, &c, sizeof (c));
888 /* mark all active tasks as ready due to shutdown */
889 GNUNET_SCHEDULER_shutdown ();
890}
891
892
1032/** 893/**
1033 * Cancel the task with the specified identifier. 894 * Cancel the task with the specified identifier.
1034 * The task must not yet have run. 895 * The task must not yet have run. Only allowed to be called as long as the
896 * scheduler is running (#GNUNET_SCHEDULER_run or
897 * #GNUNET_SCHEDULER_run_with_driver has been called and has not returned yet).
1035 * 898 *
1036 * @param task id of the task to cancel 899 * @param task id of the task to cancel
1037 * @return original closure of the task 900 * @return original closure of the task
@@ -1040,34 +903,50 @@ void *
1040GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task) 903GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task)
1041{ 904{
1042 enum GNUNET_SCHEDULER_Priority p; 905 enum GNUNET_SCHEDULER_Priority p;
906 int is_fd_task;
1043 void *ret; 907 void *ret;
1044 908
909 LOG (GNUNET_ERROR_TYPE_DEBUG,
910 "canceling task %p\n",
911 task);
912
913 /* scheduler must be running */
914 GNUNET_assert (NULL != scheduler_driver);
1045 GNUNET_assert ( (NULL != active_task) || 915 GNUNET_assert ( (NULL != active_task) ||
1046 (GNUNET_NO == task->lifeness) ); 916 (GNUNET_NO == task->lifeness) );
1047 if (! task->in_ready_list) 917 is_fd_task = (NULL != task->fds);
918 if (is_fd_task)
1048 { 919 {
1049 if ( (-1 == task->read_fd) && 920 int del_result = scheduler_driver->del (scheduler_driver->cls, task);
1050 (-1 == task->write_fd) && 921 if (GNUNET_OK != del_result)
1051 (NULL == task->read_set) &&
1052 (NULL == task->write_set) )
1053 { 922 {
1054 if (GNUNET_YES == task->on_shutdown) 923 LOG (GNUNET_ERROR_TYPE_ERROR,
1055 GNUNET_CONTAINER_DLL_remove (shutdown_head, 924 "driver could not delete task\n");
1056 shutdown_tail, 925 GNUNET_assert (0);
1057 task);
1058 else
1059 GNUNET_CONTAINER_DLL_remove (pending_timeout_head,
1060 pending_timeout_tail,
1061 task);
1062 if (task == pending_timeout_last)
1063 pending_timeout_last = NULL;
1064 } 926 }
1065 else 927 }
928 if (! task->in_ready_list)
929 {
930 if (is_fd_task)
1066 { 931 {
1067 GNUNET_CONTAINER_DLL_remove (pending_head, 932 GNUNET_CONTAINER_DLL_remove (pending_head,
1068 pending_tail, 933 pending_tail,
1069 task); 934 task);
1070 } 935 }
936 else if (GNUNET_YES == task->on_shutdown)
937 {
938 GNUNET_CONTAINER_DLL_remove (shutdown_head,
939 shutdown_tail,
940 task);
941 }
942 else
943 {
944 GNUNET_CONTAINER_DLL_remove (pending_timeout_head,
945 pending_timeout_tail,
946 task);
947 if (pending_timeout_last == task)
948 pending_timeout_last = NULL;
949 }
1071 } 950 }
1072 else 951 else
1073 { 952 {
@@ -1078,9 +957,6 @@ GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task)
1078 ready_count--; 957 ready_count--;
1079 } 958 }
1080 ret = task->callback_cls; 959 ret = task->callback_cls;
1081 LOG (GNUNET_ERROR_TYPE_DEBUG,
1082 "Canceling task %p\n",
1083 task);
1084 destroy_task (task); 960 destroy_task (task);
1085 return ret; 961 return ret;
1086} 962}
@@ -1101,8 +977,10 @@ init_backtrace (struct GNUNET_SCHEDULER_Task *t)
1101 = backtrace (backtrace_array, MAX_TRACE_DEPTH); 977 = backtrace (backtrace_array, MAX_TRACE_DEPTH);
1102 t->backtrace_strings = 978 t->backtrace_strings =
1103 backtrace_symbols (backtrace_array, 979 backtrace_symbols (backtrace_array,
1104 t->num_backtrace_strings); 980 t->num_backtrace_strings);
1105 dump_backtrace (t); 981 dump_backtrace (t);
982#else
983 (void) t;
1106#endif 984#endif
1107} 985}
1108 986
@@ -1218,7 +1096,7 @@ GNUNET_SCHEDULER_add_at_with_priority (struct GNUNET_TIME_Absolute at,
1218 pending_timeout_last = t; 1096 pending_timeout_last = t;
1219 1097
1220 LOG (GNUNET_ERROR_TYPE_DEBUG, 1098 LOG (GNUNET_ERROR_TYPE_DEBUG,
1221 "Adding task: %p\n", 1099 "Adding task %p\n",
1222 t); 1100 t);
1223 init_backtrace (t); 1101 init_backtrace (t);
1224 return t; 1102 return t;
@@ -1238,8 +1116,8 @@ GNUNET_SCHEDULER_add_at_with_priority (struct GNUNET_TIME_Absolute at,
1238 */ 1116 */
1239struct GNUNET_SCHEDULER_Task * 1117struct GNUNET_SCHEDULER_Task *
1240GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay, 1118GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
1241 enum GNUNET_SCHEDULER_Priority priority, 1119 enum GNUNET_SCHEDULER_Priority priority,
1242 GNUNET_SCHEDULER_TaskCallback task, 1120 GNUNET_SCHEDULER_TaskCallback task,
1243 void *task_cls) 1121 void *task_cls)
1244{ 1122{
1245 return GNUNET_SCHEDULER_add_at_with_priority (GNUNET_TIME_relative_to_absolute (delay), 1123 return GNUNET_SCHEDULER_add_at_with_priority (GNUNET_TIME_relative_to_absolute (delay),
@@ -1307,12 +1185,12 @@ GNUNET_SCHEDULER_add_at (struct GNUNET_TIME_Absolute at,
1307struct GNUNET_SCHEDULER_Task * 1185struct GNUNET_SCHEDULER_Task *
1308GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, 1186GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
1309 GNUNET_SCHEDULER_TaskCallback task, 1187 GNUNET_SCHEDULER_TaskCallback task,
1310 void *task_cls) 1188 void *task_cls)
1311{ 1189{
1312 return GNUNET_SCHEDULER_add_delayed_with_priority (delay, 1190 return GNUNET_SCHEDULER_add_delayed_with_priority (delay,
1313 GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1191 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1314 task, 1192 task,
1315 task_cls); 1193 task_cls);
1316} 1194}
1317 1195
1318 1196
@@ -1333,11 +1211,11 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
1333 */ 1211 */
1334struct GNUNET_SCHEDULER_Task * 1212struct GNUNET_SCHEDULER_Task *
1335GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_TaskCallback task, 1213GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_TaskCallback task,
1336 void *task_cls) 1214 void *task_cls)
1337{ 1215{
1338 return GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_ZERO, 1216 return GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_ZERO,
1339 task, 1217 task,
1340 task_cls); 1218 task_cls);
1341} 1219}
1342 1220
1343 1221
@@ -1353,7 +1231,7 @@ GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_TaskCallback task,
1353 */ 1231 */
1354struct GNUNET_SCHEDULER_Task * 1232struct GNUNET_SCHEDULER_Task *
1355GNUNET_SCHEDULER_add_shutdown (GNUNET_SCHEDULER_TaskCallback task, 1233GNUNET_SCHEDULER_add_shutdown (GNUNET_SCHEDULER_TaskCallback task,
1356 void *task_cls) 1234 void *task_cls)
1357{ 1235{
1358 struct GNUNET_SCHEDULER_Task *t; 1236 struct GNUNET_SCHEDULER_Task *t;
1359 1237
@@ -1370,12 +1248,12 @@ GNUNET_SCHEDULER_add_shutdown (GNUNET_SCHEDULER_TaskCallback task,
1370 t->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; 1248 t->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
1371 t->priority = GNUNET_SCHEDULER_PRIORITY_SHUTDOWN; 1249 t->priority = GNUNET_SCHEDULER_PRIORITY_SHUTDOWN;
1372 t->on_shutdown = GNUNET_YES; 1250 t->on_shutdown = GNUNET_YES;
1373 t->lifeness = GNUNET_YES; 1251 t->lifeness = GNUNET_NO;
1374 GNUNET_CONTAINER_DLL_insert (shutdown_head, 1252 GNUNET_CONTAINER_DLL_insert (shutdown_head,
1375 shutdown_tail, 1253 shutdown_tail,
1376 t); 1254 t);
1377 LOG (GNUNET_ERROR_TYPE_DEBUG, 1255 LOG (GNUNET_ERROR_TYPE_DEBUG,
1378 "Adding task: %p\n", 1256 "Adding shutdown task %p\n",
1379 t); 1257 t);
1380 init_backtrace (t); 1258 init_backtrace (t);
1381 return t; 1259 return t;
@@ -1409,6 +1287,33 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
1409} 1287}
1410 1288
1411 1289
1290#if DEBUG_FDS
1291/**
1292 * check a raw file descriptor and abort if it is bad (for debugging purposes)
1293 *
1294 * @param t the task related to the file descriptor
1295 * @param raw_fd the raw file descriptor to check
1296 */
1297void
1298check_fd (struct GNUNET_SCHEDULER_Task *t, int raw_fd)
1299{
1300 if (-1 != raw_fd)
1301 {
1302 int flags = fcntl (raw_fd, F_GETFD);
1303
1304 if ((flags == -1) && (errno == EBADF))
1305 {
1306 LOG (GNUNET_ERROR_TYPE_ERROR,
1307 "Got invalid file descriptor %d!\n",
1308 raw_fd);
1309 init_backtrace (t);
1310 GNUNET_assert (0);
1311 }
1312 }
1313}
1314#endif
1315
1316
1412/** 1317/**
1413 * Schedule a new task to be run with a specified delay or when any of 1318 * Schedule a new task to be run with a specified delay or when any of
1414 * the specified file descriptor sets is ready. The delay can be used 1319 * the specified file descriptor sets is ready. The delay can be used
@@ -1437,9 +1342,11 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
1437#ifndef MINGW 1342#ifndef MINGW
1438static struct GNUNET_SCHEDULER_Task * 1343static struct GNUNET_SCHEDULER_Task *
1439add_without_sets (struct GNUNET_TIME_Relative delay, 1344add_without_sets (struct GNUNET_TIME_Relative delay,
1440 enum GNUNET_SCHEDULER_Priority priority, 1345 enum GNUNET_SCHEDULER_Priority priority,
1441 int rfd, 1346 const struct GNUNET_NETWORK_Handle *read_nh,
1442 int wfd, 1347 const struct GNUNET_NETWORK_Handle *write_nh,
1348 const struct GNUNET_DISK_FileHandle *read_fh,
1349 const struct GNUNET_DISK_FileHandle *write_fh,
1443 GNUNET_SCHEDULER_TaskCallback task, 1350 GNUNET_SCHEDULER_TaskCallback task,
1444 void *task_cls) 1351 void *task_cls)
1445{ 1352{
@@ -1448,39 +1355,23 @@ add_without_sets (struct GNUNET_TIME_Relative delay,
1448 GNUNET_assert (NULL != active_task); 1355 GNUNET_assert (NULL != active_task);
1449 GNUNET_assert (NULL != task); 1356 GNUNET_assert (NULL != task);
1450 t = GNUNET_new (struct GNUNET_SCHEDULER_Task); 1357 t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
1358 init_fd_info (t,
1359 &read_nh,
1360 read_nh ? 1 : 0,
1361 &write_nh,
1362 write_nh ? 1 : 0,
1363 &read_fh,
1364 read_fh ? 1 : 0,
1365 &write_fh,
1366 write_fh ? 1 : 0);
1451 t->callback = task; 1367 t->callback = task;
1452 t->callback_cls = task_cls; 1368 t->callback_cls = task_cls;
1453#if DEBUG_FDS 1369#if DEBUG_FDS
1454 if (-1 != rfd) 1370 check_fd (t, NULL != read_nh ? GNUNET_NETWORK_get_fd (read_nh) : -1);
1455 { 1371 check_fd (t, NULL != write_nh ? GNUNET_NETWORK_get_fd (write_nh) : -1);
1456 int flags = fcntl (rfd, F_GETFD); 1372 check_fd (t, NULL != read_fh ? read_fh->fd : -1);
1457 1373 check_fd (t, NULL != write_fh ? write_fh->fd : -1);
1458 if ((flags == -1) && (errno == EBADF))
1459 {
1460 LOG (GNUNET_ERROR_TYPE_ERROR,
1461 "Got invalid file descriptor %d!\n",
1462 rfd);
1463 init_backtrace (t);
1464 GNUNET_assert (0);
1465 }
1466 }
1467 if (-1 != wfd)
1468 {
1469 int flags = fcntl (wfd, F_GETFD);
1470
1471 if (flags == -1 && errno == EBADF)
1472 {
1473 LOG (GNUNET_ERROR_TYPE_ERROR,
1474 "Got invalid file descriptor %d!\n",
1475 wfd);
1476 init_backtrace (t);
1477 GNUNET_assert (0);
1478 }
1479 }
1480#endif 1374#endif
1481 t->read_fd = rfd;
1482 GNUNET_assert (wfd >= -1);
1483 t->write_fd = wfd;
1484#if PROFILE_DELAYS 1375#if PROFILE_DELAYS
1485 t->start_time = GNUNET_TIME_absolute_get (); 1376 t->start_time = GNUNET_TIME_absolute_get ();
1486#endif 1377#endif
@@ -1490,11 +1381,9 @@ add_without_sets (struct GNUNET_TIME_Relative delay,
1490 GNUNET_CONTAINER_DLL_insert (pending_head, 1381 GNUNET_CONTAINER_DLL_insert (pending_head,
1491 pending_tail, 1382 pending_tail,
1492 t); 1383 t);
1384 driver_add_multiple (t);
1493 max_priority_added = GNUNET_MAX (max_priority_added, 1385 max_priority_added = GNUNET_MAX (max_priority_added,
1494 t->priority); 1386 t->priority);
1495 LOG (GNUNET_ERROR_TYPE_DEBUG,
1496 "Adding task %p\n",
1497 t);
1498 init_backtrace (t); 1387 init_backtrace (t);
1499 return t; 1388 return t;
1500} 1389}
@@ -1507,6 +1396,9 @@ add_without_sets (struct GNUNET_TIME_Relative delay,
1507 * used as a timeout on the socket being ready. The task will be 1396 * used as a timeout on the socket being ready. The task will be
1508 * scheduled for execution once either the delay has expired or the 1397 * scheduled for execution once either the delay has expired or the
1509 * socket operation is ready. It will be run with the DEFAULT priority. 1398 * socket operation is ready. It will be run with the DEFAULT priority.
1399 * Only allowed to be called as long as the scheduler is running
1400 * (#GNUNET_SCHEDULER_run or #GNUNET_SCHEDULER_run_with_driver has been
1401 * called and has not returned yet).
1510 * 1402 *
1511 * @param delay when should this operation time out? 1403 * @param delay when should this operation time out?
1512 * @param rfd read file-descriptor 1404 * @param rfd read file-descriptor
@@ -1522,8 +1414,8 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
1522 void *task_cls) 1414 void *task_cls)
1523{ 1415{
1524 return GNUNET_SCHEDULER_add_read_net_with_priority (delay, 1416 return GNUNET_SCHEDULER_add_read_net_with_priority (delay,
1525 GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1417 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1526 rfd, task, task_cls); 1418 rfd, task, task_cls);
1527} 1419}
1528 1420
1529 1421
@@ -1534,6 +1426,9 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
1534 * socket being ready. The task will be scheduled for execution once 1426 * socket being ready. The task will be scheduled for execution once
1535 * either the delay has expired or the socket operation is ready. It 1427 * either the delay has expired or the socket operation is ready. It
1536 * will be run with the DEFAULT priority. 1428 * will be run with the DEFAULT priority.
1429 * Only allowed to be called as long as the scheduler is running
1430 * (#GNUNET_SCHEDULER_run or #GNUNET_SCHEDULER_run_with_driver has been
1431 * called and has not returned yet).
1537 * 1432 *
1538 * @param delay when should this operation time out? 1433 * @param delay when should this operation time out?
1539 * @param priority priority to use for the task 1434 * @param priority priority to use for the task
@@ -1545,9 +1440,9 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
1545 */ 1440 */
1546struct GNUNET_SCHEDULER_Task * 1441struct GNUNET_SCHEDULER_Task *
1547GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay, 1442GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay,
1548 enum GNUNET_SCHEDULER_Priority priority, 1443 enum GNUNET_SCHEDULER_Priority priority,
1549 struct GNUNET_NETWORK_Handle *rfd, 1444 struct GNUNET_NETWORK_Handle *rfd,
1550 GNUNET_SCHEDULER_TaskCallback task, 1445 GNUNET_SCHEDULER_TaskCallback task,
1551 void *task_cls) 1446 void *task_cls)
1552{ 1447{
1553 return GNUNET_SCHEDULER_add_net_with_priority (delay, priority, 1448 return GNUNET_SCHEDULER_add_net_with_priority (delay, priority,
@@ -1565,6 +1460,9 @@ GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay,
1565 * scheduled for execution once either the delay has expired or the 1460 * scheduled for execution once either the delay has expired or the
1566 * socket operation is ready. It will be run with the priority of 1461 * socket operation is ready. It will be run with the priority of
1567 * the calling task. 1462 * the calling task.
1463 * Only allowed to be called as long as the scheduler is running
1464 * (#GNUNET_SCHEDULER_run or #GNUNET_SCHEDULER_run_with_driver has been
1465 * called and has not returned yet).
1568 * 1466 *
1569 * @param delay when should this operation time out? 1467 * @param delay when should this operation time out?
1570 * @param wfd write file-descriptor 1468 * @param wfd write file-descriptor
@@ -1592,6 +1490,9 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
1592 * used as a timeout on the socket being ready. The task will be 1490 * used as a timeout on the socket being ready. The task will be
1593 * scheduled for execution once either the delay has expired or the 1491 * scheduled for execution once either the delay has expired or the
1594 * socket operation is ready. 1492 * socket operation is ready.
1493 * Only allowed to be called as long as the scheduler is running
1494 * (#GNUNET_SCHEDULER_run or #GNUNET_SCHEDULER_run_with_driver has been
1495 * called and has not returned yet).
1595 * 1496 *
1596 * @param delay when should this operation time out? 1497 * @param delay when should this operation time out?
1597 * @param priority priority of the task 1498 * @param priority priority of the task
@@ -1612,6 +1513,9 @@ GNUNET_SCHEDULER_add_net_with_priority (struct GNUNET_TIME_Relative delay,
1612 GNUNET_SCHEDULER_TaskCallback task, 1513 GNUNET_SCHEDULER_TaskCallback task,
1613 void *task_cls) 1514 void *task_cls)
1614{ 1515{
1516 /* scheduler must be running */
1517 GNUNET_assert (NULL != scheduler_driver);
1518
1615#if MINGW 1519#if MINGW
1616 struct GNUNET_NETWORK_FDSet *s; 1520 struct GNUNET_NETWORK_FDSet *s;
1617 struct GNUNET_SCHEDULER_Task * ret; 1521 struct GNUNET_SCHEDULER_Task * ret;
@@ -1627,10 +1531,13 @@ GNUNET_SCHEDULER_add_net_with_priority (struct GNUNET_TIME_Relative delay,
1627 GNUNET_NETWORK_fdset_destroy (s); 1531 GNUNET_NETWORK_fdset_destroy (s);
1628 return ret; 1532 return ret;
1629#else 1533#else
1534 GNUNET_assert (on_read || on_write);
1630 GNUNET_assert (GNUNET_NETWORK_get_fd (fd) >= 0); 1535 GNUNET_assert (GNUNET_NETWORK_get_fd (fd) >= 0);
1631 return add_without_sets (delay, priority, 1536 return add_without_sets (delay, priority,
1632 on_read ? GNUNET_NETWORK_get_fd (fd) : -1, 1537 on_read ? fd : NULL,
1633 on_write ? GNUNET_NETWORK_get_fd (fd) : -1, 1538 on_write ? fd : NULL,
1539 NULL,
1540 NULL,
1634 task, task_cls); 1541 task, task_cls);
1635#endif 1542#endif
1636} 1543}
@@ -1642,6 +1549,9 @@ GNUNET_SCHEDULER_add_net_with_priority (struct GNUNET_TIME_Relative delay,
1642 * used as a timeout on the socket being ready. The task will be 1549 * used as a timeout on the socket being ready. The task will be
1643 * scheduled for execution once either the delay has expired or the 1550 * scheduled for execution once either the delay has expired or the
1644 * socket operation is ready. It will be run with the DEFAULT priority. 1551 * socket operation is ready. It will be run with the DEFAULT priority.
1552 * Only allowed to be called as long as the scheduler is running
1553 * (#GNUNET_SCHEDULER_run or #GNUNET_SCHEDULER_run_with_driver has been
1554 * called and has not returned yet).
1645 * 1555 *
1646 * @param delay when should this operation time out? 1556 * @param delay when should this operation time out?
1647 * @param rfd read file-descriptor 1557 * @param rfd read file-descriptor
@@ -1668,6 +1578,9 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
1668 * used as a timeout on the socket being ready. The task will be 1578 * used as a timeout on the socket being ready. The task will be
1669 * scheduled for execution once either the delay has expired or the 1579 * scheduled for execution once either the delay has expired or the
1670 * socket operation is ready. It will be run with the DEFAULT priority. 1580 * socket operation is ready. It will be run with the DEFAULT priority.
1581 * Only allowed to be called as long as the scheduler is running
1582 * (#GNUNET_SCHEDULER_run or #GNUNET_SCHEDULER_run_with_driver has been
1583 * called and has not returned yet).
1671 * 1584 *
1672 * @param delay when should this operation time out? 1585 * @param delay when should this operation time out?
1673 * @param wfd write file-descriptor 1586 * @param wfd write file-descriptor
@@ -1694,6 +1607,9 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
1694 * used as a timeout on the socket being ready. The task will be 1607 * used as a timeout on the socket being ready. The task will be
1695 * scheduled for execution once either the delay has expired or the 1608 * scheduled for execution once either the delay has expired or the
1696 * socket operation is ready. 1609 * socket operation is ready.
1610 * Only allowed to be called as long as the scheduler is running
1611 * (#GNUNET_SCHEDULER_run or #GNUNET_SCHEDULER_run_with_driver has been
1612 * called and has not returned yet).
1697 * 1613 *
1698 * @param delay when should this operation time out? 1614 * @param delay when should this operation time out?
1699 * @param priority priority of the task 1615 * @param priority priority of the task
@@ -1712,6 +1628,9 @@ GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay,
1712 int on_read, int on_write, 1628 int on_read, int on_write,
1713 GNUNET_SCHEDULER_TaskCallback task, void *task_cls) 1629 GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
1714{ 1630{
1631 /* scheduler must be running */
1632 GNUNET_assert (NULL != scheduler_driver);
1633
1715#if MINGW 1634#if MINGW
1716 struct GNUNET_NETWORK_FDSet *s; 1635 struct GNUNET_NETWORK_FDSet *s;
1717 struct GNUNET_SCHEDULER_Task * ret; 1636 struct GNUNET_SCHEDULER_Task * ret;
@@ -1727,19 +1646,71 @@ GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay,
1727 GNUNET_NETWORK_fdset_destroy (s); 1646 GNUNET_NETWORK_fdset_destroy (s);
1728 return ret; 1647 return ret;
1729#else 1648#else
1730 int real_fd; 1649 GNUNET_assert (on_read || on_write);
1731 1650 GNUNET_assert (fd->fd >= 0);
1732 GNUNET_DISK_internal_file_handle_ (fd, &real_fd, sizeof (int)); 1651 return add_without_sets (delay, priority,
1733 GNUNET_assert (real_fd >= 0); 1652 NULL,
1734 return add_without_sets ( 1653 NULL,
1735 delay, priority, 1654 on_read ? fd : NULL,
1736 on_read ? real_fd : -1, 1655 on_write ? fd : NULL,
1737 on_write ? real_fd : -1, 1656 task, task_cls);
1738 task, task_cls);
1739#endif 1657#endif
1740} 1658}
1741 1659
1742 1660
1661void
1662extract_handles (struct GNUNET_SCHEDULER_Task *t,
1663 const struct GNUNET_NETWORK_FDSet *fdset,
1664 const struct GNUNET_NETWORK_Handle ***ntarget,
1665 unsigned int *extracted_nhandles,
1666 const struct GNUNET_DISK_FileHandle ***ftarget,
1667 unsigned int *extracted_fhandles)
1668{
1669 // FIXME: this implementation only works for unix, for WIN32 the file handles
1670 // in fdset must be handled separately
1671 const struct GNUNET_NETWORK_Handle **nhandles;
1672 const struct GNUNET_DISK_FileHandle **fhandles;
1673 unsigned int nhandles_len;
1674 unsigned int fhandles_len;
1675
1676 (void) t;
1677 nhandles = NULL;
1678 fhandles = NULL;
1679 nhandles_len = 0;
1680 fhandles_len = 0;
1681 for (int sock = 0; sock != fdset->nsds; ++sock)
1682 {
1683 if (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (fdset, sock))
1684 {
1685 struct GNUNET_NETWORK_Handle *nhandle;
1686 struct GNUNET_DISK_FileHandle *fhandle;
1687
1688 nhandle = GNUNET_NETWORK_socket_box_native (sock);
1689 if (NULL != nhandle)
1690 {
1691 GNUNET_array_append (nhandles, nhandles_len, nhandle);
1692 }
1693 else
1694 {
1695 fhandle = GNUNET_DISK_get_handle_from_int_fd (sock);
1696 if (NULL != fhandle)
1697 {
1698 GNUNET_array_append (fhandles, fhandles_len, fhandle);
1699 }
1700 else
1701 {
1702 GNUNET_assert (0);
1703 }
1704 }
1705 }
1706 }
1707 *ntarget = nhandles_len > 0 ? nhandles : NULL;
1708 *ftarget = fhandles_len > 0 ? fhandles : NULL;
1709 *extracted_nhandles = nhandles_len;
1710 *extracted_fhandles = fhandles_len;
1711}
1712
1713
1743/** 1714/**
1744 * Schedule a new task to be run with a specified delay or when any of 1715 * Schedule a new task to be run with a specified delay or when any of
1745 * the specified file descriptor sets is ready. The delay can be used 1716 * the specified file descriptor sets is ready. The delay can be used
@@ -1755,6 +1726,9 @@ GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay,
1755 * || any-rs-ready 1726 * || any-rs-ready
1756 * || any-ws-ready) ) 1727 * || any-ws-ready) )
1757 * </code> 1728 * </code>
1729 * Only allowed to be called as long as the scheduler is running
1730 * (#GNUNET_SCHEDULER_run or #GNUNET_SCHEDULER_run_with_driver has been
1731 * called and has not returned yet).
1758 * 1732 *
1759 * @param prio how important is this task? 1733 * @param prio how important is this task?
1760 * @param delay how long should we wait? 1734 * @param delay how long should we wait?
@@ -1774,13 +1748,23 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
1774 void *task_cls) 1748 void *task_cls)
1775{ 1749{
1776 struct GNUNET_SCHEDULER_Task *t; 1750 struct GNUNET_SCHEDULER_Task *t;
1777 1751 const struct GNUNET_NETWORK_Handle **read_nhandles;
1778 if ( (NULL == rs) && 1752 const struct GNUNET_NETWORK_Handle **write_nhandles;
1779 (NULL == ws) ) 1753 const struct GNUNET_DISK_FileHandle **read_fhandles;
1754 const struct GNUNET_DISK_FileHandle **write_fhandles;
1755 unsigned int read_nhandles_len, write_nhandles_len,
1756 read_fhandles_len, write_fhandles_len;
1757 int no_fdsets = (NULL == rs) && (NULL == ws);
1758 int no_socket_descriptors =
1759 ((NULL != rs) && (0 == rs->nsds)) && ((NULL != ws) && (0 == ws->nsds));
1760
1761 if (no_fdsets || no_socket_descriptors)
1780 return GNUNET_SCHEDULER_add_delayed_with_priority (delay, 1762 return GNUNET_SCHEDULER_add_delayed_with_priority (delay,
1781 prio, 1763 prio,
1782 task, 1764 task,
1783 task_cls); 1765 task_cls);
1766 /* scheduler must be running */
1767 GNUNET_assert (NULL != scheduler_driver);
1784 GNUNET_assert (NULL != active_task); 1768 GNUNET_assert (NULL != active_task);
1785 GNUNET_assert (NULL != task); 1769 GNUNET_assert (NULL != task);
1786 t = GNUNET_new (struct GNUNET_SCHEDULER_Task); 1770 t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
@@ -1788,16 +1772,48 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
1788 t->callback_cls = task_cls; 1772 t->callback_cls = task_cls;
1789 t->read_fd = -1; 1773 t->read_fd = -1;
1790 t->write_fd = -1; 1774 t->write_fd = -1;
1775 t->own_handles = GNUNET_YES;
1776 read_nhandles = NULL;
1777 write_nhandles = NULL;
1778 read_fhandles = NULL;
1779 write_fhandles = NULL;
1780 read_nhandles_len = 0;
1781 write_nhandles_len = 0;
1782 read_fhandles_len = 0;
1783 write_fhandles_len = 0;
1791 if (NULL != rs) 1784 if (NULL != rs)
1792 { 1785 {
1793 t->read_set = GNUNET_NETWORK_fdset_create (); 1786 extract_handles (t,
1794 GNUNET_NETWORK_fdset_copy (t->read_set, rs); 1787 rs,
1788 &read_nhandles,
1789 &read_nhandles_len,
1790 &read_fhandles,
1791 &read_fhandles_len);
1795 } 1792 }
1796 if (NULL != ws) 1793 if (NULL != ws)
1797 { 1794 {
1798 t->write_set = GNUNET_NETWORK_fdset_create (); 1795 extract_handles (t,
1799 GNUNET_NETWORK_fdset_copy (t->write_set, ws); 1796 ws,
1797 &write_nhandles,
1798 &write_nhandles_len,
1799 &write_fhandles,
1800 &write_fhandles_len);
1800 } 1801 }
1802 init_fd_info (t,
1803 read_nhandles,
1804 read_nhandles_len,
1805 write_nhandles,
1806 write_nhandles_len,
1807 read_fhandles,
1808 read_fhandles_len,
1809 write_fhandles,
1810 write_fhandles_len);
1811 /* free the arrays of pointers to network / file handles, the actual
1812 * handles will be freed in destroy_task */
1813 GNUNET_array_grow (read_nhandles, read_nhandles_len, 0);
1814 GNUNET_array_grow (write_nhandles, write_nhandles_len, 0);
1815 GNUNET_array_grow (read_fhandles, read_fhandles_len, 0);
1816 GNUNET_array_grow (write_fhandles, write_fhandles_len, 0);
1801#if PROFILE_DELAYS 1817#if PROFILE_DELAYS
1802 t->start_time = GNUNET_TIME_absolute_get (); 1818 t->start_time = GNUNET_TIME_absolute_get ();
1803#endif 1819#endif
@@ -1810,8 +1826,9 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
1810 GNUNET_CONTAINER_DLL_insert (pending_head, 1826 GNUNET_CONTAINER_DLL_insert (pending_head,
1811 pending_tail, 1827 pending_tail,
1812 t); 1828 t);
1829 driver_add_multiple (t);
1813 max_priority_added = GNUNET_MAX (max_priority_added, 1830 max_priority_added = GNUNET_MAX (max_priority_added,
1814 t->priority); 1831 t->priority);
1815 LOG (GNUNET_ERROR_TYPE_DEBUG, 1832 LOG (GNUNET_ERROR_TYPE_DEBUG,
1816 "Adding task %p\n", 1833 "Adding task %p\n",
1817 t); 1834 t);
@@ -1822,17 +1839,18 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
1822 1839
1823/** 1840/**
1824 * Function used by event-loop implementations to signal the scheduler 1841 * Function used by event-loop implementations to signal the scheduler
1825 * that a particular @a task is ready due to an event of type @a et. 1842 * that a particular @a task is ready due to an event specified in the
1843 * et field of @a fdi.
1826 * 1844 *
1827 * This function will then queue the task to notify the application 1845 * This function will then queue the task to notify the application
1828 * that the task is ready (with the respective priority). 1846 * that the task is ready (with the respective priority).
1829 * 1847 *
1830 * @param task the task that is ready, NULL for wake up calls 1848 * @param task the task that is ready
1831 * @param et information about why the task is ready 1849 * @param fdi information about the related FD
1832 */ 1850 */
1833void 1851void
1834GNUNET_SCHEDULER_task_ready (struct GNUNET_SCHEDULER_Task *task, 1852GNUNET_SCHEDULER_task_ready (struct GNUNET_SCHEDULER_Task *task,
1835 enum GNUNET_SCHEDULER_EventType et) 1853 struct GNUNET_SCHEDULER_FdInfo *fdi)
1836{ 1854{
1837 enum GNUNET_SCHEDULER_Reason reason; 1855 enum GNUNET_SCHEDULER_Reason reason;
1838 struct GNUNET_TIME_Absolute now; 1856 struct GNUNET_TIME_Absolute now;
@@ -1842,17 +1860,20 @@ GNUNET_SCHEDULER_task_ready (struct GNUNET_SCHEDULER_Task *task,
1842 if (now.abs_value_us >= task->timeout.abs_value_us) 1860 if (now.abs_value_us >= task->timeout.abs_value_us)
1843 reason |= GNUNET_SCHEDULER_REASON_TIMEOUT; 1861 reason |= GNUNET_SCHEDULER_REASON_TIMEOUT;
1844 if ( (0 == (reason & GNUNET_SCHEDULER_REASON_READ_READY)) && 1862 if ( (0 == (reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
1845 (0 != (GNUNET_SCHEDULER_ET_IN & et)) ) 1863 (0 != (GNUNET_SCHEDULER_ET_IN & fdi->et)) )
1846 reason |= GNUNET_SCHEDULER_REASON_READ_READY; 1864 reason |= GNUNET_SCHEDULER_REASON_READ_READY;
1847 if ( (0 == (reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) && 1865 if ( (0 == (reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) &&
1848 (0 != (GNUNET_SCHEDULER_ET_OUT & et)) ) 1866 (0 != (GNUNET_SCHEDULER_ET_OUT & fdi->et)) )
1849 reason |= GNUNET_SCHEDULER_REASON_WRITE_READY; 1867 reason |= GNUNET_SCHEDULER_REASON_WRITE_READY;
1850 reason |= GNUNET_SCHEDULER_REASON_PREREQ_DONE; 1868 reason |= GNUNET_SCHEDULER_REASON_PREREQ_DONE;
1851 task->reason = reason; 1869 task->reason = reason;
1852 task->fds = &task->fdx; 1870 if (GNUNET_NO == task->in_ready_list)
1853 task->fdx.et = et; 1871 {
1854 task->fds_len = 1; 1872 GNUNET_CONTAINER_DLL_remove (pending_head,
1855 queue_ready_task (task); 1873 pending_tail,
1874 task);
1875 queue_ready_task (task);
1876 }
1856} 1877}
1857 1878
1858 1879
@@ -1862,15 +1883,16 @@ GNUNET_SCHEDULER_task_ready (struct GNUNET_SCHEDULER_Task *task,
1862 * there are tasks left to run just to give other tasks a chance as 1883 * there are tasks left to run just to give other tasks a chance as
1863 * well. If we return #GNUNET_YES, the driver should call this 1884 * well. If we return #GNUNET_YES, the driver should call this
1864 * function again as soon as possible, while if we return #GNUNET_NO 1885 * function again as soon as possible, while if we return #GNUNET_NO
1865 * it must block until the operating system has more work as the 1886 * it must block until either the operating system has more work (the
1866 * scheduler has no more work to do right now. 1887 * scheduler has no more work to do right now) or the timeout set by
1888 * the scheduler (using the set_wakeup callback) is reached.
1867 * 1889 *
1868 * @param sh scheduler handle that was given to the `loop` 1890 * @param sh scheduler handle that was given to the `loop`
1869 * @return #GNUNET_OK if there are more tasks that are ready, 1891 * @return #GNUNET_OK if there are more tasks that are ready,
1870 * and thus we would like to run more (yield to avoid 1892 * and thus we would like to run more (yield to avoid
1871 * blocking other activities for too long) 1893 * blocking other activities for too long)
1872 * #GNUNET_NO if we are done running tasks (yield to block) 1894 * #GNUNET_NO if we are done running tasks (yield to block)
1873 * #GNUNET_SYSERR on error 1895 * #GNUNET_SYSERR on error, e.g. no tasks were ready
1874 */ 1896 */
1875int 1897int
1876GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh) 1898GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh)
@@ -1894,9 +1916,27 @@ GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh)
1894 pending_timeout_last = NULL; 1916 pending_timeout_last = NULL;
1895 queue_ready_task (pos); 1917 queue_ready_task (pos);
1896 } 1918 }
1919 pos = pending_head;
1920 while (NULL != pos)
1921 {
1922 struct GNUNET_SCHEDULER_Task *next = pos->next;
1923 if (now.abs_value_us >= pos->timeout.abs_value_us)
1924 {
1925 pos->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT;
1926 GNUNET_CONTAINER_DLL_remove (pending_head,
1927 pending_tail,
1928 pos);
1929 queue_ready_task (pos);
1930 }
1931 pos = next;
1932 }
1897 1933
1898 if (0 == ready_count) 1934 if (0 == ready_count)
1899 return GNUNET_NO; 1935 {
1936 LOG (GNUNET_ERROR_TYPE_ERROR,
1937 "GNUNET_SCHEDULER_run_from_driver was called, but no tasks are ready!\n");
1938 return GNUNET_SYSERR;
1939 }
1900 1940
1901 /* find out which task priority level we are going to 1941 /* find out which task priority level we are going to
1902 process this time */ 1942 process this time */
@@ -1916,49 +1956,74 @@ GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh)
1916 while (NULL != (pos = ready_head[p])) 1956 while (NULL != (pos = ready_head[p]))
1917 { 1957 {
1918 GNUNET_CONTAINER_DLL_remove (ready_head[p], 1958 GNUNET_CONTAINER_DLL_remove (ready_head[p],
1919 ready_tail[p], 1959 ready_tail[p],
1920 pos); 1960 pos);
1921 ready_count--; 1961 ready_count--;
1922 current_priority = pos->priority; 1962 current_priority = pos->priority;
1923 current_lifeness = pos->lifeness; 1963 current_lifeness = pos->lifeness;
1924 active_task = pos; 1964 active_task = pos;
1925#if PROFILE_DELAYS 1965#if PROFILE_DELAYS
1926 if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value_us > 1966 if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value_us >
1927 DELAY_THRESHOLD.rel_value_us) 1967 DELAY_THRESHOLD.rel_value_us)
1928 { 1968 {
1929 LOG (GNUNET_ERROR_TYPE_DEBUG, 1969 LOG (GNUNET_ERROR_TYPE_DEBUG,
1930 "Task %p took %s to be scheduled\n", 1970 "Task %p took %s to be scheduled\n",
1931 pos, 1971 pos,
1932 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (pos->start_time), 1972 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (pos->start_time),
1933 GNUNET_YES)); 1973 GNUNET_YES));
1934 } 1974 }
1935#endif 1975#endif
1936 tc.reason = pos->reason; 1976 tc.reason = pos->reason;
1937 GNUNET_NETWORK_fdset_zero (sh->rs); 1977 GNUNET_NETWORK_fdset_zero (sh->rs);
1938 GNUNET_NETWORK_fdset_zero (sh->ws); 1978 GNUNET_NETWORK_fdset_zero (sh->ws);
1979 // FIXME: do we have to remove FdInfos from fds if they are not ready?
1939 tc.fds_len = pos->fds_len; 1980 tc.fds_len = pos->fds_len;
1940 tc.fds = pos->fds; 1981 tc.fds = pos->fds;
1941 tc.read_ready = (NULL == pos->read_set) ? sh->rs : pos->read_set; 1982 for (unsigned int i = 0; i != pos->fds_len; ++i)
1942 if ( (-1 != pos->read_fd) && 1983 {
1943 (0 != (pos->reason & GNUNET_SCHEDULER_REASON_READ_READY)) ) 1984 struct GNUNET_SCHEDULER_FdInfo *fdi = &pos->fds[i];
1944 GNUNET_NETWORK_fdset_set_native (sh->rs, 1985 if (0 != (GNUNET_SCHEDULER_ET_IN & fdi->et))
1945 pos->read_fd); 1986 {
1946 tc.write_ready = (NULL == pos->write_set) ? sh->ws : pos->write_set; 1987 GNUNET_NETWORK_fdset_set_native (sh->rs,
1947 if ((-1 != pos->write_fd) && 1988 fdi->sock);
1948 (0 != (pos->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))) 1989 }
1949 GNUNET_NETWORK_fdset_set_native (sh->ws, 1990 if (0 != (GNUNET_SCHEDULER_ET_OUT & fdi->et))
1950 pos->write_fd); 1991 {
1992 GNUNET_NETWORK_fdset_set_native (sh->ws,
1993 fdi->sock);
1994 }
1995 }
1996 tc.read_ready = sh->rs;
1997 tc.write_ready = sh->ws;
1951 LOG (GNUNET_ERROR_TYPE_DEBUG, 1998 LOG (GNUNET_ERROR_TYPE_DEBUG,
1952 "Running task: %p\n", 1999 "Running task %p\n",
1953 pos); 2000 pos);
2001 GNUNET_assert (NULL != pos->callback);
1954 pos->callback (pos->callback_cls); 2002 pos->callback (pos->callback_cls);
2003 if (NULL != pos->fds)
2004 {
2005 int del_result = scheduler_driver->del (scheduler_driver->cls, pos);
2006 if (GNUNET_OK != del_result)
2007 {
2008 LOG (GNUNET_ERROR_TYPE_ERROR,
2009 "driver could not delete task\n");
2010 GNUNET_assert (0);
2011 }
2012 }
1955 active_task = NULL; 2013 active_task = NULL;
1956 dump_backtrace (pos); 2014 dump_backtrace (pos);
1957 destroy_task (pos); 2015 destroy_task (pos);
1958 tasks_run++; 2016 tasks_run++;
1959 } 2017 }
2018 shutdown_if_no_lifeness ();
1960 if (0 == ready_count) 2019 if (0 == ready_count)
2020 {
2021 scheduler_driver->set_wakeup (scheduler_driver->cls,
2022 get_timeout ());
1961 return GNUNET_NO; 2023 return GNUNET_NO;
2024 }
2025 scheduler_driver->set_wakeup (scheduler_driver->cls,
2026 GNUNET_TIME_absolute_get ());
1962 return GNUNET_OK; 2027 return GNUNET_OK;
1963} 2028}
1964 2029
@@ -1981,8 +2046,8 @@ GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh)
1981 */ 2046 */
1982int 2047int
1983GNUNET_SCHEDULER_run_with_driver (const struct GNUNET_SCHEDULER_Driver *driver, 2048GNUNET_SCHEDULER_run_with_driver (const struct GNUNET_SCHEDULER_Driver *driver,
1984 GNUNET_SCHEDULER_TaskCallback task, 2049 GNUNET_SCHEDULER_TaskCallback task,
1985 void *task_cls) 2050 void *task_cls)
1986{ 2051{
1987 int ret; 2052 int ret;
1988 struct GNUNET_SIGNAL_Context *shc_int; 2053 struct GNUNET_SIGNAL_Context *shc_int;
@@ -1997,7 +2062,6 @@ GNUNET_SCHEDULER_run_with_driver (const struct GNUNET_SCHEDULER_Driver *driver,
1997#endif 2062#endif
1998 struct GNUNET_SCHEDULER_Task tsk; 2063 struct GNUNET_SCHEDULER_Task tsk;
1999 const struct GNUNET_DISK_FileHandle *pr; 2064 const struct GNUNET_DISK_FileHandle *pr;
2000 struct GNUNET_SCHEDULER_Handle sh;
2001 2065
2002 /* general set-up */ 2066 /* general set-up */
2003 GNUNET_assert (NULL == active_task); 2067 GNUNET_assert (NULL == active_task);
@@ -2009,54 +2073,56 @@ GNUNET_SCHEDULER_run_with_driver (const struct GNUNET_SCHEDULER_Driver *driver,
2009 GNUNET_assert (NULL != shutdown_pipe_handle); 2073 GNUNET_assert (NULL != shutdown_pipe_handle);
2010 pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle, 2074 pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle,
2011 GNUNET_DISK_PIPE_END_READ); 2075 GNUNET_DISK_PIPE_END_READ);
2012 GNUNET_assert (NULL != pr);
2013 my_pid = getpid (); 2076 my_pid = getpid ();
2077 scheduler_driver = driver;
2014 2078
2015 /* install signal handlers */ 2079 /* install signal handlers */
2016 LOG (GNUNET_ERROR_TYPE_DEBUG, 2080 LOG (GNUNET_ERROR_TYPE_DEBUG,
2017 "Registering signal handlers\n"); 2081 "Registering signal handlers\n");
2018 shc_int = GNUNET_SIGNAL_handler_install (SIGINT, 2082 shc_int = GNUNET_SIGNAL_handler_install (SIGINT,
2019 &sighandler_shutdown); 2083 &sighandler_shutdown);
2020 shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, 2084 shc_term = GNUNET_SIGNAL_handler_install (SIGTERM,
2021 &sighandler_shutdown); 2085 &sighandler_shutdown);
2022#if (SIGTERM != GNUNET_TERM_SIG) 2086#if (SIGTERM != GNUNET_TERM_SIG)
2023 shc_gterm = GNUNET_SIGNAL_handler_install (GNUNET_TERM_SIG, 2087 shc_gterm = GNUNET_SIGNAL_handler_install (GNUNET_TERM_SIG,
2024 &sighandler_shutdown); 2088 &sighandler_shutdown);
2025#endif 2089#endif
2026#ifndef MINGW 2090#ifndef MINGW
2027 shc_pipe = GNUNET_SIGNAL_handler_install (SIGPIPE, 2091 shc_pipe = GNUNET_SIGNAL_handler_install (SIGPIPE,
2028 &sighandler_pipe); 2092 &sighandler_pipe);
2029 shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT, 2093 shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT,
2030 &sighandler_shutdown); 2094 &sighandler_shutdown);
2031 shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP, 2095 shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP,
2032 &sighandler_shutdown); 2096 &sighandler_shutdown);
2033#endif 2097#endif
2034 2098
2035 /* Setup initial tasks */ 2099 /* Setup initial tasks */
2036 current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; 2100 current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT;
2037 current_lifeness = GNUNET_YES; 2101 current_lifeness = GNUNET_NO;
2038 memset (&tsk, 2102 memset (&tsk,
2039 0, 2103 0,
2040 sizeof (tsk)); 2104 sizeof (tsk));
2041 active_task = &tsk; 2105 active_task = &tsk;
2042 tsk.sh = &sh; 2106 GNUNET_SCHEDULER_add_now (&GNUNET_OS_install_parent_control_handler,
2107 NULL);
2108 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
2109 pr,
2110 &shutdown_cb,
2111 NULL);
2112 current_lifeness = GNUNET_YES;
2043 GNUNET_SCHEDULER_add_with_reason_and_priority (task, 2113 GNUNET_SCHEDULER_add_with_reason_and_priority (task,
2044 task_cls, 2114 task_cls,
2045 GNUNET_SCHEDULER_REASON_STARTUP, 2115 GNUNET_SCHEDULER_REASON_STARTUP,
2046 GNUNET_SCHEDULER_PRIORITY_DEFAULT); 2116 GNUNET_SCHEDULER_PRIORITY_DEFAULT);
2047 GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO,
2048 &GNUNET_OS_install_parent_control_handler,
2049 NULL);
2050 active_task = NULL; 2117 active_task = NULL;
2051 driver->set_wakeup (driver->cls, 2118 scheduler_driver->set_wakeup (scheduler_driver->cls,
2052 GNUNET_TIME_absolute_get ()); 2119 get_timeout ());
2053
2054 /* begin main event loop */ 2120 /* begin main event loop */
2055 sh.rs = GNUNET_NETWORK_fdset_create (); 2121 sh.rs = GNUNET_NETWORK_fdset_create ();
2056 sh.ws = GNUNET_NETWORK_fdset_create (); 2122 sh.ws = GNUNET_NETWORK_fdset_create ();
2057 sh.driver = driver; 2123 GNUNET_NETWORK_fdset_handle_set (sh.rs, pr);
2058 ret = driver->loop (driver->cls, 2124 ret = driver->loop (driver->cls,
2059 &sh); 2125 &sh);
2060 GNUNET_NETWORK_fdset_destroy (sh.rs); 2126 GNUNET_NETWORK_fdset_destroy (sh.rs);
2061 GNUNET_NETWORK_fdset_destroy (sh.ws); 2127 GNUNET_NETWORK_fdset_destroy (sh.ws);
2062 2128
@@ -2073,20 +2139,215 @@ GNUNET_SCHEDULER_run_with_driver (const struct GNUNET_SCHEDULER_Driver *driver,
2073#endif 2139#endif
2074 GNUNET_DISK_pipe_close (shutdown_pipe_handle); 2140 GNUNET_DISK_pipe_close (shutdown_pipe_handle);
2075 shutdown_pipe_handle = NULL; 2141 shutdown_pipe_handle = NULL;
2142 scheduler_driver = NULL;
2143 return ret;
2144}
2145
2146
2147int
2148select_add (void *cls,
2149 struct GNUNET_SCHEDULER_Task *task,
2150 struct GNUNET_SCHEDULER_FdInfo *fdi)
2151{
2152 struct DriverContext *context = cls;
2153 GNUNET_assert (NULL != context);
2154 GNUNET_assert (NULL != task);
2155 GNUNET_assert (NULL != fdi);
2156 GNUNET_assert (0 != (GNUNET_SCHEDULER_ET_IN & fdi->et) ||
2157 0 != (GNUNET_SCHEDULER_ET_OUT & fdi->et));
2158
2159 if (!((NULL != fdi->fd) ^ (NULL != fdi->fh)) || (fdi->sock < 0))
2160 {
2161 /* exactly one out of {fd, hf} must be != NULL and the OS handle must be valid */
2162 return GNUNET_SYSERR;
2163 }
2164
2165 struct Scheduled *scheduled = GNUNET_new (struct Scheduled);
2166 scheduled->task = task;
2167 scheduled->fdi = fdi;
2168 scheduled->et = fdi->et;
2169
2170 GNUNET_CONTAINER_DLL_insert (context->scheduled_head,
2171 context->scheduled_tail,
2172 scheduled);
2173 return GNUNET_OK;
2174}
2175
2176
2177int
2178select_del (void *cls,
2179 struct GNUNET_SCHEDULER_Task *task)
2180{
2181 struct DriverContext *context;
2182 struct Scheduled *pos;
2183 int ret;
2184
2185 GNUNET_assert (NULL != cls);
2186
2187 context = cls;
2188 ret = GNUNET_SYSERR;
2189 pos = context->scheduled_head;
2190 while (NULL != pos)
2191 {
2192 struct Scheduled *next = pos->next;
2193 if (pos->task == task)
2194 {
2195 GNUNET_CONTAINER_DLL_remove (context->scheduled_head,
2196 context->scheduled_tail,
2197 pos);
2198 GNUNET_free (pos);
2199 ret = GNUNET_OK;
2200 }
2201 pos = next;
2202 }
2076 return ret; 2203 return ret;
2077} 2204}
2078 2205
2079 2206
2207int
2208select_loop (void *cls,
2209 struct GNUNET_SCHEDULER_Handle *sh)
2210{
2211 struct GNUNET_NETWORK_FDSet *rs;
2212 struct GNUNET_NETWORK_FDSet *ws;
2213 struct DriverContext *context;
2214 int select_result;
2215 int tasks_ready;
2216
2217 context = cls;
2218 GNUNET_assert (NULL != context);
2219 rs = GNUNET_NETWORK_fdset_create ();
2220 ws = GNUNET_NETWORK_fdset_create ();
2221 tasks_ready = GNUNET_NO;
2222 while (NULL != context->scheduled_head ||
2223 GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != context->timeout.rel_value_us)
2224 {
2225 LOG (GNUNET_ERROR_TYPE_DEBUG,
2226 "select timeout = %s\n",
2227 GNUNET_STRINGS_relative_time_to_string (context->timeout, GNUNET_NO));
2228
2229 GNUNET_NETWORK_fdset_zero (rs);
2230 GNUNET_NETWORK_fdset_zero (ws);
2231 struct Scheduled *pos;
2232 for (pos = context->scheduled_head; NULL != pos; pos = pos->next)
2233 {
2234 if (0 != (GNUNET_SCHEDULER_ET_IN & pos->et))
2235 {
2236 GNUNET_NETWORK_fdset_set_native (rs, pos->fdi->sock);
2237 }
2238 if (0 != (GNUNET_SCHEDULER_ET_OUT & pos->et))
2239 {
2240 GNUNET_NETWORK_fdset_set_native (ws, pos->fdi->sock);
2241 }
2242 }
2243 if (NULL == scheduler_select)
2244 {
2245 select_result = GNUNET_NETWORK_socket_select (rs,
2246 ws,
2247 NULL,
2248 context->timeout);
2249 }
2250 else
2251 {
2252 select_result = scheduler_select (scheduler_select_cls,
2253 rs,
2254 ws,
2255 NULL,
2256 context->timeout);
2257 }
2258 if (select_result == GNUNET_SYSERR)
2259 {
2260 if (errno == EINTR)
2261 continue;
2262
2263 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "select");
2264#ifndef MINGW
2265#if USE_LSOF
2266 char lsof[512];
2267
2268 snprintf (lsof, sizeof (lsof), "lsof -p %d", getpid ());
2269 (void) close (1);
2270 (void) dup2 (2, 1);
2271 if (0 != system (lsof))
2272 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
2273 "system");
2274#endif
2275#endif
2276#if DEBUG_FDS
2277 struct Scheduled *s;
2278 for (s = context->scheduled_head; NULL != s; s = s->next)
2279 {
2280 int flags = fcntl (s->fdi->sock, F_GETFD);
2281 if ((flags == -1) && (errno == EBADF))
2282 {
2283 LOG (GNUNET_ERROR_TYPE_ERROR,
2284 "Got invalid file descriptor %d!\n",
2285 s->fdi->sock);
2286 }
2287 }
2288#endif
2289 GNUNET_assert (0);
2290 GNUNET_NETWORK_fdset_destroy (rs);
2291 GNUNET_NETWORK_fdset_destroy (ws);
2292 return GNUNET_SYSERR;
2293 }
2294 for (pos = context->scheduled_head; NULL != pos; pos = pos->next)
2295 {
2296 int is_ready = GNUNET_NO;
2297 if (0 != (GNUNET_SCHEDULER_ET_IN & pos->et) &&
2298 GNUNET_YES == GNUNET_NETWORK_fdset_test_native (rs, pos->fdi->sock))
2299 {
2300 pos->fdi->et |= GNUNET_SCHEDULER_ET_IN;
2301 is_ready = GNUNET_YES;
2302 }
2303 if (0 != (GNUNET_SCHEDULER_ET_OUT & pos->et) &&
2304 GNUNET_YES == GNUNET_NETWORK_fdset_test_native (ws, pos->fdi->sock))
2305 {
2306 pos->fdi->et |= GNUNET_SCHEDULER_ET_OUT;
2307 is_ready = GNUNET_YES;
2308 }
2309 if (GNUNET_YES == is_ready)
2310 {
2311 GNUNET_SCHEDULER_task_ready (pos->task, pos->fdi);
2312 }
2313 }
2314 tasks_ready = GNUNET_SCHEDULER_run_from_driver (sh);
2315 GNUNET_assert (GNUNET_SYSERR != tasks_ready);
2316 }
2317 GNUNET_NETWORK_fdset_destroy (rs);
2318 GNUNET_NETWORK_fdset_destroy (ws);
2319 return GNUNET_OK;
2320}
2321
2322
2323void
2324select_set_wakeup(void *cls,
2325 struct GNUNET_TIME_Absolute dt)
2326{
2327 struct DriverContext *context = cls;
2328 GNUNET_assert (NULL != context);
2329
2330 context->timeout = GNUNET_TIME_absolute_get_remaining (dt);
2331}
2332
2333
2080/** 2334/**
2081 * Obtain the driver for using select() as the event loop. 2335 * Obtain the driver for using select() as the event loop.
2082 * 2336 *
2083 * @return NULL on error 2337 * @return NULL on error
2084 */ 2338 */
2085const struct GNUNET_SCHEDULER_Driver * 2339struct GNUNET_SCHEDULER_Driver *
2086GNUNET_SCHEDULER_driver_select () 2340GNUNET_SCHEDULER_driver_select ()
2087{ 2341{
2088 GNUNET_break (0); // not implemented 2342 struct GNUNET_SCHEDULER_Driver *select_driver;
2089 return NULL; 2343 select_driver = GNUNET_new (struct GNUNET_SCHEDULER_Driver);
2344
2345 select_driver->loop = &select_loop;
2346 select_driver->add = &select_add;
2347 select_driver->del = &select_del;
2348 select_driver->set_wakeup = &select_set_wakeup;
2349
2350 return select_driver;
2090} 2351}
2091 2352
2092 2353
diff --git a/src/util/service.c b/src/util/service.c
index fcdf45a51..1156093f4 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -1932,6 +1932,11 @@ do_send (void *cls)
1932 size_t left; 1932 size_t left;
1933 const char *buf; 1933 const char *buf;
1934 1934
1935 LOG (GNUNET_ERROR_TYPE_DEBUG,
1936 "service: sending message with type %u",
1937 ntohs(client->msg->type));
1938
1939
1935 client->send_task = NULL; 1940 client->send_task = NULL;
1936 buf = (const char *) client->msg; 1941 buf = (const char *) client->msg;
1937 left = ntohs (client->msg->size) - client->msg_pos; 1942 left = ntohs (client->msg->size) - client->msg_pos;
@@ -1941,6 +1946,8 @@ do_send (void *cls)
1941 GNUNET_assert (ret <= (ssize_t) left); 1946 GNUNET_assert (ret <= (ssize_t) left);
1942 if (0 == ret) 1947 if (0 == ret)
1943 { 1948 {
1949 LOG (GNUNET_ERROR_TYPE_DEBUG,
1950 "no data send");
1944 GNUNET_MQ_inject_error (client->mq, 1951 GNUNET_MQ_inject_error (client->mq,
1945 GNUNET_MQ_ERROR_WRITE); 1952 GNUNET_MQ_ERROR_WRITE);
1946 return; 1953 return;
@@ -1958,6 +1965,9 @@ do_send (void *cls)
1958 if (EPIPE != errno) 1965 if (EPIPE != errno)
1959 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 1966 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
1960 "send"); 1967 "send");
1968 LOG (GNUNET_ERROR_TYPE_DEBUG,
1969 "socket send returned with error code %i",
1970 errno);
1961 GNUNET_MQ_inject_error (client->mq, 1971 GNUNET_MQ_inject_error (client->mq,
1962 GNUNET_MQ_ERROR_WRITE); 1972 GNUNET_MQ_ERROR_WRITE);
1963 return; 1973 return;
@@ -1968,7 +1978,7 @@ do_send (void *cls)
1968 GNUNET_MQ_impl_send_in_flight (client->mq); 1978 GNUNET_MQ_impl_send_in_flight (client->mq);
1969 } 1979 }
1970 client->msg_pos += ret; 1980 client->msg_pos += ret;
1971 if (left > ret) 1981 if (left > (size_t) ret)
1972 { 1982 {
1973 GNUNET_assert (NULL == client->drop_task); 1983 GNUNET_assert (NULL == client->drop_task);
1974 client->send_task 1984 client->send_task
@@ -1997,6 +2007,7 @@ service_mq_send (struct GNUNET_MQ_Handle *mq,
1997{ 2007{
1998 struct GNUNET_SERVICE_Client *client = impl_state; 2008 struct GNUNET_SERVICE_Client *client = impl_state;
1999 2009
2010 (void) mq;
2000 if (NULL != client->drop_task) 2011 if (NULL != client->drop_task)
2001 return; /* we're going down right now, do not try to send */ 2012 return; /* we're going down right now, do not try to send */
2002 GNUNET_assert (NULL == client->send_task); 2013 GNUNET_assert (NULL == client->send_task);
@@ -2026,6 +2037,7 @@ service_mq_cancel (struct GNUNET_MQ_Handle *mq,
2026{ 2037{
2027 struct GNUNET_SERVICE_Client *client = impl_state; 2038 struct GNUNET_SERVICE_Client *client = impl_state;
2028 2039
2040 (void) mq;
2029 GNUNET_assert (0 == client->msg_pos); 2041 GNUNET_assert (0 == client->msg_pos);
2030 client->msg = NULL; 2042 client->msg = NULL;
2031 GNUNET_SCHEDULER_cancel (client->send_task); 2043 GNUNET_SCHEDULER_cancel (client->send_task);
@@ -2402,7 +2414,7 @@ resume_client_receive (void *cls)
2402 GNUNET_YES); 2414 GNUNET_YES);
2403 if (GNUNET_SYSERR == ret) 2415 if (GNUNET_SYSERR == ret)
2404 { 2416 {
2405 if (NULL != c->drop_task) 2417 if (NULL == c->drop_task)
2406 GNUNET_SERVICE_client_drop (c); 2418 GNUNET_SERVICE_client_drop (c);
2407 return; 2419 return;
2408 } 2420 }
@@ -2431,6 +2443,7 @@ resume_client_receive (void *cls)
2431void 2443void
2432GNUNET_SERVICE_client_continue (struct GNUNET_SERVICE_Client *c) 2444GNUNET_SERVICE_client_continue (struct GNUNET_SERVICE_Client *c)
2433{ 2445{
2446 GNUNET_assert (NULL == c->drop_task);
2434 GNUNET_assert (GNUNET_YES == c->needs_continue); 2447 GNUNET_assert (GNUNET_YES == c->needs_continue);
2435 GNUNET_assert (NULL == c->recv_task); 2448 GNUNET_assert (NULL == c->recv_task);
2436 c->needs_continue = GNUNET_NO; 2449 c->needs_continue = GNUNET_NO;
@@ -2513,6 +2526,24 @@ GNUNET_SERVICE_client_drop (struct GNUNET_SERVICE_Client *c)
2513{ 2526{
2514 struct GNUNET_SERVICE_Handle *sh = c->sh; 2527 struct GNUNET_SERVICE_Handle *sh = c->sh;
2515 2528
2529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2530 "Client dropped: %p (MQ: %p)\n",
2531 c,
2532 c->mq);
2533
2534#if EXECINFO
2535 void *backtrace_array[MAX_TRACE_DEPTH];
2536 int num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
2537 char **backtrace_strings =
2538 backtrace_symbols (backtrace_array,
2539 t->num_backtrace_strings);
2540 for (unsigned int i = 0; i < num_backtrace_strings; i++)
2541 LOG (GNUNET_ERROR_TYPE_DEBUG,
2542 "client drop trace %u: %s\n",
2543 i,
2544 backtrace_strings[i]);
2545#endif
2546
2516 if (NULL != c->drop_task) 2547 if (NULL != c->drop_task)
2517 { 2548 {
2518 /* asked to drop twice! */ 2549 /* asked to drop twice! */
diff --git a/src/util/speedup.c b/src/util/speedup.c
index c6a4cf678..f5e81f16b 100644
--- a/src/util/speedup.c
+++ b/src/util/speedup.c
@@ -42,6 +42,7 @@ do_speedup (void *cls)
42{ 42{
43 static long long current_offset; 43 static long long current_offset;
44 44
45 (void) cls;
45 speedup_task = NULL; 46 speedup_task = NULL;
46 current_offset += delta.rel_value_us; 47 current_offset += delta.rel_value_us;
47 GNUNET_TIME_set_offset (current_offset); 48 GNUNET_TIME_set_offset (current_offset);
diff --git a/src/util/strings.c b/src/util/strings.c
index f554a9e83..4cfcd63b3 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -1069,11 +1069,13 @@ GNUNET_STRINGS_string_to_data (const char *enc, size_t enclen,
1069 * (if they weren't NULL). 1069 * (if they weren't NULL).
1070 */ 1070 */
1071int 1071int
1072GNUNET_STRINGS_parse_uri (const char *path, char **scheme_part, 1072GNUNET_STRINGS_parse_uri (const char *path,
1073 const char **path_part) 1073 char **scheme_part,
1074 const char **path_part)
1074{ 1075{
1075 size_t len; 1076 size_t len;
1076 int i, end; 1077 size_t i;
1078 int end;
1077 int pp_state = 0; 1079 int pp_state = 0;
1078 const char *post_scheme_part = NULL; 1080 const char *post_scheme_part = NULL;
1079 len = strlen (path); 1081 len = strlen (path);
@@ -1082,7 +1084,7 @@ GNUNET_STRINGS_parse_uri (const char *path, char **scheme_part,
1082 switch (pp_state) 1084 switch (pp_state)
1083 { 1085 {
1084 case 0: 1086 case 0:
1085 if (path[i] == ':' && i > 0) 1087 if ( (path[i] == ':') && (i > 0) )
1086 { 1088 {
1087 pp_state += 1; 1089 pp_state += 1;
1088 continue; 1090 continue;
diff --git a/src/util/test_service.c b/src/util/test_service.c
index 1567c97ce..424a445bb 100644
--- a/src/util/test_service.c
+++ b/src/util/test_service.c
@@ -30,10 +30,17 @@
30 */ 30 */
31#define MY_TYPE 256 31#define MY_TYPE 256
32 32
33#define TIMEOUT GNUNET_TIME_UNIT_SECONDS
34
33static int global_ret = 1; 35static int global_ret = 1;
34 36
35static struct GNUNET_MQ_Handle *mq; 37static struct GNUNET_MQ_Handle *mq;
36 38
39/**
40 * Timeout task.
41 */
42static struct GNUNET_SCHEDULER_Task *tt;
43
37 44
38static void 45static void
39handle_recv (void *cls, 46handle_recv (void *cls,
@@ -45,8 +52,11 @@ handle_recv (void *cls,
45 "Received client message...\n"); 52 "Received client message...\n");
46 GNUNET_SERVICE_client_continue (client); 53 GNUNET_SERVICE_client_continue (client);
47 global_ret = 2; 54 global_ret = 2;
48 GNUNET_MQ_destroy (mq); 55 if (NULL != mq)
49 mq = NULL; 56 {
57 GNUNET_MQ_destroy (mq);
58 mq = NULL;
59 }
50} 60}
51 61
52 62
@@ -86,10 +96,29 @@ disconnect_cb (void *cls,
86 { 96 {
87 GNUNET_SCHEDULER_shutdown (); 97 GNUNET_SCHEDULER_shutdown ();
88 global_ret = 0; 98 global_ret = 0;
99 if (NULL != tt)
100 {
101 GNUNET_SCHEDULER_cancel (tt);
102 tt = NULL;
103 }
89 } 104 }
90} 105}
91 106
92 107
108static void
109timeout_task (void *cls)
110{
111 tt = NULL;
112 if (NULL != mq)
113 {
114 GNUNET_MQ_destroy (mq);
115 mq = NULL;
116 }
117 global_ret = 33;
118 GNUNET_SCHEDULER_shutdown ();
119}
120
121
93/** 122/**
94 * Initialization function of the service. Starts 123 * Initialization function of the service. Starts
95 * a client to connect to the service. 124 * a client to connect to the service.
@@ -106,7 +135,11 @@ service_init (void *cls,
106 const char *service_name = cls; 135 const char *service_name = cls;
107 struct GNUNET_MQ_Envelope *env; 136 struct GNUNET_MQ_Envelope *env;
108 struct GNUNET_MessageHeader *msg; 137 struct GNUNET_MessageHeader *msg;
109 138
139 GNUNET_assert (NULL == tt);
140 tt = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
141 &timeout_task,
142 NULL);
110 mq = GNUNET_CLIENT_connect (cfg, 143 mq = GNUNET_CLIENT_connect (cfg,
111 service_name, 144 service_name,
112 NULL, 145 NULL,
diff --git a/src/util/time.c b/src/util/time.c
index 19100ac36..5ffb19ec1 100644
--- a/src/util/time.c
+++ b/src/util/time.c
@@ -693,7 +693,7 @@ GNUNET_TIME_year_to_time (unsigned int year)
693 } 693 }
694 t.tm_year = year - 1900; 694 t.tm_year = year - 1900;
695 t.tm_mday = 1; 695 t.tm_mday = 1;
696 t.tm_mon = 1; 696 t.tm_mon = 0;
697 t.tm_wday = 1; 697 t.tm_wday = 1;
698 t.tm_yday = 1; 698 t.tm_yday = 1;
699 tp = mktime (&t); 699 tp = mktime (&t);
diff --git a/src/vpn/gnunet-helper-vpn.c b/src/vpn/gnunet-helper-vpn.c
index 4ed4e079e..26f77d2fc 100644
--- a/src/vpn/gnunet-helper-vpn.c
+++ b/src/vpn/gnunet-helper-vpn.c
@@ -649,6 +649,7 @@ main (int argc, char **argv)
649 { 649 {
650 fprintf (stderr, 650 fprintf (stderr,
651 "Fatal: prefix_len out of range\n"); 651 "Fatal: prefix_len out of range\n");
652 close (fd_tun);
652 return 1; 653 return 1;
653 } 654 }
654 655
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c
index d9daaa7e2..bdc638176 100644
--- a/src/vpn/gnunet-service-vpn.c
+++ b/src/vpn/gnunet-service-vpn.c
@@ -2218,6 +2218,9 @@ route_packet (struct DestinationEntry *destination,
2218 * 2218 *
2219 * @param cls closure, NULL 2219 * @param cls closure, NULL
2220 * @param message message we got from the client (VPN channel interface) 2220 * @param message message we got from the client (VPN channel interface)
2221 * @return #GNUNET_OK on success,
2222 * #GNUNET_NO to stop further processing (no error)
2223 * #GNUNET_SYSERR to stop further processing with error
2221 */ 2224 */
2222static int 2225static int
2223message_token (void *cls, 2226message_token (void *cls,