diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-11-15 23:24:08 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-11-15 23:24:08 +0100 |
commit | 84d51248d563d4187fc5414fbe795a5a4e284262 (patch) | |
tree | fdab79094163b761c403c600337e9f3a8d763e85 /src | |
parent | 92b7e711f94b4cba262992965a59c67d1fffb046 (diff) | |
download | gnunet-84d51248d563d4187fc5414fbe795a5a4e284262.tar.gz gnunet-84d51248d563d4187fc5414fbe795a5a4e284262.zip |
handle addr add/remove messages
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/gnunet-service-tng.c | 143 |
1 files changed, 114 insertions, 29 deletions
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c index 1e638377a..555210585 100644 --- a/src/transport/gnunet-service-tng.c +++ b/src/transport/gnunet-service-tng.c | |||
@@ -120,6 +120,11 @@ struct Queue | |||
120 | struct TransportClient *tc; | 120 | struct TransportClient *tc; |
121 | 121 | ||
122 | /** | 122 | /** |
123 | * Address served by the queue. | ||
124 | */ | ||
125 | const char *address; | ||
126 | |||
127 | /** | ||
123 | * Unique identifier of this queue with the communicator. | 128 | * Unique identifier of this queue with the communicator. |
124 | */ | 129 | */ |
125 | uint32_t qid; | 130 | uint32_t qid; |
@@ -128,11 +133,6 @@ struct Queue | |||
128 | * Network type offered by this queue. | 133 | * Network type offered by this queue. |
129 | */ | 134 | */ |
130 | enum GNUNET_ATS_Network_Type nt; | 135 | enum GNUNET_ATS_Network_Type nt; |
131 | |||
132 | /** | ||
133 | * Address served by the queue. | ||
134 | */ | ||
135 | const char *address; | ||
136 | }; | 136 | }; |
137 | 137 | ||
138 | 138 | ||
@@ -166,7 +166,7 @@ struct Neighbour | |||
166 | * Tail of DLL of queues to this peer. | 166 | * Tail of DLL of queues to this peer. |
167 | */ | 167 | */ |
168 | struct Queue *queue_tail; | 168 | struct Queue *queue_tail; |
169 | 169 | ||
170 | }; | 170 | }; |
171 | 171 | ||
172 | 172 | ||
@@ -209,7 +209,52 @@ struct PendingMessage | |||
209 | * Size of the original message. | 209 | * Size of the original message. |
210 | */ | 210 | */ |
211 | uint32_t bytes_msg; | 211 | uint32_t bytes_msg; |
212 | 212 | ||
213 | }; | ||
214 | |||
215 | |||
216 | /** | ||
217 | * One of the addresses of this peer. | ||
218 | */ | ||
219 | struct AddressListEntry | ||
220 | { | ||
221 | |||
222 | /** | ||
223 | * Kept in a DLL. | ||
224 | */ | ||
225 | struct AddressListEntry *next; | ||
226 | |||
227 | /** | ||
228 | * Kept in a DLL. | ||
229 | */ | ||
230 | struct AddressListEntry *prev; | ||
231 | |||
232 | /** | ||
233 | * Which communicator provides this address? | ||
234 | */ | ||
235 | struct TransportClient *tc; | ||
236 | |||
237 | /** | ||
238 | * The actual address. | ||
239 | */ | ||
240 | const char *address; | ||
241 | |||
242 | /** | ||
243 | * What is a typical lifetime the communicator expects this | ||
244 | * address to have? (Always from now.) | ||
245 | */ | ||
246 | struct GNUNET_TIME_Relative expiration; | ||
247 | |||
248 | /** | ||
249 | * Address identifier used by the communicator. | ||
250 | */ | ||
251 | uint32_t aid; | ||
252 | |||
253 | /** | ||
254 | * Network type offered by this address. | ||
255 | */ | ||
256 | enum GNUNET_ATS_Network_Type nt; | ||
257 | |||
213 | }; | 258 | }; |
214 | 259 | ||
215 | 260 | ||
@@ -261,14 +306,14 @@ struct TransportClient | |||
261 | * Tail of list of messages pending for this client. | 306 | * Tail of list of messages pending for this client. |
262 | */ | 307 | */ |
263 | struct PendingMessage *pending_msg_tail; | 308 | struct PendingMessage *pending_msg_tail; |
264 | 309 | ||
265 | } core; | 310 | } core; |
266 | 311 | ||
267 | /** | 312 | /** |
268 | * Information for @e type #CT_MONITOR. | 313 | * Information for @e type #CT_MONITOR. |
269 | */ | 314 | */ |
270 | struct { | 315 | struct { |
271 | 316 | ||
272 | /** | 317 | /** |
273 | * Peer identity to monitor the addresses of. | 318 | * Peer identity to monitor the addresses of. |
274 | * Zero to monitor all neighbours. Valid if | 319 | * Zero to monitor all neighbours. Valid if |
@@ -280,30 +325,40 @@ struct TransportClient | |||
280 | * Is this a one-shot monitor? | 325 | * Is this a one-shot monitor? |
281 | */ | 326 | */ |
282 | int one_shot; | 327 | int one_shot; |
283 | 328 | ||
284 | } monitor; | 329 | } monitor; |
285 | 330 | ||
286 | 331 | ||
287 | /** | 332 | /** |
288 | * Information for @e type #CT_COMMUNICATOR. | 333 | * Information for @e type #CT_COMMUNICATOR. |
289 | */ | 334 | */ |
290 | struct { | 335 | struct { |
291 | /** | 336 | /** |
292 | * If @e type is #CT_COMMUNICATOR, this communicator | 337 | * If @e type is #CT_COMMUNICATOR, this communicator |
293 | * supports communicating using these addresses. | 338 | * supports communicating using these addresses. |
294 | */ | 339 | */ |
295 | char *address_prefix; | 340 | char *address_prefix; |
296 | 341 | ||
297 | /** | 342 | /** |
298 | * Head of DLL of queues offered by this communicator. | 343 | * Head of DLL of queues offered by this communicator. |
299 | */ | 344 | */ |
300 | struct Queue *queue_head; | 345 | struct Queue *queue_head; |
301 | 346 | ||
302 | /** | 347 | /** |
303 | * Tail of DLL of queues offered by this communicator. | 348 | * Tail of DLL of queues offered by this communicator. |
304 | */ | 349 | */ |
305 | struct Queue *queue_tail; | 350 | struct Queue *queue_tail; |
306 | 351 | ||
352 | /** | ||
353 | * Head of list of the addresses of this peer offered by this communicator. | ||
354 | */ | ||
355 | struct AddressListEntry *addr_head; | ||
356 | |||
357 | /** | ||
358 | * Tail of list of the addresses of this peer offered by this communicator. | ||
359 | */ | ||
360 | struct AddressListEntry *addr_tail; | ||
361 | |||
307 | } communicator; | 362 | } communicator; |
308 | 363 | ||
309 | } details; | 364 | } details; |
@@ -491,7 +546,7 @@ check_client_send (void *cls, | |||
491 | struct TransportClient *tc = cls; | 546 | struct TransportClient *tc = cls; |
492 | uint16_t size; | 547 | uint16_t size; |
493 | const struct GNUNET_MessageHeader *obmm; | 548 | const struct GNUNET_MessageHeader *obmm; |
494 | 549 | ||
495 | if (CT_CORE != tc->type) | 550 | if (CT_CORE != tc->type) |
496 | { | 551 | { |
497 | GNUNET_break (0); | 552 | GNUNET_break (0); |
@@ -514,7 +569,7 @@ check_client_send (void *cls, | |||
514 | 569 | ||
515 | 570 | ||
516 | /** | 571 | /** |
517 | * Send a response to the @a pm that we have processed a | 572 | * Send a response to the @a pm that we have processed a |
518 | * "send" request with status @a success. We | 573 | * "send" request with status @a success. We |
519 | * transmitted @a bytes_physical on the actual wire. | 574 | * transmitted @a bytes_physical on the actual wire. |
520 | * Sends a confirmation to the "core" client responsible | 575 | * Sends a confirmation to the "core" client responsible |
@@ -586,7 +641,7 @@ handle_client_send (void *cls, | |||
586 | as this should be rare. */ | 641 | as this should be rare. */ |
587 | struct GNUNET_MQ_Envelope *env; | 642 | struct GNUNET_MQ_Envelope *env; |
588 | struct SendOkMessage *som; | 643 | struct SendOkMessage *som; |
589 | 644 | ||
590 | env = GNUNET_MQ_msg (som, | 645 | env = GNUNET_MQ_msg (som, |
591 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); | 646 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); |
592 | som->success = htonl (GNUNET_SYSERR); | 647 | som->success = htonl (GNUNET_SYSERR); |
@@ -601,7 +656,7 @@ handle_client_send (void *cls, | |||
601 | 1, | 656 | 1, |
602 | GNUNET_NO); | 657 | GNUNET_NO); |
603 | return; | 658 | return; |
604 | } | 659 | } |
605 | pm = GNUNET_new (struct PendingMessage); | 660 | pm = GNUNET_new (struct PendingMessage); |
606 | pm->client = tc; | 661 | pm->client = tc; |
607 | pm->target = target; | 662 | pm->target = target; |
@@ -721,7 +776,23 @@ handle_add_address (void *cls, | |||
721 | const struct GNUNET_TRANSPORT_AddAddressMessage *aam) | 776 | const struct GNUNET_TRANSPORT_AddAddressMessage *aam) |
722 | { | 777 | { |
723 | struct TransportClient *tc = cls; | 778 | struct TransportClient *tc = cls; |
724 | 779 | struct AddressListEntry *ale; | |
780 | size_t slen; | ||
781 | |||
782 | slen = ntohs (aam->header.size) - sizeof (*aam); | ||
783 | ale = GNUNET_malloc (sizeof (struct AddressListEntry) + slen); | ||
784 | ale->tc = tc; | ||
785 | ale->address = (const char *) &ale[1]; | ||
786 | ale->expiration = GNUNET_TIME_relative_ntoh (aam->expiration); | ||
787 | ale->aid = aam->aid; | ||
788 | ale->nt = (enum GNUNET_ATS_Network_Type) ntohl (aam->nt); | ||
789 | memcpy (&ale[1], | ||
790 | &aam[1], | ||
791 | slen); | ||
792 | GNUNET_CONTAINER_DLL_insert (tc->details.communicator.addr_head, | ||
793 | tc->details.communicator.addr_tail, | ||
794 | ale); | ||
795 | // FIXME: notify somebody?! | ||
725 | GNUNET_SERVICE_client_continue (tc->client); | 796 | GNUNET_SERVICE_client_continue (tc->client); |
726 | } | 797 | } |
727 | 798 | ||
@@ -744,8 +815,22 @@ handle_del_address (void *cls, | |||
744 | GNUNET_SERVICE_client_drop (tc->client); | 815 | GNUNET_SERVICE_client_drop (tc->client); |
745 | return; | 816 | return; |
746 | } | 817 | } |
747 | 818 | for (struct AddressListEntry *ale = tc->details.communicator.addr_head; | |
748 | GNUNET_SERVICE_client_continue (tc->client); | 819 | NULL != ale; |
820 | ale = ale->next) | ||
821 | { | ||
822 | if (dam->aid != ale->aid) | ||
823 | continue; | ||
824 | GNUNET_assert (ale->tc == tc); | ||
825 | GNUNET_CONTAINER_DLL_remove (tc->details.communicator.addr_head, | ||
826 | tc->details.communicator.addr_tail, | ||
827 | ale); | ||
828 | // FIXME: notify somebody? | ||
829 | GNUNET_free (ale); | ||
830 | GNUNET_SERVICE_client_continue (tc->client); | ||
831 | } | ||
832 | GNUNET_break (0); | ||
833 | GNUNET_SERVICE_client_drop (tc->client); | ||
749 | } | 834 | } |
750 | 835 | ||
751 | 836 | ||
@@ -861,11 +946,11 @@ handle_add_queue_message (void *cls, | |||
861 | &neighbour->pid, | 946 | &neighbour->pid, |
862 | neighbour, | 947 | neighbour, |
863 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 948 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
864 | // FIXME: notify cores/monitors! | 949 | // FIXME: notify ATS/COREs/monitors! |
865 | } | 950 | } |
866 | addr_len = ntohs (aqm->header.size) - sizeof (*aqm); | 951 | addr_len = ntohs (aqm->header.size) - sizeof (*aqm); |
867 | addr = (const char *) &aqm[1]; | 952 | addr = (const char *) &aqm[1]; |
868 | 953 | ||
869 | queue = GNUNET_malloc (sizeof (struct Queue) + addr_len); | 954 | queue = GNUNET_malloc (sizeof (struct Queue) + addr_len); |
870 | queue->qid = aqm->qid; | 955 | queue->qid = aqm->qid; |
871 | queue->nt = (enum GNUNET_ATS_Network_Type) ntohl (aqm->nt); | 956 | queue->nt = (enum GNUNET_ATS_Network_Type) ntohl (aqm->nt); |
@@ -948,7 +1033,7 @@ handle_del_queue_message (void *cls, | |||
948 | // FIXME: notify cores/monitors! | 1033 | // FIXME: notify cores/monitors! |
949 | free_neighbour (neighbour); | 1034 | free_neighbour (neighbour); |
950 | } | 1035 | } |
951 | GNUNET_SERVICE_client_continue (tc->client); | 1036 | GNUNET_SERVICE_client_continue (tc->client); |
952 | return; | 1037 | return; |
953 | } | 1038 | } |
954 | GNUNET_break (0); | 1039 | GNUNET_break (0); |
@@ -1020,10 +1105,10 @@ free_neighbour_cb (void *cls, | |||
1020 | struct Neighbour *neighbour = value; | 1105 | struct Neighbour *neighbour = value; |
1021 | 1106 | ||
1022 | (void) cls; | 1107 | (void) cls; |
1023 | (void) pid; | 1108 | (void) pid; |
1024 | GNUNET_break (0); // should this ever happen? | 1109 | GNUNET_break (0); // should this ever happen? |
1025 | free_neighbour (neighbour); | 1110 | free_neighbour (neighbour); |
1026 | 1111 | ||
1027 | return GNUNET_OK; | 1112 | return GNUNET_OK; |
1028 | } | 1113 | } |
1029 | 1114 | ||
@@ -1077,8 +1162,8 @@ run (void *cls, | |||
1077 | GST_my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (GST_cfg); | 1162 | GST_my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (GST_cfg); |
1078 | if (NULL == GST_my_private_key) | 1163 | if (NULL == GST_my_private_key) |
1079 | { | 1164 | { |
1080 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1165 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1081 | _("Transport service is lacking key configuration settings. Exiting.\n")); | 1166 | _("Transport service is lacking key configuration settings. Exiting.\n")); |
1082 | GNUNET_SCHEDULER_shutdown (); | 1167 | GNUNET_SCHEDULER_shutdown (); |
1083 | return; | 1168 | return; |
1084 | } | 1169 | } |