Commit bc2875c3 authored by Olivier Crête's avatar Olivier Crête 👻
Browse files

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