aboutsummaryrefslogtreecommitdiff
path: root/src/core/test_core_quota_compliance.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-10-29 14:20:22 +0000
committerChristian Grothoff <christian@grothoff.org>2015-10-29 14:20:22 +0000
commit8459c76076092899a74aa7e4451ed24faf91684b (patch)
treef66e960ec08f0270387afcbed3e10ea2cb04d6cd /src/core/test_core_quota_compliance.c
parent6486831b520ad18632aa117ee8c15305d6b89c29 (diff)
downloadgnunet-8459c76076092899a74aa7e4451ed24faf91684b.tar.gz
gnunet-8459c76076092899a74aa7e4451ed24faf91684b.zip
-preparations for replacement of try_connect call
Diffstat (limited to 'src/core/test_core_quota_compliance.c')
-rw-r--r--src/core/test_core_quota_compliance.c152
1 files changed, 87 insertions, 65 deletions
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c
index bc71aa5d7..ce62dbe3b 100644
--- a/src/core/test_core_quota_compliance.c
+++ b/src/core/test_core_quota_compliance.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, 2010 Christian Grothoff (and other contributing authors) 3 Copyright (C) 2009, 2010, 2015 Christian Grothoff (and other contributing authors)
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
@@ -24,10 +24,8 @@
24#include "platform.h" 24#include "platform.h"
25#include "gnunet_arm_service.h" 25#include "gnunet_arm_service.h"
26#include "gnunet_core_service.h" 26#include "gnunet_core_service.h"
27#include "gnunet_getopt_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_os_lib.h" 28#include "gnunet_ats_service.h"
29#include "gnunet_program_lib.h"
30#include "gnunet_scheduler_lib.h"
31#include "gnunet_transport_service.h" 29#include "gnunet_transport_service.h"
32#include "gnunet_statistics_service.h" 30#include "gnunet_statistics_service.h"
33 31
@@ -62,11 +60,11 @@ static unsigned long long total_bytes_recv;
62 60
63static struct GNUNET_TIME_Absolute start_time; 61static struct GNUNET_TIME_Absolute start_time;
64 62
65static struct GNUNET_SCHEDULER_Task * err_task; 63static struct GNUNET_SCHEDULER_Task *err_task;
66 64
67static struct GNUNET_SCHEDULER_Task * measure_task; 65static struct GNUNET_SCHEDULER_Task *measure_task;
68 66
69static struct GNUNET_SCHEDULER_Task * connect_task; 67static struct GNUNET_SCHEDULER_Task *connect_task;
70 68
71 69
72struct PeerContext 70struct PeerContext
@@ -79,6 +77,8 @@ struct PeerContext
79 struct GNUNET_MessageHeader *hello; 77 struct GNUNET_MessageHeader *hello;
80 struct GNUNET_STATISTICS_Handle *stats; 78 struct GNUNET_STATISTICS_Handle *stats;
81 struct GNUNET_TRANSPORT_GetHelloHandle *ghh; 79 struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
80 struct GNUNET_ATS_ConnectivityHandle *ats;
81 struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh;
82 int connect_status; 82 int connect_status;
83 struct GNUNET_OS_Process *arm_proc; 83 struct GNUNET_OS_Process *arm_proc;
84}; 84};
@@ -110,85 +110,93 @@ struct TestMessage
110 uint32_t num; 110 uint32_t num;
111}; 111};
112 112
113static void
114process_hello (void *cls, const struct GNUNET_MessageHeader *message);
115 113
116static void 114static void
117terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 115terminate_peer (struct PeerContext *p)
118{ 116{
119 struct GNUNET_CORE_Handle *ch; 117 if (p->nth != NULL)
118 {
119 GNUNET_CORE_notify_transmit_ready_cancel (p->nth);
120 p->nth = NULL;
121 }
122 if (NULL != p->ch)
123 {
124 GNUNET_CORE_disconnect (p->ch);
125 p->ch = NULL;
126 }
127 if (NULL != p->th)
128 {
129 GNUNET_TRANSPORT_get_hello_cancel (p->ghh);
130 GNUNET_TRANSPORT_disconnect (p->th);
131 p->th = NULL;
132 }
133 if (NULL != p->ats_sh)
134 {
135 GNUNET_ATS_connectivity_suggest_cancel (p->ats_sh);
136 p->ats_sh = NULL;
137 }
138 if (NULL != p->ats)
139 {
140 GNUNET_ATS_connectivity_done (p->ats);
141 p->ats = NULL;
142 }
143 if (NULL != p->stats)
144 {
145 GNUNET_STATISTICS_destroy (p->stats, GNUNET_NO);
146 p->stats = NULL;
147 }
148 if (NULL != p->hello)
149 {
150 GNUNET_free (p->hello);
151 p->hello = NULL;
152 }
153}
120 154
155
156static void
157terminate_task (void *cls,
158 const struct GNUNET_SCHEDULER_TaskContext *tc)
159{
121 err_task = NULL; 160 err_task = NULL;
122 GNUNET_STATISTICS_destroy (p1.stats, GNUNET_NO); 161 terminate_peer (&p1);
123 GNUNET_STATISTICS_destroy (p2.stats, GNUNET_NO); 162 terminate_peer (&p2);
124 GNUNET_TRANSPORT_get_hello_cancel (p2.ghh); 163 if (NULL != connect_task)
125 GNUNET_TRANSPORT_get_hello_cancel (p1.ghh);
126 if (p1.nth != NULL)
127 {
128 GNUNET_CORE_notify_transmit_ready_cancel (p1.nth);
129 p1.nth = NULL;
130 }
131 if (connect_task != NULL)
132 { 164 {
133 GNUNET_SCHEDULER_cancel (connect_task); 165 GNUNET_SCHEDULER_cancel (connect_task);
134 connect_task = NULL; 166 connect_task = NULL;
135 } 167 }
136 ch = p1.ch;
137 p1.ch = NULL;
138 GNUNET_CORE_disconnect (ch);
139 ch = p2.ch;
140 p2.ch = NULL;
141 GNUNET_CORE_disconnect (ch);
142 GNUNET_TRANSPORT_disconnect (p1.th);
143 p1.th = NULL;
144 GNUNET_TRANSPORT_disconnect (p2.th);
145 p2.th = NULL;
146 GNUNET_free_non_null (p1.hello);
147 GNUNET_free_non_null (p2.hello);
148} 168}
149 169
150 170
151static void 171static void
152terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 172terminate_task_error (void *cls,
173 const struct GNUNET_SCHEDULER_TaskContext *tc)
153{ 174{
154 err_task = NULL; 175 err_task = NULL;
155 176
156 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 177 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
157 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase failed!\n"); 178 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
179 "Testcase failed!\n");
180 terminate_peer (&p1);
181 terminate_peer (&p2);
158 //GNUNET_break (0); 182 //GNUNET_break (0);
159 if (p1.nth != NULL) 183 if (NULL != measure_task)
160 { 184 {
161 GNUNET_CORE_notify_transmit_ready_cancel (p1.nth);
162 p1.nth = NULL;
163 }
164 if (measure_task != NULL)
165 GNUNET_SCHEDULER_cancel (measure_task); 185 GNUNET_SCHEDULER_cancel (measure_task);
166 if (connect_task != NULL) 186 measure_task = NULL;
187 }
188 if (NULL != connect_task)
167 { 189 {
168 GNUNET_SCHEDULER_cancel (connect_task); 190 GNUNET_SCHEDULER_cancel (connect_task);
169 connect_task = NULL; 191 connect_task = NULL;
170 } 192 }
171
172 GNUNET_TRANSPORT_get_hello_cancel (p1.ghh);
173 GNUNET_TRANSPORT_get_hello_cancel (p2.ghh);
174 if (NULL != p1.ch)
175 GNUNET_CORE_disconnect (p1.ch);
176 p1.ch = NULL;
177 if (NULL != p2.ch)
178 GNUNET_CORE_disconnect (p2.ch);
179 p2.ch = NULL;
180 if (NULL != p1.th)
181 GNUNET_TRANSPORT_disconnect (p1.th);
182 p1.th = NULL;
183 if (NULL != p2.th)
184 GNUNET_TRANSPORT_disconnect (p2.th);
185 p2.th = NULL;
186 ok = 42; 193 ok = 42;
187} 194}
188 195
189 196
190static void 197static void
191try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 198try_connect (void *cls,
199 const struct GNUNET_SCHEDULER_TaskContext *tc)
192{ 200{
193 connect_task = 201 connect_task =
194 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect, 202 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect,
@@ -197,6 +205,7 @@ try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
197 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id, NULL, NULL); /*FIXME TRY_CONNECT change */ 205 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id, NULL, NULL); /*FIXME TRY_CONNECT change */
198} 206}
199 207
208
200/** 209/**
201 * Callback function to process statistic values. 210 * Callback function to process statistic values.
202 * 211 *
@@ -204,24 +213,33 @@ try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
204 * @param subsystem name of subsystem that created the statistic 213 * @param subsystem name of subsystem that created the statistic
205 * @param name the name of the datum 214 * @param name the name of the datum
206 * @param value the current value 215 * @param value the current value
207 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not 216 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
208 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 217 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
209 */ 218 */
210static int 219static int
211print_stat (void *cls, const char *subsystem, const char *name, uint64_t value, 220print_stat (void *cls,
221 const char *subsystem,
222 const char *name,
223 uint64_t value,
212 int is_persistent) 224 int is_persistent)
213{ 225{
214 if (cls == &p1) 226 if (cls == &p1)
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer1 %50s = %12llu\n", name, 227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
228 "Peer1 %50s = %12llu\n",
229 name,
216 (unsigned long long) value); 230 (unsigned long long) value);
217 if (cls == &p2) 231 if (cls == &p2)
218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer2 %50s = %12llu\n", name, 232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
233 "Peer2 %50s = %12llu\n",
234 name,
219 (unsigned long long) value); 235 (unsigned long long) value);
220 return GNUNET_OK; 236 return GNUNET_OK;
221} 237}
222 238
239
223static void 240static void
224measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 241measurement_stop (void *cls,
242 const struct GNUNET_SCHEDULER_TaskContext *tc)
225{ 243{
226 unsigned long long delta; 244 unsigned long long delta;
227 unsigned long long throughput_out; 245 unsigned long long throughput_out;
@@ -311,6 +329,7 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
311 329
312} 330}
313 331
332
314static size_t 333static size_t
315transmit_ready (void *cls, size_t size, void *buf) 334transmit_ready (void *cls, size_t size, void *buf)
316{ 335{
@@ -453,6 +472,7 @@ outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
453static size_t 472static size_t
454transmit_ready (void *cls, size_t size, void *buf); 473transmit_ready (void *cls, size_t size, void *buf);
455 474
475
456static int 476static int
457process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, 477process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
458 const struct GNUNET_MessageHeader *message) 478 const struct GNUNET_MessageHeader *message)
@@ -571,7 +591,7 @@ setup_peer (struct PeerContext *p, const char *cfgname)
571 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); 591 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
572 p->cfg = GNUNET_CONFIGURATION_create (); 592 p->cfg = GNUNET_CONFIGURATION_create ();
573 p->arm_proc = 593 p->arm_proc =
574 GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 594 GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
575 NULL, NULL, NULL, 595 NULL, NULL, NULL,
576 binary, 596 binary,
577 "gnunet-service-arm", 597 "gnunet-service-arm",
@@ -581,6 +601,8 @@ setup_peer (struct PeerContext *p, const char *cfgname)
581 GNUNET_assert (p->stats != NULL); 601 GNUNET_assert (p->stats != NULL);
582 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); 602 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL);
583 GNUNET_assert (p->th != NULL); 603 GNUNET_assert (p->th != NULL);
604 p->ats = GNUNET_ATS_connectivity_init (p->cfg);
605 GNUNET_assert (NULL != p->ats);
584 p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); 606 p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p);
585 GNUNET_free (binary); 607 GNUNET_free (binary);
586} 608}