diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-11-30 07:31:09 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-11-30 07:31:09 +0100 |
commit | 1b4333f3a6a4f76aa76fc3abc21e8476ea0a92e3 (patch) | |
tree | 86bbecfcd30d250ab5a123c793595f8ff6ff33b1 /src/nat/gnunet-service-nat.c | |
parent | 27068700bceca89cd940816a7b5cd03933d3cc0b (diff) | |
download | gnunet-1b4333f3a6a4f76aa76fc3abc21e8476ea0a92e3.tar.gz gnunet-1b4333f3a6a4f76aa76fc3abc21e8476ea0a92e3.zip |
towards moving STUN logic into new NAT service
Diffstat (limited to 'src/nat/gnunet-service-nat.c')
-rw-r--r-- | src/nat/gnunet-service-nat.c | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/src/nat/gnunet-service-nat.c b/src/nat/gnunet-service-nat.c index f7dbbce3a..8499a9724 100644 --- a/src/nat/gnunet-service-nat.c +++ b/src/nat/gnunet-service-nat.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include "gnunet_signatures.h" | 34 | #include "gnunet_signatures.h" |
35 | #include "gnunet_statistics_service.h" | 35 | #include "gnunet_statistics_service.h" |
36 | #include "gnunet_nat_service.h" | 36 | #include "gnunet_nat_service.h" |
37 | #include "gnunet-service-nat_stun.h" | ||
37 | #include "nat.h" | 38 | #include "nat.h" |
38 | #include <gcrypt.h> | 39 | #include <gcrypt.h> |
39 | 40 | ||
@@ -360,6 +361,7 @@ handle_stun (void *cls, | |||
360 | const void *payload; | 361 | const void *payload; |
361 | size_t sa_len; | 362 | size_t sa_len; |
362 | size_t payload_size; | 363 | size_t payload_size; |
364 | struct sockaddr_in external_addr; | ||
363 | 365 | ||
364 | sa_len = ntohs (message->sender_addr_size); | 366 | sa_len = ntohs (message->sender_addr_size); |
365 | payload_size = ntohs (message->payload_size); | 367 | payload_size = ntohs (message->payload_size); |
@@ -386,7 +388,28 @@ handle_stun (void *cls, | |||
386 | } | 388 | } |
387 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 389 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
388 | "Received HANDLE_STUN message from client\n"); | 390 | "Received HANDLE_STUN message from client\n"); |
389 | // FIXME: actually handle STUN request! | 391 | if (GNUNET_OK == |
392 | GNUNET_NAT_stun_handle_packet_ (payload, | ||
393 | payload_size, | ||
394 | &external_addr)) | ||
395 | { | ||
396 | /* FIXME: do something with "external_addr"! We | ||
397 | now know that a server at "sa" claims that | ||
398 | we are visible at IP "external_addr". | ||
399 | |||
400 | We should (for some fixed period of time) tell | ||
401 | all of our clients that listen to a NAT'ed address | ||
402 | that they might want to consider the given 'external_ip' | ||
403 | as their public IP address (this includes TCP and UDP | ||
404 | clients, even if only UDP sends STUN requests). | ||
405 | |||
406 | If we do not get a renewal, the "external_addr" should be | ||
407 | removed again. The timeout frequency should be configurable | ||
408 | (with a sane default), so that the UDP plugin can tell how | ||
409 | often to re-request STUN. | ||
410 | */ | ||
411 | |||
412 | } | ||
390 | GNUNET_SERVICE_client_continue (ch->client); | 413 | GNUNET_SERVICE_client_continue (ch->client); |
391 | } | 414 | } |
392 | 415 | ||
@@ -786,12 +809,14 @@ ifc_proc (void *cls, | |||
786 | * of addresses this peer has. | 809 | * of addresses this peer has. |
787 | * | 810 | * |
788 | * @param delta the entry in the list that changed | 811 | * @param delta the entry in the list that changed |
812 | * @param ch client to contact | ||
789 | * @param add #GNUNET_YES to add, #GNUNET_NO to remove | 813 | * @param add #GNUNET_YES to add, #GNUNET_NO to remove |
790 | * @param addr the address that changed | 814 | * @param addr the address that changed |
791 | * @param addr_len number of bytes in @a addr | 815 | * @param addr_len number of bytes in @a addr |
792 | */ | 816 | */ |
793 | static void | 817 | static void |
794 | notify_client (struct LocalAddressList *delta, | 818 | notify_client (struct LocalAddressList *delta, |
819 | struct ClientHandle *ch, | ||
795 | int add, | 820 | int add, |
796 | const void *addr, | 821 | const void *addr, |
797 | size_t addr_len) | 822 | size_t addr_len) |
@@ -800,13 +825,13 @@ notify_client (struct LocalAddressList *delta, | |||
800 | struct GNUNET_NAT_AddressChangeNotificationMessage *msg; | 825 | struct GNUNET_NAT_AddressChangeNotificationMessage *msg; |
801 | 826 | ||
802 | env = GNUNET_MQ_msg_extra (msg, | 827 | env = GNUNET_MQ_msg_extra (msg, |
803 | alen, | 828 | addr_len, |
804 | GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE); | 829 | GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE); |
805 | msg->add_remove = htonl (add); | 830 | msg->add_remove = htonl (add); |
806 | msg->addr_class = htonl (delta->ac); | 831 | msg->addr_class = htonl (delta->ac); |
807 | GNUNET_memcpy (&msg[1], | 832 | GNUNET_memcpy (&msg[1], |
808 | addr, | 833 | addr, |
809 | alen); | 834 | addr_len); |
810 | GNUNET_MQ_send (ch->mq, | 835 | GNUNET_MQ_send (ch->mq, |
811 | env); | 836 | env); |
812 | } | 837 | } |
@@ -849,6 +874,7 @@ notify_clients (struct LocalAddressList *delta, | |||
849 | c4 = (const struct sockaddr_in *) ch->addrs[i]; | 874 | c4 = (const struct sockaddr_in *) ch->addrs[i]; |
850 | v4.sin_port = c4->sin_port; | 875 | v4.sin_port = c4->sin_port; |
851 | notify_client (delta, | 876 | notify_client (delta, |
877 | ch, | ||
852 | add, | 878 | add, |
853 | &v4, | 879 | &v4, |
854 | alen); | 880 | alen); |
@@ -866,8 +892,9 @@ notify_clients (struct LocalAddressList *delta, | |||
866 | if (AF_INET6 != ch->addrs[i]->sa_family) | 892 | if (AF_INET6 != ch->addrs[i]->sa_family) |
867 | continue; /* IPv4 not relevant */ | 893 | continue; /* IPv4 not relevant */ |
868 | c6 = (const struct sockaddr_in6 *) ch->addrs[i]; | 894 | c6 = (const struct sockaddr_in6 *) ch->addrs[i]; |
869 | v6.sin_port = c6->sin_port; | 895 | v6.sin6_port = c6->sin6_port; |
870 | notify_client (delta, | 896 | notify_client (delta, |
897 | ch, | ||
871 | add, | 898 | add, |
872 | &v6, | 899 | &v6, |
873 | alen); | 900 | alen); |