aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-service-fs_cp.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-03-23 17:21:14 +0000
committerChristian Grothoff <christian@grothoff.org>2015-03-23 17:21:14 +0000
commited51bc86aad5044b88ce4fc3641cc920c8186863 (patch)
treef266d6766c2571ad22e35e64b31b7f33272b4d40 /src/fs/gnunet-service-fs_cp.c
parent15b4998482d695ba26948a769f7ced4327ae8c05 (diff)
downloadgnunet-ed51bc86aad5044b88ce4fc3641cc920c8186863.tar.gz
gnunet-ed51bc86aad5044b88ce4fc3641cc920c8186863.zip
-doxygen and indentation
Diffstat (limited to 'src/fs/gnunet-service-fs_cp.c')
-rw-r--r--src/fs/gnunet-service-fs_cp.c92
1 files changed, 57 insertions, 35 deletions
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c
index eff8286fc..d866a003a 100644
--- a/src/fs/gnunet-service-fs_cp.c
+++ b/src/fs/gnunet-service-fs_cp.c
@@ -17,7 +17,6 @@
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20
21/** 20/**
22 * @file fs/gnunet-service-fs_cp.c 21 * @file fs/gnunet-service-fs_cp.c
23 * @brief API to handle 'connected peers' 22 * @brief API to handle 'connected peers'
@@ -286,19 +285,19 @@ struct GSF_ConnectedPeer
286 uint32_t disk_respect; 285 uint32_t disk_respect;
287 286
288 /** 287 /**
289 * Which offset in "last_p2p_replies" will be updated next? 288 * Which offset in @e last_p2p_replies will be updated next?
290 * (we go round-robin). 289 * (we go round-robin).
291 */ 290 */
292 unsigned int last_p2p_replies_woff; 291 unsigned int last_p2p_replies_woff;
293 292
294 /** 293 /**
295 * Which offset in "last_client_replies" will be updated next? 294 * Which offset in @e last_client_replies will be updated next?
296 * (we go round-robin). 295 * (we go round-robin).
297 */ 296 */
298 unsigned int last_client_replies_woff; 297 unsigned int last_client_replies_woff;
299 298
300 /** 299 /**
301 * Current offset into 'last_request_times' ring buffer. 300 * Current offset into @e last_request_times ring buffer.
302 */ 301 */
303 unsigned int last_request_times_off; 302 unsigned int last_request_times_off;
304 303
@@ -327,7 +326,7 @@ struct GSF_ConnectedPeer
327 326
328 327
329/** 328/**
330 * Map from peer identities to 'struct GSF_ConnectPeer' entries. 329 * Map from peer identities to `struct GSF_ConnectPeer` entries.
331 */ 330 */
332static struct GNUNET_CONTAINER_MultiPeerMap *cp_map; 331static struct GNUNET_CONTAINER_MultiPeerMap *cp_map;
333 332
@@ -352,7 +351,8 @@ GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id,
352 cp = GSF_peer_get_ (id); 351 cp = GSF_peer_get_ (id);
353 if (NULL == cp) 352 if (NULL == cp)
354 return; /* we're not yet connected at the core level, ignore */ 353 return; /* we're not yet connected at the core level, ignore */
355 GNUNET_LOAD_value_set_decline (cp->ppd.transmission_delay, latency); 354 GNUNET_LOAD_value_set_decline (cp->ppd.transmission_delay,
355 latency);
356} 356}
357 357
358 358
@@ -428,7 +428,8 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth)
428 cp->inc_preference = 0; 428 cp->inc_preference = 0;
429 } 429 }
430 430
431 if ((GNUNET_YES == pth->is_query) && (GNUNET_YES != pth->was_reserved)) 431 if ( (GNUNET_YES == pth->is_query) &&
432 (GNUNET_YES != pth->was_reserved) )
432 { 433 {
433 /* query, need reservation */ 434 /* query, need reservation */
434 if (GNUNET_YES != cp->did_reserve) 435 if (GNUNET_YES != cp->did_reserve)
@@ -436,9 +437,11 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth)
436 cp->did_reserve = GNUNET_NO; 437 cp->did_reserve = GNUNET_NO;
437 /* reservation already done! */ 438 /* reservation already done! */
438 pth->was_reserved = GNUNET_YES; 439 pth->was_reserved = GNUNET_YES;
439 cp->rc = 440 cp->rc = GNUNET_ATS_reserve_bandwidth (GSF_ats,
440 GNUNET_ATS_reserve_bandwidth (GSF_ats, &target, DBLOCK_SIZE, 441 &target,
441 &ats_reserve_callback, cp); 442 DBLOCK_SIZE,
443 &ats_reserve_callback,
444 cp);
442 return; 445 return;
443 } 446 }
444 GNUNET_assert (NULL == cp->cth); 447 GNUNET_assert (NULL == cp->cth);
@@ -447,8 +450,7 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth)
447 GNUNET_CORE_notify_transmit_ready (GSF_core, 450 GNUNET_CORE_notify_transmit_ready (GSF_core,
448 GNUNET_YES, 451 GNUNET_YES,
449 GNUNET_CORE_PRIO_BACKGROUND, 452 GNUNET_CORE_PRIO_BACKGROUND,
450 GNUNET_TIME_absolute_get_remaining 453 GNUNET_TIME_absolute_get_remaining (pth->timeout),
451 (pth->timeout),
452 &target, 454 &target,
453 pth->size, 455 pth->size,
454 &peer_transmit_ready_cb, cp); 456 &peer_transmit_ready_cb, cp);
@@ -495,7 +497,7 @@ peer_transmit_ready_cb (void *cls,
495 { 497 {
496 cp->ppd.last_request_times[(cp->last_request_times_off++) % 498 cp->ppd.last_request_times[(cp->last_request_times_off++) %
497 MAX_QUEUE_PER_PEER] = 499 MAX_QUEUE_PER_PEER] =
498 GNUNET_TIME_absolute_get (); 500 GNUNET_TIME_absolute_get ();
499 GNUNET_assert (0 < cp->ppd.pending_queries--); 501 GNUNET_assert (0 < cp->ppd.pending_queries--);
500 } 502 }
501 else if (GNUNET_NO == pth->is_query) 503 else if (GNUNET_NO == pth->is_query)
@@ -566,21 +568,28 @@ ats_reserve_callback (void *cls,
566 if (0 == amount) 568 if (0 == amount)
567 { 569 {
568 cp->rc_delay_task = 570 cp->rc_delay_task =
569 GNUNET_SCHEDULER_add_delayed (res_delay, &retry_reservation, cp); 571 GNUNET_SCHEDULER_add_delayed (res_delay,
572 &retry_reservation,
573 cp);
570 return; 574 return;
571 } 575 }
572 cp->did_reserve = GNUNET_YES; 576 cp->did_reserve = GNUNET_YES;
573 pth = cp->pth_head; 577 pth = cp->pth_head;
574 if ((NULL != pth) && (NULL == cp->cth) && (0 == cp->cth_in_progress)) 578 if ( (NULL != pth) &&
579 (NULL == cp->cth) &&
580 (0 == cp->cth_in_progress) )
575 { 581 {
576 /* reservation success, try transmission now! */ 582 /* reservation success, try transmission now! */
577 cp->cth_in_progress++; 583 cp->cth_in_progress++;
578 cp->cth = 584 cp->cth =
579 GNUNET_CORE_notify_transmit_ready (GSF_core, GNUNET_YES, 585 GNUNET_CORE_notify_transmit_ready (GSF_core,
586 GNUNET_YES,
580 GNUNET_CORE_PRIO_BACKGROUND, 587 GNUNET_CORE_PRIO_BACKGROUND,
581 GNUNET_TIME_absolute_get_remaining 588 GNUNET_TIME_absolute_get_remaining (pth->timeout),
582 (pth->timeout), peer, pth->size, 589 peer,
583 &peer_transmit_ready_cb, cp); 590 pth->size,
591 &peer_transmit_ready_cb,
592 cp);
584 GNUNET_assert (NULL != cp->cth); 593 GNUNET_assert (NULL != cp->cth);
585 GNUNET_assert (0 < cp->cth_in_progress--); 594 GNUNET_assert (0 < cp->cth_in_progress--);
586 } 595 }
@@ -764,14 +773,16 @@ copy_reply (void *cls,
764 size = ntohs (pm->header.size); 773 size = ntohs (pm->header.size);
765 memcpy (buf, pm, size); 774 memcpy (buf, pm, size);
766 GNUNET_STATISTICS_update (GSF_stats, 775 GNUNET_STATISTICS_update (GSF_stats,
767 gettext_noop 776 gettext_noop ("# replies transmitted to other peers"),
768 ("# replies transmitted to other peers"), 1, 777 1,
769 GNUNET_NO); 778 GNUNET_NO);
770 } 779 }
771 else 780 else
772 { 781 {
773 size = 0; 782 size = 0;
774 GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# replies dropped"), 1, 783 GNUNET_STATISTICS_update (GSF_stats,
784 gettext_noop ("# replies dropped"),
785 1,
775 GNUNET_NO); 786 GNUNET_NO);
776 } 787 }
777 GNUNET_free (pm); 788 GNUNET_free (pm);
@@ -1268,7 +1279,7 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1268 GNUNET_NO); 1279 GNUNET_NO);
1269 return NULL; 1280 return NULL;
1270 } 1281 }
1271 if (cp->ppd.pending_replies + cp->delay_queue_size > 128) 1282 if (cp->ppd.pending_replies + cp->delay_queue_size > MAX_QUEUE_PER_PEER)
1272 { 1283 {
1273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1274 "Peer `%s' has too many replies queued already. Dropping query.\n", 1285 "Peer `%s' has too many replies queued already. Dropping query.\n",
@@ -1334,8 +1345,9 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1334 ttl -= ttl_decrement; 1345 ttl -= ttl_decrement;
1335 1346
1336 /* test if the request already exists */ 1347 /* test if the request already exists */
1337 peerreq = GNUNET_CONTAINER_multihashmap_get (cp->request_map, &gm->query); 1348 peerreq = GNUNET_CONTAINER_multihashmap_get (cp->request_map,
1338 if (peerreq != NULL) 1349 &gm->query);
1350 if (NULL != peerreq)
1339 { 1351 {
1340 pr = peerreq->pr; 1352 pr = peerreq->pr;
1341 prd = GSF_pending_request_get_data_ (pr); 1353 prd = GSF_pending_request_get_data_ (pr);
@@ -1363,13 +1375,21 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1363 1375
1364 peerreq = GNUNET_new (struct PeerRequest); 1376 peerreq = GNUNET_new (struct PeerRequest);
1365 peerreq->cp = cp; 1377 peerreq->cp = cp;
1366 pr = GSF_pending_request_create_ (options, type, &gm->query, 1378 pr = GSF_pending_request_create_ (options,
1379 type,
1380 &gm->query,
1367 target, 1381 target,
1368 (bfsize > 1382 (bfsize > 0)
1369 0) ? (const char *) &opt[bits] : NULL, 1383 ? (const char *) &opt[bits]
1370 bfsize, ntohl (gm->filter_mutator), 1384 : NULL,
1371 1 /* anonymity */ , 1385 bfsize,
1372 (uint32_t) priority, ttl, spid, GNUNET_PEER_intern (other), NULL, 0, /* replies_seen */ 1386 ntohl (gm->filter_mutator),
1387 1 /* anonymity */,
1388 (uint32_t) priority,
1389 ttl,
1390 spid,
1391 GNUNET_PEER_intern (other),
1392 NULL, 0, /* replies_seen */
1373 &handle_p2p_reply, peerreq); 1393 &handle_p2p_reply, peerreq);
1374 GNUNET_assert (NULL != pr); 1394 GNUNET_assert (NULL != pr);
1375 peerreq->pr = pr; 1395 peerreq->pr = pr;
@@ -1881,12 +1901,13 @@ GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp,
1881 * @param tc task context, not used 1901 * @param tc task context, not used
1882 */ 1902 */
1883static void 1903static void
1884cron_flush_respect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1904cron_flush_respect (void *cls,
1905 const struct GNUNET_SCHEDULER_TaskContext *tc)
1885{ 1906{
1886
1887 if (NULL == cp_map) 1907 if (NULL == cp_map)
1888 return; 1908 return;
1889 GNUNET_CONTAINER_multipeermap_iterate (cp_map, &flush_respect, NULL); 1909 GNUNET_CONTAINER_multipeermap_iterate (cp_map,
1910 &flush_respect, NULL);
1890 if (NULL == tc) 1911 if (NULL == tc)
1891 return; 1912 return;
1892 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1913 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
@@ -1935,7 +1956,8 @@ void
1935GSF_connected_peer_done_ () 1956GSF_connected_peer_done_ ()
1936{ 1957{
1937 cron_flush_respect (NULL, NULL); 1958 cron_flush_respect (NULL, NULL);
1938 GNUNET_CONTAINER_multipeermap_iterate (cp_map, &clean_peer, NULL); 1959 GNUNET_CONTAINER_multipeermap_iterate (cp_map,
1960 &clean_peer, NULL);
1939 GNUNET_CONTAINER_multipeermap_destroy (cp_map); 1961 GNUNET_CONTAINER_multipeermap_destroy (cp_map);
1940 cp_map = NULL; 1962 cp_map = NULL;
1941 GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES); 1963 GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES);