aboutsummaryrefslogtreecommitdiff
path: root/src/core/gnunet-service-core_neighbours.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-02-09 19:15:47 +0000
committerChristian Grothoff <christian@grothoff.org>2014-02-09 19:15:47 +0000
commit09104d9e153cfce464ef38cda9ccbba4b029ae11 (patch)
tree4e31100cf6f0bd5ef925bd40a27abc96bbed4601 /src/core/gnunet-service-core_neighbours.c
parentcca6080579e6c7b1be3bff72a31a528779177fb6 (diff)
downloadgnunet-09104d9e153cfce464ef38cda9ccbba4b029ae11.tar.gz
gnunet-09104d9e153cfce464ef38cda9ccbba4b029ae11.zip
implement #3295: only transmit background traffic if there is excess bandwidth
Diffstat (limited to 'src/core/gnunet-service-core_neighbours.c')
-rw-r--r--src/core/gnunet-service-core_neighbours.c67
1 files changed, 61 insertions, 6 deletions
diff --git a/src/core/gnunet-service-core_neighbours.c b/src/core/gnunet-service-core_neighbours.c
index ddca0859a..aa5b6121e 100644
--- a/src/core/gnunet-service-core_neighbours.c
+++ b/src/core/gnunet-service-core_neighbours.c
@@ -105,6 +105,11 @@ struct Neighbour
105 */ 105 */
106 GNUNET_SCHEDULER_TaskIdentifier retry_plaintext_task; 106 GNUNET_SCHEDULER_TaskIdentifier retry_plaintext_task;
107 107
108 /**
109 * #GNUNET_YES if this peer currently has excess bandwidth.
110 */
111 int has_excess_bandwidth;
112
108}; 113};
109 114
110 115
@@ -213,13 +218,13 @@ transmit_ready (void *cls, size_t size, void *buf)
213 218
214 n->th = NULL; 219 n->th = NULL;
215 m = n->message_head; 220 m = n->message_head;
216 if (m == NULL) 221 if (NULL == m)
217 { 222 {
218 GNUNET_break (0); 223 GNUNET_break (0);
219 return 0; 224 return 0;
220 } 225 }
221 GNUNET_CONTAINER_DLL_remove (n->message_head, n->message_tail, m); 226 GNUNET_CONTAINER_DLL_remove (n->message_head, n->message_tail, m);
222 if (buf == NULL) 227 if (NULL == buf)
223 { 228 {
224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
225 "Transmission of message of type %u and size %u failed\n", 230 "Transmission of message of type %u and size %u failed\n",
@@ -240,6 +245,7 @@ transmit_ready (void *cls, size_t size, void *buf)
240 ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), 245 ntohs (((struct GNUNET_MessageHeader *) &m[1])->type),
241 (unsigned int) ret, GNUNET_i2s (&n->peer)); 246 (unsigned int) ret, GNUNET_i2s (&n->peer));
242 GNUNET_free (m); 247 GNUNET_free (m);
248 n->has_excess_bandwidth = GNUNET_NO;
243 process_queue (n); 249 process_queue (n);
244 GNUNET_STATISTICS_update (GSC_stats, 250 GNUNET_STATISTICS_update (GSC_stats,
245 gettext_noop 251 gettext_noop
@@ -450,6 +456,54 @@ GSC_NEIGHBOURS_transmit (const struct GNUNET_PeerIdentity *target,
450 456
451 457
452/** 458/**
459 * One of our neighbours has excess bandwidth,
460 * remember this.
461 *
462 * @param cls NULL
463 * @param pid identity of the peer with excess bandwidth
464 */
465static void
466handle_transport_notify_excess_bw (void *cls,
467 const struct GNUNET_PeerIdentity *pid)
468{
469 struct Neighbour *n;
470
471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
472 "Peer %s has excess bandwidth available\n",
473 GNUNET_i2s (pid));
474 n = find_neighbour (pid);
475 if (NULL == n)
476 {
477 GNUNET_break (0);
478 return;
479 }
480 n->has_excess_bandwidth = GNUNET_YES;
481 GSC_SESSIONS_solicit (pid);
482}
483
484
485/**
486 * Check if the given neighbour has excess bandwidth available.
487 *
488 * @param target neighbour to check
489 * @return #GNUNET_YES if excess bandwidth is available, #GNUNET_NO if not
490 */
491int
492GSC_NEIGHBOURS_check_excess_bandwidth (const struct GNUNET_PeerIdentity *target)
493{
494 struct Neighbour *n;
495
496 n = find_neighbour (target);
497 if (NULL == n)
498 {
499 GNUNET_break (0);
500 return GNUNET_SYSERR;
501 }
502 return n->has_excess_bandwidth;
503}
504
505
506/**
453 * Initialize neighbours subsystem. 507 * Initialize neighbours subsystem.
454 */ 508 */
455int 509int
@@ -457,10 +511,11 @@ GSC_NEIGHBOURS_init ()
457{ 511{
458 neighbours = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); 512 neighbours = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
459 transport = 513 transport =
460 GNUNET_TRANSPORT_connect (GSC_cfg, &GSC_my_identity, NULL, 514 GNUNET_TRANSPORT_connect2 (GSC_cfg, &GSC_my_identity, NULL,
461 &handle_transport_receive, 515 &handle_transport_receive,
462 &handle_transport_notify_connect, 516 &handle_transport_notify_connect,
463 &handle_transport_notify_disconnect); 517 &handle_transport_notify_disconnect,
518 &handle_transport_notify_excess_bw);
464 if (NULL == transport) 519 if (NULL == transport)
465 { 520 {
466 GNUNET_CONTAINER_multipeermap_destroy (neighbours); 521 GNUNET_CONTAINER_multipeermap_destroy (neighbours);