aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2011-02-22 15:22:00 +0000
committerNathan S. Evans <evans@in.tum.de>2011-02-22 15:22:00 +0000
commit9173f13cc42380833bdb1ec3e3fcd0c971ddbe74 (patch)
treefa0b83d73bb760fc0ecd7d0ef60db44c7532a1c9 /src/transport/transport_api.c
parent7c0698d2296e00d9544f48819f24ed4319e3fad8 (diff)
downloadgnunet-9173f13cc42380833bdb1ec3e3fcd0c971ddbe74.tar.gz
gnunet-9173f13cc42380833bdb1ec3e3fcd0c971ddbe74.zip
Offer hello api change(!)
Diffstat (limited to 'src/transport/transport_api.c')
-rw-r--r--src/transport/transport_api.c64
1 files changed, 50 insertions, 14 deletions
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c
index ca2f2cc60..0246b8aec 100644
--- a/src/transport/transport_api.c
+++ b/src/transport/transport_api.c
@@ -395,6 +395,27 @@ struct GNUNET_TRANSPORT_Handle
395 int check_self; 395 int check_self;
396}; 396};
397 397
398struct HelloContext
399{
400
401 /**
402 * Size of the HELLO copied to end of struct.
403 */
404 uint16_t size;
405
406 /**
407 * Continuation to call once HELLO sent.
408 */
409 GNUNET_SCHEDULER_Task cont;
410
411 /**
412 * Closure to call with the continuation.
413 */
414 void *cont_cls;
415
416 /* HELLO */
417};
418
398 419
399/** 420/**
400 * Get the neighbour list entry for the given peer 421 * Get the neighbour list entry for the given peer
@@ -1039,9 +1060,8 @@ GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_Handle *handle,
1039static size_t 1060static size_t
1040send_hello (void *cls, size_t size, void *buf) 1061send_hello (void *cls, size_t size, void *buf)
1041{ 1062{
1042 struct GNUNET_MessageHeader *hello = cls; 1063 struct HelloContext *hc = cls;
1043 uint16_t msize; 1064 uint16_t ssize;
1044
1045 if (buf == NULL) 1065 if (buf == NULL)
1046 { 1066 {
1047#if DEBUG_TRANSPORT_TIMEOUT 1067#if DEBUG_TRANSPORT_TIMEOUT
@@ -1049,18 +1069,24 @@ send_hello (void *cls, size_t size, void *buf)
1049 "Timeout while trying to transmit `%s' request.\n", 1069 "Timeout while trying to transmit `%s' request.\n",
1050 "HELLO"); 1070 "HELLO");
1051#endif 1071#endif
1052 GNUNET_free (hello); 1072 GNUNET_SCHEDULER_add_now(hc->cont, hc->cont_cls);
1073 GNUNET_free (hc);
1053 return 0; 1074 return 0;
1054 } 1075 }
1055#if DEBUG_TRANSPORT 1076#if DEBUG_TRANSPORT
1056 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1077 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1057 "Transmitting `%s' request.\n", "HELLO"); 1078 "Transmitting `%s' request.\n", "HELLO");
1058#endif 1079#endif
1059 msize = ntohs (hello->size); 1080 GNUNET_assert (size >= hc->size);
1060 GNUNET_assert (size >= msize); 1081 memcpy (buf, &hc[1], hc->size);
1061 memcpy (buf, hello, msize); 1082
1062 GNUNET_free (hello); 1083 if (hc->cont != NULL)
1063 return msize; 1084 {
1085 GNUNET_SCHEDULER_add_continuation(hc->cont, hc->cont_cls, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1086 }
1087 ssize = hc->size;
1088 GNUNET_free (hc);
1089 return ssize;
1064} 1090}
1065 1091
1066 1092
@@ -1071,14 +1097,19 @@ send_hello (void *cls, size_t size, void *buf)
1071 * 1097 *
1072 * @param handle connection to transport service 1098 * @param handle connection to transport service
1073 * @param hello the hello message 1099 * @param hello the hello message
1100 * @param cont continuation to call when HELLO has been sent
1101 * @param cls closure for continuation
1102 *
1074 */ 1103 */
1075void 1104void
1076GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle, 1105GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
1077 const struct GNUNET_MessageHeader *hello) 1106 const struct GNUNET_MessageHeader *hello,
1107 GNUNET_SCHEDULER_Task cont,
1108 void *cls)
1078{ 1109{
1079 struct GNUNET_MessageHeader *hc;
1080 uint16_t size; 1110 uint16_t size;
1081 struct GNUNET_PeerIdentity peer; 1111 struct GNUNET_PeerIdentity peer;
1112 struct HelloContext *hc;
1082 1113
1083 GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO); 1114 GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO);
1084 size = ntohs (hello->size); 1115 size = ntohs (hello->size);
@@ -1089,14 +1120,19 @@ GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
1089 GNUNET_break (0); 1120 GNUNET_break (0);
1090 return; 1121 return;
1091 } 1122 }
1123 hc = GNUNET_malloc(sizeof(struct HelloContext) + size);
1124 hc->size = size;
1125 hc->cont = cont;
1126 hc->cont_cls = cls;
1127 memcpy (&hc[1], hello, size);
1128
1092#if DEBUG_TRANSPORT 1129#if DEBUG_TRANSPORT
1093 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1094 "Offering `%s' message of `%4s' to transport for validation.\n", 1131 "Offering `%s' message of `%4s' to transport for validation.\n",
1095 "HELLO", 1132 "HELLO",
1096 GNUNET_i2s (&peer)); 1133 GNUNET_i2s (&peer));
1097#endif 1134#endif
1098 hc = GNUNET_malloc (size); 1135
1099 memcpy (hc, hello, size);
1100 schedule_control_transmit (handle, 1136 schedule_control_transmit (handle,
1101 size, 1137 size,
1102 GNUNET_NO, OFFER_HELLO_TIMEOUT, &send_hello, hc); 1138 GNUNET_NO, OFFER_HELLO_TIMEOUT, &send_hello, hc);
@@ -1608,7 +1644,7 @@ GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle)
1608 "Disconnecting from transport service for good.\n"); 1644 "Disconnecting from transport service for good.\n");
1609#endif 1645#endif
1610 handle->client = NULL; 1646 handle->client = NULL;
1611 GNUNET_CLIENT_disconnect (client, GNUNET_NO); 1647 GNUNET_CLIENT_disconnect (client, GNUNET_YES);
1612 } 1648 }
1613 GNUNET_free (handle); 1649 GNUNET_free (handle);
1614} 1650}