2 This file is part of GNUnet.
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file core/gnunet-service-core.c
23 * @brief high-level P2P messaging
24 * @author Christian Grothoff
26 * Type map implementation:
27 * - track type maps for neighbours (can wait)
28 * - only notify clients about peers with matching type maps (can wait)
30 * Considerations for later:
31 * - check that hostkey used by transport (for HELLOs) is the
32 * same as the hostkey that we are using!
36 #include "gnunet_constants.h"
37 #include "gnunet_util_lib.h"
38 #include "gnunet_hello_lib.h"
39 #include "gnunet_peerinfo_service.h"
40 #include "gnunet_protocols.h"
41 #include "gnunet_signatures.h"
42 #include "gnunet_statistics_service.h"
43 #include "gnunet_transport_service.h"
44 #include "gnunet-service-core.h"
45 #include "gnunet-service-core_clients.h"
46 #include "gnunet-service-core_kx.h"
47 #include "gnunet-service-core_neighbours.h"
48 #include "gnunet-service-core_sessions.h"
49 #include "gnunet-service-core_typemap.h"
52 #define DEBUG_HANDSHAKE GNUNET_EXTRA_LOGGING
54 #define DEBUG_CORE_QUOTA GNUNET_EXTRA_LOGGING
57 * Receive and send buffer windows grow over time. For
58 * how long can 'unused' bandwidth accumulate before we
59 * need to cap it? (specified in seconds).
61 #define MAX_WINDOW_TIME_S (5 * 60)
64 * How many messages do we queue up at most for optional
65 * notifications to a client? (this can cause notifications
66 * about outgoing messages to be dropped).
68 #define MAX_NOTIFY_QUEUE 1024
71 * Minimum bandwidth (out) to assign to any connected peer.
72 * Should be rather low; values larger than DEFAULT_BW_IN_OUT make no
75 #define MIN_BANDWIDTH_PER_PEER GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT
78 * After how much time past the "official" expiration time do
79 * we discard messages? Should not be zero since we may
80 * intentionally defer transmission until close to the deadline
81 * and then may be slightly past the deadline due to inaccuracy
82 * in sleep and our own CPU consumption.
84 #define PAST_EXPIRATION_DISCARD_TIME GNUNET_TIME_UNIT_SECONDS
87 * What is the maximum delay for a SET_KEY message?
89 #define MAX_SET_KEY_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
92 * How long do we wait for SET_KEY confirmation initially?
94 #define INITIAL_SET_KEY_RETRY_FREQUENCY GNUNET_TIME_relative_multiply (MAX_SET_KEY_DELAY, 1)
97 * What is the maximum delay for a PING message?
99 #define MAX_PING_DELAY GNUNET_TIME_relative_multiply (MAX_SET_KEY_DELAY, 2)
102 * What is the maximum delay for a PONG message?
104 #define MAX_PONG_DELAY GNUNET_TIME_relative_multiply (MAX_PING_DELAY, 2)
107 * What is the minimum frequency for a PING message?
109 #define MIN_PING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
112 * How often do we recalculate bandwidth quotas?
114 #define QUOTA_UPDATE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
117 * What is the priority for a SET_KEY message?
119 #define SET_KEY_PRIORITY 0xFFFFFF
122 * What is the priority for a PING message?
124 #define PING_PRIORITY 0xFFFFFF
127 * What is the priority for a PONG message?
129 #define PONG_PRIORITY 0xFFFFFF
132 * How many messages do we queue per peer at most? Must be at
135 #define MAX_PEER_QUEUE_SIZE 16
138 * How many non-mandatory messages do we queue per client at most?
140 #define MAX_CLIENT_QUEUE_SIZE 32
143 * What is the maximum age of a message for us to consider
144 * processing it? Note that this looks at the timestamp used
145 * by the other peer, so clock skew between machines does
146 * come into play here. So this should be picked high enough
147 * so that a little bit of clock skew does not prevent peers
148 * from connecting to us.
150 #define MAX_MESSAGE_AGE GNUNET_TIME_UNIT_DAYS
155 * Number of bytes (at the beginning) of "struct EncryptedMessage"
156 * that are NOT encrypted.
158 #define ENCRYPTED_HEADER_SIZE (offsetof(struct EncryptedMessage, sequence_number))
164 struct GNUNET_PeerIdentity GSC_my_identity;
169 const struct GNUNET_CONFIGURATION_Handle *GSC_cfg;
172 * For creating statistics.
174 struct GNUNET_STATISTICS_Handle *GSC_stats;
178 * Last task run during shutdown. Disconnects us from
182 cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
186 "Core service shutting down.\n");
189 GSC_SESSIONS_done ();
190 GSC_NEIGHBOURS_done ();
193 if (GSC_stats != NULL)
195 GNUNET_STATISTICS_destroy (GSC_stats, GNUNET_NO);
203 * Initiate core service.
206 * @param server the initialized server
207 * @param c configuration to use
210 run (void *cls, struct GNUNET_SERVER_Handle *server,
211 const struct GNUNET_CONFIGURATION_Handle *c)
214 GSC_stats = GNUNET_STATISTICS_create ("core", GSC_cfg);
215 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task,
218 if ( (GNUNET_OK != GSC_KX_init ()) ||
219 (GNUNET_OK != GSC_NEIGHBOURS_init ()) )
221 GNUNET_SCHEDULER_shutdown ();
224 GSC_SESSIONS_init ();
225 GSC_CLIENTS_init (server);
226 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Core service of `%4s' ready.\n"),
227 GNUNET_i2s (&GSC_my_identity));
233 * The main function for the transport service.
235 * @param argc number of arguments from the command line
236 * @param argv command line arguments
237 * @return 0 ok, 1 on error
240 main (int argc, char *const *argv)
243 GNUNET_SERVICE_run (argc, argv, "core", GNUNET_SERVICE_OPTION_NONE,
244 &run, NULL)) ? 0 : 1;
247 /* end of gnunet-service-core.c */