2 This file is part of GNUnet.
3 (C) 2009 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 2, 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.c
23 * @brief low-level P2P messaging
24 * @author Christian Grothoff
27 * - if we do not receive an ACK in response to our
28 * HELLO, retransmit HELLO!
31 #include "gnunet_client_lib.h"
32 #include "gnunet_constants.h"
33 #include "gnunet_getopt_lib.h"
34 #include "gnunet_hello_lib.h"
35 #include "gnunet_os_lib.h"
36 #include "gnunet_peerinfo_service.h"
37 #include "gnunet_plugin_lib.h"
38 #include "gnunet_protocols.h"
39 #include "gnunet_service_lib.h"
40 #include "gnunet_signatures.h"
41 #include "plugin_transport.h"
42 #include "transport.h"
45 * How many messages can we have pending for a given client process
46 * before we start to drop incoming messages? We typically should
47 * have only one client and so this would be the primary buffer for
48 * messages, so the number should be chosen rather generously.
50 * The expectation here is that most of the time the queue is large
51 * enough so that a drop is virtually never required.
53 #define MAX_PENDING 128
56 * How often should we try to reconnect to a peer using a particular
57 * transport plugin before giving up? Note that the plugin may be
58 * added back to the list after PLUGIN_RETRY_FREQUENCY expires.
60 #define MAX_CONNECT_RETRY 3
63 * How often must a peer violate bandwidth quotas before we start
64 * to simply drop its messages?
66 #define QUOTA_VIOLATION_DROP_THRESHOLD 100
69 * How long until a HELLO verification attempt should time out?
70 * Must be rather small, otherwise a partially successful HELLO
71 * validation (some addresses working) might not be available
72 * before a client's request for a connection fails for good.
73 * Besides, if a single request to an address takes a long time,
74 * then the peer is unlikely worthwhile anyway.
76 #define HELLO_VERIFICATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
79 * How often do we re-add (cheaper) plugins to our list of plugins
80 * to try for a given connected peer?
82 #define PLUGIN_RETRY_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
85 * After how long do we expire an address in a HELLO
86 * that we just validated? This value is also used
87 * for our own addresses when we create a HELLO.
89 #define HELLO_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 12)
93 * Entry in linked list of network addresses.
98 * This is a linked list.
100 struct AddressList *next;
103 * The address, actually a pointer to the end
104 * of this struct. Do not free!
109 * How long until we auto-expire this address (unless it is
110 * re-confirmed by the transport)?
112 struct GNUNET_TIME_Absolute expires;
123 * Entry in linked list of all of our plugins.
125 struct TransportPlugin
129 * This is a linked list.
131 struct TransportPlugin *next;
134 * API of the transport as returned by the plugin's
135 * initialization function.
137 struct GNUNET_TRANSPORT_PluginFunctions *api;
140 * Short name for the plugin (i.e. "tcp").
145 * Name of the library (i.e. "gnunet_plugin_transport_tcp").
150 * List of our known addresses for this transport.
152 struct AddressList *addresses;
155 * Environment this transport service is using
158 struct GNUNET_TRANSPORT_PluginEnvironment env;
161 * ID of task that is used to clean up expired addresses.
163 GNUNET_SCHEDULER_TaskIdentifier address_update_task;
167 * Set to GNUNET_YES if we need to scrap the existing
168 * list of "addresses" and start fresh when we receive
169 * the next address update from a transport. Set to
170 * GNUNET_NO if we should just add the new address
171 * to the list and wait for the commit call.
176 struct NeighbourList;
179 * For each neighbour we keep a list of messages
180 * that we still want to transmit to the neighbour.
186 * This is a linked list.
188 struct MessageQueue *next;
191 * The message we want to transmit.
193 struct GNUNET_MessageHeader *message;
196 * Client responsible for queueing the message;
197 * used to check that a client has not two messages
198 * pending for the same target. Can be NULL.
200 struct TransportClient *client;
203 * Neighbour this entry belongs to.
205 struct NeighbourList *neighbour;
208 * Plugin that we used for the transmission.
209 * NULL until we scheduled a transmission.
211 struct TransportPlugin *plugin;
214 * Internal message of the transport system that should not be
215 * included in the usual SEND-SEND_OK transmission confirmation
216 * traffic management scheme. Typically, "internal_msg" will
217 * be set whenever "client" is NULL (but it is not strictly
223 * How important is the message?
225 unsigned int priority;
231 * For a given Neighbour, which plugins are available
232 * to talk to this peer and what are their costs?
238 * This is a linked list.
240 struct ReadyList *next;
243 * Which of our transport plugins does this entry
246 struct TransportPlugin *plugin;
249 * Neighbour this entry belongs to.
251 struct NeighbourList *neighbour;
254 * Opaque handle (specific to the plugin) for the
255 * connection to our target; can be NULL.
260 * What was the last latency observed for this plugin
261 * and peer? Invalid if connected is GNUNET_NO.
263 struct GNUNET_TIME_Relative latency;
266 * If we did not successfully transmit a message to the
267 * given peer via this connection during the specified
268 * time, we should consider the connection to be dead.
269 * This is used in the case that a TCP transport simply
270 * stalls writing to the stream but does not formerly
271 * get a signal that the other peer died.
273 struct GNUNET_TIME_Absolute timeout;
276 * Is this plugin currently connected? The first time
277 * we transmit or send data to a peer via a particular
278 * plugin, we set this to GNUNET_YES. If we later get
279 * an error (disconnect notification or transmission
280 * failure), we set it back to GNUNET_NO. Each time the
281 * value is set to GNUNET_YES, we increment the
282 * "connect_attempts" counter. If that one reaches a
283 * particular threshold, we consider the plugin to not
284 * be working properly at this time for the given peer
285 * and remove it from the eligible list.
290 * How often have we tried to connect using this plugin?
292 unsigned int connect_attempts;
295 * Is this plugin ready to transmit to the specific
296 * target? GNUNET_NO if not. Initially, all plugins
297 * are marked ready. If a transmission is in progress,
298 * "transmit_ready" is set to GNUNET_NO.
306 * Entry in linked list of all of our current neighbours.
312 * This is a linked list.
314 struct NeighbourList *next;
317 * Which of our transports is connected to this peer
318 * and what is their status?
320 struct ReadyList *plugins;
323 * List of messages we would like to send to this peer;
324 * must contain at most one message per client.
326 struct MessageQueue *messages;
329 * Identity of this neighbour.
331 struct GNUNET_PeerIdentity id;
334 * ID of task scheduled to run when this peer is about to
335 * time out (will free resources associated with the peer).
337 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
340 * How long until we should consider this peer dead
341 * (if we don't receive another message in the
344 struct GNUNET_TIME_Absolute peer_timeout;
347 * At what time did we reset last_received last?
349 struct GNUNET_TIME_Absolute last_quota_update;
352 * At what time should we try to again add plugins to
355 struct GNUNET_TIME_Absolute retry_plugins_time;
358 * How many bytes have we received since the "last_quota_update"
361 uint64_t last_received;
364 * Global quota for inbound traffic for the neighbour in bytes/ms.
369 * How often has the other peer (recently) violated the
370 * inbound traffic limit? Incremented by 10 per violation,
371 * decremented by 1 per non-violation (for each
374 unsigned int quota_violation_count;
377 * Have we seen an ACK from this neighbour in the past?
378 * (used to make up a fake ACK for clients connecting after
379 * the neighbour connected to us).
387 * Linked list of messages to be transmitted to
388 * the client. Each entry is followed by the
391 struct ClientMessageQueueEntry
394 * This is a linked list.
396 struct ClientMessageQueueEntry *next;
401 * Client connected to the transport service.
403 struct TransportClient
407 * This is a linked list.
409 struct TransportClient *next;
412 * Handle to the client.
414 struct GNUNET_SERVER_Client *client;
417 * Linked list of messages yet to be transmitted to
420 struct ClientMessageQueueEntry *message_queue_head;
423 * Tail of linked list of messages yet to be transmitted to the
426 struct ClientMessageQueueEntry *message_queue_tail;
429 * Is a call to "transmit_send_continuation" pending? If so, we
430 * must not free this struct (even if the corresponding client
431 * disconnects) and instead only remove it from the linked list and
432 * set the "client" field to NULL.
437 * Length of the list of messages pending for this client.
439 unsigned int message_count;
445 * For each HELLO, we may have to validate multiple addresses;
446 * each address gets its own request entry.
448 struct ValidationAddress
451 * This is a linked list.
453 struct ValidationAddress *next;
456 * Name of the transport.
458 char *transport_name;
461 * When should this validated address expire?
463 struct GNUNET_TIME_Absolute expiration;
466 * Length of the address we are validating.
471 * Challenge number we used.
476 * Set to GNUNET_YES if the challenge was met,
477 * GNUNET_SYSERR if we know it failed, GNUNET_NO
478 * if we are waiting on a response.
485 * Entry in linked list of all HELLOs awaiting validation.
487 struct ValidationList
491 * This is a linked list.
493 struct ValidationList *next;
496 * Linked list with one entry per address from the HELLO
497 * that needs to be validated.
499 struct ValidationAddress *addresses;
502 * The public key of the peer.
504 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded publicKey;
507 * When does this record time-out? (assuming the
508 * challenge goes unanswered)
510 struct GNUNET_TIME_Absolute timeout;
516 * HELLOs awaiting validation.
518 static struct ValidationList *pending_validations;
523 static struct GNUNET_HELLO_Message *our_hello;
526 * "version" of "our_hello". Used to see if a given
527 * neighbour has already been sent the latest version
528 * of our HELLO message.
530 static unsigned int our_hello_version;
535 static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key;
540 static struct GNUNET_PeerIdentity my_identity;
545 static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
550 struct GNUNET_SCHEDULER_Handle *sched;
555 const struct GNUNET_CONFIGURATION_Handle *cfg;
558 * Linked list of all clients to this service.
560 static struct TransportClient *clients;
563 * All loaded plugins.
565 static struct TransportPlugin *plugins;
570 static struct GNUNET_SERVER_Handle *server;
573 * All known neighbours and their HELLOs.
575 static struct NeighbourList *neighbours;
578 * Number of neighbours we'd like to have.
580 static uint32_t max_connect_per_transport;
584 * Find an entry in the neighbour list for a particular peer.
586 * @return NULL if not found.
588 static struct NeighbourList *
589 find_neighbour (const struct GNUNET_PeerIdentity *key)
591 struct NeighbourList *head = neighbours;
592 while ((head != NULL) &&
593 (0 != memcmp (key, &head->id, sizeof (struct GNUNET_PeerIdentity))))
600 * Find an entry in the transport list for a particular transport.
602 * @return NULL if not found.
604 static struct TransportPlugin *
605 find_transport (const char *short_name)
607 struct TransportPlugin *head = plugins;
608 while ((head != NULL) && (0 != strcmp (short_name, head->short_name)))
615 * Update the quota values for the given neighbour now.
618 update_quota (struct NeighbourList *n)
620 struct GNUNET_TIME_Relative delta;
624 delta = GNUNET_TIME_absolute_get_duration (n->last_quota_update);
625 if (delta.value < MIN_QUOTA_REFRESH_TIME)
626 return; /* not enough time passed for doing quota update */
627 allowed = delta.value * n->quota_in;
628 if (n->last_received < allowed)
630 remaining = allowed - n->last_received;
632 remaining /= n->quota_in;
635 if (remaining > MAX_BANDWIDTH_CARRY)
636 remaining = MAX_BANDWIDTH_CARRY;
637 n->last_received = 0;
638 n->last_quota_update = GNUNET_TIME_absolute_get ();
639 n->last_quota_update.value -= remaining;
640 if (n->quota_violation_count > 0)
641 n->quota_violation_count--;
645 n->last_received -= allowed;
646 n->last_quota_update = GNUNET_TIME_absolute_get ();
647 if (n->last_received > allowed)
649 /* more than twice the allowed rate! */
650 n->quota_violation_count += 10;
657 * Function called to notify a client about the socket
658 * being ready to queue more data. "buf" will be
659 * NULL and "size" zero if the socket was closed for
660 * writing in the meantime.
663 * @param size number of bytes available in buf
664 * @param buf where the callee should write the message
665 * @return number of bytes written to buf
668 transmit_to_client_callback (void *cls, size_t size, void *buf)
670 struct TransportClient *client = cls;
671 struct ClientMessageQueueEntry *q;
674 const struct GNUNET_MessageHeader *msg;
675 struct GNUNET_CONNECTION_TransmitHandle *th;
680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
681 "Transmission to client failed, closing connection.\n");
682 /* fatal error with client, free message queue! */
683 while (NULL != (q = client->message_queue_head))
685 client->message_queue_head = q->next;
688 client->message_queue_tail = NULL;
689 client->message_count = 0;
694 while (NULL != (q = client->message_queue_head))
696 msg = (const struct GNUNET_MessageHeader *) &q[1];
697 msize = ntohs (msg->size);
698 if (msize + tsize > size)
701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
702 "Transmitting message of type %u to client.\n",
705 client->message_queue_head = q->next;
707 client->message_queue_tail = NULL;
708 memcpy (&cbuf[tsize], msg, msize);
711 client->message_count--;
715 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
716 th = GNUNET_SERVER_notify_transmit_ready (client->client,
718 GNUNET_TIME_UNIT_FOREVER_REL,
719 &transmit_to_client_callback,
721 GNUNET_assert (th != NULL);
728 * Send the specified message to the specified client. Since multiple
729 * messages may be pending for the same client at a time, this code
730 * makes sure that no message is lost.
732 * @param client client to transmit the message to
733 * @param msg the message to send
734 * @param may_drop can this message be dropped if the
735 * message queue for this client is getting far too large?
738 transmit_to_client (struct TransportClient *client,
739 const struct GNUNET_MessageHeader *msg, int may_drop)
741 struct ClientMessageQueueEntry *q;
743 struct GNUNET_CONNECTION_TransmitHandle *th;
745 if ((client->message_count >= MAX_PENDING) && (GNUNET_YES == may_drop))
747 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
749 ("Dropping message, have %u messages pending (%u is the soft limit)\n"),
750 client->message_count, MAX_PENDING);
751 /* TODO: call to statistics... */
754 client->message_count++;
755 msize = ntohs (msg->size);
756 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
757 q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize);
758 memcpy (&q[1], msg, msize);
759 /* append to message queue */
760 if (client->message_queue_tail == NULL)
762 client->message_queue_tail = q;
766 client->message_queue_tail->next = q;
767 client->message_queue_tail = q;
769 if (client->message_queue_head == NULL)
771 client->message_queue_head = q;
772 th = GNUNET_SERVER_notify_transmit_ready (client->client,
774 GNUNET_TIME_UNIT_FOREVER_REL,
775 &transmit_to_client_callback,
777 GNUNET_assert (th != NULL);
783 * Find alternative plugins for communication.
785 * @param neighbour for which neighbour should we try to find
789 try_alternative_plugins (struct NeighbourList *neighbour)
791 struct ReadyList *rl;
793 if ((neighbour->plugins != NULL) &&
794 (neighbour->retry_plugins_time.value >
795 GNUNET_TIME_absolute_get ().value))
796 return; /* don't try right now */
797 neighbour->retry_plugins_time
798 = GNUNET_TIME_relative_to_absolute (PLUGIN_RETRY_FREQUENCY);
800 rl = neighbour->plugins;
803 if (rl->connect_attempts > 0)
804 rl->connect_attempts--; /* amnesty */
812 * The peer specified by the given neighbour has timed-out or a plugin
813 * has disconnected. We may either need to do nothing (other plugins
814 * still up), or trigger a full disconnect and clean up. This
815 * function updates our state and do the necessary notifications.
816 * Also notifies our clients that the neighbour is now officially
819 * @param n the neighbour list entry for the peer
820 * @param check should we just check if all plugins
821 * disconnected or must we ask all plugins to
825 disconnect_neighbour (struct NeighbourList *n,
830 * Check the ready list for the given neighbour and
831 * if a plugin is ready for transmission (and if we
832 * have a message), do so!
834 * @param neighbour target peer for which to check the plugins
837 try_transmission_to_peer (struct NeighbourList *neighbour);
841 * Function called by the GNUNET_TRANSPORT_TransmitFunction
842 * upon "completion" of a send request. This tells the API
843 * that it is now legal to send another message to the given
846 * @param cls closure, identifies the entry on the
847 * message queue that was transmitted and the
848 * client responsible for queueing the message
849 * @param rl identifies plugin used for the transmission for
850 * this neighbour; needs to be re-enabled for
851 * future transmissions
852 * @param target the peer receiving the message
853 * @param result GNUNET_OK on success, if the transmission
854 * failed, we should not tell the client to transmit
858 transmit_send_continuation (void *cls,
859 struct ReadyList *rl,
860 const struct GNUNET_PeerIdentity *target,
863 struct MessageQueue *mq = cls;
864 struct SendOkMessage send_ok_msg;
865 struct NeighbourList *n;
867 GNUNET_assert (mq != NULL);
869 GNUNET_assert (n != NULL);
871 memcmp (&n->id, target,
872 sizeof (struct GNUNET_PeerIdentity)));
876 while ((rl != NULL) && (rl->plugin != mq->plugin))
878 GNUNET_assert (rl != NULL);
880 if (result == GNUNET_OK)
882 rl->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
886 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
887 "Transmission to peer `%s' failed, marking connection as down.\n",
889 rl->connected = GNUNET_NO;
890 rl->plugin_handle = NULL;
892 if (!mq->internal_msg)
893 rl->transmit_ready = GNUNET_YES;
894 if (mq->client != NULL)
896 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
897 "Notifying client %p about failed transission to peer `%4s'.\n",
900 send_ok_msg.header.size = htons (sizeof (send_ok_msg));
901 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
902 send_ok_msg.success = htonl (result);
903 send_ok_msg.peer = n->id;
904 transmit_to_client (mq->client, &send_ok_msg.header, GNUNET_NO);
906 GNUNET_free (mq->message);
908 /* one plugin just became ready again, try transmitting
909 another message (if available) */
910 if (result == GNUNET_OK)
911 try_transmission_to_peer (n);
913 disconnect_neighbour (n, GNUNET_YES);
918 * Check the ready list for the given neighbour and
919 * if a plugin is ready for transmission (and if we
920 * have a message), do so!
923 try_transmission_to_peer (struct NeighbourList *neighbour)
925 struct ReadyList *pos;
926 struct GNUNET_TIME_Relative min_latency;
927 struct ReadyList *rl;
928 struct MessageQueue *mq;
929 struct GNUNET_TIME_Absolute now;
931 if (neighbour->messages == NULL)
932 return; /* nothing to do */
933 try_alternative_plugins (neighbour);
934 min_latency = GNUNET_TIME_UNIT_FOREVER_REL;
936 mq = neighbour->messages;
937 now = GNUNET_TIME_absolute_get ();
938 pos = neighbour->plugins;
941 /* set plugins that are inactive for a long time back to disconnected */
942 if ((pos->timeout.value < now.value) && (pos->connected == GNUNET_YES))
945 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
946 "Marking long-time inactive connection to `%4s' as down.\n",
947 GNUNET_i2s (&neighbour->id));
949 pos->connected = GNUNET_NO;
951 if (((GNUNET_YES == pos->transmit_ready) ||
952 (mq->internal_msg)) &&
953 (pos->connect_attempts < MAX_CONNECT_RETRY) &&
954 ((rl == NULL) || (min_latency.value > pos->latency.value)))
957 min_latency = pos->latency;
964 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
965 "No plugin ready to transmit message\n");
967 return; /* nobody ready */
969 if (GNUNET_NO == rl->connected)
971 rl->connect_attempts++;
972 rl->connected = GNUNET_YES;
974 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
975 "Establishing fresh connection with `%4s' via plugin `%s'\n",
976 GNUNET_i2s (&neighbour->id), rl->plugin->short_name);
979 neighbour->messages = mq->next;
980 mq->plugin = rl->plugin;
981 if (!mq->internal_msg)
982 rl->transmit_ready = GNUNET_NO;
984 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
985 "Giving message of type `%u' for `%4s' to plugin `%s'\n",
986 ntohs (mq->message->type),
987 GNUNET_i2s (&neighbour->id), rl->plugin->short_name);
990 = rl->plugin->api->send (rl->plugin->api->cls,
996 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
997 &transmit_send_continuation, mq);
1002 * Send the specified message to the specified peer.
1004 * @param client source of the transmission request (can be NULL)
1005 * @param priority how important is the message
1006 * @param msg message to send
1007 * @param is_internal is this an internal message
1008 * @param neighbour handle to the neighbour for transmission
1011 transmit_to_peer (struct TransportClient *client,
1012 unsigned int priority,
1013 const struct GNUNET_MessageHeader *msg,
1014 int is_internal, struct NeighbourList *neighbour)
1016 struct MessageQueue *mq;
1017 struct MessageQueue *mqe;
1018 struct GNUNET_MessageHeader *m;
1021 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1022 _("Sending message of type %u to peer `%4s'\n"),
1023 ntohs (msg->type), GNUNET_i2s (&neighbour->id));
1027 /* check for duplicate submission */
1028 mq = neighbour->messages;
1031 if (mq->client == client)
1033 /* client transmitted to same peer twice
1034 before getting SendOk! */
1041 mq = GNUNET_malloc (sizeof (struct MessageQueue));
1042 mq->client = client;
1043 m = GNUNET_malloc (ntohs (msg->size));
1044 memcpy (m, msg, ntohs (msg->size));
1046 mq->neighbour = neighbour;
1047 mq->internal_msg = is_internal;
1048 mq->priority = priority;
1051 mqe = neighbour->messages;
1053 while (mqe->next != NULL)
1058 neighbour->messages = mq;
1059 try_transmission_to_peer (neighbour);
1072 struct GeneratorContext
1074 struct TransportPlugin *plug_pos;
1075 struct AddressList *addr_pos;
1076 struct GNUNET_TIME_Absolute expiration;
1084 address_generator (void *cls, size_t max, void *buf)
1086 struct GeneratorContext *gc = cls;
1089 while ((gc->addr_pos == NULL) && (gc->plug_pos != NULL))
1091 gc->plug_pos = gc->plug_pos->next;
1092 gc->addr_pos = (gc->plug_pos != NULL) ? gc->plug_pos->addresses : NULL;
1094 if (NULL == gc->plug_pos)
1096 ret = GNUNET_HELLO_add_address (gc->plug_pos->short_name,
1099 gc->addr_pos->addrlen, buf, max);
1100 gc->addr_pos = gc->addr_pos->next;
1106 * Construct our HELLO message from all of the addresses of
1107 * all of the transports.
1112 struct GNUNET_HELLO_Message *hello;
1113 struct TransportClient *cpos;
1114 struct NeighbourList *npos;
1115 struct GeneratorContext gc;
1118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
1119 "Refreshing my `%s'\n",
1122 gc.plug_pos = plugins;
1123 gc.addr_pos = plugins != NULL ? plugins->addresses : NULL;
1124 gc.expiration = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
1125 hello = GNUNET_HELLO_create (&my_public_key, &address_generator, &gc);
1127 while (cpos != NULL)
1129 transmit_to_client (cpos,
1130 (const struct GNUNET_MessageHeader *) hello,
1135 GNUNET_free_non_null (our_hello);
1137 our_hello_version++;
1138 GNUNET_PEERINFO_add_peer (cfg, sched, &my_identity, our_hello);
1140 while (npos != NULL)
1143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
1144 "Transmitting updated `%s' to neighbour `%4s'\n",
1146 GNUNET_i2s(&npos->id));
1148 transmit_to_peer (NULL, 0,
1149 (const struct GNUNET_MessageHeader *) our_hello,
1157 * Task used to clean up expired addresses for a plugin.
1159 * @param cls closure
1163 expire_address_task (void *cls,
1164 const struct GNUNET_SCHEDULER_TaskContext *tc);
1168 * Update the list of addresses for this plugin,
1169 * expiring those that are past their expiration date.
1171 * @param plugin addresses of which plugin should be recomputed?
1172 * @param fresh set to GNUNET_YES if a new address was added
1173 * and we need to regenerate the HELLO even if nobody
1177 update_addresses (struct TransportPlugin *plugin, int fresh)
1179 struct GNUNET_TIME_Relative min_remaining;
1180 struct GNUNET_TIME_Relative remaining;
1181 struct GNUNET_TIME_Absolute now;
1182 struct AddressList *pos;
1183 struct AddressList *prev;
1184 struct AddressList *next;
1187 if (plugin->address_update_task != GNUNET_SCHEDULER_NO_TASK)
1188 GNUNET_SCHEDULER_cancel (plugin->env.sched, plugin->address_update_task);
1189 plugin->address_update_task = GNUNET_SCHEDULER_NO_TASK;
1190 now = GNUNET_TIME_absolute_get ();
1191 min_remaining = GNUNET_TIME_UNIT_FOREVER_REL;
1192 expired = GNUNET_NO;
1194 pos = plugin->addresses;
1198 if (pos->expires.value < now.value)
1200 expired = GNUNET_YES;
1202 plugin->addresses = pos->next;
1204 prev->next = pos->next;
1209 remaining = GNUNET_TIME_absolute_get_remaining (pos->expires);
1210 if (remaining.value < min_remaining.value)
1211 min_remaining = remaining;
1217 if (expired || fresh)
1219 if (min_remaining.value < GNUNET_TIME_UNIT_FOREVER_REL.value)
1220 plugin->address_update_task
1221 = GNUNET_SCHEDULER_add_delayed (plugin->env.sched,
1223 &expire_address_task, plugin);
1229 * Task used to clean up expired addresses for a plugin.
1231 * @param cls closure
1235 expire_address_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1237 struct TransportPlugin *plugin = cls;
1238 plugin->address_update_task = GNUNET_SCHEDULER_NO_TASK;
1239 update_addresses (plugin, GNUNET_NO);
1244 * Function that must be called by each plugin to notify the
1245 * transport service about the addresses under which the transport
1246 * provided by the plugin can be reached.
1248 * @param cls closure
1249 * @param name name of the transport that generated the address
1250 * @param addr one of the addresses of the host, NULL for the last address
1251 * the specific address format depends on the transport
1252 * @param addrlen length of the address
1253 * @param expires when should this address automatically expire?
1256 plugin_env_notify_address (void *cls,
1260 struct GNUNET_TIME_Relative expires)
1262 struct TransportPlugin *p = cls;
1263 struct AddressList *al;
1264 struct GNUNET_TIME_Absolute abex;
1266 abex = GNUNET_TIME_relative_to_absolute (expires);
1267 GNUNET_assert (p == find_transport (name));
1272 if ((addrlen == al->addrlen) && (0 == memcmp (addr, &al[1], addrlen)))
1274 if (al->expires.value < abex.value)
1281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1282 "Plugin `%s' informs us about a new address `%s'\n", name,
1283 GNUNET_a2s(addr, addrlen));
1285 al = GNUNET_malloc (sizeof (struct AddressList) + addrlen);
1287 al->next = p->addresses;
1290 al->addrlen = addrlen;
1291 memcpy (&al[1], addr, addrlen);
1292 update_addresses (p, GNUNET_YES);
1299 struct LookupHelloContext
1301 GNUNET_TRANSPORT_AddressCallback iterator;
1311 lookup_address_callback (void *cls,
1313 struct GNUNET_TIME_Absolute expiration,
1314 const void *addr, size_t addrlen)
1316 struct LookupHelloContext *lhc = cls;
1317 lhc->iterator (lhc->iterator_cls, tname, addr, addrlen);
1326 lookup_hello_callback (void *cls,
1327 const struct GNUNET_PeerIdentity *peer,
1328 const struct GNUNET_HELLO_Message *h, uint32_t trust)
1330 struct LookupHelloContext *lhc = cls;
1334 lhc->iterator (lhc->iterator_cls, NULL, NULL, 0);
1340 GNUNET_HELLO_iterate_addresses (h,
1341 GNUNET_NO, &lookup_address_callback, lhc);
1346 * Function that allows a transport to query the known
1347 * network addresses for a given peer.
1349 * @param cls closure
1350 * @param timeout after how long should we time out?
1351 * @param target which peer are we looking for?
1352 * @param iter function to call for each known address
1353 * @param iter_cls closure for iter
1356 plugin_env_lookup_address (void *cls,
1357 struct GNUNET_TIME_Relative timeout,
1358 const struct GNUNET_PeerIdentity *target,
1359 GNUNET_TRANSPORT_AddressCallback iter,
1362 struct LookupHelloContext *lhc;
1364 lhc = GNUNET_malloc (sizeof (struct LookupHelloContext));
1365 lhc->iterator = iter;
1366 lhc->iterator_cls = iter_cls;
1367 GNUNET_PEERINFO_for_all (cfg,
1369 target, 0, timeout, &lookup_hello_callback, &lhc);
1374 * Notify all of our clients about a peer connecting.
1377 notify_clients_connect (const struct GNUNET_PeerIdentity *peer,
1378 struct GNUNET_TIME_Relative latency)
1380 struct ConnectInfoMessage cim;
1381 struct TransportClient *cpos;
1384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1385 "Informing clients about peer `%4s' connecting to us\n",
1388 cim.header.size = htons (sizeof (struct ConnectInfoMessage));
1389 cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
1390 cim.quota_out = htonl (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT / (60*1000));
1391 cim.latency = GNUNET_TIME_relative_hton (latency);
1392 memcpy (&cim.id, peer, sizeof (struct GNUNET_PeerIdentity));
1394 while (cpos != NULL)
1396 transmit_to_client (cpos, &cim.header, GNUNET_NO);
1403 * Notify all of our clients about a peer disconnecting.
1406 notify_clients_disconnect (const struct GNUNET_PeerIdentity *peer)
1408 struct DisconnectInfoMessage dim;
1409 struct TransportClient *cpos;
1412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1413 "Informing clients about peer `%4s' disconnecting\n",
1416 dim.header.size = htons (sizeof (struct DisconnectInfoMessage));
1417 dim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
1418 dim.reserved = htonl (0);
1419 memcpy (&dim.peer, peer, sizeof (struct GNUNET_PeerIdentity));
1421 while (cpos != NULL)
1423 transmit_to_client (cpos, &dim.header, GNUNET_NO);
1430 * Copy any validated addresses to buf.
1432 * @return 0 once all addresses have been
1436 list_validated_addresses (void *cls, size_t max, void *buf)
1438 struct ValidationAddress **va = cls;
1441 while ((NULL != *va) && ((*va)->ok != GNUNET_YES))
1445 ret = GNUNET_HELLO_add_address ((*va)->transport_name,
1447 &(*va)[1], (*va)->addr_len, buf, max);
1454 * HELLO validation cleanup task.
1457 cleanup_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1459 struct ValidationAddress *va;
1460 struct ValidationList *pos;
1461 struct ValidationList *prev;
1462 struct GNUNET_TIME_Absolute now;
1463 struct GNUNET_TIME_Absolute first;
1464 struct GNUNET_HELLO_Message *hello;
1465 struct GNUNET_PeerIdentity pid;
1466 struct NeighbourList *n;
1469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
1470 "HELLO validation cleanup background task running...\n");
1472 now = GNUNET_TIME_absolute_get ();
1474 pos = pending_validations;
1477 if (pos->timeout.value < now.value)
1480 pending_validations = pos->next;
1482 prev->next = pos->next;
1483 va = pos->addresses;
1484 hello = GNUNET_HELLO_create (&pos->publicKey,
1485 &list_validated_addresses, &va);
1486 GNUNET_CRYPTO_hash (&pos->publicKey,
1488 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1492 "Creating persistent `%s' message for peer `%4s' based on confirmed addresses.\n",
1493 "HELLO", GNUNET_i2s (&pid));
1495 GNUNET_PEERINFO_add_peer (cfg, sched, &pid, hello);
1496 n = find_neighbour (&pid);
1498 try_transmission_to_peer (n);
1499 GNUNET_free (hello);
1500 while (NULL != (va = pos->addresses))
1502 pos->addresses = va->next;
1503 GNUNET_free (va->transport_name);
1508 pos = pending_validations;
1517 /* finally, reschedule cleanup if needed; list is
1518 ordered by timeout, so we need the last element... */
1519 if (NULL != pending_validations)
1521 first = pending_validations->timeout;
1522 pos = pending_validations;
1525 first = GNUNET_TIME_absolute_min (first, pos->timeout);
1528 GNUNET_SCHEDULER_add_delayed (sched,
1529 GNUNET_TIME_absolute_get_remaining (first),
1530 &cleanup_validation, NULL);
1538 * Function that will be called if we receive a validation
1539 * of an address challenge that we transmitted to another
1540 * peer. Note that the validation should only be considered
1541 * acceptable if the challenge matches AND if the sender
1542 * address is at least a plausible address for this peer
1543 * (otherwise we may be seeing a MiM attack).
1545 * @param cls closure
1546 * @param name name of the transport that generated the address
1547 * @param peer who responded to our challenge
1548 * @param challenge the challenge number we presumably used
1549 * @param sender_addr string describing our sender address (as observed
1550 * by the other peer in human-readable format)
1553 plugin_env_notify_validation (void *cls,
1555 const struct GNUNET_PeerIdentity *peer,
1557 const char *sender_addr)
1559 unsigned int not_done;
1561 struct ValidationList *pos;
1562 struct ValidationAddress *va;
1563 struct GNUNET_PeerIdentity id;
1565 pos = pending_validations;
1568 GNUNET_CRYPTO_hash (&pos->publicKey,
1570 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1573 memcmp (peer, &id, sizeof (struct GNUNET_PeerIdentity)))
1579 /* TODO: call statistics (unmatched PONG) */
1580 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1582 ("Received validation response but have no record of any validation request for `%4s'. Ignoring.\n"),
1587 matched = GNUNET_NO;
1588 va = pos->addresses;
1591 if (va->challenge == challenge)
1594 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1595 "Confirmed validity of address, peer `%4s' has address `%s'.\n",
1597 GNUNET_a2s ((const struct sockaddr*) &va[1],
1600 GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
1601 _("Another peer saw us using the address `%s' via `%s'. If this is not plausible, this address should be listed in the configuration as implausible to avoid MiM attacks.\n"),
1604 va->ok = GNUNET_YES;
1606 GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
1607 matched = GNUNET_YES;
1609 if (va->ok != GNUNET_YES)
1613 if (GNUNET_NO == matched)
1615 /* TODO: call statistics (unmatched PONG) */
1616 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1618 ("Received `%s' message but have no record of a matching `%s' message. Ignoring.\n"),
1624 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1625 "All addresses validated, will now construct `%s' for `%4s'.\n",
1629 pos->timeout.value = 0;
1630 GNUNET_SCHEDULER_add_with_priority (sched,
1631 GNUNET_SCHEDULER_PRIORITY_IDLE,
1632 &cleanup_validation, NULL);
1637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1638 "Still waiting for %u additional `%s' messages before constructing `%s' for `%4s'.\n",
1648 struct CheckHelloValidatedContext
1651 * Plugin for which we are validating.
1653 struct TransportPlugin *plugin;
1656 * Hello that we are validating.
1658 struct GNUNET_HELLO_Message *hello;
1661 * Validation list being build.
1663 struct ValidationList *e;
1669 * Append the given address to the list of entries
1670 * that need to be validated.
1673 run_validation (void *cls,
1675 struct GNUNET_TIME_Absolute expiration,
1676 const void *addr, size_t addrlen)
1678 struct ValidationList *e = cls;
1679 struct TransportPlugin *tp;
1680 struct ValidationAddress *va;
1681 struct GNUNET_PeerIdentity id;
1683 tp = find_transport (tname);
1686 GNUNET_log (GNUNET_ERROR_TYPE_INFO |
1687 GNUNET_ERROR_TYPE_BULK,
1689 ("Transport `%s' not loaded, will not try to validate peer address using this transport.\n"),
1693 GNUNET_CRYPTO_hash (&e->publicKey,
1695 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1697 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1698 "Scheduling validation of address `%s' via `%s' for `%4s'\n",
1699 GNUNET_a2s(addr, addrlen),
1703 va = GNUNET_malloc (sizeof (struct ValidationAddress) + addrlen);
1704 va->next = e->addresses;
1706 va->transport_name = GNUNET_strdup (tname);
1707 va->addr_len = addrlen;
1708 va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1710 memcpy (&va[1], addr, addrlen);
1716 * Check if addresses in validated hello "h" overlap with
1717 * those in "chvc->hello" and update "chvc->hello" accordingly,
1718 * removing those addresses that have already been validated.
1721 check_hello_validated (void *cls,
1722 const struct GNUNET_PeerIdentity *peer,
1723 const struct GNUNET_HELLO_Message *h,
1726 struct CheckHelloValidatedContext *chvc = cls;
1727 struct ValidationAddress *va;
1728 struct TransportPlugin *tp;
1730 struct GNUNET_PeerIdentity apeer;
1732 first_call = GNUNET_NO;
1733 if (chvc->e == NULL)
1735 first_call = GNUNET_YES;
1736 chvc->e = GNUNET_malloc (sizeof (struct ValidationList));
1737 GNUNET_assert (GNUNET_OK ==
1738 GNUNET_HELLO_get_key (h != NULL ? h : chvc->hello,
1739 &chvc->e->publicKey));
1741 GNUNET_TIME_relative_to_absolute (HELLO_VERIFICATION_TIMEOUT);
1742 chvc->e->next = pending_validations;
1743 pending_validations = chvc->e;
1747 GNUNET_HELLO_iterate_new_addresses (chvc->hello,
1749 GNUNET_TIME_absolute_get (),
1750 &run_validation, chvc->e);
1752 else if (GNUNET_YES == first_call)
1754 /* no existing HELLO, all addresses are new */
1755 GNUNET_HELLO_iterate_addresses (chvc->hello,
1756 GNUNET_NO, &run_validation, chvc->e);
1759 return; /* wait for next call */
1760 /* finally, transmit validation attempts */
1761 GNUNET_assert (GNUNET_OK ==
1762 GNUNET_HELLO_get_id (chvc->hello,
1765 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1766 "Ready to validate addresses from `%s' message for peer `%4s'\n",
1767 "HELLO", GNUNET_i2s (&apeer));
1769 va = chvc->e->addresses;
1773 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1774 "Establishing `%s' connection to validate `%s' address `%s' of `%4s'\n",
1777 GNUNET_a2s ((const struct sockaddr*) &va[1],
1779 GNUNET_i2s (&apeer));
1781 tp = find_transport (va->transport_name);
1782 GNUNET_assert (tp != NULL);
1784 tp->api->validate (tp->api->cls,
1787 HELLO_VERIFICATION_TIMEOUT,
1790 va->ok = GNUNET_SYSERR;
1793 GNUNET_SCHEDULER_add_delayed (sched,
1794 GNUNET_TIME_absolute_get_remaining (chvc->e->timeout),
1795 &cleanup_validation, NULL);
1801 * Process HELLO-message.
1803 * @param plugin transport involved, may be NULL
1804 * @param message the actual message
1805 * @return GNUNET_OK if the HELLO was well-formed, GNUNET_SYSERR otherwise
1808 process_hello (struct TransportPlugin *plugin,
1809 const struct GNUNET_MessageHeader *message)
1811 struct ValidationList *e;
1813 struct GNUNET_PeerIdentity target;
1814 const struct GNUNET_HELLO_Message *hello;
1815 struct CheckHelloValidatedContext *chvc;
1816 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded publicKey;
1818 hsize = ntohs (message->size);
1819 if ((ntohs (message->type) != GNUNET_MESSAGE_TYPE_HELLO) ||
1820 (hsize < sizeof (struct GNUNET_MessageHeader)))
1823 return GNUNET_SYSERR;
1825 /* first, check if load is too high */
1826 if (GNUNET_OS_load_cpu_get (cfg) > 100)
1828 /* TODO: call to stats? */
1831 hello = (const struct GNUNET_HELLO_Message *) message;
1832 if (GNUNET_OK != GNUNET_HELLO_get_key (hello, &publicKey))
1834 GNUNET_break_op (0);
1835 return GNUNET_SYSERR;
1837 GNUNET_CRYPTO_hash (&publicKey,
1838 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1839 &target.hashPubKey);
1841 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1842 "Processing `%s' message for `%4s'\n",
1843 "HELLO", GNUNET_i2s (&target));
1845 /* check if a HELLO for this peer is already on the validation list */
1846 e = pending_validations;
1849 if (0 == memcmp (&e->publicKey,
1852 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
1854 /* TODO: call to stats? */
1856 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1857 "`%s' message for peer `%4s' is already pending; ignoring new message\n",
1858 "HELLO", GNUNET_i2s (&target));
1864 chvc = GNUNET_malloc (sizeof (struct CheckHelloValidatedContext) + hsize);
1865 chvc->plugin = plugin;
1866 chvc->hello = (struct GNUNET_HELLO_Message *) &chvc[1];
1867 memcpy (chvc->hello, hello, hsize);
1868 /* finally, check if HELLO was previously validated
1869 (continuation will then schedule actual validation) */
1870 GNUNET_PEERINFO_for_all (cfg,
1874 HELLO_VERIFICATION_TIMEOUT,
1875 &check_hello_validated, chvc);
1881 * The peer specified by the given neighbour has timed-out or a plugin
1882 * has disconnected. We may either need to do nothing (other plugins
1883 * still up), or trigger a full disconnect and clean up. This
1884 * function updates our state and do the necessary notifications.
1885 * Also notifies our clients that the neighbour is now officially
1888 * @param n the neighbour list entry for the peer
1889 * @param check should we just check if all plugins
1890 * disconnected or must we ask all plugins to
1894 disconnect_neighbour (struct NeighbourList *n,
1897 struct ReadyList *rpos;
1898 struct NeighbourList *npos;
1899 struct NeighbourList *nprev;
1900 struct MessageQueue *mq;
1902 if (GNUNET_YES == check)
1905 while (NULL != rpos)
1907 if (GNUNET_YES == rpos->connected)
1908 return; /* still connected */
1914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
1915 "Disconnecting from `%4s'\n",
1916 GNUNET_i2s(&n->id));
1918 /* remove n from neighbours list */
1921 while ((npos != NULL) && (npos != n))
1926 GNUNET_assert (npos != NULL);
1928 neighbours = n->next;
1930 nprev->next = n->next;
1932 /* notify all clients about disconnect */
1933 notify_clients_disconnect (&n->id);
1935 /* clean up all plugins, cancel connections and pending transmissions */
1936 while (NULL != (rpos = n->plugins))
1938 n->plugins = rpos->next;
1939 GNUNET_assert (rpos->neighbour == n);
1940 if (GNUNET_YES == rpos->connected)
1941 rpos->plugin->api->cancel (rpos->plugin->api->cls,
1942 rpos->plugin_handle,
1948 /* free all messages on the queue */
1949 while (NULL != (mq = n->messages))
1951 n->messages = mq->next;
1952 GNUNET_assert (mq->neighbour == n);
1955 if (n->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1956 GNUNET_SCHEDULER_cancel (sched,
1958 /* finally, free n itself */
1964 * Add an entry for each of our transport plugins
1965 * (that are able to send) to the list of plugins
1966 * for this neighbour.
1968 * @param neighbour to initialize
1971 add_plugins (struct NeighbourList *neighbour)
1973 struct TransportPlugin *tp;
1974 struct ReadyList *rl;
1976 neighbour->retry_plugins_time
1977 = GNUNET_TIME_relative_to_absolute (PLUGIN_RETRY_FREQUENCY);
1981 if (tp->api->send != NULL)
1983 rl = GNUNET_malloc (sizeof (struct ReadyList));
1984 rl->next = neighbour->plugins;
1985 neighbour->plugins = rl;
1987 rl->neighbour = neighbour;
1988 rl->transmit_ready = GNUNET_YES;
1996 neighbour_timeout_task (void *cls,
1997 const struct GNUNET_SCHEDULER_TaskContext *tc)
1999 struct NeighbourList *n = cls;
2002 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2003 "Neighbour `%4s' has timed out!\n",
2004 GNUNET_i2s(&n->id));
2006 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2007 disconnect_neighbour (n, GNUNET_NO);
2012 * Create a fresh entry in our neighbour list for the given peer.
2013 * Will try to transmit our current HELLO to the new neighbour. Also
2014 * notifies our clients about the new "connection".
2016 * @param peer the peer for which we create the entry
2017 * @return the new neighbour list entry
2019 static struct NeighbourList *
2020 setup_new_neighbour (const struct GNUNET_PeerIdentity *peer)
2022 struct NeighbourList *n;
2025 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2026 "Setting up new neighbour `%4s', sending our HELLO to introduce ourselves\n",
2029 GNUNET_assert (our_hello != NULL);
2030 n = GNUNET_malloc (sizeof (struct NeighbourList));
2031 n->next = neighbours;
2034 n->last_quota_update = GNUNET_TIME_absolute_get ();
2036 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2037 n->quota_in = (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT + 59999) / (60 * 1000);
2039 n->timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
2040 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
2041 &neighbour_timeout_task, n);
2042 transmit_to_peer (NULL, 0,
2043 (const struct GNUNET_MessageHeader *) our_hello,
2045 notify_clients_connect (peer, GNUNET_TIME_UNIT_FOREVER_REL);
2051 * Function called by the plugin for each received message.
2052 * Update data volumes, possibly notify plugins about
2053 * reducing the rate at which they read from the socket
2054 * and generally forward to our receive callback.
2056 * @param cls the "struct TransportPlugin *" we gave to the plugin
2057 * @param plugin_context value to pass to this plugin
2058 * to respond to the given peer (use is optional,
2059 * but may speed up processing)
2060 * @param service_context value passed to the transport-service
2061 * to identify the neighbour; will be NULL on the first
2062 * call for a given peer
2063 * @param latency estimated latency for communicating with the
2065 * @param peer (claimed) identity of the other peer
2066 * @param message the message, NULL if peer was disconnected
2067 * @return the new service_context that the plugin should use
2068 * for future receive calls for messages from this
2071 static struct ReadyList *
2072 plugin_env_receive (void *cls,
2073 void *plugin_context,
2074 struct ReadyList *service_context,
2075 struct GNUNET_TIME_Relative latency,
2076 const struct GNUNET_PeerIdentity *peer,
2077 const struct GNUNET_MessageHeader *message)
2079 const struct GNUNET_MessageHeader ack = {
2080 htons (sizeof (struct GNUNET_MessageHeader)),
2081 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ACK)
2083 struct TransportPlugin *plugin = cls;
2084 struct TransportClient *cpos;
2085 struct InboundMessage *im;
2087 struct NeighbourList *n;
2089 if (service_context != NULL)
2091 n = service_context->neighbour;
2092 GNUNET_assert (n != NULL);
2096 n = find_neighbour (peer);
2099 if (message == NULL)
2100 return NULL; /* disconnect of peer already marked down */
2101 n = setup_new_neighbour (peer);
2103 service_context = n->plugins;
2104 while ((service_context != NULL) && (plugin != service_context->plugin))
2105 service_context = service_context->next;
2106 GNUNET_assert ((plugin->api->send == NULL) ||
2107 (service_context != NULL));
2109 if (message == NULL)
2112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2113 "Receive failed from `%4s', triggering disconnect\n",
2114 GNUNET_i2s(&n->id));
2116 /* TODO: call stats */
2117 if ((service_context != NULL) &&
2118 (service_context->plugin_handle == plugin_context))
2120 service_context->connected = GNUNET_NO;
2121 service_context->plugin_handle = NULL;
2123 disconnect_neighbour (n, GNUNET_YES);
2127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2128 "Processing message of type `%u' received by plugin...\n",
2129 ntohs (message->type));
2131 if (service_context != NULL)
2133 if (service_context->connected == GNUNET_NO)
2135 service_context->connected = GNUNET_YES;
2136 service_context->transmit_ready = GNUNET_YES;
2137 service_context->connect_attempts++;
2139 service_context->timeout
2140 = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2141 service_context->plugin_handle = plugin_context;
2142 service_context->latency = latency;
2144 /* update traffic received amount ... */
2145 msize = ntohs (message->size);
2146 n->last_received += msize;
2147 GNUNET_SCHEDULER_cancel (sched, n->timeout_task);
2149 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2151 GNUNET_SCHEDULER_add_delayed (sched,
2152 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
2153 &neighbour_timeout_task, n);
2155 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
2157 /* dropping message due to frequent inbound volume violations! */
2158 GNUNET_log (GNUNET_ERROR_TYPE_WARNING |
2159 GNUNET_ERROR_TYPE_BULK,
2161 ("Dropping incoming message due to repeated bandwidth quota violations.\n"));
2162 /* TODO: call stats */
2163 GNUNET_assert ( (service_context == NULL) ||
2164 (NULL != service_context->neighbour) );
2165 return service_context;
2167 switch (ntohs (message->type))
2169 case GNUNET_MESSAGE_TYPE_HELLO:
2171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2172 "Receiving `%s' message from `%4s'.\n", "HELLO",
2175 process_hello (plugin, message);
2177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2178 "Sending `%s' message to connecting peer `%4s'.\n", "ACK",
2181 transmit_to_peer (NULL, 0, &ack, GNUNET_YES, n);
2183 case GNUNET_MESSAGE_TYPE_TRANSPORT_ACK:
2184 n->saw_ack = GNUNET_YES;
2185 /* intentional fall-through! */
2188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2189 "Received message of type %u from `%4s', sending to all clients.\n",
2190 ntohs (message->type),
2193 /* transmit message to all clients */
2194 im = GNUNET_malloc (sizeof (struct InboundMessage) + msize);
2195 im->header.size = htons (sizeof (struct InboundMessage) + msize);
2196 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
2197 im->latency = GNUNET_TIME_relative_hton (latency);
2199 memcpy (&im[1], message, msize);
2202 while (cpos != NULL)
2204 transmit_to_client (cpos, &im->header, GNUNET_YES);
2209 GNUNET_assert ( (service_context == NULL) ||
2210 (NULL != service_context->neighbour) );
2211 return service_context;
2216 * Handle START-message. This is the first message sent to us
2217 * by any client which causes us to add it to our list.
2219 * @param cls closure (always NULL)
2220 * @param client identification of the client
2221 * @param message the actual message
2224 handle_start (void *cls,
2225 struct GNUNET_SERVER_Client *client,
2226 const struct GNUNET_MessageHeader *message)
2228 struct TransportClient *c;
2229 struct ConnectInfoMessage cim;
2230 struct NeighbourList *n;
2231 struct InboundMessage *im;
2232 struct GNUNET_MessageHeader *ack;
2235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2236 "Received `%s' request from client\n", "START");
2241 if (c->client == client)
2243 /* client already on our list! */
2245 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2250 c = GNUNET_malloc (sizeof (struct TransportClient));
2254 if (our_hello != NULL)
2257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2258 "Sending our own `%s' to new client\n",
2261 transmit_to_client (c,
2262 (const struct GNUNET_MessageHeader *) our_hello,
2264 /* tell new client about all existing connections */
2265 cim.header.size = htons (sizeof (struct ConnectInfoMessage));
2266 cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
2267 cim.quota_out = htonl (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT / (60 * 1000));
2268 cim.latency = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO); /* FIXME? */
2269 im = GNUNET_malloc (sizeof (struct InboundMessage) +
2270 sizeof (struct GNUNET_MessageHeader));
2271 im->header.size = htons (sizeof (struct InboundMessage) +
2272 sizeof (struct GNUNET_MessageHeader));
2273 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
2274 im->latency = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO); /* FIXME? */
2275 ack = (struct GNUNET_MessageHeader *) &im[1];
2276 ack->size = htons (sizeof (struct GNUNET_MessageHeader));
2277 ack->type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ACK);
2278 for (n = neighbours; n != NULL; n = n->next)
2281 transmit_to_client (c, &cim.header, GNUNET_NO);
2285 transmit_to_client (c, &im->header, GNUNET_NO);
2290 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2295 * Handle HELLO-message.
2297 * @param cls closure (always NULL)
2298 * @param client identification of the client
2299 * @param message the actual message
2302 handle_hello (void *cls,
2303 struct GNUNET_SERVER_Client *client,
2304 const struct GNUNET_MessageHeader *message)
2309 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2310 "Received `%s' request from client\n", "HELLO");
2312 ret = process_hello (NULL, message);
2313 GNUNET_SERVER_receive_done (client, ret);
2318 * Handle SEND-message.
2320 * @param cls closure (always NULL)
2321 * @param client identification of the client
2322 * @param message the actual message
2325 handle_send (void *cls,
2326 struct GNUNET_SERVER_Client *client,
2327 const struct GNUNET_MessageHeader *message)
2329 struct TransportClient *tc;
2330 struct NeighbourList *n;
2331 const struct OutboundMessage *obm;
2332 const struct GNUNET_MessageHeader *obmm;
2336 size = ntohs (message->size);
2338 sizeof (struct OutboundMessage) + sizeof (struct GNUNET_MessageHeader))
2341 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2344 obm = (const struct OutboundMessage *) message;
2346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2347 "Received `%s' request from client with target `%4s'\n",
2348 "SEND", GNUNET_i2s (&obm->peer));
2350 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
2351 msize = ntohs (obmm->size);
2352 if (size != msize + sizeof (struct OutboundMessage))
2355 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2358 n = find_neighbour (&obm->peer);
2360 n = setup_new_neighbour (&obm->peer);
2362 while ((tc != NULL) && (tc->client != client))
2366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2367 "Client asked to transmit %u-byte message of type %u to `%4s'\n",
2369 ntohs (obmm->type), GNUNET_i2s (&obm->peer));
2371 transmit_to_peer (tc, ntohl(obm->priority), obmm, GNUNET_NO, n);
2372 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2377 * Handle SET_QUOTA-message.
2379 * @param cls closure (always NULL)
2380 * @param client identification of the client
2381 * @param message the actual message
2384 handle_set_quota (void *cls,
2385 struct GNUNET_SERVER_Client *client,
2386 const struct GNUNET_MessageHeader *message)
2388 const struct QuotaSetMessage *qsm =
2389 (const struct QuotaSetMessage *) message;
2390 struct NeighbourList *n;
2391 struct TransportPlugin *p;
2392 struct ReadyList *rl;
2395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2396 "Received `%s' request from client for peer `%4s'\n",
2397 "SET_QUOTA", GNUNET_i2s (&qsm->peer));
2399 n = find_neighbour (&qsm->peer);
2402 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2406 if (n->quota_in < ntohl (qsm->quota_in))
2407 n->last_quota_update = GNUNET_TIME_absolute_get ();
2408 n->quota_in = ntohl (qsm->quota_in);
2413 p->api->set_receive_quota (p->api->cls,
2414 &qsm->peer, ntohl (qsm->quota_in));
2417 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2422 * Handle TRY_CONNECT-message.
2424 * @param cls closure (always NULL)
2425 * @param client identification of the client
2426 * @param message the actual message
2429 handle_try_connect (void *cls,
2430 struct GNUNET_SERVER_Client *client,
2431 const struct GNUNET_MessageHeader *message)
2433 const struct TryConnectMessage *tcm;
2435 tcm = (const struct TryConnectMessage *) message;
2437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2438 "Received `%s' request from client %p asking to connect to `%4s'\n",
2441 GNUNET_i2s (&tcm->peer));
2443 if (NULL == find_neighbour (&tcm->peer))
2444 setup_new_neighbour (&tcm->peer);
2447 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2448 "Client asked to connect to `%4s', but connection already exists\n",
2450 GNUNET_i2s (&tcm->peer));
2452 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2456 transmit_address_to_client (void *cls, const char *address)
2458 struct GNUNET_SERVER_TransmitContext *tc = cls;
2461 if (NULL == address)
2464 slen = strlen (address) + 1;
2465 GNUNET_SERVER_transmit_context_append (tc, address, slen,
2466 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
2467 if (NULL == address)
2468 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
2472 * Handle AddressLookup-message.
2474 * @param cls closure (always NULL)
2475 * @param client identification of the client
2476 * @param message the actual message
2479 handle_address_lookup (void *cls,
2480 struct GNUNET_SERVER_Client *client,
2481 const struct GNUNET_MessageHeader *message)
2483 const struct AddressLookupMessage *alum;
2484 struct TransportPlugin *lsPlugin;
2485 const char *nameTransport;
2486 const char *address;
2488 struct GNUNET_SERVER_TransmitContext *tc;
2490 size = ntohs (message->size);
2491 if (size < sizeof(struct AddressLookupMessage))
2493 GNUNET_break_op (0);
2494 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2497 alum = (const struct AddressLookupMessage *) message;
2498 uint32_t addressLen = ntohl(alum->addrlen);
2499 if (size <= sizeof(struct AddressLookupMessage) + addressLen)
2501 GNUNET_break_op (0);
2502 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2505 address = (const char *)&alum[1];
2506 nameTransport = (const char*)&address[addressLen];
2507 if (nameTransport [size - sizeof (struct AddressLookupMessage) - addressLen -1] != '\0')
2509 GNUNET_break_op (0);
2510 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2513 struct GNUNET_TIME_Absolute timeout= GNUNET_TIME_absolute_ntoh(alum->timeout);
2514 struct GNUNET_TIME_Relative rtimeout = GNUNET_TIME_absolute_get_remaining(timeout);
2515 lsPlugin = find_transport(nameTransport);
2516 if (NULL == lsPlugin)
2518 tc = GNUNET_SERVER_transmit_context_create (client);
2519 GNUNET_SERVER_transmit_context_append (tc, NULL, 0, GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
2520 GNUNET_SERVER_transmit_context_run (tc, rtimeout);
2523 tc = GNUNET_SERVER_transmit_context_create (client);
2524 lsPlugin->api->address_pretty_printer(cls, nameTransport,
2525 address, addressLen, GNUNET_YES, rtimeout, &transmit_address_to_client, tc);
2529 * List of handlers for the messages understood by this
2532 static struct GNUNET_SERVER_MessageHandler handlers[] = {
2533 {&handle_start, NULL,
2534 GNUNET_MESSAGE_TYPE_TRANSPORT_START, 0},
2535 {&handle_hello, NULL,
2536 GNUNET_MESSAGE_TYPE_HELLO, 0},
2537 {&handle_send, NULL,
2538 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0},
2539 {&handle_set_quota, NULL,
2540 GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, sizeof (struct QuotaSetMessage)},
2541 {&handle_try_connect, NULL,
2542 GNUNET_MESSAGE_TYPE_TRANSPORT_TRY_CONNECT,
2543 sizeof (struct TryConnectMessage)},
2544 {&handle_address_lookup, NULL,
2545 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP,
2552 * Setup the environment for this plugin.
2555 create_environment (struct TransportPlugin *plug)
2557 plug->env.cfg = cfg;
2558 plug->env.sched = sched;
2559 plug->env.my_public_key = &my_public_key;
2560 plug->env.my_private_key = my_private_key;
2561 plug->env.my_identity = &my_identity;
2562 plug->env.cls = plug;
2563 plug->env.receive = &plugin_env_receive;
2564 plug->env.lookup = &plugin_env_lookup_address;
2565 plug->env.notify_address = &plugin_env_notify_address;
2566 plug->env.notify_validation = &plugin_env_notify_validation;
2567 plug->env.default_quota_in = (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT + 59999) / (60 * 1000);
2568 plug->env.max_connections = max_connect_per_transport;
2573 * Start the specified transport (load the plugin).
2576 start_transport (struct GNUNET_SERVER_Handle *server, const char *name)
2578 struct TransportPlugin *plug;
2581 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2582 _("Loading `%s' transport plugin\n"), name);
2583 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", name);
2584 plug = GNUNET_malloc (sizeof (struct TransportPlugin));
2585 create_environment (plug);
2586 plug->short_name = GNUNET_strdup (name);
2587 plug->lib_name = libname;
2588 plug->next = plugins;
2590 plug->api = GNUNET_PLUGIN_load (libname, &plug->env);
2591 if (plug->api == NULL)
2593 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2594 _("Failed to load transport plugin for `%s'\n"), name);
2595 GNUNET_free (plug->short_name);
2596 plugins = plug->next;
2597 GNUNET_free (libname);
2604 * Called whenever a client is disconnected. Frees our
2605 * resources associated with that client.
2607 * @param cls closure
2608 * @param client identification of the client
2611 client_disconnect_notification (void *cls,
2612 struct GNUNET_SERVER_Client *client)
2614 struct TransportClient *pos;
2615 struct TransportClient *prev;
2616 struct ClientMessageQueueEntry *mqe;
2619 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2620 "Client disconnected, cleaning up.\n");
2624 while ((pos != NULL) && (pos->client != client))
2631 while (NULL != (mqe = pos->message_queue_head))
2633 pos->message_queue_head = mqe->next;
2636 pos->message_queue_head = NULL;
2638 clients = pos->next;
2640 prev->next = pos->next;
2641 if (GNUNET_YES == pos->tcs_pending)
2651 * Function called when the service shuts down. Unloads our plugins.
2653 * @param cls closure, unused
2654 * @param tc task context (unused)
2657 unload_plugins (void *cls,
2658 const struct GNUNET_SCHEDULER_TaskContext *tc)
2660 struct TransportPlugin *plug;
2661 struct AddressList *al;
2664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2665 "Transport service is unloading plugins...\n");
2667 while (NULL != (plug = plugins))
2669 plugins = plug->next;
2670 GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
2671 GNUNET_free (plug->lib_name);
2672 GNUNET_free (plug->short_name);
2673 while (NULL != (al = plug->addresses))
2675 plug->addresses = al->next;
2680 if (my_private_key != NULL)
2681 GNUNET_CRYPTO_rsa_key_free (my_private_key);
2682 GNUNET_free_non_null (our_hello);
2687 * Initiate transport service.
2689 * @param cls closure
2690 * @param s scheduler to use
2691 * @param serv the initialized server
2692 * @param c configuration to use
2696 struct GNUNET_SCHEDULER_Handle *s,
2697 struct GNUNET_SERVER_Handle *serv,
2698 const struct GNUNET_CONFIGURATION_Handle *c)
2703 unsigned long long tneigh;
2708 /* parse configuration */
2710 GNUNET_CONFIGURATION_get_value_number (c,
2715 GNUNET_CONFIGURATION_get_value_filename (c,
2717 "HOSTKEY", &keyfile)))
2719 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2721 ("Transport service is lacking key configuration settings. Exiting.\n"));
2722 GNUNET_SCHEDULER_shutdown (s);
2725 max_connect_per_transport = (uint32_t) tneigh;
2726 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
2727 GNUNET_free (keyfile);
2728 if (my_private_key == NULL)
2730 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2732 ("Transport service could not access hostkey. Exiting.\n"));
2733 GNUNET_SCHEDULER_shutdown (s);
2736 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
2737 GNUNET_CRYPTO_hash (&my_public_key,
2738 sizeof (my_public_key), &my_identity.hashPubKey);
2739 /* setup notification */
2741 GNUNET_SERVER_disconnect_notify (server,
2742 &client_disconnect_notification, NULL);
2743 /* load plugins... */
2746 GNUNET_CONFIGURATION_get_value_string (c,
2747 "TRANSPORT", "PLUGINS", &plugs))
2749 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2750 _("Starting transport plugins `%s'\n"), plugs);
2751 pos = strtok (plugs, " ");
2754 start_transport (server, pos);
2756 pos = strtok (NULL, " ");
2758 GNUNET_free (plugs);
2760 GNUNET_SCHEDULER_add_delayed (sched,
2761 GNUNET_TIME_UNIT_FOREVER_REL,
2762 &unload_plugins, NULL);
2766 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2767 _("Transport service ready.\n"));
2769 /* process client requests */
2770 GNUNET_SERVER_add_handlers (server, handlers);
2775 * The main function for the transport service.
2777 * @param argc number of arguments from the command line
2778 * @param argv command line arguments
2779 * @return 0 ok, 1 on error
2782 main (int argc, char *const *argv)
2784 return (GNUNET_OK ==
2785 GNUNET_SERVICE_run (argc,
2788 GNUNET_SERVICE_OPTION_NONE,
2789 &run, NULL)) ? 0 : 1;
2792 /* end of gnunet-service-transport.c */