diff options
author | xrs <xrs@mail36.net> | 2020-02-29 17:58:00 +0100 |
---|---|---|
committer | xrs <xrs@mail36.net> | 2020-05-21 22:46:48 +0200 |
commit | b74a439892768274c39349e4c6974074e7e1203a (patch) | |
tree | 6516816eecc8b5e5051f01af3e4986807b856c5b /src | |
parent | 28074776fde60f2efa0210f02a5ef59f8e3e4e2b (diff) | |
download | gnunet-b74a439892768274c39349e4c6974074e7e1203a.tar.gz gnunet-b74a439892768274c39349e4c6974074e7e1203a.zip |
refactor function logs; refactor conntect to services
Diffstat (limited to 'src')
-rw-r--r-- | src/cadet/test_cadeT.c | 99 |
1 files changed, 61 insertions, 38 deletions
diff --git a/src/cadet/test_cadeT.c b/src/cadet/test_cadeT.c index f489ca56d..cf335a948 100644 --- a/src/cadet/test_cadeT.c +++ b/src/cadet/test_cadeT.c | |||
@@ -47,6 +47,7 @@ | |||
47 | * | 47 | * |
48 | * Development | 48 | * Development |
49 | * - red -> green -> refactor (cyclic) | 49 | * - red -> green -> refactor (cyclic) |
50 | * - be aware of Continuation Passing Style (CPS) programming | ||
50 | */ | 51 | */ |
51 | #include "platform.h" | 52 | #include "platform.h" |
52 | #include "gnunet_testbed_service.h" | 53 | #include "gnunet_testbed_service.h" |
@@ -60,12 +61,12 @@ | |||
60 | /** | 61 | /** |
61 | * Testbed operation for connecting to the services. | 62 | * Testbed operation for connecting to the services. |
62 | */ | 63 | */ |
63 | struct GNUNET_TESTBED_Operation *testbed_to_svc[2]; | 64 | static struct GNUNET_TESTBED_Operation *testbed_to_svc[2]; |
64 | 65 | ||
65 | /** | 66 | /** |
66 | * Testbed operation for requesting peer information. | 67 | * Testbed operation for requesting peer information. |
67 | */ | 68 | */ |
68 | struct GNUNET_TESTBED_Operation *testbed_info_req[2]; | 69 | static struct GNUNET_TESTBED_Operation *testbed_info_req[2]; |
69 | 70 | ||
70 | /** | 71 | /** |
71 | * Port name kown by the two peers. | 72 | * Port name kown by the two peers. |
@@ -81,20 +82,31 @@ static int test_result = 0; | |||
81 | static int cnt = 0; | 82 | static int cnt = 0; |
82 | 83 | ||
83 | /** | 84 | /** |
85 | * Counter for gathering peerinformation. | ||
86 | */ | ||
87 | static int peerinfo_cnt = 0; | ||
88 | |||
89 | /** | ||
84 | * Structure for storing information of testbed peers. | 90 | * Structure for storing information of testbed peers. |
85 | */ | 91 | */ |
86 | struct testbed_peers | 92 | struct TEST_PEERS |
87 | { | 93 | { |
88 | /** | 94 | /** |
89 | * Index of the peer. | 95 | * Index of the peer. |
90 | */ | 96 | */ |
91 | int index; | 97 | int idx; |
92 | 98 | ||
93 | /** | 99 | /** |
94 | * Peer Identity. | 100 | * Peer Identity. |
95 | */ | 101 | */ |
96 | struct GNUNET_PeerIdentity id; | 102 | struct GNUNET_PeerIdentity id; |
97 | } testbed_peers[2]; | 103 | |
104 | struct GNUNET_TESTBED_Peer *testbed_peer; | ||
105 | |||
106 | int ready; | ||
107 | |||
108 | } test_peers[2]; | ||
109 | |||
98 | 110 | ||
99 | /****************************** TEST LOGIC ********************************/ | 111 | /****************************** TEST LOGIC ********************************/ |
100 | 112 | ||
@@ -115,7 +127,7 @@ disconnect_from_peer (void *cls, | |||
115 | { | 127 | { |
116 | struct GNUNET_CADET_Handle *cadet = op_result; | 128 | struct GNUNET_CADET_Handle *cadet = op_result; |
117 | 129 | ||
118 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "disconnect_from_cadet ()\n"); | 130 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); |
119 | 131 | ||
120 | GNUNET_CADET_disconnect (cadet); | 132 | GNUNET_CADET_disconnect (cadet); |
121 | } | 133 | } |
@@ -135,7 +147,7 @@ setup_initiating_peer (void *cls, | |||
135 | struct GNUNET_PeerIdentity *destination; | 147 | struct GNUNET_PeerIdentity *destination; |
136 | struct GNUNET_CADET_Channel *channel; | 148 | struct GNUNET_CADET_Channel *channel; |
137 | 149 | ||
138 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "setup_initiating_peer()\n"); | 150 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); |
139 | 151 | ||
140 | cadet = GNUNET_CADET_connect (cfg); | 152 | cadet = GNUNET_CADET_connect (cfg); |
141 | 153 | ||
@@ -174,7 +186,7 @@ setup_listening_peer (void *cls, | |||
174 | struct GNUNET_CADET_Handle *cadet; | 186 | struct GNUNET_CADET_Handle *cadet; |
175 | struct GNUNET_CADET_Port *port; | 187 | struct GNUNET_CADET_Port *port; |
176 | 188 | ||
177 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "setup_listening_peer()\n"); | 189 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); |
178 | 190 | ||
179 | cadet = GNUNET_CADET_connect (cfg); | 191 | cadet = GNUNET_CADET_connect (cfg); |
180 | 192 | ||
@@ -198,26 +210,45 @@ check_test_readyness (void *cls, | |||
198 | void *ca_result, | 210 | void *ca_result, |
199 | const char *emsg) | 211 | const char *emsg) |
200 | { | 212 | { |
201 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "check_test_readyness()\n"); | 213 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); |
202 | 214 | ||
203 | if (2 == ++cnt) | 215 | if (2 == ++cnt) |
204 | GNUNET_SCHEDULER_shutdown (); | 216 | GNUNET_SCHEDULER_shutdown (); |
205 | } | 217 | } |
206 | 218 | ||
207 | 219 | ||
208 | static void | 220 | static int |
209 | process_info_req (void *cb_cls, | 221 | peerinfo_complete () |
210 | struct GNUNET_TESTBED_Operation *op, | ||
211 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
212 | const char *emsg) | ||
213 | { | 222 | { |
214 | struct testbed_peers *testbed_peer = cb_cls; | 223 | return (REQUESTED_PEERS == ++peerinfo_cnt) ? GNUNET_YES : GNUNET_NO; |
215 | struct GNUNET_PeerIdentity id = testbed_peer->id; | 224 | } |
216 | |||
217 | GNUNET_memcpy (&id, pinfo->result.id, sizeof (struct GNUNET_PeerIdentity)); | ||
218 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer %s ready\n", GNUNET_i2s (&id)); | ||
219 | 225 | ||
220 | // TODO: connect_to_peer_services | 226 | static void |
227 | connect_to_service (void *cb_cls, | ||
228 | struct GNUNET_TESTBED_Operation *op, | ||
229 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
230 | const char *emsg) | ||
231 | { | ||
232 | struct TEST_PEERS *test_peer = cb_cls; | ||
233 | |||
234 | // Store peer ID. | ||
235 | test_peer->id = *(pinfo->result.id); | ||
236 | |||
237 | if (peerinfo_complete()) | ||
238 | { | ||
239 | testbed_to_svc[1] = | ||
240 | GNUNET_TESTBED_service_connect (NULL, test_peers[1].testbed_peer, | ||
241 | "cadet", | ||
242 | &check_test_readyness, NULL, | ||
243 | &setup_listening_peer, | ||
244 | &disconnect_from_peer, NULL); | ||
245 | testbed_to_svc[0] = | ||
246 | GNUNET_TESTBED_service_connect (NULL, test_peers[0].testbed_peer, | ||
247 | "cadet", | ||
248 | &check_test_readyness, NULL, | ||
249 | &setup_initiating_peer, | ||
250 | &disconnect_from_peer, NULL); | ||
251 | } | ||
221 | } | 252 | } |
222 | 253 | ||
223 | static void | 254 | static void |
@@ -228,33 +259,25 @@ connect_to_peers (void *cls, | |||
228 | unsigned int links_succeeded, | 259 | unsigned int links_succeeded, |
229 | unsigned int links_failed) | 260 | unsigned int links_failed) |
230 | { | 261 | { |
231 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "connect_to_peers()\n"); | 262 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); |
232 | 263 | ||
233 | GNUNET_assert (0 == links_failed); | 264 | GNUNET_assert (0 == links_failed); |
234 | 265 | ||
235 | for (int i=0; i<num_peers; i++) | 266 | for (int i=0; i<num_peers; i++) |
236 | testbed_peers[i].index = i; | 267 | { |
268 | test_peers[i].ready = GNUNET_NO; | ||
269 | test_peers[i].idx = i; | ||
270 | test_peers[i].testbed_peer = peers[i]; | ||
271 | } | ||
237 | 272 | ||
238 | testbed_info_req[0] = GNUNET_TESTBED_peer_get_information (peers[0], | 273 | testbed_info_req[0] = GNUNET_TESTBED_peer_get_information (peers[0], |
239 | GNUNET_TESTBED_PIT_IDENTITY, | 274 | GNUNET_TESTBED_PIT_IDENTITY, |
240 | &process_info_req, | 275 | &connect_to_service, |
241 | &testbed_peers[0]); | 276 | &test_peers[0]); |
242 | testbed_info_req[1] = GNUNET_TESTBED_peer_get_information (peers[1], | 277 | testbed_info_req[1] = GNUNET_TESTBED_peer_get_information (peers[1], |
243 | GNUNET_TESTBED_PIT_IDENTITY, | 278 | GNUNET_TESTBED_PIT_IDENTITY, |
244 | &process_info_req, | 279 | &connect_to_service, |
245 | &testbed_peers[1]); | 280 | &test_peers[1]); |
246 | |||
247 | |||
248 | testbed_to_svc[1] = GNUNET_TESTBED_service_connect (NULL, peers[1], | ||
249 | "cadet", | ||
250 | &check_test_readyness, NULL, | ||
251 | &setup_listening_peer, | ||
252 | &disconnect_from_peer, NULL); | ||
253 | testbed_to_svc[0] = GNUNET_TESTBED_service_connect (NULL, peers[0], | ||
254 | "cadet", | ||
255 | &check_test_readyness, NULL, | ||
256 | &setup_initiating_peer, | ||
257 | &disconnect_from_peer, NULL); | ||
258 | 281 | ||
259 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 282 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
260 | } | 283 | } |