X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Ftransport%2Ftransport-testing-send.c;h=cb4be57de941a1e0450856c34a327003427820be;hb=1b1edf92c24f91c36747458e880e0d6a5e559e95;hp=60fed23a694ab1a362c1545b07be26e9e8fc4e96;hpb=0979ddcbd310b856b7c36c6ed9c8dc17c0b032db;p=oweals%2Fgnunet.git diff --git a/src/transport/transport-testing-send.c b/src/transport/transport-testing-send.c index 60fed23a6..cb4be57de 100644 --- a/src/transport/transport-testing-send.c +++ b/src/transport/transport-testing-send.c @@ -2,20 +2,20 @@ This file is part of GNUnet. Copyright (C) 2016 GNUnet e.V. - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. + SPDX-License-Identifier: AGPL3.0-or-later */ /** * @file transport-testing-send.c @@ -27,64 +27,7 @@ /** * Acceptable transmission delay. */ -#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) - - -static size_t -notify_ready (void *cls, - size_t size, - void *buf) -{ - struct TRANSPORT_TESTING_SendJob *sj = cls; - struct GNUNET_TRANSPORT_TESTING_PeerContext *sender = sj->sender; - struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver = sj->receiver; - struct GNUNET_TRANSPORT_TESTING_Handle *tth = sender->tth; - uint16_t msize = sj->msize; - struct GNUNET_TRANSPORT_TESTING_TestMessage *test; - - sj->th = NULL; - GNUNET_CONTAINER_DLL_remove (tth->sj_head, - tth->sj_tail, - sj); - if (NULL == buf) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Timeout occurred while waiting for transmit_ready\n"); - GNUNET_SCHEDULER_shutdown (); - GNUNET_free (sj); - return 0; - } - - GNUNET_assert (size >= msize); - if (NULL != buf) - { - memset (buf, sj->num, msize); - test = buf; - test->header.size = htons (msize); - test->header.type = htons (sj->mtype); - test->num = htonl (sj->num); - } - - { - char *ps = GNUNET_strdup (GNUNET_i2s (&sender->id)); - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Sending message %u from %u (%s) with type %u and size %u bytes to peer %u (%s)\n", - (unsigned int) sj->num, - sender->no, - ps, - sj->mtype, - msize, - receiver->no, - GNUNET_i2s (&receiver->id)); - GNUNET_free (ps); - } - if (NULL != sj->cont) - GNUNET_SCHEDULER_add_now (sj->cont, - sj->cont_cls); - GNUNET_free (sj); - return msize; -} +#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) /** @@ -96,6 +39,8 @@ find_cr (void *cls, { struct GNUNET_TRANSPORT_TESTING_ConnectRequest **cr = cls; + if (GNUNET_NO == cx->connected) + return; *cr = cx; } @@ -125,10 +70,10 @@ GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *send GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls) { - struct GNUNET_TRANSPORT_TESTING_Handle *tth = sender->tth; - struct TRANSPORT_TESTING_SendJob *sj; struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cr; - + struct GNUNET_MQ_Envelope *env; + struct GNUNET_TRANSPORT_TESTING_TestMessage *test; + if (msize < sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)) { GNUNET_break (0); @@ -144,23 +89,16 @@ GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *send sender, &find_cr, &cr); - if ( (NULL == cr) || - (GNUNET_YES != cr->connected) ) + if (NULL == cr) + { + GNUNET_break (0); + return GNUNET_NO; + } + if (NULL == cr->mq) { GNUNET_break (0); return GNUNET_NO; } - sj = GNUNET_new (struct TRANSPORT_TESTING_SendJob); - sj->num = num; - sj->sender = sender; - sj->receiver = receiver; - sj->cont = cont; - sj->cont_cls = cont_cls; - sj->mtype = mtype; - sj->msize = msize; - GNUNET_CONTAINER_DLL_insert (tth->sj_head, - tth->sj_tail, - sj); { char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id)); @@ -172,13 +110,18 @@ GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *send receiver_s); GNUNET_free (receiver_s); } - sj->th = GNUNET_TRANSPORT_notify_transmit_ready (sender->th, - &receiver->id, - msize, - TIMEOUT_TRANSMIT, - ¬ify_ready, - sj); - GNUNET_assert (NULL != sj->th); + env = GNUNET_MQ_msg_extra (test, + msize - sizeof (*test), + mtype); + test->num = htonl (num); + memset (&test[1], + num, + msize - sizeof (*test)); + GNUNET_MQ_notify_sent (env, + cont, + cont_cls); + GNUNET_MQ_send (cr->mq, + env); return GNUNET_OK; }