diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-10-29 14:20:22 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-10-29 14:20:22 +0000 |
commit | 8459c76076092899a74aa7e4451ed24faf91684b (patch) | |
tree | f66e960ec08f0270387afcbed3e10ea2cb04d6cd /src/core/test_core_api_reliability.c | |
parent | 6486831b520ad18632aa117ee8c15305d6b89c29 (diff) | |
download | gnunet-8459c76076092899a74aa7e4451ed24faf91684b.tar.gz gnunet-8459c76076092899a74aa7e4451ed24faf91684b.zip |
-preparations for replacement of try_connect call
Diffstat (limited to 'src/core/test_core_api_reliability.c')
-rw-r--r-- | src/core/test_core_api_reliability.c | 91 |
1 files changed, 48 insertions, 43 deletions
diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c index bd55565e3..dfea0cdcc 100644 --- a/src/core/test_core_api_reliability.c +++ b/src/core/test_core_api_reliability.c | |||
@@ -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 <gauger.h> | 30 | #include <gauger.h> |
33 | 31 | ||
@@ -68,6 +66,8 @@ struct PeerContext | |||
68 | struct GNUNET_TRANSPORT_Handle *th; | 66 | struct GNUNET_TRANSPORT_Handle *th; |
69 | struct GNUNET_MessageHeader *hello; | 67 | struct GNUNET_MessageHeader *hello; |
70 | struct GNUNET_TRANSPORT_GetHelloHandle *ghh; | 68 | struct GNUNET_TRANSPORT_GetHelloHandle *ghh; |
69 | struct GNUNET_ATS_ConnectivityHandle *ats; | ||
70 | struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; | ||
71 | int connect_status; | 71 | int connect_status; |
72 | struct GNUNET_OS_Process *arm_proc; | 72 | struct GNUNET_OS_Process *arm_proc; |
73 | }; | 73 | }; |
@@ -103,30 +103,48 @@ get_size (unsigned int iter) | |||
103 | 103 | ||
104 | 104 | ||
105 | static void | 105 | static void |
106 | process_hello (void *cls, const struct GNUNET_MessageHeader *message); | 106 | terminate_peer (struct PeerContext *p) |
107 | { | ||
108 | if (NULL != p->ch) | ||
109 | { | ||
110 | GNUNET_CORE_disconnect (p->ch); | ||
111 | p->ch = NULL; | ||
112 | } | ||
113 | if (NULL != p->th) | ||
114 | { | ||
115 | GNUNET_TRANSPORT_get_hello_cancel (p->ghh); | ||
116 | GNUNET_TRANSPORT_disconnect (p->th); | ||
117 | p->th = NULL; | ||
118 | } | ||
119 | if (NULL != p->ats_sh) | ||
120 | { | ||
121 | GNUNET_ATS_connectivity_suggest_cancel (p->ats_sh); | ||
122 | p->ats_sh = NULL; | ||
123 | } | ||
124 | if (NULL != p->ats) | ||
125 | { | ||
126 | GNUNET_ATS_connectivity_done (p->ats); | ||
127 | p->ats = NULL; | ||
128 | } | ||
129 | } | ||
107 | 130 | ||
108 | 131 | ||
109 | static void | 132 | static void |
110 | terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 133 | terminate_task (void *cls, |
134 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
111 | { | 135 | { |
112 | unsigned long long delta; | 136 | unsigned long long delta; |
113 | 137 | ||
114 | GNUNET_TRANSPORT_get_hello_cancel (p1.ghh); | 138 | terminate_peer (&p1); |
115 | GNUNET_TRANSPORT_get_hello_cancel (p2.ghh); | 139 | terminate_peer (&p2); |
116 | GNUNET_CORE_disconnect (p1.ch); | 140 | if (NULL != connect_task) |
117 | p1.ch = NULL; | 141 | { |
118 | GNUNET_free_non_null (p1.hello); | ||
119 | GNUNET_CORE_disconnect (p2.ch); | ||
120 | p2.ch = NULL; | ||
121 | GNUNET_free_non_null (p2.hello); | ||
122 | if (connect_task != NULL) | ||
123 | GNUNET_SCHEDULER_cancel (connect_task); | 142 | GNUNET_SCHEDULER_cancel (connect_task); |
124 | GNUNET_TRANSPORT_disconnect (p1.th); | 143 | connect_task = NULL; |
125 | p1.th = NULL; | 144 | } |
126 | GNUNET_TRANSPORT_disconnect (p2.th); | ||
127 | p2.th = NULL; | ||
128 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; | 145 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; |
129 | FPRINTF (stderr, "\nThroughput was %llu kb/s\n", | 146 | FPRINTF (stderr, |
147 | "\nThroughput was %llu kb/s\n", | ||
130 | total_bytes * 1000000LL / 1024 / delta); | 148 | total_bytes * 1000000LL / 1024 / delta); |
131 | GAUGER ("CORE", "Core throughput/s", total_bytes * 1000000LL / 1024 / delta, | 149 | GAUGER ("CORE", "Core throughput/s", total_bytes * 1000000LL / 1024 / delta, |
132 | "kb/s"); | 150 | "kb/s"); |
@@ -135,39 +153,24 @@ terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
135 | 153 | ||
136 | 154 | ||
137 | static void | 155 | static void |
138 | terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 156 | terminate_task_error (void *cls, |
157 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
139 | { | 158 | { |
140 | GNUNET_break (0); | 159 | GNUNET_break (0); |
141 | if (p1.ch != NULL) | 160 | terminate_peer (&p1); |
142 | { | 161 | terminate_peer (&p2); |
143 | GNUNET_CORE_disconnect (p1.ch); | 162 | if (NULL != connect_task) |
144 | p1.ch = NULL; | ||
145 | } | ||
146 | if (p2.ch != NULL) | ||
147 | { | 163 | { |
148 | GNUNET_CORE_disconnect (p2.ch); | ||
149 | p2.ch = NULL; | ||
150 | } | ||
151 | if (connect_task != NULL) | ||
152 | GNUNET_SCHEDULER_cancel (connect_task); | 164 | GNUNET_SCHEDULER_cancel (connect_task); |
153 | if (p1.th != NULL) | 165 | connect_task = NULL; |
154 | { | ||
155 | GNUNET_TRANSPORT_get_hello_cancel (p1.ghh); | ||
156 | GNUNET_TRANSPORT_disconnect (p1.th); | ||
157 | p1.th = NULL; | ||
158 | } | ||
159 | if (p2.th != NULL) | ||
160 | { | ||
161 | GNUNET_TRANSPORT_get_hello_cancel (p2.ghh); | ||
162 | GNUNET_TRANSPORT_disconnect (p2.th); | ||
163 | p2.th = NULL; | ||
164 | } | 166 | } |
165 | ok = 42; | 167 | ok = 42; |
166 | } | 168 | } |
167 | 169 | ||
168 | 170 | ||
169 | static void | 171 | static void |
170 | try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 172 | try_connect (void *cls, |
173 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
171 | { | 174 | { |
172 | connect_task = | 175 | connect_task = |
173 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect, | 176 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect, |
@@ -435,6 +438,8 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
435 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 438 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
436 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); | 439 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); |
437 | GNUNET_assert (p->th != NULL); | 440 | GNUNET_assert (p->th != NULL); |
441 | p->ats = GNUNET_ATS_connectivity_init (p->cfg); | ||
442 | GNUNET_assert (NULL != p->ats); | ||
438 | p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); | 443 | p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); |
439 | GNUNET_free (binary); | 444 | GNUNET_free (binary); |
440 | } | 445 | } |