2 This file is part of GNUnet.
3 Copyright (C) 2009-2013, 2016 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file transport/transport_api_offer_hello.c
23 * @brief library to offer HELLOs to transport service
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
28 #include "gnunet_hello_lib.h"
29 #include "gnunet_protocols.h"
30 #include "gnunet_transport_service.h"
34 * Entry in linked list for all offer-HELLO requests.
36 struct GNUNET_TRANSPORT_OfferHelloHandle
40 * Transport service handle we use for transmission.
42 struct GNUNET_MQ_Handle *mq;
45 * Function to call once we are done.
47 GNUNET_SCHEDULER_TaskCallback cont;
58 * Done sending HELLO message to the service, notify application.
60 * @param cls the handle for the operation
63 finished_hello (void *cls)
65 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh = cls;
67 if (NULL != ohh->cont)
69 GNUNET_TRANSPORT_offer_hello_cancel (ohh);
74 * Offer the transport service the HELLO of another peer. Note that
75 * the transport service may just ignore this message if the HELLO is
76 * malformed or useless due to our local configuration.
78 * @param cfg configuration
79 * @param hello the hello message
80 * @param cont continuation to call when HELLO has been sent,
81 * tc reason #GNUNET_SCHEDULER_REASON_TIMEOUT for fail
82 * tc reasong #GNUNET_SCHEDULER_REASON_READ_READY for success
83 * @param cont_cls closure for @a cont
84 * @return a `struct GNUNET_TRANSPORT_OfferHelloHandle` handle or NULL on failure,
85 * in case of failure @a cont will not be called
88 struct GNUNET_TRANSPORT_OfferHelloHandle *
89 GNUNET_TRANSPORT_offer_hello (const struct GNUNET_CONFIGURATION_Handle *cfg,
90 const struct GNUNET_MessageHeader *hello,
91 GNUNET_SCHEDULER_TaskCallback cont,
94 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh
95 = GNUNET_new (struct GNUNET_TRANSPORT_OfferHelloHandle);
96 struct GNUNET_MQ_Envelope *env;
97 struct GNUNET_PeerIdentity peer;
100 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hello,
107 ohh->mq = GNUNET_CLIENT_connect (cfg,
119 GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO);
120 env = GNUNET_MQ_msg_copy (hello);
121 GNUNET_MQ_notify_sent (env,
124 GNUNET_MQ_send (ohh->mq,
131 * Cancel the request to transport to offer the HELLO message
133 * @param ohh the handle for the operation to cancel
136 GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh)
138 GNUNET_MQ_destroy (ohh->mq);
143 /* end of transport_api_offer_hello.c */