2 This file is part of GNUnet.
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file transport/transport_api_monitoring.c
23 * @brief montoring api for transport peer status and validation entries
25 * This api provides the ability to query the transport service about
26 * the status of a specific or all peers as well as address validation entries.
28 * Calls back with information about peer(s) including address used, state and
29 * state timeout for peer requests and address, address lifetime and next revalidation
30 * for validation entries.
33 #include "gnunet_util_lib.h"
34 #include "gnunet_arm_service.h"
35 #include "gnunet_hello_lib.h"
36 #include "gnunet_protocols.h"
37 #include "gnunet_transport_service.h"
38 #include "transport.h"
41 * Context for iterating validation entries.
43 struct GNUNET_TRANSPORT_PeerMonitoringContext
46 * Function to call with the binary address.
48 GNUNET_TRANSPORT_PeerIterateCallback cb;
56 * Connection to the service.
58 struct GNUNET_CLIENT_Connection *client;
61 * Configuration we use.
63 const struct GNUNET_CONFIGURATION_Handle *cfg;
66 * When should this operation time out?
68 struct GNUNET_TIME_Absolute timeout;
71 * Backoff for reconnect.
73 struct GNUNET_TIME_Relative backoff;
76 * Task ID for reconnect.
78 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
81 * Identity of the peer to monitor.
83 struct GNUNET_PeerIdentity peer;
86 * Was this a one-shot request?
93 * Context for the address lookup.
95 struct GNUNET_TRANSPORT_ValidationMonitoringContext
98 * Function to call with the binary address.
100 GNUNET_TRANSPORT_ValidationIterateCallback cb;
108 * Connection to the service.
110 struct GNUNET_CLIENT_Connection *client;
113 * Configuration we use.
115 const struct GNUNET_CONFIGURATION_Handle *cfg;
118 * When should this operation time out?
120 struct GNUNET_TIME_Absolute timeout;
123 * Backoff for reconnect.
125 struct GNUNET_TIME_Relative backoff;
128 * Task ID for reconnect.
130 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
133 * Identity of the peer to monitor.
135 struct GNUNET_PeerIdentity peer;
138 * Was this a one-shot request?
144 * Check if a state is defined as connected
146 * @param state the state value
147 * @return GNUNET_YES or GNUNET_NO
150 GNUNET_TRANSPORT_is_connected (enum GNUNET_TRANSPORT_PeerState state)
154 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
155 case GNUNET_TRANSPORT_PS_INIT_ATS:
156 case GNUNET_TRANSPORT_PS_CONNECT_SENT:
157 case GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS:
158 case GNUNET_TRANSPORT_PS_CONNECT_RECV_BLACKLIST:
159 case GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK:
161 case GNUNET_TRANSPORT_PS_CONNECTED:
162 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
163 case GNUNET_TRANSPORT_PS_RECONNECT_BLACKLIST:
164 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
165 case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_BLACKLIST:
166 case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT:
168 case GNUNET_TRANSPORT_PS_DISCONNECT:
169 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
172 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
173 "Unhandled state `%s' \n",
174 GNUNET_TRANSPORT_ps2s (state));
178 return GNUNET_SYSERR;
182 * Convert peer state to human-readable string.
184 * @param state the state value
185 * @return corresponding string
188 GNUNET_TRANSPORT_ps2s (enum GNUNET_TRANSPORT_PeerState state)
192 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
193 return "S_NOT_CONNECTED";
194 case GNUNET_TRANSPORT_PS_INIT_ATS:
196 case GNUNET_TRANSPORT_PS_CONNECT_SENT:
197 return "S_CONNECT_SENT";
198 case GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS:
199 return "S_CONNECT_RECV_ATS";
200 case GNUNET_TRANSPORT_PS_CONNECT_RECV_BLACKLIST:
201 return "S_CONNECT_RECV_BLACKLIST";
202 case GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK:
203 return "S_CONNECT_RECV_ACK";
204 case GNUNET_TRANSPORT_PS_CONNECTED:
205 return "S_CONNECTED";
206 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
207 return "S_RECONNECT_ATS";
208 case GNUNET_TRANSPORT_PS_RECONNECT_BLACKLIST:
209 return "S_RECONNECT_BLACKLIST";
210 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
211 return "S_RECONNECT_SENT";
212 case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_BLACKLIST:
213 return "S_CONNECTED_SWITCHING_BLACKLIST";
214 case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT:
215 return "S_CONNECTED_SWITCHING_CONNECT_SENT";
216 case GNUNET_TRANSPORT_PS_DISCONNECT:
217 return "S_DISCONNECT";
218 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
219 return "S_DISCONNECT_FINISHED";
227 * Convert validation state to human-readable string.
229 * @param state the state value
230 * @return corresponding string
233 GNUNET_TRANSPORT_vs2s (enum GNUNET_TRANSPORT_ValidationState state)
237 case GNUNET_TRANSPORT_VS_NONE:
239 case GNUNET_TRANSPORT_VS_NEW:
241 case GNUNET_TRANSPORT_VS_REMOVE:
243 case GNUNET_TRANSPORT_VS_TIMEOUT:
245 case GNUNET_TRANSPORT_VS_UPDATE:
255 * Function called with responses from the service.
257 * @param cls our 'struct GNUNET_TRANSPORT_PeerAddressLookupContext*'
258 * @param msg NULL on timeout or error, otherwise presumably a
259 * message with the human-readable address
262 peer_response_processor (void *cls, const struct GNUNET_MessageHeader *msg);
266 * Function called with responses from the service.
268 * @param cls our 'struct GNUNET_TRANSPORT_PeerAddressLookupContext*'
269 * @param msg NULL on timeout or error, otherwise presumably a
270 * message with the human-readable address
273 val_response_processor (void *cls, const struct GNUNET_MessageHeader *msg);
276 * Send our subscription request to the service.
278 * @param pal_ctx our context
281 send_peer_mon_request (struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx)
283 struct PeerMonitorMessage msg;
285 msg.header.size = htons (sizeof (struct PeerMonitorMessage));
286 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST);
287 msg.one_shot = htonl (pal_ctx->one_shot);
288 msg.peer = pal_ctx->peer;
289 GNUNET_assert (GNUNET_OK ==
290 GNUNET_CLIENT_transmit_and_get_response (pal_ctx->client,
292 GNUNET_TIME_absolute_get_remaining (pal_ctx->timeout),
294 &peer_response_processor,
299 * Send our subscription request to the service.
301 * @param val_ctx our context
304 send_val_mon_request (struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx)
306 struct ValidationMonitorMessage msg;
308 msg.header.size = htons (sizeof (struct ValidationMonitorMessage));
309 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST);
310 msg.one_shot = htonl (val_ctx->one_shot);
311 msg.peer = val_ctx->peer;
312 GNUNET_assert (GNUNET_OK ==
313 GNUNET_CLIENT_transmit_and_get_response (val_ctx->client,
315 GNUNET_TIME_absolute_get_remaining (val_ctx->timeout),
317 &val_response_processor,
322 * Task run to re-establish the connection.
324 * @param cls our 'struct GNUNET_TRANSPORT_PeerAddressLookupContext*'
325 * @param tc scheduler context, unused
328 do_peer_connect (void *cls,
329 const struct GNUNET_SCHEDULER_TaskContext *tc)
331 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
333 pal_ctx->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
334 pal_ctx->client = GNUNET_CLIENT_connect ("transport", pal_ctx->cfg);
335 GNUNET_assert (NULL != pal_ctx->client);
336 send_peer_mon_request (pal_ctx);
341 * Cut the existing connection and reconnect.
343 * @param pal_ctx our context
346 reconnect_peer_ctx (struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx)
348 GNUNET_assert (GNUNET_NO == pal_ctx->one_shot);
349 GNUNET_CLIENT_disconnect (pal_ctx->client);
350 pal_ctx->client = NULL;
351 pal_ctx->backoff = GNUNET_TIME_STD_BACKOFF (pal_ctx->backoff);
352 pal_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (pal_ctx->backoff,
359 * Task run to re-establish the connection.
361 * @param cls our 'struct GNUNET_TRANSPORT_PeerAddressLookupContext*'
362 * @param tc scheduler context, unused
365 do_val_connect (void *cls,
366 const struct GNUNET_SCHEDULER_TaskContext *tc)
368 struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx = cls;
370 val_ctx->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
371 val_ctx->client = GNUNET_CLIENT_connect ("transport", val_ctx->cfg);
372 GNUNET_assert (NULL != val_ctx->client);
373 send_val_mon_request (val_ctx);
377 * Cut the existing connection and reconnect.
379 * @param val_ctx our context
382 reconnect_val_ctx (struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx)
384 GNUNET_assert (GNUNET_NO == val_ctx->one_shot);
385 GNUNET_CLIENT_disconnect (val_ctx->client);
386 val_ctx->client = NULL;
387 val_ctx->backoff = GNUNET_TIME_STD_BACKOFF (val_ctx->backoff);
388 val_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (val_ctx->backoff,
394 * Function called with responses from the service.
396 * @param cls our 'struct GNUNET_TRANSPORT_PeerMonitoringContext*'
397 * @param msg NULL on timeout or error, otherwise presumably a
398 * message with the human-readable address
401 val_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
403 struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx = cls;
404 struct ValidationIterateResponseMessage *vr_msg;
405 struct GNUNET_HELLO_Address *address;
407 const char *transport_name;
414 if (val_ctx->one_shot)
417 val_ctx->cb (val_ctx->cb_cls, NULL, NULL,
418 GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO_ABS,
419 GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_VS_TIMEOUT);
420 GNUNET_TRANSPORT_monitor_validation_entries_cancel (val_ctx);
424 reconnect_val_ctx (val_ctx);
428 size = ntohs (msg->size);
429 GNUNET_break (ntohs (msg->type) ==
430 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE);
432 if (size == sizeof (struct GNUNET_MessageHeader))
435 if (val_ctx->one_shot)
437 val_ctx->cb (val_ctx->cb_cls, NULL, NULL,
438 GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO_ABS,
439 GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_VS_NONE);
440 GNUNET_TRANSPORT_monitor_validation_entries_cancel (val_ctx);
444 reconnect_val_ctx (val_ctx);
449 if ((size < sizeof (struct ValidationIterateResponseMessage)) ||
450 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE))
453 if (val_ctx->one_shot)
455 val_ctx->cb (val_ctx->cb_cls, NULL, NULL,
456 GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO_ABS,
457 GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_VS_NONE);
458 GNUNET_TRANSPORT_monitor_validation_entries_cancel (val_ctx);
462 reconnect_val_ctx (val_ctx);
467 vr_msg = (struct ValidationIterateResponseMessage *) msg;
468 tlen = ntohl (vr_msg->pluginlen);
469 alen = ntohl (vr_msg->addrlen);
471 if (size != sizeof (struct ValidationIterateResponseMessage) + tlen + alen)
474 if (val_ctx->one_shot)
476 val_ctx->cb (val_ctx->cb_cls, NULL, NULL,
477 GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO_ABS,
478 GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_VS_NONE);
479 GNUNET_TRANSPORT_monitor_validation_entries_cancel (val_ctx);
483 reconnect_val_ctx (val_ctx);
487 if ( (0 == tlen) && (0 == alen) )
490 if (val_ctx->one_shot)
492 val_ctx->cb (val_ctx->cb_cls, NULL, NULL,
493 GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO_ABS,
494 GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_VS_NONE);
495 GNUNET_TRANSPORT_monitor_validation_entries_cancel (val_ctx);
499 reconnect_val_ctx (val_ctx);
507 GNUNET_break (0); /* This must not happen: address without plugin */
510 addr = (const char *) &vr_msg[1];
511 transport_name = &addr[alen];
513 if (transport_name[tlen - 1] != '\0')
515 /* Corrupt plugin name */
517 if (val_ctx->one_shot)
519 val_ctx->cb (val_ctx->cb_cls, NULL, NULL,
520 GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO_ABS,
521 GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_VS_NONE);
522 GNUNET_TRANSPORT_monitor_validation_entries_cancel (val_ctx);
526 reconnect_val_ctx (val_ctx);
532 address = GNUNET_HELLO_address_allocate (&vr_msg->peer,
533 transport_name, addr, alen, ntohl(vr_msg->local_address_info));
534 val_ctx->cb (val_ctx->cb_cls, &vr_msg->peer, address,
535 GNUNET_TIME_absolute_ntoh(vr_msg->last_validation),
536 GNUNET_TIME_absolute_ntoh(vr_msg->valid_until),
537 GNUNET_TIME_absolute_ntoh(vr_msg->next_validation),
538 ntohl(vr_msg->state));
539 GNUNET_HELLO_address_free (address);
541 /* expect more replies */
542 GNUNET_CLIENT_receive (val_ctx->client, &val_response_processor,
543 val_ctx, GNUNET_TIME_absolute_get_remaining (val_ctx->timeout));
548 * Function called with responses from the service.
550 * @param cls our 'struct GNUNET_TRANSPORT_PeerMonitoringContext*'
551 * @param msg NULL on timeout or error, otherwise presumably a
552 * message with the human-readable address
555 peer_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
557 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
558 struct PeerIterateResponseMessage *pir_msg;
559 struct GNUNET_HELLO_Address *address;
561 const char *transport_name;
568 if (pal_ctx->one_shot)
571 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL,
572 GNUNET_TRANSPORT_PS_NOT_CONNECTED, GNUNET_TIME_UNIT_ZERO_ABS);
573 GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx);
577 reconnect_peer_ctx (pal_ctx);
581 size = ntohs (msg->size);
582 GNUNET_break (ntohs (msg->type) ==
583 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE);
584 if (size == sizeof (struct GNUNET_MessageHeader))
587 if (pal_ctx->one_shot)
589 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL,
590 GNUNET_TRANSPORT_PS_NOT_CONNECTED, GNUNET_TIME_UNIT_ZERO_ABS);
591 GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx);
595 reconnect_peer_ctx (pal_ctx);
600 if ((size < sizeof (struct PeerIterateResponseMessage)) ||
601 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE))
604 if (pal_ctx->one_shot)
606 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL,
607 GNUNET_TRANSPORT_PS_NOT_CONNECTED, GNUNET_TIME_UNIT_ZERO_ABS);
608 GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx);
612 reconnect_peer_ctx (pal_ctx);
617 pir_msg = (struct PeerIterateResponseMessage *) msg;
618 tlen = ntohl (pir_msg->pluginlen);
619 alen = ntohl (pir_msg->addrlen);
621 if (size != sizeof (struct PeerIterateResponseMessage) + tlen + alen)
624 if (pal_ctx->one_shot)
626 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL,
627 GNUNET_TRANSPORT_PS_NOT_CONNECTED, GNUNET_TIME_UNIT_ZERO_ABS);
628 GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx);
632 reconnect_peer_ctx (pal_ctx);
637 if ( (0 == tlen) && (0 == alen) )
639 /* No address available */
640 pal_ctx->cb (pal_ctx->cb_cls, &pir_msg->peer, NULL,
641 ntohl(pir_msg->state),
642 GNUNET_TIME_absolute_ntoh (pir_msg->state_timeout));
648 GNUNET_break (0); /* This must not happen: address without plugin */
651 addr = (const char *) &pir_msg[1];
652 transport_name = &addr[alen];
654 if (transport_name[tlen - 1] != '\0')
656 /* Corrupt plugin name */
658 if (pal_ctx->one_shot)
660 pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL,
661 GNUNET_TRANSPORT_PS_NOT_CONNECTED, GNUNET_TIME_UNIT_ZERO_ABS);
662 GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx);
666 reconnect_peer_ctx (pal_ctx);
672 address = GNUNET_HELLO_address_allocate (&pir_msg->peer,
673 transport_name, addr, alen, ntohl(pir_msg->local_address_info));
674 pal_ctx->cb (pal_ctx->cb_cls, &pir_msg->peer, address,
675 ntohl(pir_msg->state),
676 GNUNET_TIME_absolute_ntoh (pir_msg->state_timeout));
677 GNUNET_HELLO_address_free (address);
681 /* expect more replies */
682 GNUNET_CLIENT_receive (pal_ctx->client, &peer_response_processor,
684 GNUNET_TIME_absolute_get_remaining (pal_ctx->timeout));
689 * Return information about a specific peer or all peers currently known to
690 * transport service once or in monitoring mode. To obtain information about
691 * a specific peer, a peer identity can be passed. To obtain information about
692 * all peers currently known to transport service, NULL can be passed as peer
695 * For each peer, the callback is called with information about the address used
696 * to communicate with this peer, the state this peer is currently in and the
697 * the current timeout for this state.
699 * Upon completion, the 'GNUNET_TRANSPORT_PeerIterateCallback' is called one
700 * more time with 'NULL'. After this, the operation must no longer be
701 * explicitly canceled.
703 * The #GNUNET_TRANSPORT_monitor_peers_cancel call MUST not be called in the
706 * @param cfg configuration to use
707 * @param peer a specific peer identity to obtain information for,
709 * @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL),
710 * GNUNET_NO to monitor peers continuously
711 * @param timeout how long is the lookup allowed to take at most
712 * @param peer_callback function to call with the results
713 * @param peer_callback_cls closure for peer_address_callback
715 struct GNUNET_TRANSPORT_PeerMonitoringContext *
716 GNUNET_TRANSPORT_monitor_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
717 const struct GNUNET_PeerIdentity *peer,
719 struct GNUNET_TIME_Relative timeout,
720 GNUNET_TRANSPORT_PeerIterateCallback peer_callback,
721 void *peer_callback_cls)
723 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx;
724 struct GNUNET_CLIENT_Connection *client;
726 client = GNUNET_CLIENT_connect ("transport", cfg);
729 if (GNUNET_YES != one_shot)
730 timeout = GNUNET_TIME_UNIT_FOREVER_REL;
731 pal_ctx = GNUNET_new (struct GNUNET_TRANSPORT_PeerMonitoringContext);
732 pal_ctx->cb = peer_callback;
733 pal_ctx->cb_cls = peer_callback_cls;
735 pal_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
737 pal_ctx->peer = *peer;
738 pal_ctx->one_shot = one_shot;
739 pal_ctx->client = client;
740 send_peer_mon_request (pal_ctx);
747 * Cancel request to monitor peers
749 * @param pic handle for the request to cancel
752 GNUNET_TRANSPORT_monitor_peers_cancel (struct GNUNET_TRANSPORT_PeerMonitoringContext *pic)
754 if (NULL != pic->client)
756 GNUNET_CLIENT_disconnect (pic->client);
759 if (GNUNET_SCHEDULER_NO_TASK != pic->reconnect_task)
761 GNUNET_SCHEDULER_cancel (pic->reconnect_task);
762 pic->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
769 * Return information about pending address validation operations for a specific
772 * @param cfg configuration to use
773 * @param peer a specific peer identity to obtain validation entries for,
775 * @param one_shot GNUNET_YES to return all entries and then end (with NULL+NULL),
776 * GNUNET_NO to monitor validation entries continuously
777 * @param timeout how long is the lookup allowed to take at most
778 * @param validation_callback function to call with the results
779 * @param validation_callback_cls closure for peer_address_callback
781 struct GNUNET_TRANSPORT_ValidationMonitoringContext *
782 GNUNET_TRANSPORT_monitor_validation_entries (const struct
783 GNUNET_CONFIGURATION_Handle *cfg,
784 const struct GNUNET_PeerIdentity *peer,
786 struct GNUNET_TIME_Relative timeout,
787 GNUNET_TRANSPORT_ValidationIterateCallback validation_callback,
788 void *validation_callback_cls)
790 struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx;
791 struct GNUNET_CLIENT_Connection *client;
793 client = GNUNET_CLIENT_connect ("transport", cfg);
796 if (GNUNET_YES != one_shot)
797 timeout = GNUNET_TIME_UNIT_FOREVER_REL;
798 val_ctx = GNUNET_new (struct GNUNET_TRANSPORT_ValidationMonitoringContext);
799 val_ctx->cb = validation_callback;
800 val_ctx->cb_cls = validation_callback_cls;
802 val_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
804 val_ctx->peer = *peer;
805 val_ctx->one_shot = one_shot;
806 val_ctx->client = client;
807 send_val_mon_request (val_ctx);
814 * Return information about all current pending validation operations
816 * @param vic handle for the request to cancel
819 GNUNET_TRANSPORT_monitor_validation_entries_cancel (struct GNUNET_TRANSPORT_ValidationMonitoringContext *vic)
821 if (NULL != vic->client)
823 GNUNET_CLIENT_disconnect (vic->client);
826 if (GNUNET_SCHEDULER_NO_TASK != vic->reconnect_task)
828 GNUNET_SCHEDULER_cancel (vic->reconnect_task);
829 vic->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
835 /* end of transport_api_monitoring.c */