Commit 8d1a9b66 authored by Martti Mela's avatar Martti Mela

default STUN debug changed to less informative

darcs-hash:20060109124007-1b897-e4a80098599d681483967a842deec4e2842b047a.gz
parent 4a22f24f
......@@ -24,6 +24,7 @@ stun_prog_targets =
endif
noinst_LTLIBRARIES = libstun.la
noinst_PROGRAMS = ${stun_prog_targets}
# ----------------------------------------------------------------------
......@@ -42,12 +43,17 @@ LDADD = libstun.la \
torture_stun_LDFLAGS = -static
# ----------------------------------------------------------------------
# tests
# XXX: torture_stun cannot be used as a automake test as is
#TESTS = torture_stun
# ----------------------------------------------------------------------
# Install and distribution rules
# ----------------------------------------------------------------------
# Sofia specific rules
# XXX: torture_stun cannot be used as a automake test as is
#TESTS = torture_stun
include ../sofia.am
TAG_DLL_FLAGS = LIST=stun_tag_list
......@@ -1456,14 +1456,14 @@ int process_get_lifetime(stun_request_t *req, stun_msg_t *binding_response)
sd->sd_lt_cur = sd->sd_lt;
sd->sd_lt = (int) (sd->sd_lt + sd->sd_lt_max) / 2;
SU_DEBUG_3(("%s: Response received from socket X, " \
SU_DEBUG_1(("%s: Response received from socket X, " \
"lifetime at least %d sec, next trial: %d sec\n",
__func__, sd->sd_lt_cur, sd->sd_lt));
}
else {
sd->sd_lt_max = sd->sd_lt;
sd->sd_lt = (int) (sd->sd_lt + sd->sd_lt_cur) / 2;
SU_DEBUG_3(("%s: No response received from socket X, " \
SU_DEBUG_1(("%s: No response received from socket X, " \
"lifetime at most %d sec, next trial: %d sec\n",
__func__, sd->sd_lt_max, sd->sd_lt));
}
......@@ -2066,7 +2066,7 @@ int stun_handle_get_lifetime(stun_handle_t *sh,
sd->sd_socket = sockfdy;
sd->sd_from_y = -1;
SU_DEBUG_3(("%s: determining binding life time, this may take a while.\n", __func__));
SU_DEBUG_1(("%s: determining binding life time, this may take a while.\n", __func__));
if (stun_make_binding_req(sh, req, req->sr_msg, 0, 0) < 0)
return -1;
......@@ -2082,131 +2082,6 @@ int stun_handle_get_lifetime(stun_handle_t *sh,
return 0;
}
#if 0
int stun_handle_get_lifetime(stun_handle_t *sh,
su_localinfo_t *my_addr,
int *addrlen,
int *lifetime)
{
int retval = -1, sockfdx, sockfdy;
socklen_t x_len, y_len, recv_addr_len, mapped_len;
struct sockaddr_in *clnt_addr = 0, x_addr, y_addr, recv_addr, mapped_addr;
int lt_cur=0, lt=STUN_LIFETIME_EST, lt_max = STUN_LIFETIME_MAX;
stun_attr_t *mapped_addr_attr;
/* testing su_getlocalinfo() */
su_localinfo_t hints[1] = {{ LI_CANONNAME | LI_NUMERIC }}, *li, *res = NULL;
int i, error, found=0, z;
fd_set rfds;
struct timeval tv;
stun_msg_t binding_request, binding_response;
unsigned char dgram[512];
assert(sh);
SU_DEBUG_3(("%s: determining binding life time, this may take a while.\n", __func__));
/* get local ip address */
clnt_addr = (struct sockaddr_in *) my_addr;
/* run protocol here... */
sockfdx = sh->sh_bind_socket;
i = 1;
while (abs(lt_cur-lt) > STUN_LIFETIME_CI) {
SU_DEBUG_3(("%s: Lifetime determination round %d, testing lifetime of %d sec.\n", __func__, i++, lt));
/* send request from X */
if (stun_make_binding_req(sh, NULL, &binding_request, 0, 0) < 0)
return retval;
if (stun_send_message(sockfdx, sh->sh_pri_addr, &binding_request, &(sh->sh_passwd)) < 0)
return retval;
FD_ZERO(&rfds);
FD_SET(sockfdx, &rfds); /* Set sockfdx for read monitoring */
z = 0;
tv.tv_sec = 5;
tv.tv_usec = 0;
if(select(sockfdx+1, &rfds, NULL, NULL, &tv)) {
/* response received */
recv_addr_len = sizeof(recv_addr);
z = recvfrom(sockfdx, dgram, 512, 0,
(struct sockaddr *)&recv_addr, &recv_addr_len);
if(z<0) {
return retval;
}
binding_response.enc_buf.data = (unsigned char *)malloc(z);
binding_response.enc_buf.size = z;
memcpy(binding_response.enc_buf.data, dgram, z);
SU_DEBUG_3(("%s: response from server %s:%u\n", __func__, inet_ntoa(recv_addr.sin_addr), ntohs(recv_addr.sin_port)));
debug_print(&binding_response.enc_buf);
}
else {
SU_DEBUG_3(("%s: No response from server. Check configuration.\n", __func__));
return retval;
}
/* process response */
if (stun_parse_message(&binding_response) < 0) {
SU_DEBUG_5(("%s: Error parsing response.\n", __func__));
return retval;
}
if (binding_response.stun_hdr.msg_type == BINDING_RESPONSE) {
memset(&mapped_addr, 0, sizeof(mapped_addr)); mapped_len = sizeof(mapped_addr);
mapped_addr_attr = stun_get_attr(binding_response.stun_attr, MAPPED_ADDRESS);
if (mapped_addr_attr != NULL) {
memcpy(&mapped_addr, mapped_addr_attr->pattr, mapped_len);
}
else {
return retval;
}
}
stun_free_message(&binding_request);
stun_free_message(&binding_response);
sleep(lt);
/* send from sockfdy */
if (stun_make_binding_req(sh, NULL, &binding_request, 0, 0) <0)
return retval;
stun_add_response_address(&binding_request, &mapped_addr);
if (stun_send_message(sockfdy, sh->sh_pri_addr, &binding_request, &(sh->sh_passwd)) < 0)
return retval;
FD_ZERO(&rfds);
FD_SET(sockfdx, &rfds); /* Set sockfdx for read monitoring */
z = 0;
tv.tv_sec = 5;
tv.tv_usec = 0;
if(select(sockfdx+1, &rfds, NULL, NULL, &tv)) {
/* response received */
recv_addr_len = sizeof(recv_addr);
z = recvfrom(sockfdx, dgram, 512, 0,
(struct sockaddr *)&recv_addr, &recv_addr_len);
if(z<0) {
return retval;
}
/* mapping with X still valid */
lt_cur = lt;
lt = (int) (lt+lt_max)/2;
SU_DEBUG_3(("%s: Response received from socket X, lifetime at least %d sec, next trial: %d sec\n\n", __func__,
lt_cur, lt));
}
else {
/* no response */
lt_max = lt;
lt = (int) (lt+lt_cur)/2;
SU_DEBUG_3(("%s: No response received from socket X, lifetime at most %d sec, next trial: %d sec\n\n", __func__,
lt_max, lt));
}
}
*lifetime = lt_cur;
return 0;
}
#endif
int stun_add_response_address(stun_msg_t *req, struct sockaddr_in *mapped_addr)
{
stun_attr_sockaddr_t *addr;
......
......@@ -45,7 +45,7 @@
#ifndef SU_DEBUG
#define SU_DEBUG 3
#define SU_DEBUG 0
#endif
#define SU_LOG (stun_log)
#include <su_debug.h>
......@@ -129,7 +129,7 @@ int stun_parse_attribute(stun_msg_t *msg, unsigned char *p) {
p+=2;
len = ntohs(tmp16);
SU_DEBUG_1(("%s: received attribute: Type %02X, Length %d - %s\n", __func__,
SU_DEBUG_3(("%s: received attribute: Type %02X, Length %d - %s\n", __func__,
attr->attr_type, len, stun_attr_phrase(attr->attr_type)));
switch(attr->attr_type) {
......@@ -212,7 +212,7 @@ int stun_parse_attr_address(stun_attr_t *attr, const unsigned char *p, unsigned
memcpy(&addr->sin_port, p+2, 2);
memcpy(&addr->sin_addr.s_addr, p+4, 4);
SU_DEBUG_1(("%s: address attribute: %s:%d\n", __func__, inet_ntoa(addr->sin_addr), ntohs(addr->sin_port)));
SU_DEBUG_3(("%s: address attribute: %s:%d\n", __func__, inet_ntoa(addr->sin_addr), ntohs(addr->sin_port)));
attr->pattr = addr;
stun_init_buffer(&attr->enc_buf);
......
......@@ -31,6 +31,10 @@
* @author Kai Vehmanen <kai.vehmanen@nokia.com>
*/
#ifndef SU_DEBUG
#define SU_DEBUG 0
#endif
#ifndef SU_WAIT_H
#include <su_wait.h>
#endif
......@@ -43,9 +47,6 @@
#include "stun.h"
#endif
#ifndef SU_DEBUG
#define SU_DEBUG 3
#endif
#define SU_LOG (stun_log)
#include <su_debug.h>
......
......@@ -45,7 +45,7 @@ typedef struct stunc_s stunc_t;
#include <su.h>
#ifndef SU_DEBUG
#define SU_DEBUG 3
#define SU_DEBUG 0
#endif
#define SU_LOG (stun_log)
#include <su_debug.h>
......@@ -84,11 +84,11 @@ void stunc_callback(stunc_t *stunc, stun_handle_t *sh,
case stun_discovery_done:
if (action == stun_action_get_nattype) {
nattype = stun_nattype(sd);
SU_DEBUG_3(("%s: NAT type: %s\n", __func__, nattype));
SU_DEBUG_0(("%s: NAT type: %s\n", __func__, nattype));
}
else if (action == stun_action_get_lifetime) {
lifetime = stun_lifetime(sd);
SU_DEBUG_3(("%s: Life time is %d s.\n", __func__, lifetime));
SU_DEBUG_0(("%s: Life time is %d s.\n", __func__, lifetime));
}
su_root_break(stun_handle_root(sh));
......@@ -97,13 +97,13 @@ void stunc_callback(stunc_t *stunc, stun_handle_t *sh,
case stun_bind_done:
li = stun_request_get_localinfo(req);
inet_ntop(li->li_family, SU_ADDR(li->li_addr), ipaddr, sizeof(ipaddr)),
SU_DEBUG_3(("%s: local address NATed as %s:%u\n", __func__,
SU_DEBUG_0(("%s: local address NATed as %s:%u\n", __func__,
ipaddr, (unsigned) ntohs(li->li_addr->su_port)));
su_root_break(stun_handle_root(sh));
break;
case stun_bind_error:
SU_DEBUG_3(("%s: no nat detected\n", __func__));
SU_DEBUG_0(("%s: no nat detected\n", __func__));
su_root_break(stun_handle_root(sh));
break;
......@@ -143,7 +143,7 @@ int main(int argc, char *argv[])
TAG_NULL());
if (!se) {
SU_DEBUG_3(("%s: %s failed\n", __func__, "stun_handle_tcreate()"));
SU_DEBUG_0(("%s: %s failed\n", __func__, "stun_handle_tcreate()"));
return -1;
}
......@@ -157,35 +157,27 @@ int main(int argc, char *argv[])
s = su_socket(AF_INET, SOCK_DGRAM, 0);
if (s == -1) {
SU_DEBUG_3(("%s: %s failed: %s\n", __func__, "stun_socket_create()", su_gli_strerror(errno)));
SU_DEBUG_0(("%s: %s failed: %s\n", __func__, "stun_socket_create()", su_gli_strerror(errno)));
return -1;
}
#if 0
if (stun_handle_set_bind_socket(se, s) < 0) {
SU_DEBUG_3(("%s: %s failed\n", __func__, "stun_handle_set_bind_socket()"));
return -1;
}
#endif
lifetime = 0;
if (stun_handle_bind(se, &lifetime, STUNTAG_SOCKET(s), TAG_NULL()) < 0) {
SU_DEBUG_3(("%s: %s failed\n", __func__, "stun_handle_bind()"));
SU_DEBUG_0(("%s: %s failed\n", __func__, "stun_handle_bind()"));
return -1;
}
su_root_run(root);
if (stun_handle_get_nattype(se, /* STUNTAG_SOCKET(s), */ TAG_NULL()) < 0) {
SU_DEBUG_3(("%s: %s failed\n", __func__, "stun_handle_get_nattype()"));
SU_DEBUG_0(("%s: %s failed\n", __func__, "stun_handle_get_nattype()"));
return -1;
}
su_root_run(root);
if (stun_handle_get_lifetime(se, /* STUNTAG_SOCKET(s), */ TAG_NULL()) < 0) {
SU_DEBUG_3(("%s: %s failed\n", __func__, "stun_handle_get_lifetime()"));
SU_DEBUG_0(("%s: %s failed\n", __func__, "stun_handle_get_lifetime()"));
return -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