aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gns/gnunet-gns-proxy.c4
-rw-r--r--src/include/gnunet_namestore_service.h2
-rw-r--r--src/namestore/Makefile.am16
-rw-r--r--src/namestore/namestore_api.c20
-rw-r--r--src/namestore/test_namestore_api_zone_to_name.c212
-rw-r--r--src/rps/Makefile.am4
-rw-r--r--src/rps/gnunet-service-rps.c21
-rw-r--r--src/rps/test_rps.c204
-rw-r--r--src/util/scheduler.c60
9 files changed, 415 insertions, 128 deletions
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index 25092dcf0..591dff04f 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -1150,8 +1150,8 @@ curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls)
1150 hdr_type, 1150 hdr_type,
1151 hdr_val); 1151 hdr_val);
1152 header = GNUNET_new (struct HttpResponseHeader); 1152 header = GNUNET_new (struct HttpResponseHeader);
1153 header->type = GNUNET_strndup (hdr_type, strlen (hdr_type)); 1153 header->type = GNUNET_strdup (hdr_type);
1154 header->value = GNUNET_strndup (hdr_val, strlen (hdr_val)); 1154 header->value = GNUNET_strdup (hdr_val);
1155 GNUNET_CONTAINER_DLL_insert (s5r->header_head, 1155 GNUNET_CONTAINER_DLL_insert (s5r->header_head,
1156 s5r->header_tail, 1156 s5r->header_tail,
1157 header); 1157 header);
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h
index 0add8852a..6d3c07f1d 100644
--- a/src/include/gnunet_namestore_service.h
+++ b/src/include/gnunet_namestore_service.h
@@ -193,7 +193,7 @@ GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
193 * Returns at most one result to the processor. 193 * Returns at most one result to the processor.
194 * 194 *
195 * @param h handle to the namestore 195 * @param h handle to the namestore
196 * @param zone public key of the zone to look up in, never NULL 196 * @param zone private key of the zone to look up in, never NULL
197 * @param value_zone public key of the target zone (value), never NULL 197 * @param value_zone public key of the target zone (value), never NULL
198 * @param error_cb function to call on error (i.e. disconnect) 198 * @param error_cb function to call on error (i.e. disconnect)
199 * the handle is afterwards invalid 199 * the handle is afterwards invalid
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index 4f710e116..a848d4b72 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -59,8 +59,8 @@ TESTING_TESTS = \
59 test_namestore_api_zone_iteration_specific_zone.nc \ 59 test_namestore_api_zone_iteration_specific_zone.nc \
60 test_namestore_api_zone_iteration_stop.nc \ 60 test_namestore_api_zone_iteration_stop.nc \
61 test_namestore_api_monitoring.nc \ 61 test_namestore_api_monitoring.nc \
62 test_namestore_api_monitoring_existing.nc 62 test_namestore_api_monitoring_existing.nc \
63# test_namestore_api_zone_to_name 63 test_namestore_api_zone_to_name
64endif 64endif
65 65
66# Declare .nc (NO-CONCURRENCY) as a test extension so that we can impart 66# Declare .nc (NO-CONCURRENCY) as a test extension so that we can impart
@@ -298,12 +298,12 @@ test_namestore_api_remove_not_existing_record_nc_LDADD = \
298 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 298 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
299 libgnunetnamestore.la 299 libgnunetnamestore.la
300 300
301#test_namestore_api_zone_to_name_SOURCES = \ 301test_namestore_api_zone_to_name_SOURCES = \
302# test_namestore_api_zone_to_name.c 302 test_namestore_api_zone_to_name.c
303#test_namestore_api_zone_to_name_LDADD = \ 303test_namestore_api_zone_to_name_LDADD = \
304# $(top_builddir)/src/testing/libgnunettesting.la \ 304 $(top_builddir)/src/testing/libgnunettesting.la \
305# $(top_builddir)/src/util/libgnunetutil.la \ 305 $(top_builddir)/src/util/libgnunetutil.la \
306# libgnunetnamestore.la 306 libgnunetnamestore.la
307 307
308test_namestore_api_monitoring_nc_SOURCES = \ 308test_namestore_api_monitoring_nc_SOURCES = \
309 test_namestore_api_monitoring.c 309 test_namestore_api_monitoring.c
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index 92068cc01..a187bd250 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -405,6 +405,7 @@ check_lookup_result (void *cls,
405 size_t name_len; 405 size_t name_len;
406 size_t rd_len; 406 size_t rd_len;
407 407
408 (void) cls;
408 rd_len = ntohs (msg->rd_len); 409 rd_len = ntohs (msg->rd_len);
409 msg_len = ntohs (msg->gns_header.header.size); 410 msg_len = ntohs (msg->gns_header.header.size);
410 name_len = ntohs (msg->name_len); 411 name_len = ntohs (msg->name_len);
@@ -517,6 +518,7 @@ check_record_result (void *cls,
517 size_t name_len; 518 size_t name_len;
518 size_t rd_len; 519 size_t rd_len;
519 520
521 (void) cls;
520 rd_len = ntohs (msg->rd_len); 522 rd_len = ntohs (msg->rd_len);
521 msg_len = ntohs (msg->gns_header.header.size); 523 msg_len = ntohs (msg->gns_header.header.size);
522 name_len = ntohs (msg->name_len); 524 name_len = ntohs (msg->name_len);
@@ -656,6 +658,7 @@ check_zone_to_name_response (void *cls,
656 size_t rd_ser_len; 658 size_t rd_ser_len;
657 const char *name_tmp; 659 const char *name_tmp;
658 660
661 (void) cls;
659 if (GNUNET_OK != ntohs (msg->res)) 662 if (GNUNET_OK != ntohs (msg->res))
660 return GNUNET_OK; 663 return GNUNET_OK;
661 name_len = ntohs (msg->name_len); 664 name_len = ntohs (msg->name_len);
@@ -771,6 +774,7 @@ mq_error_handler (void *cls,
771{ 774{
772 struct GNUNET_NAMESTORE_Handle *h = cls; 775 struct GNUNET_NAMESTORE_Handle *h = cls;
773 776
777 (void) error;
774 force_reconnect (h); 778 force_reconnect (h);
775} 779}
776 780
@@ -994,6 +998,7 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
994 size_t name_len; 998 size_t name_len;
995 uint32_t rid; 999 uint32_t rid;
996 struct RecordStoreMessage *msg; 1000 struct RecordStoreMessage *msg;
1001 ssize_t sret;
997 1002
998 name_len = strlen (label) + 1; 1003 name_len = strlen (label) + 1;
999 if (name_len > MAX_NAME_LEN) 1004 if (name_len > MAX_NAME_LEN)
@@ -1029,11 +1034,16 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
1029 label, 1034 label,
1030 name_len); 1035 name_len);
1031 rd_ser = &name_tmp[name_len]; 1036 rd_ser = &name_tmp[name_len];
1032 GNUNET_assert (rd_ser_len == 1037 sret = GNUNET_GNSRECORD_records_serialize (rd_count,
1033 GNUNET_GNSRECORD_records_serialize (rd_count, 1038 rd,
1034 rd, 1039 rd_ser_len,
1035 rd_ser_len, 1040 rd_ser);
1036 rd_ser)); 1041 if (0 > sret)
1042 {
1043 GNUNET_free (env);
1044 return NULL;
1045 }
1046 GNUNET_assert (rd_ser_len == (size_t) sret);
1037 LOG (GNUNET_ERROR_TYPE_DEBUG, 1047 LOG (GNUNET_ERROR_TYPE_DEBUG,
1038 "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n", 1048 "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n",
1039 label, 1049 label,
diff --git a/src/namestore/test_namestore_api_zone_to_name.c b/src/namestore/test_namestore_api_zone_to_name.c
index ca33ee280..2bc7d34a3 100644
--- a/src/namestore/test_namestore_api_zone_to_name.c
+++ b/src/namestore/test_namestore_api_zone_to_name.c
@@ -37,28 +37,25 @@
37#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 37#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100)
38 38
39 39
40static struct GNUNET_NAMESTORE_Handle * nsh; 40static struct GNUNET_NAMESTORE_Handle *nsh;
41 41
42static struct GNUNET_SCHEDULER_Task * endbadly_task; 42static struct GNUNET_SCHEDULER_Task *endbadly_task;
43 43
44static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey; 44static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
45 45
46static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; 46static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
47 47
48static struct GNUNET_TIME_Absolute expire; 48static struct GNUNET_CRYPTO_EcdsaPublicKey s_zone_value;
49
50static struct GNUNET_CRYPTO_ShortHashCode s_zone;
51
52static struct GNUNET_CRYPTO_ShortHashCode s_zone_value;
53 49
54static char * s_name; 50static char * s_name;
55 51
56static struct GNUNET_CRYPTO_EcdsaSignature *s_signature;
57
58static int res; 52static int res;
59 53
60static char *directory; 54static char *directory;
61 55
56static struct GNUNET_NAMESTORE_QueueEntry *qe;
57
58
62/** 59/**
63 * Re-establish the connection to the service. 60 * Re-establish the connection to the service.
64 * 61 *
@@ -67,12 +64,8 @@ static char *directory;
67static void 64static void
68endbadly (void *cls) 65endbadly (void *cls)
69{ 66{
70 if (nsh != NULL) 67 (void) cls;
71 GNUNET_NAMESTORE_disconnect (nsh); 68 GNUNET_SCHEDULER_shutdown ();
72 nsh = NULL;
73 if (privkey != NULL)
74 GNUNET_free (privkey);
75 privkey = NULL;
76 res = 1; 69 res = 1;
77} 70}
78 71
@@ -80,50 +73,69 @@ endbadly (void *cls)
80static void 73static void
81end (void *cls) 74end (void *cls)
82{ 75{
83 if (endbadly_task != NULL) 76 if (NULL != qe)
77 {
78 GNUNET_NAMESTORE_cancel (qe);
79 qe = NULL;
80 }
81 if (NULL != endbadly_task)
84 { 82 {
85 GNUNET_SCHEDULER_cancel (endbadly_task); 83 GNUNET_SCHEDULER_cancel (endbadly_task);
86 endbadly_task = NULL; 84 endbadly_task = NULL;
87 } 85 }
88 if (privkey != NULL) 86 if (NULL != privkey)
87 {
89 GNUNET_free (privkey); 88 GNUNET_free (privkey);
90 privkey = NULL; 89 privkey = NULL;
91 if (nsh != NULL) 90 }
91 if (NULL != nsh)
92 {
92 GNUNET_NAMESTORE_disconnect (nsh); 93 GNUNET_NAMESTORE_disconnect (nsh);
93 nsh = NULL; 94 nsh = NULL;
95 }
94} 96}
95 97
96 98
97static void 99static void
98zone_to_name_proc (void *cls, 100zone_to_name_proc (void *cls,
99 const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key, 101 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
100 struct GNUNET_TIME_Absolute expire,
101 const char *n, 102 const char *n,
102 unsigned int rd_count, 103 unsigned int rd_count,
103 const struct GNUNET_GNSRECORD_Data *rd, 104 const struct GNUNET_GNSRECORD_Data *rd)
104 const struct GNUNET_CRYPTO_EcdsaSignature *signature)
105{ 105{
106 int fail = GNUNET_NO; 106 int fail = GNUNET_NO;
107 107
108 if ((zone_key == NULL) && (n == NULL) && (rd_count == 0) && (rd == NULL) && (signature == NULL)) 108 qe = NULL;
109 if ( (NULL == zone_key) &&
110 (NULL == n) &&
111 (0 == rd_count) &&
112 (NULL == rd) )
109 { 113 {
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No result found\n"); 114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
115 "No result found\n");
111 res = 1; 116 res = 1;
112 } 117 }
113 else 118 else
114 { 119 {
115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result found: `%s'\n", n); 120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
116 if ((n == NULL) || (0 != strcmp(n, s_name))) 121 "Result found: `%s'\n",
122 n);
123 if ( (NULL == n) ||
124 (0 != strcmp (n,
125 s_name)))
117 { 126 {
118 fail = GNUNET_YES; 127 fail = GNUNET_YES;
119 GNUNET_break (0); 128 GNUNET_break (0);
120 } 129 }
121 if (rd_count != 1) 130 if (1 != rd_count)
122 { 131 {
123 fail = GNUNET_YES; 132 fail = GNUNET_YES;
124 GNUNET_break (0); 133 GNUNET_break (0);
125 } 134 }
126 if ((zone_key == NULL) || (0 != memcmp (zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))) 135 if ( (NULL == zone_key) ||
136 (0 != memcmp (zone_key,
137 privkey,
138 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))))
127 { 139 {
128 fail = GNUNET_YES; 140 fail = GNUNET_YES;
129 GNUNET_break (0); 141 GNUNET_break (0);
@@ -133,29 +145,54 @@ zone_to_name_proc (void *cls,
133 else 145 else
134 res = 1; 146 res = 1;
135 } 147 }
136 GNUNET_SCHEDULER_add_now(&end, NULL); 148 GNUNET_SCHEDULER_add_now (&end,
149 NULL);
137} 150}
138 151
139 152
140static void 153static void
141put_cont (void *cls, int32_t success, const char *emsg) 154error_cb (void *cls)
155{
156 (void) cls;
157 qe = NULL;
158 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
159 "Not found!\n");
160 GNUNET_SCHEDULER_shutdown ();
161 res = 2;
162}
163
164
165static void
166put_cont (void *cls,
167 int32_t success,
168 const char *emsg)
142{ 169{
143 char *name = cls; 170 char *name = cls;
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 171
172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
173 "Name store added record for `%s': %s\n",
174 name,
175 (success == GNUNET_OK) ? "SUCCESS" : emsg);
145 if (success == GNUNET_OK) 176 if (success == GNUNET_OK)
146 { 177 {
147 res = 0; 178 res = 0;
148 179
149 /* create initial record */ 180 qe = GNUNET_NAMESTORE_zone_to_name (nsh,
150 GNUNET_NAMESTORE_zone_to_name (nsh, &s_zone, &s_zone_value, zone_to_name_proc, NULL); 181 privkey,
151 182 &s_zone_value,
183 &error_cb,
184 NULL,
185 &zone_to_name_proc,
186 NULL);
152 } 187 }
153 else 188 else
154 { 189 {
155 res = 1; 190 res = 1;
156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 191 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
157 "Failed to put records for name `%s'\n", name); 192 "Failed to put records for name `%s'\n",
158 GNUNET_SCHEDULER_add_now(&end, NULL); 193 name);
194 GNUNET_SCHEDULER_add_now (&end,
195 NULL);
159 } 196 }
160} 197}
161 198
@@ -165,57 +202,72 @@ run (void *cls,
165 const struct GNUNET_CONFIGURATION_Handle *cfg, 202 const struct GNUNET_CONFIGURATION_Handle *cfg,
166 struct GNUNET_TESTING_Peer *peer) 203 struct GNUNET_TESTING_Peer *peer)
167{ 204{
168 struct GNUNET_TIME_Absolute et; 205 (void) cls;
169 206 (void) peer;
170 directory = NULL; 207 directory = NULL;
171 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory); 208 GNUNET_assert (GNUNET_OK ==
209 GNUNET_CONFIGURATION_get_value_string (cfg,
210 "PATHS",
211 "GNUNET_TEST_HOME",
212 &directory));
172 GNUNET_DISK_directory_remove (directory); 213 GNUNET_DISK_directory_remove (directory);
173 214
174 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); 215 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
216 &endbadly,
217 NULL);
218 GNUNET_SCHEDULER_add_shutdown (&end,
219 NULL);
175 GNUNET_asprintf (&s_name, "dummy"); 220 GNUNET_asprintf (&s_name, "dummy");
176 /* load privat key */ 221 /* load privat key */
177 char *hostkey_file; 222 {
178 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, 223 char *zonekey_file;
179 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); 224
180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 225 GNUNET_asprintf (&zonekey_file,
181 "Using zonekey file `%s'\n", 226 "zonefiles%s%s",
182 hostkey_file); 227 DIR_SEPARATOR_STR,
183 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); 228 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
184 GNUNET_free (hostkey_file); 229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
185 GNUNET_assert (privkey != NULL); 230 "Using zonekey file `%s'\n",
231 zonekey_file);
232 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (zonekey_file);
233 GNUNET_free (zonekey_file);
234 }
235 GNUNET_assert (NULL != privkey);
186 /* get public key */ 236 /* get public key */
187 GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey); 237 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
238 &pubkey);
188 239
189 /* zone hash */ 240 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
190 GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), &s_zone); 241 &s_zone_value,
191 GNUNET_CRYPTO_short_hash (s_name, strlen (s_name) + 1, &s_zone_value); 242 sizeof (s_zone_value));
192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 243 {
193 "Using PKEY `%s' \n", 244 struct GNUNET_GNSRECORD_Data rd;
194 GNUNET_NAMESTORE_short_h2s (&s_zone_value)); 245
195 246 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us;
196 struct GNUNET_GNSRECORD_Data rd; 247 rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY;
197 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us; 248 rd.data_size = sizeof (s_zone_value);
198 rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; 249 rd.data = &s_zone_value;
199 rd.data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode); 250 rd.flags = 0;
200 rd.data = GNUNET_malloc(sizeof (struct GNUNET_CRYPTO_ShortHashCode)); 251
201 rd.flags = 0; 252 nsh = GNUNET_NAMESTORE_connect (cfg);
202 GNUNET_memcpy ((char *) rd.data, &s_zone_value, sizeof (struct GNUNET_CRYPTO_ShortHashCode)); 253 GNUNET_break (NULL != nsh);
203 nsh = GNUNET_NAMESTORE_connect (cfg); 254 GNUNET_NAMESTORE_records_store (nsh,
204 GNUNET_break (NULL != nsh); 255 privkey,
205 256 s_name,
206 expire = GNUNET_TIME_absolute_get (); 257 1,
207 et.abs_value_us = rd.expiration_time; 258 &rd,
208 s_signature = GNUNET_NAMESTORE_create_signature(privkey, et, s_name, &rd, 1); 259 &put_cont,
209 GNUNET_NAMESTORE_record_put(nsh, &pubkey, s_name, expire, 1, &rd, s_signature, put_cont, NULL); 260 NULL);
210 261 }
211 GNUNET_free ((void *) rd.data);
212} 262}
213 263
214 264
215
216int 265int
217main (int argc, char *argv[]) 266main (int argc,
267 char *argv[])
218{ 268{
269 (void) argc;
270 (void) argv;
219 res = 1; 271 res = 1;
220 if (0 != 272 if (0 !=
221 GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name", 273 GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name",
@@ -227,8 +279,8 @@ main (int argc, char *argv[])
227 } 279 }
228 if (NULL != directory) 280 if (NULL != directory)
229 { 281 {
230 GNUNET_DISK_directory_remove (directory); 282 GNUNET_DISK_directory_remove (directory);
231 GNUNET_free (directory); 283 GNUNET_free (directory);
232 } 284 }
233 return res; 285 return res;
234} 286}
diff --git a/src/rps/Makefile.am b/src/rps/Makefile.am
index de3469254..b5f712268 100644
--- a/src/rps/Makefile.am
+++ b/src/rps/Makefile.am
@@ -141,7 +141,9 @@ test_rps_churn_SOURCES = $(rps_test_src)
141test_rps_churn_LDADD = $(ld_rps_test_lib) 141test_rps_churn_LDADD = $(ld_rps_test_lib)
142 142
143gnunet_rps_profiler_SOURCES = $(rps_test_src) 143gnunet_rps_profiler_SOURCES = $(rps_test_src)
144gnunet_rps_profiler_LDADD = $(ld_rps_test_lib) 144gnunet_rps_profiler_LDADD = \
145 $(top_builddir)/src/statistics/libgnunetstatistics.la \
146 $(ld_rps_test_lib)
145 147
146EXTRA_DIST = \ 148EXTRA_DIST = \
147 test_rps.conf 149 test_rps.conf
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index ec70075cf..877893ee8 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -29,6 +29,7 @@
29#include "gnunet_cadet_service.h" 29#include "gnunet_cadet_service.h"
30#include "gnunet_peerinfo_service.h" 30#include "gnunet_peerinfo_service.h"
31#include "gnunet_nse_service.h" 31#include "gnunet_nse_service.h"
32#include "gnunet_statistics_service.h"
32#include "rps.h" 33#include "rps.h"
33#include "rps-test_util.h" 34#include "rps-test_util.h"
34#include "gnunet-service-rps_sampler.h" 35#include "gnunet-service-rps_sampler.h"
@@ -60,6 +61,11 @@
60static const struct GNUNET_CONFIGURATION_Handle *cfg; 61static const struct GNUNET_CONFIGURATION_Handle *cfg;
61 62
62/** 63/**
64 * Handle to the statistics service.
65 */
66static struct GNUNET_STATISTICS_Handle *stats;
67
68/**
63 * Our own identity. 69 * Our own identity.
64 */ 70 */
65static struct GNUNET_PeerIdentity own_identity; 71static struct GNUNET_PeerIdentity own_identity;
@@ -2390,6 +2396,7 @@ send_pull_reply (const struct GNUNET_PeerIdentity *peer_id,
2390 send_size * sizeof (struct GNUNET_PeerIdentity)); 2396 send_size * sizeof (struct GNUNET_PeerIdentity));
2391 2397
2392 Peers_send_message (peer_id, ev, "PULL REPLY"); 2398 Peers_send_message (peer_id, ev, "PULL REPLY");
2399 GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO);
2393} 2400}
2394 2401
2395 2402
@@ -2961,6 +2968,7 @@ handle_peer_push (void *cls,
2961 LOG (GNUNET_ERROR_TYPE_DEBUG, 2968 LOG (GNUNET_ERROR_TYPE_DEBUG,
2962 "Received PUSH (%s)\n", 2969 "Received PUSH (%s)\n",
2963 GNUNET_i2s (peer)); 2970 GNUNET_i2s (peer));
2971 GNUNET_STATISTICS_update(stats, "# push messages received", 1, GNUNET_NO);
2964 2972
2965 #ifdef ENABLE_MALICIOUS 2973 #ifdef ENABLE_MALICIOUS
2966 struct AttackedPeer *tmp_att_peer; 2974 struct AttackedPeer *tmp_att_peer;
@@ -3013,6 +3021,7 @@ handle_peer_pull_request (void *cls,
3013 const struct GNUNET_PeerIdentity *view_array; 3021 const struct GNUNET_PeerIdentity *view_array;
3014 3022
3015 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (peer)); 3023 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (peer));
3024 GNUNET_STATISTICS_update(stats, "# pull request messages received", 1, GNUNET_NO);
3016 3025
3017 #ifdef ENABLE_MALICIOUS 3026 #ifdef ENABLE_MALICIOUS
3018 if (1 == mal_type 3027 if (1 == mal_type
@@ -3096,6 +3105,7 @@ handle_peer_pull_reply (void *cls,
3096#endif /* ENABLE_MALICIOUS */ 3105#endif /* ENABLE_MALICIOUS */
3097 3106
3098 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REPLY (%s)\n", GNUNET_i2s (sender)); 3107 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REPLY (%s)\n", GNUNET_i2s (sender));
3108 GNUNET_STATISTICS_update(stats, "# pull reply messages received", 1, GNUNET_NO);
3099 3109
3100 #ifdef ENABLE_MALICIOUS 3110 #ifdef ENABLE_MALICIOUS
3101 // We shouldn't even receive pull replies as we're not sending 3111 // We shouldn't even receive pull replies as we're not sending
@@ -3234,6 +3244,7 @@ send_pull_request (const struct GNUNET_PeerIdentity *peer)
3234 3244
3235 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); 3245 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST);
3236 Peers_send_message (peer, ev, "PULL REQUEST"); 3246 Peers_send_message (peer, ev, "PULL REQUEST");
3247 GNUNET_STATISTICS_update(stats, "# pull request send issued", 1, GNUNET_NO);
3237} 3248}
3238 3249
3239 3250
@@ -3253,6 +3264,7 @@ send_push (const struct GNUNET_PeerIdentity *peer_id)
3253 3264
3254 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); 3265 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH);
3255 Peers_send_message (peer_id, ev, "PUSH"); 3266 Peers_send_message (peer_id, ev, "PUSH");
3267 GNUNET_STATISTICS_update(stats, "# push send issued", 1, GNUNET_NO);
3256} 3268}
3257 3269
3258 3270
@@ -3554,6 +3566,7 @@ do_round (void *cls)
3554 3566
3555 LOG (GNUNET_ERROR_TYPE_DEBUG, 3567 LOG (GNUNET_ERROR_TYPE_DEBUG,
3556 "Going to execute next round.\n"); 3568 "Going to execute next round.\n");
3569 GNUNET_STATISTICS_update(stats, "# rounds", 1, GNUNET_NO);
3557 do_round_task = NULL; 3570 do_round_task = NULL;
3558 LOG (GNUNET_ERROR_TYPE_DEBUG, 3571 LOG (GNUNET_ERROR_TYPE_DEBUG,
3559 "Printing view:\n"); 3572 "Printing view:\n");
@@ -3706,6 +3719,7 @@ do_round (void *cls)
3706 else 3719 else
3707 { 3720 {
3708 LOG (GNUNET_ERROR_TYPE_DEBUG, "No update of the view.\n"); 3721 LOG (GNUNET_ERROR_TYPE_DEBUG, "No update of the view.\n");
3722 GNUNET_STATISTICS_update(stats, "# rounds blocked", 1, GNUNET_NO);
3709 } 3723 }
3710 // TODO independent of that also get some peers from CADET_get_peers()? 3724 // TODO independent of that also get some peers from CADET_get_peers()?
3711 3725
@@ -3881,6 +3895,11 @@ shutdown_task (void *cls)
3881 View_destroy (); 3895 View_destroy ();
3882 CustomPeerMap_destroy (push_map); 3896 CustomPeerMap_destroy (push_map);
3883 CustomPeerMap_destroy (pull_map); 3897 CustomPeerMap_destroy (pull_map);
3898 if (NULL != stats)
3899 {
3900 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
3901 stats = NULL;
3902 }
3884 #ifdef ENABLE_MALICIOUS 3903 #ifdef ENABLE_MALICIOUS
3885 struct AttackedPeer *tmp_att_peer; 3904 struct AttackedPeer *tmp_att_peer;
3886 GNUNET_free (file_name_view_log); 3905 GNUNET_free (file_name_view_log);
@@ -4129,6 +4148,8 @@ run (void *cls,
4129 LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduled first round\n"); 4148 LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduled first round\n");
4130 4149
4131 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 4150 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
4151 stats = GNUNET_STATISTICS_create ("rps", cfg);
4152
4132} 4153}
4133 4154
4134 4155
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c
index 7d61ae6a1..c958194a8 100644
--- a/src/rps/test_rps.c
+++ b/src/rps/test_rps.c
@@ -41,6 +41,11 @@
41static uint32_t num_peers; 41static uint32_t num_peers;
42 42
43/** 43/**
44 * How many peers are ready to shutdown?
45 */
46static uint32_t num_shutdown_ready;
47
48/**
44 * How long do we run the test? 49 * How long do we run the test?
45 */ 50 */
46//#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 51//#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
@@ -236,6 +241,16 @@ struct RPSPeer
236 * Pending operation on that peer 241 * Pending operation on that peer
237 */ 242 */
238 const struct OpListEntry *entry_op_manage; 243 const struct OpListEntry *entry_op_manage;
244
245 /**
246 * Testbed operation to connect to statistics service
247 */
248 struct GNUNET_TESTBED_Operation *stat_op;
249
250 /**
251 * Handle to the statistics service
252 */
253 struct GNUNET_STATISTICS_Handle *stats_h;
239}; 254};
240 255
241 256
@@ -318,7 +333,7 @@ typedef void (*ReplyHandle) (void *cls,
318/** 333/**
319 * Called directly before disconnecting from the service 334 * Called directly before disconnecting from the service
320 */ 335 */
321typedef void (*PostTest) (void *cls, struct GNUNET_RPS_Handle *h); 336typedef void (*PostTest) (const struct RPSPeer *peer);
322 337
323/** 338/**
324 * Function called after disconnect to evaluate test success 339 * Function called after disconnect to evaluate test success
@@ -355,6 +370,21 @@ enum OPTION_QUICK_QUIT {
355}; 370};
356 371
357/** 372/**
373 * @brief Do we collect statistics at the end?
374 */
375enum OPTION_COLLECT_STATISTICS {
376 /**
377 * @brief We collect statistics at the end
378 */
379 COLLECT_STATISTICS,
380
381 /**
382 * @brief We do not collect statistics at the end
383 */
384 NO_COLLECT_STATISTICS,
385};
386
387/**
358 * Structure to define a single test 388 * Structure to define a single test
359 */ 389 */
360struct SingleTestRun 390struct SingleTestRun
@@ -413,6 +443,11 @@ struct SingleTestRun
413 * Quit test before timeout? 443 * Quit test before timeout?
414 */ 444 */
415 enum OPTION_QUICK_QUIT have_quick_quit; 445 enum OPTION_QUICK_QUIT have_quick_quit;
446
447 /**
448 * Collect statistics at the end?
449 */
450 enum OPTION_COLLECT_STATISTICS have_collect_statistics;
416} cur_test_run; 451} cur_test_run;
417 452
418/** 453/**
@@ -575,9 +610,21 @@ shutdown_op (void *cls)
575 churn_task = NULL; 610 churn_task = NULL;
576 } 611 }
577 for (i = 0; i < num_peers; i++) 612 for (i = 0; i < num_peers; i++)
613 {
578 if (NULL != rps_peers[i].op) 614 if (NULL != rps_peers[i].op)
579 GNUNET_TESTBED_operation_done (rps_peers[i].op); 615 GNUNET_TESTBED_operation_done (rps_peers[i].op);
580 GNUNET_SCHEDULER_shutdown (); 616 if (NULL != cur_test_run.post_test)
617 {
618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i);
619 cur_test_run.post_test (&rps_peers[i]);
620 }
621 }
622 /* If we do not collect statistics, shut down directly */
623 if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics ||
624 num_peers <= num_shutdown_ready)
625 {
626 GNUNET_SCHEDULER_shutdown ();
627 }
581} 628}
582 629
583 630
@@ -753,6 +800,76 @@ rps_connect_adapter (void *cls,
753 return h; 800 return h;
754} 801}
755 802
803/**
804 * Called to open a connection to the peer's statistics
805 *
806 * @param cls peer context
807 * @param cfg configuration of the peer to connect to; will be available until
808 * GNUNET_TESTBED_operation_done() is called on the operation returned
809 * from GNUNET_TESTBED_service_connect()
810 * @return service handle to return in 'op_result', NULL on error
811 */
812static void *
813stat_connect_adapter (void *cls,
814 const struct GNUNET_CONFIGURATION_Handle *cfg)
815{
816 struct RPSPeer *peer = cls;
817
818 peer->stats_h = GNUNET_STATISTICS_create ("rps-profiler", cfg);
819 return peer->stats_h;
820}
821
822/**
823 * Called to disconnect from peer's statistics service
824 *
825 * @param cls peer context
826 * @param op_result service handle returned from the connect adapter
827 */
828static void
829stat_disconnect_adapter (void *cls, void *op_result)
830{
831 struct RPSPeer *peer = cls;
832
833 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
834 // (peer->stats_h, "core", "# peers connected",
835 // stat_iterator, peer));
836 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
837 // (peer->stats_h, "nse", "# peers connected",
838 // stat_iterator, peer));
839 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
840 peer->stats_h = NULL;
841}
842
843/**
844 * Called after successfully opening a connection to a peer's statistics
845 * service; we register statistics monitoring for CORE and NSE here.
846 *
847 * @param cls the callback closure from functions generating an operation
848 * @param op the operation that has been finished
849 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
850 * @param emsg error message in case the operation has failed; will be NULL if
851 * operation has executed successfully.
852 */
853static void
854stat_complete_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
855 void *ca_result, const char *emsg )
856{
857 //struct GNUNET_STATISTICS_Handle *sh = ca_result;
858 //struct RPSPeer *peer = (struct RPSPeer *) cls;
859
860 if (NULL != emsg)
861 {
862 GNUNET_break (0);
863 return;
864 }
865 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
866 // (sh, "core", "# peers connected",
867 // stat_iterator, peer));
868 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
869 // (sh, "nse", "# peers connected",
870 // stat_iterator, peer));
871}
872
756 873
757/** 874/**
758 * Adapter function called to destroy connection to 875 * Adapter function called to destroy connection to
@@ -1541,6 +1658,71 @@ profiler_eval (void)
1541 return evaluate (); 1658 return evaluate ();
1542} 1659}
1543 1660
1661/**
1662 * Continuation called by #GNUNET_STATISTICS_get() functions.
1663 *
1664 * Checks whether all peers received their statistics yet.
1665 * Issues the shutdown.
1666 *
1667 * @param cls closure
1668 * @param success #GNUNET_OK if statistics were
1669 * successfully obtained, #GNUNET_SYSERR if not.
1670 */
1671void
1672post_test_shutdown_ready_cb (void *cls,
1673 int success)
1674{
1675 const struct RPSPeer *rps_peer = (const struct RPSPeer *) cls;
1676 if (NULL != rps_peer->stat_op)
1677 {
1678 GNUNET_TESTBED_operation_done (rps_peer->stat_op);
1679 }
1680 num_shutdown_ready++;
1681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1682 "%" PRIu32 " of %" PRIu32 " Peers are ready to shut down\n",
1683 num_shutdown_ready,
1684 num_peers);
1685 if (num_peers <= num_shutdown_ready)
1686 {
1687 GNUNET_SCHEDULER_shutdown ();
1688 }
1689}
1690
1691/**
1692 * Callback function to process statistic values.
1693 *
1694 * @param cls closure
1695 * @param subsystem name of subsystem that created the statistic
1696 * @param name the name of the datum
1697 * @param value the current value
1698 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
1699 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
1700 */
1701int
1702stat_iterator (void *cls,
1703 const char *subsystem,
1704 const char *name,
1705 uint64_t value,
1706 int is_persistent)
1707{
1708 //const struct RPSPeer *rps_peer = (const struct RPSPeer *) cls;
1709 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %" PRIu64 "\n", value);
1710 return GNUNET_OK;
1711}
1712
1713void post_profiler (const struct RPSPeer *rps_peer)
1714{
1715 if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics)
1716 {
1717 GNUNET_STATISTICS_get (rps_peer->stats_h,
1718 "rps",
1719 "# rounds",
1720 post_test_shutdown_ready_cb,
1721 stat_iterator,
1722 (struct RPSPeer *) rps_peer);
1723 }
1724}
1725
1544 1726
1545/*********************************************************************** 1727/***********************************************************************
1546 * /Definition of tests 1728 * /Definition of tests
@@ -1623,6 +1805,19 @@ run (void *cls,
1623 &rps_disconnect_adapter, 1805 &rps_disconnect_adapter,
1624 &rps_peers[i]); 1806 &rps_peers[i]);
1625 } 1807 }
1808 /* Connect all peers to statistics service */
1809 if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics)
1810 {
1811 rps_peers[i].stat_op =
1812 GNUNET_TESTBED_service_connect (NULL,
1813 peers[i],
1814 "statistics",
1815 stat_complete_cb,
1816 &rps_peers[i],
1817 &stat_connect_adapter,
1818 &stat_disconnect_adapter,
1819 &rps_peers[i]);
1820 }
1626 } 1821 }
1627 1822
1628 if (NULL != churn_task) 1823 if (NULL != churn_task)
@@ -1644,12 +1839,15 @@ main (int argc, char *argv[])
1644 int ret_value; 1839 int ret_value;
1645 1840
1646 num_peers = 5; 1841 num_peers = 5;
1842 num_shutdown_ready = 0;
1647 cur_test_run.name = "test-rps-default"; 1843 cur_test_run.name = "test-rps-default";
1648 cur_test_run.init_peer = default_init_peer; 1844 cur_test_run.init_peer = default_init_peer;
1649 cur_test_run.pre_test = NULL; 1845 cur_test_run.pre_test = NULL;
1650 cur_test_run.reply_handle = default_reply_handle; 1846 cur_test_run.reply_handle = default_reply_handle;
1651 cur_test_run.eval_cb = default_eval_cb; 1847 cur_test_run.eval_cb = default_eval_cb;
1848 cur_test_run.post_test = NULL;
1652 cur_test_run.have_churn = HAVE_CHURN; 1849 cur_test_run.have_churn = HAVE_CHURN;
1850 cur_test_run.have_collect_statistics = NO_COLLECT_STATISTICS;
1653 churn_task = NULL; 1851 churn_task = NULL;
1654 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); 1852 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
1655 1853
@@ -1767,10 +1965,12 @@ main (int argc, char *argv[])
1767 cur_test_run.main_test = profiler_cb; 1965 cur_test_run.main_test = profiler_cb;
1768 cur_test_run.reply_handle = profiler_reply_handle; 1966 cur_test_run.reply_handle = profiler_reply_handle;
1769 cur_test_run.eval_cb = profiler_eval; 1967 cur_test_run.eval_cb = profiler_eval;
1968 cur_test_run.post_test = post_profiler;
1770 cur_test_run.request_interval = 2; 1969 cur_test_run.request_interval = 2;
1771 cur_test_run.num_requests = 5; 1970 cur_test_run.num_requests = 5;
1772 cur_test_run.have_churn = HAVE_CHURN; 1971 cur_test_run.have_churn = HAVE_CHURN;
1773 cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; 1972 cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT;
1973 cur_test_run.have_collect_statistics = COLLECT_STATISTICS;
1774 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300); 1974 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300);
1775 1975
1776 /* 'Clean' directory */ 1976 /* 'Clean' directory */
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index e92405a96..1e52dce9f 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -424,7 +424,7 @@ get_timeout ()
424 { 424 {
425 if (0 != pos->reason) 425 if (0 != pos->reason)
426 { 426 {
427 timeout = now; 427 return now;
428 } 428 }
429 else 429 else
430 { 430 {
@@ -435,7 +435,7 @@ get_timeout ()
435 { 435 {
436 if (0 != pos->reason) 436 if (0 != pos->reason)
437 { 437 {
438 timeout = now; 438 return now;
439 } 439 }
440 else if ((pos->timeout.abs_value_us != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) && 440 else if ((pos->timeout.abs_value_us != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) &&
441 (timeout.abs_value_us > pos->timeout.abs_value_us)) 441 (timeout.abs_value_us > pos->timeout.abs_value_us))
@@ -994,7 +994,7 @@ GNUNET_SCHEDULER_add_with_reason_and_priority (GNUNET_SCHEDULER_TaskCallback tas
994 t->start_time = GNUNET_TIME_absolute_get (); 994 t->start_time = GNUNET_TIME_absolute_get ();
995#endif 995#endif
996 t->reason = reason; 996 t->reason = reason;
997 t->priority = priority; 997 t->priority = check_priority (priority);
998 t->lifeness = current_lifeness; 998 t->lifeness = current_lifeness;
999 LOG (GNUNET_ERROR_TYPE_DEBUG, 999 LOG (GNUNET_ERROR_TYPE_DEBUG,
1000 "Adding continuation task %p\n", 1000 "Adding continuation task %p\n",
@@ -1036,7 +1036,7 @@ GNUNET_SCHEDULER_add_at_with_priority (struct GNUNET_TIME_Absolute at,
1036 t->start_time = GNUNET_TIME_absolute_get (); 1036 t->start_time = GNUNET_TIME_absolute_get ();
1037#endif 1037#endif
1038 t->timeout = at; 1038 t->timeout = at;
1039 t->priority = priority; 1039 t->priority = check_priority (priority);
1040 t->lifeness = current_lifeness; 1040 t->lifeness = current_lifeness;
1041 /* try tail first (optimization in case we are 1041 /* try tail first (optimization in case we are
1042 * appending to a long list of tasks with timeouts) */ 1042 * appending to a long list of tasks with timeouts) */
@@ -1095,8 +1095,8 @@ GNUNET_SCHEDULER_add_at_with_priority (struct GNUNET_TIME_Absolute at,
1095 */ 1095 */
1096struct GNUNET_SCHEDULER_Task * 1096struct GNUNET_SCHEDULER_Task *
1097GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay, 1097GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
1098 enum GNUNET_SCHEDULER_Priority priority, 1098 enum GNUNET_SCHEDULER_Priority priority,
1099 GNUNET_SCHEDULER_TaskCallback task, 1099 GNUNET_SCHEDULER_TaskCallback task,
1100 void *task_cls) 1100 void *task_cls)
1101{ 1101{
1102 return GNUNET_SCHEDULER_add_at_with_priority (GNUNET_TIME_relative_to_absolute (delay), 1102 return GNUNET_SCHEDULER_add_at_with_priority (GNUNET_TIME_relative_to_absolute (delay),
@@ -1839,12 +1839,8 @@ GNUNET_SCHEDULER_task_ready (struct GNUNET_SCHEDULER_Task *task,
1839 struct GNUNET_SCHEDULER_FdInfo *fdi) 1839 struct GNUNET_SCHEDULER_FdInfo *fdi)
1840{ 1840{
1841 enum GNUNET_SCHEDULER_Reason reason; 1841 enum GNUNET_SCHEDULER_Reason reason;
1842 struct GNUNET_TIME_Absolute now;
1843 1842
1844 now = GNUNET_TIME_absolute_get ();
1845 reason = task->reason; 1843 reason = task->reason;
1846 if (now.abs_value_us >= task->timeout.abs_value_us)
1847 reason |= GNUNET_SCHEDULER_REASON_TIMEOUT;
1848 if ( (0 == (reason & GNUNET_SCHEDULER_REASON_READ_READY)) && 1844 if ( (0 == (reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
1849 (0 != (GNUNET_SCHEDULER_ET_IN & fdi->et)) ) 1845 (0 != (GNUNET_SCHEDULER_ET_IN & fdi->et)) )
1850 reason |= GNUNET_SCHEDULER_REASON_READ_READY; 1846 reason |= GNUNET_SCHEDULER_REASON_READ_READY;
@@ -1889,8 +1885,10 @@ GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh)
1889 1885
1890 /* check for tasks that reached the timeout! */ 1886 /* check for tasks that reached the timeout! */
1891 now = GNUNET_TIME_absolute_get (); 1887 now = GNUNET_TIME_absolute_get ();
1892 while (NULL != (pos = pending_timeout_head)) 1888 pos = pending_timeout_head;
1889 while (NULL != pos)
1893 { 1890 {
1891 struct GNUNET_SCHEDULER_Task *next = pos->next;
1894 if (now.abs_value_us >= pos->timeout.abs_value_us) 1892 if (now.abs_value_us >= pos->timeout.abs_value_us)
1895 pos->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT; 1893 pos->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT;
1896 if (0 == pos->reason) 1894 if (0 == pos->reason)
@@ -1901,6 +1899,7 @@ GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh)
1901 if (pending_timeout_last == pos) 1899 if (pending_timeout_last == pos)
1902 pending_timeout_last = NULL; 1900 pending_timeout_last = NULL;
1903 queue_ready_task (pos); 1901 queue_ready_task (pos);
1902 pos = next;
1904 } 1903 }
1905 pos = pending_head; 1904 pos = pending_head;
1906 while (NULL != pos) 1905 while (NULL != pos)
@@ -2276,24 +2275,27 @@ select_loop (void *cls,
2276 GNUNET_NETWORK_fdset_destroy (ws); 2275 GNUNET_NETWORK_fdset_destroy (ws);
2277 return GNUNET_SYSERR; 2276 return GNUNET_SYSERR;
2278 } 2277 }
2279 for (pos = context->scheduled_head; NULL != pos; pos = pos->next) 2278 if (select_result > 0)
2280 { 2279 {
2281 int is_ready = GNUNET_NO; 2280 for (pos = context->scheduled_head; NULL != pos; pos = pos->next)
2282 if (0 != (GNUNET_SCHEDULER_ET_IN & pos->et) &&
2283 GNUNET_YES == GNUNET_NETWORK_fdset_test_native (rs, pos->fdi->sock))
2284 {
2285 pos->fdi->et |= GNUNET_SCHEDULER_ET_IN;
2286 is_ready = GNUNET_YES;
2287 }
2288 if (0 != (GNUNET_SCHEDULER_ET_OUT & pos->et) &&
2289 GNUNET_YES == GNUNET_NETWORK_fdset_test_native (ws, pos->fdi->sock))
2290 { 2281 {
2291 pos->fdi->et |= GNUNET_SCHEDULER_ET_OUT; 2282 int is_ready = GNUNET_NO;
2292 is_ready = GNUNET_YES; 2283 if (0 != (GNUNET_SCHEDULER_ET_IN & pos->et) &&
2293 } 2284 GNUNET_YES == GNUNET_NETWORK_fdset_test_native (rs, pos->fdi->sock))
2294 if (GNUNET_YES == is_ready) 2285 {
2295 { 2286 pos->fdi->et |= GNUNET_SCHEDULER_ET_IN;
2296 GNUNET_SCHEDULER_task_ready (pos->task, pos->fdi); 2287 is_ready = GNUNET_YES;
2288 }
2289 if (0 != (GNUNET_SCHEDULER_ET_OUT & pos->et) &&
2290 GNUNET_YES == GNUNET_NETWORK_fdset_test_native (ws, pos->fdi->sock))
2291 {
2292 pos->fdi->et |= GNUNET_SCHEDULER_ET_OUT;
2293 is_ready = GNUNET_YES;
2294 }
2295 if (GNUNET_YES == is_ready)
2296 {
2297 GNUNET_SCHEDULER_task_ready (pos->task, pos->fdi);
2298 }
2297 } 2299 }
2298 } 2300 }
2299 tasks_ready = GNUNET_SCHEDULER_run_from_driver (sh); 2301 tasks_ready = GNUNET_SCHEDULER_run_from_driver (sh);
@@ -2306,8 +2308,8 @@ select_loop (void *cls,
2306 2308
2307 2309
2308void 2310void
2309select_set_wakeup(void *cls, 2311select_set_wakeup (void *cls,
2310 struct GNUNET_TIME_Absolute dt) 2312 struct GNUNET_TIME_Absolute dt)
2311{ 2313{
2312 struct DriverContext *context = cls; 2314 struct DriverContext *context = cls;
2313 GNUNET_assert (NULL != context); 2315 GNUNET_assert (NULL != context);