diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-08-08 10:31:02 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-08-08 10:31:02 +0000 |
commit | bda5bf075b7a03ce193ab99f74cb1853e110602d (patch) | |
tree | 4d7f4f6d1b9a972e901fa316c7de2bcca4003f01 /src/transport/transport_api.c | |
parent | c5847f5ae64f1cca69a6e78add37f52fa8b0607e (diff) | |
download | gnunet-bda5bf075b7a03ce193ab99f74cb1853e110602d.tar.gz gnunet-bda5bf075b7a03ce193ab99f74cb1853e110602d.zip |
callback for offer_hello
Diffstat (limited to 'src/transport/transport_api.c')
-rw-r--r-- | src/transport/transport_api.c | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index 7d57d3eb1..49a885c73 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c | |||
@@ -999,6 +999,15 @@ GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle, | |||
999 | } | 999 | } |
1000 | 1000 | ||
1001 | 1001 | ||
1002 | struct SendHelloContext | ||
1003 | { | ||
1004 | GNUNET_SCHEDULER_Task cont; | ||
1005 | |||
1006 | void *cls; | ||
1007 | |||
1008 | struct GNUNET_MessageHeader *msg; | ||
1009 | }; | ||
1010 | |||
1002 | /** | 1011 | /** |
1003 | * Send HELLO message to the service. | 1012 | * Send HELLO message to the service. |
1004 | * | 1013 | * |
@@ -1010,14 +1019,21 @@ GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle, | |||
1010 | static size_t | 1019 | static size_t |
1011 | send_hello (void *cls, size_t size, void *buf) | 1020 | send_hello (void *cls, size_t size, void *buf) |
1012 | { | 1021 | { |
1013 | struct GNUNET_MessageHeader *msg = cls; | 1022 | struct SendHelloContext *shc = cls; |
1023 | struct GNUNET_MessageHeader *msg = shc->msg; | ||
1014 | uint16_t ssize; | 1024 | uint16_t ssize; |
1025 | struct GNUNET_SCHEDULER_TaskContext tc; | ||
1015 | 1026 | ||
1016 | if (buf == NULL) | 1027 | if (buf == NULL) |
1017 | { | 1028 | { |
1018 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1029 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1019 | "Timeout while trying to transmit `%s' request.\n", "HELLO"); | 1030 | "Timeout while trying to transmit `%s' request.\n", "HELLO"); |
1031 | tc.read_ready = NULL; | ||
1032 | tc.write_ready = NULL; | ||
1033 | tc.reason = GNUNET_SCHEDULER_REASON_TIMEOUT; | ||
1034 | shc->cont (shc->cls, &tc); | ||
1020 | GNUNET_free (msg); | 1035 | GNUNET_free (msg); |
1036 | GNUNET_free (shc); | ||
1021 | return 0; | 1037 | return 0; |
1022 | } | 1038 | } |
1023 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "HELLO"); | 1039 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "HELLO"); |
@@ -1025,6 +1041,11 @@ send_hello (void *cls, size_t size, void *buf) | |||
1025 | GNUNET_assert (size >= ssize); | 1041 | GNUNET_assert (size >= ssize); |
1026 | memcpy (buf, msg, ssize); | 1042 | memcpy (buf, msg, ssize); |
1027 | GNUNET_free (msg); | 1043 | GNUNET_free (msg); |
1044 | tc.read_ready = NULL; | ||
1045 | tc.write_ready = NULL; | ||
1046 | tc.reason = GNUNET_SCHEDULER_REASON_READ_READY; | ||
1047 | shc->cont (shc->cls, &tc); | ||
1048 | GNUNET_free (shc); | ||
1028 | return ssize; | 1049 | return ssize; |
1029 | } | 1050 | } |
1030 | 1051 | ||
@@ -1036,7 +1057,9 @@ send_hello (void *cls, size_t size, void *buf) | |||
1036 | * | 1057 | * |
1037 | * @param handle connection to transport service | 1058 | * @param handle connection to transport service |
1038 | * @param hello the hello message | 1059 | * @param hello the hello message |
1039 | * @param cont continuation to call when HELLO has been sent | 1060 | * @param cont continuation to call when HELLO has been sent, |
1061 | * tc reason GNUNET_SCHEDULER_REASON_TIMEOUT for fail | ||
1062 | * tc reasong GNUNET_SCHEDULER_REASON_READY for success | ||
1040 | * @param cls closure for continuation | 1063 | * @param cls closure for continuation |
1041 | * | 1064 | * |
1042 | */ | 1065 | */ |
@@ -1048,9 +1071,17 @@ GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle, | |||
1048 | uint16_t size; | 1071 | uint16_t size; |
1049 | struct GNUNET_PeerIdentity peer; | 1072 | struct GNUNET_PeerIdentity peer; |
1050 | struct GNUNET_MessageHeader *msg; | 1073 | struct GNUNET_MessageHeader *msg; |
1074 | struct SendHelloContext * shc; | ||
1075 | struct GNUNET_SCHEDULER_TaskContext tc; | ||
1051 | 1076 | ||
1052 | if (NULL == handle->client) | 1077 | if (NULL == handle->client) |
1078 | { | ||
1079 | tc.read_ready = NULL; | ||
1080 | tc.write_ready = NULL; | ||
1081 | tc.reason = GNUNET_SCHEDULER_REASON_TIMEOUT; | ||
1082 | cont (cls, &tc); | ||
1053 | return; | 1083 | return; |
1084 | } | ||
1054 | GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO); | 1085 | GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO); |
1055 | size = ntohs (hello->size); | 1086 | size = ntohs (hello->size); |
1056 | GNUNET_break (size >= sizeof (struct GNUNET_MessageHeader)); | 1087 | GNUNET_break (size >= sizeof (struct GNUNET_MessageHeader)); |
@@ -1058,6 +1089,10 @@ GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle, | |||
1058 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hello, &peer)) | 1089 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hello, &peer)) |
1059 | { | 1090 | { |
1060 | GNUNET_break (0); | 1091 | GNUNET_break (0); |
1092 | tc.read_ready = NULL; | ||
1093 | tc.write_ready = NULL; | ||
1094 | tc.reason = GNUNET_SCHEDULER_REASON_TIMEOUT; | ||
1095 | cont (cls, &tc); | ||
1061 | return; | 1096 | return; |
1062 | } | 1097 | } |
1063 | msg = GNUNET_malloc (size); | 1098 | msg = GNUNET_malloc (size); |
@@ -1065,7 +1100,11 @@ GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle, | |||
1065 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1100 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1066 | "Offering `%s' message of `%4s' to transport for validation.\n", "HELLO", | 1101 | "Offering `%s' message of `%4s' to transport for validation.\n", "HELLO", |
1067 | GNUNET_i2s (&peer)); | 1102 | GNUNET_i2s (&peer)); |
1068 | schedule_control_transmit (handle, size, &send_hello, msg); | 1103 | shc = GNUNET_malloc (sizeof (struct SendHelloContext)); |
1104 | shc->msg = msg; | ||
1105 | shc->cont = cont; | ||
1106 | shc->cls = cls; | ||
1107 | schedule_control_transmit (handle, size, &send_hello, shc); | ||
1069 | } | 1108 | } |
1070 | 1109 | ||
1071 | 1110 | ||