aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_clients.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-12 09:02:38 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-12 09:02:38 +0000
commitf76896d09afabb721219d3217037cc7a7f26d570 (patch)
treeb5910f5b68aa22954dcdca675017db18481a96d0 /src/transport/gnunet-service-transport_clients.c
parentd220651a00e92367387e6f0d881c8115fc9e2973 (diff)
downloadgnunet-f76896d09afabb721219d3217037cc7a7f26d570.tar.gz
gnunet-f76896d09afabb721219d3217037cc7a7f26d570.zip
implementing client's send
Diffstat (limited to 'src/transport/gnunet-service-transport_clients.c')
-rw-r--r--src/transport/gnunet-service-transport_clients.c99
1 files changed, 97 insertions, 2 deletions
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
index 5136e03f1..209b507cc 100644
--- a/src/transport/gnunet-service-transport_clients.c
+++ b/src/transport/gnunet-service-transport_clients.c
@@ -445,6 +445,48 @@ GST_clients_handle_hello (void *cls,
445 445
446 446
447/** 447/**
448 * Closure for 'handle_send_transmit_continuation'
449 */
450struct SendTransmitContinuationContext
451{
452 /**
453 * Client that made the request.
454 */
455 struct GNUNET_SERVER_Client *client;
456
457 /**
458 * Peer that was the target.
459 */
460 struct GNUNET_PeerIdentity target;
461};
462
463
464/**
465 * Function called after the transmission is done. Notify the client that it is
466 * OK to send the next message.
467 *
468 * @param cls closure
469 * @param success GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR if we're not connected
470 */
471static void
472handle_send_transmit_continuation (void *cls,
473 int success)
474{
475 struct SendTransmitContinuationContext *stcc = cls;
476 struct SendOkMessage send_ok_msg;
477
478 send_ok_msg.header.size = htons (sizeof (send_ok_msg));
479 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
480 send_ok_msg.success = htonl (success);
481 send_ok_msg.latency = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_FOREVER_REL);
482 send_ok_msg.peer = stcc->target;
483 GST_clients_unicast (stcc->client, &send_ok_msg.header, GNUNET_NO);
484 GNUNET_SERVER_client_drop (stcc->client);
485 GNUNET_free (stcc);
486}
487
488
489/**
448 * Client asked for transmission to a peer. Process the request. 490 * Client asked for transmission to a peer. Process the request.
449 * 491 *
450 * @param cls unused 492 * @param cls unused
@@ -456,8 +498,61 @@ GST_clients_handle_send (void *cls,
456 struct GNUNET_SERVER_Client *client, 498 struct GNUNET_SERVER_Client *client,
457 const struct GNUNET_MessageHeader *message) 499 const struct GNUNET_MessageHeader *message)
458{ 500{
459 /* FIXME */ 501 const struct OutboundMessage *obm;
460 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 502 const struct GNUNET_MessageHeader *obmm;
503 struct SendTransmitContinuationContext *stcc;
504 uint16_t size;
505 uint16_t msize;
506
507 size = ntohs (message->size);
508 if (size < sizeof (struct OutboundMessage) + sizeof (struct GNUNET_MessageHeader))
509 {
510 GNUNET_break (0);
511 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
512 return;
513 }
514 obm = (const struct OutboundMessage *) message;
515 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
516 msize = size - sizeof (struct OutboundMessage);
517 if (msize < sizeof (struct GNUNET_MessageHeader))
518 {
519 GNUNET_break (0);
520 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
521 return;
522 }
523 GNUNET_STATISTICS_update (GST_stats,
524 gettext_noop ("# bytes payload received for other peers"),
525 msize,
526 GNUNET_NO);
527#if DEBUG_TRANSPORT
528 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
529 "Received `%s' request from client with target `%4s' and first message of type %u and total size %u\n",
530 "SEND",
531 GNUNET_i2s (&obm->peer),
532 ntohs (obmm->type),
533 msize);
534#endif
535 if (GNUNET_NO ==
536 GST_neighbours_test_connected (&obm->peer))
537 {
538 /* not connected, not allowed to send; can happen due to asynchronous operations */
539 GNUNET_STATISTICS_update (GST_stats,
540 gettext_noop ("# bytes payload dropped (other peer was not connected)"),
541 msize,
542 GNUNET_NO);
543 GNUNET_SERVER_receive_done (client, GNUNET_OK);
544 return;
545 }
546 GNUNET_SERVER_receive_done (client, GNUNET_OK);
547 stcc = GNUNET_malloc (sizeof (struct SendTransmitContinuationContext));
548 stcc->target = obm->peer;
549 stcc->client = client;
550 GNUNET_SERVER_client_keep (client);
551 GST_neighbours_send (&obm->peer,
552 obmm, msize,
553 GNUNET_TIME_relative_ntoh (obm->timeout),
554 &handle_send_transmit_continuation,
555 stcc);
461} 556}
462 557
463 558