aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-07 13:37:05 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-07 13:37:05 +0000
commit7ba6e451d50e4a9388e80c4082ab79ce1ddefbf8 (patch)
tree557d80d62cdea177946f2b0d4b486543a5b2484e /src/transport
parent63760db5bbd9c8b5cc2552b9705141f0d696b5d1 (diff)
downloadgnunet-7ba6e451d50e4a9388e80c4082ab79ce1ddefbf8.tar.gz
gnunet-7ba6e451d50e4a9388e80c4082ab79ce1ddefbf8.zip
stuff
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport_clients.c2
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c276
-rw-r--r--src/transport/gnunet-service-transport_neighbours.h2
-rw-r--r--src/transport/gnunet-service-transport_validation.c3
-rw-r--r--src/transport/gnunet-service-transport_validation.h2
5 files changed, 174 insertions, 111 deletions
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
index 454f544fd..5136e03f1 100644
--- a/src/transport/gnunet-service-transport_clients.c
+++ b/src/transport/gnunet-service-transport_clients.c
@@ -591,6 +591,7 @@ GST_clients_handle_address_lookup (void *cls,
591 * Send an address to the client. 591 * Send an address to the client.
592 * 592 *
593 * @param cls our 'struct GNUNET_SERVER_TransmitContext' (for sending) 593 * @param cls our 'struct GNUNET_SERVER_TransmitContext' (for sending)
594 * @param public_key public key for the peer, never NULL
594 * @param target peer this change is about, never NULL 595 * @param target peer this change is about, never NULL
595 * @param valid_until until what time do we consider the address valid? 596 * @param valid_until until what time do we consider the address valid?
596 * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO) 597 * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO)
@@ -602,6 +603,7 @@ GST_clients_handle_address_lookup (void *cls,
602 */ 603 */
603static void 604static void
604send_address_to_client (void *cls, 605send_address_to_client (void *cls,
606 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
605 const struct GNUNET_PeerIdentity *target, 607 const struct GNUNET_PeerIdentity *target,
606 struct GNUNET_TIME_Absolute valid_until, 608 struct GNUNET_TIME_Absolute valid_until,
607 struct GNUNET_TIME_Absolute validation_block, 609 struct GNUNET_TIME_Absolute validation_block,
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 6f6b366c2..ab82153dd 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -25,9 +25,11 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet-service-transport_neighbours.h" 27#include "gnunet-service-transport_neighbours.h"
28#include "gnunet-service-transport_validation.h"
28#include "gnunet-service-transport.h" 29#include "gnunet-service-transport.h"
29#include "gnunet_peerinfo_service.h" 30#include "gnunet_peerinfo_service.h"
30#include "gnunet_constants.h" 31#include "gnunet_constants.h"
32#include "transport.h"
31 33
32 34
33/** 35/**
@@ -36,6 +38,7 @@
36#define NEIGHBOUR_TABLE_SIZE 256 38#define NEIGHBOUR_TABLE_SIZE 256
37 39
38 40
41
39// TODO: 42// TODO:
40// - have a way to access the currently 'connected' session 43// - have a way to access the currently 'connected' session
41// (for sending and to notice disconnect of it!) 44// (for sending and to notice disconnect of it!)
@@ -122,10 +125,10 @@ struct NeighbourMapEntry
122 struct MessageQueue *messages_tail; 125 struct MessageQueue *messages_tail;
123 126
124 /** 127 /**
125 * Context for peerinfo iteration. 128 * Context for validation address iteration.
126 * NULL after we are done processing peerinfo's information. 129 * NULL after we are connected.
127 */ 130 */
128 struct GNUNET_PEERINFO_IteratorContext *piter; 131 struct GST_ValidationIteratorContext *vic;
129 132
130 /** 133 /**
131 * Performance data for the peer. 134 * Performance data for the peer.
@@ -135,7 +138,7 @@ struct NeighbourMapEntry
135 /** 138 /**
136 * Public key for this peer. Valid only if the respective flag is set below. 139 * Public key for this peer. Valid only if the respective flag is set below.
137 */ 140 */
138 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded publicKey; 141 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
139 142
140 /** 143 /**
141 * Identity of this neighbour. 144 * Identity of this neighbour.
@@ -394,93 +397,6 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
394 GNUNET_SYSERR); 397 GNUNET_SYSERR);
395 } 398 }
396} 399}
397
398
399/**
400 * Create a fresh entry in our neighbour list for the given peer.
401 * Will try to transmit our current HELLO to the new neighbour.
402 * Do not call this function directly, use 'setup_peer_check_blacklist.
403 *
404 * @param peer the peer for which we create the entry
405 * @param do_hello should we schedule transmitting a HELLO
406 * @return the new neighbour list entry
407 */
408static struct NeighbourMapEntry *
409setup_new_neighbour (const struct GNUNET_PeerIdentity *peer,
410 int do_hello)
411{
412 struct NeighbourMapEntry *n;
413 struct TransportPlugin *tp;
414 struct ReadyList *rl;
415
416 GNUNET_assert (0 != memcmp (peer,
417 &my_identity,
418 sizeof (struct GNUNET_PeerIdentity)));
419#if DEBUG_TRANSPORT
420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
421 "Setting up state for neighbour `%4s'\n",
422 GNUNET_i2s (peer));
423#endif
424 GNUNET_STATISTICS_update (stats,
425 gettext_noop ("# active neighbours"),
426 1,
427 GNUNET_NO);
428 n = GNUNET_malloc (sizeof (struct NeighbourMapEntry));
429 n->id = *peer;
430 n->peer_timeout =
431 GNUNET_TIME_relative_to_absolute
432 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
433 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker,
434 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
435 MAX_BANDWIDTH_CARRY_S);
436 tp = plugins;
437 while (tp != NULL)
438 {
439 if ((tp->api->send != NULL) && (!is_blacklisted(peer, tp)))
440 {
441 rl = GNUNET_malloc (sizeof (struct ReadyList));
442 rl->neighbour = n;
443 rl->next = n->plugins;
444 n->plugins = rl;
445 rl->plugin = tp;
446 rl->addresses = NULL;
447 }
448 tp = tp->next;
449 }
450 n->latency = GNUNET_TIME_UNIT_FOREVER_REL;
451 n->distance = -1;
452 n->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
453 &neighbour_timeout_task, n);
454 GNUNET_CONTAINER_multihashmap_put (neighbours,
455 &n->id.hashPubKey,
456 n,
457 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
458 if (do_hello)
459 {
460 GNUNET_STATISTICS_update (stats,
461 gettext_noop ("# peerinfo new neighbor iterate requests"),
462 1,
463 GNUNET_NO);
464 GNUNET_STATISTICS_update (stats,
465 gettext_noop ("# outstanding peerinfo iterate requests"),
466 1,
467 GNUNET_NO);
468 n->piter = GNUNET_PEERINFO_iterate (peerinfo, peer,
469 GNUNET_TIME_UNIT_FOREVER_REL,
470 &add_hello_for_peer, n);
471
472 GNUNET_STATISTICS_update (stats,
473 gettext_noop ("# HELLO's sent to new neighbors"),
474 1,
475 GNUNET_NO);
476 if (NULL != our_hello)
477 transmit_to_peer (NULL, NULL, 0,
478 HELLO_ADDRESS_EXPIRATION,
479 (const char *) our_hello, GNUNET_HELLO_size(our_hello),
480 GNUNET_NO, n);
481 }
482 return n;
483}
484#endif 400#endif
485 401
486 402
@@ -526,10 +442,10 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
526 mq); 442 mq);
527 GNUNET_free (mq); 443 GNUNET_free (mq);
528 } 444 }
529 if (NULL != n->piter) 445 if (NULL != n->vic)
530 { 446 {
531 GNUNET_PEERINFO_iterate_cancel (n->piter); 447 GST_validation_get_addresses_cancel (n->vic);
532 n->piter = NULL; 448 n->vic = NULL;
533 } 449 }
534 GNUNET_array_grow (n->ats, 450 GNUNET_array_grow (n->ats,
535 n->ats_count, 451 n->ats_count,
@@ -581,6 +497,69 @@ GST_neighbours_stop ()
581 497
582 498
583/** 499/**
500 * Try to connect to the target peer using the given address
501 * (if is valid).
502 *
503 * @param cls the 'struct NeighbourMapEntry' of the target
504 * @param public_key public key for the peer, never NULL
505 * @param target identity of the target peer
506 * @param valid_until is ZERO if we never validated the address,
507 * otherwise a time up to when we consider it (or was) valid
508 * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO)
509 * is ZERO if the address is considered valid (no validation needed)
510 * otherwise a time in the future if we're currently denying re-validation
511 * @param plugin_name name of the plugin
512 * @param plugin_address binary address
513 * @param plugin_address_len length of address
514 */
515static void
516try_connect_using_address (void *cls,
517 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
518 const struct GNUNET_PeerIdentity *target,
519 struct GNUNET_TIME_Absolute valid_until,
520 struct GNUNET_TIME_Absolute validation_block,
521 const char *plugin_name,
522 const void *plugin_address,
523 size_t plugin_address_len)
524{
525 struct NeighbourMapEntry *n = cls;
526
527 if (n->public_key_valid == GNUNET_NO)
528 {
529 n->public_key = *public_key;
530 n->public_key_valid = GNUNET_YES;
531 }
532 if (GNUNET_TIME_absolute_get_remaining (valid_until).rel_value == 0)
533 return; /* address is not valid right now */
534 /* FIXME: do ATS here! */
535
536}
537
538
539/**
540 * We've tried to connect but waited long enough and failed. Clean up.
541 *
542 * @param cls the 'struct NeighbourMapEntry' of the neighbour that failed to connect
543 * @param tc scheduler context
544 */
545static void
546neighbour_connect_timeout_task (void *cls,
547 const struct GNUNET_SCHEDULER_TaskContext *tc)
548{
549 struct NeighbourMapEntry *n = cls;
550
551 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
552 GNUNET_assert (GNUNET_YES ==
553 GNUNET_CONTAINER_multihashmap_remove (neighbours,
554 &n->id.hashPubKey,
555 n));
556 GNUNET_assert (NULL == n->messages_head);
557 GNUNET_assert (NULL == n->ats);
558 GNUNET_free (n);
559}
560
561
562/**
584 * Try to create a connection to the given target (eventually). 563 * Try to create a connection to the given target (eventually).
585 * 564 *
586 * @param target peer to try to connect to 565 * @param target peer to try to connect to
@@ -588,6 +567,38 @@ GST_neighbours_stop ()
588void 567void
589GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target) 568GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
590{ 569{
570 struct NeighbourMapEntry *n;
571
572 GNUNET_assert (0 != memcmp (target,
573 &GST_my_identity,
574 sizeof (struct GNUNET_PeerIdentity)));
575 n = lookup_neighbour (target);
576 if ( (NULL != n) ||
577 (GNUNET_TIME_absolute_get_remaining (n->peer_timeout).rel_value > 0) )
578 return; /* already connected */
579 if (n == NULL)
580 {
581 n = GNUNET_malloc (sizeof (struct NeighbourMapEntry));
582 n->id = *target;
583 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker,
584 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
585 MAX_BANDWIDTH_CARRY_S);
586 n->latency = GNUNET_TIME_UNIT_FOREVER_REL;
587 n->distance = UINT32_MAX;
588 n->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
589 &neighbour_connect_timeout_task, n);
590 GNUNET_assert (GNUNET_OK ==
591 GNUNET_CONTAINER_multihashmap_put (neighbours,
592 &n->id.hashPubKey,
593 n,
594 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
595 }
596 if (n->vic != NULL)
597 return; /* already trying */
598 n->vic = GST_validation_get_addresses (target,
599 GNUNET_NO,
600 &try_connect_using_address,
601 n);
591} 602}
592 603
593 604
@@ -702,21 +713,6 @@ GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
702 713
703 714
704/** 715/**
705 * If we have an active connection to the given target, it must be shutdown.
706 *
707 * @param target peer to disconnect from
708 */
709void
710GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
711{
712 struct NeighbourMapEntry *n;
713
714 n = lookup_neighbour (target);
715 disconnect_neighbour (n);
716}
717
718
719/**
720 * Closure for the neighbours_iterate function. 716 * Closure for the neighbours_iterate function.
721 */ 717 */
722struct IteratorContext 718struct IteratorContext
@@ -825,10 +821,63 @@ GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender,
825 const char *plugin_name, 821 const char *plugin_name,
826 const void *sender_address, 822 const void *sender_address,
827 size_t sender_address_len, 823 size_t sender_address_len,
824 struct Session *session,
828 const struct GNUNET_TRANSPORT_ATS_Information *ats, 825 const struct GNUNET_TRANSPORT_ATS_Information *ats,
829 uint32_t ats_count) 826 uint32_t ats_count)
827{
828 struct NeighbourMapEntry *n;
829
830 if (0 == memcmp (sender,
831 &GST_my_identity,
832 sizeof (struct GNUNET_PeerIdentity)))
833 {
834 GNUNET_break (0);
835 return GNUNET_SYSERR;
836 }
837 n = lookup_neighbour (sender);
838 if ( (NULL != n) ||
839 (GNUNET_TIME_absolute_get_remaining (n->peer_timeout).rel_value > 0) )
840 {
841 /* already connected */
842 // FIXME: switch session!?
843 return GNUNET_OK;
844 }
845 if (n == NULL)
846 {
847 n = GNUNET_malloc (sizeof (struct NeighbourMapEntry));
848 n->id = *sender;
849 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker,
850 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
851 MAX_BANDWIDTH_CARRY_S);
852 n->latency = GNUNET_TIME_UNIT_FOREVER_REL;
853 n->distance = UINT32_MAX;
854 n->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
855 &neighbour_connect_timeout_task, n);
856 GNUNET_assert (GNUNET_OK ==
857 GNUNET_CONTAINER_multihashmap_put (neighbours,
858 &n->id.hashPubKey,
859 n,
860 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
861 }
862 // FIXME: mark connected, etc?
863
864 return GNUNET_OK;
865}
866
867
868/**
869 * If we have an active connection to the given target, it must be shutdown.
870 *
871 * @param target peer to disconnect from
872 */
873void
874GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
830{ 875{
831 return GNUNET_SYSERR; 876 struct NeighbourMapEntry *n;
877
878 n = lookup_neighbour (target);
879 /* FIXME: send disconnect message to target... */
880 disconnect_neighbour (n);
832} 881}
833 882
834 883
@@ -850,7 +899,12 @@ GST_neighbours_handle_disconnect (const struct GNUNET_PeerIdentity *sender,
850 const void *sender_address, 899 const void *sender_address,
851 size_t sender_address_len) 900 size_t sender_address_len)
852{ 901{
853 return GNUNET_SYSERR; 902 struct NeighbourMapEntry *n;
903
904 n = lookup_neighbour (sender);
905 /* FIXME: should disconnects have a signature that we should check here? */
906 disconnect_neighbour (n);
907 return GNUNET_OK;
854} 908}
855 909
856 910
diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h
index fc7576bbc..1b0a98a2b 100644
--- a/src/transport/gnunet-service-transport_neighbours.h
+++ b/src/transport/gnunet-service-transport_neighbours.h
@@ -28,6 +28,7 @@
28 28
29#include "gnunet_statistics_service.h" 29#include "gnunet_statistics_service.h"
30#include "gnunet_transport_service.h" 30#include "gnunet_transport_service.h"
31#include "gnunet_transport_plugin.h"
31#include "gnunet_util_lib.h" 32#include "gnunet_util_lib.h"
32 33
33// TODO: 34// TODO:
@@ -187,6 +188,7 @@ GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender,
187 const char *plugin_name, 188 const char *plugin_name,
188 const void *sender_address, 189 const void *sender_address,
189 size_t sender_address_len, 190 size_t sender_address_len,
191 struct Session *session,
190 const struct GNUNET_TRANSPORT_ATS_Information *ats, 192 const struct GNUNET_TRANSPORT_ATS_Information *ats,
191 uint32_t ats_count); 193 uint32_t ats_count);
192 194
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index c06725c58..c77fe7a44 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -548,6 +548,7 @@ timeout_hello_validation (void *cls,
548 * Send the given PONG to the given address. 548 * Send the given PONG to the given address.
549 * 549 *
550 * @param cls the PONG message 550 * @param cls the PONG message
551 * @param public_key public key for the peer, never NULL
551 * @param target peer this change is about, never NULL 552 * @param target peer this change is about, never NULL
552 * @param valid_until is ZERO if we never validated the address, 553 * @param valid_until is ZERO if we never validated the address,
553 * otherwise a time up to when we consider it (or was) valid 554 * otherwise a time up to when we consider it (or was) valid
@@ -560,6 +561,7 @@ timeout_hello_validation (void *cls,
560 */ 561 */
561static void 562static void
562multicast_pong (void *cls, 563multicast_pong (void *cls,
564 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
563 const struct GNUNET_PeerIdentity *target, 565 const struct GNUNET_PeerIdentity *target,
564 struct GNUNET_TIME_Absolute valid_until, 566 struct GNUNET_TIME_Absolute valid_until,
565 struct GNUNET_TIME_Absolute validation_block, 567 struct GNUNET_TIME_Absolute validation_block,
@@ -1188,6 +1190,7 @@ iterate_addresses (void *cls,
1188 struct ValidationEntry *ve = value; 1190 struct ValidationEntry *ve = value;
1189 1191
1190 vic->cb (vic->cb_cls, 1192 vic->cb (vic->cb_cls,
1193 &ve->public_key,
1191 &ve->pid, 1194 &ve->pid,
1192 ve->valid_until, 1195 ve->valid_until,
1193 ve->validation_block, 1196 ve->validation_block,
diff --git a/src/transport/gnunet-service-transport_validation.h b/src/transport/gnunet-service-transport_validation.h
index 27d30d83a..77c5164f9 100644
--- a/src/transport/gnunet-service-transport_validation.h
+++ b/src/transport/gnunet-service-transport_validation.h
@@ -105,6 +105,7 @@ struct GST_ValidationIteratorContext;
105 * the validation module is aware of (for the given target). 105 * the validation module is aware of (for the given target).
106 * 106 *
107 * @param cls closure 107 * @param cls closure
108 * @param public_key public key for the peer, never NULL
108 * @param target peer this change is about, never NULL 109 * @param target peer this change is about, never NULL
109 * @param valid_until is ZERO if we never validated the address, 110 * @param valid_until is ZERO if we never validated the address,
110 * otherwise a time up to when we consider it (or was) valid 111 * otherwise a time up to when we consider it (or was) valid
@@ -116,6 +117,7 @@ struct GST_ValidationIteratorContext;
116 * @param plugin_address_len length of address 117 * @param plugin_address_len length of address
117 */ 118 */
118typedef void (*GST_ValidationAddressCallback)(void *cls, 119typedef void (*GST_ValidationAddressCallback)(void *cls,
120 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
119 const struct GNUNET_PeerIdentity *target, 121 const struct GNUNET_PeerIdentity *target,
120 struct GNUNET_TIME_Absolute valid_until, 122 struct GNUNET_TIME_Absolute valid_until,
121 struct GNUNET_TIME_Absolute validation_block, 123 struct GNUNET_TIME_Absolute validation_block,