aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_clients.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-service-transport_clients.c')
-rw-r--r--src/transport/gnunet-service-transport_clients.c533
1 files changed, 253 insertions, 280 deletions
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
index ca686057d..542e3e00b 100644
--- a/src/transport/gnunet-service-transport_clients.c
+++ b/src/transport/gnunet-service-transport_clients.c
@@ -134,13 +134,13 @@ lookup_client (struct GNUNET_SERVER_Client *client)
134{ 134{
135 struct TransportClient *tc; 135 struct TransportClient *tc;
136 136
137 tc = clients_head; 137 tc = clients_head;
138 while (tc != NULL) 138 while (tc != NULL)
139 { 139 {
140 if (tc->client == client) 140 if (tc->client == client)
141 return tc; 141 return tc;
142 tc = tc->next; 142 tc = tc->next;
143 } 143 }
144 return NULL; 144 return NULL;
145} 145}
146 146
@@ -155,12 +155,10 @@ static struct TransportClient *
155setup_client (struct GNUNET_SERVER_Client *client) 155setup_client (struct GNUNET_SERVER_Client *client)
156{ 156{
157 struct TransportClient *tc; 157 struct TransportClient *tc;
158 158
159 tc = GNUNET_malloc (sizeof (struct TransportClient)); 159 tc = GNUNET_malloc (sizeof (struct TransportClient));
160 tc->client = client; 160 tc->client = client;
161 GNUNET_CONTAINER_DLL_insert (clients_head, 161 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc);
162 clients_tail,
163 tc);
164 return tc; 162 return tc;
165} 163}
166 164
@@ -176,9 +174,7 @@ setup_client (struct GNUNET_SERVER_Client *client)
176 * @return number of bytes written to buf 174 * @return number of bytes written to buf
177 */ 175 */
178static size_t 176static size_t
179transmit_to_client_callback (void *cls, 177transmit_to_client_callback (void *cls, size_t size, void *buf)
180 size_t size,
181 void *buf)
182{ 178{
183 struct TransportClient *tc = cls; 179 struct TransportClient *tc = cls;
184 struct ClientMessageQueueEntry *q; 180 struct ClientMessageQueueEntry *q;
@@ -189,46 +185,43 @@ transmit_to_client_callback (void *cls,
189 185
190 tc->th = NULL; 186 tc->th = NULL;
191 if (buf == NULL) 187 if (buf == NULL)
192 { 188 {
193#if DEBUG_TRANSPORT 189#if DEBUG_TRANSPORT
194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
195 "Transmission to client failed, closing connection.\n"); 191 "Transmission to client failed, closing connection.\n");
196#endif 192#endif
197 return 0; 193 return 0;
198 } 194 }
199 cbuf = buf; 195 cbuf = buf;
200 tsize = 0; 196 tsize = 0;
201 while (NULL != (q = tc->message_queue_head)) 197 while (NULL != (q = tc->message_queue_head))
202 { 198 {
203 msg = (const struct GNUNET_MessageHeader *) &q[1]; 199 msg = (const struct GNUNET_MessageHeader *) &q[1];
204 msize = ntohs (msg->size); 200 msize = ntohs (msg->size);
205 if (msize + tsize > size) 201 if (msize + tsize > size)
206 break; 202 break;
207#if DEBUG_TRANSPORT 203#if DEBUG_TRANSPORT
208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
209 "Transmitting message of type %u to client.\n", 205 "Transmitting message of type %u to client.\n",
210 ntohs (msg->type)); 206 ntohs (msg->type));
211#endif 207#endif
212 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head, 208 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head,
213 tc->message_queue_tail, 209 tc->message_queue_tail, q);
214 q); 210 tc->message_count--;
215 tc->message_count--; 211 memcpy (&cbuf[tsize], msg, msize);
216 memcpy (&cbuf[tsize], 212 GNUNET_free (q);
217 msg, 213 tsize += msize;
218 msize); 214 }
219 GNUNET_free (q);
220 tsize += msize;
221 }
222 if (NULL != q) 215 if (NULL != q)
223 { 216 {
224 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); 217 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
225 tc->th = GNUNET_SERVER_notify_transmit_ready (tc->client, 218 tc->th = GNUNET_SERVER_notify_transmit_ready (tc->client,
226 msize, 219 msize,
227 GNUNET_TIME_UNIT_FOREVER_REL, 220 GNUNET_TIME_UNIT_FOREVER_REL,
228 &transmit_to_client_callback, 221 &transmit_to_client_callback,
229 tc); 222 tc);
230 GNUNET_assert (tc->th != NULL); 223 GNUNET_assert (tc->th != NULL);
231 } 224 }
232 return tsize; 225 return tsize;
233} 226}
234 227
@@ -242,43 +235,39 @@ transmit_to_client_callback (void *cls,
242 */ 235 */
243static void 236static void
244unicast (struct TransportClient *tc, 237unicast (struct TransportClient *tc,
245 const struct GNUNET_MessageHeader *msg, 238 const struct GNUNET_MessageHeader *msg, int may_drop)
246 int may_drop)
247{ 239{
248 struct ClientMessageQueueEntry *q; 240 struct ClientMessageQueueEntry *q;
249 uint16_t msize; 241 uint16_t msize;
250 242
251 if ( (tc->message_count >= MAX_PENDING) && 243 if ((tc->message_count >= MAX_PENDING) && (GNUNET_YES == may_drop))
252 (GNUNET_YES == may_drop) ) 244 {
253 { 245 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
254 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 246 _
255 _("Dropping message of type %u and size %u, have %u/%u messages pending\n"), 247 ("Dropping message of type %u and size %u, have %u/%u messages pending\n"),
256 ntohs (msg->type), 248 ntohs (msg->type), ntohs (msg->size), tc->message_count,
257 ntohs (msg->size), 249 MAX_PENDING);
258 tc->message_count, 250 GNUNET_STATISTICS_update (GST_stats,
259 MAX_PENDING); 251 gettext_noop
260 GNUNET_STATISTICS_update (GST_stats, 252 ("# messages dropped due to slow client"), 1,
261 gettext_noop ("# messages dropped due to slow client"), 253 GNUNET_NO);
262 1, 254 return;
263 GNUNET_NO); 255 }
264 return;
265 }
266 msize = ntohs (msg->size); 256 msize = ntohs (msg->size);
267 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); 257 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
268 q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize); 258 q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize);
269 memcpy (&q[1], msg, msize); 259 memcpy (&q[1], msg, msize);
270 GNUNET_CONTAINER_DLL_insert_tail (tc->message_queue_head, 260 GNUNET_CONTAINER_DLL_insert_tail (tc->message_queue_head,
271 tc->message_queue_tail, 261 tc->message_queue_tail, q);
272 q);
273 tc->message_count++; 262 tc->message_count++;
274 if (tc->th != NULL) 263 if (tc->th != NULL)
275 return; 264 return;
276 tc->th = GNUNET_SERVER_notify_transmit_ready (tc->client, 265 tc->th = GNUNET_SERVER_notify_transmit_ready (tc->client,
277 msize, 266 msize,
278 GNUNET_TIME_UNIT_FOREVER_REL, 267 GNUNET_TIME_UNIT_FOREVER_REL,
279 &transmit_to_client_callback, 268 &transmit_to_client_callback,
280 tc); 269 tc);
281 GNUNET_assert (tc->th != NULL); 270 GNUNET_assert (tc->th != NULL);
282} 271}
283 272
284 273
@@ -290,8 +279,7 @@ unicast (struct TransportClient *tc,
290 * @param client identification of the client 279 * @param client identification of the client
291 */ 280 */
292static void 281static void
293client_disconnect_notification (void *cls, 282client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
294 struct GNUNET_SERVER_Client *client)
295{ 283{
296 struct TransportClient *tc; 284 struct TransportClient *tc;
297 struct ClientMessageQueueEntry *mqe; 285 struct ClientMessageQueueEntry *mqe;
@@ -306,21 +294,18 @@ client_disconnect_notification (void *cls,
306 "Client disconnected, cleaning up.\n"); 294 "Client disconnected, cleaning up.\n");
307#endif 295#endif
308 while (NULL != (mqe = tc->message_queue_head)) 296 while (NULL != (mqe = tc->message_queue_head))
309 { 297 {
310 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head, 298 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head,
311 tc->message_queue_tail, 299 tc->message_queue_tail, mqe);
312 mqe); 300 tc->message_count--;
313 tc->message_count--; 301 GNUNET_free (mqe);
314 GNUNET_free (mqe); 302 }
315 } 303 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc);
316 GNUNET_CONTAINER_DLL_remove (clients_head,
317 clients_tail,
318 tc);
319 if (tc->th != NULL) 304 if (tc->th != NULL)
320 { 305 {
321 GNUNET_CONNECTION_notify_transmit_ready_cancel (tc->th); 306 GNUNET_CONNECTION_notify_transmit_ready_cancel (tc->th);
322 tc->th = NULL; 307 tc->th = NULL;
323 } 308 }
324 GNUNET_break (0 == tc->message_count); 309 GNUNET_break (0 == tc->message_count);
325 GNUNET_free (tc); 310 GNUNET_free (tc);
326} 311}
@@ -337,24 +322,25 @@ client_disconnect_notification (void *cls,
337 */ 322 */
338static void 323static void
339notify_client_about_neighbour (void *cls, 324notify_client_about_neighbour (void *cls,
340 const struct GNUNET_PeerIdentity *peer, 325 const struct GNUNET_PeerIdentity *peer,
341 const struct GNUNET_TRANSPORT_ATS_Information *ats, 326 const struct GNUNET_TRANSPORT_ATS_Information
342 uint32_t ats_count) 327 *ats, uint32_t ats_count)
343{ 328{
344 struct TransportClient *tc = cls; 329 struct TransportClient *tc = cls;
345 struct ConnectInfoMessage *cim; 330 struct ConnectInfoMessage *cim;
346 size_t size; 331 size_t size;
347 332
348 size = sizeof (struct ConnectInfoMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 333 size =
334 sizeof (struct ConnectInfoMessage) +
335 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
349 GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); 336 GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
350 cim = GNUNET_malloc (size); 337 cim = GNUNET_malloc (size);
351 cim->header.size = htons (size); 338 cim->header.size = htons (size);
352 cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 339 cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
353 cim->ats_count = htonl(ats_count); 340 cim->ats_count = htonl (ats_count);
354 cim->id = *peer; 341 cim->id = *peer;
355 memcpy (&cim->ats, 342 memcpy (&cim->ats,
356 ats, 343 ats, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
357 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
358 unicast (tc, &cim->header, GNUNET_NO); 344 unicast (tc, &cim->header, GNUNET_NO);
359 GNUNET_free (cim); 345 GNUNET_free (cim);
360} 346}
@@ -371,35 +357,35 @@ notify_client_about_neighbour (void *cls,
371 */ 357 */
372static void 358static void
373clients_handle_start (void *cls, 359clients_handle_start (void *cls,
374 struct GNUNET_SERVER_Client *client, 360 struct GNUNET_SERVER_Client *client,
375 const struct GNUNET_MessageHeader *message) 361 const struct GNUNET_MessageHeader *message)
376{ 362{
377 const struct StartMessage *start; 363 const struct StartMessage *start;
378 struct TransportClient *tc; 364 struct TransportClient *tc;
379 365
380 tc = lookup_client (client); 366 tc = lookup_client (client);
381 if (tc != NULL) 367 if (tc != NULL)
382 { 368 {
383 /* got 'start' twice from the same client, not allowed */ 369 /* got 'start' twice from the same client, not allowed */
384 GNUNET_break (0); 370 GNUNET_break (0);
385 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 371 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
386 return; 372 return;
387 } 373 }
388 start = (const struct StartMessage*) message; 374 start = (const struct StartMessage *) message;
389 if ( (GNUNET_NO != ntohl (start->do_check)) && 375 if ((GNUNET_NO != ntohl (start->do_check)) &&
390 (0 != memcmp (&start->self, 376 (0 != memcmp (&start->self,
391 &GST_my_identity, 377 &GST_my_identity, sizeof (struct GNUNET_PeerIdentity))))
392 sizeof (struct GNUNET_PeerIdentity))) ) 378 {
393 { 379 /* client thinks this is a different peer, reject */
394 /* client thinks this is a different peer, reject */ 380 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
395 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 381 _
396 _("Rejecting control connection from peer `%s', which is not me!\n"), 382 ("Rejecting control connection from peer `%s', which is not me!\n"),
397 GNUNET_i2s (&start->self)); 383 GNUNET_i2s (&start->self));
398 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 384 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
399 return; 385 return;
400 } 386 }
401 tc = setup_client (client); 387 tc = setup_client (client);
402 unicast (tc, GST_hello_get(), GNUNET_NO); 388 unicast (tc, GST_hello_get (), GNUNET_NO);
403 GST_neighbours_iterate (&notify_client_about_neighbour, tc); 389 GST_neighbours_iterate (&notify_client_about_neighbour, tc);
404 GNUNET_SERVER_receive_done (client, GNUNET_OK); 390 GNUNET_SERVER_receive_done (client, GNUNET_OK);
405} 391}
@@ -414,8 +400,8 @@ clients_handle_start (void *cls,
414 */ 400 */
415static void 401static void
416clients_handle_hello (void *cls, 402clients_handle_hello (void *cls,
417 struct GNUNET_SERVER_Client *client, 403 struct GNUNET_SERVER_Client *client,
418 const struct GNUNET_MessageHeader *message) 404 const struct GNUNET_MessageHeader *message)
419{ 405{
420 GST_validation_handle_hello (message); 406 GST_validation_handle_hello (message);
421 GNUNET_SERVER_receive_done (client, GNUNET_OK); 407 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -447,8 +433,7 @@ struct SendTransmitContinuationContext
447 * @param success GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR if we're not connected 433 * @param success GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR if we're not connected
448 */ 434 */
449static void 435static void
450handle_send_transmit_continuation (void *cls, 436handle_send_transmit_continuation (void *cls, int success)
451 int success)
452{ 437{
453 struct SendTransmitContinuationContext *stcc = cls; 438 struct SendTransmitContinuationContext *stcc = cls;
454 struct SendOkMessage send_ok_msg; 439 struct SendOkMessage send_ok_msg;
@@ -456,9 +441,10 @@ handle_send_transmit_continuation (void *cls,
456 send_ok_msg.header.size = htons (sizeof (send_ok_msg)); 441 send_ok_msg.header.size = htons (sizeof (send_ok_msg));
457 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); 442 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
458 send_ok_msg.success = htonl (success); 443 send_ok_msg.success = htonl (success);
459 send_ok_msg.latency = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_FOREVER_REL); 444 send_ok_msg.latency =
445 GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_FOREVER_REL);
460 send_ok_msg.peer = stcc->target; 446 send_ok_msg.peer = stcc->target;
461 GST_clients_unicast (stcc->client, &send_ok_msg.header, GNUNET_NO); 447 GST_clients_unicast (stcc->client, &send_ok_msg.header, GNUNET_NO);
462 GNUNET_SERVER_client_drop (stcc->client); 448 GNUNET_SERVER_client_drop (stcc->client);
463 GNUNET_free (stcc); 449 GNUNET_free (stcc);
464} 450}
@@ -473,8 +459,8 @@ handle_send_transmit_continuation (void *cls,
473 */ 459 */
474static void 460static void
475clients_handle_send (void *cls, 461clients_handle_send (void *cls,
476 struct GNUNET_SERVER_Client *client, 462 struct GNUNET_SERVER_Client *client,
477 const struct GNUNET_MessageHeader *message) 463 const struct GNUNET_MessageHeader *message)
478{ 464{
479 const struct OutboundMessage *obm; 465 const struct OutboundMessage *obm;
480 const struct GNUNET_MessageHeader *obmm; 466 const struct GNUNET_MessageHeader *obmm;
@@ -483,56 +469,52 @@ clients_handle_send (void *cls,
483 uint16_t msize; 469 uint16_t msize;
484 470
485 size = ntohs (message->size); 471 size = ntohs (message->size);
486 if (size < sizeof (struct OutboundMessage) + sizeof (struct GNUNET_MessageHeader)) 472 if (size <
487 { 473 sizeof (struct OutboundMessage) + sizeof (struct GNUNET_MessageHeader))
488 GNUNET_break (0); 474 {
489 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 475 GNUNET_break (0);
490 return; 476 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
491 } 477 return;
478 }
492 obm = (const struct OutboundMessage *) message; 479 obm = (const struct OutboundMessage *) message;
493 obmm = (const struct GNUNET_MessageHeader *) &obm[1]; 480 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
494 msize = size - sizeof (struct OutboundMessage); 481 msize = size - sizeof (struct OutboundMessage);
495 if (msize < sizeof (struct GNUNET_MessageHeader)) 482 if (msize < sizeof (struct GNUNET_MessageHeader))
496 { 483 {
497 GNUNET_break (0); 484 GNUNET_break (0);
498 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 485 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
499 return; 486 return;
500 } 487 }
501 GNUNET_STATISTICS_update (GST_stats, 488 GNUNET_STATISTICS_update (GST_stats,
502 gettext_noop ("# bytes payload received for other peers"), 489 gettext_noop
503 msize, 490 ("# bytes payload received for other peers"), msize,
504 GNUNET_NO); 491 GNUNET_NO);
505#if DEBUG_TRANSPORT 492#if DEBUG_TRANSPORT
506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 493 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
507 "Received `%s' request from client with target `%4s' and first message of type %u and total size %u\n", 494 "Received `%s' request from client with target `%4s' and first message of type %u and total size %u\n",
508 "SEND", 495 "SEND", GNUNET_i2s (&obm->peer), ntohs (obmm->type), msize);
509 GNUNET_i2s (&obm->peer),
510 ntohs (obmm->type),
511 msize);
512#endif 496#endif
513 if (GNUNET_NO == 497 if (GNUNET_NO == GST_neighbours_test_connected (&obm->peer))
514 GST_neighbours_test_connected (&obm->peer)) 498 {
515 { 499 /* not connected, not allowed to send; can happen due to asynchronous operations */
516 /* not connected, not allowed to send; can happen due to asynchronous operations */ 500 GNUNET_STATISTICS_update (GST_stats,
517 GNUNET_STATISTICS_update (GST_stats, 501 gettext_noop
518 gettext_noop ("# bytes payload dropped (other peer was not connected)"), 502 ("# bytes payload dropped (other peer was not connected)"),
519 msize, 503 msize, GNUNET_NO);
520 GNUNET_NO); 504 GNUNET_SERVER_receive_done (client, GNUNET_OK);
521 GNUNET_SERVER_receive_done (client, GNUNET_OK); 505 return;
522 return; 506 }
523 }
524 GNUNET_SERVER_receive_done (client, GNUNET_OK); 507 GNUNET_SERVER_receive_done (client, GNUNET_OK);
525 stcc = GNUNET_malloc (sizeof (struct SendTransmitContinuationContext)); 508 stcc = GNUNET_malloc (sizeof (struct SendTransmitContinuationContext));
526 stcc->target = obm->peer; 509 stcc->target = obm->peer;
527 stcc->client = client; 510 stcc->client = client;
528 GNUNET_SERVER_client_keep (client); 511 GNUNET_SERVER_client_keep (client);
529 GST_neighbours_send (&obm->peer, 512 GST_neighbours_send (&obm->peer,
530 obmm, msize, 513 obmm, msize,
531 GNUNET_TIME_relative_ntoh (obm->timeout), 514 GNUNET_TIME_relative_ntoh (obm->timeout),
532 &handle_send_transmit_continuation, 515 &handle_send_transmit_continuation, stcc);
533 stcc);
534} 516}
535 517
536 518
537/** 519/**
538 * Try to initiate a connection to the given peer if the blacklist 520 * Try to initiate a connection to the given peer if the blacklist
@@ -545,11 +527,10 @@ clients_handle_send (void *cls,
545 */ 527 */
546static void 528static void
547try_connect_if_allowed (void *cls, 529try_connect_if_allowed (void *cls,
548 const struct GNUNET_PeerIdentity *peer, 530 const struct GNUNET_PeerIdentity *peer, int result)
549 int result)
550{ 531{
551 if (GNUNET_OK != result) 532 if (GNUNET_OK != result)
552 return; /* not allowed */ 533 return; /* not allowed */
553 GST_neighbours_try_connect (peer); 534 GST_neighbours_try_connect (peer);
554} 535}
555 536
@@ -563,23 +544,23 @@ try_connect_if_allowed (void *cls,
563 */ 544 */
564static void 545static void
565clients_handle_request_connect (void *cls, 546clients_handle_request_connect (void *cls,
566 struct GNUNET_SERVER_Client *client, 547 struct GNUNET_SERVER_Client *client,
567 const struct GNUNET_MessageHeader *message) 548 const struct GNUNET_MessageHeader *message)
568{ 549{
569 const struct TransportRequestConnectMessage *trcm = 550 const struct TransportRequestConnectMessage *trcm =
570 (const struct TransportRequestConnectMessage *) message; 551 (const struct TransportRequestConnectMessage *) message;
571 552
572 GNUNET_STATISTICS_update (GST_stats, 553 GNUNET_STATISTICS_update (GST_stats,
573 gettext_noop ("# REQUEST CONNECT messages received"), 554 gettext_noop
574 1, 555 ("# REQUEST CONNECT messages received"), 1,
575 GNUNET_NO); 556 GNUNET_NO);
576#if DEBUG_TRANSPORT 557#if DEBUG_TRANSPORT
577 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 558 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
578 "Received a request connect message for peer `%s'\n", 559 "Received a request connect message for peer `%s'\n",
579 GNUNET_i2s(&trcm->peer)); 560 GNUNET_i2s (&trcm->peer));
580#endif 561#endif
581 (void) GST_blacklist_test_allowed (&trcm->peer, NULL, 562 (void) GST_blacklist_test_allowed (&trcm->peer, NULL,
582 &try_connect_if_allowed, NULL); 563 &try_connect_if_allowed, NULL);
583 GNUNET_SERVER_receive_done (client, GNUNET_OK); 564 GNUNET_SERVER_receive_done (client, GNUNET_OK);
584} 565}
585 566
@@ -593,25 +574,23 @@ clients_handle_request_connect (void *cls,
593 */ 574 */
594static void 575static void
595clients_handle_set_quota (void *cls, 576clients_handle_set_quota (void *cls,
596 struct GNUNET_SERVER_Client *client, 577 struct GNUNET_SERVER_Client *client,
597 const struct GNUNET_MessageHeader *message) 578 const struct GNUNET_MessageHeader *message)
598{ 579{
599 const struct QuotaSetMessage *qsm; 580 const struct QuotaSetMessage *qsm;
600 581
601 qsm = (const struct QuotaSetMessage *) message; 582 qsm = (const struct QuotaSetMessage *) message;
602 GNUNET_STATISTICS_update (GST_stats, 583 GNUNET_STATISTICS_update (GST_stats,
603 gettext_noop ("# SET QUOTA messages received"), 584 gettext_noop ("# SET QUOTA messages received"),
604 1, 585 1, GNUNET_NO);
605 GNUNET_NO); 586#if DEBUG_TRANSPORT
606#if DEBUG_TRANSPORT
607 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
608 "Received `%s' request (new quota %u) from client for peer `%4s'\n", 588 "Received `%s' request (new quota %u) from client for peer `%4s'\n",
609 "SET_QUOTA", 589 "SET_QUOTA",
610 (unsigned int) ntohl (qsm->quota.value__), 590 (unsigned int) ntohl (qsm->quota.value__),
611 GNUNET_i2s (&qsm->peer)); 591 GNUNET_i2s (&qsm->peer));
612#endif 592#endif
613 GST_neighbours_set_incoming_quota (&qsm->peer, 593 GST_neighbours_set_incoming_quota (&qsm->peer, qsm->quota);
614 qsm->quota);
615 GNUNET_SERVER_receive_done (client, GNUNET_OK); 594 GNUNET_SERVER_receive_done (client, GNUNET_OK);
616} 595}
617 596
@@ -624,22 +603,20 @@ clients_handle_set_quota (void *cls,
624 * @param address the resolved name, NULL to indicate the last response 603 * @param address the resolved name, NULL to indicate the last response
625 */ 604 */
626static void 605static void
627transmit_address_to_client (void *cls, 606transmit_address_to_client (void *cls, const char *address)
628 const char *address)
629{ 607{
630 struct GNUNET_SERVER_TransmitContext *tc = cls; 608 struct GNUNET_SERVER_TransmitContext *tc = cls;
631 609
632 if (NULL == address) 610 if (NULL == address)
633 { 611 {
634 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 612 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
635 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 613 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
636 GNUNET_SERVER_transmit_context_run (tc, 614 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
637 GNUNET_TIME_UNIT_FOREVER_REL); 615 return;
638 return; 616 }
639 } 617 GNUNET_SERVER_transmit_context_append_data (tc,
640 GNUNET_SERVER_transmit_context_append_data (tc, 618 address, strlen (address) + 1,
641 address, strlen (address) + 1, 619 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
642 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
643} 620}
644 621
645 622
@@ -652,8 +629,8 @@ transmit_address_to_client (void *cls,
652 */ 629 */
653static void 630static void
654clients_handle_address_lookup (void *cls, 631clients_handle_address_lookup (void *cls,
655 struct GNUNET_SERVER_Client *client, 632 struct GNUNET_SERVER_Client *client,
656 const struct GNUNET_MessageHeader *message) 633 const struct GNUNET_MessageHeader *message)
657{ 634{
658 const struct AddressLookupMessage *alum; 635 const struct AddressLookupMessage *alum;
659 struct GNUNET_TRANSPORT_PluginFunctions *papi; 636 struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -667,46 +644,45 @@ clients_handle_address_lookup (void *cls,
667 644
668 size = ntohs (message->size); 645 size = ntohs (message->size);
669 if (size < sizeof (struct AddressLookupMessage)) 646 if (size < sizeof (struct AddressLookupMessage))
670 { 647 {
671 GNUNET_break (0); 648 GNUNET_break (0);
672 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 649 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
673 return; 650 return;
674 } 651 }
675 alum = (const struct AddressLookupMessage *) message; 652 alum = (const struct AddressLookupMessage *) message;
676 address_len = ntohl (alum->addrlen); 653 address_len = ntohl (alum->addrlen);
677 if (size <= sizeof (struct AddressLookupMessage) + address_len) 654 if (size <= sizeof (struct AddressLookupMessage) + address_len)
678 { 655 {
679 GNUNET_break (0); 656 GNUNET_break (0);
680 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 657 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
681 return; 658 return;
682 } 659 }
683 address = (const char *) &alum[1]; 660 address = (const char *) &alum[1];
684 plugin_name = (const char *) &address[address_len]; 661 plugin_name = (const char *) &address[address_len];
685 if (plugin_name 662 if (plugin_name
686 [size - sizeof (struct AddressLookupMessage) - address_len - 1] != '\0') 663 [size - sizeof (struct AddressLookupMessage) - address_len - 1] != '\0')
687 { 664 {
688 GNUNET_break (0); 665 GNUNET_break (0);
689 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 666 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
690 return; 667 return;
691 } 668 }
692 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout); 669 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
693 numeric = ntohl (alum->numeric_only); 670 numeric = ntohl (alum->numeric_only);
694 tc = GNUNET_SERVER_transmit_context_create (client); 671 tc = GNUNET_SERVER_transmit_context_create (client);
695 papi = GST_plugins_find (plugin_name); 672 papi = GST_plugins_find (plugin_name);
696 if (NULL == papi) 673 if (NULL == papi)
697 { 674 {
698 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 675 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
699 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 676 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
700 GNUNET_SERVER_transmit_context_run (tc, rtimeout); 677 GNUNET_SERVER_transmit_context_run (tc, rtimeout);
701 return; 678 return;
702 } 679 }
703 GNUNET_SERVER_disable_receive_done_warning (client); 680 GNUNET_SERVER_disable_receive_done_warning (client);
704 papi->address_pretty_printer (papi->cls, 681 papi->address_pretty_printer (papi->cls,
705 plugin_name, 682 plugin_name,
706 address, address_len, 683 address, address_len,
707 numeric, 684 numeric,
708 rtimeout, 685 rtimeout, &transmit_address_to_client, tc);
709 &transmit_address_to_client, tc);
710} 686}
711 687
712 688
@@ -726,28 +702,26 @@ clients_handle_address_lookup (void *cls,
726 */ 702 */
727static void 703static void
728send_address_to_client (void *cls, 704send_address_to_client (void *cls,
729 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, 705 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
730 const struct GNUNET_PeerIdentity *target, 706 *public_key, const struct GNUNET_PeerIdentity *target,
731 struct GNUNET_TIME_Absolute valid_until, 707 struct GNUNET_TIME_Absolute valid_until,
732 struct GNUNET_TIME_Absolute validation_block, 708 struct GNUNET_TIME_Absolute validation_block,
733 const char *plugin_name, 709 const char *plugin_name, const void *plugin_address,
734 const void *plugin_address, 710 size_t plugin_address_len)
735 size_t plugin_address_len)
736{ 711{
737 struct GNUNET_SERVER_TransmitContext *tc = cls; 712 struct GNUNET_SERVER_TransmitContext *tc = cls;
738 char *addr_buf; 713 char *addr_buf;
739 714
740 /* FIXME: move to a binary format!!! */ 715 /* FIXME: move to a binary format!!! */
741 GNUNET_asprintf (&addr_buf, "%s --- %s, %s", 716 GNUNET_asprintf (&addr_buf, "%s --- %s, %s",
742 GST_plugins_a2s (plugin_name, 717 GST_plugins_a2s (plugin_name,
743 plugin_address, 718 plugin_address,
744 plugin_address_len), 719 plugin_address_len),
745 (GNUNET_YES == GST_neighbours_test_connected (target)) 720 (GNUNET_YES == GST_neighbours_test_connected (target))
746 ? "CONNECTED" 721 ? "CONNECTED"
747 : "DISCONNECTED", 722 : "DISCONNECTED",
748 (GNUNET_TIME_absolute_get_remaining (valid_until).rel_value > 0) 723 (GNUNET_TIME_absolute_get_remaining (valid_until).rel_value >
749 ? "VALIDATED" 724 0) ? "VALIDATED" : "UNVALIDATED");
750 : "UNVALIDATED");
751 transmit_address_to_client (tc, addr_buf); 725 transmit_address_to_client (tc, addr_buf);
752 GNUNET_free (addr_buf); 726 GNUNET_free (addr_buf);
753} 727}
@@ -764,8 +738,8 @@ send_address_to_client (void *cls,
764 */ 738 */
765static void 739static void
766clients_handle_peer_address_lookup (void *cls, 740clients_handle_peer_address_lookup (void *cls,
767 struct GNUNET_SERVER_Client *client, 741 struct GNUNET_SERVER_Client *client,
768 const struct GNUNET_MessageHeader *message) 742 const struct GNUNET_MessageHeader *message)
769{ 743{
770 const struct PeerAddressLookupMessage *peer_address_lookup; 744 const struct PeerAddressLookupMessage *peer_address_lookup;
771 struct GNUNET_SERVER_TransmitContext *tc; 745 struct GNUNET_SERVER_TransmitContext *tc;
@@ -774,13 +748,11 @@ clients_handle_peer_address_lookup (void *cls,
774 GNUNET_break (ntohl (peer_address_lookup->reserved) == 0); 748 GNUNET_break (ntohl (peer_address_lookup->reserved) == 0);
775 tc = GNUNET_SERVER_transmit_context_create (client); 749 tc = GNUNET_SERVER_transmit_context_create (client);
776 GST_validation_get_addresses (&peer_address_lookup->peer, 750 GST_validation_get_addresses (&peer_address_lookup->peer,
777 &send_address_to_client, 751 &send_address_to_client, tc);
778 tc);
779 GNUNET_SERVER_transmit_context_append_data (tc, 752 GNUNET_SERVER_transmit_context_append_data (tc,
780 NULL, 0, 753 NULL, 0,
781 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 754 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
782 GNUNET_SERVER_transmit_context_run (tc, 755 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
783 GNUNET_TIME_UNIT_FOREVER_REL);
784} 756}
785 757
786 758
@@ -794,18 +766,17 @@ clients_handle_peer_address_lookup (void *cls,
794 */ 766 */
795static void 767static void
796output_addresses (void *cls, 768output_addresses (void *cls,
797 const struct GNUNET_PeerIdentity *neighbour, 769 const struct GNUNET_PeerIdentity *neighbour,
798 const struct GNUNET_TRANSPORT_ATS_Information *ats, 770 const struct GNUNET_TRANSPORT_ATS_Information *ats,
799 uint32_t ats_count) 771 uint32_t ats_count)
800{ 772{
801 struct GNUNET_SERVER_TransmitContext *tc = cls; 773 struct GNUNET_SERVER_TransmitContext *tc = cls;
802 char *addr_buf; 774 char *addr_buf;
803 775
804 /* FIXME: move to a binary format!!! */ 776 /* FIXME: move to a binary format!!! */
805 GNUNET_asprintf (&addr_buf, 777 GNUNET_asprintf (&addr_buf,
806 "%s: %s", 778 "%s: %s",
807 GNUNET_i2s(neighbour), 779 GNUNET_i2s (neighbour), GST_plugins_a2s ("FIXME", NULL, 0));
808 GST_plugins_a2s ("FIXME", NULL, 0));
809 transmit_address_to_client (tc, addr_buf); 780 transmit_address_to_client (tc, addr_buf);
810 GNUNET_free (addr_buf); 781 GNUNET_free (addr_buf);
811} 782}
@@ -821,15 +792,14 @@ output_addresses (void *cls,
821 */ 792 */
822static void 793static void
823clients_handle_address_iterate (void *cls, 794clients_handle_address_iterate (void *cls,
824 struct GNUNET_SERVER_Client *client, 795 struct GNUNET_SERVER_Client *client,
825 const struct GNUNET_MessageHeader *message) 796 const struct GNUNET_MessageHeader *message)
826{ 797{
827 struct GNUNET_SERVER_TransmitContext *tc; 798 struct GNUNET_SERVER_TransmitContext *tc;
828 799
829 GNUNET_SERVER_disable_receive_done_warning (client); 800 GNUNET_SERVER_disable_receive_done_warning (client);
830 tc = GNUNET_SERVER_transmit_context_create (client); 801 tc = GNUNET_SERVER_transmit_context_create (client);
831 GST_neighbours_iterate (&output_addresses, 802 GST_neighbours_iterate (&output_addresses, tc);
832 tc);
833 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 803 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
834 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 804 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
835 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 805 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
@@ -841,30 +811,35 @@ clients_handle_address_iterate (void *cls,
841 * 811 *
842 * @param server server used to accept clients from. 812 * @param server server used to accept clients from.
843 */ 813 */
844void 814void
845GST_clients_start (struct GNUNET_SERVER_Handle *server) 815GST_clients_start (struct GNUNET_SERVER_Handle *server)
846{ 816{
847 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 817 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
848 { &clients_handle_start, NULL, 818 {&clients_handle_start, NULL,
849 GNUNET_MESSAGE_TYPE_TRANSPORT_START, sizeof (struct StartMessage)}, 819 GNUNET_MESSAGE_TYPE_TRANSPORT_START, sizeof (struct StartMessage)},
850 { &clients_handle_hello, NULL, 820 {&clients_handle_hello, NULL,
851 GNUNET_MESSAGE_TYPE_HELLO, 0}, 821 GNUNET_MESSAGE_TYPE_HELLO, 0},
852 { &clients_handle_send, NULL, 822 {&clients_handle_send, NULL,
853 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND , 0}, 823 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0},
854 { &clients_handle_request_connect, NULL, 824 {&clients_handle_request_connect, NULL,
855 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT, sizeof (struct TransportRequestConnectMessage)}, 825 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT,
856 { &clients_handle_set_quota, NULL, 826 sizeof (struct TransportRequestConnectMessage)},
857 GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, sizeof (struct QuotaSetMessage)}, 827 {&clients_handle_set_quota, NULL,
858 { &clients_handle_address_lookup, NULL, 828 GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, sizeof (struct QuotaSetMessage)},
859 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP , 0}, 829 {&clients_handle_address_lookup, NULL,
860 { &clients_handle_peer_address_lookup, NULL, 830 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP, 0},
861 GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP, sizeof (struct PeerAddressLookupMessage)}, 831 {&clients_handle_peer_address_lookup, NULL,
862 { &clients_handle_address_iterate, NULL, 832 GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP,
863 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE, sizeof (struct GNUNET_MessageHeader)}, 833 sizeof (struct PeerAddressLookupMessage)},
864 { &GST_blacklist_handle_init, NULL, 834 {&clients_handle_address_iterate, NULL,
865 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, sizeof (struct GNUNET_MessageHeader)}, 835 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE,
866 { &GST_blacklist_handle_reply, NULL, 836 sizeof (struct GNUNET_MessageHeader)},
867 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY, sizeof (struct BlacklistMessage)}, 837 {&GST_blacklist_handle_init, NULL,
838 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
839 sizeof (struct GNUNET_MessageHeader)},
840 {&GST_blacklist_handle_reply, NULL,
841 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
842 sizeof (struct BlacklistMessage)},
868 {NULL, NULL, 0, 0} 843 {NULL, NULL, 0, 0}
869 }; 844 };
870 GNUNET_SERVER_add_handlers (server, handlers); 845 GNUNET_SERVER_add_handlers (server, handlers);
@@ -890,8 +865,7 @@ GST_clients_stop ()
890 * @param may_drop GNUNET_YES if the message can be dropped 865 * @param may_drop GNUNET_YES if the message can be dropped
891 */ 866 */
892void 867void
893GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, 868GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop)
894 int may_drop)
895{ 869{
896 struct TransportClient *tc; 870 struct TransportClient *tc;
897 871
@@ -909,8 +883,7 @@ GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
909 */ 883 */
910void 884void
911GST_clients_unicast (struct GNUNET_SERVER_Client *client, 885GST_clients_unicast (struct GNUNET_SERVER_Client *client,
912 const struct GNUNET_MessageHeader *msg, 886 const struct GNUNET_MessageHeader *msg, int may_drop)
913 int may_drop)
914{ 887{
915 struct TransportClient *tc; 888 struct TransportClient *tc;
916 889