GNUnet  0.11.x
transport_api_manipulation.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_constants.h"
29 #include "gnunet_arm_service.h"
30 #include "gnunet_hello_lib.h"
31 #include "gnunet_protocols.h"
33 #include "transport.h"
34 
35 #define LOG(kind, ...) GNUNET_log_from (kind, "transport-api", __VA_ARGS__)
36 
37 
43 {
48 
53 
58 
63 
68 };
69 
70 
77 static void
80 
81 
91 static void
92 mq_error_handler (void *cls,
93  enum GNUNET_MQ_Error error)
94 {
96 
98  "Error receiving from transport service, disconnecting temporarily.\n");
101 }
102 
103 
109 static void
110 reconnect (void *cls)
111 {
113  struct GNUNET_MQ_MessageHandler handlers[] = {
115  };
116  struct GNUNET_MQ_Envelope *env;
117  struct StartMessage *s;
118 
119  h->reconnect_task = NULL;
121  "Connecting to transport service.\n");
122  GNUNET_assert (NULL == h->mq);
123  h->reconnecting = GNUNET_NO;
124  h->mq = GNUNET_CLIENT_connect (h->cfg,
125  "transport",
126  handlers,
128  h);
129  if (NULL == h->mq)
130  return;
131  env = GNUNET_MQ_msg (s,
133  GNUNET_MQ_send (h->mq,
134  env);
135 }
136 
137 
144 static void
147 {
148  GNUNET_assert (NULL == h->reconnect_task);
149  if (NULL != h->mq)
150  {
151  GNUNET_MQ_destroy (h->mq);
152  h->mq = NULL;
153  }
154  h->reconnect_task =
156  &reconnect,
157  h);
159 }
160 
161 
174 void
177  const struct GNUNET_PeerIdentity *peer,
178  const struct GNUNET_ATS_Properties *prop,
181 {
182  struct GNUNET_MQ_Envelope *env;
183  struct TrafficMetricMessage *msg;
184 
185  if (NULL == handle->mq)
186  return;
187  env = GNUNET_MQ_msg (msg,
189  msg->reserved = htonl (0);
190  msg->peer = *peer;
192  prop);
193  msg->delay_in = GNUNET_TIME_relative_hton (delay_in);
194  msg->delay_out = GNUNET_TIME_relative_hton (delay_out);
195  GNUNET_MQ_send (handle->mq,
196  env);
197 }
198 
199 
210 {
212 
214  h->cfg = cfg;
216  "Connecting to transport service.\n");
217  reconnect (h);
218  if (NULL == h->mq)
219  {
220  GNUNET_free (h);
221  return NULL;
222  }
223  return h;
224 }
225 
226 
232 void
235  handle)
236 {
237  if (NULL == handle->reconnect_task)
239  /* and now we stop trying to connect again... */
240  if (NULL != handle->reconnect_task)
241  {
243  handle->reconnect_task = NULL;
244  }
245  GNUNET_free (handle);
246 }
247 
248 
249 /* end of transport_api_manipulation.c */
struct GNUNET_PeerIdentity peer
The identity of the peer to look up.
Definition: transport.h:508
static struct GNUNET_TIME_Relative delay_in
Inbound delay to apply to all peers.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
common internal definitions for transport service
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
struct GNUNET_TIME_RelativeNBO delay_in
Fake delay to add on inbound traffic.
Definition: transport.h:518
GNUNET_MQ_Error
Error codes for the queue.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_ATS_properties_hton(struct GNUNET_ATS_PropertiesNBO *nbo, const struct GNUNET_ATS_Properties *hbo)
Convert ATS properties from host to network byte order.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC
Message containing traffic metrics for transport service.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Handle for the transport service (includes all of the state for the transport service).
ATS performance characteristics for an address.
static void disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_ManipulationHandle *h)
Function that will schedule the job that will try to connect us again to the client.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
struct GNUNET_TIME_Relative reconnect_delay
Delay until we try to reconnect.
struct GNUNET_TIME_RelativeNBO delay_out
Fake delay to add on outbound traffic.
Definition: transport.h:523
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1253
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
struct GNUNET_MQ_Handle * mq
My client connection to the transport service.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
Message from the library to the transport service asking for binary addresses known for a peer...
Definition: transport.h:493
#define GNUNET_MESSAGE_TYPE_TRANSPORT_START
Message from the core saying that the transport server should start giving it messages.
Message handler for a specific message type.
const struct GNUNET_CONFIGURATION_Handle * cfg
My configuration.
Message from the transport service to the library asking to check if both processes agree about this ...
Definition: transport.h:91
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_ATS_PropertiesNBO properties
Fake properties to generate.
Definition: transport.h:513
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:625
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
static struct GNUNET_TIME_Relative delay_out
Outbound delay to apply to all peers.
Handle to a message queue.
Definition: mq.c:85
The identity of the host (wraps the signing key of the peer).
#define LOG(kind,...)
struct GNUNET_TRANSPORT_ManipulationHandle * GNUNET_TRANSPORT_manipulation_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the transport service.
configuration data
Definition: configuration.c:85
Entry in list of pending tasks.
Definition: scheduler.c:134
void GNUNET_TRANSPORT_manipulation_disconnect(struct GNUNET_TRANSPORT_ManipulationHandle *handle)
Disconnect from the transport service.
static void reconnect(void *cls)
Try again to connect to transport service.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#define GNUNET_YES
Definition: gnunet_common.h:77
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:353
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the task trying to reconnect to the service.
void GNUNET_TRANSPORT_manipulation_set(struct GNUNET_TRANSPORT_ManipulationHandle *handle, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Properties *prop, struct GNUNET_TIME_Relative delay_in, struct GNUNET_TIME_Relative delay_out)
Set transport metrics for a peer and a direction.
uint32_t reserved
Always zero.
Definition: transport.h:503
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966