diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-12 09:02:38 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-12 09:02:38 +0000 |
commit | f76896d09afabb721219d3217037cc7a7f26d570 (patch) | |
tree | b5910f5b68aa22954dcdca675017db18481a96d0 /src | |
parent | d220651a00e92367387e6f0d881c8115fc9e2973 (diff) | |
download | gnunet-f76896d09afabb721219d3217037cc7a7f26d570.tar.gz gnunet-f76896d09afabb721219d3217037cc7a7f26d570.zip |
implementing client's send
Diffstat (limited to 'src')
4 files changed, 109 insertions, 11 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 | */ | ||
450 | struct 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 | */ | ||
471 | static void | ||
472 | handle_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 | ||
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index 742fa9caf..a7c1136f2 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c | |||
@@ -521,20 +521,21 @@ GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target) | |||
521 | * | 521 | * |
522 | * @param target destination | 522 | * @param target destination |
523 | * @param msg message to send | 523 | * @param msg message to send |
524 | * @param msg_size number of bytes in msg | ||
524 | * @param timeout when to fail with timeout | 525 | * @param timeout when to fail with timeout |
525 | * @param cont function to call when done | 526 | * @param cont function to call when done |
526 | * @param cont_cls closure for 'cont' | 527 | * @param cont_cls closure for 'cont' |
527 | */ | 528 | */ |
528 | void | 529 | void |
529 | GST_neighbours_send (const struct GNUNET_PeerIdentity *target, | 530 | GST_neighbours_send (const struct GNUNET_PeerIdentity *target, |
530 | const struct GNUNET_MessageHeader *msg, | 531 | const void *msg, |
532 | size_t msg_size, | ||
531 | struct GNUNET_TIME_Relative timeout, | 533 | struct GNUNET_TIME_Relative timeout, |
532 | GST_NeighbourSendContinuation cont, | 534 | GST_NeighbourSendContinuation cont, |
533 | void *cont_cls) | 535 | void *cont_cls) |
534 | { | 536 | { |
535 | struct NeighbourMapEntry *n; | 537 | struct NeighbourMapEntry *n; |
536 | struct MessageQueue *mq; | 538 | struct MessageQueue *mq; |
537 | uint16_t message_buf_size; | ||
538 | 539 | ||
539 | n = lookup_neighbour (target); | 540 | n = lookup_neighbour (target); |
540 | if ( (n == NULL) || | 541 | if ( (n == NULL) || |
@@ -549,17 +550,16 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, | |||
549 | GNUNET_SYSERR); | 550 | GNUNET_SYSERR); |
550 | return; | 551 | return; |
551 | } | 552 | } |
552 | message_buf_size = ntohs (msg->size); | 553 | GNUNET_assert (msg_size >= sizeof (struct GNUNET_MessageHeader)); |
553 | GNUNET_assert (message_buf_size >= sizeof (struct GNUNET_MessageHeader)); | ||
554 | GNUNET_STATISTICS_update (GST_stats, | 554 | GNUNET_STATISTICS_update (GST_stats, |
555 | gettext_noop ("# bytes in message queue for other peers"), | 555 | gettext_noop ("# bytes in message queue for other peers"), |
556 | message_buf_size, | 556 | msg_size, |
557 | GNUNET_NO); | 557 | GNUNET_NO); |
558 | mq = GNUNET_malloc (sizeof (struct MessageQueue) + message_buf_size); | 558 | mq = GNUNET_malloc (sizeof (struct MessageQueue) + msg_size); |
559 | /* FIXME: this memcpy can be up to 7% of our total runtime! */ | 559 | /* FIXME: this memcpy can be up to 7% of our total runtime! */ |
560 | memcpy (&mq[1], msg, message_buf_size); | 560 | memcpy (&mq[1], msg, msg_size); |
561 | mq->message_buf = (const char*) &mq[1]; | 561 | mq->message_buf = (const char*) &mq[1]; |
562 | mq->message_buf_size = message_buf_size; | 562 | mq->message_buf_size = msg_size; |
563 | mq->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 563 | mq->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
564 | GNUNET_CONTAINER_DLL_insert_tail (n->messages_head, | 564 | GNUNET_CONTAINER_DLL_insert_tail (n->messages_head, |
565 | n->messages_tail, | 565 | n->messages_tail, |
diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h index 8ccf3cb67..76e5e7336 100644 --- a/src/transport/gnunet-service-transport_neighbours.h +++ b/src/transport/gnunet-service-transport_neighbours.h | |||
@@ -90,13 +90,15 @@ typedef void (*GST_NeighbourSendContinuation)(void *cls, | |||
90 | * | 90 | * |
91 | * @param target destination | 91 | * @param target destination |
92 | * @param msg message to send | 92 | * @param msg message to send |
93 | * @param msg_size number of bytes in msg | ||
93 | * @param timeout when to fail with timeout | 94 | * @param timeout when to fail with timeout |
94 | * @param cont function to call when done | 95 | * @param cont function to call when done |
95 | * @param cont_cls closure for 'cont' | 96 | * @param cont_cls closure for 'cont' |
96 | */ | 97 | */ |
97 | void | 98 | void |
98 | GST_neighbours_send (const struct GNUNET_PeerIdentity *target, | 99 | GST_neighbours_send (const struct GNUNET_PeerIdentity *target, |
99 | const struct GNUNET_MessageHeader *msg, | 100 | const void *msg, |
101 | size_t msg_size, | ||
100 | struct GNUNET_TIME_Relative timeout, | 102 | struct GNUNET_TIME_Relative timeout, |
101 | GST_NeighbourSendContinuation cont, | 103 | GST_NeighbourSendContinuation cont, |
102 | void *cont_cls); | 104 | void *cont_cls); |
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index 13522931a..13d48bce2 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include "gnunet_peerinfo_service.h" | 32 | #include "gnunet_peerinfo_service.h" |
33 | #include "gnunet_signatures.h" | 33 | #include "gnunet_signatures.h" |
34 | 34 | ||
35 | // TODO: observe latency between PING/PONG and give information to ATS! | ||
35 | 36 | ||
36 | /** | 37 | /** |
37 | * How long is a PONG signature valid? We'll recycle a signature until | 38 | * How long is a PONG signature valid? We'll recycle a signature until |