aboutsummaryrefslogtreecommitdiff
path: root/src/core/core_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/core/core_api.c
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/core/core_api.c')
-rw-r--r--src/core/core_api.c109
1 files changed, 50 insertions, 59 deletions
diff --git a/src/core/core_api.c b/src/core/core_api.c
index c6fcc0b47..5ec48d68c 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -404,8 +404,8 @@ reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
404 * @return GNUNET_YES (continue) 404 * @return GNUNET_YES (continue)
405 */ 405 */
406static int 406static int
407disconnect_and_free_peer_entry (void *cls, 407disconnect_and_free_peer_entry (void *cls, const GNUNET_HashCode * key,
408 const GNUNET_HashCode * key, void *value) 408 void *value)
409{ 409{
410 static struct GNUNET_BANDWIDTH_Value32NBO zero; 410 static struct GNUNET_BANDWIDTH_Value32NBO zero;
411 struct GNUNET_CORE_Handle *h = cls; 411 struct GNUNET_CORE_Handle *h = cls;
@@ -485,8 +485,8 @@ reconnect_later (struct GNUNET_CORE_Handle *h)
485 } 485 }
486 h->currently_down = GNUNET_YES; 486 h->currently_down = GNUNET_YES;
487 GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK); 487 GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
488 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff, 488 h->reconnect_task =
489 &reconnect_task, h); 489 GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_task, h);
490 while (NULL != (cm = h->control_pending_head)) 490 while (NULL != (cm = h->control_pending_head))
491 { 491 {
492 GNUNET_CONTAINER_DLL_remove (h->control_pending_head, 492 GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
@@ -502,8 +502,8 @@ reconnect_later (struct GNUNET_CORE_Handle *h)
502 while (NULL != (pr = h->ready_peer_head)) 502 while (NULL != (pr = h->ready_peer_head))
503 GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr); 503 GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr);
504 GNUNET_assert (h->control_pending_head == NULL); 504 GNUNET_assert (h->control_pending_head == NULL);
505 h->retry_backoff = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, 505 h->retry_backoff =
506 h->retry_backoff); 506 GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, h->retry_backoff);
507 h->retry_backoff = GNUNET_TIME_relative_multiply (h->retry_backoff, 2); 507 h->retry_backoff = GNUNET_TIME_relative_multiply (h->retry_backoff, 2);
508} 508}
509 509
@@ -515,8 +515,8 @@ reconnect_later (struct GNUNET_CORE_Handle *h)
515 * @param h core handle 515 * @param h core handle
516 * @param ignore_currently_down transmit message even if not initialized? 516 * @param ignore_currently_down transmit message even if not initialized?
517 */ 517 */
518static void 518static void trigger_next_request (struct GNUNET_CORE_Handle *h,
519trigger_next_request (struct GNUNET_CORE_Handle *h, int ignore_currently_down); 519 int ignore_currently_down);
520 520
521 521
522/** 522/**
@@ -526,8 +526,9 @@ trigger_next_request (struct GNUNET_CORE_Handle *h, int ignore_currently_down);
526 * @param cls the transmit handle of the request that timed out 526 * @param cls the transmit handle of the request that timed out
527 * @param tc context, can be NULL (!) 527 * @param tc context, can be NULL (!)
528 */ 528 */
529static void 529static void transmission_timeout (void *cls,
530transmission_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 530 const struct GNUNET_SCHEDULER_TaskContext
531 *tc);
531 532
532 533
533/** 534/**
@@ -702,8 +703,9 @@ transmit_message (void *cls, size_t size, void *buf)
702 sm->peer = pr->peer; 703 sm->peer = pr->peer;
703 sm->cork = htonl ((uint32_t) th->cork); 704 sm->cork = htonl ((uint32_t) th->cork);
704 sm->reserved = htonl (0); 705 sm->reserved = htonl (0);
705 ret = th->get_message (th->get_message_cls, 706 ret =
706 size - sizeof (struct SendMessage), &sm[1]); 707 th->get_message (th->get_message_cls,
708 size - sizeof (struct SendMessage), &sm[1]);
707 709
708#if DEBUG_CORE 710#if DEBUG_CORE
709 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -774,8 +776,8 @@ trigger_next_request (struct GNUNET_CORE_Handle *h, int ignore_currently_down)
774 } 776 }
775 if (h->control_pending_head != NULL) 777 if (h->control_pending_head != NULL)
776 msize = 778 msize =
777 ntohs (((struct GNUNET_MessageHeader *) &h-> 779 ntohs (((struct GNUNET_MessageHeader *) &h->control_pending_head[1])->
778 control_pending_head[1])->size); 780 size);
779 else if (h->ready_peer_head != NULL) 781 else if (h->ready_peer_head != NULL)
780 msize = 782 msize =
781 h->ready_peer_head->pending_head->msize + sizeof (struct SendMessage); 783 h->ready_peer_head->pending_head->msize + sizeof (struct SendMessage);
@@ -787,11 +789,10 @@ trigger_next_request (struct GNUNET_CORE_Handle *h, int ignore_currently_down)
787#endif 789#endif
788 return; /* no pending message */ 790 return; /* no pending message */
789 } 791 }
790 h->cth = GNUNET_CLIENT_notify_transmit_ready (h->client, 792 h->cth =
791 msize, 793 GNUNET_CLIENT_notify_transmit_ready (h->client, msize,
792 GNUNET_TIME_UNIT_FOREVER_REL, 794 GNUNET_TIME_UNIT_FOREVER_REL,
793 GNUNET_NO, 795 GNUNET_NO, &transmit_message, h);
794 &transmit_message, h);
795} 796}
796 797
797 798
@@ -857,8 +858,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
857 } 858 }
858 h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS; 859 h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
859 GNUNET_CRYPTO_hash (&m->publicKey, 860 GNUNET_CRYPTO_hash (&m->publicKey,
860 sizeof (struct 861 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
861 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
862 &h->me.hashPubKey); 862 &h->me.hashPubKey);
863 if (NULL != (init = h->init)) 863 if (NULL != (init = h->init))
864 { 864 {
@@ -886,8 +886,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
886 pr->ch = h; 886 pr->ch = h;
887 GNUNET_assert (GNUNET_YES == 887 GNUNET_assert (GNUNET_YES ==
888 GNUNET_CONTAINER_multihashmap_put (h->peers, 888 GNUNET_CONTAINER_multihashmap_put (h->peers,
889 &h->me.hashPubKey, 889 &h->me.hashPubKey, pr,
890 pr,
891 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 890 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
892 if (NULL != h->connects) 891 if (NULL != h->connects)
893 h->connects (h->cls, &h->me, NULL); 892 h->connects (h->cls, &h->me, NULL);
@@ -934,8 +933,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
934 pr->ch = h; 933 pr->ch = h;
935 GNUNET_assert (GNUNET_YES == 934 GNUNET_assert (GNUNET_YES ==
936 GNUNET_CONTAINER_multihashmap_put (h->peers, 935 GNUNET_CONTAINER_multihashmap_put (h->peers,
937 &cnm->peer.hashPubKey, 936 &cnm->peer.hashPubKey, pr,
938 pr,
939 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 937 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
940 if (NULL != h->connects) 938 if (NULL != h->connects)
941 h->connects (h->cls, &cnm->peer, &cnm->ats); 939 h->connects (h->cls, &cnm->peer, &cnm->ats);
@@ -967,8 +965,8 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
967 reconnect_later (h); 965 reconnect_later (h);
968 return; 966 return;
969 } 967 }
970 trigger = ((pr->prev != NULL) || 968 trigger = ((pr->prev != NULL) || (pr->next != NULL) ||
971 (pr->next != NULL) || (h->ready_peer_head == pr)); 969 (h->ready_peer_head == pr));
972 disconnect_and_free_peer_entry (h, &dnm->peer.hashPubKey, pr); 970 disconnect_and_free_peer_entry (h, &dnm->peer.hashPubKey, pr);
973 if (trigger) 971 if (trigger)
974 trigger_next_request (h, GNUNET_NO); 972 trigger_next_request (h, GNUNET_NO);
@@ -1015,9 +1013,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
1015 reconnect_later (h); 1013 reconnect_later (h);
1016 return; 1014 return;
1017 } 1015 }
1018 h->status_events (h->cls, 1016 h->status_events (h->cls, &psnm->peer, psnm->bandwidth_in,
1019 &psnm->peer,
1020 psnm->bandwidth_in,
1021 psnm->bandwidth_out, 1017 psnm->bandwidth_out,
1022 GNUNET_TIME_absolute_ntoh (psnm->timeout), &psnm->ats); 1018 GNUNET_TIME_absolute_ntoh (psnm->timeout), &psnm->ats);
1023 break; 1019 break;
@@ -1056,7 +1052,8 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
1056 return; 1052 return;
1057 } 1053 }
1058 if ((GNUNET_NO == h->inbound_hdr_only) && 1054 if ((GNUNET_NO == h->inbound_hdr_only) &&
1059 (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage) + 1055 (msize !=
1056 ntohs (em->size) + sizeof (struct NotifyTrafficMessage) +
1060 +ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information))) 1057 +ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)))
1061 { 1058 {
1062 GNUNET_break (0); 1059 GNUNET_break (0);
@@ -1124,8 +1121,9 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
1124 GNUNET_i2s (&ntm->peer)); 1121 GNUNET_i2s (&ntm->peer));
1125#endif 1122#endif
1126 if ((GNUNET_NO == h->outbound_hdr_only) && 1123 if ((GNUNET_NO == h->outbound_hdr_only) &&
1127 (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage) 1124 (msize !=
1128 + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information))) 1125 ntohs (em->size) + sizeof (struct NotifyTrafficMessage) +
1126 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)))
1129 { 1127 {
1130 GNUNET_break (0); 1128 GNUNET_break (0);
1131 reconnect_later (h); 1129 reconnect_later (h);
@@ -1221,10 +1219,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
1221 GNUNET_free_non_null (pr->pcic_ptr); 1219 GNUNET_free_non_null (pr->pcic_ptr);
1222 pr->pcic_ptr = NULL; 1220 pr->pcic_ptr = NULL;
1223 if (pcic != NULL) 1221 if (pcic != NULL)
1224 pcic (pr->pcic_cls, 1222 pcic (pr->pcic_cls, &pr->peer, cim->bw_out, ntohl (cim->reserved_amount),
1225 &pr->peer,
1226 cim->bw_out,
1227 ntohl (cim->reserved_amount),
1228 GNUNET_TIME_relative_ntoh (cim->reserve_delay), 1223 GNUNET_TIME_relative_ntoh (cim->reserve_delay),
1229 GNUNET_ntohll (cim->preference)); 1224 GNUNET_ntohll (cim->preference));
1230 break; 1225 break;
@@ -1232,8 +1227,8 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
1232 reconnect_later (h); 1227 reconnect_later (h);
1233 return; 1228 return;
1234 } 1229 }
1235 GNUNET_CLIENT_receive (h->client, 1230 GNUNET_CLIENT_receive (h->client, &main_notify_handler, h,
1236 &main_notify_handler, h, GNUNET_TIME_UNIT_FOREVER_REL); 1231 GNUNET_TIME_UNIT_FOREVER_REL);
1237} 1232}
1238 1233
1239 1234
@@ -1261,8 +1256,8 @@ init_done_task (void *cls, int success)
1261 reconnect_later (h); 1256 reconnect_later (h);
1262 return; 1257 return;
1263 } 1258 }
1264 GNUNET_CLIENT_receive (h->client, 1259 GNUNET_CLIENT_receive (h->client, &main_notify_handler, h,
1265 &main_notify_handler, h, GNUNET_TIME_UNIT_FOREVER_REL); 1260 GNUNET_TIME_UNIT_FOREVER_REL);
1266} 1261}
1267 1262
1268 1263
@@ -1321,8 +1316,8 @@ reconnect (struct GNUNET_CORE_Handle *h)
1321 ts = (uint16_t *) & init[1]; 1316 ts = (uint16_t *) & init[1];
1322 for (hpos = 0; hpos < h->hcnt; hpos++) 1317 for (hpos = 0; hpos < h->hcnt; hpos++)
1323 ts[hpos] = htons (h->handlers[hpos].type); 1318 ts[hpos] = htons (h->handlers[hpos].type);
1324 GNUNET_CONTAINER_DLL_insert (h->control_pending_head, 1319 GNUNET_CONTAINER_DLL_insert (h->control_pending_head, h->control_pending_tail,
1325 h->control_pending_tail, cm); 1320 cm);
1326 trigger_next_request (h, GNUNET_YES); 1321 trigger_next_request (h, GNUNET_YES);
1327} 1322}
1328 1323
@@ -1354,8 +1349,7 @@ reconnect (struct GNUNET_CORE_Handle *h)
1354 */ 1349 */
1355struct GNUNET_CORE_Handle * 1350struct GNUNET_CORE_Handle *
1356GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 1351GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1357 unsigned int queue_size, 1352 unsigned int queue_size, void *cls,
1358 void *cls,
1359 GNUNET_CORE_StartupCallback init, 1353 GNUNET_CORE_StartupCallback init,
1360 GNUNET_CORE_ConnectEventHandler connects, 1354 GNUNET_CORE_ConnectEventHandler connects,
1361 GNUNET_CORE_DisconnectEventHandler disconnects, 1355 GNUNET_CORE_DisconnectEventHandler disconnects,
@@ -1485,8 +1479,7 @@ run_request_next_transmission (void *cls,
1485 * memory); if NULL is returned, "notify" will NOT be called. 1479 * memory); if NULL is returned, "notify" will NOT be called.
1486 */ 1480 */
1487struct GNUNET_CORE_TransmitHandle * 1481struct GNUNET_CORE_TransmitHandle *
1488GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, 1482GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, int cork,
1489 int cork,
1490 uint32_t priority, 1483 uint32_t priority,
1491 struct GNUNET_TIME_Relative maxdelay, 1484 struct GNUNET_TIME_Relative maxdelay,
1492 const struct GNUNET_PeerIdentity *target, 1485 const struct GNUNET_PeerIdentity *target,
@@ -1562,8 +1555,8 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
1562 /* Order entries by deadline, but SKIP 'HEAD' if 1555 /* Order entries by deadline, but SKIP 'HEAD' if
1563 * we're in the 'ready_peer_*' DLL */ 1556 * we're in the 'ready_peer_*' DLL */
1564 pos = pr->pending_head; 1557 pos = pr->pending_head;
1565 if ((pr->prev != NULL) || 1558 if ((pr->prev != NULL) || (pr->next != NULL) ||
1566 (pr->next != NULL) || (pr == handle->ready_peer_head)) 1559 (pr == handle->ready_peer_head))
1567 { 1560 {
1568 GNUNET_assert (pos != NULL); 1561 GNUNET_assert (pos != NULL);
1569 pos = pos->next; /* skip head */ 1562 pos = pos->next; /* skip head */
@@ -1576,17 +1569,16 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
1576 prev = pos; 1569 prev = pos;
1577 pos = pos->next; 1570 pos = pos->next;
1578 } 1571 }
1579 GNUNET_CONTAINER_DLL_insert_after (pr->pending_head, 1572 GNUNET_CONTAINER_DLL_insert_after (pr->pending_head, pr->pending_tail, prev,
1580 pr->pending_tail, prev, th); 1573 th);
1581 pr->queue_size++; 1574 pr->queue_size++;
1582 /* was the request queue previously empty? */ 1575 /* was the request queue previously empty? */
1583#if DEBUG_CORE 1576#if DEBUG_CORE
1584 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission request added to queue\n"); 1577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission request added to queue\n");
1585#endif 1578#endif
1586 if ((pr->pending_head == th) && 1579 if ((pr->pending_head == th) && (pr->ntr_task == GNUNET_SCHEDULER_NO_TASK) &&
1587 (pr->ntr_task == GNUNET_SCHEDULER_NO_TASK) && 1580 (pr->next == NULL) && (pr->prev == NULL) &&
1588 (pr->next == NULL) && 1581 (handle->ready_peer_head != pr))
1589 (pr->prev == NULL) && (handle->ready_peer_head != pr))
1590 pr->ntr_task = 1582 pr->ntr_task =
1591 GNUNET_SCHEDULER_add_now (&run_request_next_transmission, pr); 1583 GNUNET_SCHEDULER_add_now (&run_request_next_transmission, pr);
1592 return th; 1584 return th;
@@ -1760,8 +1752,8 @@ GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle
1760 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1752 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1761 "A CHANGE PREFERENCE request was cancelled!\n"); 1753 "A CHANGE PREFERENCE request was cancelled!\n");
1762#endif 1754#endif
1763 GNUNET_CONTAINER_DLL_remove (h->control_pending_head, 1755 GNUNET_CONTAINER_DLL_remove (h->control_pending_head, h->control_pending_tail,
1764 h->control_pending_tail, cm); 1756 cm);
1765 GNUNET_free (cm); 1757 GNUNET_free (cm);
1766 GNUNET_free (req); 1758 GNUNET_free (req);
1767} 1759}
@@ -1834,8 +1826,7 @@ GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h,
1834 const struct GNUNET_PeerIdentity *peer, 1826 const struct GNUNET_PeerIdentity *peer,
1835 struct GNUNET_TIME_Relative timeout, 1827 struct GNUNET_TIME_Relative timeout,
1836 struct GNUNET_BANDWIDTH_Value32NBO bw_out, 1828 struct GNUNET_BANDWIDTH_Value32NBO bw_out,
1837 int32_t amount, 1829 int32_t amount, uint64_t preference,
1838 uint64_t preference,
1839 GNUNET_CORE_PeerConfigurationInfoCallback 1830 GNUNET_CORE_PeerConfigurationInfoCallback
1840 info, void *info_cls) 1831 info, void *info_cls)
1841{ 1832{