Commit bc2875c3 authored by Olivier Crête's avatar Olivier Crête

agent: Avoid calling nice_address_to_string() when debugging is disabled

parent 7832e1e2
......@@ -223,5 +223,21 @@ compact_output_message (const NiceOutputMessage *message, gsize *buffer_length);
gsize
output_message_get_size (const NiceOutputMessage *message);
/*
* nice_debug_init:
*
* Initialize the debugging system. Uses the NICE_DEBUG environment variable
* to set the appropriate debugging flags
*/
void nice_debug_init (void);
#ifdef NDEBUG
static inline gboolean nice_debug_is_enabled (void) { return FALSE };
static inline void nice_debug (const char *fmt, ...) G_GNUC_PRINTF (1, 2) { }
#else
gboolean nice_debug_is_enabled (void);
void nice_debug (const char *fmt, ...) G_GNUC_PRINTF (1, 2);
#endif
#endif /*_NICE_AGENT_PRIV_H */
......@@ -1307,18 +1307,16 @@ pseudo_tcp_socket_write_packet (PseudoTcpSocket *socket,
sock = component->selected_pair.local->sockptr;
#ifndef NDEBUG
{
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (&component->selected_pair.remote->addr, tmpbuf);
if (nice_debug_is_enabled ()) {
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (&component->selected_pair.remote->addr, tmpbuf);
nice_debug (
"Agent %p : s%d:%d: sending %d bytes on socket %p (FD %d) to [%s]:%d",
component->agent, component->stream->id, component->id, len,
sock->fileno, g_socket_get_fd (sock->fileno), tmpbuf,
nice_address_get_port (&component->selected_pair.remote->addr));
}
#endif
nice_debug (
"Agent %p : s%d:%d: sending %d bytes on socket %p (FD %d) to [%s]:%d",
component->agent, component->stream->id, component->id, len,
sock->fileno, g_socket_get_fd (sock->fileno), tmpbuf,
nice_address_get_port (&component->selected_pair.remote->addr));
}
addr = &component->selected_pair.remote->addr;
......@@ -1407,7 +1405,7 @@ void agent_gathering_done (NiceAgent *agent)
for (k = component->local_candidates; k; k = k->next) {
NiceCandidate *local_candidate = k->data;
{
if (nice_debug_is_enabled ()) {
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (&local_candidate->addr, tmpbuf);
nice_debug ("Agent %p: gathered local candidate : [%s]:%u"
......@@ -2117,10 +2115,13 @@ nice_agent_gather_candidates (
nice_address_set_port (addr, 0);
if (!host_candidate) {
gchar ip[NICE_ADDRESS_STRING_LEN];
nice_address_to_string (addr, ip);
nice_debug ("Agent %p: Unable to add local host candidate %s for s%d:%d"
". Invalid interface?", agent, ip, stream->id, component->id);
if (nice_debug_is_enabled ()) {
gchar ip[NICE_ADDRESS_STRING_LEN];
nice_address_to_string (addr, ip);
nice_debug ("Agent %p: Unable to add local host candidate %s for"
" s%d:%d. Invalid interface?", agent, ip, stream->id,
component->id);
}
ret = FALSE;
goto error;
}
......@@ -2346,7 +2347,7 @@ static gboolean priv_add_remote_candidate (
/* step: check whether the candidate already exists */
candidate = component_find_remote_candidate(component, addr, transport);
if (candidate) {
{
if (nice_debug_is_enabled ()) {
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (addr, tmpbuf);
nice_debug ("Agent %p : Updating existing remote candidate with addr [%s]:%u"
......@@ -2397,9 +2398,9 @@ static gboolean priv_add_remote_candidate (
if (addr)
candidate->addr = *addr;
{
if (nice_debug_is_enabled ()) {
gchar tmpbuf[INET6_ADDRSTRLEN] = {0};
if(addr)
if (addr)
nice_address_to_string (addr, tmpbuf);
nice_debug ("Agent %p : Adding remote candidate with addr [%s]:%u"
" for s%d/c%d. U/P '%s'/'%s' prio: %u", agent, tmpbuf,
......@@ -2626,15 +2627,13 @@ agent_recv_message_unlocked (
goto done;
}
#ifndef NDEBUG
if (message->length > 0) {
if (nice_debug_is_enabled () && message->length > 0) {
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (message->from, tmpbuf);
nice_debug ("Agent %p : Packet received on local socket %d from [%s]:%u (%" G_GSSIZE_FORMAT " octets).", agent,
g_socket_get_fd (socket->fileno), tmpbuf,
nice_address_get_port (message->from), message->length);
}
#endif
for (item = component->turn_servers; item; item = g_list_next (item)) {
TurnServer *turn = item->data;
......@@ -2643,10 +2642,8 @@ agent_recv_message_unlocked (
if (!nice_address_equal (message->from, &turn->server))
continue;
#ifndef NDEBUG
nice_debug ("Agent %p : Packet received from TURN server candidate.",
agent);
#endif
for (i = component->local_candidates; i; i = i->next) {
NiceCandidate *cand = i->data;
......@@ -2755,7 +2752,9 @@ static void
nice_debug_input_message_composition (const NiceInputMessage *messages,
guint n_messages)
{
#ifndef NDEBUG
if (!nice_debug_is_enabled ())
return;
guint i;
for (i = 0; i < n_messages; i++) {
......@@ -2775,7 +2774,6 @@ nice_debug_input_message_composition (const NiceInputMessage *messages,
buffer->size);
}
}
#endif
}
static guint8 *
......@@ -3293,14 +3291,14 @@ nice_agent_send_messages_nonblocking_internal (
NiceSocket *sock;
NiceAddress *addr;
#ifndef NDEBUG
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (&component->selected_pair.remote->addr, tmpbuf);
if (nice_debug_is_enabled ()) {
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (&component->selected_pair.remote->addr, tmpbuf);
nice_debug ("Agent %p : s%d:%d: sending %u messages to "
"[%s]:%d", agent, stream_id, component_id, n_messages, tmpbuf,
nice_address_get_port (&component->selected_pair.remote->addr));
#endif
nice_debug ("Agent %p : s%d:%d: sending %u messages to "
"[%s]:%d", agent, stream_id, component_id, n_messages, tmpbuf,
nice_address_get_port (&component->selected_pair.remote->addr));
}
sock = component->selected_pair.local->sockptr;
addr = &component->selected_pair.remote->addr;
......
......@@ -581,16 +581,18 @@ static gboolean priv_conn_keepalive_tick_unlocked (NiceAgent *agent)
uint8_t *password = NULL;
size_t password_len = priv_get_password (agent,
agent_find_stream (agent, stream->id), p->remote, &password);
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (&p->remote->addr, tmpbuf);
nice_debug ("Agent %p : Keepalive STUN-CC REQ to '%s:%u', "
"socket=%u (c-id:%u), username='%s' (%" G_GSIZE_FORMAT "), "
"password='%s' (%" G_GSIZE_FORMAT "), priority=%u.", agent,
tmpbuf, nice_address_get_port (&p->remote->addr),
g_socket_get_fd(((NiceSocket *)p->local->sockptr)->fileno), component->id,
uname, uname_len, password, password_len, priority);
if (nice_debug_is_enabled ()) {
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (&p->remote->addr, tmpbuf);
nice_debug ("Agent %p : Keepalive STUN-CC REQ to '%s:%u', "
"socket=%u (c-id:%u), username='%s' (%" G_GSIZE_FORMAT "), "
"password='%s' (%" G_GSIZE_FORMAT "), priority=%u.", agent,
tmpbuf, nice_address_get_port (&p->remote->addr),
g_socket_get_fd(((NiceSocket *)p->local->sockptr)->fileno),
component->id, uname, uname_len, password, password_len,
priority);
}
if (uname_len > 0) {
buf_len = stun_usage_ice_conncheck_create (&agent->stun_agent,
&p->keepalive.stun_message, p->keepalive.stun_buffer,
......@@ -1666,7 +1668,7 @@ int conn_check_send (NiceAgent *agent, CandidateCheckPair *pair)
password = g_base64_decode ((gchar *) password, &password_len);
}
{
if (nice_debug_is_enabled ()) {
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (&pair->remote->addr, tmpbuf);
nice_debug ("Agent %p : STUN-CC REQ to '%s:%u', socket=%u, "
......@@ -1904,7 +1906,7 @@ static void priv_reply_to_conn_check (NiceAgent *agent, Stream *stream, Componen
{
g_assert (rcand == NULL || nice_address_equal(&rcand->addr, toaddr) == TRUE);
{
if (nice_debug_is_enabled ()) {
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (toaddr, tmpbuf);
nice_debug ("Agent %p : STUN-CC RESP to '%s:%u', socket=%u, len=%u, cand=%p (c-id:%u), use-cand=%d.", agent,
......@@ -1917,7 +1919,7 @@ static void priv_reply_to_conn_check (NiceAgent *agent, Stream *stream, Componen
}
nice_socket_send (socket, toaddr, rbuf_len, (const gchar*)rbuf);
if (rcand) {
/* note: upon successful check, make the reserve check immediately */
priv_schedule_triggered_check (agent, stream, component, socket, rcand, use_candidate);
......@@ -2140,18 +2142,19 @@ static gboolean priv_map_reply_to_conn_check_request (NiceAgent *agent, Stream *
* sent the original request to (see 7.1.2.1. "Failure
* Cases") */
if (nice_address_equal (from, &p->remote->addr) != TRUE) {
gchar tmpbuf[INET6_ADDRSTRLEN];
gchar tmpbuf2[INET6_ADDRSTRLEN];
p->state = NICE_CHECK_FAILED;
nice_debug ("Agent %p : conncheck %p FAILED"
" (mismatch of source address).", agent, p);
nice_address_to_string (&p->remote->addr, tmpbuf);
nice_address_to_string (from, tmpbuf2);
nice_debug ("Agent %p : '%s:%u' != '%s:%u'", agent,
tmpbuf, nice_address_get_port (&p->remote->addr),
tmpbuf2, nice_address_get_port (from));
if (nice_debug_is_enabled ()) {
gchar tmpbuf[INET6_ADDRSTRLEN];
gchar tmpbuf2[INET6_ADDRSTRLEN];
nice_debug ("Agent %p : conncheck %p FAILED"
" (mismatch of source address).", agent, p);
nice_address_to_string (&p->remote->addr, tmpbuf);
nice_address_to_string (from, tmpbuf2);
nice_debug ("Agent %p : '%s:%u' != '%s:%u'", agent,
tmpbuf, nice_address_get_port (&p->remote->addr),
tmpbuf2, nice_address_get_port (from));
}
trans_found = TRUE;
break;
}
......@@ -2746,14 +2749,12 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
/* note: contents of 'buf' already validated, so it is
* a valid and fully received STUN message */
#ifndef NDEBUG
{
if (nice_debug_is_enabled ()) {
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (from, tmpbuf);
nice_debug ("Agent %p: inbound STUN packet for %u/%u (stream/component) from [%s]:%u (%u octets) :",
agent, stream->id, component->id, tmpbuf, nice_address_get_port (from), len);
}
#endif
/* note: ICE 7.2. "STUN Server Procedures" (ID-19) */
......
......@@ -43,6 +43,8 @@
#include "stunagent.h"
#include "pseudotcp.h"
#include "agent-priv.h"
static int debug_enabled = 0;
#define NICE_DEBUG_STUN 1
......@@ -91,6 +93,11 @@ void nice_debug_init (void)
}
}
gboolean nice_debug_is_enabled (void)
{
return debug_enabled;
}
void nice_debug_enable (gboolean with_stun)
{
nice_debug_init ();
......
......@@ -73,14 +73,6 @@
G_BEGIN_DECLS
/**
* nice_debug_init:
*
* Initialize the debugging system. Uses the NICE_DEBUG environment variable
* to set the appropriate debugging flags
*/
void nice_debug_init (void);
/**
* nice_debug_enable:
* @with_stun: Also enable stun debugging messages
......@@ -97,8 +89,6 @@ void nice_debug_enable (gboolean with_stun);
*/
void nice_debug_disable (gboolean with_stun);
void nice_debug (const char *fmt, ...) G_GNUC_PRINTF (1, 2);
G_END_DECLS
#endif /* _DEBUG_H */
......
......@@ -846,7 +846,7 @@ static gboolean priv_discovery_tick_unlocked (gpointer pointer)
if (agent->discovery_unsched_items)
--agent->discovery_unsched_items;
{
if (nice_debug_is_enabled ()) {
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (&cand->server, tmpbuf);
nice_debug ("Agent %p : discovery - scheduling cand type %u addr %s.\n",
......
......@@ -27,7 +27,7 @@
#endif
#include "interfaces.h"
#include "debug.h"
#include "agent-priv.h"
#ifdef G_OS_UNIX
......
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