GNUnet 0.22.2
transport_api2_monitor.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2018 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_protocols.h"
30#include "transport.h"
31
32
37{
42
47
52
57
62
66 void *cb_cls;
67};
68
69
75static void
77
78
85static void
87{
88 struct GNUNET_MQ_Envelope *env;
90
91 if (NULL == mc->mq)
92 return;
94 smm->one_shot = htonl ((uint32_t) mc->one_shot);
95 smm->peer = mc->peer;
96 GNUNET_MQ_send (mc->mq, env);
97}
98
99
105static void
107{
108 if (NULL == mc->mq)
109 return;
110 GNUNET_MQ_destroy (mc->mq);
111 mc->mq = NULL;
112}
113
114
121static void
122error_handler (void *cls, enum GNUNET_MQ_Error error)
123{
125
127 "MQ failure %d, reconnecting to transport service.\n",
128 error);
129 disconnect (mc);
130 /* TODO: maybe do this with exponential backoff/delay */
131 reconnect (mc);
132}
133
134
143static int
145{
146 (void) cls;
148 return GNUNET_OK;
149}
150
151
158static void
160{
163
164 mi.address = (const char *) &md[1];
165 mi.nt = ntohl (md->nt);
166 mi.cs = ntohl (md->cs);
167 mi.num_msg_pending = ntohl (md->num_msg_pending);
168 mi.num_bytes_pending = ntohl (md->num_bytes_pending);
173 mc->cb (mc->cb_cls, &md->peer, &mi);
174}
175
176
183static void
185{
187
188 if (GNUNET_YES != mc->one_shot)
189 {
190 GNUNET_break (0);
191 disconnect (mc);
192 reconnect (mc);
193 return;
194 }
195 mc->cb (mc->cb_cls, NULL, NULL);
197}
198
199
205static void
207{
209 { GNUNET_MQ_hd_var_size (monitor_data,
212 mc),
213 GNUNET_MQ_hd_fixed_size (monitor_end,
216 mc),
218
219 mc->mq =
220 GNUNET_CLIENT_connect (mc->cfg, "transport", handlers, &error_handler, mc);
221 if (NULL == mc->mq)
222 return;
224}
225
226
255 const struct GNUNET_PeerIdentity *peer,
256 int one_shot,
258 void *cb_cls)
259{
261
263 mc->cfg = cfg;
264 if (NULL != peer)
265 mc->peer = *peer;
266 mc->one_shot = one_shot;
267 mc->cb = cb;
268 mc->cb_cls = cb_cls;
269 reconnect (mc);
270 if (NULL == mc->mq)
271 {
272 GNUNET_free (mc);
273 return NULL;
274 }
275 return mc;
276}
277
278
284void
286{
287 disconnect (mc);
288 GNUNET_free (mc);
289}
290
291
292/* end of transport_api2_monitor.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
Constants for network protocols.
Monitoring / diagnostics API for the transport service.
void(* GNUNET_TRANSPORT_MonitorCallback)(void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_TRANSPORT_MonitorInformation *mi)
Function to call with information about a peer.
struct GNUNET_TRANSPORT_MonitorContext * GNUNET_TRANSPORT_monitor(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *peer, int one_shot, GNUNET_TRANSPORT_MonitorCallback cb, void *cb_cls)
Return information about a specific peer or all peers currently known to transport service once or in...
void GNUNET_TRANSPORT_monitor_cancel(struct GNUNET_TRANSPORT_MonitorContext *mc)
Cancel request to monitor peers.
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:1060
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_YES
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MQ_Error
Error codes for the queue.
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:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:78
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:700
#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA
Message sent to indicate to a monitor about events.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START
Message sent to indicate to the transport that a monitor wants to observe certain events.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_END
Message sent to indicate to a monitor that a one-shot iteration over events is done.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:630
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:741
Handle to a message queue.
Definition: mq.c:87
Message handler for a specific message type.
Header for all communications.
The identity of the host (wraps the signing key of the peer).
Opaque handle to the transport service for monitors.
GNUNET_TRANSPORT_MonitorCallback cb
Function to call with monitor data.
struct GNUNET_MQ_Handle * mq
Queue to talk to the transport service.
int one_shot
GNUNET_YES to return the current state and then end.
struct GNUNET_PeerIdentity peer
Peer we monitor, all zeros for "all".
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
uint32_t num_msg_pending
Messages pending (in NBO).
Definition: transport.h:766
struct GNUNET_PeerIdentity peer
Target identifier.
Definition: transport.h:744
struct GNUNET_TIME_AbsoluteNBO valid_until
Definition: transport.h:750
struct GNUNET_TIME_AbsoluteNBO last_validation
Definition: transport.h:749
uint32_t num_bytes_pending
Bytes pending (in NBO).
Definition: transport.h:771
struct GNUNET_TIME_AbsoluteNBO next_validation
Definition: transport.h:751
uint32_t nt
Network type (an enum GNUNET_NetworkType in NBO).
Definition: transport.h:739
struct GNUNET_TIME_RelativeNBO rtt
Current round-trip time estimate.
Definition: transport.h:756
uint32_t cs
Connection status (in NBO).
Definition: transport.h:761
Information about another peer's address.
struct GNUNET_TIME_Absolute next_validation
Time of the next validation operation.
struct GNUNET_TIME_Absolute last_validation
When was this address last validated.
uint32_t num_msg_pending
Number of messages pending transmission for this address.
enum GNUNET_NetworkType nt
Network type of the address.
const char * address
Address we have for the peer, human-readable, 0-terminated, in UTF-8.
uint32_t num_bytes_pending
Number of bytes pending transmission for this address.
struct GNUNET_TIME_Absolute valid_until
When does this address expire.
struct GNUNET_TIME_Relative rtt
Current estimate of the RTT.
enum GNUNET_TRANSPORT_ConnectionStatus cs
Connection status.
Request to start monitoring.
Definition: transport.h:708
uint32_t one_shot
GNUNET_YES for one-shot montoring, GNUNET_NO for continuous monitoring.
Definition: transport.h:717
struct GNUNET_PeerIdentity peer
Target identifier to monitor, all zeros for "all peers".
Definition: transport.h:722
common internal definitions for transport service
static void disconnect(struct GNUNET_TRANSPORT_MonitorContext *mc)
Disconnect from the transport service.
static void reconnect(struct GNUNET_TRANSPORT_MonitorContext *mc)
(re)connect our monitor to the transport service
static int check_monitor_data(void *cls, const struct GNUNET_TRANSPORT_MonitorData *md)
Transport service sends us information about what is going on.
static void error_handler(void *cls, enum GNUNET_MQ_Error error)
Function called on MQ errors.
static void handle_monitor_data(void *cls, const struct GNUNET_TRANSPORT_MonitorData *md)
Transport service sends us information about what is going on.
static void handle_monitor_end(void *cls, const struct GNUNET_MessageHeader *me)
One shot was requested, and transport service is done.
static void send_start_monitor(struct GNUNET_TRANSPORT_MonitorContext *mc)
Send message to the transport service about our montoring desire.