a9dbd3573bd2a03997f05a52071918ad74031127
[oweals/gnunet.git] / src / topology / gnunet-daemon-topology.c
1 /*
2      This file is part of GNUnet.
3      (C) 2007, 2008, 2009, 2010 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19 */
20
21 /**
22  * @file topology/gnunet-daemon-topology.c
23  * @brief code for maintaining the mesh topology
24  * @author Christian Grothoff
25  */
26 #include "platform.h"
27 #include "gnunet_constants.h"
28 #include "gnunet_core_service.h"
29 #include "gnunet_protocols.h"
30 #include "gnunet_peerinfo_service.h"
31 #include "gnunet_statistics_service.h"
32 #include "gnunet_transport_service.h"
33 #include "gnunet_util_lib.h"
34
35
36 /**
37  * For how long do we blacklist a peer after a failed connection
38  * attempt?  This is the baseline factor which is then multiplied by
39  * two to the power of the number of failed attempts.
40  */
41 #define GREYLIST_AFTER_ATTEMPT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
42
43 /**
44  * For how long do we blacklist a friend after a failed connection
45  * attempt?  This is the baseline factor which is then multiplied by
46  * two to the power of the number of failed attempts.
47  */
48 #define GREYLIST_AFTER_ATTEMPT_FRIEND GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2)
49
50 /**
51  * For how long do we blacklist anyone under any cirumstances at least after a failed connection
52  * attempt?  This is the absolute minimum, regardless of what the calculation based on
53  * exponential backoff returns.
54  */
55 #define GREYLIST_AFTER_ATTEMPT_MIN GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
56
57 /**
58  * For how long do we blacklist anyone under any cirumstances at most after a failed connection
59  * attempt?  This is the absolute maximum, regardless of what the calculation based on 
60  * exponential back-off returns.
61  */
62 #define GREYLIST_AFTER_ATTEMPT_MAX GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1)
63
64 /**
65  * At what frequency do we sent HELLOs to a peer?
66  */
67 #define HELLO_ADVERTISEMENT_MIN_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
68
69 /**
70  * After what time period do we expire the HELLO Bloom filter?
71  */
72 #define HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
73
74
75 /**
76  * Record for neighbours, friends and blacklisted peers.
77  */
78 struct Peer
79 {
80   /**
81    * Which peer is this entry about?
82    */
83   struct GNUNET_PeerIdentity pid;
84
85   /**
86    * Our handle for the request to transmit HELLOs to this peer; NULL
87    * if no such request is pending.
88    */
89   struct GNUNET_CORE_TransmitHandle *hello_req;
90
91   /**
92    * Pointer to the HELLO message of this peer; can be NULL.
93    */
94   struct GNUNET_HELLO_Message *hello;
95
96   /**
97    * Bloom filter used to mark which peers already got the HELLO
98    * from this peer.
99    */
100   struct GNUNET_CONTAINER_BloomFilter *filter;
101
102   /**
103    * Until what time should we not try to connect again
104    * to this peer?
105    */
106   struct GNUNET_TIME_Absolute greylisted_until;
107
108   /**
109    * Next time we are allowed to transmit a HELLO to this peer?
110    */
111   struct GNUNET_TIME_Absolute next_hello_allowed;
112
113   /**
114    * When should we reset the bloom filter of this entry?
115    */
116   struct GNUNET_TIME_Absolute filter_expiration;
117
118   /**
119    * ID of task we use to wait for the time to send the next HELLO
120    * to this peer.
121    */
122   GNUNET_SCHEDULER_TaskIdentifier hello_delay_task;
123
124   /**
125    * ID of task we use to clear peers from the greylist.
126    */
127   GNUNET_SCHEDULER_TaskIdentifier greylist_clean_task;
128
129   /**
130    * How often have we tried so far?
131    */
132   unsigned int connect_attempts;
133
134   /**
135    * Is this peer listed here because he is a friend?
136    */
137   int is_friend;
138
139   /**
140    * Are we connected to this peer right now?
141    */
142   int is_connected;
143
144 };
145
146
147 /**
148  * Our peerinfo notification context.  We use notification
149  * to instantly learn about new peers as they are discovered.
150  */
151 static struct GNUNET_PEERINFO_NotifyContext *peerinfo_notify;
152
153 /**
154  * Our configuration.
155  */
156 static const struct GNUNET_CONFIGURATION_Handle *cfg;
157
158 /**
159  * Handle to the core API.
160  */
161 static struct GNUNET_CORE_Handle *handle;
162
163 /**
164  * Handle to the transport API.
165  */
166 static struct GNUNET_TRANSPORT_Handle *transport;
167
168 /**
169  * Identity of this peer.
170  */
171 static struct GNUNET_PeerIdentity my_identity;
172
173 /**
174  * All of our friends, all of our current neighbours and all peers for
175  * which we have HELLOs.  So pretty much everyone.  Maps peer identities
176  * to 'struct Peer *' values.
177  */
178 static struct GNUNET_CONTAINER_MultiHashMap *peers;
179
180 /**
181  * Handle for reporting statistics.
182  */
183 static struct GNUNET_STATISTICS_Handle *stats;
184
185 /**
186  * Blacklist (NULL if we have none).
187  */
188 static struct GNUNET_TRANSPORT_Blacklist *blacklist;
189
190 /**
191  * Task scheduled to try to add peers.
192  */
193 static GNUNET_SCHEDULER_TaskIdentifier add_task;
194
195 /**
196  * Flag to disallow non-friend connections (pure F2F mode).
197  */
198 static int friends_only;
199
200 /**
201  * Minimum number of friends to have in the
202  * connection set before we allow non-friends.
203  */
204 static unsigned int minimum_friend_count;
205
206 /**
207  * Number of peers (friends and others) that we are currently connected to.
208  */
209 static unsigned int connection_count;
210
211 /**
212  * Target number of connections.
213  */
214 static unsigned int target_connection_count;
215
216 /**
217  * Number of friends that we are currently connected to.
218  */
219 static unsigned int friend_count;
220
221 /**
222  * Should the topology daemon try to establish connections?
223  */
224 static int autoconnect;
225
226
227 /**
228  * Function that decides if a connection is acceptable or not.
229  * If we have a blacklist, only friends are allowed, so the check
230  * is rather simple.
231  *
232  * @param cls closure
233  * @param pid peer to approve or disapproave
234  * @return GNUNET_OK if the connection is allowed
235  */
236 static int
237 blacklist_check (void *cls, const struct GNUNET_PeerIdentity *pid)
238 {
239   struct Peer *pos;
240
241   pos = GNUNET_CONTAINER_multihashmap_get (peers, &pid->hashPubKey);
242   if ((pos != NULL) && (pos->is_friend == GNUNET_YES))
243     return GNUNET_OK;
244   GNUNET_STATISTICS_update (stats, gettext_noop ("# peers blacklisted"), 1,
245                             GNUNET_NO);
246   return GNUNET_SYSERR;
247 }
248
249
250 /**
251  * Whitelist all peers that we blacklisted; we've passed
252  * the minimum number of friends.
253  */
254 static void
255 whitelist_peers ()
256 {
257   if (blacklist != NULL)
258   {
259     GNUNET_TRANSPORT_blacklist_cancel (blacklist);
260     blacklist = NULL;
261   }
262 }
263
264
265 /**
266  * Check if an additional connection from the given peer is allowed.
267  *
268  * @param peer connection to check
269  * @return GNUNET_OK if the connection is allowed
270  */
271 static int
272 is_connection_allowed (struct Peer *peer)
273 {
274   if (0 ==
275       memcmp (&my_identity, &peer->pid, sizeof (struct GNUNET_PeerIdentity)))
276     return GNUNET_SYSERR;       /* disallow connections to self */
277   if (peer->is_friend)
278     return GNUNET_OK;
279   if (GNUNET_YES == friends_only)
280   {
281     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
282                 "Determined that `%s' is not allowed to connect (not a friend)\n",
283                 GNUNET_i2s (&peer->pid));
284     return GNUNET_SYSERR;
285   }
286   if (friend_count >= minimum_friend_count)
287     return GNUNET_OK;
288   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
289               "Determined that `%s' is not allowed to connect (not enough connected friends)\n",
290               GNUNET_i2s (&peer->pid));
291   return GNUNET_SYSERR;
292 }
293
294
295 /**
296  * Free all resources associated with the given peer.
297  *
298  * @param cls closure (not used)
299  * @param pid identity of the peer
300  * @param value peer to free
301  * @return GNUNET_YES (always: continue to iterate)
302  */
303 static int
304 free_peer (void *cls, const GNUNET_HashCode * pid, void *value)
305 {
306   struct Peer *pos = value;
307
308   GNUNET_break (GNUNET_NO == pos->is_connected);
309   GNUNET_break (GNUNET_OK ==
310                 GNUNET_CONTAINER_multihashmap_remove (peers, pid, pos));
311   if (pos->hello_req != NULL)
312     GNUNET_CORE_notify_transmit_ready_cancel (pos->hello_req);
313   if (pos->hello_delay_task != GNUNET_SCHEDULER_NO_TASK)
314     GNUNET_SCHEDULER_cancel (pos->hello_delay_task);
315   if (pos->greylist_clean_task != GNUNET_SCHEDULER_NO_TASK)
316     GNUNET_SCHEDULER_cancel (pos->greylist_clean_task);
317   GNUNET_free_non_null (pos->hello);
318   if (pos->filter != NULL)
319     GNUNET_CONTAINER_bloomfilter_free (pos->filter);
320   GNUNET_free (pos);
321   return GNUNET_YES;
322 }
323
324
325 /**
326  * Discard peer entries for greylisted peers
327  * where the greylisting has expired.
328  *
329  * @param cls 'struct Peer' to greylist
330  * @param tc scheduler context
331  */
332 static void
333 remove_from_greylist (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
334
335
336 /**
337  * Try to connect to the specified peer.
338  *
339  * @param pos peer to connect to
340  */
341 static void
342 attempt_connect (struct Peer *pos)
343 {
344   struct GNUNET_TIME_Relative rem;
345
346   if ((connection_count >= target_connection_count) &&
347       (friend_count >= minimum_friend_count))
348     return;
349   if (GNUNET_YES == pos->is_connected)
350     return;
351   if (GNUNET_OK != is_connection_allowed (pos))
352     return;
353   if (GNUNET_TIME_absolute_get_remaining (pos->greylisted_until).rel_value > 0)
354     return;
355   if (GNUNET_YES == pos->is_friend)
356     rem = GREYLIST_AFTER_ATTEMPT_FRIEND;
357   else
358     rem = GREYLIST_AFTER_ATTEMPT;
359   rem = GNUNET_TIME_relative_multiply (rem, connection_count);
360   rem = GNUNET_TIME_relative_divide (rem, target_connection_count);
361   if (pos->connect_attempts > 30)
362     pos->connect_attempts = 30;
363   rem = GNUNET_TIME_relative_multiply (rem, 1 << (++pos->connect_attempts));
364   rem = GNUNET_TIME_relative_max (rem, GREYLIST_AFTER_ATTEMPT_MIN);
365   rem = GNUNET_TIME_relative_min (rem, GREYLIST_AFTER_ATTEMPT_MAX);
366   pos->greylisted_until = GNUNET_TIME_relative_to_absolute (rem);
367   if (pos->greylist_clean_task != GNUNET_SCHEDULER_NO_TASK)
368     GNUNET_SCHEDULER_cancel (pos->greylist_clean_task);
369   pos->greylist_clean_task =
370       GNUNET_SCHEDULER_add_delayed (rem, &remove_from_greylist, pos);
371   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking  to connect to `%s'\n",
372               GNUNET_i2s (&pos->pid));
373   GNUNET_STATISTICS_update (stats,
374                             gettext_noop
375                             ("# connect requests issued to transport"), 1,
376                             GNUNET_NO);
377   GNUNET_TRANSPORT_try_connect (transport, &pos->pid);
378 }
379
380
381 /**
382  * Discard peer entries for greylisted peers
383  * where the greylisting has expired.
384  *
385  * @param cls 'struct Peer' to greylist
386  * @param tc scheduler context
387  */
388 static void
389 remove_from_greylist (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
390 {
391   struct Peer *pos = cls;
392   struct GNUNET_TIME_Relative rem;
393
394   pos->greylist_clean_task = GNUNET_SCHEDULER_NO_TASK;
395   rem = GNUNET_TIME_absolute_get_remaining (pos->greylisted_until);
396   if (rem.rel_value == 0)
397   {
398     attempt_connect (pos);
399   }
400   else
401   {
402     pos->greylist_clean_task =
403         GNUNET_SCHEDULER_add_delayed (rem, &remove_from_greylist, pos);
404   }
405   if ((GNUNET_NO == pos->is_friend) && (GNUNET_NO == pos->is_connected) &&
406       (NULL == pos->hello))
407   {
408     free_peer (NULL, &pos->pid.hashPubKey, pos);
409     return;
410   }
411 }
412
413
414 /**
415  * Create a new entry in the peer list.
416  *
417  * @param peer identity of the new entry
418  * @param hello hello message, can be NULL
419  * @param is_friend is the new entry for a friend?
420  * @return the new entry
421  */
422 static struct Peer *
423 make_peer (const struct GNUNET_PeerIdentity *peer,
424            const struct GNUNET_HELLO_Message *hello, int is_friend)
425 {
426   struct Peer *ret;
427
428   ret = GNUNET_malloc (sizeof (struct Peer));
429   ret->pid = *peer;
430   ret->is_friend = is_friend;
431   if (hello != NULL)
432   {
433     ret->hello = GNUNET_malloc (GNUNET_HELLO_size (hello));
434     memcpy (ret->hello, hello, GNUNET_HELLO_size (hello));
435   }
436   GNUNET_break (GNUNET_OK ==
437                 GNUNET_CONTAINER_multihashmap_put (peers, &peer->hashPubKey,
438                                                    ret,
439                                                    GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
440   return ret;
441 }
442
443
444 /**
445  * Setup bloom filter for the given peer entry.
446  *
447  * @param peer entry to initialize
448  */
449 static void
450 setup_filter (struct Peer *peer)
451 {
452   /* 2^{-5} chance of not sending a HELLO to a peer is
453    * acceptably small (if the filter is 50% full);
454    * 64 bytes of memory are small compared to the rest
455    * of the data structure and would only really become
456    * "useless" once a HELLO has been passed on to ~100
457    * other peers, which is likely more than enough in
458    * any case; hence 64, 5 as bloomfilter parameters. */
459   peer->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, 64, 5);
460   peer->filter_expiration =
461       GNUNET_TIME_relative_to_absolute
462       (HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY);
463   /* never send a peer its own HELLO */
464   GNUNET_CONTAINER_bloomfilter_add (peer->filter, &peer->pid.hashPubKey);
465 }
466
467
468 /**
469  * Function to fill send buffer with HELLO.
470  *
471  * @param cls 'struct Peer' of the target peer
472  * @param size number of bytes available in buf
473  * @param buf where the callee should write the message
474  * @return number of bytes written to buf
475  */
476 static size_t
477 hello_advertising_ready (void *cls, size_t size, void *buf);
478
479
480 /**
481  * Closure for 'find_advertisable_hello'.
482  */
483 struct FindAdvHelloContext
484 {
485
486   /**
487    * Peer we want to advertise to.
488    */
489   struct Peer *peer;
490
491   /**
492    * Where to store the result (peer selected for advertising).
493    */
494   struct Peer *result;
495
496   /**
497    * Maximum HELLO size we can use right now.
498    */
499   size_t max_size;
500
501   struct GNUNET_TIME_Relative next_adv;
502 };
503
504
505 /**
506  * Find a peer that would be reasonable for advertising.
507  *
508  * @param cls closure
509  * @param pid identity of a peer
510  * @param value 'struct Peer*' for the peer we are considering
511  * @return GNUNET_YES (continue iteration)
512  */
513 static int
514 find_advertisable_hello (void *cls, const GNUNET_HashCode * pid, void *value)
515 {
516   struct FindAdvHelloContext *fah = cls;
517   struct Peer *pos = value;
518   struct GNUNET_TIME_Relative rst_time;
519   size_t hs;
520
521   if (pos == fah->peer)
522     return GNUNET_YES;
523   if (pos->hello == NULL)
524     return GNUNET_YES;
525   rst_time = GNUNET_TIME_absolute_get_remaining (pos->filter_expiration);
526   if (0 == rst_time.rel_value)
527   {
528     /* time to discard... */
529     GNUNET_CONTAINER_bloomfilter_free (pos->filter);
530     setup_filter (pos);
531   }
532   fah->next_adv = GNUNET_TIME_relative_min (rst_time, fah->next_adv);
533   hs = GNUNET_HELLO_size (pos->hello);
534   if (hs > fah->max_size)
535     return GNUNET_YES;
536   if (GNUNET_NO ==
537       GNUNET_CONTAINER_bloomfilter_test (pos->filter,
538                                          &fah->peer->pid.hashPubKey))
539     fah->result = pos;
540   return GNUNET_YES;
541 }
542
543
544 /**
545  * Calculate when we would like to send the next HELLO to this
546  * peer and ask for it.
547  *
548  * @param cls for which peer to schedule the HELLO
549  * @param tc task context
550  */
551 static void
552 schedule_next_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
553 {
554   struct Peer *pl = cls;
555   struct FindAdvHelloContext fah;
556   size_t next_want;
557   struct GNUNET_TIME_Relative delay;
558
559   pl->hello_delay_task = GNUNET_SCHEDULER_NO_TASK;
560   GNUNET_assert (GNUNET_YES == pl->is_connected);
561   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
562     return;                     /* we're out of here */
563   if (pl->hello_req != NULL)
564     return;                     /* did not finish sending the previous one */
565   /* find applicable HELLOs */
566   fah.peer = pl;
567   fah.result = NULL;
568   fah.max_size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1;
569   fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL;
570   GNUNET_CONTAINER_multihashmap_iterate (peers, &find_advertisable_hello, &fah);
571   pl->hello_delay_task =
572       GNUNET_SCHEDULER_add_delayed (fah.next_adv, &schedule_next_hello, pl);
573   if (fah.result == NULL)
574     return;
575   next_want = GNUNET_HELLO_size (fah.result->hello);
576   delay = GNUNET_TIME_absolute_get_remaining (pl->next_hello_allowed);
577   if (delay.rel_value == 0)
578   {
579     /* now! */
580     pl->hello_req =
581         GNUNET_CORE_notify_transmit_ready (handle, GNUNET_YES, 0,
582                                            GNUNET_CONSTANTS_SERVICE_TIMEOUT,
583                                            &pl->pid, next_want,
584                                            &hello_advertising_ready, pl);
585   }
586 }
587
588
589 /**
590  * Cancel existing requests for sending HELLOs to this peer
591  * and recalculate when we should send HELLOs to it based
592  * on our current state (something changed!).
593  *
594  * @param cls closure, 'struct Peer' to skip, or NULL
595  * @param pid identity of a peer
596  * @param value 'struct Peer*' for the peer
597  * @return GNUNET_YES (always)
598  */
599 static int
600 reschedule_hellos (void *cls, const GNUNET_HashCode * pid, void *value)
601 {
602   struct Peer *peer = value;
603   struct Peer *skip = cls;
604
605   if (skip == peer)
606     return GNUNET_YES;
607   if (!peer->is_connected)
608     return GNUNET_YES;
609   if (peer->hello_req != NULL)
610   {
611     GNUNET_CORE_notify_transmit_ready_cancel (peer->hello_req);
612     peer->hello_req = NULL;
613   }
614   if (peer->hello_delay_task != GNUNET_SCHEDULER_NO_TASK)
615   {
616     GNUNET_SCHEDULER_cancel (peer->hello_delay_task);
617     peer->hello_delay_task = GNUNET_SCHEDULER_NO_TASK;
618   }
619   peer->hello_delay_task =
620       GNUNET_SCHEDULER_add_now (&schedule_next_hello, peer);
621   return GNUNET_YES;
622 }
623
624
625 /**
626  * Method called whenever a peer connects.
627  *
628  * @param cls closure
629  * @param peer peer identity this notification is about
630  * @param atsi performance data
631  * @param atsi_count number of records in 'atsi'
632  */
633 static void
634 connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
635                 const struct GNUNET_ATS_Information *atsi,
636                 unsigned int atsi_count)
637 {
638   struct Peer *pos;
639
640   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
641               "Core told us that we are connecting to `%s'\n",
642               GNUNET_i2s (peer));
643   if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
644     return;
645
646   connection_count++;
647   GNUNET_STATISTICS_set (stats, gettext_noop ("# peers connected"),
648                          connection_count, GNUNET_NO);
649   pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
650   if (NULL == pos)
651   {
652     pos = make_peer (peer, NULL, GNUNET_NO);
653     GNUNET_break (GNUNET_OK == is_connection_allowed (pos));
654   }
655   else
656   {
657     GNUNET_assert (GNUNET_NO == pos->is_connected);
658     pos->greylisted_until.abs_value = 0;        /* remove greylisting */
659   }
660   pos->is_connected = GNUNET_YES;
661   pos->connect_attempts = 0;    /* re-set back-off factor */
662   if (pos->is_friend)
663   {
664     if ((friend_count == minimum_friend_count - 1) &&
665         (GNUNET_YES != friends_only))
666       whitelist_peers ();
667     friend_count++;
668     GNUNET_STATISTICS_set (stats, gettext_noop ("# friends connected"),
669                            friend_count, GNUNET_NO);
670   }
671   reschedule_hellos (NULL, &peer->hashPubKey, pos);
672 }
673
674
675 /**
676  * Try to add more peers to our connection set.
677  *
678  * @param cls closure, not used
679  * @param pid identity of a peer
680  * @param value 'struct Peer*' for the peer
681  * @return GNUNET_YES (continue to iterate)
682  */
683 static int
684 try_add_peers (void *cls, const GNUNET_HashCode * pid, void *value)
685 {
686   struct Peer *pos = value;
687
688   attempt_connect (pos);
689   return GNUNET_YES;
690 }
691
692
693 /**
694  * Last task run during shutdown.  Disconnects us from
695  * the transport and core.
696  *
697  * @param cls unused, NULL
698  * @param tc scheduler context
699  */
700 static void
701 add_peer_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
702 {
703   add_task = GNUNET_SCHEDULER_NO_TASK;
704
705   GNUNET_CONTAINER_multihashmap_iterate (peers, &try_add_peers, NULL);
706 }
707
708 /**
709  * Method called whenever a peer disconnects.
710  *
711  * @param cls closure
712  * @param peer peer identity this notification is about
713  */
714 static void
715 disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
716 {
717   struct Peer *pos;
718
719   if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
720     return;
721   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
722               "Core told us that we disconnected from `%s'\n",
723               GNUNET_i2s (peer));
724   pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
725   if (NULL == pos)
726   {
727     GNUNET_break (0);
728     return;
729   }
730   if (pos->is_connected != GNUNET_YES)
731   {
732     GNUNET_break (0);
733     return;
734   }
735   pos->is_connected = GNUNET_NO;
736   connection_count--;
737   if (NULL != pos->hello_req)
738   {
739     GNUNET_CORE_notify_transmit_ready_cancel (pos->hello_req);
740     pos->hello_req = NULL;
741   }
742   if (GNUNET_SCHEDULER_NO_TASK != pos->hello_delay_task)
743   {
744     GNUNET_SCHEDULER_cancel (pos->hello_delay_task);
745     pos->hello_delay_task = GNUNET_SCHEDULER_NO_TASK;
746   }
747   GNUNET_STATISTICS_set (stats, gettext_noop ("# peers connected"),
748                          connection_count, GNUNET_NO);
749   if (pos->is_friend)
750   {
751     friend_count--;
752     GNUNET_STATISTICS_set (stats, gettext_noop ("# friends connected"),
753                            friend_count, GNUNET_NO);
754   }
755   if (((connection_count < target_connection_count) ||
756        (friend_count < minimum_friend_count)) &&
757       (GNUNET_SCHEDULER_NO_TASK == add_task))
758     add_task = GNUNET_SCHEDULER_add_now (&add_peer_task, NULL);
759   if ((friend_count < minimum_friend_count) && (blacklist == NULL))
760     blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL);
761 }
762
763
764 /**
765  * Iterator called on each address.
766  *
767  * @param cls flag that we will set if we see any addresses
768  * @param address the address of the peer
769  * @param expiration when will the given address expire
770  * @return GNUNET_SYSERR always, to terminate iteration
771  */
772 static int
773 address_iterator (void *cls, const struct GNUNET_HELLO_Address *address,
774                   struct GNUNET_TIME_Absolute expiration)
775 {
776   int *flag = cls;
777
778   *flag = GNUNET_YES;
779   return GNUNET_SYSERR;
780 }
781
782
783 /**
784  * We've gotten a HELLO from another peer.  Consider it for
785  * advertising.
786  *
787  * @param hello the HELLO we got
788  */
789 static void
790 consider_for_advertising (const struct GNUNET_HELLO_Message *hello)
791 {
792   int have_address;
793   struct GNUNET_PeerIdentity pid;
794   struct GNUNET_TIME_Absolute dt;
795   struct GNUNET_HELLO_Message *nh;
796   struct Peer *peer;
797   uint16_t size;
798
799   if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
800   {
801     GNUNET_break (0);
802     return;
803   }
804   if (0 == memcmp (&pid, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
805     return;                     /* that's me! */
806   have_address = GNUNET_NO;
807   GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &address_iterator,
808                                   &have_address);
809   if (GNUNET_NO == have_address)
810     return;                     /* no point in advertising this one... */
811   peer = GNUNET_CONTAINER_multihashmap_get (peers, &pid.hashPubKey);
812   if (NULL == peer)
813   {
814     peer = make_peer (&pid, hello, GNUNET_NO);
815   }
816   else if (peer->hello != NULL)
817   {
818     dt = GNUNET_HELLO_equals (peer->hello, hello, GNUNET_TIME_absolute_get ());
819     if (dt.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value)
820       return;                   /* nothing new here */
821   }
822   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
823               "Found `%s' from peer `%s' for advertising\n", "HELLO",
824               GNUNET_i2s (&pid));
825   if (peer->hello != NULL)
826   {
827     nh = GNUNET_HELLO_merge (peer->hello, hello);
828     GNUNET_free (peer->hello);
829     peer->hello = nh;
830   }
831   else
832   {
833     size = GNUNET_HELLO_size (hello);
834     peer->hello = GNUNET_malloc (size);
835     memcpy (peer->hello, hello, size);
836   }
837   if (peer->filter != NULL)
838     GNUNET_CONTAINER_bloomfilter_free (peer->filter);
839   setup_filter (peer);
840   /* since we have a new HELLO to pick from, re-schedule all
841    * HELLO requests that are not bound by the HELLO send rate! */
842   GNUNET_CONTAINER_multihashmap_iterate (peers, &reschedule_hellos, peer);
843 }
844
845
846 /**
847  * PEERINFO calls this function to let us know about a possible peer
848  * that we might want to connect to.
849  *
850  * @param cls closure (not used)
851  * @param peer potential peer to connect to
852  * @param hello HELLO for this peer (or NULL)
853  * @param err_msg NULL if successful, otherwise contains error message
854  */
855 static void
856 process_peer (void *cls, const struct GNUNET_PeerIdentity *peer,
857               const struct GNUNET_HELLO_Message *hello, const char *err_msg)
858 {
859   struct Peer *pos;
860
861   if (err_msg != NULL)
862   {
863     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
864                 _("Error in communication with PEERINFO service: %s\n"),
865                 err_msg);
866     GNUNET_PEERINFO_notify_cancel (peerinfo_notify);
867     peerinfo_notify = GNUNET_PEERINFO_notify (cfg, &process_peer, NULL);
868     return;
869   }
870   GNUNET_assert (peer != NULL);
871   if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
872     return;                     /* that's me! */
873   if (hello == NULL)
874   {
875     /* free existing HELLO, if any */
876     pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
877     if (NULL != pos)
878     {
879       GNUNET_free_non_null (pos->hello);
880       pos->hello = NULL;
881       if (pos->filter != NULL)
882       {
883         GNUNET_CONTAINER_bloomfilter_free (pos->filter);
884         pos->filter = NULL;
885       }
886       if ((GNUNET_NO == pos->is_connected) && (GNUNET_NO == pos->is_friend) &&
887           (0 ==
888            GNUNET_TIME_absolute_get_remaining (pos->
889                                                greylisted_until).rel_value))
890         free_peer (NULL, &pos->pid.hashPubKey, pos);
891     }
892     return;
893   }
894   consider_for_advertising (hello);
895   pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
896   if (pos == NULL)
897     pos = make_peer (peer, hello, GNUNET_NO);
898   GNUNET_assert (NULL != pos);
899   if (GNUNET_YES == pos->is_connected)
900   {
901     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Already connected to peer `%s'\n",
902                 GNUNET_i2s (peer));
903     return;
904   }
905   if (GNUNET_TIME_absolute_get_remaining (pos->greylisted_until).rel_value > 0)
906   {
907     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Already tried peer `%s' recently\n",
908                 GNUNET_i2s (peer));
909     return;                     /* peer still greylisted */
910   }
911   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Considering connecting to peer `%s'\n",
912               GNUNET_i2s (peer));
913   attempt_connect (pos);
914 }
915
916
917 /**
918  * Function called after GNUNET_CORE_connect has succeeded
919  * (or failed for good).
920  *
921  * @param cls closure
922  * @param server handle to the server, NULL if we failed
923  * @param my_id ID of this peer, NULL if we failed
924  */
925 static void
926 core_init (void *cls, struct GNUNET_CORE_Handle *server,
927            const struct GNUNET_PeerIdentity *my_id)
928 {
929   if (server == NULL)
930   {
931     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
932                 _
933                 ("Failed to connect to core service, can not manage topology!\n"));
934     GNUNET_SCHEDULER_shutdown ();
935     return;
936   }
937   handle = server;
938   my_identity = *my_id;
939   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s (my_id));
940   peerinfo_notify = GNUNET_PEERINFO_notify (cfg, &process_peer, NULL);
941 }
942
943
944 /**
945  * Read the friends file.
946  */
947 static void
948 read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
949 {
950   char *fn;
951   char *data;
952   size_t pos;
953   struct GNUNET_PeerIdentity pid;
954   uint64_t fsize;
955   struct GNUNET_CRYPTO_HashAsciiEncoded enc;
956   unsigned int entries_found;
957   struct Peer *fl;
958
959   if (GNUNET_OK !=
960       GNUNET_CONFIGURATION_get_value_filename (cfg, "TOPOLOGY", "FRIENDS", &fn))
961   {
962     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
963                 _("Option `%s' in section `%s' not specified!\n"), "FRIENDS",
964                 "TOPOLOGY");
965     return;
966   }
967   if (GNUNET_OK != GNUNET_DISK_file_test (fn))
968     GNUNET_DISK_fn_write (fn, NULL, 0,
969                           GNUNET_DISK_PERM_USER_READ |
970                           GNUNET_DISK_PERM_USER_WRITE);
971   if (GNUNET_OK != GNUNET_DISK_file_size (fn,
972       &fsize, GNUNET_NO, GNUNET_YES))
973   {
974     if ((friends_only) || (minimum_friend_count > 0))
975       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
976                   _("Could not read friends list `%s'\n"), fn);
977     GNUNET_free (fn);
978     return;
979   }
980   if (fsize == 0)
981   {
982     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Friends file `%s' is empty.\n"),
983                 fn);
984     GNUNET_free (fn);
985     return;
986   }
987   data = GNUNET_malloc_large (fsize);
988   if (data == NULL)
989   {
990     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
991                 _("Failed to read friends list from `%s': out of memory\n"),
992                 fn);
993     GNUNET_free (fn);
994     return;
995   }
996   if (fsize != GNUNET_DISK_fn_read (fn, data, fsize))
997   {
998     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
999                 _("Failed to read friends list from `%s'\n"), fn);
1000     GNUNET_free (fn);
1001     GNUNET_free (data);
1002     return;
1003   }
1004   entries_found = 0;
1005   pos = 0;
1006   while ((pos < fsize) && isspace ((unsigned char) data[pos]))
1007     pos++;
1008   while ((fsize >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) &&
1009          (pos <=
1010           fsize - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)))
1011   {
1012     memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
1013     if (!isspace
1014         ((unsigned char)
1015          enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1]))
1016     {
1017       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1018                   _
1019                   ("Syntax error in topology specification at offset %llu, skipping bytes.\n"),
1020                   (unsigned long long) pos);
1021       pos++;
1022       while ((pos < fsize) && (!isspace ((unsigned char) data[pos])))
1023         pos++;
1024       continue;
1025     }
1026     enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
1027     if (GNUNET_OK !=
1028         GNUNET_CRYPTO_hash_from_string ((char *) &enc, &pid.hashPubKey))
1029     {
1030       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1031                   _
1032                   ("Syntax error in topology specification at offset %llu, skipping bytes `%s'.\n"),
1033                   (unsigned long long) pos, &enc);
1034     }
1035     else
1036     {
1037       if (0 != memcmp (&pid, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
1038       {
1039         entries_found++;
1040         fl = make_peer (&pid, NULL, GNUNET_YES);
1041         GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1042                     _("Found friend `%s' in configuration\n"),
1043                     GNUNET_i2s (&fl->pid));
1044       }
1045       else
1046       {
1047         GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1048                     _("Found myself `%s' in friend list (useless, ignored)\n"),
1049                     GNUNET_i2s (&pid));
1050       }
1051     }
1052     pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded);
1053     while ((pos < fsize) && isspace ((unsigned char) data[pos]))
1054       pos++;
1055   }
1056   GNUNET_free (data);
1057   GNUNET_free (fn);
1058   GNUNET_STATISTICS_update (stats, gettext_noop ("# friends in configuration"),
1059                             entries_found, GNUNET_NO);
1060   if ((minimum_friend_count > entries_found) && (friends_only == GNUNET_NO))
1061   {
1062     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1063                 _
1064                 ("Fewer friends specified than required by minimum friend count. Will only connect to friends.\n"));
1065   }
1066   if ((minimum_friend_count > target_connection_count) &&
1067       (friends_only == GNUNET_NO))
1068   {
1069     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1070                 _
1071                 ("More friendly connections required than target total number of connections.\n"));
1072   }
1073 }
1074
1075
1076 /**
1077  * This function is called whenever an encrypted HELLO message is
1078  * received.
1079  *
1080  * @param cls closure
1081  * @param other the other peer involved (sender or receiver, NULL
1082  *        for loopback messages where we are both sender and receiver)
1083  * @param message the actual HELLO message
1084  * @param atsi performance data
1085  * @param atsi_count number of records in 'atsi'
1086  * @return GNUNET_OK to keep the connection open,
1087  *         GNUNET_SYSERR to close it (signal serious error)
1088  */
1089 static int
1090 handle_encrypted_hello (void *cls, const struct GNUNET_PeerIdentity *other,
1091                         const struct GNUNET_MessageHeader *message,
1092                         const struct GNUNET_ATS_Information *atsi,
1093                         unsigned int atsi_count)
1094 {
1095   struct Peer *peer;
1096   struct GNUNET_PeerIdentity pid;
1097
1098   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received encrypted `%s' from peer `%s'",
1099               "HELLO", GNUNET_i2s (other));
1100   if (GNUNET_OK !=
1101       GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) message, &pid))
1102   {
1103     GNUNET_break_op (0);
1104     return GNUNET_SYSERR;
1105   }
1106   GNUNET_STATISTICS_update (stats, gettext_noop ("# HELLO messages received"),
1107                             1, GNUNET_NO);
1108   peer = GNUNET_CONTAINER_multihashmap_get (peers, &pid.hashPubKey);
1109   if (NULL == peer)
1110   {
1111     if ((GNUNET_YES == friends_only) || (friend_count < minimum_friend_count))
1112       return GNUNET_OK;
1113   }
1114   else
1115   {
1116     if ((GNUNET_YES != peer->is_friend) && (GNUNET_YES == friends_only))
1117       return GNUNET_OK;
1118     if ((GNUNET_YES != peer->is_friend) &&
1119         (friend_count < minimum_friend_count))
1120       return GNUNET_OK;
1121   }
1122   if (transport != NULL)
1123     GNUNET_TRANSPORT_offer_hello (transport, message, NULL, NULL);
1124   return GNUNET_OK;
1125 }
1126
1127
1128 /**
1129  * Function to fill send buffer with HELLO.
1130  *
1131  * @param cls 'struct Peer' of the target peer
1132  * @param size number of bytes available in buf
1133  * @param buf where the callee should write the message
1134  * @return number of bytes written to buf
1135  */
1136 static size_t
1137 hello_advertising_ready (void *cls, size_t size, void *buf)
1138 {
1139   struct Peer *pl = cls;
1140   struct FindAdvHelloContext fah;
1141   size_t want;
1142
1143   pl->hello_req = NULL;
1144   GNUNET_assert (GNUNET_YES == pl->is_connected);
1145   /* find applicable HELLOs */
1146   fah.peer = pl;
1147   fah.result = NULL;
1148   fah.max_size = size;
1149   fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL;
1150   GNUNET_CONTAINER_multihashmap_iterate (peers, &find_advertisable_hello, &fah);
1151   want = 0;
1152   if (fah.result != NULL)
1153   {
1154     want = GNUNET_HELLO_size (fah.result->hello);
1155     GNUNET_assert (want <= size);
1156     memcpy (buf, fah.result->hello, want);
1157     GNUNET_CONTAINER_bloomfilter_add (fah.result->filter, &pl->pid.hashPubKey);
1158     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' with %u bytes", "HELLO",
1159                 (unsigned int) want);
1160     GNUNET_STATISTICS_update (stats,
1161                               gettext_noop ("# HELLO messages gossipped"), 1,
1162                               GNUNET_NO);
1163   }
1164
1165   if (pl->hello_delay_task != GNUNET_SCHEDULER_NO_TASK)
1166     GNUNET_SCHEDULER_cancel (pl->hello_delay_task);
1167   pl->next_hello_allowed =
1168       GNUNET_TIME_relative_to_absolute (HELLO_ADVERTISEMENT_MIN_FREQUENCY);
1169   pl->hello_delay_task = GNUNET_SCHEDULER_add_now (&schedule_next_hello, pl);
1170   return want;
1171 }
1172
1173
1174 /**
1175  * Last task run during shutdown.  Disconnects us from
1176  * the transport and core.
1177  *
1178  * @param cls unused, NULL
1179  * @param tc scheduler context
1180  */
1181 static void
1182 cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1183 {
1184   if (NULL != peerinfo_notify)
1185   {
1186     GNUNET_PEERINFO_notify_cancel (peerinfo_notify);
1187     peerinfo_notify = NULL;
1188   }
1189   GNUNET_TRANSPORT_disconnect (transport);
1190   transport = NULL;
1191   if (handle != NULL)
1192   {
1193     GNUNET_CORE_disconnect (handle);
1194     handle = NULL;
1195   }
1196   whitelist_peers ();
1197   if (GNUNET_SCHEDULER_NO_TASK != add_task)
1198   {
1199     GNUNET_SCHEDULER_cancel (add_task);
1200     add_task = GNUNET_SCHEDULER_NO_TASK;
1201   }
1202   GNUNET_CONTAINER_multihashmap_iterate (peers, &free_peer, NULL);
1203   GNUNET_CONTAINER_multihashmap_destroy (peers);
1204   peers = NULL;
1205   if (stats != NULL)
1206   {
1207     GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
1208     stats = NULL;
1209   }
1210 }
1211
1212
1213 /**
1214  * Main function that will be run.
1215  *
1216  * @param cls closure
1217  * @param args remaining command-line arguments
1218  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1219  * @param c configuration
1220  */
1221 static void
1222 run (void *cls, char *const *args, const char *cfgfile,
1223      const struct GNUNET_CONFIGURATION_Handle *c)
1224 {
1225   static struct GNUNET_CORE_MessageHandler handlers[] = {
1226     {&handle_encrypted_hello, GNUNET_MESSAGE_TYPE_HELLO, 0},
1227     {NULL, 0, 0}
1228   };
1229   unsigned long long opt;
1230
1231   cfg = c;
1232   stats = GNUNET_STATISTICS_create ("topology", cfg);
1233   autoconnect =
1234       GNUNET_CONFIGURATION_get_value_yesno (cfg, "TOPOLOGY", "AUTOCONNECT");
1235   friends_only =
1236       GNUNET_CONFIGURATION_get_value_yesno (cfg, "TOPOLOGY", "FRIENDS-ONLY");
1237   if (GNUNET_OK !=
1238       GNUNET_CONFIGURATION_get_value_number (cfg, "TOPOLOGY", "MINIMUM-FRIENDS",
1239                                              &opt))
1240     opt = 0;
1241   minimum_friend_count = (unsigned int) opt;
1242   if (GNUNET_OK !=
1243       GNUNET_CONFIGURATION_get_value_number (cfg, "TOPOLOGY",
1244                                              "TARGET-CONNECTION-COUNT", &opt))
1245     opt = 16;
1246   target_connection_count = (unsigned int) opt;
1247   peers = GNUNET_CONTAINER_multihashmap_create (target_connection_count * 2);
1248
1249   if ((friends_only == GNUNET_YES) || (minimum_friend_count > 0))
1250     read_friends_file (cfg);
1251   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1252               "Topology would like %u connections with at least %u friends (%s)\n",
1253               target_connection_count, minimum_friend_count,
1254               autoconnect ? "autoconnect enabled" : "autoconnect disabled");
1255   if ((friend_count < minimum_friend_count) && (blacklist == NULL))
1256     blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL);
1257   transport = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, NULL, NULL);
1258   handle =
1259       GNUNET_CORE_connect (cfg, 1, NULL, &core_init, &connect_notify,
1260                            &disconnect_notify, NULL, GNUNET_NO, NULL, GNUNET_NO,
1261                            handlers);
1262   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task,
1263                                 NULL);
1264   if (NULL == transport)
1265   {
1266     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1267                 _("Failed to connect to `%s' service.\n"), "transport");
1268     GNUNET_SCHEDULER_shutdown ();
1269     return;
1270   }
1271   if (NULL == handle)
1272   {
1273     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1274                 _("Failed to connect to `%s' service.\n"), "core");
1275     GNUNET_SCHEDULER_shutdown ();
1276     return;
1277   }
1278 }
1279
1280
1281 /**
1282  * The main function for the topology daemon.
1283  *
1284  * @param argc number of arguments from the command line
1285  * @param argv command line arguments
1286  * @return 0 ok, 1 on error
1287  */
1288 int
1289 main (int argc, char *const *argv)
1290 {
1291   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1292     GNUNET_GETOPT_OPTION_END
1293   };
1294   int ret;
1295
1296   ret =
1297       (GNUNET_OK ==
1298        GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-topology",
1299                            _
1300                            ("GNUnet topology control (maintaining P2P mesh and F2F constraints)"),
1301                            options, &run, NULL)) ? 0 : 1;
1302   return ret;
1303 }
1304
1305 /* end of gnunet-daemon-topology.c */