Commit 9bae6304 authored by Martti Mela's avatar Martti Mela

added timeout timer for STUN's connect()

darcs-hash:20051215170037-1b897-49938b70cc68bf69543ebb4fd4f06710b3846cb1.gz
parent 7bbb41a1
2005-12-02 Pekka Pessi <Pekka.Pessi@nokia.com>
Again, syncing darcs and CVS.
* Disabling stun for the moment, use --enable-stun to use it. [pp]
M ./configure.ac -2 +9
* working async stun support [mm]
M ./libsofia-sip-ua/stun/stun.c -139 +131
M ./libsofia-sip-ua/stun/stun.h -1 +3
M ./libsofia-sip-ua/stun/stun_common.c -14 +18
M ./libsofia-sip-ua/stun/stunc.c -21 +15
M ./libsofia-sip-ua/stun/torture_stun.c -1 +1
* initial async stun support. Does not work with tport yet. [mm]
M ./libsofia-sip-ua/stun/stun.c -269 +350
M ./libsofia-sip-ua/stun/stun.h -6 +28
M ./libsofia-sip-ua/stun/stun_common.c -5 +23
M ./libsofia-sip-ua/stun/stun_common.h -1 +1
M ./libsofia-sip-ua/stun/stun_internal.h -4 +5
M ./libsofia-sip-ua/stun/stunc.c -3 +10
M ./libsofia-sip-ua/stun/torture_stun.c -2 +2
* async stunning contd. Juhui! [mm]
M ./libsofia-sip-ua/stun/stun.c -19 +13
M ./libsofia-sip-ua/stun/stun_common.c -4 +9
M ./libsofia-sip-ua/stun/stun_internal.h -1 +16
* stun asyncing contd. NOT WORKING [mm]
M ./libsofia-sip-ua/stun/stun.c -70 +86
M ./libsofia-sip-ua/stun/stun.h -9 +7
M ./libsofia-sip-ua/stun/stun_common.c -3 +8
M ./libsofia-sip-ua/stun/stun_common.h -1 +4
M ./libsofia-sip-ua/stun/stun_internal.h -3 +6
M ./libsofia-sip-ua/stun/stunc.c -13 +17
M ./libsofia-sip-ua/stun/torture_stun.c -12 +15
* stun async contd. [mm]
M ./libsofia-sip-ua/stun/stun.c -26 +56
M ./libsofia-sip-ua/stun/stun.h +4
M ./libsofia-sip-ua/stun/stunc.c -4 +9
* DON'T APPLY THIS: does not work. I need this for syncing. [mm]
M ./libsofia-sip-ua/stun/stun.c -81 +209
M ./libsofia-sip-ua/stun/stun.h -3 +15
M ./libsofia-sip-ua/stun/stun_internal.h -1 +1
M ./libsofia-sip-ua/stun/stunc.c -3 +7
M ./libsofia-sip-ua/stun/torture_stun.c -4 +4
* async connect continued [mm]
M ./libsofia-sip-ua/stun/stun.c -24 +71
* async stun continued [mm]
M ./libsofia-sip-ua/stun/stun.c -27 +53
M ./libsofia-sip-ua/stun/torture_stun.c +7
M ./libsofia-sip-ua/tport/test_tport.c -1 +8
M ./libsofia-sip-ua/tport/tport.c -1 +2
* su_localinfo returns now valid address also in Windows [mm]
M ./libsofia-sip-ua/nua/test_nua.c +3
M ./libsofia-sip-ua/su/su_localinfo.c +4
* tport cygwin modifications [mm]
M ./libsofia-sip-ua/tport/tport.c -3 +7
* Declaring h_errno as a variable imported from DLL (when using WIN32). [pp]
M ./libsofia-sip-ua/su/su_addrinfo.c -3 +8
* Try random port next if a port is taken. [pp]
M ./libsofia-sip-ua/tport/tport.c -1 +2
* Moved LGPL reference so that it will be included in the autogenerated
files. [pp]
M ./libsofia-sip-ua/http/http_parser_table.c.in -8 +8
M ./libsofia-sip-ua/http/http_protos.h.in -6 +6
M ./libsofia-sip-ua/http/http_tag.c.in -8 +8
M ./libsofia-sip-ua/http/http_tag.h.in -7 +7
M ./libsofia-sip-ua/msg/msg_mime_protos.h.in -6 +6
M ./libsofia-sip-ua/msg/msg_protos.h.in -6 +6
M ./libsofia-sip-ua/msg/test_protos.h.in -7 +7
M ./libsofia-sip-ua/sip/sip_hclasses.h.in -6 +7
M ./libsofia-sip-ua/sip/sip_parser_table.c.in -7 +7
M ./libsofia-sip-ua/sip/sip_protos.h.in -5 +5
M ./libsofia-sip-ua/sip/sip_rfc2543.h.in -6 +5
M ./libsofia-sip-ua/sip/sip_tag.c.in -7 +7
M ./libsofia-sip-ua/sip/sip_tag.h.in -7 +7
* Collected copyrights belonging someone else but Nokia to COPYRIGHTS
file. [pp]
M ./COPYRIGHTS -1 +223
M ./libsofia-sip-ua/ipt/rc4.c -24
M ./libsofia-sip-ua/su/getopt.c -24
M ./libsofia-sip-ua/su/su_md5.c -11 +14
* Fixed bug in su_addrinfo.c [FIX]. [pp]
Setting ai_addrlen even if there is no sa_len.
M ./libsofia-sip-ua/su/su_addrinfo.c +1
* sresolv now compiles without IPv6 [mm]
M ./libsofia-sip-ua/nua/nua.h -2
M ./libsofia-sip-ua/sresolv/sresolv.c -1 +1
M ./libsofia-sip-ua/tport/tport.c -1 +1
* using 500 timers instead of 500000 timers in su_timer_test [mm]
M ./libsofia-sip-ua/su/su_timer_test.c -2 +2
* added #include <netinet/tcp.h> to stun_common.h [mm]
M ./libsofia-sip-ua/nth/Makefile.am -3 +2
M ./libsofia-sip-ua/stun/stun_common.h +1
* added stun_internal.h [mm]
A ./libsofia-sip-ua/stun/stun_internal.h
* tport_stun_cb parameter type change [mm]
R ./libsofia-sip-ua/sip/sip_p_tag.c
M ./libsofia-sip-ua/tport/tport.c -1 +1
* initial async stun, compiles not works. [mm]
M ./libsofia-sip-ua/nth/Makefile.am -2 +3
M ./libsofia-sip-ua/sip/sip_p_tag.c -105
M ./libsofia-sip-ua/stun/stun.c -65 +121
M ./libsofia-sip-ua/stun/stun.h -23 +18
M ./libsofia-sip-ua/stun/stunc.c -2 +26
M ./libsofia-sip-ua/stun/torture_stun.c -4 +29
M ./libsofia-sip-ua/tport/tport.c -3 +17
* Removed sip_rfc2543{.h,.h.in,.c} from dist. [pp]
M ./libsofia-sip-ua/sip/Makefile.am -3 +2
2005-12-02 Pekka Pessi <Pekka.Pessi@nokia.com>
Syncing darcs and CVS.
......
......@@ -61,8 +61,15 @@ AC_DEFINE([HAVE_SOFIA_SIP], 1, [Define as 1 always])
AC_DEFINE([HAVE_SOFIA_SRESOLV], 1, [Define as 1 if we use DNS library])
AC_DEFINE([HAVE_SOFIA_SMIME], 0, [Define as 1 if we use S/MIME library])
dnl compile STUN only if OPENSSL is available
if test x${HAVE_OPENSSL} != x1 ; then
dnl Disable stun by default while it is broken
AC_ARG_ENABLE(stun,
[ --enable-stun enable stun module (disabled)],
, enable_stun=no)
if test x$enable_stun = xno ; then
AC_MSG_WARN([** STUN support disabled **])
elif test x${HAVE_OPENSSL} != x1 ; then
dnl compile STUN only if OPENSSL is available
AC_MSG_WARN([** STUN support disabled as OpenSSL headers and/or libraries were not found **])
else
AC_DEFINE([HAVE_SOFIA_STUN], 1, [Define as 1 if we use STUN library])
......
2005-12-15 Martti Mela <martti.mela@nokia.com>
* STUN updated to work asynchronously.
* stun.c: added timeout timer for connect() (defaults to 8 seconds).
* stun_internal.h: added.
* stun.h: Does not contain functions that are interal. Cleaned the API. Specified
more states for stun_states_t.
2005-11-19 Kai Vehmanen <kaiv@.devtag.AUTHORS>
* stun.h (stun_set_uname_pwd): Changed from unsigned to signed
......
......@@ -60,9 +60,11 @@
su_log_t stun_log[] = { SU_LOG_INIT("stun", "STUN_DEBUG", SU_DEBUG) };
enum {
STUN_TIMEOUT = 1000,
STUN_SENDTO_TIMEOUT = 1000,
STUN_CONNECT_TIMEOUT = 8000,
};
char const stun_nat_unknown[] = "NAT type undetermined",
stun_open_internet[] = "Open Internet",
stun_udp_blocked[] = "UDP traffic is blocked, or Server unreachable",
......@@ -115,11 +117,25 @@ struct stun_socket_s
{
stun_engine_t *ss_engine;
int ss_sockfd;
int ss_root_index; /**< object index of su_root_register() */
};
char const stun_version[] =
"sofia-sip-stun using " OPENSSL_VERSION_TEXT;
static void stun_sendto_timer_cb(su_root_magic_t *magic,
su_timer_t *t,
stun_engine_t *se);
static void stun_connect_timer_cb(su_root_magic_t *magic,
su_timer_t *t,
stun_engine_t *se);
/**
* Return su_root_t assigned to stun_engine_t.
*
......@@ -245,7 +261,7 @@ stun_engine_t *stun_engine_tcreate(stun_magic_t *context,
stun->st_retry_count = 0;
/* default timeout for next sendto() */
stun->st_timeout = STUN_TIMEOUT;
stun->st_timeout = STUN_SENDTO_TIMEOUT;
/* alternative address set to 0 */
......@@ -591,15 +607,14 @@ int stun_connect_wait(su_root_magic_t *m, su_wait_t *w, stun_engine_t *self)
SU_DEBUG_3(("Shared secret NOT obtained from server. " \
"Proceed without username/password.\n"));
self->st_state = stun_no_shared_secret_obtained;
self->st_state = stun_client_connection_failed;
self->st_callback(self->st_context, self, self->st_state);
return 0;
}
self->st_state = stun_shared_secret_obtained;
self->st_state = stun_client_connected;
self->st_callback(self->st_context, self, self->st_state);
/* compose shared secret request */
if (stun_make_sharedsecret_req(&req) != 0) {
STUN_ERROR(errno, stun_make_sharedsecret_req);
......@@ -644,7 +659,7 @@ int stun_connect_wait(su_root_magic_t *m, su_wait_t *w, stun_engine_t *self)
}
/* Inform application about the progress */
self->st_state = stun_connect_success;
self->st_state = stun_client_connected;
self->st_callback(self->st_context, self, self->st_state);
SU_DEBUG_3(("TLS connection using %s\n", SSL_get_cipher(ssl)));
......@@ -718,6 +733,28 @@ int stun_connect_wait(su_root_magic_t *m, su_wait_t *w, stun_engine_t *self)
return 0;
}
static void stun_connect_timer_cb(su_root_magic_t *magic,
su_timer_t *t,
stun_engine_t *se)
{
SU_DEBUG_3(("%s: connect() timeout.\n", __func__));
if (se->st_state != stun_client_connecting) {
su_destroy_timer(t);
return;
}
su_root_deregister(se->st_root, se->st_root_index);
se->st_state = stun_client_connection_timeout;
se->st_callback(se->st_context, se, se->st_state);
return;
}
/** Shared secret request/response processing */
int stun_connect_start(stun_engine_t *se)
{
......@@ -728,6 +765,7 @@ int stun_connect_start(stun_engine_t *se)
int family;
su_addrinfo_t *ai = NULL;
su_addrinfo_t *name;
su_timer_t *connect_timer = NULL;
assert(se);
ai = &se->st_pri_info;
......@@ -775,15 +813,19 @@ int stun_connect_start(stun_engine_t *se)
SU_DEBUG_3(("%s: %s: %s\n", __func__, "connect",
su_strerror(err)));
if (su_root_register(se->st_root,
wait,
stun_connect_wait,
se,
0) == -1) {
if ((se->st_root_index =
su_root_register(se->st_root, wait, stun_connect_wait, se, 0)) == -1) {
STUN_ERROR(errno, su_root_register);
return -1;
}
se->st_state = stun_client_connecting;
/* Create and start timer for connect() timeout */
SU_DEBUG_3(("%s: creating timeout timer for connect()\n", __func__));
connect_timer = su_timer_create(su_root_task(se->st_root), STUN_CONNECT_TIMEOUT);
su_timer_set(connect_timer, stun_connect_timer_cb, se);
return 0;
}
......@@ -869,7 +911,7 @@ int stun_send_wait(su_root_magic_t *m, su_wait_t *w, stun_engine_t *self)
/* Allow incoming events (recvfrom) */
events = SU_WAIT_IN | SU_WAIT_ERR; /* | SU_WAIT_OUT */
su_root_eventmask(self->st_root, self->st_root_index, s, events);
su_root_eventmask(self->st_root, ss->ss_root_index, s, events);
}
/* receive response */
......@@ -966,12 +1008,7 @@ int stun_send_wait(su_root_magic_t *m, su_wait_t *w, stun_engine_t *self)
}
static void stun_timer_callback(su_root_magic_t *magic,
su_timer_t *t,
stun_engine_t *se);
static void stun_timer_callback(su_root_magic_t *magic,
static void stun_sendto_timer_cb(su_root_magic_t *magic,
su_timer_t *t,
stun_engine_t *se)
{
......@@ -992,7 +1029,7 @@ static void stun_timer_callback(su_root_magic_t *magic,
/* check if max retry count has been exceeded */
if (se->st_retry_count >= se->st_max_retries) {
errno = ETIMEDOUT;
STUN_ERROR(errno, stun_timer_callback);
STUN_ERROR(errno, stun_sendto_timer_cb);
stun_free_message(se->st_binding_request);
free(se->st_binding_request), se->st_binding_request = NULL;
......@@ -1000,7 +1037,7 @@ static void stun_timer_callback(su_root_magic_t *magic,
/* set timeout to default value */
se->st_retry_count = 0;
se->st_timeout = STUN_TIMEOUT;
se->st_timeout = STUN_SENDTO_TIMEOUT;
su_timer_destroy(t);
se->st_state = stun_client_timeout;
......@@ -1016,7 +1053,7 @@ static void stun_timer_callback(su_root_magic_t *magic,
return;
}
su_timer_set_at(t, stun_timer_callback, se, su_time_add(su_now(), se->st_timeout *= 2));
su_timer_set_at(t, stun_sendto_timer_cb, se, su_time_add(su_now(), se->st_timeout *= 2));
return;
}
......@@ -1063,7 +1100,7 @@ int stun_bind_test(stun_socket_t *ss,
unsigned rmem = 0, wmem = 0;
su_wait_t wait[1] = { SU_WAIT_INIT };
su_timer_t *send_timer = NULL;
su_timer_t *sendto_timer = NULL;
char ipaddr[SU_ADDRSIZE + 2];
struct sockaddr_in recv_addr;
......@@ -1099,7 +1136,7 @@ int stun_bind_test(stun_socket_t *ss,
}
/* Register receiving function with events specified above */
if ((se->st_root_index = su_root_register(se->st_root,
if ((ss->ss_root_index = su_root_register(se->st_root,
wait, stun_send_wait,
se, 0)) < 0) {
STUN_ERROR(errno, su_root_register);
......@@ -1107,8 +1144,8 @@ int stun_bind_test(stun_socket_t *ss,
}
/* Create and start timer */
send_timer = su_timer_create(su_root_task(se->st_root), STUN_TIMEOUT);
su_timer_set(send_timer, stun_timer_callback, se);
sendto_timer = su_timer_create(su_root_task(se->st_root), STUN_SENDTO_TIMEOUT);
su_timer_set(sendto_timer, stun_sendto_timer_cb, se);
se->st_state = stun_client_sending;
/* se->st_callback(se->st_context, se, se->st_state); */
......
......@@ -59,16 +59,18 @@ extern char const stun_version[]; /**< Name and version of STUN software */
typedef enum stun_states_e {
/* stun engine errors */
stun_connect_error = -10,
stun_no_shared_secret_obtained = -9,
stun_client_connection_timeout = -10,
stun_client_connection_failed = -9,
stun_no_shared_secret_obtained = -8,
/* stun client errors */
stun_client_error = -5, /**< Sending query to server */
stun_client_error = -5,
stun_client_timeout = -1,
/* stun_engine related */
stun_shared_secret_obtained = 0,
stun_connect_success,
stun_client_connecting,
stun_client_connected,
/* client: stun socket */
......
......@@ -6842,11 +6842,13 @@ void thrp_udp_send_report(su_root_magic_t *magic,
#if HAVE_SOFIA_STUN
int tport_stun_cb(tport_master_t *tport, stun_engine_t *se)
void tport_stun_cb(tport_master_t *tport,
stun_engine_t *se,
stun_states_t event)
{
/* xxx - mela: here events that can be sent to nua_events */
return 0;
return;
}
#endif
......@@ -6939,7 +6941,7 @@ int tport_nat_stun_bind(struct tport_nat_s *nat,
{
int nat_bound = 0, lifetime = 0, bind_res = 0;
nat->stun_socket = stun_socket_create(nat->stun, s);
bind_res = stun_bind(nat->stun_socket, &su->su_sa, sulen, &lifetime);
bind_res = stun_bind(nat->stun_socket, /* &su->su_sa, sulen, */ &lifetime);
if (bind_res >= 0) {
SU_DEBUG_9(("%s: stun_bind() ok\n", __func__));
nat->stun_enabled = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment