aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_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/transport/transport_api.c
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/transport/transport_api.c')
-rw-r--r--src/transport/transport_api.c85
1 files changed, 38 insertions, 47 deletions
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c
index 2cdaacad6..b732871ca 100644
--- a/src/transport/transport_api.c
+++ b/src/transport/transport_api.c
@@ -304,8 +304,8 @@ static void schedule_transmission (struct GNUNET_TRANSPORT_Handle *h);
304 * 304 *
305 * @param h transport service to reconnect 305 * @param h transport service to reconnect
306 */ 306 */
307static void 307static void disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle
308disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h); 308 *h);
309 309
310 310
311/** 311/**
@@ -335,8 +335,8 @@ neighbour_add (struct GNUNET_TRANSPORT_Handle *h,
335 struct Neighbour *n; 335 struct Neighbour *n;
336 336
337#if DEBUG_TRANSPORT 337#if DEBUG_TRANSPORT
338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating entry for neighbour `%4s'.\n",
339 "Creating entry for neighbour `%4s'.\n", GNUNET_i2s (pid)); 339 GNUNET_i2s (pid));
340#endif 340#endif
341 n = GNUNET_malloc (sizeof (struct Neighbour)); 341 n = GNUNET_malloc (sizeof (struct Neighbour));
342 n->id = *pid; 342 n->id = *pid;
@@ -347,8 +347,7 @@ neighbour_add (struct GNUNET_TRANSPORT_Handle *h,
347 MAX_BANDWIDTH_CARRY_S); 347 MAX_BANDWIDTH_CARRY_S);
348 GNUNET_assert (GNUNET_OK == 348 GNUNET_assert (GNUNET_OK ==
349 GNUNET_CONTAINER_multihashmap_put (h->neighbours, 349 GNUNET_CONTAINER_multihashmap_put (h->neighbours,
350 &pid->hashPubKey, 350 &pid->hashPubKey, n,
351 n,
352 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 351 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
353 return n; 352 return n;
354} 353}
@@ -375,8 +374,8 @@ neighbour_delete (void *cls, const GNUNET_HashCode * key, void *value)
375 GNUNET_assert (NULL == n->th); 374 GNUNET_assert (NULL == n->th);
376 GNUNET_assert (NULL == n->hn); 375 GNUNET_assert (NULL == n->hn);
377 GNUNET_assert (GNUNET_YES == 376 GNUNET_assert (GNUNET_YES ==
378 GNUNET_CONTAINER_multihashmap_remove (handle->neighbours, 377 GNUNET_CONTAINER_multihashmap_remove (handle->neighbours, key,
379 key, n)); 378 n));
380 GNUNET_free (n); 379 GNUNET_free (n);
381 return GNUNET_YES; 380 return GNUNET_YES;
382} 381}
@@ -414,8 +413,8 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
414 disconnect_and_schedule_reconnect (h); 413 disconnect_and_schedule_reconnect (h);
415 return; 414 return;
416 } 415 }
417 GNUNET_CLIENT_receive (h->client, 416 GNUNET_CLIENT_receive (h->client, &demultiplexer, h,
418 &demultiplexer, h, GNUNET_TIME_UNIT_FOREVER_REL); 417 GNUNET_TIME_UNIT_FOREVER_REL);
419 size = ntohs (msg->size); 418 size = ntohs (msg->size);
420 switch (ntohs (msg->type)) 419 switch (ntohs (msg->type))
421 { 420 {
@@ -428,8 +427,8 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
428 } 427 }
429#if DEBUG_TRANSPORT 428#if DEBUG_TRANSPORT
430 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
431 "Receiving (my own) `%s' message, I am `%4s'.\n", 430 "Receiving (my own) `%s' message, I am `%4s'.\n", "HELLO",
432 "HELLO", GNUNET_i2s (&me)); 431 GNUNET_i2s (&me));
433#endif 432#endif
434 GNUNET_free_non_null (h->my_hello); 433 GNUNET_free_non_null (h->my_hello);
435 h->my_hello = NULL; 434 h->my_hello = NULL;
@@ -465,8 +464,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
465 break; 464 break;
466 } 465 }
467#if DEBUG_TRANSPORT 466#if DEBUG_TRANSPORT
468 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message for `%4s'.\n",
469 "Receiving `%s' message for `%4s'.\n",
470 "CONNECT", GNUNET_i2s (&cim->id)); 468 "CONNECT", GNUNET_i2s (&cim->id));
471#endif 469#endif
472 n = neighbour_find (h, &cim->id); 470 n = neighbour_find (h, &cim->id);
@@ -488,8 +486,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
488 dim = (const struct DisconnectInfoMessage *) msg; 486 dim = (const struct DisconnectInfoMessage *) msg;
489 GNUNET_break (ntohl (dim->reserved) == 0); 487 GNUNET_break (ntohl (dim->reserved) == 0);
490#if DEBUG_TRANSPORT_DISCONNECT 488#if DEBUG_TRANSPORT_DISCONNECT
491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message for `%4s'.\n",
492 "Receiving `%s' message for `%4s'.\n",
493 "DISCONNECT", GNUNET_i2s (&dim->peer)); 490 "DISCONNECT", GNUNET_i2s (&dim->peer));
494#endif 491#endif
495 n = neighbour_find (h, &dim->peer); 492 n = neighbour_find (h, &dim->peer);
@@ -551,8 +548,8 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
551 } 548 }
552#if DEBUG_TRANSPORT 549#if DEBUG_TRANSPORT
553 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
554 "Received message of type %u from `%4s'.\n", 551 "Received message of type %u from `%4s'.\n", ntohs (imm->type),
555 ntohs (imm->type), GNUNET_i2s (&im->peer)); 552 GNUNET_i2s (&im->peer));
556#endif 553#endif
557 n = neighbour_find (h, &im->peer); 554 n = neighbour_find (h, &im->peer);
558 if (n == NULL) 555 if (n == NULL)
@@ -565,8 +562,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
565 break; 562 break;
566 default: 563 default:
567 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 564 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
568 _ 565 _("Received unexpected message of type %u in %s:%u\n"),
569 ("Received unexpected message of type %u in %s:%u\n"),
570 ntohs (msg->type), __FILE__, __LINE__); 566 ntohs (msg->type), __FILE__, __LINE__);
571 GNUNET_break (0); 567 GNUNET_break (0);
572 break; 568 break;
@@ -663,17 +659,17 @@ transport_notify_ready (void *cls, size_t size, void *buf)
663 th = n->th; 659 th = n->th;
664 if (th->notify_size + sizeof (struct OutboundMessage) > size) 660 if (th->notify_size + sizeof (struct OutboundMessage) > size)
665 break; /* does not fit */ 661 break; /* does not fit */
666 if (GNUNET_BANDWIDTH_tracker_get_delay 662 if (GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, th->notify_size).
667 (&n->out_tracker, th->notify_size).rel_value > 0) 663 rel_value > 0)
668 break; /* too early */ 664 break; /* too early */
669 GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap)); 665 GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap));
670 n->hn = NULL; 666 n->hn = NULL;
671 n->th = NULL; 667 n->th = NULL;
672 n->is_ready = GNUNET_NO; 668 n->is_ready = GNUNET_NO;
673 GNUNET_assert (size >= sizeof (struct OutboundMessage)); 669 GNUNET_assert (size >= sizeof (struct OutboundMessage));
674 mret = th->notify (th->notify_cls, 670 mret =
675 size - sizeof (struct OutboundMessage), 671 th->notify (th->notify_cls, size - sizeof (struct OutboundMessage),
676 &cbuf[ret + sizeof (struct OutboundMessage)]); 672 &cbuf[ret + sizeof (struct OutboundMessage)]);
677 GNUNET_assert (mret <= size - sizeof (struct OutboundMessage)); 673 GNUNET_assert (mret <= size - sizeof (struct OutboundMessage));
678 if (mret != 0) 674 if (mret != 0)
679 { 675 {
@@ -756,11 +752,10 @@ schedule_transmission_task (void *cls,
756 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling notify_transmit_ready\n"); 752 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling notify_transmit_ready\n");
757#endif 753#endif
758 h->cth = 754 h->cth =
759 GNUNET_CLIENT_notify_transmit_ready (h->client, 755 GNUNET_CLIENT_notify_transmit_ready (h->client, size,
760 size,
761 GNUNET_TIME_UNIT_FOREVER_REL, 756 GNUNET_TIME_UNIT_FOREVER_REL,
762 GNUNET_NO, 757 GNUNET_NO, &transport_notify_ready,
763 &transport_notify_ready, h); 758 h);
764 GNUNET_assert (NULL != h->cth); 759 GNUNET_assert (NULL != h->cth);
765} 760}
766 761
@@ -794,8 +789,8 @@ schedule_transmission (struct GNUNET_TRANSPORT_Handle *h)
794 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 789 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
795 "Scheduling next transmission to service in %llu ms\n", 790 "Scheduling next transmission to service in %llu ms\n",
796 (unsigned long long) delay.rel_value); 791 (unsigned long long) delay.rel_value);
797 h->quota_task = GNUNET_SCHEDULER_add_delayed (delay, 792 h->quota_task =
798 &schedule_transmission_task, h); 793 GNUNET_SCHEDULER_add_delayed (delay, &schedule_transmission_task, h);
799} 794}
800 795
801 796
@@ -809,8 +804,7 @@ schedule_transmission (struct GNUNET_TRANSPORT_Handle *h)
809 * @param notify_cls closure for notify 804 * @param notify_cls closure for notify
810 */ 805 */
811static void 806static void
812schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h, 807schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h, size_t size,
813 size_t size,
814 GNUNET_CONNECTION_TransmitReadyNotify notify, 808 GNUNET_CONNECTION_TransmitReadyNotify notify,
815 void *notify_cls) 809 void *notify_cls)
816{ 810{
@@ -861,8 +855,8 @@ send_start (void *cls, size_t size, void *buf)
861 s.do_check = htonl (h->check_self); 855 s.do_check = htonl (h->check_self);
862 s.self = h->self; 856 s.self = h->self;
863 memcpy (buf, &s, sizeof (struct StartMessage)); 857 memcpy (buf, &s, sizeof (struct StartMessage));
864 GNUNET_CLIENT_receive (h->client, 858 GNUNET_CLIENT_receive (h->client, &demultiplexer, h,
865 &demultiplexer, h, GNUNET_TIME_UNIT_FOREVER_REL); 859 GNUNET_TIME_UNIT_FOREVER_REL);
866 return sizeof (struct StartMessage); 860 return sizeof (struct StartMessage);
867} 861}
868 862
@@ -936,8 +930,8 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h)
936 "Scheduling task to reconnect to transport service in %llu ms.\n", 930 "Scheduling task to reconnect to transport service in %llu ms.\n",
937 h->reconnect_delay.rel_value); 931 h->reconnect_delay.rel_value);
938#endif 932#endif
939 h->reconnect_task 933 h->reconnect_task =
940 = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); 934 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
941 if (h->reconnect_delay.rel_value == 0) 935 if (h->reconnect_delay.rel_value == 0)
942 { 936 {
943 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS; 937 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
@@ -945,8 +939,8 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h)
945 else 939 else
946 { 940 {
947 h->reconnect_delay = GNUNET_TIME_relative_multiply (h->reconnect_delay, 2); 941 h->reconnect_delay = GNUNET_TIME_relative_multiply (h->reconnect_delay, 2);
948 h->reconnect_delay = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, 942 h->reconnect_delay =
949 h->reconnect_delay); 943 GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, h->reconnect_delay);
950 } 944 }
951} 945}
952 946
@@ -990,8 +984,8 @@ send_set_quota (void *cls, size_t size, void *buf)
990 } 984 }
991#if DEBUG_TRANSPORT 985#if DEBUG_TRANSPORT
992 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 986 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
993 "Transmitting `%s' request with respect to `%4s'.\n", 987 "Transmitting `%s' request with respect to `%4s'.\n", "SET_QUOTA",
994 "SET_QUOTA", GNUNET_i2s (&sqc->target)); 988 GNUNET_i2s (&sqc->target));
995#endif 989#endif
996 GNUNET_assert (size >= sizeof (struct QuotaSetMessage)); 990 GNUNET_assert (size >= sizeof (struct QuotaSetMessage));
997 msg.header.size = htons (sizeof (struct QuotaSetMessage)); 991 msg.header.size = htons (sizeof (struct QuotaSetMessage));
@@ -1038,8 +1032,7 @@ GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle,
1038 (unsigned int) n->out_tracker.available_bytes_per_s__, 1032 (unsigned int) n->out_tracker.available_bytes_per_s__,
1039 (unsigned int) ntohl (quota_out.value__), GNUNET_i2s (target)); 1033 (unsigned int) ntohl (quota_out.value__), GNUNET_i2s (target));
1040 else 1034 else
1041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Quota remains at %u for peer `%s'\n",
1042 "Quota remains at %u for peer `%s'\n",
1043 (unsigned int) n->out_tracker.available_bytes_per_s__, 1036 (unsigned int) n->out_tracker.available_bytes_per_s__,
1044 GNUNET_i2s (target)); 1037 GNUNET_i2s (target));
1045#endif 1038#endif
@@ -1047,8 +1040,7 @@ GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle,
1047 sqc = GNUNET_malloc (sizeof (struct SetQuotaContext)); 1040 sqc = GNUNET_malloc (sizeof (struct SetQuotaContext));
1048 sqc->target = *target; 1041 sqc->target = *target;
1049 sqc->quota_in = quota_in; 1042 sqc->quota_in = quota_in;
1050 schedule_control_transmit (handle, 1043 schedule_control_transmit (handle, sizeof (struct QuotaSetMessage),
1051 sizeof (struct QuotaSetMessage),
1052 &send_set_quota, sqc); 1044 &send_set_quota, sqc);
1053} 1045}
1054 1046
@@ -1257,8 +1249,7 @@ GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_Handle *handle,
1257 */ 1249 */
1258struct GNUNET_TRANSPORT_Handle * 1250struct GNUNET_TRANSPORT_Handle *
1259GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 1251GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1260 const struct GNUNET_PeerIdentity *self, 1252 const struct GNUNET_PeerIdentity *self, void *cls,
1261 void *cls,
1262 GNUNET_TRANSPORT_ReceiveCallback rec, 1253 GNUNET_TRANSPORT_ReceiveCallback rec,
1263 GNUNET_TRANSPORT_NotifyConnect nc, 1254 GNUNET_TRANSPORT_NotifyConnect nc,
1264 GNUNET_TRANSPORT_NotifyDisconnect nd) 1255 GNUNET_TRANSPORT_NotifyDisconnect nd)