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-service-mesh_peer.h"
27 /******************************************************************************/
28 /******************************** STRUCTS **********************************/
29 /******************************************************************************/
32 * Struct containing all information regarding a given peer
42 * Last time we heard from this peer
44 struct GNUNET_TIME_Absolute last_contact;
47 * Paths to reach the peer, ordered by ascending hop count
49 struct MeshPeerPath *path_head;
52 * Paths to reach the peer, ordered by ascending hop count
54 struct MeshPeerPath *path_tail;
57 * Handle to stop the DHT search for paths to this peer
59 struct GNUNET_DHT_GetHandle *dhtget;
62 * Tunnel to this peer, if any.
64 struct MeshTunnel2 *tunnel;
67 * Connections that go through this peer, indexed by tid;
69 struct GNUNET_CONTAINER_MultiHashMap *connections;
72 * Handle for queued transmissions
74 struct GNUNET_CORE_TransmitHandle *core_transmit;
77 * Transmission queue to core DLL head
79 struct MeshPeerQueue *queue_head;
82 * Transmission queue to core DLL tail
84 struct MeshPeerQueue *queue_tail;
87 * How many messages are in the queue to this peer.
93 /******************************************************************************/
94 /******************************* GLOBALS ***********************************/
95 /******************************************************************************/
98 * Peers known, indexed by PeerIdentity (MeshPeer).
100 static struct GNUNET_CONTAINER_MultiPeerMap *peers;
103 * How many peers do we want to remember?
105 static unsigned long long max_peers;
108 /******************************************************************************/
109 /******************************** STATIC ***********************************/
110 /******************************************************************************/
113 * Iterator over tunnel hash map entries to destroy the tunnel during shutdown.
116 * @param key current key code
117 * @param value value in the hash map
118 * @return #GNUNET_YES if we should continue to iterate,
122 shutdown_tunnel (void *cls,
123 const struct GNUNET_PeerIdentity *key,
126 struct MeshPeer *p = value;
127 struct MeshTunnel2 *t = p->tunnel;
135 /******************************************************************************/
136 /******************************** API ***********************************/
137 /******************************************************************************/
140 * Initialize the peer subsystem.
142 * @param c Configuration.
145 GMP_init (const struct GNUNET_CONFIGURATION_Handle *c)
147 peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
149 GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_PEERS",
152 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING,
153 "MESH", "MAX_PEERS", "USING DEFAULT");
159 * Shut down the peer subsystem.
164 GNUNET_CONTAINER_multipeermap_iterate (peers, &shutdown_tunnel, NULL);