2 This file is part of GNUnet.
3 (C) 2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
23 #include "gnunet_util_lib.h"
25 #include "gnunet_core_service.h"
26 #include "gnunet_statistics_service.h"
28 #include "mesh_protocol.h"
30 #include "gnunet-service-mesh_peer.h"
31 #include "gnunet-service-mesh_dht.h"
32 #include "gnunet-service-mesh_connection.h"
33 #include "gnunet-service-mesh_tunnel.h"
34 #include "mesh_path.h"
36 #define LOG(level, ...) GNUNET_log_from (level,"mesh-p2p",__VA_ARGS__)
38 /******************************************************************************/
39 /******************************** STRUCTS **********************************/
40 /******************************************************************************/
43 * Struct containing info about a queued transmission to this peer
50 struct MeshPeerQueue *next;
55 struct MeshPeerQueue *prev;
58 * Peer this transmission is directed to.
60 struct MeshPeer *peer;
63 * Connection this message belongs to.
65 struct MeshConnection *c;
73 * Pointer to info stucture used as cls.
88 * Set when this message starts waiting for CORE.
90 struct GNUNET_TIME_Absolute start_waiting;
93 * Function to call on sending.
98 * Closure for callback.
104 * Struct containing all information regarding a given peer
114 * Last time we heard from this peer
116 struct GNUNET_TIME_Absolute last_contact;
119 * Paths to reach the peer, ordered by ascending hop count
121 struct MeshPeerPath *path_head;
124 * Paths to reach the peer, ordered by ascending hop count
126 struct MeshPeerPath *path_tail;
129 * Handle to stop the DHT search for paths to this peer
131 struct GMD_search_handle *search_h;
134 * Tunnel to this peer, if any.
136 struct MeshTunnel3 *tunnel;
139 * Connections that go through this peer, indexed by tid;
141 struct GNUNET_CONTAINER_MultiHashMap *connections;
144 * Handle for queued transmissions
146 struct GNUNET_CORE_TransmitHandle *core_transmit;
149 * Transmission queue to core DLL head
151 struct MeshPeerQueue *queue_head;
154 * Transmission queue to core DLL tail
156 struct MeshPeerQueue *queue_tail;
159 * How many messages are in the queue to this peer.
161 unsigned int queue_n;
166 const struct GNUNET_HELLO_Message* hello;
170 /******************************************************************************/
171 /******************************* GLOBALS ***********************************/
172 /******************************************************************************/
175 * Global handle to the statistics service.
177 extern struct GNUNET_STATISTICS_Handle *stats;
180 * Local peer own ID (full value).
182 extern struct GNUNET_PeerIdentity my_full_id;
185 * Local peer own ID (short)
187 extern GNUNET_PEER_Id myid;
190 * Peers known, indexed by PeerIdentity (MeshPeer).
192 static struct GNUNET_CONTAINER_MultiPeerMap *peers;
195 * How many peers do we want to remember?
197 static unsigned long long max_peers;
200 * Percentage of messages that will be dropped (for test purposes only).
202 static unsigned long long drop_percent;
205 * Handle to communicate with core.
207 static struct GNUNET_CORE_Handle *core_handle;
210 /******************************************************************************/
211 /***************************** CORE CALLBACKS *********************************/
212 /******************************************************************************/
216 * Iterator to notify all connections of a broken link. Mark connections
217 * to destroy after all traffic has been sent.
219 * @param cls Closure (peer disconnected).
220 * @param key Current key code (peer id).
221 * @param value Value in the hash map (connection).
223 * @return #GNUNET_YES to continue to iterate.
226 notify_broken (void *cls,
227 const struct GNUNET_HashCode *key,
230 struct MeshPeer *peer = cls;
231 struct MeshConnection *c = value;
233 LOG (GNUNET_ERROR_TYPE_DEBUG, " notifying %s due to %s\n",
234 GMC_2s (c), GMP_2s (peer));
235 GMC_notify_broken (c, peer);
242 * Remove the direct path to the peer.
244 * @param peer Peer to remove the direct path from.
247 static struct MeshPeerPath *
248 pop_direct_path (struct MeshPeer *peer)
250 struct MeshPeerPath *iter;
252 for (iter = peer->path_head; NULL != iter; iter = iter->next)
254 if (2 <= iter->length)
256 GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, iter);
266 * Method called whenever a given peer connects.
269 * @param peer peer identity this notification is about
272 core_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
275 struct MeshPeerPath *path;
277 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer connected\n");
278 LOG (GNUNET_ERROR_TYPE_DEBUG, " %s\n", GNUNET_i2s (&my_full_id));
282 LOG (GNUNET_ERROR_TYPE_DEBUG, " (self)\n");
287 LOG (GNUNET_ERROR_TYPE_DEBUG, " %s\n", GNUNET_i2s (peer));
289 path->peers[1] = mp->id;
290 GNUNET_PEER_change_rc (mp->id, 1);
291 GNUNET_STATISTICS_update (stats, "# peers", 1, GNUNET_NO);
293 path->peers[0] = myid;
294 GNUNET_PEER_change_rc (myid, 1);
295 GMP_add_path (mp, path, GNUNET_YES);
297 mp->connections = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES);
303 * Method called whenever a peer disconnects.
306 * @param peer peer identity this notification is about
309 core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
312 struct MeshPeerPath *direct_path;
314 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer disconnected\n");
315 p = GNUNET_CONTAINER_multipeermap_get (peers, peer);
322 LOG (GNUNET_ERROR_TYPE_DEBUG, " (self: %s)\n", GMP_2s (p));
324 LOG (GNUNET_ERROR_TYPE_DEBUG, " %s\n", GMP_2s (p));
326 direct_path = pop_direct_path (p);
327 GNUNET_CONTAINER_multihashmap_iterate (p->connections, ¬ify_broken, p);
328 GNUNET_CONTAINER_multihashmap_destroy (p->connections);
329 p->connections = NULL;
330 if (NULL != p->core_transmit)
332 GNUNET_CORE_notify_transmit_ready_cancel (p->core_transmit);
333 p->core_transmit = NULL;
335 GNUNET_STATISTICS_update (stats, "# peers", -1, GNUNET_NO);
337 path_destroy (direct_path);
343 * Functions to handle messages from core
345 static struct GNUNET_CORE_MessageHandler core_handlers[] = {
346 {&GMC_handle_create, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE,
348 {&GMC_handle_confirm, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK,
349 sizeof (struct GNUNET_MESH_ConnectionACK)},
350 {&GMC_handle_broken, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN,
351 sizeof (struct GNUNET_MESH_ConnectionBroken)},
352 {&GMC_handle_destroy, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY,
353 sizeof (struct GNUNET_MESH_ConnectionDestroy)},
354 {&GMC_handle_keepalive, GNUNET_MESSAGE_TYPE_MESH_KEEPALIVE,
355 sizeof (struct GNUNET_MESH_ConnectionKeepAlive)},
356 {&GMC_handle_ack, GNUNET_MESSAGE_TYPE_MESH_ACK,
357 sizeof (struct GNUNET_MESH_ACK)},
358 {&GMC_handle_poll, GNUNET_MESSAGE_TYPE_MESH_POLL,
359 sizeof (struct GNUNET_MESH_Poll)},
360 {&GMC_handle_encrypted, GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED, 0},
361 {&GMC_handle_kx, GNUNET_MESSAGE_TYPE_MESH_KX, 0},
367 * To be called on core init/fail.
369 * @param cls Closure (config)
370 * @param identity the public identity of this peer
373 core_init (void *cls,
374 const struct GNUNET_PeerIdentity *identity)
376 const struct GNUNET_CONFIGURATION_Handle *c = cls;
379 LOG (GNUNET_ERROR_TYPE_DEBUG, "Core init\n");
380 if (0 != memcmp (identity, &my_full_id, sizeof (my_full_id)))
382 LOG (GNUNET_ERROR_TYPE_ERROR, _("Wrong CORE service\n"));
383 LOG (GNUNET_ERROR_TYPE_ERROR, " core id %s\n", GNUNET_i2s (identity));
384 LOG (GNUNET_ERROR_TYPE_ERROR, " my id %s\n", GNUNET_i2s (&my_full_id));
385 GNUNET_CORE_disconnect (core_handle);
386 core_handle = GNUNET_CORE_connect (c, /* Main configuration */
387 NULL, /* Closure passed to MESH functions */
388 &core_init, /* Call core_init once connected */
389 &core_connect, /* Handle connects */
390 &core_disconnect, /* remove peers on disconnects */
391 NULL, /* Don't notify about all incoming messages */
392 GNUNET_NO, /* For header only in notification */
393 NULL, /* Don't notify about all outbound messages */
394 GNUNET_NO, /* For header-only out notification */
395 core_handlers); /* Register these handlers */
404 * Core callback to write a pre-constructed data packet to core buffer
406 * @param cls Closure (MeshTransmissionDescriptor with data in "data" member).
407 * @param size Number of bytes available in buf.
408 * @param buf Where the to write the message.
410 * @return number of bytes written to buf
413 send_core_data_raw (void *cls, size_t size, void *buf)
415 struct GNUNET_MessageHeader *msg = cls;
418 GNUNET_assert (NULL != msg);
419 total_size = ntohs (msg->size);
421 if (total_size > size)
426 memcpy (buf, msg, total_size);
433 * Function to send a create connection message to a peer.
435 * @param c Connection to create.
436 * @param size number of bytes available in buf
437 * @param buf where the callee should write the message
438 * @return number of bytes written to buf
441 send_core_connection_create (struct MeshConnection *c, size_t size, void *buf)
443 struct GNUNET_MESH_ConnectionCreate *msg;
444 struct GNUNET_PeerIdentity *peer_ptr;
445 const struct MeshPeerPath *p = GMC_get_path (c);
452 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending CONNECTION CREATE...\n");
454 sizeof (struct GNUNET_MESH_ConnectionCreate) +
455 p->length * sizeof (struct GNUNET_PeerIdentity);
457 if (size < size_needed || NULL == buf)
462 msg = (struct GNUNET_MESH_ConnectionCreate *) buf;
463 msg->header.size = htons (size_needed);
464 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE);
465 msg->cid = *GMC_get_id (c);
467 peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1];
468 for (i = 0; i < p->length; i++)
470 GNUNET_PEER_resolve (p->peers[i], peer_ptr++);
473 LOG (GNUNET_ERROR_TYPE_DEBUG,
474 "CONNECTION CREATE (%u bytes long) sent!\n",
481 * Creates a path ack message in buf and frees all unused resources.
483 * @param c Connection to send an ACK on.
484 * @param size number of bytes available in buf
485 * @param buf where the callee should write the message
487 * @return number of bytes written to buf
490 send_core_connection_ack (struct MeshConnection *c, size_t size, void *buf)
492 struct GNUNET_MESH_ConnectionACK *msg = buf;
494 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending CONNECTION ACK...\n");
495 if (sizeof (struct GNUNET_MESH_ConnectionACK) > size)
500 msg->header.size = htons (sizeof (struct GNUNET_MESH_ConnectionACK));
501 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK);
502 msg->cid = *GMC_get_id (c);
505 /* TODO add signature */
507 LOG (GNUNET_ERROR_TYPE_DEBUG, "CONNECTION ACK sent!\n");
508 return sizeof (struct GNUNET_MESH_ConnectionACK);
512 /******************************************************************************/
513 /******************************** STATIC ***********************************/
514 /******************************************************************************/
518 * Get priority for a queued message.
520 * @param q Queued message
522 * @return CORE priority to use.
524 static enum GNUNET_CORE_Priority
525 get_priority (struct MeshPeerQueue *q)
527 enum GNUNET_CORE_Priority low;
528 enum GNUNET_CORE_Priority high;
533 return GNUNET_CORE_PRIO_BACKGROUND;
536 /* Relayed traffic has lower priority, our own traffic has higher */
537 if (NULL == q->c || GNUNET_NO == GMC_is_origin (q->c, q->fwd))
539 low = GNUNET_CORE_PRIO_BEST_EFFORT;
540 high = GNUNET_CORE_PRIO_URGENT;
544 low = GNUNET_CORE_PRIO_URGENT;
545 high = GNUNET_CORE_PRIO_CRITICAL_CONTROL;
548 /* Bulky payload has lower priority, control traffic has higher. */
549 if (GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED == q->type)
557 * Iterator over tunnel hash map entries to destroy the tunnel during shutdown.
560 * @param key current key code
561 * @param value value in the hash map
562 * @return #GNUNET_YES if we should continue to iterate,
566 shutdown_tunnel (void *cls,
567 const struct GNUNET_PeerIdentity *key,
570 struct MeshPeer *p = value;
571 struct MeshTunnel3 *t = p->tunnel;
580 * Destroy the peer_info and free any allocated resources linked to it
582 * @param peer The peer_info to destroy.
584 * @return GNUNET_OK on success
587 peer_destroy (struct MeshPeer *peer)
589 struct GNUNET_PeerIdentity id;
590 struct MeshPeerPath *p;
591 struct MeshPeerPath *nextp;
593 GNUNET_PEER_resolve (peer->id, &id);
594 GNUNET_PEER_change_rc (peer->id, -1);
596 LOG (GNUNET_ERROR_TYPE_WARNING, "destroying peer %s\n", GNUNET_i2s (&id));
599 GNUNET_CONTAINER_multipeermap_remove (peers, &id, peer))
602 LOG (GNUNET_ERROR_TYPE_WARNING, " not in peermap!!\n");
604 if (NULL != peer->search_h)
606 GMD_search_stop (peer->search_h);
612 GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, p);
616 GMT_destroy_empty (peer->tunnel);
623 * Returns if peer is used (has a tunnel or is neighbor).
625 * @param peer Peer to check.
627 * @return #GNUNET_YES if peer is in use.
630 peer_is_used (struct MeshPeer *peer)
632 struct MeshPeerPath *p;
634 if (NULL != peer->tunnel)
637 for (p = peer->path_head; NULL != p; p = p->next)
647 * Iterator over all the peers to get the oldest timestamp.
649 * @param cls Closure (unsued).
650 * @param key ID of the peer.
651 * @param value Peer_Info of the peer.
654 peer_get_oldest (void *cls,
655 const struct GNUNET_PeerIdentity *key,
658 struct MeshPeer *p = value;
659 struct GNUNET_TIME_Absolute *abs = cls;
661 /* Don't count active peers */
662 if (GNUNET_YES == peer_is_used (p))
665 if (abs->abs_value_us < p->last_contact.abs_value_us)
666 abs->abs_value_us = p->last_contact.abs_value_us;
673 * Iterator over all the peers to remove the oldest entry.
675 * @param cls Closure (unsued).
676 * @param key ID of the peer.
677 * @param value Peer_Info of the peer.
680 peer_timeout (void *cls,
681 const struct GNUNET_PeerIdentity *key,
684 struct MeshPeer *p = value;
685 struct GNUNET_TIME_Absolute *abs = cls;
687 LOG (GNUNET_ERROR_TYPE_WARNING,
688 "peer %s timeout\n", GNUNET_i2s (key));
690 if (p->last_contact.abs_value_us == abs->abs_value_us &&
691 GNUNET_NO == peer_is_used (p))
701 * Delete oldest unused peer.
704 peer_delete_oldest (void)
706 struct GNUNET_TIME_Absolute abs;
708 abs = GNUNET_TIME_UNIT_FOREVER_ABS;
710 GNUNET_CONTAINER_multipeermap_iterate (peers,
713 GNUNET_CONTAINER_multipeermap_iterate (peers,
720 * Choose the best (yet unused) path towards a peer,
721 * considering the tunnel properties.
723 * @param peer The destination peer.
725 * @return Best current known path towards the peer, if any.
727 static struct MeshPeerPath *
728 peer_get_best_path (const struct MeshPeer *peer)
730 struct MeshPeerPath *best_p;
731 struct MeshPeerPath *p;
732 unsigned int best_cost;
735 best_cost = UINT_MAX;
737 for (p = peer->path_head; NULL != p; p = p->next)
739 if (GNUNET_YES == GMT_is_path_used (peer->tunnel, p))
740 continue; /* If path is already in use, skip it. */
742 if (GNUNET_NO == path_is_valid (p))
743 continue; /* Don't use invalid paths. */
745 if ((cost = GMT_get_path_cost (peer->tunnel, p)) < best_cost)
756 queue_is_sendable (struct MeshPeerQueue *q)
758 /* Is PID-independent? */
761 case GNUNET_MESSAGE_TYPE_MESH_ACK:
762 case GNUNET_MESSAGE_TYPE_MESH_POLL:
763 case GNUNET_MESSAGE_TYPE_MESH_KX:
764 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE:
765 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK:
766 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY:
767 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN:
768 case GNUNET_MESSAGE_TYPE_MESH_KEEPALIVE:
771 case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED:
778 if (GMC_is_sendable (q->c, q->fwd))
786 * Get first sendable message.
788 * @param peer The destination peer.
790 * @return Best current known path towards the peer, if any.
792 static struct MeshPeerQueue *
793 peer_get_first_message (const struct MeshPeer *peer)
795 struct MeshPeerQueue *q;
797 for (q = peer->queue_head; NULL != q; q = q->next)
799 if (queue_is_sendable (q))
808 * Function to process paths received for a new peer addition. The recorded
809 * paths form the initial tunnel, which can be optimized later.
810 * Called on each result obtained for the DHT search.
816 search_handler (void *cls, const struct MeshPeerPath *path)
818 struct MeshPeer *peer = cls;
819 unsigned int connection_count;
821 GMP_add_path_to_all (path, GNUNET_NO);
823 /* Count connections */
824 connection_count = GMT_count_connections (peer->tunnel);
826 /* If we already have 3 (or more (?!)) connections, it's enough */
827 if (3 <= connection_count)
830 if (MESH_TUNNEL3_SEARCHING == GMT_get_cstate (peer->tunnel))
832 LOG (GNUNET_ERROR_TYPE_DEBUG, " ... connect!\n");
841 * Core callback to write a queued packet to core buffer
843 * @param cls Closure (peer info).
844 * @param size Number of bytes available in buf.
845 * @param buf Where the to write the message.
847 * @return number of bytes written to buf
850 queue_send (void *cls, size_t size, void *buf)
852 struct MeshPeer *peer = cls;
853 struct MeshConnection *c;
854 struct MeshPeerQueue *queue;
855 const struct GNUNET_PeerIdentity *dst_id;
858 peer->core_transmit = NULL;
859 LOG (GNUNET_ERROR_TYPE_DEBUG, "* Queue send towards %s (max %u)\n",
860 GMP_2s (peer), size);
862 if (NULL == buf || 0 == size)
864 LOG (GNUNET_ERROR_TYPE_DEBUG, "* Buffer size 0.\n");
869 queue = peer_get_first_message (peer);
872 GNUNET_break (0); /* Core tmt_rdy should've been canceled */
877 dst_id = GNUNET_PEER_resolve2 (peer->id);
878 LOG (GNUNET_ERROR_TYPE_DEBUG, "* on connection %s\n", GMC_2s (c));
879 /* Check if buffer size is enough for the message */
880 if (queue->size > size)
882 LOG (GNUNET_ERROR_TYPE_DEBUG, "* not enough room, reissue\n");
883 peer->core_transmit =
884 GNUNET_CORE_notify_transmit_ready (core_handle,
885 GNUNET_NO, get_priority (queue),
886 GNUNET_TIME_UNIT_FOREVER_REL,
893 LOG (GNUNET_ERROR_TYPE_DEBUG, "* size %u ok\n", queue->size);
898 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY:
899 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN:
900 case GNUNET_MESSAGE_TYPE_MESH_KEEPALIVE:
901 case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED:
902 case GNUNET_MESSAGE_TYPE_MESH_KX:
903 case GNUNET_MESSAGE_TYPE_MESH_ACK:
904 case GNUNET_MESSAGE_TYPE_MESH_POLL:
905 LOG (GNUNET_ERROR_TYPE_DEBUG, "* raw: %s\n", GM_m2s (queue->type));
906 data_size = send_core_data_raw (queue->cls, size, buf);
908 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE:
909 LOG (GNUNET_ERROR_TYPE_DEBUG, "* path create\n");
910 if (GMC_is_origin (c, GNUNET_YES))
911 data_size = send_core_connection_create (queue->c, size, buf);
913 data_size = send_core_data_raw (queue->cls, size, buf);
915 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK:
916 LOG (GNUNET_ERROR_TYPE_DEBUG, "* path ack\n");
917 if (GMC_is_origin (c, GNUNET_NO) ||
918 GMC_is_origin (c, GNUNET_YES))
919 data_size = send_core_connection_ack (queue->c, size, buf);
921 data_size = send_core_data_raw (queue->cls, size, buf);
923 case GNUNET_MESSAGE_TYPE_MESH_DATA:
924 case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE:
925 case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY:
926 /* This should be encapsulted */
932 LOG (GNUNET_ERROR_TYPE_WARNING, "* type unknown: %u\n", queue->type);
936 if (0 < drop_percent &&
937 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 101) < drop_percent)
939 LOG (GNUNET_ERROR_TYPE_WARNING,
940 "Dropping message of type %s\n",
941 GM_m2s (queue->type));
945 /* Free queue, but cls was freed by send_core_* */
946 GMP_queue_destroy (queue, GNUNET_NO);
948 /* If more data in queue, send next */
949 queue = peer_get_first_message (peer);
952 LOG (GNUNET_ERROR_TYPE_DEBUG, "* more data!\n");
953 if (NULL == peer->core_transmit)
955 peer->core_transmit =
956 GNUNET_CORE_notify_transmit_ready (core_handle,
957 GNUNET_NO, get_priority (queue),
958 GNUNET_TIME_UNIT_FOREVER_REL,
963 queue->start_waiting = GNUNET_TIME_absolute_get ();
967 LOG (GNUNET_ERROR_TYPE_DEBUG,
968 "* tmt rdy called somewhere else\n");
970 // GMC_start_poll (); FIXME needed?
974 // GMC_stop_poll(); FIXME needed?
977 LOG (GNUNET_ERROR_TYPE_DEBUG, "* Return %d\n", data_size);
982 /******************************************************************************/
983 /******************************** API ***********************************/
984 /******************************************************************************/
988 * Free a transmission that was already queued with all resources
989 * associated to the request.
991 * @param queue Queue handler to cancel.
992 * @param clear_cls Is it necessary to free associated cls?
995 GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls)
997 struct MeshPeer *peer;
1001 if (GNUNET_YES == clear_cls)
1003 LOG (GNUNET_ERROR_TYPE_DEBUG, "# queue destroy type %s\n",
1004 GM_m2s (queue->type));
1005 switch (queue->type)
1007 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY:
1008 LOG (GNUNET_ERROR_TYPE_INFO, "destroying a DESTROY message\n");
1010 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK:
1011 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE:
1012 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN:
1013 case GNUNET_MESSAGE_TYPE_MESH_KEEPALIVE:
1014 case GNUNET_MESSAGE_TYPE_MESH_KX:
1015 case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED:
1016 case GNUNET_MESSAGE_TYPE_MESH_ACK:
1017 case GNUNET_MESSAGE_TYPE_MESH_POLL:
1018 GNUNET_free_non_null (queue->cls);
1023 LOG (GNUNET_ERROR_TYPE_ERROR, "# type %s unknown!\n",
1024 GM_m2s (queue->type));
1027 GNUNET_CONTAINER_DLL_remove (peer->queue_head, peer->queue_tail, queue);
1029 if (queue->type != GNUNET_MESSAGE_TYPE_MESH_ACK &&
1030 queue->type != GNUNET_MESSAGE_TYPE_MESH_POLL)
1035 if (NULL != queue->callback)
1037 LOG (GNUNET_ERROR_TYPE_DEBUG, "# Calling callback\n");
1038 queue->callback (queue->callback_cls,
1039 queue->c, queue->type,
1040 queue->fwd, queue->size,
1041 GNUNET_TIME_absolute_get_duration (queue->start_waiting));
1044 GNUNET_free (queue);
1049 * @brief Queue and pass message to core when possible.
1051 * @param peer Peer towards which to queue the message.
1052 * @param cls Closure (@c type dependant). It will be used by queue_send to
1053 * build the message to be sent if not already prebuilt.
1054 * @param type Type of the message, 0 for a raw message.
1055 * @param size Size of the message.
1056 * @param c Connection this message belongs to (can be NULL).
1057 * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!)
1058 * @param cont Continuation to be called once CORE has taken the message.
1059 * @param cont_cls Closure for @c cont.
1061 * @return Handle to cancel the message before it is sent. Once cont is called
1062 * message has been sent and therefore the handle is no longer valid.
1064 struct MeshPeerQueue *
1065 GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size,
1066 struct MeshConnection *c, int fwd,
1067 GMP_sent cont, void *cont_cls)
1069 struct MeshPeerQueue *queue;
1073 LOG (GNUNET_ERROR_TYPE_DEBUG,
1074 "queue add %s %s towards %s (size %u) on c %p (%s)\n",
1075 GM_f2s (fwd), GM_m2s (type), GMP_2s(peer),
1076 size, c, GMC_2s (c));
1078 if (NULL == peer->connections)
1080 /* We are not connected to this peer, ignore request. */
1081 LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING %s not a neighbor\n", GMP_2s (peer));
1082 GNUNET_STATISTICS_update (stats, "# messages dropped due to wrong hop", 1,
1089 if (GNUNET_MESSAGE_TYPE_MESH_POLL == type ||
1090 GNUNET_MESSAGE_TYPE_MESH_ACK == type)
1095 LOG (GNUNET_ERROR_TYPE_DEBUG, "priority %d\n", priority);
1097 call_core = NULL == c ? GNUNET_YES : GMC_is_sendable (c, fwd);
1098 queue = GNUNET_new (struct MeshPeerQueue);
1105 queue->callback = cont;
1106 queue->callback_cls = cont_cls;
1109 GNUNET_CONTAINER_DLL_insert_tail (peer->queue_head, peer->queue_tail, queue);
1114 GNUNET_CONTAINER_DLL_insert (peer->queue_head, peer->queue_tail, queue);
1115 call_core = GNUNET_YES;
1118 if (NULL == peer->core_transmit && GNUNET_YES == call_core)
1120 LOG (GNUNET_ERROR_TYPE_DEBUG,
1121 "calling core tmt rdy towards %s for %u bytes\n",
1122 GMP_2s (peer), size);
1123 peer->core_transmit =
1124 GNUNET_CORE_notify_transmit_ready (core_handle,
1125 GNUNET_NO, get_priority (queue),
1126 GNUNET_TIME_UNIT_FOREVER_REL,
1127 GNUNET_PEER_resolve2 (peer->id),
1131 queue->start_waiting = GNUNET_TIME_absolute_get ();
1135 LOG (GNUNET_ERROR_TYPE_DEBUG,
1136 "core tmt rdy towards %s already called\n",
1145 * Cancel all queued messages to a peer that belong to a certain connection.
1147 * @param peer Peer towards whom to cancel.
1148 * @param c Connection whose queued messages to cancel. Might be destroyed by
1149 * the sent continuation call.
1152 GMP_queue_cancel (struct MeshPeer *peer, struct MeshConnection *c)
1154 struct MeshPeerQueue *q;
1155 struct MeshPeerQueue *next;
1156 struct MeshPeerQueue *prev;
1158 for (q = peer->queue_head; NULL != q; q = next)
1163 LOG (GNUNET_ERROR_TYPE_DEBUG, "GMP_cancel_queue %s\n", GM_m2s (q->type));
1164 GMP_queue_destroy (q, GNUNET_YES);
1166 /* Get next from prev, q->next might be already freed:
1167 * queue destroy -> callback -> GMC_destroy -> cancel_queues -> here
1170 next = peer->queue_head;
1179 if (NULL == peer->queue_head)
1181 if (NULL != peer->core_transmit)
1183 GNUNET_CORE_notify_transmit_ready_cancel (peer->core_transmit);
1184 peer->core_transmit = NULL;
1191 * Get the first transmittable message for a connection.
1193 * @param peer Neighboring peer.
1194 * @param c Connection.
1196 * @return First transmittable message.
1198 static struct MeshPeerQueue *
1199 connection_get_first_message (struct MeshPeer *peer, struct MeshConnection *c)
1201 struct MeshPeerQueue *q;
1203 for (q = peer->queue_head; NULL != q; q = q->next)
1207 if (queue_is_sendable (q))
1209 LOG (GNUNET_ERROR_TYPE_DEBUG, " sendable!!\n");
1212 LOG (GNUNET_ERROR_TYPE_DEBUG, " not sendable\n");
1220 GMP_queue_unlock (struct MeshPeer *peer, struct MeshConnection *c)
1222 struct MeshPeerQueue *q;
1225 if (NULL != peer->core_transmit)
1227 LOG (GNUNET_ERROR_TYPE_DEBUG, " already unlocked!\n");
1228 return; /* Already unlocked */
1231 q = connection_get_first_message (peer, c);
1234 LOG (GNUNET_ERROR_TYPE_DEBUG, " queue empty!\n");
1235 return; /* Nothing to transmit */
1239 peer->core_transmit =
1240 GNUNET_CORE_notify_transmit_ready (core_handle,
1241 GNUNET_NO, get_priority (q),
1242 GNUNET_TIME_UNIT_FOREVER_REL,
1243 GNUNET_PEER_resolve2 (peer->id),
1251 * Initialize the peer subsystem.
1253 * @param c Configuration.
1256 GMP_init (const struct GNUNET_CONFIGURATION_Handle *c)
1258 LOG (GNUNET_ERROR_TYPE_DEBUG, "init\n");
1259 peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
1261 GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_PEERS",
1264 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING,
1265 "MESH", "MAX_PEERS", "USING DEFAULT");
1270 GNUNET_CONFIGURATION_get_value_number (c, "MESH", "DROP_PERCENT",
1277 LOG (GNUNET_ERROR_TYPE_WARNING,
1278 "\n***************************************\n"
1279 "Mesh is running with drop mode enabled.\n"
1280 "This is NOT a good idea!\n"
1281 "Remove the DROP_PERCENT option from your configuration.\n"
1282 "***************************************\n");
1285 core_handle = GNUNET_CORE_connect (c, /* Main configuration */
1286 NULL, /* Closure passed to MESH functions */
1287 &core_init, /* Call core_init once connected */
1288 &core_connect, /* Handle connects */
1289 &core_disconnect, /* remove peers on disconnects */
1290 NULL, /* Don't notify about all incoming messages */
1291 GNUNET_NO, /* For header only in notification */
1292 NULL, /* Don't notify about all outbound messages */
1293 GNUNET_NO, /* For header-only out notification */
1294 core_handlers); /* Register these handlers */
1295 if (NULL == core_handle)
1298 GNUNET_SCHEDULER_shutdown ();
1304 * Shut down the peer subsystem.
1309 GNUNET_CONTAINER_multipeermap_iterate (peers, &shutdown_tunnel, NULL);
1311 if (core_handle != NULL)
1313 GNUNET_CORE_disconnect (core_handle);
1316 GNUNET_PEER_change_rc (myid, -1);
1320 * Retrieve the MeshPeer stucture associated with the peer, create one
1321 * and insert it in the appropriate structures if the peer is not known yet.
1323 * @param peer_id Full identity of the peer.
1325 * @return Existing or newly created peer structure.
1328 GMP_get (const struct GNUNET_PeerIdentity *peer_id)
1330 struct MeshPeer *peer;
1332 peer = GNUNET_CONTAINER_multipeermap_get (peers, peer_id);
1335 peer = GNUNET_new (struct MeshPeer);
1336 if (GNUNET_CONTAINER_multipeermap_size (peers) > max_peers)
1338 peer_delete_oldest ();
1340 GNUNET_CONTAINER_multipeermap_put (peers, peer_id, peer,
1341 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1342 peer->id = GNUNET_PEER_intern (peer_id);
1344 peer->last_contact = GNUNET_TIME_absolute_get();
1351 * Retrieve the MeshPeer stucture associated with the peer, create one
1352 * and insert it in the appropriate structures if the peer is not known yet.
1354 * @param peer Short identity of the peer.
1356 * @return Existing or newly created peer structure.
1359 GMP_get_short (const GNUNET_PEER_Id peer)
1361 return GMP_get (GNUNET_PEER_resolve2 (peer));
1366 * Try to establish a new connection to this peer (in its tunnel).
1367 * If the peer doesn't have any path to it yet, try to get one.
1368 * If the peer already has some path, send a CREATE CONNECTION towards it.
1370 * @param peer Peer to connect to.
1373 GMP_connect (struct MeshPeer *peer)
1375 struct MeshTunnel3 *t;
1376 struct MeshPeerPath *p;
1377 struct MeshConnection *c;
1380 LOG (GNUNET_ERROR_TYPE_DEBUG, "peer_connect towards %s\n", GMP_2s (peer));
1383 rerun_search = GNUNET_NO;
1385 if (NULL != peer->path_head)
1387 LOG (GNUNET_ERROR_TYPE_DEBUG, " some path exists\n");
1388 p = peer_get_best_path (peer);
1391 LOG (GNUNET_ERROR_TYPE_DEBUG, " %u hops\n", p->length);
1392 c = GMT_use_path (t, p);
1395 /* This case can happen when the path includes a first hop that is
1396 * not yet known to be connected.
1398 * This happens quite often during testing when running mesh
1399 * under valgrind: core connect notifications come very late and the
1400 * DHT result has already come and created a valid path.
1401 * In this case, the peer->connections hashmap will be NULL and
1402 * tunnel_use_path will not be able to create a connection from that
1405 * Re-running the DHT GET should give core time to callback.
1407 * GMT_use_path -> GMC_new -> register_neighbors takes care of
1408 * updating statistics about this issue.
1410 rerun_search = GNUNET_YES;
1414 GMC_send_create (c);
1420 LOG (GNUNET_ERROR_TYPE_DEBUG, " but is NULL, all paths are in use\n");
1424 if (NULL != peer->search_h && GNUNET_YES == rerun_search)
1426 GMD_search_stop (peer->search_h);
1427 peer->search_h = NULL;
1428 LOG (GNUNET_ERROR_TYPE_DEBUG,
1429 " Stopping DHT GET for peer %s\n",
1433 if (NULL == peer->search_h)
1435 const struct GNUNET_PeerIdentity *id;
1437 id = GNUNET_PEER_resolve2 (peer->id);
1438 LOG (GNUNET_ERROR_TYPE_DEBUG,
1439 " Starting DHT GET for peer %s\n", GMP_2s (peer));
1440 peer->search_h = GMD_search (id, &search_handler, peer);
1441 if (MESH_TUNNEL3_NEW == GMT_get_cstate (t))
1442 GMT_change_cstate (t, MESH_TUNNEL3_SEARCHING);
1448 * Chech whether there is a direct (core level) connection to peer.
1450 * @param peer Peer to check.
1452 * @return #GNUNET_YES if there is a direct connection.
1455 GMP_is_neighbor (const struct MeshPeer *peer)
1457 struct MeshPeerPath *path;
1459 if (NULL == peer->connections)
1462 for (path = peer->path_head; NULL != path; path = path->next)
1464 if (3 > path->length)
1468 /* Is not a neighbor but connections is not NULL, probably disconnecting */
1474 * Create and initialize a new tunnel towards a peer, in case it has none.
1475 * In case the peer already has a tunnel, nothing is done.
1477 * Does not generate any traffic, just creates the local data structures.
1479 * @param peer Peer towards which to create the tunnel.
1482 GMP_add_tunnel (struct MeshPeer *peer)
1484 if (NULL != peer->tunnel)
1486 peer->tunnel = GMT_new (peer);
1491 * Add a connection to a neighboring peer.
1493 * Store that the peer is the first hop of the connection in one
1494 * direction and that on peer disconnect the connection must be
1495 * notified and destroyed, for it will no longer be valid.
1497 * @param peer Peer to add connection to.
1498 * @param c Connection to add.
1500 * @return GNUNET_OK on success.
1503 GMP_add_connection (struct MeshPeer *peer,
1504 struct MeshConnection *c)
1507 LOG (GNUNET_ERROR_TYPE_DEBUG, "adding connection %s\n", GMC_2s (c));
1508 LOG (GNUNET_ERROR_TYPE_DEBUG, "to peer %s\n", GMP_2s (peer));
1510 if (NULL == peer->connections)
1513 LOG (GNUNET_ERROR_TYPE_DEBUG,
1514 "Peer %s is not a neighbor!\n",
1516 return GNUNET_SYSERR;
1518 LOG (GNUNET_ERROR_TYPE_DEBUG,
1519 "peer %s ok, has %u connections.\n",
1520 GMP_2s (peer), GNUNET_CONTAINER_multihashmap_size (peer->connections));
1521 result = GNUNET_CONTAINER_multihashmap_put (peer->connections,
1524 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1525 LOG (GNUNET_ERROR_TYPE_DEBUG,
1526 " now has %u connections.\n",
1527 GNUNET_CONTAINER_multihashmap_size (peer->connections));
1528 LOG (GNUNET_ERROR_TYPE_DEBUG, "result %u\n", result);
1535 * Add the path to the peer and update the path used to reach it in case this
1538 * @param peer Destination peer to add the path to.
1539 * @param path New path to add. Last peer must be the peer in arg 1.
1540 * Path will be either used of freed if already known.
1541 * @param trusted Do we trust that this path is real?
1543 * @return path if path was taken, pointer to existing duplicate if exists
1546 struct MeshPeerPath *
1547 GMP_add_path (struct MeshPeer *peer, struct MeshPeerPath *path,
1550 struct MeshPeerPath *aux;
1554 LOG (GNUNET_ERROR_TYPE_DEBUG, "adding path [%u] to peer %s\n",
1555 path->length, GMP_2s (peer));
1557 if ((NULL == peer) || (NULL == path))
1560 path_destroy (path);
1563 if (path->peers[path->length - 1] != peer->id)
1566 path_destroy (path);
1569 if (2 >= path->length && GNUNET_NO == trusted)
1571 /* Only allow CORE to tell us about direct paths */
1572 path_destroy (path);
1575 for (l = 1; l < path->length; l++)
1577 if (path->peers[l] == myid)
1579 LOG (GNUNET_ERROR_TYPE_DEBUG, "shortening path by %u\n", l);
1580 for (l2 = 0; l2 < path->length - l; l2++)
1582 path->peers[l2] = path->peers[l + l2];
1586 path->peers = GNUNET_realloc (path->peers,
1587 path->length * sizeof (GNUNET_PEER_Id));
1591 LOG (GNUNET_ERROR_TYPE_DEBUG, "adding path [%u]\n", path->length);
1593 l = path_get_length (path);
1596 path_destroy (path);
1600 GNUNET_assert (peer->id == path->peers[path->length - 1]);
1601 for (aux = peer->path_head; aux != NULL; aux = aux->next)
1603 l2 = path_get_length (aux);
1606 LOG (GNUNET_ERROR_TYPE_DEBUG, " added\n");
1607 GNUNET_CONTAINER_DLL_insert_before (peer->path_head,
1608 peer->path_tail, aux, path);
1613 if (l2 == l && memcmp (path->peers, aux->peers, l) == 0)
1615 LOG (GNUNET_ERROR_TYPE_DEBUG, " already known\n");
1616 path_destroy (path);
1621 GNUNET_CONTAINER_DLL_insert_tail (peer->path_head, peer->path_tail,
1623 LOG (GNUNET_ERROR_TYPE_DEBUG, " added last\n");
1629 * Add the path to the origin peer and update the path used to reach it in case
1630 * this is the shortest.
1631 * The path is given in peer_info -> destination, therefore we turn the path
1632 * upside down first.
1634 * @param peer Peer to add the path to, being the origin of the path.
1635 * @param path New path to add after being inversed.
1636 * Path will be either used or freed.
1637 * @param trusted Do we trust that this path is real?
1639 * @return path if path was taken, pointer to existing duplicate if exists
1642 struct MeshPeerPath *
1643 GMP_add_path_to_origin (struct MeshPeer *peer,
1644 struct MeshPeerPath *path,
1650 return GMP_add_path (peer, path, trusted);
1655 * Adds a path to the info of all the peers in the path
1657 * @param p Path to process.
1658 * @param confirmed Whether we know if the path works or not.
1661 GMP_add_path_to_all (const struct MeshPeerPath *p, int confirmed)
1665 /* TODO: invert and add */
1666 for (i = 0; i < p->length && p->peers[i] != myid; i++) /* skip'em */ ;
1667 for (i++; i < p->length; i++)
1669 struct MeshPeer *aux;
1670 struct MeshPeerPath *copy;
1672 aux = GMP_get_short (p->peers[i]);
1673 copy = path_duplicate (p);
1674 copy->length = i + 1;
1675 GMP_add_path (aux, copy, p->length < 3 ? GNUNET_NO : confirmed);
1681 * Remove any path to the peer that has the extact same peers as the one given.
1683 * @param peer Peer to remove the path from.
1684 * @param path Path to remove. Is always destroyed .
1687 GMP_remove_path (struct MeshPeer *peer, struct MeshPeerPath *path)
1689 struct MeshPeerPath *iter;
1690 struct MeshPeerPath *next;
1692 GNUNET_assert (myid == path->peers[0]);
1693 GNUNET_assert (peer->id == path->peers[path->length - 1]);
1695 for (iter = peer->path_head; NULL != iter; iter = next)
1698 if (0 == memcmp (path->peers, iter->peers,
1699 sizeof (GNUNET_PEER_Id) * path->length))
1701 GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, iter);
1702 path_destroy (iter);
1707 path_destroy (path);
1712 * Remove a connection from a neighboring peer.
1714 * @param peer Peer to remove connection from.
1715 * @param c Connection to remove.
1717 * @return GNUNET_OK on success.
1720 GMP_remove_connection (struct MeshPeer *peer,
1721 const struct MeshConnection *c)
1723 LOG (GNUNET_ERROR_TYPE_DEBUG, "removing connection %s\n", GMC_2s (c));
1724 LOG (GNUNET_ERROR_TYPE_DEBUG, "from peer %s\n", GMP_2s (peer));
1726 if (NULL == peer || NULL == peer->connections)
1728 LOG (GNUNET_ERROR_TYPE_DEBUG,
1729 "Peer %s is not a neighbor!\n",
1731 return GNUNET_SYSERR;
1733 LOG (GNUNET_ERROR_TYPE_DEBUG,
1734 "peer %s ok, has %u connections.\n",
1735 GMP_2s (peer), GNUNET_CONTAINER_multihashmap_size (peer->connections));
1737 return GNUNET_CONTAINER_multihashmap_remove (peer->connections,
1743 * Start the DHT search for new paths towards the peer: we don't have
1744 * enough good connections.
1746 * @param peer Destination peer.
1749 GMP_start_search (struct MeshPeer *peer)
1751 if (NULL != peer->search_h)
1757 peer->search_h = GMD_search (GMP_get_id (peer), &search_handler, peer);
1762 * Stop the DHT search for new paths towards the peer: we already have
1763 * enough good connections.
1765 * @param peer Destination peer.
1768 GMP_stop_search (struct MeshPeer *peer)
1770 if (NULL == peer->search_h)
1776 GMD_search_stop (peer->search_h);
1777 peer->search_h = NULL;
1782 * Get the Full ID of a peer.
1784 * @param peer Peer to get from.
1786 * @return Full ID of peer.
1788 const struct GNUNET_PeerIdentity *
1789 GMP_get_id (const struct MeshPeer *peer)
1791 return GNUNET_PEER_resolve2 (peer->id);
1796 * Get the Short ID of a peer.
1798 * @param peer Peer to get from.
1800 * @return Short ID of peer.
1803 GMP_get_short_id (const struct MeshPeer *peer)
1816 GMP_set_tunnel (struct MeshPeer *peer, struct MeshTunnel3 *t)
1823 * Get the tunnel towards a peer.
1825 * @param peer Peer to get from.
1827 * @return Tunnel towards peer.
1829 struct MeshTunnel3 *
1830 GMP_get_tunnel (const struct MeshPeer *peer)
1832 return peer->tunnel;
1837 * Set the hello message.
1839 * @param peer Peer whose message to set.
1840 * @param hello Hello message.
1843 GMP_set_hello (struct MeshPeer *peer, const struct GNUNET_HELLO_Message *hello)
1845 struct GNUNET_TIME_Absolute expiration;
1846 struct GNUNET_TIME_Relative remaining;
1848 if (NULL == peer->hello)
1850 peer->hello = hello;
1854 expiration = GNUNET_HELLO_get_last_expiration (peer->hello);
1855 remaining = GNUNET_TIME_absolute_get_remaining (expiration);
1856 if (0 == remaining.rel_value_us)
1858 GNUNET_free (peer->hello);
1859 peer->hello = hello;
1862 peer->hello = GNUNET_HELLO_merge (peer->hello, hello);
1867 * Get the hello message.
1869 * @param peer Peer whose message to get.
1871 * @return Hello message.
1873 const struct GNUNET_HELLO_Message *
1874 GMP_get_hello (struct MeshPeer *peer)
1881 * Count the number of known paths toward the peer.
1883 * @param peer Peer to get path info.
1885 * @return Number of known paths.
1888 GMP_count_paths (const struct MeshPeer *peer)
1890 struct MeshPeerPath *iter;
1893 for (iter = peer->path_head, i = 0; NULL != iter; iter = iter->next)
1901 * Iterate all known peers.
1903 * @param iter Iterator.
1904 * @param cls Closure for @c iter.
1907 GMP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter, void *cls)
1909 GNUNET_CONTAINER_multipeermap_iterate (peers, iter, cls);
1914 * Get the static string for a peer ID.
1918 * @return Static string for it's ID.
1921 GMP_2s (const struct MeshPeer *peer)
1925 return GNUNET_i2s (GNUNET_PEER_resolve2 (peer->id));