2 This file is part of GNUnet.
3 (C) 2010-2014 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/gnunet-service-transport_clients.c
23 * @brief plugin management API
24 * @author Christian Grothoff
27 #include "gnunet-service-transport_blacklist.h"
28 #include "gnunet-service-transport_clients.h"
29 #include "gnunet-service-transport_hello.h"
30 #include "gnunet-service-transport_neighbours.h"
31 #include "gnunet-service-transport_plugins.h"
32 #include "gnunet-service-transport_validation.h"
33 #include "gnunet-service-transport_manipulation.h"
34 #include "gnunet-service-transport.h"
35 #include "transport.h"
39 * How many messages can we have pending for a given client process
40 * before we start to drop incoming messages? We typically should
41 * have only one client and so this would be the primary buffer for
42 * messages, so the number should be chosen rather generously.
44 * The expectation here is that most of the time the queue is large
45 * enough so that a drop is virtually never required. Note that
46 * this value must be about as large as 'TOTAL_MSGS' in the
47 * 'test_transport_api_reliability.c', otherwise that testcase may
50 #define MAX_PENDING (128 * 1024)
54 * Linked list of messages to be transmitted to the client. Each
55 * entry is followed by the actual message.
57 struct ClientMessageQueueEntry
60 * This is a doubly-linked list.
62 struct ClientMessageQueueEntry *next;
65 * This is a doubly-linked list.
67 struct ClientMessageQueueEntry *prev;
72 * Client connected to the transport service.
74 struct TransportClient
78 * This is a doubly-linked list.
80 struct TransportClient *next;
83 * This is a doubly-linked list.
85 struct TransportClient *prev;
88 * Handle to the client.
90 struct GNUNET_SERVER_Client *client;
93 * Linked list of messages yet to be transmitted to
96 struct ClientMessageQueueEntry *message_queue_head;
99 * Tail of linked list of messages yet to be transmitted to the
102 struct ClientMessageQueueEntry *message_queue_tail;
105 * Current transmit request handle.
107 struct GNUNET_SERVER_TransmitHandle *th;
110 * Length of the list of messages pending for this client.
112 unsigned int message_count;
115 * Is this client interested in payload messages?
122 * Context for address to string operations
124 struct AddressToStringContext
127 * This is a doubly-linked list.
129 struct AddressToStringContext *next;
132 * This is a doubly-linked list.
134 struct AddressToStringContext *prev;
137 * Transmission context
139 struct GNUNET_SERVER_TransmitContext* tc;
144 * Client monitoring changes of active addresses of our neighbours.
146 struct MonitoringClient
149 * This is a doubly-linked list.
151 struct MonitoringClient *next;
154 * This is a doubly-linked list.
156 struct MonitoringClient *prev;
159 * Handle to the client.
161 struct GNUNET_SERVER_Client *client;
164 * Peer identity to monitor the addresses of.
165 * Zero to monitor all neighrours.
167 struct GNUNET_PeerIdentity peer;
173 * Head of linked list of all clients to this service.
175 static struct TransportClient *clients_head;
178 * Tail of linked list of all clients to this service.
180 static struct TransportClient *clients_tail;
183 * Head of linked list of all pending address iterations
185 struct AddressToStringContext *a2s_head;
188 * Tail of linked list of all pending address iterations
190 struct AddressToStringContext *a2s_tail;
193 * Head of linked list of monitoring clients.
195 static struct MonitoringClient *peer_monitoring_clients_head;
198 * Tail of linked list of monitoring clients.
200 static struct MonitoringClient *peer_monitoring_clients_tail;
203 * Head of linked list of validation monitoring clients.
205 static struct MonitoringClient *val_monitoring_clients_head;
208 * Tail of linked list of validation monitoring clients.
210 static struct MonitoringClient *val_monitoring_clients_tail;
213 * Notification context, to send updates on changes to active addresses
216 static struct GNUNET_SERVER_NotificationContext *peer_nc;
219 * Notification context, to send updates on changes to active addresses
222 static struct GNUNET_SERVER_NotificationContext *val_nc;
225 * Notification context, to send updates on changes to active plugin
228 static struct GNUNET_SERVER_NotificationContext *plugin_nc;
231 * Plugin monitoring client we are currently syncing, NULL if all
232 * monitoring clients are in sync.
234 static struct GNUNET_SERVER_Client *sync_client;
237 * Peer identity that is all zeros, used as a way to indicate
238 * "all peers". Used for comparissons.
240 static struct GNUNET_PeerIdentity all_zeros;
244 * Find the internal handle associated with the given client handle.
246 * @param client server's client handle to look up
247 * @return internal client handle
249 static struct TransportClient *
250 lookup_client (struct GNUNET_SERVER_Client *client)
252 return GNUNET_SERVER_client_get_user_context (client,
253 struct TransportClient);
258 * Create the internal handle for the given server client handle.
260 * @param client server's client handle to create our internal handle for
261 * @return fresh internal client handle
263 static struct TransportClient *
264 setup_client (struct GNUNET_SERVER_Client *client)
266 struct TransportClient *tc;
268 GNUNET_assert (NULL == lookup_client (client));
269 tc = GNUNET_new (struct TransportClient);
271 GNUNET_SERVER_client_set_user_context (client, tc);
272 GNUNET_CONTAINER_DLL_insert (clients_head,
275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
276 "Client %p connected\n",
283 * Find the handle to the monitoring client associated with the given
286 * @param head the head of the client queue to look in
287 * @param client server's client handle to look up
288 * @return handle to the monitoring client
290 static struct MonitoringClient *
291 lookup_monitoring_client (struct MonitoringClient *head,
292 struct GNUNET_SERVER_Client *client)
294 struct MonitoringClient *mc;
296 for (mc = head; NULL != mc; mc = mc->next)
297 if (mc->client == client)
304 * Setup a new monitoring client using the given server client handle and
307 * @param client server's client handle to create our internal handle for
308 * @param peer identity of the peer to monitor the addresses of,
309 * zero to monitor all neighrours.
310 * @return handle to the new monitoring client
312 static struct MonitoringClient *
313 setup_peer_monitoring_client (struct GNUNET_SERVER_Client *client,
314 const struct GNUNET_PeerIdentity *peer)
316 struct MonitoringClient *mc;
318 GNUNET_assert (NULL ==
319 lookup_monitoring_client (peer_monitoring_clients_head,
321 mc = GNUNET_new (struct MonitoringClient);
324 GNUNET_CONTAINER_DLL_insert (peer_monitoring_clients_head,
325 peer_monitoring_clients_tail,
327 GNUNET_SERVER_client_mark_monitor (client);
328 GNUNET_SERVER_notification_context_add (peer_nc,
330 if (0 != memcmp (peer,
332 sizeof (struct GNUNET_PeerIdentity)))
333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
334 "Client %p started monitoring of the peer `%s'\n",
338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
339 "Client %p started monitoring all peers\n",
346 * Setup a new monitoring client using the given server client handle and
349 * @param client server's client handle to create our internal handle for
350 * @param peer identity of the peer to monitor the addresses of,
351 * zero to monitor all neighrours.
352 * @return handle to the new monitoring client
354 static struct MonitoringClient *
355 setup_val_monitoring_client (struct GNUNET_SERVER_Client *client,
356 struct GNUNET_PeerIdentity *peer)
358 struct MonitoringClient *mc;
360 GNUNET_assert (NULL ==
361 lookup_monitoring_client (val_monitoring_clients_head,
363 mc = GNUNET_new (struct MonitoringClient);
366 GNUNET_CONTAINER_DLL_insert (val_monitoring_clients_head,
367 val_monitoring_clients_tail,
369 GNUNET_SERVER_notification_context_add (val_nc, client);
371 if (0 != memcmp (peer,
373 sizeof (struct GNUNET_PeerIdentity)))
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
375 "Client %p started monitoring of the peer `%s'\n",
376 mc, GNUNET_i2s (peer));
378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
379 "Client %p started monitoring all peers\n", mc);
385 * Function called to notify a client about the socket being ready to
386 * queue more data. @a buf will be NULL and @a size zero if the socket
387 * was closed for writing in the meantime.
390 * @param size number of bytes available in @a buf
391 * @param buf where the callee should write the message
392 * @return number of bytes written to @a buf
395 transmit_to_client_callback (void *cls,
399 struct TransportClient *tc = cls;
400 struct ClientMessageQueueEntry *q;
401 const struct GNUNET_MessageHeader *msg;
409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
410 "Transmission to client failed, closing connection.\n");
415 while (NULL != (q = tc->message_queue_head))
417 msg = (const struct GNUNET_MessageHeader *) &q[1];
418 msize = ntohs (msg->size);
419 if (msize + tsize > size)
421 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
422 "Transmitting message of type %u to client %p.\n",
425 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head,
426 tc->message_queue_tail,
429 memcpy (&cbuf[tsize], msg, msize);
435 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
437 GNUNET_SERVER_notify_transmit_ready (tc->client, msize,
438 GNUNET_TIME_UNIT_FOREVER_REL,
439 &transmit_to_client_callback, tc);
440 GNUNET_assert (NULL != tc->th);
447 * Queue the given message for transmission to the given client
449 * @param tc target of the message
450 * @param msg message to transmit
451 * @param may_drop #GNUNET_YES if the message can be dropped
454 unicast (struct TransportClient *tc,
455 const struct GNUNET_MessageHeader *msg,
458 struct ClientMessageQueueEntry *q;
466 if ( (tc->message_count >= MAX_PENDING) &&
467 (GNUNET_YES == may_drop) )
469 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
470 _("Dropping message of type %u and size %u, have %u/%u messages pending\n"),
475 GNUNET_STATISTICS_update (GST_stats,
477 ("# messages dropped due to slow client"), 1,
481 msize = ntohs (msg->size);
482 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
483 q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize);
484 memcpy (&q[1], msg, msize);
485 GNUNET_CONTAINER_DLL_insert_tail (tc->message_queue_head,
486 tc->message_queue_tail,
492 GNUNET_SERVER_notify_transmit_ready (tc->client, msize,
493 GNUNET_TIME_UNIT_FOREVER_REL,
494 &transmit_to_client_callback, tc);
495 GNUNET_assert (NULL != tc->th);
500 * Called whenever a client is disconnected. Frees our
501 * resources associated with that client.
503 * @param cls closure, NULL
504 * @param client identification of the client
507 client_disconnect_notification (void *cls,
508 struct GNUNET_SERVER_Client *client)
510 struct TransportClient *tc;
511 struct MonitoringClient *mc;
512 struct ClientMessageQueueEntry *mqe;
516 mc = lookup_monitoring_client (peer_monitoring_clients_head,
520 GNUNET_CONTAINER_DLL_remove (peer_monitoring_clients_head,
521 peer_monitoring_clients_tail,
525 mc = lookup_monitoring_client (val_monitoring_clients_head,
529 GNUNET_CONTAINER_DLL_remove (val_monitoring_clients_head,
530 val_monitoring_clients_tail,
534 tc = lookup_client (client);
537 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
538 "Client %p disconnected, cleaning up.\n", tc);
539 while (NULL != (mqe = tc->message_queue_head))
541 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head, tc->message_queue_tail,
546 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc);
547 GNUNET_SERVER_client_set_user_context (client, NULL);
550 GNUNET_SERVER_notify_transmit_ready_cancel (tc->th);
553 GNUNET_break (0 == tc->message_count);
559 * Function called for each of our connected neighbours. Notify the
560 * client about the existing neighbour.
562 * @param cls the `struct TransportClient *` to notify
563 * @param peer identity of the neighbour
564 * @param address the address
565 * @param state the current state of the peer
566 * @param state_timeout the time out for the state
567 * @param bandwidth_in inbound bandwidth in NBO
568 * @param bandwidth_out outbound bandwidth in NBO
571 notify_client_about_neighbour (void *cls,
572 const struct GNUNET_PeerIdentity *peer,
573 const struct GNUNET_HELLO_Address *address,
574 enum GNUNET_TRANSPORT_PeerState state,
575 struct GNUNET_TIME_Absolute state_timeout,
576 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
577 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
579 struct TransportClient *tc = cls;
580 struct ConnectInfoMessage *cim;
581 size_t size = sizeof (struct ConnectInfoMessage);
582 char buf[size] GNUNET_ALIGN;
584 if (GNUNET_NO == GST_neighbours_test_connected (peer))
587 GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
588 cim = (struct ConnectInfoMessage *) buf;
589 cim->header.size = htons (size);
590 cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
592 cim->quota_in = bandwidth_in;
593 cim->quota_out = bandwidth_out;
594 unicast (tc, &cim->header, GNUNET_NO);
599 * Initialize a normal client. We got a start message from this
600 * client, add him to the list of clients for broadcasting of inbound
604 * @param client the client
605 * @param message the start message that was sent
608 clients_handle_start (void *cls,
609 struct GNUNET_SERVER_Client *client,
610 const struct GNUNET_MessageHeader *message)
612 const struct StartMessage *start;
613 struct TransportClient *tc;
616 tc = lookup_client (client);
618 GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
619 "Client %p sent START\n", tc);
622 /* got 'start' twice from the same client, not allowed */
623 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
624 "TransportClient %p ServerClient %p sent multiple START messages\n",
627 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
630 start = (const struct StartMessage *) message;
631 options = ntohl (start->options);
632 if ((0 != (1 & options)) &&
634 memcmp (&start->self, &GST_my_identity,
635 sizeof (struct GNUNET_PeerIdentity))))
637 /* client thinks this is a different peer, reject */
638 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
639 _("Rejecting control connection from peer `%s', which is not me!\n"),
640 GNUNET_i2s (&start->self));
641 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
644 tc = setup_client (client);
645 tc->send_payload = (0 != (2 & options));
649 GST_neighbours_iterate (¬ify_client_about_neighbour, tc);
650 GNUNET_SERVER_receive_done (client, GNUNET_OK);
655 * Client sent us a HELLO. Process the request.
658 * @param client the client
659 * @param message the HELLO message
662 clients_handle_hello (void *cls, struct GNUNET_SERVER_Client *client,
663 const struct GNUNET_MessageHeader *message)
665 GST_validation_handle_hello (message);
666 GNUNET_SERVER_receive_done (client, GNUNET_OK);
671 * Closure for #handle_send_transmit_continuation()
673 struct SendTransmitContinuationContext
676 * Client that made the request.
678 struct GNUNET_SERVER_Client *client;
681 * Peer that was the target.
683 struct GNUNET_PeerIdentity target;
688 * Function called after the transmission is done. Notify the client that it is
689 * OK to send the next message.
692 * @param success #GNUNET_OK on success, #GNUNET_NO on failure, #GNUNET_SYSERR if we're not connected
693 * @param bytes_payload bytes payload sent
694 * @param bytes_on_wire bytes sent on wire
697 handle_send_transmit_continuation (void *cls,
699 size_t bytes_payload,
700 size_t bytes_on_wire)
702 struct SendTransmitContinuationContext *stcc = cls;
703 struct SendOkMessage send_ok_msg;
705 if (GNUNET_OK == success)
706 GST_neighbours_notify_payload_sent (&stcc->target,
708 send_ok_msg.header.size = htons (sizeof (send_ok_msg));
709 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
710 send_ok_msg.bytes_msg = htonl (bytes_payload);
711 send_ok_msg.bytes_physical = htonl (bytes_on_wire);
712 send_ok_msg.success = htonl (success);
713 send_ok_msg.peer = stcc->target;
714 GST_clients_unicast (stcc->client,
717 GNUNET_SERVER_client_drop (stcc->client);
723 * Client asked for transmission to a peer. Process the request.
726 * @param client the client
727 * @param message the send message that was sent
730 clients_handle_send (void *cls,
731 struct GNUNET_SERVER_Client *client,
732 const struct GNUNET_MessageHeader *message)
734 const struct OutboundMessage *obm;
735 const struct GNUNET_MessageHeader *obmm;
736 struct SendTransmitContinuationContext *stcc;
739 struct TransportClient *tc;
741 tc = lookup_client (client);
744 /* client asked for transmission before 'START' */
746 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
750 size = ntohs (message->size);
752 sizeof (struct OutboundMessage) + sizeof (struct GNUNET_MessageHeader))
755 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
758 obm = (const struct OutboundMessage *) message;
759 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
760 msize = size - sizeof (struct OutboundMessage);
761 if (msize < sizeof (struct GNUNET_MessageHeader))
764 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
768 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
769 "Received `%s' request from client with target `%4s' and first message of type %u and total size %u\n",
771 GNUNET_i2s (&obm->peer),
774 if (GNUNET_NO == GST_neighbours_test_connected (&obm->peer))
776 /* not connected, not allowed to send; can happen due to asynchronous operations */
777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
778 "Could not send message to peer `%s': not connected\n",
779 GNUNET_i2s (&obm->peer));
780 GNUNET_STATISTICS_update (GST_stats,
782 ("# bytes payload dropped (other peer was not connected)"),
784 GNUNET_SERVER_receive_done (client, GNUNET_OK);
787 GNUNET_SERVER_receive_done (client, GNUNET_OK);
788 stcc = GNUNET_new (struct SendTransmitContinuationContext);
789 stcc->target = obm->peer;
790 stcc->client = client;
791 GNUNET_SERVER_client_keep (client);
792 GST_manipulation_send (&obm->peer, obmm, msize,
793 GNUNET_TIME_relative_ntoh (obm->timeout),
794 &handle_send_transmit_continuation, stcc);
799 * Try to initiate a connection to the given peer if the blacklist
802 * @param cls closure (unused, NULL)
803 * @param peer identity of peer that was tested
804 * @param result #GNUNET_OK if the connection is allowed,
808 try_connect_if_allowed (void *cls,
809 const struct GNUNET_PeerIdentity *peer,
812 if (GNUNET_OK != result)
814 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
815 _("Blacklist refuses connection attempt to peer `%s'\n"),
817 return; /* not allowed */
820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
821 _("Blacklist allows connection attempt to peer `%s'\n"),
824 GST_neighbours_try_connect (peer);
829 * Handle request connect message
831 * @param cls closure (always NULL)
832 * @param client identification of the client
833 * @param message the actual message
836 clients_handle_request_connect (void *cls,
837 struct GNUNET_SERVER_Client *client,
838 const struct GNUNET_MessageHeader *message)
840 const struct TransportRequestConnectMessage *trcm;
842 trcm = (const struct TransportRequestConnectMessage *) message;
843 GNUNET_break (0 == ntohl (trcm->reserved));
844 GNUNET_STATISTICS_update (GST_stats,
846 ("# REQUEST CONNECT messages received"), 1,
848 if (0 == memcmp (&trcm->peer,
850 sizeof (struct GNUNET_PeerIdentity)))
853 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
854 "Received a request connect message myself `%s'\n",
855 GNUNET_i2s (&trcm->peer));
856 GNUNET_SERVER_receive_done (client, GNUNET_OK);
859 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
860 _("Received a request connect message for peer `%s'\n"),
861 GNUNET_i2s (&trcm->peer));
862 (void) GST_blacklist_test_allowed (&trcm->peer,
864 &try_connect_if_allowed,
866 GNUNET_SERVER_receive_done (client, GNUNET_OK);
871 * Handle request disconnect message
873 * @param cls closure (always NULL)
874 * @param client identification of the client
875 * @param message the actual message
878 clients_handle_request_disconnect (void *cls,
879 struct GNUNET_SERVER_Client *client,
880 const struct GNUNET_MessageHeader *message)
882 const struct TransportRequestDisconnectMessage *trdm;
884 trdm = (const struct TransportRequestDisconnectMessage *) message;
885 GNUNET_break (0 == ntohl (trdm->reserved));
886 GNUNET_STATISTICS_update (GST_stats,
888 ("# REQUEST DISCONNECT messages received"), 1,
890 if (0 == memcmp (&trdm->peer,
892 sizeof (struct GNUNET_PeerIdentity)))
895 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
896 "Received a request disconnect message myself `%s'\n",
897 GNUNET_i2s (&trdm->peer));
898 GNUNET_SERVER_receive_done (client, GNUNET_OK);
901 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
902 _("Received a request disconnect message for peer `%s'\n"),
903 GNUNET_i2s (&trdm->peer));
904 (void) GST_neighbours_force_disconnect (&trdm->peer);
905 GNUNET_SERVER_receive_done (client, GNUNET_OK);
910 * Take the given address and append it to the set of results sent back to
911 * the client. This function may be called serveral times for a single
912 * conversion. The last invocation will be with a @a address of
913 * NULL and a @a res of #GNUNET_OK. Thus, to indicate conversion
914 * errors, the callback might be called first with @a address NULL and
915 * @a res being #GNUNET_SYSERR. In that case, there will still be a
916 * subsequent call later with @a address NULL and @a res #GNUNET_OK.
918 * @param cls the transmission context used (`struct GNUNET_SERVER_TransmitContext *`)
919 * @param buf text to transmit (contains the human-readable address, or NULL)
920 * @param res #GNUNET_OK if conversion was successful, #GNUNET_SYSERR on error,
924 transmit_address_to_client (void *cls,
928 struct AddressToStringContext *actx = cls;
929 struct AddressToStringResultMessage *atsm;
933 GNUNET_assert ( (GNUNET_OK == res) ||
934 (GNUNET_SYSERR == res) );
937 len = sizeof (struct AddressToStringResultMessage);
938 atsm = GNUNET_malloc (len);
939 atsm->header.size = ntohs (len);
940 atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
941 if (GNUNET_OK == res)
943 /* this was the last call, transmit */
944 atsm->res = htonl (GNUNET_OK);
945 atsm->addr_len = htonl (0);
946 GNUNET_SERVER_transmit_context_append_message (actx->tc,
947 (const struct GNUNET_MessageHeader *) atsm);
948 GNUNET_SERVER_transmit_context_run (actx->tc,
949 GNUNET_TIME_UNIT_FOREVER_REL);
950 GNUNET_CONTAINER_DLL_remove (a2s_head,
957 if (GNUNET_SYSERR == res)
959 /* address conversion failed, but there will be more callbacks */
960 atsm->res = htonl (GNUNET_SYSERR);
961 atsm->addr_len = htonl (0);
962 GNUNET_SERVER_transmit_context_append_message (actx->tc,
963 (const struct GNUNET_MessageHeader *) atsm);
968 GNUNET_assert (GNUNET_OK == res);
969 /* succesful conversion, append*/
970 slen = strlen (buf) + 1;
971 len = sizeof (struct AddressToStringResultMessage) + slen;
972 atsm = GNUNET_malloc (len);
973 atsm->header.size = ntohs (len);
974 atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
975 atsm->res = htonl (GNUNET_YES);
976 atsm->addr_len = htonl (slen);
980 GNUNET_SERVER_transmit_context_append_message (actx->tc,
981 (const struct GNUNET_MessageHeader *) atsm);
987 * Client asked to resolve an address. Process the request.
990 * @param client the client
991 * @param message the resolution request
994 clients_handle_address_to_string (void *cls,
995 struct GNUNET_SERVER_Client *client,
996 const struct GNUNET_MessageHeader *message)
998 const struct AddressLookupMessage *alum;
999 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1000 const char *plugin_name;
1001 const char *address;
1002 uint32_t address_len;
1004 struct GNUNET_SERVER_TransmitContext *tc;
1005 struct AddressToStringContext *actx;
1006 struct AddressToStringResultMessage atsm;
1007 struct GNUNET_TIME_Relative rtimeout;
1010 size = ntohs (message->size);
1011 if (size < sizeof (struct AddressLookupMessage))
1014 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1017 alum = (const struct AddressLookupMessage *) message;
1018 address_len = ntohs (alum->addrlen);
1019 if (size <= sizeof (struct AddressLookupMessage) + address_len)
1022 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1025 address = (const char *) &alum[1];
1026 plugin_name = (const char *) &address[address_len];
1027 if ('\0' != plugin_name[size - sizeof (struct AddressLookupMessage) - address_len - 1])
1030 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1033 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
1034 numeric = ntohs (alum->numeric_only);
1035 tc = GNUNET_SERVER_transmit_context_create (client);
1036 papi = GST_plugins_printer_find (plugin_name);
1039 atsm.header.size = ntohs (sizeof (struct AddressToStringResultMessage));
1040 atsm.header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
1041 atsm.res = htonl (GNUNET_SYSERR);
1042 atsm.addr_len = htonl (0);
1043 GNUNET_SERVER_transmit_context_append_message (tc,
1045 atsm.header.size = ntohs (sizeof (struct AddressToStringResultMessage));
1046 atsm.header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
1047 atsm.res = htonl (GNUNET_OK);
1048 atsm.addr_len = htonl (0);
1049 GNUNET_SERVER_transmit_context_append_message (tc,
1051 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
1054 actx = GNUNET_new (struct AddressToStringContext);
1056 GNUNET_CONTAINER_DLL_insert (a2s_head, a2s_tail, actx);
1057 GNUNET_SERVER_disable_receive_done_warning (client);
1058 papi->address_pretty_printer (papi->cls,
1060 address, address_len,
1063 &transmit_address_to_client,
1069 * Compose #PeerIterateResponseMessage using the given peer and address.
1071 * @param peer identity of the peer
1072 * @param address the address, NULL on disconnect
1073 * @return composed message
1075 static struct PeerIterateResponseMessage *
1076 compose_address_iterate_response_message (const struct GNUNET_PeerIdentity *peer,
1077 const struct GNUNET_HELLO_Address *address)
1079 struct PeerIterateResponseMessage *msg;
1085 GNUNET_assert (NULL != peer);
1086 if (NULL != address)
1088 tlen = strlen (address->transport_name) + 1;
1089 alen = address->address_length;
1093 size = (sizeof (struct PeerIterateResponseMessage) + alen + tlen);
1094 msg = GNUNET_malloc (size);
1095 msg->header.size = htons (size);
1097 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE);
1098 msg->reserved = htonl (0);
1100 msg->addrlen = htonl (alen);
1101 msg->pluginlen = htonl (tlen);
1103 if (NULL != address)
1105 msg->local_address_info = htonl((uint32_t) address->local_info);
1106 addr = (char *) &msg[1];
1107 memcpy (addr, address->address, alen);
1108 memcpy (&addr[alen], address->transport_name, tlen);
1115 * Compose #PeerIterateResponseMessage using the given peer and address.
1117 * @param peer identity of the peer
1118 * @param address the address, NULL on disconnect
1119 * @return composed message
1121 static struct ValidationIterateResponseMessage *
1122 compose_validation_iterate_response_message (const struct GNUNET_PeerIdentity *peer,
1123 const struct GNUNET_HELLO_Address *address)
1125 struct ValidationIterateResponseMessage *msg;
1131 GNUNET_assert (NULL != peer);
1132 if (NULL != address)
1134 tlen = strlen (address->transport_name) + 1;
1135 alen = address->address_length;
1139 size = (sizeof (struct ValidationIterateResponseMessage) + alen + tlen);
1140 msg = GNUNET_malloc (size);
1141 msg->header.size = htons (size);
1143 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE);
1144 msg->reserved = htonl (0);
1146 msg->addrlen = htonl (alen);
1147 msg->pluginlen = htonl (tlen);
1149 if (NULL != address)
1151 msg->local_address_info = htonl((uint32_t) address->local_info);
1152 addr = (char *) &msg[1];
1153 memcpy (addr, address->address, alen);
1154 memcpy (&addr[alen], address->transport_name, tlen);
1161 * Context for #send_validation_information() and
1162 * #send_peer_information().
1164 struct IterationContext
1167 * Context to use for the transmission.
1169 struct GNUNET_SERVER_TransmitContext *tc;
1172 * Which peers do we care about?
1174 struct GNUNET_PeerIdentity id;
1177 * #GNUNET_YES if @e id should be ignored because we want all peers.
1184 * Output information of validation entries to the given client.
1186 * @param cls the `struct IterationContext *`
1187 * @param peer identity of the neighbour
1188 * @param address the address
1189 * @param last_validation point in time when last validation was performed
1190 * @param valid_until point in time how long address is valid
1191 * @param next_validation point in time when next validation will be performed
1192 * @param state state of validation notification
1195 send_validation_information (void *cls,
1196 const struct GNUNET_PeerIdentity *peer,
1197 const struct GNUNET_HELLO_Address *address,
1198 struct GNUNET_TIME_Absolute last_validation,
1199 struct GNUNET_TIME_Absolute valid_until,
1200 struct GNUNET_TIME_Absolute next_validation,
1201 enum GNUNET_TRANSPORT_ValidationState state)
1203 struct IterationContext *pc = cls;
1204 struct ValidationIterateResponseMessage *msg;
1206 if ( (GNUNET_YES == pc->all) ||
1207 (0 == memcmp (peer, &pc->id, sizeof (pc->id))) )
1209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1210 "Sending information about for validation entry for peer `%s' using address `%s'\n",
1211 GNUNET_i2s(peer), (address != NULL) ? GST_plugins_a2s (address) : "<none>");
1212 msg = compose_validation_iterate_response_message (peer, address);
1213 msg->last_validation = GNUNET_TIME_absolute_hton(last_validation);
1214 msg->valid_until = GNUNET_TIME_absolute_hton(valid_until);
1215 msg->next_validation = GNUNET_TIME_absolute_hton(next_validation);
1216 msg->state = htonl ((uint32_t) state);
1217 GNUNET_SERVER_transmit_context_append_message (pc->tc, &msg->header);
1224 * Output information of neighbours to the given client.
1226 * @param cls the `struct PeerIterationContext *`
1227 * @param peer identity of the neighbour
1228 * @param address the address
1229 * @param state current state this peer is in
1230 * @param state_timeout timeout for the current state of the peer
1231 * @param bandwidth_in inbound quota in NBO
1232 * @param bandwidth_out outbound quota in NBO
1235 send_peer_information (void *cls,
1236 const struct GNUNET_PeerIdentity *peer,
1237 const struct GNUNET_HELLO_Address *address,
1238 enum GNUNET_TRANSPORT_PeerState state,
1239 struct GNUNET_TIME_Absolute state_timeout,
1240 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1241 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1243 struct IterationContext *pc = cls;
1244 struct PeerIterateResponseMessage *msg;
1246 if ( (GNUNET_YES == pc->all) ||
1247 (0 == memcmp (peer, &pc->id, sizeof (pc->id))) )
1249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1250 "Sending information about `%s' using address `%s' in state `%s'\n",
1252 (address != NULL) ? GST_plugins_a2s (address) : "<none>",
1253 GNUNET_TRANSPORT_ps2s (state));
1254 msg = compose_address_iterate_response_message (peer, address);
1255 msg->state = htonl (state);
1256 msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout);
1257 GNUNET_SERVER_transmit_context_append_message (pc->tc, &msg->header);
1264 * Client asked to obtain information about a specific or all peers
1265 * Process the request.
1268 * @param client the client
1269 * @param message the peer address information request
1272 clients_handle_monitor_peers (void *cls,
1273 struct GNUNET_SERVER_Client *client,
1274 const struct GNUNET_MessageHeader *message)
1276 struct GNUNET_SERVER_TransmitContext *tc;
1277 const struct PeerMonitorMessage *msg;
1278 struct IterationContext pc;
1280 msg = (const struct PeerMonitorMessage *) message;
1281 if ( (GNUNET_YES != ntohl (msg->one_shot)) &&
1282 (NULL != lookup_monitoring_client (peer_monitoring_clients_head,
1285 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
1286 "ServerClient %p tried to start monitoring twice\n",
1289 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1292 GNUNET_SERVER_disable_receive_done_warning (client);
1293 GNUNET_SERVER_client_mark_monitor (client);
1294 pc.tc = tc = GNUNET_SERVER_transmit_context_create (client);
1296 /* Send initial list */
1297 if (0 == memcmp (&msg->peer, &all_zeros, sizeof (struct GNUNET_PeerIdentity)))
1299 /* iterate over all neighbours */
1300 pc.all = GNUNET_YES;
1305 /* just return one neighbour */
1309 GST_neighbours_iterate (&send_peer_information, &pc);
1311 if (GNUNET_YES != ntohl (msg->one_shot))
1313 setup_peer_monitoring_client (client, &msg->peer);
1317 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
1318 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE);
1321 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
1326 * Client asked to obtain information about a specific or all validation
1330 * @param client the client
1331 * @param message the peer address information request
1334 clients_handle_monitor_validation (void *cls,
1335 struct GNUNET_SERVER_Client *client,
1336 const struct GNUNET_MessageHeader *message)
1338 struct GNUNET_SERVER_TransmitContext *tc;
1339 struct PeerMonitorMessage *msg;
1340 struct IterationContext pc;
1342 if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST)
1345 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1348 if (ntohs (message->size) != sizeof (struct ValidationMonitorMessage))
1351 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1354 msg = (struct PeerMonitorMessage *) message;
1355 if ( (GNUNET_YES != ntohl (msg->one_shot)) &&
1356 (NULL != lookup_monitoring_client (val_monitoring_clients_head, client)) )
1358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
1359 "ServerClient %p tried to start monitoring twice\n",
1362 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1365 GNUNET_SERVER_disable_receive_done_warning (client);
1366 GNUNET_SERVER_client_mark_monitor (client);
1367 pc.tc = tc = GNUNET_SERVER_transmit_context_create (client);
1369 /* Send initial list */
1370 if (0 == memcmp (&msg->peer, &all_zeros, sizeof (struct GNUNET_PeerIdentity)))
1372 /* iterate over all neighbours */
1373 pc.all = GNUNET_YES;
1378 /* just return one neighbour */
1383 GST_validation_iterate (&send_validation_information, &pc);
1385 if (GNUNET_YES != ntohl (msg->one_shot))
1387 setup_val_monitoring_client (client, &msg->peer);
1391 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
1392 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE);
1394 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
1399 * Function called by the plugin with information about the
1400 * current sessions managed by the plugin (for monitoring).
1402 * @param cls closure
1403 * @param session session handle this information is about,
1404 * NULL to indicate that we are "in sync" (initial
1405 * iteration complete)
1406 * @param info information about the state of the session,
1407 * NULL if @a session is also NULL and we are
1408 * merely signalling that the initial iteration is over
1411 plugin_session_info_cb (void *cls,
1412 struct Session *session,
1413 const struct GNUNET_TRANSPORT_SessionInfo *info)
1415 struct TransportPluginMonitorMessage *msg;
1416 struct GNUNET_MessageHeader sync;
1423 if (0 == GNUNET_SERVER_notification_context_get_size (plugin_nc))
1425 fprintf (stderr, "UNSUB!\n");
1426 GST_plugins_monitor_subscribe (NULL, NULL);
1429 if ( (NULL == info) &&
1432 /* end of initial iteration */
1433 if (NULL != sync_client)
1435 sync.size = htons (sizeof (struct GNUNET_MessageHeader));
1436 sync.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC);
1437 GNUNET_SERVER_notification_context_unicast (plugin_nc,
1445 GNUNET_assert (NULL != info);
1446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1447 "Plugin event for peer %s on transport %s\n",
1448 GNUNET_i2s (&info->address->peer),
1449 info->address->transport_name);
1450 slen = strlen (info->address->transport_name) + 1;
1451 alen = info->address->address_length;
1452 size = sizeof (struct TransportPluginMonitorMessage) + slen + alen;
1453 if (size > UINT16_MAX)
1458 msg = GNUNET_malloc (size);
1459 msg->header.size = htons (size);
1460 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT);
1461 msg->session_state = htons ((uint16_t) info->state);
1462 msg->is_inbound = htons ((int16_t) info->is_inbound);
1463 msg->msgs_pending = htonl (info->num_msg_pending);
1464 msg->bytes_pending = htonl (info->num_bytes_pending);
1465 msg->timeout = GNUNET_TIME_absolute_hton (info->session_timeout);
1466 msg->delay = GNUNET_TIME_absolute_hton (info->receive_delay);
1467 msg->peer = info->address->peer;
1468 msg->session_id = (uint64_t) (intptr_t) session;
1469 msg->plugin_name_len = htons (slen);
1470 msg->plugin_address_len = htons (alen);
1471 name = (char *) &msg[1];
1472 memcpy (name, info->address->transport_name, slen);
1473 addr = &name[slen + 1];
1474 memcpy (addr, info->address->address, alen);
1475 if (NULL != sync_client)
1476 GNUNET_SERVER_notification_context_unicast (plugin_nc,
1481 GNUNET_SERVER_notification_context_broadcast (plugin_nc,
1489 * Client asked to obtain information about all plugin connections.
1492 * @param client the client
1493 * @param message the peer address information request
1496 clients_handle_monitor_plugins (void *cls,
1497 struct GNUNET_SERVER_Client *client,
1498 const struct GNUNET_MessageHeader *message)
1500 GNUNET_SERVER_client_mark_monitor (client);
1501 GNUNET_SERVER_disable_receive_done_warning (client);
1502 GNUNET_SERVER_notification_context_add (plugin_nc, client);
1503 sync_client = client;
1504 GST_plugins_monitor_subscribe (&plugin_session_info_cb, NULL);
1509 * Start handling requests from clients.
1511 * @param server server used to accept clients from.
1514 GST_clients_start (struct GNUNET_SERVER_Handle *server)
1516 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
1517 {&clients_handle_start, NULL,
1518 GNUNET_MESSAGE_TYPE_TRANSPORT_START, sizeof (struct StartMessage)},
1519 {&clients_handle_hello, NULL,
1520 GNUNET_MESSAGE_TYPE_HELLO, 0},
1521 {&clients_handle_send, NULL,
1522 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0},
1523 {&clients_handle_request_connect, NULL,
1524 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT,
1525 sizeof (struct TransportRequestConnectMessage)},
1526 {&clients_handle_request_disconnect, NULL,
1527 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_DISCONNECT,
1528 sizeof (struct TransportRequestDisconnectMessage)},
1529 {&clients_handle_address_to_string, NULL,
1530 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0},
1531 {&clients_handle_monitor_peers, NULL,
1532 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST,
1533 sizeof (struct PeerMonitorMessage)},
1534 {&clients_handle_monitor_validation, NULL,
1535 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST,
1536 sizeof (struct ValidationMonitorMessage)},
1537 {&GST_blacklist_handle_init, NULL,
1538 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
1539 sizeof (struct GNUNET_MessageHeader)},
1540 {&GST_blacklist_handle_reply, NULL,
1541 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
1542 sizeof (struct BlacklistMessage)},
1543 {&GST_manipulation_set_metric, NULL,
1544 GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC, 0},
1545 {&clients_handle_monitor_plugins, NULL,
1546 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START,
1547 sizeof (struct GNUNET_MessageHeader) },
1550 peer_nc = GNUNET_SERVER_notification_context_create (server, 0);
1551 val_nc = GNUNET_SERVER_notification_context_create (server, 0);
1552 plugin_nc = GNUNET_SERVER_notification_context_create (server, 0);
1553 GNUNET_SERVER_add_handlers (server, handlers);
1554 GNUNET_SERVER_disconnect_notify (server,
1555 &client_disconnect_notification,
1561 * Stop processing clients.
1566 struct AddressToStringContext *cur;
1568 while (NULL != (cur = a2s_head))
1570 GNUNET_SERVER_transmit_context_destroy (cur->tc, GNUNET_NO);
1571 GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, cur);
1574 if (NULL != peer_nc)
1576 GNUNET_SERVER_notification_context_destroy (peer_nc);
1581 GNUNET_SERVER_notification_context_destroy (val_nc);
1584 if (NULL != plugin_nc)
1586 GNUNET_SERVER_notification_context_destroy (plugin_nc);
1593 * Broadcast the given message to all of our clients.
1595 * @param msg message to broadcast
1596 * @param may_drop #GNUNET_YES if the message can be dropped / is payload
1599 GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
1602 struct TransportClient *tc;
1604 for (tc = clients_head; NULL != tc; tc = tc->next)
1606 if ( (GNUNET_YES == may_drop) &&
1607 (GNUNET_YES != tc->send_payload) )
1608 continue; /* skip, this client does not care about payload */
1609 unicast (tc, msg, may_drop);
1615 * Send the given message to a particular client
1617 * @param client target of the message
1618 * @param msg message to transmit
1619 * @param may_drop #GNUNET_YES if the message can be dropped
1622 GST_clients_unicast (struct GNUNET_SERVER_Client *client,
1623 const struct GNUNET_MessageHeader *msg,
1626 struct TransportClient *tc;
1628 tc = lookup_client (client);
1630 return; /* client got disconnected in the meantime, drop message */
1631 unicast (tc, msg, may_drop);
1636 * Broadcast the new active address to all clients monitoring the peer.
1638 * @param peer peer this update is about (never NULL)
1639 * @param address address, NULL on disconnect
1640 * @param state the current state of the peer
1641 * @param state_timeout the time out for the state
1644 GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer,
1645 const struct GNUNET_HELLO_Address *address,
1646 enum GNUNET_TRANSPORT_PeerState state,
1647 struct GNUNET_TIME_Absolute state_timeout)
1649 struct PeerIterateResponseMessage *msg;
1650 struct MonitoringClient *mc;
1652 msg = compose_address_iterate_response_message (peer, address);
1653 msg->state = htonl (state);
1654 msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout);
1655 mc = peer_monitoring_clients_head;
1658 if ((0 == memcmp (&mc->peer, &all_zeros,
1659 sizeof (struct GNUNET_PeerIdentity))) ||
1660 (0 == memcmp (&mc->peer, peer,
1661 sizeof (struct GNUNET_PeerIdentity))))
1663 GNUNET_SERVER_notification_context_unicast (peer_nc, mc->client,
1664 &msg->header, GNUNET_NO);
1673 * Broadcast the new validation changes to all clients monitoring the peer.
1675 * @param peer peer this update is about (never NULL)
1676 * @param address address, NULL on disconnect
1677 * @param last_validation point in time when last validation was performed
1678 * @param valid_until point in time how long address is valid
1679 * @param next_validation point in time when next validation will be performed
1680 * @param state state of validation notification
1683 GST_clients_broadcast_validation_notification (const struct GNUNET_PeerIdentity *peer,
1684 const struct GNUNET_HELLO_Address *address,
1685 struct GNUNET_TIME_Absolute last_validation,
1686 struct GNUNET_TIME_Absolute valid_until,
1687 struct GNUNET_TIME_Absolute next_validation,
1688 enum GNUNET_TRANSPORT_ValidationState state)
1690 struct ValidationIterateResponseMessage *msg;
1691 struct MonitoringClient *mc;
1693 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1694 "Sending information about for validation entry for peer `%s' using address `%s'\n",
1695 GNUNET_i2s(peer), (address != NULL) ? GST_plugins_a2s (address) : "<none>");
1697 msg = compose_validation_iterate_response_message (peer, address);
1698 msg->last_validation = GNUNET_TIME_absolute_hton(last_validation);
1699 msg->valid_until = GNUNET_TIME_absolute_hton(valid_until);
1700 msg->next_validation = GNUNET_TIME_absolute_hton(next_validation);
1701 msg->state = htonl ((uint32_t) state);
1702 mc = val_monitoring_clients_head;
1705 if ((0 == memcmp (&mc->peer, &all_zeros,
1706 sizeof (struct GNUNET_PeerIdentity))) ||
1707 (0 == memcmp (&mc->peer, peer,
1708 sizeof (struct GNUNET_PeerIdentity))))
1710 GNUNET_SERVER_notification_context_unicast (val_nc, mc->client,
1711 &msg->header, GNUNET_NO);
1720 /* end of file gnunet-service-transport_clients.c */