aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-01-24 16:47:51 +0000
committerChristian Grothoff <christian@grothoff.org>2010-01-24 16:47:51 +0000
commit145d221194b71a52403a8323839f7b4039764ece (patch)
tree5383522d05700fdaaf3e977575350053aa866af7
parent6b26c6b0babd2b0964875cad68c866639ea94936 (diff)
downloadgnunet-145d221194b71a52403a8323839f7b4039764ece.tar.gz
gnunet-145d221194b71a52403a8323839f7b4039764ece.zip
adding support for outbound message monitoring
-rw-r--r--TODO1
-rw-r--r--src/core/gnunet-service-core.c62
-rw-r--r--src/include/gnunet_core_service.h32
3 files changed, 71 insertions, 24 deletions
diff --git a/TODO b/TODO
index 492d5b5ff..f5d5ac56d 100644
--- a/TODO
+++ b/TODO
@@ -17,7 +17,6 @@ Urgent items (before announcing ng.gnunet.org):
17 - main service not implemented [Nate] 17 - main service not implemented [Nate]
18 - testcases crash & burn (no surprise) 18 - testcases crash & burn (no surprise)
19* CORE: 19* CORE:
20 - outbound message monitoring not supported [Christian]
21 - test currently fails spectacularly [segv of transport service] 20 - test currently fails spectacularly [segv of transport service]
22 => need transport to work first! 21 => need transport to work first!
23 - request connect not working [Christian, need transport first] 22 - request connect not working [Christian, need transport first]
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c
index cb74fc8c2..a0e1fb1c7 100644
--- a/src/core/gnunet-service-core.c
+++ b/src/core/gnunet-service-core.c
@@ -23,11 +23,6 @@
23 * @brief high-level P2P messaging 23 * @brief high-level P2P messaging
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 * 25 *
26 * TODO:
27 * - not all GNUNET_CORE_OPTION_SEND_* flags are fully supported yet
28 * (i.e. no SEND_XXX_OUTBOUND).
29 * - 'REQUEST_DISCONNECT' is not implemented (transport API is lacking!)
30 *
31 * Considerations for later: 26 * Considerations for later:
32 * - check that hostkey used by transport (for HELLOs) is the 27 * - check that hostkey used by transport (for HELLOs) is the
33 * same as the hostkey that we are using! 28 * same as the hostkey that we are using!
@@ -54,6 +49,13 @@
54#define MAX_WINDOW_TIME (5 * 60 * 1000) 49#define MAX_WINDOW_TIME (5 * 60 * 1000)
55 50
56/** 51/**
52 * How many messages do we queue up at most for optional
53 * notifications to a client? (this can cause notifications
54 * about outgoing messages to be dropped).
55 */
56#define MAX_NOTIFY_QUEUE 16
57
58/**
57 * Minimum of bytes per minute (out) to assign to any connected peer. 59 * Minimum of bytes per minute (out) to assign to any connected peer.
58 * Should be rather low; values larger than DEFAULT_BPM_IN_OUT make no 60 * Should be rather low; values larger than DEFAULT_BPM_IN_OUT make no
59 * sense. 61 * sense.
@@ -1350,11 +1352,13 @@ batch_message (struct Neighbour *n,
1350 struct GNUNET_TIME_Relative *retry_time, 1352 struct GNUNET_TIME_Relative *retry_time,
1351 unsigned int *priority) 1353 unsigned int *priority)
1352{ 1354{
1355 char ntmb[GNUNET_SERVER_MAX_MESSAGE_SIZE];
1356 struct NotifyTrafficMessage *ntm = (struct NotifyTrafficMessage*) ntmb;
1353 struct MessageEntry *pos; 1357 struct MessageEntry *pos;
1354 struct MessageEntry *prev; 1358 struct MessageEntry *prev;
1355 struct MessageEntry *next; 1359 struct MessageEntry *next;
1356 size_t ret; 1360 size_t ret;
1357 1361
1358 ret = 0; 1362 ret = 0;
1359 *priority = 0; 1363 *priority = 0;
1360 *deadline = GNUNET_TIME_UNIT_FOREVER_ABS; 1364 *deadline = GNUNET_TIME_UNIT_FOREVER_ABS;
@@ -1366,6 +1370,11 @@ batch_message (struct Neighbour *n,
1366 retry_time->value); 1370 retry_time->value);
1367 return 0; 1371 return 0;
1368 } 1372 }
1373 ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND);
1374 ntm->distance = htonl (n->last_distance);
1375 ntm->latency = GNUNET_TIME_relative_hton (n->last_latency);
1376 ntm->peer = n->peer;
1377
1369 pos = n->messages; 1378 pos = n->messages;
1370 prev = NULL; 1379 prev = NULL;
1371 while ((pos != NULL) && (size >= sizeof (struct GNUNET_MessageHeader))) 1380 while ((pos != NULL) && (size >= sizeof (struct GNUNET_MessageHeader)))
@@ -1374,6 +1383,33 @@ batch_message (struct Neighbour *n,
1374 if (GNUNET_YES == pos->do_transmit) 1383 if (GNUNET_YES == pos->do_transmit)
1375 { 1384 {
1376 GNUNET_assert (pos->size <= size); 1385 GNUNET_assert (pos->size <= size);
1386 /* do notifications */
1387 /* FIXME: track if we have *any* client that wants
1388 full notifications and only do this if that is
1389 actually true */
1390 if (pos->size < GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct NotifyTrafficMessage))
1391 {
1392 memcpy (&ntm[1], &pos[1], pos->size);
1393 ntm->header.size = htons (sizeof (struct NotifyTrafficMessage) +
1394 sizeof (struct GNUNET_MessageHeader));
1395 send_to_all_clients (&ntm->header,
1396 GNUNET_YES,
1397 GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
1398 }
1399 else
1400 {
1401 /* message too large for 'full' notifications, we do at
1402 least the 'hdr' type */
1403 memcpy (&ntm[1],
1404 &pos[1],
1405 sizeof (struct GNUNET_MessageHeader));
1406 }
1407 ntm->header.size = htons (sizeof (struct NotifyTrafficMessage) +
1408 pos->size);
1409 send_to_all_clients (&ntm->header,
1410 GNUNET_YES,
1411 GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
1412 /* copy for encrypted transmission */
1377 memcpy (&buf[ret], &pos[1], pos->size); 1413 memcpy (&buf[ret], &pos[1], pos->size);
1378 ret += pos->size; 1414 ret += pos->size;
1379 size -= pos->size; 1415 size -= pos->size;
@@ -3096,17 +3132,6 @@ run (void *cls,
3096 "CORE", 3132 "CORE",
3097 "TOTAL_QUOTA_OUT", 3133 "TOTAL_QUOTA_OUT",
3098 &bandwidth_target_out)) || 3134 &bandwidth_target_out)) ||
3099#if 0
3100 (GNUNET_OK !=
3101 GNUNET_CONFIGURATION_get_value_number (c,
3102 "CORE",
3103 "YY",
3104 &qout)) ||
3105 (GNUNET_OK !=
3106 GNUNET_CONFIGURATION_get_value_number (c,
3107 "CORE",
3108 "ZZ_LIMIT", &tneigh)) ||
3109#endif
3110 (GNUNET_OK != 3135 (GNUNET_OK !=
3111 GNUNET_CONFIGURATION_get_value_filename (c, 3136 GNUNET_CONFIGURATION_get_value_filename (c,
3112 "GNUNETD", 3137 "GNUNETD",
@@ -3132,7 +3157,8 @@ run (void *cls,
3132 sizeof (my_public_key), &my_identity.hashPubKey); 3157 sizeof (my_public_key), &my_identity.hashPubKey);
3133 /* setup notification */ 3158 /* setup notification */
3134 server = serv; 3159 server = serv;
3135 notifier = GNUNET_SERVER_notification_context_create (server, 0); 3160 notifier = GNUNET_SERVER_notification_context_create (server,
3161 MAX_NOTIFY_QUEUE);
3136 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); 3162 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
3137 /* setup transport connection */ 3163 /* setup transport connection */
3138 transport = GNUNET_TRANSPORT_connect (sched, 3164 transport = GNUNET_TRANSPORT_connect (sched,
diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h
index d35e6fb85..af431ba56 100644
--- a/src/include/gnunet_core_service.h
+++ b/src/include/gnunet_core_service.h
@@ -148,8 +148,15 @@ typedef void
148 148
149 149
150/** 150/**
151 * Connect to the core service. Note that the connection may 151 * Connect to the core service. Note that the connection may complete
152 * complete (or fail) asynchronously. 152 * (or fail) asynchronously. This function primarily causes the given
153 * callback notification functions to be invoked whenever the
154 * specified event happens. The maximum number of queued
155 * notifications (queue length) is per client but the queue is shared
156 * across all types of notifications. So a slow client that registers
157 * for 'outbound_notify' also risks missing 'inbound_notify' messages.
158 * Certain events (such as connect/disconnect notifications) are not
159 * subject to queue size limitations.
153 * 160 *
154 * @param sched scheduler to use 161 * @param sched scheduler to use
155 * @param cfg configuration to use 162 * @param cfg configuration to use
@@ -161,14 +168,29 @@ typedef void
161 * @param connects function to call on peer connect, can be NULL 168 * @param connects function to call on peer connect, can be NULL
162 * @param disconnects function to call on peer disconnect / timeout, can be NULL 169 * @param disconnects function to call on peer disconnect / timeout, can be NULL
163 * @param inbound_notify function to call for all inbound messages, can be NULL 170 * @param inbound_notify function to call for all inbound messages, can be NULL
171 * note that the core is allowed to drop notifications about inbound
172 * messages if the client does not process them fast enough (for this
173 * notification type, a bounded queue is used)
164 * @param inbound_hdr_only set to GNUNET_YES if inbound_notify will only read the 174 * @param inbound_hdr_only set to GNUNET_YES if inbound_notify will only read the
165 * GNUNET_MessageHeader and hence we do not need to give it the full message; 175 * GNUNET_MessageHeader and hence we do not need to give it the full message;
166 * can be used to improve efficiency, ignored if inbound_notify is NULLL 176 * can be used to improve efficiency, ignored if inbound_notify is NULL
167 * @param outbound_notify function to call for all outbound messages, can be NULL 177 * note that the core is allowed to drop notifications about inbound
178 * messages if the client does not process them fast enough (for this
179 * notification type, a bounded queue is used)
180 * @param outbound_notify function to call for all outbound messages, can be NULL;
181 * note that the core is allowed to drop notifications about outbound
182 * messages if the client does not process them fast enough (for this
183 * notification type, a bounded queue is used)
168 * @param outbound_hdr_only set to GNUNET_YES if outbound_notify will only read the 184 * @param outbound_hdr_only set to GNUNET_YES if outbound_notify will only read the
169 * GNUNET_MessageHeader and hence we do not need to give it the full message 185 * GNUNET_MessageHeader and hence we do not need to give it the full message
170 * can be used to improve efficiency, ignored if outbound_notify is NULLL 186 * can be used to improve efficiency, ignored if outbound_notify is NULL
187 * note that the core is allowed to drop notifications about outbound
188 * messages if the client does not process them fast enough (for this
189 * notification type, a bounded queue is used)
171 * @param handlers callbacks for messages we care about, NULL-terminated 190 * @param handlers callbacks for messages we care about, NULL-terminated
191 * note that the core is allowed to drop notifications about inbound
192 * messages if the client does not process them fast enough (for this
193 * notification type, a bounded queue is used)
172 * @return handle to the core service (only useful for disconnect until 'init' is called), 194 * @return handle to the core service (only useful for disconnect until 'init' is called),
173 * NULL on error (in this case, init is never called) 195 * NULL on error (in this case, init is never called)
174 */ 196 */