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_CONNECTION_TransmitHandle *th;
108 * Length of the list of messages pending for this client.
110 unsigned int message_count;
115 * Head of linked list of all clients to this service.
117 static struct TransportClient *clients_head;
120 * Tail of linked list of all clients to this service.
122 static struct TransportClient *clients_tail;
125 * Find the internal handle associated with the given client handle
127 * @param client server's client handle to look up
128 * @return internal client handle
130 static struct TransportClient *
131 lookup_client (struct GNUNET_SERVER_Client *client)
133 struct TransportClient *tc;
138 if (tc->client == client)
147 * Create the internal handle for the given server client handle
149 * @param client server's client handle to create our internal handle for
150 * @return fresh internal client handle
152 static struct TransportClient *
153 setup_client (struct GNUNET_SERVER_Client *client)
155 struct TransportClient *tc;
157 GNUNET_assert (lookup_client (client) == NULL);
158 tc = GNUNET_malloc (sizeof (struct TransportClient));
160 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc);
163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
164 "Client %X connected\n", tc);
171 * Function called to notify a client about the socket being ready to
172 * queue more data. "buf" will be NULL and "size" zero if the socket
173 * was closed for writing in the meantime.
176 * @param size number of bytes available in buf
177 * @param buf where the callee should write the message
178 * @return number of bytes written to buf
181 transmit_to_client_callback (void *cls, size_t size, void *buf)
183 struct TransportClient *tc = cls;
184 struct ClientMessageQueueEntry *q;
185 const struct GNUNET_MessageHeader *msg;
194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
195 "Transmission to client failed, closing connection.\n");
201 while (NULL != (q = tc->message_queue_head))
203 msg = (const struct GNUNET_MessageHeader *) &q[1];
204 msize = ntohs (msg->size);
205 if (msize + tsize > size)
208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
209 "Transmitting message of type %u to client %X.\n",
210 ntohs (msg->type), tc);
212 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head, tc->message_queue_tail,
215 memcpy (&cbuf[tsize], msg, msize);
221 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
223 GNUNET_SERVER_notify_transmit_ready (tc->client, msize,
224 GNUNET_TIME_UNIT_FOREVER_REL,
225 &transmit_to_client_callback, tc);
226 GNUNET_assert (tc->th != NULL);
233 * Queue the given message for transmission to the given client
235 * @param tc target of the message
236 * @param msg message to transmit
237 * @param may_drop GNUNET_YES if the message can be dropped
240 unicast (struct TransportClient *tc, const struct GNUNET_MessageHeader *msg,
243 struct ClientMessageQueueEntry *q;
246 if ((tc->message_count >= MAX_PENDING) && (GNUNET_YES == may_drop))
248 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
250 ("Dropping message of type %u and size %u, have %u/%u messages pending\n"),
251 ntohs (msg->type), ntohs (msg->size), tc->message_count,
253 GNUNET_STATISTICS_update (GST_stats,
255 ("# messages dropped due to slow client"), 1,
259 msize = ntohs (msg->size);
260 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
261 q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize);
262 memcpy (&q[1], msg, msize);
263 GNUNET_CONTAINER_DLL_insert_tail (tc->message_queue_head,
264 tc->message_queue_tail, q);
269 GNUNET_SERVER_notify_transmit_ready (tc->client, msize,
270 GNUNET_TIME_UNIT_FOREVER_REL,
271 &transmit_to_client_callback, tc);
272 GNUNET_assert (tc->th != NULL);
277 * Called whenever a client is disconnected. Frees our
278 * resources associated with that client.
281 * @param client identification of the client
284 client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
286 struct TransportClient *tc;
287 struct ClientMessageQueueEntry *mqe;
291 tc = lookup_client (client);
295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
296 "Client %X disconnected, cleaning up.\n", tc);
298 while (NULL != (mqe = tc->message_queue_head))
300 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head, tc->message_queue_tail,
305 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc);
308 GNUNET_CONNECTION_notify_transmit_ready_cancel (tc->th);
311 GNUNET_break (0 == tc->message_count);
317 * Function called for each of our connected neighbours. Notify the
318 * client about the existing neighbour.
320 * @param cls the 'struct TransportClient' to notify
321 * @param peer identity of the neighbour
322 * @param ats performance data
323 * @param ats_count number of entries in ats (excluding 0-termination)
324 * @param transport plugin
325 * @param addr address
326 * @param addrlen address length
329 notify_client_about_neighbour (void *cls,
330 const struct GNUNET_PeerIdentity *peer,
331 const struct GNUNET_ATS_Information
332 *ats, uint32_t ats_count,
333 const char * transport,
337 struct TransportClient *tc = cls;
338 struct ConnectInfoMessage *cim;
342 sizeof (struct ConnectInfoMessage) +
343 ats_count * sizeof (struct GNUNET_ATS_Information);
344 GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
345 cim = GNUNET_malloc (size);
346 cim->header.size = htons (size);
347 cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
348 cim->ats_count = htonl (ats_count);
350 memcpy (&cim->ats, ats,
351 ats_count * sizeof (struct GNUNET_ATS_Information));
352 unicast (tc, &cim->header, GNUNET_NO);
358 * Initialize a normal client. We got a start message from this
359 * client, add him to the list of clients for broadcasting of inbound
363 * @param client the client
364 * @param message the start message that was sent
367 clients_handle_start (void *cls, struct GNUNET_SERVER_Client *client,
368 const struct GNUNET_MessageHeader *message)
370 const struct StartMessage *start;
371 struct TransportClient *tc;
373 tc = lookup_client (client);
377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
378 "Client %X sent START\n", tc);
380 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
381 "Client %X sent START\n", tc);
385 /* got 'start' twice from the same client, not allowed */
387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
388 "TransportClient %X ServerClient %X sent multiple START messages\n",
392 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
395 start = (const struct StartMessage *) message;
396 if ((GNUNET_NO != ntohl (start->do_check)) &&
398 memcmp (&start->self, &GST_my_identity,
399 sizeof (struct GNUNET_PeerIdentity))))
401 /* client thinks this is a different peer, reject */
402 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
404 ("Rejecting control connection from peer `%s', which is not me!\n"),
405 GNUNET_i2s (&start->self));
406 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
409 tc = setup_client (client);
411 unicast (tc, GST_hello_get (), GNUNET_NO);
412 GST_neighbours_iterate (¬ify_client_about_neighbour, tc);
413 GNUNET_SERVER_receive_done (client, GNUNET_OK);
418 * Client sent us a HELLO. Process the request.
421 * @param client the client
422 * @param message the HELLO message
425 clients_handle_hello (void *cls, struct GNUNET_SERVER_Client *client,
426 const struct GNUNET_MessageHeader *message)
428 GST_validation_handle_hello (message);
429 GNUNET_SERVER_receive_done (client, GNUNET_OK);
434 * Closure for 'handle_send_transmit_continuation'
436 struct SendTransmitContinuationContext
439 * Client that made the request.
441 struct GNUNET_SERVER_Client *client;
444 * Peer that was the target.
446 struct GNUNET_PeerIdentity target;
451 * Function called after the transmission is done. Notify the client that it is
452 * OK to send the next message.
455 * @param success GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR if we're not connected
458 handle_send_transmit_continuation (void *cls, int success)
460 struct SendTransmitContinuationContext *stcc = cls;
461 struct SendOkMessage send_ok_msg;
463 send_ok_msg.header.size = htons (sizeof (send_ok_msg));
464 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
465 send_ok_msg.success = htonl (success);
466 send_ok_msg.latency =
467 GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_FOREVER_REL);
468 send_ok_msg.peer = stcc->target;
469 GST_clients_unicast (stcc->client, &send_ok_msg.header, GNUNET_NO);
470 GNUNET_SERVER_client_drop (stcc->client);
476 * Client asked for transmission to a peer. Process the request.
479 * @param client the client
480 * @param message the send message that was sent
483 clients_handle_send (void *cls, struct GNUNET_SERVER_Client *client,
484 const struct GNUNET_MessageHeader *message)
486 const struct OutboundMessage *obm;
487 const struct GNUNET_MessageHeader *obmm;
488 struct SendTransmitContinuationContext *stcc;
491 struct TransportClient *tc;
493 tc = lookup_client (client);
496 /* client asked for transmission before 'START' */
498 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
502 size = ntohs (message->size);
504 sizeof (struct OutboundMessage) + sizeof (struct GNUNET_MessageHeader))
507 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
510 obm = (const struct OutboundMessage *) message;
511 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
512 msize = size - sizeof (struct OutboundMessage);
513 if (msize < sizeof (struct GNUNET_MessageHeader))
516 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
519 GNUNET_STATISTICS_update (GST_stats,
521 ("# bytes payload received for other peers"), msize,
524 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
525 "Received `%s' request from client with target `%4s' and first message of type %u and total size %u\n",
526 "SEND", GNUNET_i2s (&obm->peer), ntohs (obmm->type), msize);
528 if (GNUNET_NO == GST_neighbours_test_connected (&obm->peer))
530 /* not connected, not allowed to send; can happen due to asynchronous operations */
532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
533 "Could not send message to peer `%s': not connected\n",
534 GNUNET_i2s (&obm->peer));
536 GNUNET_STATISTICS_update (GST_stats,
538 ("# bytes payload dropped (other peer was not connected)"),
540 GNUNET_SERVER_receive_done (client, GNUNET_OK);
543 GNUNET_SERVER_receive_done (client, GNUNET_OK);
544 stcc = GNUNET_malloc (sizeof (struct SendTransmitContinuationContext));
545 stcc->target = obm->peer;
546 stcc->client = client;
547 GNUNET_SERVER_client_keep (client);
548 GST_neighbours_send (&obm->peer, obmm, msize,
549 GNUNET_TIME_relative_ntoh (obm->timeout),
550 &handle_send_transmit_continuation, stcc);
555 * Try to initiate a connection to the given peer if the blacklist
558 * @param cls closure (unused, NULL)
559 * @param peer identity of peer that was tested
560 * @param result GNUNET_OK if the connection is allowed,
564 try_connect_if_allowed (void *cls, const struct GNUNET_PeerIdentity *peer,
567 if (GNUNET_OK != result)
568 return; /* not allowed */
569 GST_neighbours_try_connect (peer);
574 * Handle request connect message
576 * @param cls closure (always NULL)
577 * @param client identification of the client
578 * @param message the actual message
581 clients_handle_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
582 const struct GNUNET_MessageHeader *message)
584 const struct TransportRequestConnectMessage *trcm =
585 (const struct TransportRequestConnectMessage *) message;
587 GNUNET_STATISTICS_update (GST_stats,
589 ("# REQUEST CONNECT messages received"), 1,
592 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
593 "Received a request connect message for peer `%s'\n",
594 GNUNET_i2s (&trcm->peer));
596 (void) GST_blacklist_test_allowed (&trcm->peer, NULL, &try_connect_if_allowed,
598 GNUNET_SERVER_receive_done (client, GNUNET_OK);
603 * Client asked for a quota change for a particular peer. Process the request.
606 * @param client the client
607 * @param message the quota changing message
610 clients_handle_set_quota (void *cls, struct GNUNET_SERVER_Client *client,
611 const struct GNUNET_MessageHeader *message)
613 const struct QuotaSetMessage *qsm;
615 qsm = (const struct QuotaSetMessage *) message;
616 GNUNET_STATISTICS_update (GST_stats,
617 gettext_noop ("# SET QUOTA messages received"), 1,
620 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
621 "Received `%s' request (new quota %u) from client for peer `%4s'\n",
622 "SET_QUOTA", (unsigned int) ntohl (qsm->quota.value__),
623 GNUNET_i2s (&qsm->peer));
625 GST_neighbours_set_incoming_quota (&qsm->peer, qsm->quota);
626 GNUNET_SERVER_receive_done (client, GNUNET_OK);
631 * Take the given address and append it to the set of results sent back to
634 * @param cls the transmission context used ('struct GNUNET_SERVER_TransmitContext*')
635 * @param address the resolved name, NULL to indicate the last response
638 transmit_address_to_client (void *cls, const char *buf)
640 struct GNUNET_SERVER_TransmitContext *tc = cls;
644 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
645 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
646 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
649 GNUNET_SERVER_transmit_context_append_data (tc, buf, strlen (buf) + 1,
650 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
655 * Take the given address and append it to the set of results sent back to
658 * @param cls the transmission context used ('struct GNUNET_SERVER_TransmitContext*')
659 * @param address the resolved name, NULL to indicate the last response
662 transmit_binary_to_client (void *cls, void *buf, size_t size)
664 struct GNUNET_SERVER_TransmitContext *tc = cls;
668 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
669 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
670 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
673 GNUNET_SERVER_transmit_context_append_data (tc, buf, size,
674 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
679 * Client asked to resolve an address. Process the request.
682 * @param client the client
683 * @param message the resolution request
686 clients_handle_address_lookup (void *cls, struct GNUNET_SERVER_Client *client,
687 const struct GNUNET_MessageHeader *message)
689 const struct AddressLookupMessage *alum;
690 struct GNUNET_TRANSPORT_PluginFunctions *papi;
691 const char *plugin_name;
693 uint32_t address_len;
695 struct GNUNET_SERVER_TransmitContext *tc;
696 struct GNUNET_TIME_Relative rtimeout;
699 size = ntohs (message->size);
700 if (size < sizeof (struct AddressLookupMessage))
703 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
706 alum = (const struct AddressLookupMessage *) message;
707 address_len = ntohl (alum->addrlen);
708 if (size <= sizeof (struct AddressLookupMessage) + address_len)
711 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
714 address = (const char *) &alum[1];
715 plugin_name = (const char *) &address[address_len];
716 if (plugin_name[size - sizeof (struct AddressLookupMessage) - address_len - 1]
720 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
723 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
724 numeric = ntohl (alum->numeric_only);
725 tc = GNUNET_SERVER_transmit_context_create (client);
726 papi = GST_plugins_find (plugin_name);
729 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
730 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
731 GNUNET_SERVER_transmit_context_run (tc, rtimeout);
734 GNUNET_SERVER_disable_receive_done_warning (client);
735 papi->address_pretty_printer (papi->cls, plugin_name, address, address_len,
736 numeric, rtimeout, &transmit_address_to_client,
742 * Send an address to the client.
744 * @param cls our 'struct GNUNET_SERVER_TransmitContext' (for sending)
745 * @param public_key public key for the peer, never NULL
746 * @param target peer this change is about, never NULL
747 * @param valid_until until what time do we consider the address valid?
748 * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO)
749 * is ZERO if the address is considered valid (no validation needed)
750 * is a time in the future if we're currently denying re-validation
751 * @param plugin_name name of the plugin
752 * @param plugin_address binary address
753 * @param plugin_address_len length of address
756 send_address_to_client (void *cls,
757 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
758 *public_key, const struct GNUNET_PeerIdentity *target,
759 struct GNUNET_TIME_Absolute valid_until,
760 struct GNUNET_TIME_Absolute validation_block,
761 const char *plugin_name, const void *plugin_address,
762 size_t plugin_address_len)
764 struct GNUNET_SERVER_TransmitContext *tc = cls;
767 /* FIXME: move to a binary format!!! */
768 GNUNET_asprintf (&addr_buf, "%s --- %s, %s",
769 GST_plugins_a2s (plugin_name, plugin_address,
772 GST_neighbours_test_connected (target)) ? "CONNECTED" :
774 (GNUNET_TIME_absolute_get_remaining (valid_until).rel_value >
775 0) ? "VALIDATED" : "UNVALIDATED");
776 transmit_address_to_client (tc, addr_buf);
777 GNUNET_free (addr_buf);
782 * Client asked to obtain information about a peer's addresses.
783 * Process the request.
784 * FIXME: use better name!
787 * @param client the client
788 * @param message the peer address information request
791 clients_handle_peer_address_lookup (void *cls,
792 struct GNUNET_SERVER_Client *client,
793 const struct GNUNET_MessageHeader *message)
795 const struct PeerAddressLookupMessage *peer_address_lookup;
796 struct GNUNET_SERVER_TransmitContext *tc;
798 peer_address_lookup = (const struct PeerAddressLookupMessage *) message;
799 GNUNET_break (ntohl (peer_address_lookup->reserved) == 0);
800 tc = GNUNET_SERVER_transmit_context_create (client);
801 GST_validation_get_addresses (&peer_address_lookup->peer,
802 &send_address_to_client, tc);
803 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
804 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
805 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
810 * Output the active address of connected neighbours to the given client.
812 * @param cls the 'struct GNUNET_SERVER_TransmitContext' for transmission to the client
813 * @param neighbour identity of the neighbour
814 * @param ats performance data
815 * @param ats_count number of entries in ats (excluding 0-termination)
816 * @param transport plugin
817 * @param addr address
818 * @param addrlen address length
821 output_addresses (void *cls, const struct GNUNET_PeerIdentity *peer,
822 const struct GNUNET_ATS_Information *ats,
824 const char * transport,
828 struct GNUNET_SERVER_TransmitContext *tc = cls;
829 struct AddressIterateResponseMessage * msg;
833 (sizeof (struct AddressIterateResponseMessage) + strlen(transport) + 1);
834 msg = GNUNET_malloc (size);
835 memcpy (&msg->peer, peer, sizeof (struct GNUNET_PeerIdentity));
836 memcpy (&msg[0], transport, strlen(transport)+1);
837 msg->addrlen = ntohs (addrlen);
838 msg->pluginlen = ntohs (strlen(transport)+1);
840 transmit_binary_to_client (tc, msg, size);
846 * Client asked to obtain information about all actively used addresses.
847 * Process the request. FIXME: use better name!
850 * @param client the client
851 * @param message the peer address information request
854 clients_handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client,
855 const struct GNUNET_MessageHeader *message)
857 struct GNUNET_SERVER_TransmitContext *tc;
859 GNUNET_SERVER_disable_receive_done_warning (client);
860 tc = GNUNET_SERVER_transmit_context_create (client);
861 GST_neighbours_iterate (&output_addresses, tc);
862 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
863 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
864 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
869 * Start handling requests from clients.
871 * @param server server used to accept clients from.
874 GST_clients_start (struct GNUNET_SERVER_Handle *server)
876 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
877 {&clients_handle_start, NULL,
878 GNUNET_MESSAGE_TYPE_TRANSPORT_START, sizeof (struct StartMessage)},
879 {&clients_handle_hello, NULL,
880 GNUNET_MESSAGE_TYPE_HELLO, 0},
881 {&clients_handle_send, NULL,
882 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0},
883 {&clients_handle_request_connect, NULL,
884 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT,
885 sizeof (struct TransportRequestConnectMessage)},
886 {&clients_handle_set_quota, NULL,
887 GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, sizeof (struct QuotaSetMessage)},
888 {&clients_handle_address_lookup, NULL,
889 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP, 0},
890 {&clients_handle_peer_address_lookup, NULL,
891 GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP,
892 sizeof (struct PeerAddressLookupMessage)},
893 {&clients_handle_address_iterate, NULL,
894 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE,
895 sizeof (struct AddressIterateMessage)},
896 {&GST_blacklist_handle_init, NULL,
897 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
898 sizeof (struct GNUNET_MessageHeader)},
899 {&GST_blacklist_handle_reply, NULL,
900 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
901 sizeof (struct BlacklistMessage)},
904 GNUNET_SERVER_add_handlers (server, handlers);
905 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_notification,
911 * Stop processing clients.
921 * Broadcast the given message to all of our clients.
923 * @param msg message to broadcast
924 * @param may_drop GNUNET_YES if the message can be dropped
927 GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop)
929 struct TransportClient *tc;
931 for (tc = clients_head; tc != NULL; tc = tc->next)
932 unicast (tc, msg, may_drop);
937 * Send the given message to a particular client
939 * @param client target of the message
940 * @param msg message to transmit
941 * @param may_drop GNUNET_YES if the message can be dropped
944 GST_clients_unicast (struct GNUNET_SERVER_Client *client,
945 const struct GNUNET_MessageHeader *msg, int may_drop)
947 struct TransportClient *tc;
949 tc = lookup_client (client);
951 return; /* client got disconnected in the meantime, drop message */
952 unicast (tc, msg, may_drop);
956 /* end of file gnunet-service-transport_clients.c */