Skip to content

Commit

Permalink
cleanup: Disable LAN discovery in TCP-only mode.
Browse files Browse the repository at this point in the history
It causes warnings in the logs.

Also added the IP/Port to TCP connect logging.
  • Loading branch information
iphydf committed Mar 7, 2022
1 parent 0d8b9b6 commit 0bc00ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 6 additions & 8 deletions toxcore/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,8 @@ bool net_connect(const Logger *log, Socket sock, const IP_Port *ip_port)
{
struct sockaddr_storage addr = {0};
size_t addrsize;
char ip_str[IP_NTOA_LEN];
ip_ntoa(&ip_port->ip, ip_str, sizeof(ip_str));

if (net_family_is_ipv4(ip_port->ip.family)) {
struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr;
Expand All @@ -1445,27 +1447,23 @@ bool net_connect(const Logger *log, Socket sock, const IP_Port *ip_port)
fill_addr6(&ip_port->ip.ip.v6, &addr6->sin6_addr);
addr6->sin6_port = ip_port->port;
} else {
char ip_str[IP_NTOA_LEN];
LOGGER_ERROR(log, "cannot connect to %s:%d which is neither IPv4 nor IPv6",
ip_ntoa(&ip_port->ip, ip_str, sizeof(ip_str)), ip_port->port);
LOGGER_ERROR(log, "cannot connect to %s:%d which is neither IPv4 nor IPv6", ip_str, ip_port->port);
return false;
}

#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
return true;
#else
LOGGER_DEBUG(log, "connecting socket %d", (int)sock.sock);
LOGGER_DEBUG(log, "connecting socket %d to %s:%d",
(int)sock.sock, ip_ntoa(&ip_port->ip, ip_str, sizeof(ip_str)), ip_port->port);
errno = 0;
if (connect(sock.sock, (struct sockaddr *)&addr, addrsize) == -1) {
const int error = net_error();

// Non-blocking socket: "Operation in progress" means it's connecting.
if (!should_ignore_connect_error(error)) {
char *net_strerror = net_new_strerror(error);
char ip_str[IP_NTOA_LEN];
LOGGER_ERROR(log, "failed to connect to %s:%d: %d (%s)",
ip_ntoa(&ip_port->ip, ip_str, sizeof(ip_str)), ip_port->port,
error, net_strerror);
LOGGER_ERROR(log, "failed to connect to %s:%d: %d (%s)", ip_str, ip_port->port, error, net_strerror);
net_kill_strerror(net_strerror);
return false;
}
Expand Down
4 changes: 4 additions & 0 deletions toxcore/tox.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,10 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error)
m_options.hole_punching_enabled = tox_options_get_hole_punching_enabled(opts);
m_options.local_discovery_enabled = tox_options_get_local_discovery_enabled(opts);

if (m_options.udp_disabled) {
m_options.local_discovery_enabled = false;
}

tox->log_callback = tox_options_get_log_callback(opts);
m_options.log_callback = tox_log_handler;
m_options.log_context = tox;
Expand Down

0 comments on commit 0bc00ca

Please sign in to comment.