diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-07 14:19:27 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-07 14:19:27 +0000 |
commit | 4dca0c9b28d2115a936b05582618f2285022089a (patch) | |
tree | f420b7d11245d6f23b5eeb4b8fecb1f8758fa0b2 /src/transport/gnunet-service-transport_neighbours.c | |
parent | 7ba6e451d50e4a9388e80c4082ab79ce1ddefbf8 (diff) | |
download | gnunet-4dca0c9b28d2115a936b05582618f2285022089a.tar.gz gnunet-4dca0c9b28d2115a936b05582618f2285022089a.zip |
stuff
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours.c | 185 |
1 files changed, 48 insertions, 137 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index ab82153dd..6be718d91 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c | |||
@@ -216,6 +216,12 @@ struct NeighbourMapEntry | |||
216 | */ | 216 | */ |
217 | int in_disconnect; | 217 | int in_disconnect; |
218 | 218 | ||
219 | /** | ||
220 | * Do we currently consider this neighbour connected? (as far as | ||
221 | * the connect/disconnect callbacks are concerned)? | ||
222 | */ | ||
223 | int is_connected; | ||
224 | |||
219 | }; | 225 | }; |
220 | 226 | ||
221 | 227 | ||
@@ -264,11 +270,9 @@ lookup_neighbour (const struct GNUNET_PeerIdentity *pid) | |||
264 | static void | 270 | static void |
265 | try_transmission_to_peer (struct NeighbourMapEntry *n) | 271 | try_transmission_to_peer (struct NeighbourMapEntry *n) |
266 | { | 272 | { |
267 | struct ReadyList *rl; | ||
268 | struct MessageQueue *mq; | 273 | struct MessageQueue *mq; |
269 | struct GNUNET_TIME_Relative timeout; | 274 | struct GNUNET_TIME_Relative timeout; |
270 | ssize_t ret; | 275 | ssize_t ret; |
271 | int force_address; | ||
272 | 276 | ||
273 | if (n->messages_head == NULL) | 277 | if (n->messages_head == NULL) |
274 | { | 278 | { |
@@ -279,115 +283,21 @@ try_transmission_to_peer (struct NeighbourMapEntry *n) | |||
279 | #endif | 283 | #endif |
280 | return; /* nothing to do */ | 284 | return; /* nothing to do */ |
281 | } | 285 | } |
282 | rl = NULL; | ||
283 | mq = n->messages_head; | 286 | mq = n->messages_head; |
284 | force_address = GNUNET_YES; | ||
285 | if (mq->specific_address == NULL) | ||
286 | { | ||
287 | /* TODO: ADD ATS */ | ||
288 | mq->specific_address = get_preferred_ats_address(n); | ||
289 | GNUNET_STATISTICS_update (stats, | ||
290 | gettext_noop ("# transport selected peer address freely"), | ||
291 | 1, | ||
292 | GNUNET_NO); | ||
293 | force_address = GNUNET_NO; | ||
294 | } | ||
295 | if (mq->specific_address == NULL) | ||
296 | { | ||
297 | GNUNET_STATISTICS_update (stats, | ||
298 | gettext_noop ("# transport failed to selected peer address"), | ||
299 | 1, | ||
300 | GNUNET_NO); | ||
301 | timeout = GNUNET_TIME_absolute_get_remaining (mq->timeout); | ||
302 | if (timeout.rel_value == 0) | ||
303 | { | ||
304 | #if DEBUG_TRANSPORT | ||
305 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
306 | "No destination address available to transmit message of size %u to peer `%4s'\n", | ||
307 | mq->message_buf_size, | ||
308 | GNUNET_i2s (&mq->neighbour_id)); | ||
309 | #endif | ||
310 | GNUNET_STATISTICS_update (stats, | ||
311 | gettext_noop ("# bytes in message queue for other peers"), | ||
312 | - (int64_t) mq->message_buf_size, | ||
313 | GNUNET_NO); | ||
314 | GNUNET_STATISTICS_update (stats, | ||
315 | gettext_noop ("# bytes discarded (no destination address available)"), | ||
316 | mq->message_buf_size, | ||
317 | GNUNET_NO); | ||
318 | if (mq->client != NULL) | ||
319 | transmit_send_ok (mq->client, n, &n->id, GNUNET_NO); | ||
320 | GNUNET_CONTAINER_DLL_remove (n->messages_head, | ||
321 | n->messages_tail, | ||
322 | mq); | ||
323 | GNUNET_free (mq); | ||
324 | return; /* nobody ready */ | ||
325 | } | ||
326 | GNUNET_STATISTICS_update (stats, | ||
327 | gettext_noop ("# message delivery deferred (no address)"), | ||
328 | 1, | ||
329 | GNUNET_NO); | ||
330 | if (n->retry_task != GNUNET_SCHEDULER_NO_TASK) | ||
331 | GNUNET_SCHEDULER_cancel (n->retry_task); | ||
332 | n->retry_task = GNUNET_SCHEDULER_add_delayed (timeout, | ||
333 | &retry_transmission_task, | ||
334 | n); | ||
335 | #if DEBUG_TRANSPORT | ||
336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
337 | "No validated destination address available to transmit message of size %u to peer `%4s', will wait %llums to find an address.\n", | ||
338 | mq->message_buf_size, | ||
339 | GNUNET_i2s (&mq->neighbour_id), | ||
340 | timeout.rel_value); | ||
341 | #endif | ||
342 | /* FIXME: might want to trigger peerinfo lookup here | ||
343 | (unless that's already pending...) */ | ||
344 | return; | ||
345 | } | ||
346 | GNUNET_CONTAINER_DLL_remove (n->messages_head, | 287 | GNUNET_CONTAINER_DLL_remove (n->messages_head, |
347 | n->messages_tail, | 288 | n->messages_tail, |
348 | mq); | 289 | mq); |
349 | if (mq->specific_address->connected == GNUNET_NO) | 290 | ret = papi->send (papi->cls, |
350 | mq->specific_address->connect_attempts++; | 291 | &n->pid, |
351 | rl = mq->specific_address->ready_list; | 292 | mq->message_buf, |
352 | mq->plugin = rl->plugin; | 293 | mq->message_buf_size, |
353 | if (!mq->internal_msg) | 294 | mq->priority, |
354 | mq->specific_address->in_transmit = GNUNET_YES; | 295 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
355 | #if DEBUG_TRANSPORT | 296 | n->session, |
356 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 297 | n->addr, |
357 | "Sending message of size %u for `%4s' to `%s' via plugin `%s'\n", | 298 | n->addrlen, |
358 | mq->message_buf_size, | 299 | GNUNET_YES /*?*/, |
359 | GNUNET_i2s (&n->id), | 300 | &transmit_send_continuation, mq); |
360 | (mq->specific_address->addr != NULL) | ||
361 | ? a2s (mq->plugin->short_name, | ||
362 | mq->specific_address->addr, | ||
363 | mq->specific_address->addrlen) | ||
364 | : "<inbound>", | ||
365 | rl->plugin->short_name); | ||
366 | #endif | ||
367 | GNUNET_STATISTICS_update (stats, | ||
368 | gettext_noop ("# bytes in message queue for other peers"), | ||
369 | - (int64_t) mq->message_buf_size, | ||
370 | GNUNET_NO); | ||
371 | GNUNET_STATISTICS_update (stats, | ||
372 | gettext_noop ("# bytes pending with plugins"), | ||
373 | mq->message_buf_size, | ||
374 | GNUNET_NO); | ||
375 | |||
376 | GNUNET_CONTAINER_DLL_insert (n->cont_head, | ||
377 | n->cont_tail, | ||
378 | mq); | ||
379 | |||
380 | ret = rl->plugin->api->send (rl->plugin->api->cls, | ||
381 | &mq->neighbour_id, | ||
382 | mq->message_buf, | ||
383 | mq->message_buf_size, | ||
384 | mq->priority, | ||
385 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | ||
386 | mq->specific_address->session, | ||
387 | mq->specific_address->addr, | ||
388 | mq->specific_address->addrlen, | ||
389 | force_address, | ||
390 | &transmit_send_continuation, mq); | ||
391 | if (ret == -1) | 301 | if (ret == -1) |
392 | { | 302 | { |
393 | /* failure, but 'send' would not call continuation in this case, | 303 | /* failure, but 'send' would not call continuation in this case, |
@@ -777,32 +687,6 @@ GST_neighbours_iterate (GST_NeighbourIterator cb, | |||
777 | 687 | ||
778 | 688 | ||
779 | /** | 689 | /** |
780 | * We have received a PONG. Update lifeness of the neighbour. | ||
781 | * | ||
782 | * @param sender peer sending the PONG | ||
783 | * @param hdr the PONG message (presumably) | ||
784 | * @param plugin_name name of transport that delivered the PONG | ||
785 | * @param sender_address address of the other peer, NULL if other peer | ||
786 | * connected to us | ||
787 | * @param sender_address_len number of bytes in sender_address | ||
788 | * @param ats performance data | ||
789 | * @param ats_count number of entries in ats (excluding 0-termination) | ||
790 | * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not | ||
791 | */ | ||
792 | int | ||
793 | GST_neighbours_handle_pong (const struct GNUNET_PeerIdentity *sender, | ||
794 | const struct GNUNET_MessageHeader *hdr, | ||
795 | const char *plugin_name, | ||
796 | const void *sender_address, | ||
797 | size_t sender_address_len, | ||
798 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | ||
799 | uint32_t ats_count) | ||
800 | { | ||
801 | return GNUNET_SYSERR; | ||
802 | } | ||
803 | |||
804 | |||
805 | /** | ||
806 | * We have received a CONNECT. Set the peer to connected. | 690 | * We have received a CONNECT. Set the peer to connected. |
807 | * | 691 | * |
808 | * @param sender peer sending the PONG | 692 | * @param sender peer sending the PONG |
@@ -836,10 +720,14 @@ GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender, | |||
836 | } | 720 | } |
837 | n = lookup_neighbour (sender); | 721 | n = lookup_neighbour (sender); |
838 | if ( (NULL != n) || | 722 | if ( (NULL != n) || |
839 | (GNUNET_TIME_absolute_get_remaining (n->peer_timeout).rel_value > 0) ) | 723 | (n->is_connected == GNUNET_YES) ) |
840 | { | 724 | { |
841 | /* already connected */ | 725 | /* already connected */ |
842 | // FIXME: switch session!? | 726 | if (session != NULL) |
727 | { | ||
728 | // FIXME: ATS: switch session!? | ||
729 | // FIXME: merge/update ats? | ||
730 | } | ||
843 | return GNUNET_OK; | 731 | return GNUNET_OK; |
844 | } | 732 | } |
845 | if (n == NULL) | 733 | if (n == NULL) |
@@ -858,9 +746,32 @@ GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender, | |||
858 | &n->id.hashPubKey, | 746 | &n->id.hashPubKey, |
859 | n, | 747 | n, |
860 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 748 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
749 | if (NULL == ats) | ||
750 | { | ||
751 | GNUNET_array_grow (n->ats, | ||
752 | n->ats_count, | ||
753 | 1); | ||
754 | } | ||
755 | else | ||
756 | { | ||
757 | GNUNET_array_grow (n->ats, | ||
758 | n->ats_count, | ||
759 | ats_count); | ||
760 | memcpy (n->ats, | ||
761 | ats, | ||
762 | sizeof (struct GNUNET_TRANSPORT_ATS_Information) * ats_count); | ||
763 | } | ||
861 | } | 764 | } |
862 | // FIXME: mark connected, etc? | 765 | if (session != NULL) |
863 | 766 | { | |
767 | // FIXME: ATS: switch session!? | ||
768 | // n->session = session; | ||
769 | } | ||
770 | n->is_connected = GNUNET_YES; | ||
771 | connect_notify_cb (callback_cls, | ||
772 | sender, | ||
773 | n->ats, | ||
774 | n->ats_count); | ||
864 | return GNUNET_OK; | 775 | return GNUNET_OK; |
865 | } | 776 | } |
866 | 777 | ||