2 This file is part of GNUnet.
3 (C) 2010,2011 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.h"
34 #include "transport.h"
37 * How many messages can we have pending for a given client process
38 * before we start to drop incoming messages? We typically should
39 * have only one client and so this would be the primary buffer for
40 * messages, so the number should be chosen rather generously.
42 * The expectation here is that most of the time the queue is large
43 * enough so that a drop is virtually never required. Note that
44 * this value must be about as large as 'TOTAL_MSGS' in the
45 * 'test_transport_api_reliability.c', otherwise that testcase may
48 #define MAX_PENDING (128 * 1024)
52 * Linked list of messages to be transmitted to the client. Each
53 * entry is followed by the actual message.
55 struct ClientMessageQueueEntry
58 * This is a doubly-linked list.
60 struct ClientMessageQueueEntry *next;
63 * This is a doubly-linked list.
65 struct ClientMessageQueueEntry *prev;
70 * Client connected to the transport service.
72 struct TransportClient
76 * This is a doubly-linked list.
78 struct TransportClient *next;
81 * This is a doubly-linked list.
83 struct TransportClient *prev;
86 * Handle to the client.
88 struct GNUNET_SERVER_Client *client;
91 * Linked list of messages yet to be transmitted to
94 struct ClientMessageQueueEntry *message_queue_head;
97 * Tail of linked list of messages yet to be transmitted to the
100 struct ClientMessageQueueEntry *message_queue_tail;
103 * Current transmit request handle.
105 struct GNUNET_SERVER_TransmitHandle *th;
108 * Length of the list of messages pending for this client.
110 unsigned int message_count;
113 * Is this client interested in payload messages?
120 * Client monitoring changes of active addresses of our neighbours.
122 struct MonitoringClient
125 * This is a doubly-linked list.
127 struct MonitoringClient *next;
130 * This is a doubly-linked list.
132 struct MonitoringClient *prev;
135 * Handle to the client.
137 struct GNUNET_SERVER_Client *client;
140 * Peer identity to monitor the addresses of.
141 * Zero to monitor all neighrours.
143 struct GNUNET_PeerIdentity peer;
149 * Head of linked list of all clients to this service.
151 static struct TransportClient *clients_head;
154 * Tail of linked list of all clients to this service.
156 static struct TransportClient *clients_tail;
159 * Head of linked list of monitoring clients.
161 static struct MonitoringClient *monitoring_clients_head;
164 * Tail of linked list of monitoring clients.
166 static struct MonitoringClient *monitoring_clients_tail;
169 * Notification context, to send updates on changes to active addresses
172 struct GNUNET_SERVER_NotificationContext *nc = NULL;
176 * Find the internal handle associated with the given client handle
178 * @param client server's client handle to look up
179 * @return internal client handle
181 static struct TransportClient *
182 lookup_client (struct GNUNET_SERVER_Client *client)
184 struct TransportClient *tc;
189 if (tc->client == client)
198 * Create the internal handle for the given server client handle
200 * @param client server's client handle to create our internal handle for
201 * @return fresh internal client handle
203 static struct TransportClient *
204 setup_client (struct GNUNET_SERVER_Client *client)
206 struct TransportClient *tc;
208 GNUNET_assert (lookup_client (client) == NULL);
209 tc = GNUNET_malloc (sizeof (struct TransportClient));
211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc);
217 * Find the handle to the monitoring client associated with the given
220 * @param client server's client handle to look up
221 * @return handle to the monitoring client
223 static struct MonitoringClient *
224 lookup_monitoring_client (struct GNUNET_SERVER_Client *client)
226 struct MonitoringClient *mc;
228 mc = monitoring_clients_head;
231 if (mc->client == client)
240 * Setup a new monitoring client using the given server client handle and
243 * @param client server's client handle to create our internal handle for
244 * @param peer identity of the peer to monitor the addresses of,
245 * zero to monitor all neighrours.
246 * @return handle to the new monitoring client
248 static struct MonitoringClient *
249 setup_monitoring_client (struct GNUNET_SERVER_Client *client,
250 struct GNUNET_PeerIdentity *peer)
252 struct MonitoringClient *mc;
254 GNUNET_assert (lookup_monitoring_client (client) == NULL);
255 mc = GNUNET_malloc (sizeof (struct MonitoringClient));
258 GNUNET_CONTAINER_DLL_insert (monitoring_clients_head,
259 monitoring_clients_tail,
261 GNUNET_SERVER_notification_context_add (nc, client);
263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
264 "Client %p started monitoring of the peer `%s'\n",
265 mc, GNUNET_i2s (peer));
271 * Function called to notify a client about the socket being ready to
272 * queue more data. "buf" will be NULL and "size" zero if the socket
273 * was closed for writing in the meantime.
276 * @param size number of bytes available in buf
277 * @param buf where the callee should write the message
278 * @return number of bytes written to buf
281 transmit_to_client_callback (void *cls, size_t size, void *buf)
283 struct TransportClient *tc = cls;
284 struct ClientMessageQueueEntry *q;
285 const struct GNUNET_MessageHeader *msg;
293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
294 "Transmission to client failed, closing connection.\n");
299 while (NULL != (q = tc->message_queue_head))
301 msg = (const struct GNUNET_MessageHeader *) &q[1];
302 msize = ntohs (msg->size);
303 if (msize + tsize > size)
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
306 "Transmitting message of type %u to client %p.\n",
307 ntohs (msg->type), tc);
308 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head, tc->message_queue_tail,
311 memcpy (&cbuf[tsize], msg, msize);
317 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
319 GNUNET_SERVER_notify_transmit_ready (tc->client, msize,
320 GNUNET_TIME_UNIT_FOREVER_REL,
321 &transmit_to_client_callback, tc);
322 GNUNET_assert (tc->th != NULL);
329 * Queue the given message for transmission to the given client
331 * @param tc target of the message
332 * @param msg message to transmit
333 * @param may_drop GNUNET_YES if the message can be dropped
336 unicast (struct TransportClient *tc, const struct GNUNET_MessageHeader *msg,
339 struct ClientMessageQueueEntry *q;
348 if ((tc->message_count >= MAX_PENDING) && (GNUNET_YES == may_drop))
350 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
352 ("Dropping message of type %u and size %u, have %u/%u messages pending\n"),
353 ntohs (msg->type), ntohs (msg->size), tc->message_count,
355 GNUNET_STATISTICS_update (GST_stats,
357 ("# messages dropped due to slow client"), 1,
361 msize = ntohs (msg->size);
362 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
363 q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize);
364 memcpy (&q[1], msg, msize);
365 GNUNET_CONTAINER_DLL_insert_tail (tc->message_queue_head,
366 tc->message_queue_tail, q);
371 GNUNET_SERVER_notify_transmit_ready (tc->client, msize,
372 GNUNET_TIME_UNIT_FOREVER_REL,
373 &transmit_to_client_callback, tc);
374 GNUNET_assert (tc->th != NULL);
379 * Called whenever a client is disconnected. Frees our
380 * resources associated with that client.
383 * @param client identification of the client
386 client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
388 struct TransportClient *tc;
389 struct MonitoringClient *mc;
390 struct ClientMessageQueueEntry *mqe;
394 mc = lookup_monitoring_client (client);
397 GNUNET_CONTAINER_DLL_remove (monitoring_clients_head,
398 monitoring_clients_tail,
402 tc = lookup_client (client);
405 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
406 "Client %p disconnected, cleaning up.\n", tc);
407 while (NULL != (mqe = tc->message_queue_head))
409 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head, tc->message_queue_tail,
414 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc);
417 GNUNET_SERVER_notify_transmit_ready_cancel (tc->th);
420 GNUNET_break (0 == tc->message_count);
426 * Function called for each of our connected neighbours. Notify the
427 * client about the existing neighbour.
429 * @param cls the 'struct TransportClient' to notify
430 * @param peer identity of the neighbour
431 * @param ats performance data
432 * @param ats_count number of entries in ats (excluding 0-termination)
433 * @param address the address
436 notify_client_about_neighbour (void *cls,
437 const struct GNUNET_PeerIdentity *peer,
438 const struct GNUNET_ATS_Information *ats,
440 const struct GNUNET_HELLO_Address *address,
441 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
442 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
444 struct TransportClient *tc = cls;
445 struct ConnectInfoMessage *cim;
446 struct GNUNET_ATS_Information *ap;
448 sizeof (struct ConnectInfoMessage) +
449 ats_count * sizeof (struct GNUNET_ATS_Information);
450 char buf[size] GNUNET_ALIGN;
452 GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
453 cim = (struct ConnectInfoMessage *) buf;
454 cim->header.size = htons (size);
455 cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
456 cim->ats_count = htonl (ats_count);
458 cim->quota_in = bandwidth_in;
459 cim->quota_out = bandwidth_out;
460 ap = (struct GNUNET_ATS_Information *) &cim[1];
461 memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
462 unicast (tc, &cim->header, GNUNET_NO);
467 * Initialize a normal client. We got a start message from this
468 * client, add him to the list of clients for broadcasting of inbound
472 * @param client the client
473 * @param message the start message that was sent
476 clients_handle_start (void *cls, struct GNUNET_SERVER_Client *client,
477 const struct GNUNET_MessageHeader *message)
479 const struct StartMessage *start;
480 struct TransportClient *tc;
483 tc = lookup_client (client);
485 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
486 "Client %p sent START\n", tc);
489 /* got 'start' twice from the same client, not allowed */
490 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
491 "TransportClient %p ServerClient %p sent multiple START messages\n",
494 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
497 start = (const struct StartMessage *) message;
498 options = ntohl (start->options);
499 if ((0 != (1 & options)) &&
501 memcmp (&start->self, &GST_my_identity,
502 sizeof (struct GNUNET_PeerIdentity))))
504 /* client thinks this is a different peer, reject */
505 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
507 ("Rejecting control connection from peer `%s', which is not me!\n"),
508 GNUNET_i2s (&start->self));
509 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
512 tc = setup_client (client);
513 tc->send_payload = (0 != (2 & options));
514 unicast (tc, GST_hello_get (), GNUNET_NO);
515 GST_neighbours_iterate (¬ify_client_about_neighbour, tc);
516 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc);
517 GNUNET_SERVER_receive_done (client, GNUNET_OK);
522 * Client sent us a HELLO. Process the request.
525 * @param client the client
526 * @param message the HELLO message
529 clients_handle_hello (void *cls, struct GNUNET_SERVER_Client *client,
530 const struct GNUNET_MessageHeader *message)
532 GST_validation_handle_hello (message);
533 GNUNET_SERVER_receive_done (client, GNUNET_OK);
538 * Closure for 'handle_send_transmit_continuation'
540 struct SendTransmitContinuationContext
543 * Client that made the request.
545 struct GNUNET_SERVER_Client *client;
548 * Peer that was the target.
550 struct GNUNET_PeerIdentity target;
555 * Function called after the transmission is done. Notify the client that it is
556 * OK to send the next message.
559 * @param success GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR if we're not connected
562 handle_send_transmit_continuation (void *cls, int success)
564 struct SendTransmitContinuationContext *stcc = cls;
565 struct SendOkMessage send_ok_msg;
567 send_ok_msg.header.size = htons (sizeof (send_ok_msg));
568 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
569 send_ok_msg.success = htonl (success);
570 send_ok_msg.latency =
571 GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_FOREVER_REL);
572 send_ok_msg.peer = stcc->target;
573 GST_clients_unicast (stcc->client, &send_ok_msg.header, GNUNET_NO);
574 GNUNET_SERVER_client_drop (stcc->client);
580 * Client asked for transmission to a peer. Process the request.
583 * @param client the client
584 * @param message the send message that was sent
587 clients_handle_send (void *cls, struct GNUNET_SERVER_Client *client,
588 const struct GNUNET_MessageHeader *message)
590 const struct OutboundMessage *obm;
591 const struct GNUNET_MessageHeader *obmm;
592 struct SendTransmitContinuationContext *stcc;
595 struct TransportClient *tc;
597 tc = lookup_client (client);
600 /* client asked for transmission before 'START' */
602 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
606 size = ntohs (message->size);
608 sizeof (struct OutboundMessage) + sizeof (struct GNUNET_MessageHeader))
611 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
614 obm = (const struct OutboundMessage *) message;
615 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
616 msize = size - sizeof (struct OutboundMessage);
617 if (msize < sizeof (struct GNUNET_MessageHeader))
620 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
624 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
625 "Received `%s' request from client with target `%4s' and first message of type %u and total size %u\n",
626 "SEND", GNUNET_i2s (&obm->peer), ntohs (obmm->type), msize);
627 if (GNUNET_NO == GST_neighbours_test_connected (&obm->peer))
629 /* not connected, not allowed to send; can happen due to asynchronous operations */
630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
631 "Could not send message to peer `%s': not connected\n",
632 GNUNET_i2s (&obm->peer));
633 GNUNET_STATISTICS_update (GST_stats,
635 ("# bytes payload dropped (other peer was not connected)"),
637 GNUNET_SERVER_receive_done (client, GNUNET_OK);
640 GNUNET_SERVER_receive_done (client, GNUNET_OK);
641 stcc = GNUNET_malloc (sizeof (struct SendTransmitContinuationContext));
642 stcc->target = obm->peer;
643 stcc->client = client;
644 GNUNET_SERVER_client_keep (client);
645 GST_neighbours_send (&obm->peer, obmm, msize,
646 GNUNET_TIME_relative_ntoh (obm->timeout),
647 &handle_send_transmit_continuation, stcc);
652 * Try to initiate a connection to the given peer if the blacklist
655 * @param cls closure (unused, NULL)
656 * @param peer identity of peer that was tested
657 * @param result GNUNET_OK if the connection is allowed,
661 try_connect_if_allowed (void *cls, const struct GNUNET_PeerIdentity *peer,
664 if (GNUNET_OK != result)
665 return; /* not allowed */
666 GST_neighbours_try_connect (peer);
671 * Handle request connect message
673 * @param cls closure (always NULL)
674 * @param client identification of the client
675 * @param message the actual message
678 clients_handle_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
679 const struct GNUNET_MessageHeader *message)
681 const struct TransportRequestConnectMessage *trcm =
682 (const struct TransportRequestConnectMessage *) message;
684 GNUNET_STATISTICS_update (GST_stats,
686 ("# REQUEST CONNECT messages received"), 1,
688 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
689 "Received a request connect message for peer `%s'\n",
690 GNUNET_i2s (&trcm->peer));
691 (void) GST_blacklist_test_allowed (&trcm->peer, NULL, &try_connect_if_allowed,
693 GNUNET_SERVER_receive_done (client, GNUNET_OK);
698 * Take the given address and append it to the set of results sent back to
701 * @param cls the transmission context used ('struct GNUNET_SERVER_TransmitContext*')
702 * @param buf text to transmit
705 transmit_address_to_client (void *cls, const char *buf)
707 struct GNUNET_SERVER_TransmitContext *tc = cls;
711 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
712 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
713 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
716 GNUNET_SERVER_transmit_context_append_data (tc, buf, strlen (buf) + 1,
717 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
722 * Client asked to resolve an address. Process the request.
725 * @param client the client
726 * @param message the resolution request
729 clients_handle_address_to_string (void *cls,
730 struct GNUNET_SERVER_Client *client,
731 const struct GNUNET_MessageHeader *message)
733 const struct AddressLookupMessage *alum;
734 struct GNUNET_TRANSPORT_PluginFunctions *papi;
735 const char *plugin_name;
737 uint32_t address_len;
739 struct GNUNET_SERVER_TransmitContext *tc;
740 struct GNUNET_TIME_Relative rtimeout;
743 size = ntohs (message->size);
744 if (size < sizeof (struct AddressLookupMessage))
747 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
750 alum = (const struct AddressLookupMessage *) message;
751 address_len = ntohs (alum->addrlen);
752 if (size <= sizeof (struct AddressLookupMessage) + address_len)
755 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
758 address = (const char *) &alum[1];
759 plugin_name = (const char *) &address[address_len];
760 if (plugin_name[size - sizeof (struct AddressLookupMessage) - address_len - 1]
764 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
767 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
768 numeric = ntohs (alum->numeric_only);
769 tc = GNUNET_SERVER_transmit_context_create (client);
770 papi = GST_plugins_find (plugin_name);
773 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
774 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
775 GNUNET_SERVER_transmit_context_run (tc, rtimeout);
778 GNUNET_SERVER_disable_receive_done_warning (client);
779 papi->address_pretty_printer (papi->cls, plugin_name, address, address_len,
780 numeric, rtimeout, &transmit_address_to_client,
786 * Compose AddressIterateResponseMessage using the given peer and address.
788 * @param peer identity of the peer
789 * @param address the address, NULL on disconnect
790 * @return composed message
792 static struct AddressIterateResponseMessage *
793 compose_address_iterate_response_message (const struct GNUNET_PeerIdentity
795 const struct GNUNET_HELLO_Address
798 struct AddressIterateResponseMessage *msg;
804 GNUNET_assert (NULL != peer);
807 tlen = strlen (address->transport_name) + 1;
808 alen = address->address_length;
812 size = (sizeof (struct AddressIterateResponseMessage) + alen + tlen);
813 msg = GNUNET_malloc (size);
814 msg->header.size = htons (size);
816 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
817 msg->reserved = htonl (0);
819 msg->addrlen = htonl (alen);
820 msg->pluginlen = htonl (tlen);
823 addr = (char *) &msg[1];
824 memcpy (addr, address->address, alen);
825 memcpy (&addr[alen], address->transport_name, tlen);
832 * Output the active address of connected neighbours to the given client.
834 * @param cls the 'struct GNUNET_SERVER_TransmitContext' for transmission to the client
835 * @param peer identity of the neighbour
836 * @param ats performance data
837 * @param ats_count number of entries in ats (excluding 0-termination)
838 * @param address the address
839 * @param bandwidth_in inbound quota in NBO
840 * @param bandwidth_out outbound quota in NBO
843 output_address (void *cls, const struct GNUNET_PeerIdentity *peer,
844 const struct GNUNET_ATS_Information *ats, uint32_t ats_count,
845 const struct GNUNET_HELLO_Address *address,
846 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
847 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
849 struct GNUNET_SERVER_TransmitContext *tc = cls;
850 struct AddressIterateResponseMessage *msg;
852 msg = compose_address_iterate_response_message (peer, address);
853 GNUNET_SERVER_transmit_context_append_message (tc, &msg->header);
859 * Client asked to obtain information about all actively used addresses
861 * Process the request.
864 * @param client the client
865 * @param message the peer address information request
868 clients_handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client,
869 const struct GNUNET_MessageHeader *message)
871 static struct GNUNET_PeerIdentity all_zeros;
872 struct GNUNET_SERVER_TransmitContext *tc;
873 struct AddressIterateMessage *msg;
874 struct GNUNET_HELLO_Address *address;
876 if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE)
879 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
882 if (ntohs (message->size) != sizeof (struct AddressIterateMessage))
885 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
888 msg = (struct AddressIterateMessage *) message;
889 if ( (GNUNET_YES != ntohl (msg->one_shot)) &&
890 (NULL != lookup_monitoring_client (client)) )
892 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
893 "ServerClient %p tried to start monitoring twice\n",
896 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
899 GNUNET_SERVER_disable_receive_done_warning (client);
900 tc = GNUNET_SERVER_transmit_context_create (client);
901 if (0 == memcmp (&msg->peer, &all_zeros, sizeof (struct GNUNET_PeerIdentity)))
903 /* iterate over all neighbours */
904 GST_neighbours_iterate (&output_address, tc);
908 /* just return one neighbour */
909 address = GST_neighbour_get_current_address (&msg->peer);
911 output_address (tc, &msg->peer, NULL, 0, address,
912 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
913 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT);
915 if (GNUNET_YES != ntohl (msg->one_shot))
916 setup_monitoring_client (client, &msg->peer);
918 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
919 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
920 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
925 * Start handling requests from clients.
927 * @param server server used to accept clients from.
930 GST_clients_start (struct GNUNET_SERVER_Handle *server)
932 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
933 {&clients_handle_start, NULL,
934 GNUNET_MESSAGE_TYPE_TRANSPORT_START, sizeof (struct StartMessage)},
935 {&clients_handle_hello, NULL,
936 GNUNET_MESSAGE_TYPE_HELLO, 0},
937 {&clients_handle_send, NULL,
938 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0},
939 {&clients_handle_request_connect, NULL,
940 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT,
941 sizeof (struct TransportRequestConnectMessage)},
942 {&clients_handle_address_to_string, NULL,
943 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0},
944 {&clients_handle_address_iterate, NULL,
945 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE,
946 sizeof (struct AddressIterateMessage)},
947 {&GST_blacklist_handle_init, NULL,
948 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
949 sizeof (struct GNUNET_MessageHeader)},
950 {&GST_blacklist_handle_reply, NULL,
951 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
952 sizeof (struct BlacklistMessage)},
955 nc = GNUNET_SERVER_notification_context_create (server, 0);
956 GNUNET_SERVER_add_handlers (server, handlers);
957 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_notification,
963 * Stop processing clients.
970 GNUNET_SERVER_notification_context_destroy (nc);
977 * Broadcast the given message to all of our clients.
979 * @param msg message to broadcast
980 * @param may_drop GNUNET_YES if the message can be dropped / is payload
983 GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop)
985 struct TransportClient *tc;
987 for (tc = clients_head; tc != NULL; tc = tc->next)
989 if ((GNUNET_YES == may_drop) && (GNUNET_YES != tc->send_payload))
990 continue; /* skip, this client does not care about payload */
991 unicast (tc, msg, may_drop);
997 * Send the given message to a particular client
999 * @param client target of the message
1000 * @param msg message to transmit
1001 * @param may_drop GNUNET_YES if the message can be dropped
1004 GST_clients_unicast (struct GNUNET_SERVER_Client *client,
1005 const struct GNUNET_MessageHeader *msg, int may_drop)
1007 struct TransportClient *tc;
1009 tc = lookup_client (client);
1011 return; /* client got disconnected in the meantime, drop message */
1012 unicast (tc, msg, may_drop);
1017 * Broadcast the new active address to all clients monitoring the peer.
1019 * @param peer peer this update is about (never NULL)
1020 * @param address address, NULL on disconnect
1023 GST_clients_broadcast_address_notification (const struct GNUNET_PeerIdentity
1025 const struct GNUNET_HELLO_Address
1028 struct AddressIterateResponseMessage *msg;
1029 struct MonitoringClient *mc;
1030 static struct GNUNET_PeerIdentity all_zeros;
1032 msg = compose_address_iterate_response_message (peer, address);
1033 mc = monitoring_clients_head;
1036 if ((0 == memcmp (&mc->peer, &all_zeros,
1037 sizeof (struct GNUNET_PeerIdentity))) ||
1038 (0 == memcmp (&mc->peer, peer,
1039 sizeof (struct GNUNET_PeerIdentity))))
1041 GNUNET_SERVER_notification_context_unicast (nc, mc->client,
1042 &msg->header, GNUNET_NO);
1051 /* end of file gnunet-service-transport_clients.c */