diff options
Diffstat (limited to 'src/transport/transport_api2_communication.c')
-rw-r--r-- | src/transport/transport_api2_communication.c | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/src/transport/transport_api2_communication.c b/src/transport/transport_api2_communication.c index ffd7f208e..a8237f18f 100644 --- a/src/transport/transport_api2_communication.c +++ b/src/transport/transport_api2_communication.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "gnunet_util_lib.h" | 25 | #include "gnunet_util_lib.h" |
26 | #include "gnunet_protocols.h" | 26 | #include "gnunet_protocols.h" |
27 | #include "gnunet_transport_communication_service.h" | 27 | #include "gnunet_transport_communication_service.h" |
28 | #include "gnunet_ats_transport_service.h" | ||
28 | #include "transport.h" | 29 | #include "transport.h" |
29 | 30 | ||
30 | 31 | ||
@@ -178,6 +179,18 @@ struct GNUNET_TRANSPORT_CommunicatorHandle | |||
178 | void *mq_init_cls; | 179 | void *mq_init_cls; |
179 | 180 | ||
180 | /** | 181 | /** |
182 | * Function to call when the transport service receives messages | ||
183 | * for a communicator (i.e. for NAT traversal or for non-bidirectional | ||
184 | * communicators). | ||
185 | */ | ||
186 | GNUNET_TRANSPORT_CommunicatorNotify notify_cb; | ||
187 | |||
188 | /** | ||
189 | * Closure for @e notify_Cb. | ||
190 | */ | ||
191 | void *notify_cb_cls; | ||
192 | |||
193 | /** | ||
181 | * Queue to talk to the transport service. | 194 | * Queue to talk to the transport service. |
182 | */ | 195 | */ |
183 | struct GNUNET_MQ_Handle *mq; | 196 | struct GNUNET_MQ_Handle *mq; |
@@ -744,6 +757,7 @@ reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch) | |||
744 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG, | 757 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG, |
745 | struct GNUNET_TRANSPORT_SendMessageTo, | 758 | struct GNUNET_TRANSPORT_SendMessageTo, |
746 | ch), | 759 | ch), |
760 | // FIXME: handle backchannel notifications! | ||
747 | GNUNET_MQ_handler_end() | 761 | GNUNET_MQ_handler_end() |
748 | }; | 762 | }; |
749 | struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam; | 763 | struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam; |
@@ -790,6 +804,8 @@ reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch) | |||
790 | * the address of another peer, can be NULL if the | 804 | * the address of another peer, can be NULL if the |
791 | * communicator only supports receiving messages | 805 | * communicator only supports receiving messages |
792 | * @param mq_init_cls closure for @a mq_init | 806 | * @param mq_init_cls closure for @a mq_init |
807 | * @param notify_cb function to pass backchannel messages to communicator | ||
808 | * @param notify_cb_cls closure for @a notify_cb | ||
793 | * @return NULL on error | 809 | * @return NULL on error |
794 | */ | 810 | */ |
795 | struct GNUNET_TRANSPORT_CommunicatorHandle * | 811 | struct GNUNET_TRANSPORT_CommunicatorHandle * |
@@ -798,7 +814,9 @@ GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle | |||
798 | const char *addr_prefix, | 814 | const char *addr_prefix, |
799 | enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, | 815 | enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, |
800 | GNUNET_TRANSPORT_CommunicatorMqInit mq_init, | 816 | GNUNET_TRANSPORT_CommunicatorMqInit mq_init, |
801 | void *mq_init_cls) | 817 | void *mq_init_cls, |
818 | GNUNET_TRANSPORT_CommunicatorNotify notify_cb, | ||
819 | void *notify_cb_cls) | ||
802 | { | 820 | { |
803 | struct GNUNET_TRANSPORT_CommunicatorHandle *ch; | 821 | struct GNUNET_TRANSPORT_CommunicatorHandle *ch; |
804 | 822 | ||
@@ -808,6 +826,8 @@ GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle | |||
808 | ch->addr_prefix = addr_prefix; | 826 | ch->addr_prefix = addr_prefix; |
809 | ch->mq_init = mq_init; | 827 | ch->mq_init = mq_init; |
810 | ch->mq_init_cls = mq_init_cls; | 828 | ch->mq_init_cls = mq_init_cls; |
829 | ch->notify_cb = notify_cb; | ||
830 | ch->notify_cb_cls = notify_cb_cls; | ||
811 | ch->cc = cc; | 831 | ch->cc = cc; |
812 | reconnect (ch); | 832 | reconnect (ch); |
813 | if (GNUNET_OK != | 833 | if (GNUNET_OK != |
@@ -1041,4 +1061,48 @@ GNUNET_TRANSPORT_communicator_address_remove (struct GNUNET_TRANSPORT_AddressIde | |||
1041 | } | 1061 | } |
1042 | 1062 | ||
1043 | 1063 | ||
1064 | /* ************************* Backchannel *************************** */ | ||
1065 | |||
1066 | |||
1067 | /** | ||
1068 | * The communicator asks the transport service to route a message via | ||
1069 | * a different path to another communicator service at another peer. | ||
1070 | * This must only be done for special control traffic (as there is no | ||
1071 | * flow control for this API), such as acknowledgements, and generally | ||
1072 | * only be done if the communicator is uni-directional (i.e. cannot | ||
1073 | * send the message back itself). | ||
1074 | * | ||
1075 | * @param ch handle of this communicator | ||
1076 | * @param pid peer to send the message to | ||
1077 | * @param comm name of the communicator to send the message to | ||
1078 | * @param header header of the message to transmit and pass via the | ||
1079 | * notify-API to @a pid's communicator @a comm | ||
1080 | */ | ||
1081 | void | ||
1082 | GNUNET_TRANSPORT_communicator_notify (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, | ||
1083 | const struct GNUNET_PeerIdentity *pid, | ||
1084 | const char *comm, | ||
1085 | const struct GNUNET_MessageHeader *header) | ||
1086 | { | ||
1087 | struct GNUNET_MQ_Envelope *env; | ||
1088 | struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb; | ||
1089 | size_t slen = strlen (comm) + 1; | ||
1090 | uint16_t mlen = ntohs (header->size); | ||
1091 | |||
1092 | GNUNET_assert (mlen + slen + sizeof (*cb) < UINT16_MAX); | ||
1093 | env = GNUNET_MQ_msg_extra (cb, | ||
1094 | slen + mlen, | ||
1095 | GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL); | ||
1096 | cb->pid = *pid; | ||
1097 | memcpy (&cb[1], | ||
1098 | header, | ||
1099 | mlen); | ||
1100 | memcpy (((char *)&cb[1]) + mlen, | ||
1101 | comm, | ||
1102 | slen); | ||
1103 | GNUNET_MQ_send (ch->mq, | ||
1104 | env); | ||
1105 | } | ||
1106 | |||
1107 | |||
1044 | /* end of transport_api2_communication.c */ | 1108 | /* end of transport_api2_communication.c */ |