aboutsummaryrefslogtreecommitdiff
path: root/src/nat/nat.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-06-30 20:32:23 +0000
committerChristian Grothoff <christian@grothoff.org>2011-06-30 20:32:23 +0000
commit03fea5ab807717d8cd1263cb0f334fc042b1a32b (patch)
tree46815fc9f2d4dc2b1c0a79c9c6be3ae1af8e822e /src/nat/nat.c
parent5c5b1bd3586da2f5b076b6371e2c906e7f689c80 (diff)
downloadgnunet-03fea5ab807717d8cd1263cb0f334fc042b1a32b.tar.gz
gnunet-03fea5ab807717d8cd1263cb0f334fc042b1a32b.zip
make refresh frequencies configurable
Diffstat (limited to 'src/nat/nat.c')
-rw-r--r--src/nat/nat.c50
1 files changed, 43 insertions, 7 deletions
diff --git a/src/nat/nat.c b/src/nat/nat.c
index e5a3e0e0f..48d7faf9c 100644
--- a/src/nat/nat.c
+++ b/src/nat/nat.c
@@ -27,7 +27,6 @@
27 * 27 *
28 * TODO: 28 * TODO:
29 * - implement UPnP/PMP support 29 * - implement UPnP/PMP support
30 * - make frequency of checks configurable
31 */ 30 */
32#include "platform.h" 31#include "platform.h"
33#include "gnunet_util_lib.h" 32#include "gnunet_util_lib.h"
@@ -37,20 +36,17 @@
37/** 36/**
38 * How often do we scan for changes in our IP address from our local 37 * How often do we scan for changes in our IP address from our local
39 * interfaces? 38 * interfaces?
40 * FIXME: make this configurable...
41 */ 39 */
42#define IFC_SCAN_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 40#define IFC_SCAN_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
43 41
44/** 42/**
45 * How often do we scan for changes in how our hostname resolves? 43 * How often do we scan for changes in how our hostname resolves?
46 * FIXME: make this configurable...
47 */ 44 */
48#define HOSTNAME_DNS_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 20) 45#define HOSTNAME_DNS_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 20)
49 46
50 47
51/** 48/**
52 * How often do we scan for changes in how our external (dyndns) hostname resolves? 49 * How often do we scan for changes in how our external (dyndns) hostname resolves?
53 * FIXME: make this configurable...
54 */ 50 */
55#define DYNDNS_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 7) 51#define DYNDNS_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 7)
56 52
@@ -209,6 +205,22 @@ struct GNUNET_NAT_Handle
209 GNUNET_SCHEDULER_TaskIdentifier dns_task; 205 GNUNET_SCHEDULER_TaskIdentifier dns_task;
210 206
211 /** 207 /**
208 * How often do we scan for changes in our IP address from our local
209 * interfaces?
210 */
211 struct GNUNET_TIME_Relative ifc_scan_frequency;
212
213 /**
214 * How often do we scan for changes in how our hostname resolves?
215 */
216 struct GNUNET_TIME_Relative hostname_dns_frequency;
217
218 /**
219 * How often do we scan for changes in how our external (dyndns) hostname resolves?
220 */
221 struct GNUNET_TIME_Relative dyndns_frequency;
222
223 /**
212 * The process id of the server process (if behind NAT) 224 * The process id of the server process (if behind NAT)
213 */ 225 */
214 struct GNUNET_OS_Process *server_proc; 226 struct GNUNET_OS_Process *server_proc;
@@ -521,11 +533,16 @@ process_external_ip (void *cls,
521 socklen_t addrlen) 533 socklen_t addrlen)
522{ 534{
523 struct GNUNET_NAT_Handle *h = cls; 535 struct GNUNET_NAT_Handle *h = cls;
536 struct in_addr dummy;
524 537
525 if (addr == NULL) 538 if (addr == NULL)
526 { 539 {
527 h->ext_dns = NULL; 540 h->ext_dns = NULL;
528 h->dns_task = GNUNET_SCHEDULER_add_delayed (DYNDNS_FREQUENCY, 541 if (1 == inet_pton (AF_INET,
542 h->external_address,
543 &dummy))
544 return; /* repated lookup pointless: was numeric! */
545 h->dns_task = GNUNET_SCHEDULER_add_delayed (h->dyndns_frequency,
529 &resolve_dns, h); 546 &resolve_dns, h);
530 return; 547 return;
531 } 548 }
@@ -562,7 +579,7 @@ process_hostname_ip (void *cls,
562 if (addr == NULL) 579 if (addr == NULL)
563 { 580 {
564 h->hostname_dns = NULL; 581 h->hostname_dns = NULL;
565 h->hostname_task = GNUNET_SCHEDULER_add_delayed (HOSTNAME_DNS_FREQUENCY, 582 h->hostname_task = GNUNET_SCHEDULER_add_delayed (h->hostname_dns_frequency,
566 &resolve_hostname, h); 583 &resolve_hostname, h);
567 return; 584 return;
568 } 585 }
@@ -955,7 +972,7 @@ list_interfaces (void *cls,
955 h->ifc_task = GNUNET_SCHEDULER_NO_TASK; 972 h->ifc_task = GNUNET_SCHEDULER_NO_TASK;
956 remove_from_address_list_by_source (h, LAL_INTERFACE_ADDRESS); 973 remove_from_address_list_by_source (h, LAL_INTERFACE_ADDRESS);
957 GNUNET_OS_network_interfaces_list (&process_interfaces, h); 974 GNUNET_OS_network_interfaces_list (&process_interfaces, h);
958 h->ifc_task = GNUNET_SCHEDULER_add_delayed (IFC_SCAN_FREQUENCY, 975 h->ifc_task = GNUNET_SCHEDULER_add_delayed (h->ifc_scan_frequency,
959 &list_interfaces, h); 976 &list_interfaces, h);
960} 977}
961 978
@@ -1128,6 +1145,25 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
1128 h->disable_ipv6 = GNUNET_CONFIGURATION_get_value_yesno(cfg, 1145 h->disable_ipv6 = GNUNET_CONFIGURATION_get_value_yesno(cfg,
1129 "nat", 1146 "nat",
1130 "DISABLEV6"); 1147 "DISABLEV6");
1148 if (GNUNET_OK !=
1149 GNUNET_CONFIGURATION_get_value_time (cfg,
1150 "nat",
1151 "DYNDNS_FREQUENCY",
1152 &h->dyndns_frequency))
1153 h->dyndns_frequency = DYNDNS_FREQUENCY;
1154 if (GNUNET_OK !=
1155 GNUNET_CONFIGURATION_get_value_time (cfg,
1156 "nat",
1157 "IFC_SCAN_FREQUENCY",
1158 &h->ifc_scan_frequency))
1159 h->ifc_scan_frequency = IFC_SCAN_FREQUENCY;
1160 if (GNUNET_OK !=
1161 GNUNET_CONFIGURATION_get_value_time (cfg,
1162 "nat",
1163 "HOSTNAME_DNS_FREQUENCY",
1164 &h->hostname_dns_frequency))
1165 h->hostname_dns_frequency = HOSTNAME_DNS_FREQUENCY;
1166
1131 if (NULL == reversal_callback) 1167 if (NULL == reversal_callback)
1132 h->enable_nat_server = GNUNET_NO; 1168 h->enable_nat_server = GNUNET_NO;
1133 1169