2 This file is part of GNUnet.
3 Copyright (C) 2010-2015 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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file transport/gnunet-service-transport_clients.c
23 * @brief communication with clients (core service and monitors)
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 or validations
145 * of our neighbours. Which type is being monitored depends on the
146 * DLL this struct is in.
148 struct MonitoringClient
151 * This is a doubly-linked list.
153 struct MonitoringClient *next;
156 * This is a doubly-linked list.
158 struct MonitoringClient *prev;
161 * Handle to the client.
163 struct GNUNET_SERVER_Client *client;
166 * Peer identity to monitor the addresses of.
167 * Zero to monitor all neighrours.
169 struct GNUNET_PeerIdentity peer;
175 * Closure for #handle_send_transmit_continuation()
177 struct SendTransmitContinuationContext
180 * Client that made the request.
182 struct GNUNET_SERVER_Client *client;
185 * Peer that was the target.
187 struct GNUNET_PeerIdentity target;
190 * At what time did we receive the message?
192 struct GNUNET_TIME_Absolute send_time;
195 * Unique ID, for logging.
197 unsigned long long uuid;
200 * Set to #GNUNET_YES if the connection for @e target goes
201 * down and we thus must no longer send the
202 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK message.
209 * Head of linked list of all clients to this service.
211 static struct TransportClient *clients_head;
214 * Tail of linked list of all clients to this service.
216 static struct TransportClient *clients_tail;
219 * Map of peer identities to active send transmit continuation
220 * contexts. Used to flag contexts as 'dead' when a connection goes
221 * down. Values are of type `struct SendTransmitContinuationContext
224 static struct GNUNET_CONTAINER_MultiPeerMap *active_stccs;
227 * Head of linked list of all pending address iterations
229 static struct AddressToStringContext *a2s_head;
232 * Tail of linked list of all pending address iterations
234 static struct AddressToStringContext *a2s_tail;
237 * Head of linked list of monitoring clients.
239 static struct MonitoringClient *peer_monitoring_clients_head;
242 * Tail of linked list of monitoring clients.
244 static struct MonitoringClient *peer_monitoring_clients_tail;
247 * Head of linked list of validation monitoring clients.
249 static struct MonitoringClient *val_monitoring_clients_head;
252 * Tail of linked list of validation monitoring clients.
254 static struct MonitoringClient *val_monitoring_clients_tail;
257 * Notification context, to send updates on changes to active addresses
260 static struct GNUNET_SERVER_NotificationContext *peer_nc;
263 * Notification context, to send updates on changes to active addresses
266 static struct GNUNET_SERVER_NotificationContext *val_nc;
269 * Notification context, to send updates on changes to active plugin
272 static struct GNUNET_SERVER_NotificationContext *plugin_nc;
275 * Plugin monitoring client we are currently syncing, NULL if all
276 * monitoring clients are in sync.
278 static struct GNUNET_SERVER_Client *sync_client;
281 * Peer identity that is all zeros, used as a way to indicate
282 * "all peers". Used for comparissons.
284 static struct GNUNET_PeerIdentity all_zeros;
288 * Find the internal handle associated with the given client handle.
290 * @param client server's client handle to look up
291 * @return internal client handle
293 static struct TransportClient *
294 lookup_client (struct GNUNET_SERVER_Client *client)
296 return GNUNET_SERVER_client_get_user_context (client,
297 struct TransportClient);
302 * Create the internal handle for the given server client handle.
304 * @param client server's client handle to create our internal handle for
305 * @return fresh internal client handle
307 static struct TransportClient *
308 setup_client (struct GNUNET_SERVER_Client *client)
310 struct TransportClient *tc;
312 GNUNET_assert (NULL == lookup_client (client));
313 tc = GNUNET_new (struct TransportClient);
315 GNUNET_SERVER_client_set_user_context (client, tc);
316 GNUNET_CONTAINER_DLL_insert (clients_head,
319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
320 "Client %p connected\n",
327 * Find the handle to the monitoring client associated with the given
330 * @param head the head of the client queue to look in
331 * @param client server's client handle to look up
332 * @return handle to the monitoring client
334 static struct MonitoringClient *
335 lookup_monitoring_client (struct MonitoringClient *head,
336 struct GNUNET_SERVER_Client *client)
338 struct MonitoringClient *mc;
340 for (mc = head; NULL != mc; mc = mc->next)
341 if (mc->client == client)
348 * Setup a new monitoring client using the given server client handle and
351 * @param client server's client handle to create our internal handle for
352 * @param peer identity of the peer to monitor the addresses of,
353 * zero to monitor all neighrours.
354 * @return handle to the new monitoring client
356 static struct MonitoringClient *
357 setup_peer_monitoring_client (struct GNUNET_SERVER_Client *client,
358 const struct GNUNET_PeerIdentity *peer)
360 struct MonitoringClient *mc;
362 GNUNET_assert (NULL ==
363 lookup_monitoring_client (peer_monitoring_clients_head,
365 mc = GNUNET_new (struct MonitoringClient);
368 GNUNET_CONTAINER_DLL_insert (peer_monitoring_clients_head,
369 peer_monitoring_clients_tail,
371 GNUNET_SERVER_client_mark_monitor (client);
372 GNUNET_SERVER_notification_context_add (peer_nc,
374 if (0 != memcmp (peer,
376 sizeof (struct GNUNET_PeerIdentity)))
377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
378 "Client %p started monitoring of the peer `%s'\n",
382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
383 "Client %p started monitoring all peers\n",
390 * Setup a new monitoring client using the given server client handle and
393 * @param client server's client handle to create our internal handle for
394 * @param peer identity of the peer to monitor the addresses of,
395 * zero to monitor all neighrours.
396 * @return handle to the new monitoring client
398 static struct MonitoringClient *
399 setup_val_monitoring_client (struct GNUNET_SERVER_Client *client,
400 struct GNUNET_PeerIdentity *peer)
402 struct MonitoringClient *mc;
404 GNUNET_assert (NULL ==
405 lookup_monitoring_client (val_monitoring_clients_head,
407 mc = GNUNET_new (struct MonitoringClient);
410 GNUNET_CONTAINER_DLL_insert (val_monitoring_clients_head,
411 val_monitoring_clients_tail,
413 GNUNET_SERVER_notification_context_add (val_nc, client);
415 if (0 != memcmp (peer,
417 sizeof (struct GNUNET_PeerIdentity)))
418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
419 "Client %p started monitoring of the peer `%s'\n",
423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
424 "Client %p started monitoring all peers\n",
431 * Function called to notify a client about the socket being ready to
432 * queue more data. @a buf will be NULL and @a size zero if the socket
433 * was closed for writing in the meantime.
436 * @param size number of bytes available in @a buf
437 * @param buf where the callee should write the message
438 * @return number of bytes written to @a buf
441 transmit_to_client_callback (void *cls,
445 struct TransportClient *tc = cls;
446 struct ClientMessageQueueEntry *q;
447 const struct GNUNET_MessageHeader *msg;
455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
456 "Transmission to client failed, closing connection.\n");
461 while (NULL != (q = tc->message_queue_head))
463 msg = (const struct GNUNET_MessageHeader *) &q[1];
464 msize = ntohs (msg->size);
465 if (msize + tsize > size)
467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
468 "Transmitting message of type %u to client %p.\n",
471 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head,
472 tc->message_queue_tail,
475 memcpy (&cbuf[tsize], msg, msize);
481 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
483 GNUNET_SERVER_notify_transmit_ready (tc->client, msize,
484 GNUNET_TIME_UNIT_FOREVER_REL,
485 &transmit_to_client_callback, tc);
486 GNUNET_assert (NULL != tc->th);
493 * Queue the given message for transmission to the given client
495 * @param tc target of the message
496 * @param msg message to transmit
497 * @param may_drop #GNUNET_YES if the message can be dropped
500 unicast (struct TransportClient *tc,
501 const struct GNUNET_MessageHeader *msg,
504 struct ClientMessageQueueEntry *q;
512 if ( (tc->message_count >= MAX_PENDING) &&
513 (GNUNET_YES == may_drop) )
515 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
516 "Dropping message of type %u and size %u, have %u/%u messages pending\n",
521 GNUNET_STATISTICS_update (GST_stats,
523 ("# messages dropped due to slow client"), 1,
527 msize = ntohs (msg->size);
528 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
529 q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize);
530 memcpy (&q[1], msg, msize);
531 GNUNET_CONTAINER_DLL_insert_tail (tc->message_queue_head,
532 tc->message_queue_tail,
538 GNUNET_SERVER_notify_transmit_ready (tc->client, msize,
539 GNUNET_TIME_UNIT_FOREVER_REL,
540 &transmit_to_client_callback, tc);
541 GNUNET_assert (NULL != tc->th);
546 * Called whenever a client is disconnected. Frees our
547 * resources associated with that client.
549 * @param cls closure, NULL
550 * @param client identification of the client
553 client_disconnect_notification (void *cls,
554 struct GNUNET_SERVER_Client *client)
556 struct TransportClient *tc;
557 struct MonitoringClient *mc;
558 struct ClientMessageQueueEntry *mqe;
562 mc = lookup_monitoring_client (peer_monitoring_clients_head,
566 GNUNET_CONTAINER_DLL_remove (peer_monitoring_clients_head,
567 peer_monitoring_clients_tail,
571 mc = lookup_monitoring_client (val_monitoring_clients_head,
575 GNUNET_CONTAINER_DLL_remove (val_monitoring_clients_head,
576 val_monitoring_clients_tail,
580 tc = lookup_client (client);
583 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
584 "Client %p disconnected, cleaning up.\n",
586 while (NULL != (mqe = tc->message_queue_head))
588 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head,
589 tc->message_queue_tail,
594 GNUNET_CONTAINER_DLL_remove (clients_head,
597 GNUNET_SERVER_client_set_user_context (client, NULL);
600 GNUNET_SERVER_notify_transmit_ready_cancel (tc->th);
603 GNUNET_break (0 == tc->message_count);
609 * Function called for each of our connected neighbours. Notify the
610 * client about the existing neighbour.
612 * @param cls the `struct TransportClient *` to notify
613 * @param peer identity of the neighbour
614 * @param address the address
615 * @param state the current state of the peer
616 * @param state_timeout the time out for the state
617 * @param bandwidth_in inbound bandwidth in NBO
618 * @param bandwidth_out outbound bandwidth in NBO
621 notify_client_about_neighbour (void *cls,
622 const struct GNUNET_PeerIdentity *peer,
623 const struct GNUNET_HELLO_Address *address,
624 enum GNUNET_TRANSPORT_PeerState state,
625 struct GNUNET_TIME_Absolute state_timeout,
626 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
627 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
629 struct TransportClient *tc = cls;
630 struct ConnectInfoMessage cim;
632 if (GNUNET_NO == GST_neighbours_test_connected (peer))
634 cim.header.size = htons (sizeof (struct ConnectInfoMessage));
635 cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
637 cim.quota_in = bandwidth_in;
638 cim.quota_out = bandwidth_out;
639 unicast (tc, &cim.header, GNUNET_NO);
644 * Initialize a normal client. We got a start message from this
645 * client, add him to the list of clients for broadcasting of inbound
649 * @param client the client
650 * @param message the start message that was sent
653 clients_handle_start (void *cls,
654 struct GNUNET_SERVER_Client *client,
655 const struct GNUNET_MessageHeader *message)
657 const struct StartMessage *start;
658 const struct GNUNET_MessageHeader *hello;
659 struct TransportClient *tc;
662 tc = lookup_client (client);
665 /* got 'start' twice from the same client, not allowed */
667 GNUNET_SERVER_receive_done (client,
671 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
672 "Client %p sent START\n",
674 start = (const struct StartMessage *) message;
675 options = ntohl (start->options);
676 if ((0 != (1 & options)) &&
678 memcmp (&start->self,
680 sizeof (struct GNUNET_PeerIdentity))))
682 /* client thinks this is a different peer, reject */
684 GNUNET_SERVER_receive_done (client,
688 tc = setup_client (client);
689 tc->send_payload = (0 != (2 & options));
690 hello = GST_hello_get ();
695 GST_neighbours_iterate (¬ify_client_about_neighbour,
697 GNUNET_SERVER_receive_done (client,
703 * Client sent us a HELLO. Process the request.
706 * @param client the client
707 * @param message the HELLO message
710 clients_handle_hello (void *cls,
711 struct GNUNET_SERVER_Client *client,
712 const struct GNUNET_MessageHeader *message)
714 GST_validation_handle_hello (message);
715 GNUNET_SERVER_receive_done (client, GNUNET_OK);
720 * Function called after the transmission is done. Notify the client that it is
721 * OK to send the next message.
724 * @param success #GNUNET_OK on success, #GNUNET_NO on failure, #GNUNET_SYSERR if we're not connected
725 * @param bytes_payload bytes payload sent
726 * @param bytes_on_wire bytes sent on wire
729 handle_send_transmit_continuation (void *cls,
731 size_t bytes_payload,
732 size_t bytes_on_wire)
734 struct SendTransmitContinuationContext *stcc = cls;
735 struct SendOkMessage send_ok_msg;
736 struct GNUNET_TIME_Relative delay;
737 const struct GNUNET_HELLO_Address *addr;
739 delay = GNUNET_TIME_absolute_get_duration (stcc->send_time);
740 addr = GST_neighbour_get_current_address (&stcc->target);
741 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
742 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
743 "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
744 GNUNET_STRINGS_relative_time_to_string (delay,
746 (unsigned int) bytes_payload,
747 (unsigned int) bytes_on_wire,
748 GNUNET_i2s (&stcc->target),
750 (NULL != addr) ? addr->transport_name : "%");
752 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
753 "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
754 GNUNET_STRINGS_relative_time_to_string (delay,
756 (unsigned int) bytes_payload,
757 (unsigned int) bytes_on_wire,
758 GNUNET_i2s (&stcc->target),
760 (NULL != addr) ? addr->transport_name : "%");
762 if (GNUNET_NO == stcc->down)
764 /* Only send confirmation if we are still connected */
765 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
766 "Sending SEND_OK for transmission request %llu\n",
768 send_ok_msg.header.size = htons (sizeof (send_ok_msg));
769 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
770 send_ok_msg.bytes_msg = htonl (bytes_payload);
771 send_ok_msg.bytes_physical = htonl (bytes_on_wire);
772 send_ok_msg.success = htonl (success);
773 send_ok_msg.peer = stcc->target;
774 GST_clients_unicast (stcc->client,
778 GNUNET_SERVER_client_drop (stcc->client);
779 GNUNET_assert (GNUNET_OK ==
780 GNUNET_CONTAINER_multipeermap_remove (active_stccs,
788 * Client asked for transmission to a peer. Process the request.
791 * @param client the client
792 * @param message the send message that was sent
795 clients_handle_send (void *cls,
796 struct GNUNET_SERVER_Client *client,
797 const struct GNUNET_MessageHeader *message)
799 static unsigned long long uuid_gen;
800 const struct OutboundMessage *obm;
801 const struct GNUNET_MessageHeader *obmm;
802 struct SendTransmitContinuationContext *stcc;
805 struct TransportClient *tc;
807 tc = lookup_client (client);
810 /* client asked for transmission before 'START' */
812 GNUNET_SERVER_receive_done (client,
817 size = ntohs (message->size);
819 sizeof (struct OutboundMessage) + sizeof (struct GNUNET_MessageHeader))
822 GNUNET_SERVER_receive_done (client,
826 obm = (const struct OutboundMessage *) message;
827 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
828 msize = size - sizeof (struct OutboundMessage);
829 if (msize < sizeof (struct GNUNET_MessageHeader))
832 GNUNET_SERVER_receive_done (client,
837 if (GNUNET_NO == GST_neighbours_test_connected (&obm->peer))
839 /* not connected, not allowed to send; can happen due to asynchronous operations */
840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
841 "Could not send message to peer `%s': not connected\n",
842 GNUNET_i2s (&obm->peer));
843 GNUNET_STATISTICS_update (GST_stats,
845 ("# bytes payload dropped (other peer was not connected)"),
847 GNUNET_SERVER_receive_done (client,
851 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
852 "Received SEND request %llu for `%s' and first message of type %u and total size %u\n",
854 GNUNET_i2s (&obm->peer),
857 GNUNET_SERVER_receive_done (client,
859 stcc = GNUNET_new (struct SendTransmitContinuationContext);
860 stcc->target = obm->peer;
861 stcc->client = client;
862 stcc->send_time = GNUNET_TIME_absolute_get ();
863 stcc->uuid = uuid_gen++;
864 (void) GNUNET_CONTAINER_multipeermap_put (active_stccs,
867 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
868 GNUNET_SERVER_client_keep (client);
869 GST_manipulation_send (&obm->peer,
872 GNUNET_TIME_relative_ntoh (obm->timeout),
873 &handle_send_transmit_continuation,
879 * Handle request connect message
881 * @param cls closure (always NULL)
882 * @param client identification of the client
883 * @param message the actual message
886 clients_handle_request_connect (void *cls,
887 struct GNUNET_SERVER_Client *client,
888 const struct GNUNET_MessageHeader *message)
890 const struct TransportRequestConnectMessage *trcm;
892 trcm = (const struct TransportRequestConnectMessage *) message;
893 GNUNET_break (0 == ntohl (trcm->reserved));
894 GNUNET_STATISTICS_update (GST_stats,
896 ("# REQUEST CONNECT messages received"), 1,
898 if (0 == memcmp (&trcm->peer,
900 sizeof (struct GNUNET_PeerIdentity)))
903 GNUNET_SERVER_receive_done (client,
907 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
908 "Received a request connect message for peer `%s'\n",
909 GNUNET_i2s (&trcm->peer));
910 GST_neighbours_try_connect (&trcm->peer);
911 GNUNET_SERVER_receive_done (client, GNUNET_OK);
916 * Take the given address and append it to the set of results sent back to
917 * the client. This function may be called serveral times for a single
918 * conversion. The last invocation will be with a @a address of
919 * NULL and a @a res of #GNUNET_OK. Thus, to indicate conversion
920 * errors, the callback might be called first with @a address NULL and
921 * @a res being #GNUNET_SYSERR. In that case, there will still be a
922 * subsequent call later with @a address NULL and @a res #GNUNET_OK.
924 * @param cls the transmission context used (`struct GNUNET_SERVER_TransmitContext *`)
925 * @param buf text to transmit (contains the human-readable address, or NULL)
926 * @param res #GNUNET_OK if conversion was successful, #GNUNET_SYSERR on error,
930 transmit_address_to_client (void *cls,
934 struct AddressToStringContext *actx = cls;
935 struct AddressToStringResultMessage *atsm;
939 GNUNET_assert ( (GNUNET_OK == res) ||
940 (GNUNET_SYSERR == res) );
943 len = sizeof (struct AddressToStringResultMessage);
944 atsm = GNUNET_malloc (len);
945 atsm->header.size = ntohs (len);
946 atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
947 if (GNUNET_OK == res)
949 /* this was the last call, transmit */
950 atsm->res = htonl (GNUNET_OK);
951 atsm->addr_len = htonl (0);
952 GNUNET_SERVER_transmit_context_append_message (actx->tc,
953 (const struct GNUNET_MessageHeader *) atsm);
954 GNUNET_SERVER_transmit_context_run (actx->tc,
955 GNUNET_TIME_UNIT_FOREVER_REL);
956 GNUNET_CONTAINER_DLL_remove (a2s_head,
963 if (GNUNET_SYSERR == res)
965 /* address conversion failed, but there will be more callbacks */
966 atsm->res = htonl (GNUNET_SYSERR);
967 atsm->addr_len = htonl (0);
968 GNUNET_SERVER_transmit_context_append_message (actx->tc,
969 (const struct GNUNET_MessageHeader *) atsm);
974 GNUNET_assert (GNUNET_OK == res);
975 /* succesful conversion, append*/
976 slen = strlen (buf) + 1;
977 len = sizeof (struct AddressToStringResultMessage) + slen;
978 atsm = GNUNET_malloc (len);
979 atsm->header.size = ntohs (len);
980 atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
981 atsm->res = htonl (GNUNET_YES);
982 atsm->addr_len = htonl (slen);
986 GNUNET_SERVER_transmit_context_append_message (actx->tc,
987 (const struct GNUNET_MessageHeader *) atsm);
993 * Client asked to resolve an address. Process the request.
996 * @param client the client
997 * @param message the resolution request
1000 clients_handle_address_to_string (void *cls,
1001 struct GNUNET_SERVER_Client *client,
1002 const struct GNUNET_MessageHeader *message)
1004 const struct AddressLookupMessage *alum;
1005 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1006 const char *plugin_name;
1007 const char *address;
1008 uint32_t address_len;
1010 struct GNUNET_SERVER_TransmitContext *tc;
1011 struct AddressToStringContext *actx;
1012 struct AddressToStringResultMessage atsm;
1013 struct GNUNET_TIME_Relative rtimeout;
1016 size = ntohs (message->size);
1017 if (size < sizeof (struct AddressLookupMessage))
1020 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1023 alum = (const struct AddressLookupMessage *) message;
1024 address_len = ntohs (alum->addrlen);
1025 if (size <= sizeof (struct AddressLookupMessage) + address_len)
1028 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1031 address = (const char *) &alum[1];
1032 plugin_name = (const char *) &address[address_len];
1033 if ('\0' != plugin_name[size - sizeof (struct AddressLookupMessage) - address_len - 1])
1036 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1039 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
1040 numeric = ntohs (alum->numeric_only);
1041 tc = GNUNET_SERVER_transmit_context_create (client);
1042 papi = GST_plugins_printer_find (plugin_name);
1045 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1046 "Failed to find plugin `%s'\n",
1048 atsm.header.size = ntohs (sizeof (struct AddressToStringResultMessage));
1049 atsm.header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
1050 atsm.res = htonl (GNUNET_SYSERR);
1051 atsm.addr_len = htonl (0);
1052 GNUNET_SERVER_transmit_context_append_message (tc,
1054 atsm.header.size = ntohs (sizeof (struct AddressToStringResultMessage));
1055 atsm.header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
1056 atsm.res = htonl (GNUNET_OK);
1057 atsm.addr_len = htonl (0);
1058 GNUNET_SERVER_transmit_context_append_message (tc,
1060 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
1063 actx = GNUNET_new (struct AddressToStringContext);
1065 GNUNET_CONTAINER_DLL_insert (a2s_head, a2s_tail, actx);
1066 GNUNET_SERVER_disable_receive_done_warning (client);
1067 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1068 "Pretty-printing address of %u bytes using plugin `%s'\n",
1071 papi->address_pretty_printer (papi->cls,
1073 address, address_len,
1076 &transmit_address_to_client,
1082 * Compose #PeerIterateResponseMessage using the given peer and address.
1084 * @param peer identity of the peer
1085 * @param address the address, NULL on disconnect
1086 * @return composed message
1088 static struct PeerIterateResponseMessage *
1089 compose_address_iterate_response_message (const struct GNUNET_PeerIdentity *peer,
1090 const struct GNUNET_HELLO_Address *address)
1092 struct PeerIterateResponseMessage *msg;
1098 GNUNET_assert (NULL != peer);
1099 if (NULL != address)
1101 tlen = strlen (address->transport_name) + 1;
1102 alen = address->address_length;
1109 size = (sizeof (struct PeerIterateResponseMessage) + alen + tlen);
1110 msg = GNUNET_malloc (size);
1111 msg->header.size = htons (size);
1113 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE);
1114 msg->reserved = htonl (0);
1116 msg->addrlen = htonl (alen);
1117 msg->pluginlen = htonl (tlen);
1119 if (NULL != address)
1121 msg->local_address_info = htonl((uint32_t) address->local_info);
1122 addr = (char *) &msg[1];
1123 memcpy (addr, address->address, alen);
1124 memcpy (&addr[alen], address->transport_name, tlen);
1131 * Compose #PeerIterateResponseMessage using the given peer and address.
1133 * @param peer identity of the peer
1134 * @param address the address, NULL on disconnect
1135 * @return composed message
1137 static struct ValidationIterateResponseMessage *
1138 compose_validation_iterate_response_message (const struct GNUNET_PeerIdentity *peer,
1139 const struct GNUNET_HELLO_Address *address)
1141 struct ValidationIterateResponseMessage *msg;
1147 GNUNET_assert (NULL != peer);
1148 if (NULL != address)
1150 tlen = strlen (address->transport_name) + 1;
1151 alen = address->address_length;
1158 size = (sizeof (struct ValidationIterateResponseMessage) + alen + tlen);
1159 msg = GNUNET_malloc (size);
1160 msg->header.size = htons (size);
1162 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE);
1163 msg->reserved = htonl (0);
1165 msg->addrlen = htonl (alen);
1166 msg->pluginlen = htonl (tlen);
1168 if (NULL != address)
1170 msg->local_address_info = htonl((uint32_t) address->local_info);
1171 addr = (char *) &msg[1];
1172 memcpy (addr, address->address, alen);
1173 memcpy (&addr[alen], address->transport_name, tlen);
1180 * Context for #send_validation_information() and
1181 * #send_peer_information().
1183 struct IterationContext
1186 * Context to use for the transmission.
1188 struct GNUNET_SERVER_TransmitContext *tc;
1191 * Which peers do we care about?
1193 struct GNUNET_PeerIdentity id;
1196 * #GNUNET_YES if @e id should be ignored because we want all peers.
1203 * Output information of validation entries to the given client.
1205 * @param cls the `struct IterationContext *`
1206 * @param address the address
1207 * @param last_validation point in time when last validation was performed
1208 * @param valid_until point in time how long address is valid
1209 * @param next_validation point in time when next validation will be performed
1210 * @param state state of validation notification
1213 send_validation_information (void *cls,
1214 const struct GNUNET_HELLO_Address *address,
1215 struct GNUNET_TIME_Absolute last_validation,
1216 struct GNUNET_TIME_Absolute valid_until,
1217 struct GNUNET_TIME_Absolute next_validation,
1218 enum GNUNET_TRANSPORT_ValidationState state)
1220 struct IterationContext *pc = cls;
1221 struct ValidationIterateResponseMessage *msg;
1223 if ( (GNUNET_YES != pc->all) &&
1224 (0 != memcmp (&address->peer, &pc->id, sizeof (pc->id))) )
1226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1227 "Sending information about for validation entry for peer `%s' using address `%s'\n",
1228 GNUNET_i2s (&address->peer),
1229 (NULL != address) ? GST_plugins_a2s (address) : "<none>");
1230 msg = compose_validation_iterate_response_message (&address->peer, address);
1231 msg->last_validation = GNUNET_TIME_absolute_hton(last_validation);
1232 msg->valid_until = GNUNET_TIME_absolute_hton(valid_until);
1233 msg->next_validation = GNUNET_TIME_absolute_hton(next_validation);
1234 msg->state = htonl ((uint32_t) state);
1235 GNUNET_SERVER_transmit_context_append_message (pc->tc, &msg->header);
1241 * Output information of neighbours to the given client.
1243 * @param cls the `struct PeerIterationContext *`
1244 * @param peer identity of the neighbour
1245 * @param address the address
1246 * @param state current state this peer is in
1247 * @param state_timeout timeout for the current state of the peer
1248 * @param bandwidth_in inbound quota in NBO
1249 * @param bandwidth_out outbound quota in NBO
1252 send_peer_information (void *cls,
1253 const struct GNUNET_PeerIdentity *peer,
1254 const struct GNUNET_HELLO_Address *address,
1255 enum GNUNET_TRANSPORT_PeerState state,
1256 struct GNUNET_TIME_Absolute state_timeout,
1257 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1258 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1260 struct IterationContext *pc = cls;
1261 struct PeerIterateResponseMessage *msg;
1263 if ( (GNUNET_YES != pc->all) &&
1264 (0 != memcmp (peer, &pc->id, sizeof (pc->id))) )
1266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1267 "Sending information about `%s' using address `%s' in state `%s'\n",
1269 (NULL != address) ? GST_plugins_a2s (address) : "<none>",
1270 GNUNET_TRANSPORT_ps2s (state));
1271 msg = compose_address_iterate_response_message (peer, address);
1272 msg->state = htonl (state);
1273 msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout);
1274 GNUNET_SERVER_transmit_context_append_message (pc->tc, &msg->header);
1280 * Client asked to obtain information about a specific or all peers
1281 * Process the request.
1284 * @param client the client
1285 * @param message the peer address information request
1288 clients_handle_monitor_peers (void *cls,
1289 struct GNUNET_SERVER_Client *client,
1290 const struct GNUNET_MessageHeader *message)
1292 struct GNUNET_SERVER_TransmitContext *tc;
1293 const struct PeerMonitorMessage *msg;
1294 struct IterationContext pc;
1296 msg = (const struct PeerMonitorMessage *) message;
1297 if ( (GNUNET_YES != ntohl (msg->one_shot)) &&
1298 (NULL != lookup_monitoring_client (peer_monitoring_clients_head,
1302 GNUNET_SERVER_receive_done (client,
1306 GNUNET_SERVER_disable_receive_done_warning (client);
1307 GNUNET_SERVER_client_mark_monitor (client);
1308 pc.tc = tc = GNUNET_SERVER_transmit_context_create (client);
1310 /* Send initial list */
1311 if (0 == memcmp (&msg->peer,
1313 sizeof (struct GNUNET_PeerIdentity)))
1315 /* iterate over all neighbours */
1316 pc.all = GNUNET_YES;
1321 /* just return one neighbour */
1325 GST_neighbours_iterate (&send_peer_information,
1328 if (GNUNET_YES != ntohl (msg->one_shot))
1330 setup_peer_monitoring_client (client,
1335 GNUNET_SERVER_transmit_context_append_data (tc,
1338 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE);
1340 GNUNET_SERVER_transmit_context_run (tc,
1341 GNUNET_TIME_UNIT_FOREVER_REL);
1346 * Client asked to obtain information about a specific or all validation
1350 * @param client the client
1351 * @param message the peer address information request
1354 clients_handle_monitor_validation (void *cls,
1355 struct GNUNET_SERVER_Client *client,
1356 const struct GNUNET_MessageHeader *message)
1358 struct GNUNET_SERVER_TransmitContext *tc;
1359 struct PeerMonitorMessage *msg;
1360 struct IterationContext pc;
1362 if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST)
1365 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1368 if (ntohs (message->size) != sizeof (struct ValidationMonitorMessage))
1371 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1374 msg = (struct PeerMonitorMessage *) message;
1375 if ( (GNUNET_YES != ntohl (msg->one_shot)) &&
1376 (NULL != lookup_monitoring_client (val_monitoring_clients_head, client)) )
1379 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1382 GNUNET_SERVER_disable_receive_done_warning (client);
1383 GNUNET_SERVER_client_mark_monitor (client);
1384 pc.tc = tc = GNUNET_SERVER_transmit_context_create (client);
1386 /* Send initial list */
1387 if (0 == memcmp (&msg->peer,
1389 sizeof (struct GNUNET_PeerIdentity)))
1391 /* iterate over all neighbours */
1392 pc.all = GNUNET_YES;
1397 /* just return one neighbour */
1401 GST_validation_iterate (&send_validation_information,
1404 if (GNUNET_YES != ntohl (msg->one_shot))
1406 setup_val_monitoring_client (client, &msg->peer);
1410 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
1411 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE);
1413 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
1418 * Function called by the plugin with information about the
1419 * current sessions managed by the plugin (for monitoring).
1421 * @param cls closure
1422 * @param session session handle this information is about,
1423 * NULL to indicate that we are "in sync" (initial
1424 * iteration complete)
1425 * @param info information about the state of the session,
1426 * NULL if @a session is also NULL and we are
1427 * merely signalling that the initial iteration is over
1430 plugin_session_info_cb (void *cls,
1431 struct GNUNET_ATS_Session *session,
1432 const struct GNUNET_TRANSPORT_SessionInfo *info)
1434 struct TransportPluginMonitorMessage *msg;
1435 struct GNUNET_MessageHeader sync;
1442 if (0 == GNUNET_SERVER_notification_context_get_size (plugin_nc))
1444 GST_plugins_monitor_subscribe (NULL,
1448 if ( (NULL == info) &&
1451 /* end of initial iteration */
1452 if (NULL != sync_client)
1454 sync.size = htons (sizeof (struct GNUNET_MessageHeader));
1455 sync.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC);
1456 GNUNET_SERVER_notification_context_unicast (plugin_nc,
1464 GNUNET_assert (NULL != info);
1465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1466 "Plugin event for peer %s on transport %s\n",
1467 GNUNET_i2s (&info->address->peer),
1468 info->address->transport_name);
1469 slen = strlen (info->address->transport_name) + 1;
1470 alen = info->address->address_length;
1471 size = sizeof (struct TransportPluginMonitorMessage) + slen + alen;
1472 if (size > UINT16_MAX)
1477 msg = GNUNET_malloc (size);
1478 msg->header.size = htons (size);
1479 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT);
1480 msg->session_state = htons ((uint16_t) info->state);
1481 msg->is_inbound = htons ((int16_t) info->is_inbound);
1482 msg->msgs_pending = htonl (info->num_msg_pending);
1483 msg->bytes_pending = htonl (info->num_bytes_pending);
1484 msg->timeout = GNUNET_TIME_absolute_hton (info->session_timeout);
1485 msg->delay = GNUNET_TIME_absolute_hton (info->receive_delay);
1486 msg->peer = info->address->peer;
1487 msg->session_id = (uint64_t) (intptr_t) session;
1488 msg->plugin_name_len = htons (slen);
1489 msg->plugin_address_len = htons (alen);
1490 name = (char *) &msg[1];
1492 info->address->transport_name,
1496 info->address->address,
1498 if (NULL != sync_client)
1499 GNUNET_SERVER_notification_context_unicast (plugin_nc,
1504 GNUNET_SERVER_notification_context_broadcast (plugin_nc,
1512 * Client asked to obtain information about all plugin connections.
1515 * @param client the client
1516 * @param message the peer address information request
1519 clients_handle_monitor_plugins (void *cls,
1520 struct GNUNET_SERVER_Client *client,
1521 const struct GNUNET_MessageHeader *message)
1523 GNUNET_SERVER_client_mark_monitor (client);
1524 GNUNET_SERVER_disable_receive_done_warning (client);
1525 GNUNET_SERVER_notification_context_add (plugin_nc,
1527 GNUNET_assert (NULL == sync_client);
1528 sync_client = client;
1529 GST_plugins_monitor_subscribe (&plugin_session_info_cb,
1535 * Start handling requests from clients.
1537 * @param server server used to accept clients from.
1540 GST_clients_start (struct GNUNET_SERVER_Handle *server)
1542 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
1543 {&clients_handle_start, NULL,
1544 GNUNET_MESSAGE_TYPE_TRANSPORT_START, sizeof (struct StartMessage)},
1545 {&clients_handle_hello, NULL,
1546 GNUNET_MESSAGE_TYPE_HELLO, 0},
1547 {&clients_handle_send, NULL,
1548 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0},
1549 {&clients_handle_request_connect, NULL,
1550 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT,
1551 sizeof (struct TransportRequestConnectMessage)},
1552 {&clients_handle_address_to_string, NULL,
1553 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0},
1554 {&clients_handle_monitor_peers, NULL,
1555 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST,
1556 sizeof (struct PeerMonitorMessage)},
1557 {&clients_handle_monitor_validation, NULL,
1558 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST,
1559 sizeof (struct ValidationMonitorMessage)},
1560 {&GST_blacklist_handle_init, NULL,
1561 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
1562 sizeof (struct GNUNET_MessageHeader)},
1563 {&GST_blacklist_handle_reply, NULL,
1564 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
1565 sizeof (struct BlacklistMessage)},
1566 {&GST_manipulation_set_metric, NULL,
1567 GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC,
1568 sizeof (struct TrafficMetricMessage) },
1569 {&clients_handle_monitor_plugins, NULL,
1570 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START,
1571 sizeof (struct GNUNET_MessageHeader) },
1574 active_stccs = GNUNET_CONTAINER_multipeermap_create (128,
1576 peer_nc = GNUNET_SERVER_notification_context_create (server, 0);
1577 val_nc = GNUNET_SERVER_notification_context_create (server, 0);
1578 plugin_nc = GNUNET_SERVER_notification_context_create (server, 0);
1579 GNUNET_SERVER_add_handlers (server, handlers);
1580 GNUNET_SERVER_disconnect_notify (server,
1581 &client_disconnect_notification,
1587 * Stop processing clients.
1592 struct AddressToStringContext *cur;
1594 while (NULL != (cur = a2s_head))
1596 GNUNET_SERVER_transmit_context_destroy (cur->tc, GNUNET_NO);
1597 GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, cur);
1600 if (NULL != peer_nc)
1602 GNUNET_SERVER_notification_context_destroy (peer_nc);
1607 GNUNET_SERVER_notification_context_destroy (val_nc);
1610 if (NULL != plugin_nc)
1612 GNUNET_SERVER_notification_context_destroy (plugin_nc);
1615 GNUNET_CONTAINER_multipeermap_destroy (active_stccs);
1616 active_stccs = NULL;
1621 * Broadcast the given message to all of our clients.
1623 * @param msg message to broadcast
1624 * @param may_drop #GNUNET_YES if the message can be dropped / is payload
1627 GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
1630 struct TransportClient *tc;
1632 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1633 "Asked to broadcast message of type %u with %u bytes\n",
1634 (unsigned int) ntohs (msg->type),
1635 (unsigned int) ntohs (msg->size));
1636 for (tc = clients_head; NULL != tc; tc = tc->next)
1638 if ( (GNUNET_YES == may_drop) &&
1639 (GNUNET_YES != tc->send_payload) )
1640 continue; /* skip, this client does not care about payload */
1641 unicast (tc, msg, may_drop);
1647 * Send the given message to a particular client
1649 * @param client target of the message
1650 * @param msg message to transmit
1651 * @param may_drop #GNUNET_YES if the message can be dropped
1654 GST_clients_unicast (struct GNUNET_SERVER_Client *client,
1655 const struct GNUNET_MessageHeader *msg,
1658 struct TransportClient *tc;
1660 tc = lookup_client (client);
1662 return; /* client got disconnected in the meantime, drop message */
1663 unicast (tc, msg, may_drop);
1668 * Broadcast the new active address to all clients monitoring the peer.
1670 * @param peer peer this update is about (never NULL)
1671 * @param address address, NULL on disconnect
1672 * @param state the current state of the peer
1673 * @param state_timeout the time out for the state
1676 GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer,
1677 const struct GNUNET_HELLO_Address *address,
1678 enum GNUNET_TRANSPORT_PeerState state,
1679 struct GNUNET_TIME_Absolute state_timeout)
1681 struct PeerIterateResponseMessage *msg;
1682 struct MonitoringClient *mc;
1684 msg = compose_address_iterate_response_message (peer, address);
1685 msg->state = htonl (state);
1686 msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout);
1687 for (mc = peer_monitoring_clients_head; NULL != mc; mc = mc->next)
1688 if ((0 == memcmp (&mc->peer, &all_zeros,
1689 sizeof (struct GNUNET_PeerIdentity))) ||
1690 (0 == memcmp (&mc->peer, peer,
1691 sizeof (struct GNUNET_PeerIdentity))))
1692 GNUNET_SERVER_notification_context_unicast (peer_nc,
1701 * Broadcast the new validation changes to all clients monitoring the peer.
1703 * @param peer peer this update is about (never NULL)
1704 * @param address address, NULL on disconnect
1705 * @param last_validation point in time when last validation was performed
1706 * @param valid_until point in time how long address is valid
1707 * @param next_validation point in time when next validation will be performed
1708 * @param state state of validation notification
1711 GST_clients_broadcast_validation_notification (const struct GNUNET_PeerIdentity *peer,
1712 const struct GNUNET_HELLO_Address *address,
1713 struct GNUNET_TIME_Absolute last_validation,
1714 struct GNUNET_TIME_Absolute valid_until,
1715 struct GNUNET_TIME_Absolute next_validation,
1716 enum GNUNET_TRANSPORT_ValidationState state)
1718 struct ValidationIterateResponseMessage *msg;
1719 struct MonitoringClient *mc;
1721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1722 "Sending information about for validation entry for peer `%s' using address `%s'\n",
1724 (address != NULL) ? GST_plugins_a2s (address) : "<none>");
1725 msg = compose_validation_iterate_response_message (peer, address);
1726 msg->last_validation = GNUNET_TIME_absolute_hton(last_validation);
1727 msg->valid_until = GNUNET_TIME_absolute_hton(valid_until);
1728 msg->next_validation = GNUNET_TIME_absolute_hton(next_validation);
1729 msg->state = htonl ((uint32_t) state);
1730 for (mc = val_monitoring_clients_head; NULL != mc; mc = mc->next)
1731 if ((0 == memcmp (&mc->peer, &all_zeros,
1732 sizeof (struct GNUNET_PeerIdentity))) ||
1733 (0 == memcmp (&mc->peer, peer,
1734 sizeof (struct GNUNET_PeerIdentity))))
1735 GNUNET_SERVER_notification_context_unicast (val_nc,
1744 * Mark the peer as down so we don't call the continuation
1745 * context in the future.
1748 * @param peer peer that got disconnected
1749 * @param value a `struct SendTransmitContinuationContext` to mark
1750 * @return #GNUNET_OK (continue to iterate)
1753 mark_peer_down (void *cls,
1754 const struct GNUNET_PeerIdentity *peer,
1757 struct SendTransmitContinuationContext *stcc = value;
1759 stcc->down = GNUNET_YES;
1765 * Notify all clients about a disconnect, and cancel
1766 * pending SEND_OK messages for this peer.
1768 * @param peer peer that disconnected
1771 GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer)
1773 struct DisconnectInfoMessage disconnect_msg;
1775 GNUNET_CONTAINER_multipeermap_get_multiple (active_stccs,
1779 disconnect_msg.header.size = htons (sizeof(struct DisconnectInfoMessage));
1780 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
1781 disconnect_msg.reserved = htonl (0);
1782 disconnect_msg.peer = *peer;
1783 GST_clients_broadcast (&disconnect_msg.header,
1789 /* end of file gnunet-service-transport_clients.c */