aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport-testing.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport-testing.c')
-rw-r--r--src/transport/transport-testing.c178
1 files changed, 87 insertions, 91 deletions
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c
index 01419ce44..e6fcabb48 100644
--- a/src/transport/transport-testing.c
+++ b/src/transport/transport-testing.c
@@ -29,11 +29,11 @@
29 29
30struct ConnectingContext 30struct ConnectingContext
31{ 31{
32 struct PeerContext * p1; 32 struct PeerContext *p1;
33 struct PeerContext * p2; 33 struct PeerContext *p2;
34 GNUNET_SCHEDULER_TaskIdentifier tct; 34 GNUNET_SCHEDULER_TaskIdentifier tct;
35 GNUNET_TRANSPORT_TESTING_connect_cb cb; 35 GNUNET_TRANSPORT_TESTING_connect_cb cb;
36 void * cb_cls; 36 void *cb_cls;
37 37
38 struct GNUNET_TRANSPORT_Handle *th_p1; 38 struct GNUNET_TRANSPORT_Handle *th_p1;
39 struct GNUNET_TRANSPORT_Handle *th_p2; 39 struct GNUNET_TRANSPORT_Handle *th_p2;
@@ -42,41 +42,43 @@ struct ConnectingContext
42}; 42};
43 43
44static void 44static void
45exchange_hello_last (void *cb_cls, 45exchange_hello_last (void *cb_cls, const struct GNUNET_MessageHeader *message);
46 const struct GNUNET_MessageHeader *message);
47static void 46static void
48exchange_hello (void *cb_cls, 47exchange_hello (void *cb_cls, const struct GNUNET_MessageHeader *message);
49 const struct GNUNET_MessageHeader *message);
50 48
51static void 49static void
52notify_connect_internal (void *cls, 50notify_connect_internal (void *cls,
53 const struct GNUNET_PeerIdentity *peer, 51 const struct GNUNET_PeerIdentity *peer,
54 const struct GNUNET_TRANSPORT_ATS_Information *ats, 52 const struct GNUNET_TRANSPORT_ATS_Information *ats,
55 uint32_t ats_count) 53 uint32_t ats_count)
56{ 54{
57 struct ConnectingContext * cc = cls; 55 struct ConnectingContext *cc = cls;
58 56
59 GNUNET_assert(cc != NULL); 57 GNUNET_assert (cc != NULL);
60 58
61 if (0 == memcmp (&(*peer).hashPubKey, &cc->p1->id.hashPubKey, sizeof (GNUNET_HashCode))) 59 if (0 ==
62 { 60 memcmp (&(*peer).hashPubKey, &cc->p1->id.hashPubKey,
61 sizeof (GNUNET_HashCode)))
62 {
63 if (cc->p1_c == GNUNET_NO) 63 if (cc->p1_c == GNUNET_NO)
64 cc->p1_c = GNUNET_YES; 64 cc->p1_c = GNUNET_YES;
65 } 65 }
66 if (0 == memcmp (&(*peer).hashPubKey, &cc->p2->id.hashPubKey, sizeof (GNUNET_HashCode))) 66 if (0 ==
67 { 67 memcmp (&(*peer).hashPubKey, &cc->p2->id.hashPubKey,
68 sizeof (GNUNET_HashCode)))
69 {
68 if (cc->p2_c == GNUNET_NO) 70 if (cc->p2_c == GNUNET_NO)
69 cc->p2_c = GNUNET_YES; 71 cc->p2_c = GNUNET_YES;
70 } 72 }
71 73
72 if ((cc->p2_c == GNUNET_YES) && (cc->p2_c == GNUNET_YES)) 74 if ((cc->p2_c == GNUNET_YES) && (cc->p2_c == GNUNET_YES))
73 { 75 {
74 /* clean up */ 76 /* clean up */
75 GNUNET_TRANSPORT_get_hello_cancel (cc->th_p2, &exchange_hello_last, cc); 77 GNUNET_TRANSPORT_get_hello_cancel (cc->th_p2, &exchange_hello_last, cc);
76 GNUNET_TRANSPORT_get_hello_cancel (cc->th_p1, &exchange_hello, cc); 78 GNUNET_TRANSPORT_get_hello_cancel (cc->th_p1, &exchange_hello, cc);
77 79
78 if (cc->tct != GNUNET_SCHEDULER_NO_TASK) 80 if (cc->tct != GNUNET_SCHEDULER_NO_TASK)
79 GNUNET_SCHEDULER_cancel(cc->tct); 81 GNUNET_SCHEDULER_cancel (cc->tct);
80 82
81 cc->tct = GNUNET_SCHEDULER_NO_TASK; 83 cc->tct = GNUNET_SCHEDULER_NO_TASK;
82 84
@@ -86,7 +88,7 @@ notify_connect_internal (void *cls,
86 if (cc->cb != NULL) 88 if (cc->cb != NULL)
87 cc->cb (cc->p1, cc->p2, cc->cb_cls); 89 cc->cb (cc->p1, cc->p2, cc->cb_cls);
88 90
89 GNUNET_free(cc); 91 GNUNET_free (cc);
90 } 92 }
91} 93}
92 94
@@ -96,7 +98,8 @@ notify_connect (void *cls,
96 const struct GNUNET_TRANSPORT_ATS_Information *ats, 98 const struct GNUNET_TRANSPORT_ATS_Information *ats,
97 uint32_t ats_count) 99 uint32_t ats_count)
98{ 100{
99 struct PeerContext * p = cls; 101 struct PeerContext *p = cls;
102
100 if (p == NULL) 103 if (p == NULL)
101 return; 104 return;
102 if (p->nc != NULL) 105 if (p->nc != NULL)
@@ -106,7 +109,8 @@ notify_connect (void *cls,
106static void 109static void
107notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 110notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
108{ 111{
109 struct PeerContext * p = cls; 112 struct PeerContext *p = cls;
113
110 if (p == NULL) 114 if (p == NULL)
111 return; 115 return;
112 if (p->nd != NULL) 116 if (p->nd != NULL)
@@ -120,7 +124,8 @@ notify_receive (void *cls,
120 const struct GNUNET_TRANSPORT_ATS_Information *ats, 124 const struct GNUNET_TRANSPORT_ATS_Information *ats,
121 uint32_t ats_count) 125 uint32_t ats_count)
122{ 126{
123 struct PeerContext * p = cls; 127 struct PeerContext *p = cls;
128
124 if (p == NULL) 129 if (p == NULL)
125 return; 130 return;
126 if (p->rec != NULL) 131 if (p->rec != NULL)
@@ -129,18 +134,18 @@ notify_receive (void *cls,
129 134
130 135
131static void 136static void
132exchange_hello_last (void *cb_cls, 137exchange_hello_last (void *cb_cls, const struct GNUNET_MessageHeader *message)
133 const struct GNUNET_MessageHeader *message)
134{ 138{
135 struct ConnectingContext * cc = cb_cls; 139 struct ConnectingContext *cc = cb_cls;
136 struct PeerContext *me = cc->p2; 140 struct PeerContext *me = cc->p2;
141
137 //struct PeerContext *p1 = cc->p1; 142 //struct PeerContext *p1 = cc->p1;
138 143
139 GNUNET_assert (message != NULL); 144 GNUNET_assert (message != NULL);
140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
141 "Exchanging HELLO of size %d with peer (%s)!\n", 146 "Exchanging HELLO of size %d with peer (%s)!\n",
142 (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), 147 (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
143 GNUNET_i2s (&me->id)); 148 message), GNUNET_i2s (&me->id));
144 GNUNET_assert (GNUNET_OK == 149 GNUNET_assert (GNUNET_OK ==
145 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 150 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
146 message, &me->id)); 151 message, &me->id));
@@ -149,11 +154,11 @@ exchange_hello_last (void *cb_cls,
149 154
150 155
151static void 156static void
152exchange_hello (void *cb_cls, 157exchange_hello (void *cb_cls, const struct GNUNET_MessageHeader *message)
153 const struct GNUNET_MessageHeader *message)
154{ 158{
155 struct ConnectingContext * cc = cb_cls; 159 struct ConnectingContext *cc = cb_cls;
156 struct PeerContext *me = cc->p1; 160 struct PeerContext *me = cc->p1;
161
157 //struct PeerContext *p2 = cc->p2; 162 //struct PeerContext *p2 = cc->p2;
158 163
159 GNUNET_assert (message != NULL); 164 GNUNET_assert (message != NULL);
@@ -162,34 +167,29 @@ exchange_hello (void *cb_cls,
162 message, &me->id)); 167 message, &me->id));
163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
164 "Exchanging HELLO of size %d from peer %s!\n", 169 "Exchanging HELLO of size %d from peer %s!\n",
165 (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), 170 (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
166 GNUNET_i2s (&me->id)); 171 message), GNUNET_i2s (&me->id));
167 GNUNET_TRANSPORT_offer_hello (cc->th_p2, message, NULL, NULL); 172 GNUNET_TRANSPORT_offer_hello (cc->th_p2, message, NULL, NULL);
168} 173}
169 174
170static void 175static void
171try_connect (void *cls, 176try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
172 const struct GNUNET_SCHEDULER_TaskContext *tc)
173{ 177{
174 struct ConnectingContext * cc = cls; 178 struct ConnectingContext *cc = cls;
175 struct PeerContext *p1 = cc->p1; 179 struct PeerContext *p1 = cc->p1;
176 struct PeerContext *p2 = cc->p2; 180 struct PeerContext *p2 = cc->p2;
177 181
178 cc->tct = GNUNET_SCHEDULER_NO_TASK; 182 cc->tct = GNUNET_SCHEDULER_NO_TASK;
179 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 183 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
180 return; 184 return;
181 185
182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking peers to connect...\n");
183 "Asking peers to connect...\n");
184 /* FIXME: 'pX.id' may still be all-zeros here... */ 187 /* FIXME: 'pX.id' may still be all-zeros here... */
185 GNUNET_TRANSPORT_try_connect (cc->th_p1, 188 GNUNET_TRANSPORT_try_connect (cc->th_p1, &p2->id);
186 &p2->id); 189 GNUNET_TRANSPORT_try_connect (cc->th_p2, &p1->id);
187 GNUNET_TRANSPORT_try_connect (cc->th_p2,
188 &p1->id);
189 190
190 cc->tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 191 cc->tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
191 &try_connect, 192 &try_connect, cc);
192 cc);
193} 193}
194 194
195 195
@@ -202,30 +202,30 @@ try_connect (void *cls,
202 * @return the peer context 202 * @return the peer context
203 */ 203 */
204struct PeerContext * 204struct PeerContext *
205GNUNET_TRANSPORT_TESTING_start_peer (const char * cfgname, 205GNUNET_TRANSPORT_TESTING_start_peer (const char *cfgname,
206 GNUNET_TRANSPORT_ReceiveCallback rec, 206 GNUNET_TRANSPORT_ReceiveCallback rec,
207 GNUNET_TRANSPORT_NotifyConnect nc, 207 GNUNET_TRANSPORT_NotifyConnect nc,
208 GNUNET_TRANSPORT_NotifyDisconnect nd, 208 GNUNET_TRANSPORT_NotifyDisconnect nd,
209 void * cb_cls) 209 void *cb_cls)
210{ 210{
211 struct PeerContext * p = GNUNET_malloc (sizeof (struct PeerContext)); 211 struct PeerContext *p = GNUNET_malloc (sizeof (struct PeerContext));
212 212
213 p->cfg = GNUNET_CONFIGURATION_create (); 213 p->cfg = GNUNET_CONFIGURATION_create ();
214 214
215 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 215 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
216 if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME")) 216 if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME"))
217 GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", &p->servicehome); 217 GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME",
218 &p->servicehome);
218 if (NULL != p->servicehome) 219 if (NULL != p->servicehome)
219 GNUNET_DISK_directory_remove (p->servicehome); 220 GNUNET_DISK_directory_remove (p->servicehome);
220 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 221 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
221 "gnunet-service-arm", 222 "gnunet-service-arm", "-c", cfgname,
222 "-c", cfgname,
223#if VERBOSE_PEERS 223#if VERBOSE_PEERS
224 "-L", "DEBUG", 224 "-L", "DEBUG",
225#else 225#else
226 "-L", "ERROR", 226 "-L", "ERROR",
227#endif 227#endif
228 NULL); 228 NULL);
229 p->nc = nc; 229 p->nc = nc;
230 p->nd = nd; 230 p->nd = nd;
231 p->rec = rec; 231 p->rec = rec;
@@ -234,11 +234,10 @@ GNUNET_TRANSPORT_TESTING_start_peer (const char * cfgname,
234 else 234 else
235 p->cb_cls = p; 235 p->cb_cls = p;
236 236
237 p->th = GNUNET_TRANSPORT_connect(p->cfg, NULL, 237 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL,
238 p, 238 p,
239 &notify_receive, 239 &notify_receive,
240 &notify_connect, 240 &notify_connect, &notify_disconnect);
241 &notify_disconnect);
242 GNUNET_assert (p->th != NULL); 241 GNUNET_assert (p->th != NULL);
243 return p; 242 return p;
244} 243}
@@ -248,25 +247,25 @@ GNUNET_TRANSPORT_TESTING_start_peer (const char * cfgname,
248 * @param p the peer 247 * @param p the peer
249 */ 248 */
250void 249void
251GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext * p) 250GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext *p)
252{ 251{
253 if (p->th != NULL) 252 if (p->th != NULL)
254 GNUNET_TRANSPORT_disconnect(p->th); 253 GNUNET_TRANSPORT_disconnect (p->th);
255 254
256 if (NULL != p->arm_proc) 255 if (NULL != p->arm_proc)
257 { 256 {
258 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 257 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
259 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 258 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
260 GNUNET_OS_process_wait (p->arm_proc); 259 GNUNET_OS_process_wait (p->arm_proc);
261 GNUNET_OS_process_close (p->arm_proc); 260 GNUNET_OS_process_close (p->arm_proc);
262 p->arm_proc = NULL; 261 p->arm_proc = NULL;
263 } 262 }
264 GNUNET_CONFIGURATION_destroy (p->cfg); 263 GNUNET_CONFIGURATION_destroy (p->cfg);
265 if (p->servicehome != NULL) 264 if (p->servicehome != NULL)
266 { 265 {
267 GNUNET_DISK_directory_remove (p->servicehome); 266 GNUNET_DISK_directory_remove (p->servicehome);
268 GNUNET_free(p->servicehome); 267 GNUNET_free (p->servicehome);
269 } 268 }
270 GNUNET_free (p); 269 GNUNET_free (p);
271} 270}
272 271
@@ -280,12 +279,13 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext * p)
280 * @param cb_cls callback cls 279 * @param cb_cls callback cls
281 */ 280 */
282void 281void
283GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext * p1, 282GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext *p1,
284 struct PeerContext * p2, 283 struct PeerContext *p2,
285 GNUNET_TRANSPORT_TESTING_connect_cb cb, 284 GNUNET_TRANSPORT_TESTING_connect_cb cb,
286 void * cb_cls) 285 void *cb_cls)
287{ 286{
288 struct ConnectingContext * cc = GNUNET_malloc (sizeof (struct ConnectingContext)); 287 struct ConnectingContext *cc =
288 GNUNET_malloc (sizeof (struct ConnectingContext));
289 289
290 GNUNET_assert (p1 != NULL); 290 GNUNET_assert (p1 != NULL);
291 GNUNET_assert (p2 != NULL); 291 GNUNET_assert (p2 != NULL);
@@ -296,17 +296,13 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext * p1,
296 cc->cb = cb; 296 cc->cb = cb;
297 cc->cb_cls = cb_cls; 297 cc->cb_cls = cb_cls;
298 298
299 cc->th_p1 = GNUNET_TRANSPORT_connect(cc->p1->cfg, NULL, 299 cc->th_p1 = GNUNET_TRANSPORT_connect (cc->p1->cfg, NULL,
300 cc, 300 cc,
301 NULL, 301 NULL, &notify_connect_internal, NULL);
302 &notify_connect_internal, 302
303 NULL); 303 cc->th_p2 = GNUNET_TRANSPORT_connect (cc->p2->cfg, NULL,
304 304 cc,
305 cc->th_p2 = GNUNET_TRANSPORT_connect(cc->p2->cfg, NULL, 305 NULL, &notify_connect_internal, NULL);
306 cc,
307 NULL,
308 &notify_connect_internal,
309 NULL);
310 306
311 GNUNET_assert (cc->th_p1 != NULL); 307 GNUNET_assert (cc->th_p1 != NULL);
312 GNUNET_assert (cc->th_p2 != NULL); 308 GNUNET_assert (cc->th_p2 != NULL);