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"
47 #define DEBUG_HANDSHAKE GNUNET_EXTRA_LOGGING
49 #define DEBUG_CORE_QUOTA GNUNET_EXTRA_LOGGING
52 * Receive and send buffer windows grow over time. For
53 * how long can 'unused' bandwidth accumulate before we
54 * need to cap it? (specified in seconds).
56 #define MAX_WINDOW_TIME_S (5 * 60)
59 * How many messages do we queue up at most for optional
60 * notifications to a client? (this can cause notifications
61 * about outgoing messages to be dropped).
63 #define MAX_NOTIFY_QUEUE 1024
66 * Minimum bandwidth (out) to assign to any connected peer.
67 * Should be rather low; values larger than DEFAULT_BW_IN_OUT make no
70 #define MIN_BANDWIDTH_PER_PEER GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT
73 * After how much time past the "official" expiration time do
74 * we discard messages? Should not be zero since we may
75 * intentionally defer transmission until close to the deadline
76 * and then may be slightly past the deadline due to inaccuracy
77 * in sleep and our own CPU consumption.
79 #define PAST_EXPIRATION_DISCARD_TIME GNUNET_TIME_UNIT_SECONDS
82 * What is the maximum delay for a SET_KEY message?
84 #define MAX_SET_KEY_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
87 * How long do we wait for SET_KEY confirmation initially?
89 #define INITIAL_SET_KEY_RETRY_FREQUENCY GNUNET_TIME_relative_multiply (MAX_SET_KEY_DELAY, 1)
92 * What is the maximum delay for a PING message?
94 #define MAX_PING_DELAY GNUNET_TIME_relative_multiply (MAX_SET_KEY_DELAY, 2)
97 * What is the maximum delay for a PONG message?
99 #define MAX_PONG_DELAY GNUNET_TIME_relative_multiply (MAX_PING_DELAY, 2)
102 * What is the minimum frequency for a PING message?
104 #define MIN_PING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
107 * How often do we recalculate bandwidth quotas?
109 #define QUOTA_UPDATE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
112 * What is the priority for a SET_KEY message?
114 #define SET_KEY_PRIORITY 0xFFFFFF
117 * What is the priority for a PING message?
119 #define PING_PRIORITY 0xFFFFFF
122 * What is the priority for a PONG message?
124 #define PONG_PRIORITY 0xFFFFFF
127 * How many messages do we queue per peer at most? Must be at
130 #define MAX_PEER_QUEUE_SIZE 16
133 * How many non-mandatory messages do we queue per client at most?
135 #define MAX_CLIENT_QUEUE_SIZE 32
138 * What is the maximum age of a message for us to consider
139 * processing it? Note that this looks at the timestamp used
140 * by the other peer, so clock skew between machines does
141 * come into play here. So this should be picked high enough
142 * so that a little bit of clock skew does not prevent peers
143 * from connecting to us.
145 #define MAX_MESSAGE_AGE GNUNET_TIME_UNIT_DAYS
150 * Number of bytes (at the beginning) of "struct EncryptedMessage"
151 * that are NOT encrypted.
153 #define ENCRYPTED_HEADER_SIZE (offsetof(struct EncryptedMessage, sequence_number))
159 struct GNUNET_PeerIdentity GSC_my_identity;
164 const struct GNUNET_CONFIGURATION_Handle *GSC_cfg;
167 * For creating statistics.
169 struct GNUNET_STATISTICS_Handle *GSC_stats;
172 * Our message stream tokenizer (for encrypted payload).
174 struct GNUNET_SERVER_MessageStreamTokenizer *GSC_mst;
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");
192 GNUNET_SERVER_mst_destroy (GSC_mst);
195 if (GSC_stats != NULL)
197 GNUNET_STATISTICS_destroy (GSC_stats, GNUNET_NO);
205 * Initiate core service.
208 * @param server the initialized server
209 * @param c configuration to use
212 run (void *cls, struct GNUNET_SERVER_Handle *server,
213 const struct GNUNET_CONFIGURATION_Handle *c)
216 GSC_mst = GNUNET_SERVER_mst_create (&deliver_message, NULL);
217 GSC_stats = GNUNET_STATISTICS_create ("core", cfg);
219 GSC_CLIENTS_init (server);
220 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task,
222 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Core service of `%4s' ready.\n"),
223 GNUNET_i2s (&my_identity));
229 * The main function for the transport service.
231 * @param argc number of arguments from the command line
232 * @param argv command line arguments
233 * @return 0 ok, 1 on error
236 main (int argc, char *const *argv)
239 GNUNET_SERVICE_run (argc, argv, "core", GNUNET_SERVICE_OPTION_NONE,
240 &run, NULL)) ? 0 : 1;
243 /* end of gnunet-service-core.c */