aboutsummaryrefslogtreecommitdiff
path: root/src/service/transport/gnunet-service-transport.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/transport/gnunet-service-transport.c')
-rw-r--r--src/service/transport/gnunet-service-transport.c465
1 files changed, 441 insertions, 24 deletions
diff --git a/src/service/transport/gnunet-service-transport.c b/src/service/transport/gnunet-service-transport.c
index ca191d49d..f4be5e759 100644
--- a/src/service/transport/gnunet-service-transport.c
+++ b/src/service/transport/gnunet-service-transport.c
@@ -77,6 +77,7 @@
77#include "gnunet_statistics_service.h" 77#include "gnunet_statistics_service.h"
78#include "gnunet_transport_monitor_service.h" 78#include "gnunet_transport_monitor_service.h"
79#include "gnunet_peerstore_service.h" 79#include "gnunet_peerstore_service.h"
80#include "gnunet_nat_service.h"
80#include "gnunet_hello_uri_lib.h" 81#include "gnunet_hello_uri_lib.h"
81#include "gnunet_signatures.h" 82#include "gnunet_signatures.h"
82#include "transport.h" 83#include "transport.h"
@@ -916,6 +917,15 @@ struct TransportValidationResponseMessage
916 struct GNUNET_TIME_RelativeNBO validity_duration; 917 struct GNUNET_TIME_RelativeNBO validity_duration;
917}; 918};
918 919
920struct TransportGlobalNattedAddress
921{
922 /**
923 * Length of the address following the struct.
924 */
925 unsigned int address_length;
926
927 /* Followed by @e address_length bytes of the address. */
928};
919 929
920/** 930/**
921 * Message for Transport-to-Transport Flow control. Specifies the size 931 * Message for Transport-to-Transport Flow control. Specifies the size
@@ -973,9 +983,21 @@ struct TransportFlowControlMessage
973 * reset the counters for the number of bytes sent! 983 * reset the counters for the number of bytes sent!
974 */ 984 */
975 struct GNUNET_TIME_AbsoluteNBO sender_time; 985 struct GNUNET_TIME_AbsoluteNBO sender_time;
976};
977 986
978 987
988 /**
989 * Number of TransportGlobalNattedAddress following the struct.
990 */
991 unsigned int number_of_addresses;
992
993 /**
994 * Size of all the addresses attached to all TransportGlobalNattedAddress.
995 */
996 size_t size_of_addresses;
997
998 /* Followed by @e number_of_addresses struct TransportGlobalNattedAddress. */
999};
1000
979GNUNET_NETWORK_STRUCT_END 1001GNUNET_NETWORK_STRUCT_END
980 1002
981 1003
@@ -1921,6 +1943,12 @@ struct Queue
1921 struct PerformanceData pd; 1943 struct PerformanceData pd;
1922 1944
1923 /** 1945 /**
1946 * Handle for an operation to iterate through all hellos to compare the hello
1947 * addresses with @e address which might be a natted one.
1948 */
1949 struct GNUNET_PEERSTORE_Monitor *mo;
1950
1951 /**
1924 * Message ID generator for transmissions on this queue to the 1952 * Message ID generator for transmissions on this queue to the
1925 * communicator. 1953 * communicator.
1926 */ 1954 */
@@ -1976,6 +2004,11 @@ struct Queue
1976 * virtual link to give it a pending message. 2004 * virtual link to give it a pending message.
1977 */ 2005 */
1978 int idle; 2006 int idle;
2007
2008 /**
2009 * Set to GNUNET_yes, if this queues address is not a global natted one.
2010 */
2011 enum GNUNET_GenericReturnValue is_global_natted;
1979}; 2012};
1980 2013
1981 2014
@@ -2040,6 +2073,26 @@ struct Neighbour
2040 * PEERSTORE yet, or are we still waiting for a reply of PEERSTORE? 2073 * PEERSTORE yet, or are we still waiting for a reply of PEERSTORE?
2041 */ 2074 */
2042 int dv_monotime_available; 2075 int dv_monotime_available;
2076
2077 /**
2078 * Map of struct TransportGlobalNattedAddress for this neighbour.
2079 */
2080 struct GNUNET_CONTAINER_MultiPeerMap *natted_addresses;
2081
2082 /**
2083 * Number of global natted addresses for this neighbour.
2084 */
2085 unsigned int number_of_addresses;
2086
2087 /**
2088 * Size of all global natted addresses for this neighbour.
2089 */
2090 size_t size_of_global_addresses;
2091
2092 /**
2093 * A queue of this neighbour has a global natted address.
2094 */
2095 enum GNUNET_GenericReturnValue is_global_natted;
2043}; 2096};
2044 2097
2045 2098
@@ -2760,7 +2813,6 @@ struct Backtalker
2760 size_t body_size; 2813 size_t body_size;
2761}; 2814};
2762 2815
2763
2764/** 2816/**
2765 * Ring buffer for a CORE message we did not deliver to CORE, because of missing virtual link to sender. 2817 * Ring buffer for a CORE message we did not deliver to CORE, because of missing virtual link to sender.
2766 */ 2818 */
@@ -2897,6 +2949,11 @@ static struct LearnLaunchEntry *lle_tail = NULL;
2897static struct GNUNET_CONTAINER_Heap *validation_heap; 2949static struct GNUNET_CONTAINER_Heap *validation_heap;
2898 2950
2899/** 2951/**
2952 * Handle for connect to the NAT service.
2953 */
2954struct GNUNET_NAT_Handle *nh;
2955
2956/**
2900 * Database for peer's HELLOs. 2957 * Database for peer's HELLOs.
2901 */ 2958 */
2902static struct GNUNET_PEERSTORE_Handle *peerstore; 2959static struct GNUNET_PEERSTORE_Handle *peerstore;
@@ -3591,6 +3648,18 @@ client_connect_cb (void *cls,
3591} 3648}
3592 3649
3593 3650
3651static enum GNUNET_GenericReturnValue
3652remove_global_addresses (void *cls,
3653 const struct GNUNET_PeerIdentity *pid,
3654 void *value)
3655{
3656 (void) cls;
3657 struct TransportGlobalNattedAddress *tgna = value;
3658
3659 GNUNET_free (tgna);
3660}
3661
3662
3594/** 3663/**
3595 * Release memory used by @a neighbour. 3664 * Release memory used by @a neighbour.
3596 * 3665 *
@@ -3609,6 +3678,9 @@ free_neighbour (struct Neighbour *neighbour)
3609 neighbour)); 3678 neighbour));
3610 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3611 "Freeing neighbour\n"); 3680 "Freeing neighbour\n");
3681 GNUNET_CONTAINER_multipeermap_iterate (neighbour->natted_addresses,
3682 &remove_global_addresses,
3683 NULL);
3612 while (NULL != (dvh = neighbour->dv_head)) 3684 while (NULL != (dvh = neighbour->dv_head))
3613 { 3685 {
3614 struct DistanceVector *dv = dvh->dv; 3686 struct DistanceVector *dv = dvh->dv;
@@ -3878,6 +3950,11 @@ free_queue (struct Queue *queue)
3878 3950
3879 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3951 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3880 "Cleaning up queue %u\n", queue->qid); 3952 "Cleaning up queue %u\n", queue->qid);
3953 if (NULL != queue->mo)
3954 {
3955 GNUNET_PEERSTORE_monitor_stop (queue->mo);
3956 queue->mo = NULL;
3957 }
3881 if (NULL != queue->transmit_task) 3958 if (NULL != queue->transmit_task)
3882 { 3959 {
3883 GNUNET_SCHEDULER_cancel (queue->transmit_task); 3960 GNUNET_SCHEDULER_cancel (queue->transmit_task);
@@ -5263,6 +5340,34 @@ task_consider_sending_fc (void *cls)
5263} 5340}
5264 5341
5265 5342
5343static char *
5344get_address_without_port (const char *address);
5345
5346
5347static enum GNUNET_GenericReturnValue
5348add_global_addresses (void *cls,
5349 const struct GNUNET_PeerIdentity *pid,
5350 void *value)
5351{
5352 char *tgnas = cls;
5353 struct TransportGlobalNattedAddress *tgna = value;
5354 char *addr = (char *) &tgna[1];
5355 size_t address_len = strlen (addr);
5356 unsigned int off = 0;
5357
5358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5359 "sending address %s length %u\n",
5360 addr,
5361 address_len);
5362 tgna = GNUNET_malloc (sizeof (struct TransportGlobalNattedAddress) + address_len);
5363 tgna->address_length = htonl (address_len);
5364 GNUNET_memcpy (&tgna[1], addr, address_len);
5365 GNUNET_memcpy (&tgnas[off], tgna, sizeof (struct TransportGlobalNattedAddress) + address_len);
5366 GNUNET_free (tgna);
5367 off += sizeof(struct TransportGlobalNattedAddress) + address_len;
5368}
5369
5370
5266/** 5371/**
5267 * Something changed on the virtual link with respect to flow 5372 * Something changed on the virtual link with respect to flow
5268 * control. Consider retransmitting the FC window size. 5373 * control. Consider retransmitting the FC window size.
@@ -5274,9 +5379,32 @@ consider_sending_fc (void *cls)
5274{ 5379{
5275 struct VirtualLink *vl = cls; 5380 struct VirtualLink *vl = cls;
5276 struct GNUNET_TIME_Absolute monotime; 5381 struct GNUNET_TIME_Absolute monotime;
5277 struct TransportFlowControlMessage fc; 5382 struct TransportFlowControlMessage *fc;
5278 struct GNUNET_TIME_Relative duration; 5383 struct GNUNET_TIME_Relative duration;
5279 struct GNUNET_TIME_Relative rtt; 5384 struct GNUNET_TIME_Relative rtt;
5385 struct Neighbour *n = vl->n;
5386
5387 if (0 < n->number_of_addresses)
5388 {
5389 char *tgnas = GNUNET_malloc (n->number_of_addresses * sizeof (struct TransportGlobalNattedAddress) + n->size_of_global_addresses);
5390 size_t addresses_size;
5391
5392 addresses_size = n->number_of_addresses * sizeof (struct TransportGlobalNattedAddress) + n->size_of_global_addresses;
5393 fc = GNUNET_malloc (sizeof (struct TransportFlowControlMessage) + addresses_size);
5394 fc->header.size = htons (sizeof(struct TransportFlowControlMessage) + addresses_size);
5395 fc->size_of_addresses = htonl (n->size_of_global_addresses);
5396 fc->number_of_addresses = htonl (n->number_of_addresses);
5397 GNUNET_CONTAINER_multipeermap_iterate (n->natted_addresses,
5398 &add_global_addresses,
5399 tgnas);
5400 GNUNET_memcpy (&fc[1], tgnas, addresses_size);
5401 GNUNET_free (tgnas);
5402 }
5403 else
5404 {
5405 fc = GNUNET_malloc (sizeof (struct TransportFlowControlMessage));
5406 fc->header.size = htons (sizeof(struct TransportFlowControlMessage));
5407 }
5280 5408
5281 duration = GNUNET_TIME_absolute_get_duration (vl->last_fc_transmission); 5409 duration = GNUNET_TIME_absolute_get_duration (vl->last_fc_transmission);
5282 /* OPTIMIZE-FC-BDP: decide sane criteria on when to do this, instead of doing 5410 /* OPTIMIZE-FC-BDP: decide sane criteria on when to do this, instead of doing
@@ -5295,16 +5423,15 @@ consider_sending_fc (void *cls)
5295 (unsigned long long) vl->incoming_fc_window_size); 5423 (unsigned long long) vl->incoming_fc_window_size);
5296 monotime = GNUNET_TIME_absolute_get_monotonic (GST_cfg); 5424 monotime = GNUNET_TIME_absolute_get_monotonic (GST_cfg);
5297 vl->last_fc_transmission = monotime; 5425 vl->last_fc_transmission = monotime;
5298 fc.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL); 5426 fc->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL);
5299 fc.header.size = htons (sizeof(fc)); 5427 fc->seq = htonl (vl->fc_seq_gen++);
5300 fc.seq = htonl (vl->fc_seq_gen++); 5428 fc->inbound_window_size = GNUNET_htonll (vl->incoming_fc_window_size
5301 fc.inbound_window_size = GNUNET_htonll (vl->incoming_fc_window_size
5302 + vl->incoming_fc_window_size_used 5429 + vl->incoming_fc_window_size_used
5303 + vl->incoming_fc_window_size_loss); 5430 + vl->incoming_fc_window_size_loss);
5304 fc.outbound_sent = GNUNET_htonll (vl->outbound_fc_window_size_used); 5431 fc->outbound_sent = GNUNET_htonll (vl->outbound_fc_window_size_used);
5305 fc.outbound_window_size = GNUNET_htonll (vl->outbound_fc_window_size); 5432 fc->outbound_window_size = GNUNET_htonll (vl->outbound_fc_window_size);
5306 fc.sender_time = GNUNET_TIME_absolute_hton (monotime); 5433 fc->sender_time = GNUNET_TIME_absolute_hton (monotime);
5307 rtt = route_control_message_without_fc (vl, &fc.header, RMO_DV_ALLOWED); 5434 rtt = route_control_message_without_fc (vl, &fc->header, RMO_DV_ALLOWED);
5308 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rtt.rel_value_us) 5435 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rtt.rel_value_us)
5309 { 5436 {
5310 rtt = GNUNET_TIME_UNIT_SECONDS; 5437 rtt = GNUNET_TIME_UNIT_SECONDS;
@@ -5329,6 +5456,7 @@ consider_sending_fc (void *cls)
5329 vl->fc_retransmit_task = 5456 vl->fc_retransmit_task =
5330 GNUNET_SCHEDULER_add_delayed (rtt, &task_consider_sending_fc, vl); 5457 GNUNET_SCHEDULER_add_delayed (rtt, &task_consider_sending_fc, vl);
5331 vl->fc_retransmit_count++; 5458 vl->fc_retransmit_count++;
5459 GNUNET_free (fc);
5332} 5460}
5333 5461
5334 5462
@@ -5775,6 +5903,29 @@ store_pi (void *cls)
5775} 5903}
5776 5904
5777 5905
5906static struct AddressListEntry *
5907create_address_entry (struct TransportClient *tc,
5908 struct GNUNET_TIME_Relative expiration,
5909 enum GNUNET_NetworkType nt,
5910 const char *address,
5911 uint32_t aid,
5912 size_t slen)
5913{
5914 struct AddressListEntry *ale;
5915
5916 ale = GNUNET_malloc (sizeof(struct AddressListEntry) + slen);
5917 ale->tc = tc;
5918 ale->address = (const char *) &ale[1];
5919 ale->expiration = expiration;
5920 ale->aid = aid;
5921 ale->nt = nt;
5922 memcpy (&ale[1], address, slen);
5923 ale->st = GNUNET_SCHEDULER_add_now (&store_pi, ale);
5924
5925 return ale;
5926}
5927
5928
5778/** 5929/**
5779 * Address of our peer added. Process the request. 5930 * Address of our peer added. Process the request.
5780 * 5931 *
@@ -5788,23 +5939,24 @@ handle_add_address (void *cls,
5788 struct TransportClient *tc = cls; 5939 struct TransportClient *tc = cls;
5789 struct AddressListEntry *ale; 5940 struct AddressListEntry *ale;
5790 size_t slen; 5941 size_t slen;
5942 char *address;
5791 5943
5792 /* 0-termination of &aam[1] was checked in #check_add_address */ 5944 /* 0-termination of &aam[1] was checked in #check_add_address */
5793 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5945 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5794 "Communicator added address `%s'!\n", 5946 "Communicator added address `%s'!\n",
5795 (const char *) &aam[1]); 5947 (const char *) &aam[1]);
5796 slen = ntohs (aam->header.size) - sizeof(*aam); 5948 slen = ntohs (aam->header.size) - sizeof(*aam);
5797 ale = GNUNET_malloc (sizeof(struct AddressListEntry) + slen); 5949 address = GNUNET_malloc (slen);
5798 ale->tc = tc; 5950 memcpy (address, &aam[1], slen);
5799 ale->address = (const char *) &ale[1]; 5951 ale = create_address_entry (tc,
5800 ale->expiration = GNUNET_TIME_relative_ntoh (aam->expiration); 5952 GNUNET_TIME_relative_ntoh (aam->expiration),
5801 ale->aid = aam->aid; 5953 (enum GNUNET_NetworkType) ntohl (aam->nt),
5802 ale->nt = (enum GNUNET_NetworkType) ntohl (aam->nt); 5954 address,
5803 memcpy (&ale[1], &aam[1], slen); 5955 aam->aid,
5956 slen);
5804 GNUNET_CONTAINER_DLL_insert (tc->details.communicator.addr_head, 5957 GNUNET_CONTAINER_DLL_insert (tc->details.communicator.addr_head,
5805 tc->details.communicator.addr_tail, 5958 tc->details.communicator.addr_tail,
5806 ale); 5959 ale);
5807 ale->st = GNUNET_SCHEDULER_add_now (&store_pi, ale);
5808 GNUNET_SERVICE_client_continue (tc->client); 5960 GNUNET_SERVICE_client_continue (tc->client);
5809} 5961}
5810 5962
@@ -9446,6 +9598,37 @@ handle_incoming_msg (void *cls,
9446 demultiplex_with_cmc (cmc); 9598 demultiplex_with_cmc (cmc);
9447} 9599}
9448 9600
9601/**
9602 * Communicator gave us a transport address validation response. Check the
9603 * request.
9604 *
9605 * @param cls a `struct CommunicatorMessageContext`
9606 * @param fc the message that was received
9607 * @return #GNUNET_YES if message is well-formed
9608 */
9609static int
9610check_flow_control (void *cls, const struct TransportFlowControlMessage *fc)
9611{
9612 (void) cls;
9613 struct TransportGlobalNattedAddress *addresses = (struct TransportGlobalNattedAddress *) &fc[1];
9614 unsigned int number_of_addresses = ntohl (fc->number_of_addresses);
9615
9616 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
9617 "Flow control header size %u size of addresses %u number of addresses %u size of message struct %u second struct %u\n",
9618 ntohs (fc->header.size),
9619 ntohl (fc->size_of_addresses),
9620 ntohl (fc->number_of_addresses),
9621 sizeof(struct TransportFlowControlMessage),
9622 sizeof (struct TransportGlobalNattedAddress));
9623
9624 if (0 == number_of_addresses || ntohs (fc->header.size) == sizeof(struct TransportFlowControlMessage) + ntohl (fc->number_of_addresses) * sizeof (struct TransportGlobalNattedAddress) + ntohl (fc->size_of_addresses))
9625 return GNUNET_OK;
9626 else
9627 {
9628 GNUNET_break_op (0);
9629 return GNUNET_SYSERR;
9630 }
9631}
9449 9632
9450/** 9633/**
9451 * Communicator gave us a transport address validation response. Process the 9634 * Communicator gave us a transport address validation response. Process the
@@ -9490,6 +9673,31 @@ handle_flow_control (void *cls, const struct TransportFlowControlMessage *fc)
9490 vl, 9673 vl,
9491 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 9674 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
9492 } 9675 }
9676 if (0 != ntohl (fc->number_of_addresses))
9677 {
9678 unsigned int number_of_addresses = ntohl (fc->number_of_addresses);
9679 const char *tgnas;
9680 unsigned int off = 0;
9681
9682 tgnas = (const char *) &fc[1];
9683
9684 for (int i = 1; i <= number_of_addresses; i++)
9685 {
9686 struct TransportGlobalNattedAddress *tgna = (struct TransportGlobalNattedAddress *) &tgnas[off];
9687 char *addr = (char *) &tgna[1];
9688 unsigned int address_length;
9689
9690 address_length = ntohl (tgna->address_length);
9691 off += sizeof(struct TransportGlobalNattedAddress) + address_length;
9692
9693 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
9694 "received address %s length %u\n",
9695 addr,
9696 ntohl (tgna->address_length));
9697
9698 GNUNET_NAT_add_global_address (nh, addr, ntohl (tgna->address_length));
9699 }
9700 }
9493 st = GNUNET_TIME_absolute_ntoh (fc->sender_time); 9701 st = GNUNET_TIME_absolute_ntoh (fc->sender_time);
9494 if (st.abs_value_us < vl->last_fc_timestamp.abs_value_us) 9702 if (st.abs_value_us < vl->last_fc_timestamp.abs_value_us)
9495 { 9703 {
@@ -9596,15 +9804,15 @@ demultiplex_with_cmc (struct CommunicatorMessageContext *cmc)
9596 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX, 9804 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX,
9597 struct TransportDVBoxMessage, 9805 struct TransportDVBoxMessage,
9598 cmc), 9806 cmc),
9807 GNUNET_MQ_hd_var_size (flow_control,
9808 GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL,
9809 struct TransportFlowControlMessage,
9810 cmc),
9599 GNUNET_MQ_hd_fixed_size ( 9811 GNUNET_MQ_hd_fixed_size (
9600 validation_challenge, 9812 validation_challenge,
9601 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE, 9813 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE,
9602 struct TransportValidationChallengeMessage, 9814 struct TransportValidationChallengeMessage,
9603 cmc), 9815 cmc),
9604 GNUNET_MQ_hd_fixed_size (flow_control,
9605 GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL,
9606 struct TransportFlowControlMessage,
9607 cmc),
9608 GNUNET_MQ_hd_fixed_size ( 9816 GNUNET_MQ_hd_fixed_size (
9609 validation_response, 9817 validation_response,
9610 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE, 9818 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE,
@@ -11317,6 +11525,7 @@ check_validation_request_pending (void *cls,
11317 char *address_without_port_q; 11525 char *address_without_port_q;
11318 int success = GNUNET_YES; 11526 int success = GNUNET_YES;
11319 11527
11528 //TODO Check if this is really necessary.
11320 address_without_port_vs = get_address_without_port (vs->address); 11529 address_without_port_vs = get_address_without_port (vs->address);
11321 address_without_port_q = get_address_without_port (q->address); 11530 address_without_port_q = get_address_without_port (q->address);
11322 11531
@@ -11380,6 +11589,192 @@ neighbour_dv_monotime_cb (void *cls,
11380} 11589}
11381 11590
11382 11591
11592static void
11593iterate_address_and_compare_cb (void *cls,
11594 const struct GNUNET_PeerIdentity *pid,
11595 const char *uri)
11596{
11597 struct Queue *queue = cls;
11598 struct Neighbour *neighbour = queue->neighbour;
11599 const char *dash;
11600 const char *slash;
11601 char *address_uri;
11602 char *prefix;
11603 char *uri_without_port;
11604 char *address_uri_without_port = get_address_without_port (queue->address);
11605
11606 slash = strrchr (uri, '/');
11607 prefix = GNUNET_strndup (uri, (slash - uri) - 2);
11608 GNUNET_assert (NULL != slash);
11609 slash++;
11610 GNUNET_asprintf (&address_uri,
11611 "%s-%s",
11612 prefix,
11613 slash);
11614
11615 address_uri_without_port = get_address_without_port (queue->address);
11616 uri_without_port = get_address_without_port (address_uri);
11617 if (0 == strcmp (uri_without_port, address_uri_without_port))
11618 {
11619 queue->is_global_natted = GNUNET_NO;
11620 }
11621
11622 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
11623 "not global natted %u %s %s %s %s %s %u\n",
11624 queue->is_global_natted,
11625 uri,
11626 queue->address,
11627 uri_without_port,
11628 address_uri_without_port,
11629 prefix,
11630 GNUNET_NO);
11631 GNUNET_free (prefix);
11632 GNUNET_free (address_uri);
11633 GNUNET_free (address_uri_without_port);
11634 GNUNET_free (uri_without_port);
11635}
11636
11637
11638static void
11639check_for_global_natted_error_cb (void *cls)
11640{
11641 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
11642 "Error in PEERSTORE monitoring for checking global natted\n");
11643}
11644
11645
11646static void
11647check_for_global_natted_sync_cb (void *cls)
11648{
11649 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
11650 "Done with initial PEERSTORE iteration during monitoring for checking global natted\n");
11651}
11652
11653
11654struct TransportGlobalNattedAddressClosure
11655{
11656 /**
11657 * The address to search for.
11658 */
11659 char *addr;
11660
11661 /**
11662 * The struct TransportGlobalNattedAddress to set.
11663 */
11664 struct TransportGlobalNattedAddress *tgna;
11665};
11666
11667
11668static enum GNUNET_GenericReturnValue
11669contains_address (void *cls,
11670 const struct GNUNET_PeerIdentity *pid,
11671 void *value)
11672{
11673 struct TransportGlobalNattedAddressClosure *tgna_cls = cls;
11674 struct TransportGlobalNattedAddress *tgna = value;
11675 char *addr = (char *) &tgna[1];
11676
11677 if (0 == GNUNET_memcmp (addr, tgna_cls->addr))
11678 {
11679 tgna_cls->tgna = tgna;
11680 return GNUNET_NO;
11681 }
11682 return GNUNET_YES;
11683}
11684
11685
11686static void
11687check_for_global_natted (void *cls,
11688 const struct GNUNET_PEERSTORE_Record *record,
11689 const char *emsg)
11690{
11691 struct Queue *queue = cls;
11692 struct Neighbour *neighbour = queue->neighbour;
11693 struct GNUNET_HELLO_Builder *builder;
11694 struct GNUNET_MessageHeader *hello;
11695 struct TransportGlobalNattedAddressClosure tgna_cls;
11696 size_t address_len_without_port;
11697
11698 if (NULL != emsg)
11699 {
11700 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
11701 "Got failure from PEERSTORE: %s\n",
11702 emsg);
11703 return;
11704 }
11705 if (NULL == record)
11706 {
11707 queue->mo = NULL;
11708 return;
11709 }
11710 if (0 == record->value_size)
11711 {
11712 GNUNET_PEERSTORE_monitor_next (queue->mo, 1);
11713 GNUNET_break (0);
11714 return;
11715 }
11716 queue->is_global_natted = GNUNET_YES;
11717 hello = record->value;
11718 builder = GNUNET_HELLO_builder_from_msg (hello);
11719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
11720 "before not global natted %u\n",
11721 queue->is_global_natted);
11722 GNUNET_HELLO_builder_iterate (builder,
11723 &iterate_address_and_compare_cb,
11724 queue);
11725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
11726 "after not global natted %u\n",
11727 queue->is_global_natted);
11728 GNUNET_HELLO_builder_free (builder);
11729
11730 tgna_cls.addr = get_address_without_port (queue->address);
11731 address_len_without_port = strlen (tgna_cls.addr);
11732 GNUNET_CONTAINER_multipeermap_get_multiple (neighbour->natted_addresses,
11733 &neighbour->pid,
11734 &contains_address,
11735 &tgna_cls);
11736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
11737 " tgna_cls.tgna tgna %p %u %u %u\n",
11738 tgna_cls.tgna,
11739 neighbour->size_of_global_addresses,
11740 tgna_cls.tgna->address_length,
11741 neighbour->number_of_addresses);
11742 if (0 == tgna_cls.tgna->address_length && GNUNET_YES == queue->is_global_natted)
11743 {
11744 struct TransportGlobalNattedAddress *tgna;
11745
11746 tgna = GNUNET_malloc (sizeof (struct TransportGlobalNattedAddress) + address_len_without_port);
11747 tgna->address_length = htonl (address_len_without_port);
11748 GNUNET_memcpy (&tgna[1], tgna_cls.addr, address_len_without_port);
11749 GNUNET_CONTAINER_multipeermap_put (neighbour->natted_addresses,
11750 &neighbour->pid,
11751 tgna,
11752 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
11753 neighbour->number_of_addresses++;
11754 neighbour->size_of_global_addresses += address_len_without_port;
11755 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
11756 "Created tgna %p\n",
11757 tgna);
11758 }
11759 else if (0 != tgna_cls.tgna->address_length && GNUNET_NO == queue->is_global_natted)
11760 {
11761 GNUNET_CONTAINER_multipeermap_remove (neighbour->natted_addresses,
11762 &neighbour->pid,
11763 tgna_cls.tgna);
11764 GNUNET_assert (neighbour->size_of_global_addresses >= ntohl (tgna_cls.tgna->address_length));
11765 neighbour->size_of_global_addresses -= ntohl (tgna_cls.tgna->address_length);
11766 GNUNET_assert (0 < neighbour->number_of_addresses);
11767 neighbour->number_of_addresses--;
11768 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
11769 "removed tgna %p\n",
11770 tgna_cls.tgna);
11771 GNUNET_free (tgna_cls.tgna);
11772 }
11773 GNUNET_free (tgna_cls.addr);
11774 GNUNET_PEERSTORE_monitor_next (queue->mo, 1);
11775}
11776
11777
11383/** 11778/**
11384 * New queue became available. Process the request. 11779 * New queue became available. Process the request.
11385 * 11780 *
@@ -11426,6 +11821,7 @@ handle_add_queue_message (void *cls,
11426 if (NULL == neighbour) 11821 if (NULL == neighbour)
11427 { 11822 {
11428 neighbour = GNUNET_new (struct Neighbour); 11823 neighbour = GNUNET_new (struct Neighbour);
11824 neighbour->natted_addresses = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES);
11429 neighbour->pid = aqm->receiver; 11825 neighbour->pid = aqm->receiver;
11430 GNUNET_assert (GNUNET_OK == 11826 GNUNET_assert (GNUNET_OK ==
11431 GNUNET_CONTAINER_multipeermap_put ( 11827 GNUNET_CONTAINER_multipeermap_put (
@@ -11488,6 +11884,17 @@ handle_add_queue_message (void *cls,
11488 queue->nt = (enum GNUNET_NetworkType) ntohl (aqm->nt); 11884 queue->nt = (enum GNUNET_NetworkType) ntohl (aqm->nt);
11489 queue->cs = (enum GNUNET_TRANSPORT_ConnectionStatus) ntohl (aqm->cs); 11885 queue->cs = (enum GNUNET_TRANSPORT_ConnectionStatus) ntohl (aqm->cs);
11490 queue->idle = GNUNET_YES; 11886 queue->idle = GNUNET_YES;
11887 queue->mo = GNUNET_PEERSTORE_monitor_start (GST_cfg,
11888 GNUNET_YES,
11889 "peerstore",
11890 &neighbour->pid,
11891 GNUNET_PEERSTORE_HELLO_KEY,
11892 &check_for_global_natted_error_cb,
11893 NULL,
11894 &check_for_global_natted_sync_cb,
11895 NULL,
11896 &check_for_global_natted,
11897 queue);
11491 /* check if valdiations are waiting for the queue */ 11898 /* check if valdiations are waiting for the queue */
11492 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (validation_map, 11899 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (validation_map,
11493 &aqm->receiver)) 11900 &aqm->receiver))
@@ -11977,10 +12384,11 @@ static void
11977do_shutdown (void *cls) 12384do_shutdown (void *cls)
11978{ 12385{
11979 struct LearnLaunchEntry *lle; 12386 struct LearnLaunchEntry *lle;
12387 (void) cls;
11980 12388
11981 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 12389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
11982 "shutdown logic\n"); 12390 "shutdown logic\n");
11983 (void) cls; 12391 GNUNET_NAT_unregister (nh);
11984 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 12392 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
11985 &free_neighbour_cb, NULL); 12393 &free_neighbour_cb, NULL);
11986 if (NULL != validation_task) 12394 if (NULL != validation_task)
@@ -12134,6 +12542,15 @@ run (void *cls,
12134 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); 12542 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg);
12135 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 12543 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
12136 peerstore = GNUNET_PEERSTORE_connect (GST_cfg); 12544 peerstore = GNUNET_PEERSTORE_connect (GST_cfg);
12545 nh = GNUNET_NAT_register (GST_cfg,
12546 "transport",
12547 0,
12548 0,
12549 NULL,
12550 0,
12551 NULL,
12552 NULL,
12553 NULL);
12137 if (NULL == peerstore) 12554 if (NULL == peerstore)
12138 { 12555 {
12139 GNUNET_break (0); 12556 GNUNET_break (0);