timer based nat_map refresh

This commit is contained in:
Rupa Schomaker 2010-06-20 19:21:42 -05:00
parent 3d54eec814
commit b36f2a23bf
3 changed files with 27 additions and 0 deletions

8
src/include/switch_nat.h Normal file → Executable file
View File

@ -57,6 +57,14 @@ typedef enum {
\note Generally called by the core_init
*/
SWITCH_DECLARE(void) switch_nat_init(switch_memory_pool_t *pool);
/*!
\brief Initilize the rest of the NAT Traversal System
\note nat_init is called prior to some other modules being loaded.
This method allows us to init the rest of the NAT system.
*/
SWITCH_DECLARE(void) switch_nat_late_init(void);
/*!
\brief Shuts down the NAT Traversal System
*/

2
src/switch_core.c Normal file → Executable file
View File

@ -1325,6 +1325,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
switch_scheduler_task_thread_start();
switch_nat_late_init();
switch_rtp_init(runtime.memory_pool);
runtime.running = 1;

17
src/switch_nat.c Normal file → Executable file
View File

@ -41,6 +41,7 @@
#define MULTICAST_BUFFSIZE 65536
#define IP_LEN 16
#define NAT_REFRESH_INTERVAL 900
typedef struct {
switch_nat_type_t nat_type;
@ -677,6 +678,22 @@ SWITCH_DECLARE(void) switch_nat_republish(void)
switch_xml_free(natxml);
}
SWITCH_STANDARD_SCHED_FUNC(switch_nat_republish_sched)
{
switch_nat_republish();
if (nat_globals_perm.running == 1) {
task->runtime = switch_epoch_time_now(NULL) + NAT_REFRESH_INTERVAL;
}
}
SWITCH_DECLARE(void) switch_nat_late_init(void)
{
if (nat_globals_perm.running == 1) {
switch_scheduler_add_task(switch_epoch_time_now(NULL) + NAT_REFRESH_INTERVAL, switch_nat_republish_sched, "nat_republish", "core", 0, NULL,
SSHF_NONE);
}
}
SWITCH_DECLARE(char *) switch_nat_status(void)
{
switch_stream_handle_t stream = { 0 };