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
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file transport/transport_api_offer_hello.c
23 * @brief library to offer HELLOs to transport service
24 * @author Christian Grothoff
28 * Entry in linked list for all offer-HELLO requests.
30 struct GNUNET_TRANSPORT_OfferHelloHandle
35 struct GNUNET_TRANSPORT_OfferHelloHandle *prev;
40 struct GNUNET_TRANSPORT_OfferHelloHandle *next;
43 * Transport service handle we use for transmission.
45 struct GNUNET_TRANSPORT_Handle *th;
48 * Transmission handle for this request.
50 struct GNUNET_TRANSPORT_TransmitHandle *tth;
53 * Function to call once we are done.
55 GNUNET_SCHEDULER_TaskCallback cont;
63 * The HELLO message to be transmitted.
65 struct GNUNET_MessageHeader *msg;
71 * Offer the transport service the HELLO of another peer. Note that
72 * the transport service may just ignore this message if the HELLO is
73 * malformed or useless due to our local configuration.
75 * @param handle connection to transport service
76 * @param hello the hello message
77 * @param cont continuation to call when HELLO has been sent,
78 * tc reason #GNUNET_SCHEDULER_REASON_TIMEOUT for fail
79 * tc reasong #GNUNET_SCHEDULER_REASON_READ_READY for success
80 * @param cont_cls closure for @a cont
81 * @return a `struct GNUNET_TRANSPORT_OfferHelloHandle` handle or NULL on failure,
82 * in case of failure @a cont will not be called
85 struct GNUNET_TRANSPORT_OfferHelloHandle *
86 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
87 const struct GNUNET_MessageHeader *hello,
88 GNUNET_SCHEDULER_TaskCallback cont,
91 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh;
92 struct GNUNET_MessageHeader *msg;
93 struct GNUNET_PeerIdentity peer;
96 if (NULL == handle->mq)
98 GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO);
99 size = ntohs (hello->size);
100 GNUNET_break (size >= sizeof (struct GNUNET_MessageHeader));
102 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hello,
109 msg = GNUNET_malloc (size);
110 memcpy (msg, hello, size);
111 LOG (GNUNET_ERROR_TYPE_DEBUG,
112 "Offering HELLO message of `%s' to transport for validation.\n",
114 ohh = GNUNET_new (struct GNUNET_TRANSPORT_OfferHelloHandle);
119 ohh->tth = schedule_control_transmit (handle,
123 GNUNET_CONTAINER_DLL_insert (handle->oh_head,
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 struct GNUNET_TRANSPORT_Handle *th = ohh->th;
140 cancel_control_transmit (ohh->th, ohh->tth);
141 GNUNET_CONTAINER_DLL_remove (th->oh_head,
144 GNUNET_free (ohh->msg);
149 /* end of transport_api_offer_hello.c */