GNUnet  0.20.0
transport_api_offer_hello.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2009-2013, 2016 GNUnet e.V.
4 
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.
9 
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.
14 
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/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_hello_lib.h"
29 #include "gnunet_protocols.h"
31 
32 
37 {
42 
47 
51  void *cls;
52 };
53 
54 
60 static void
61 finished_hello (void *cls)
62 {
64 
65  if (NULL != ohh->cont)
66  ohh->cont (ohh->cls);
68 }
69 
70 
88  const struct GNUNET_MessageHeader *hello,
90  void *cont_cls)
91 {
94  struct GNUNET_MQ_Envelope *env;
96 
97  if (GNUNET_OK !=
98  GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hello,
99  &peer))
100  {
101  GNUNET_break (0);
102  GNUNET_free (ohh);
103  return NULL;
104  }
105  ohh->mq = GNUNET_CLIENT_connect (cfg,
106  "transport",
107  NULL,
108  NULL,
109  ohh);
110  if (NULL == ohh->mq)
111  {
112  GNUNET_free (ohh);
113  return NULL;
114  }
115  ohh->cont = cont;
116  ohh->cls = cont_cls;
117  GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO);
118  env = GNUNET_MQ_msg_copy (hello);
121  ohh);
122  GNUNET_MQ_send (ohh->mq,
123  env);
124  return ohh;
125 }
126 
127 
128 void
131 {
132  GNUNET_MQ_destroy (ohh->mq);
133  GNUNET_free (ohh);
134 }
135 
136 
137 /* end of transport_api_offer_hello.c */
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
Helper library for handling HELLOs.
Constants for network protocols.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1057
int GNUNET_HELLO_get_id(const struct GNUNET_HELLO_Message *hello, struct GNUNET_PeerIdentity *peer)
Get the peer identity from a HELLO message.
Definition: hello.c:649
@ GNUNET_OK
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:304
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore.
Definition: mq.c:638
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr)
Create a new envelope by copying an existing message.
Definition: mq.c:533
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683
#define GNUNET_MESSAGE_TYPE_HELLO
HELLO message with friend only flag used for communicating peer addresses.
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
void GNUNET_TRANSPORT_offer_hello_cancel(struct GNUNET_TRANSPORT_OfferHelloHandle *ohh)
Cancel the request to transport to offer the HELLO message.
struct GNUNET_TRANSPORT_OfferHelloHandle * GNUNET_TRANSPORT_offer_hello(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_MessageHeader *hello, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Offer the transport service the HELLO of another peer.
A HELLO message is used to exchange information about transports with other peers.
Handle to a message queue.
Definition: mq.c:87
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
The identity of the host (wraps the signing key of the peer).
Entry in linked list for all offer-HELLO requests.
GNUNET_SCHEDULER_TaskCallback cont
Function to call once we are done.
struct GNUNET_MQ_Handle * mq
Transport service handle we use for transmission.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static void finished_hello(void *cls)
Done sending HELLO message to the service, notify application.