Skip to content

Commit

Permalink
Merge 2377cac into cbda010
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Jul 12, 2018
2 parents cbda010 + 2377cac commit 364742e
Show file tree
Hide file tree
Showing 29 changed files with 739 additions and 619 deletions.
4 changes: 2 additions & 2 deletions .travis/cmake-linux
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ travis_script() {
# Coverage flags.
add_flag -fprofile-arcs -ftest-coverage

other/astyle/format-source . "$ASTYLE"

cmake -B_build -H. \
-DCMAKE_C_FLAGS="$C_FLAGS" \
-DCMAKE_CXX_FLAGS="$CXX_FLAGS" \
Expand All @@ -65,8 +67,6 @@ travis_script() {
make "-j$NPROC" test ARGS="-j50" || \
make "-j$NPROC" test ARGS="-j50 --rerun-failed" CTEST_OUTPUT_ON_FAILURE=1
cd - # popd

other/astyle/format-source . "$ASTYLE"
}

if [ "-z" "$ACTION" ]; then
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ if(BUILD_TOXAV)
toxav/groupav.h
toxav/msi.c
toxav/msi.h
toxav/pair.h
toxav/ring_buffer.c
toxav/ring_buffer.h
toxav/rtp.c
Expand Down
6 changes: 3 additions & 3 deletions auto_tests/file_transfer_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ static void file_transfer_test(void)
printf("after %u iterations: %.2fMiB done\n", (unsigned int)i + 1, (double)size_recv / 1024 / 1024);
}

c_sleep(MIN(tox1_interval, MIN(tox2_interval, tox3_interval)));
c_sleep(min_u32(tox1_interval, min_u32(tox2_interval, tox3_interval)));
}

ck_assert_msg(file_sending_done, "file sending did not complete after %u iterations: sendf_ok:%u file_recv:%u "
Expand Down Expand Up @@ -348,7 +348,7 @@ static void file_transfer_test(void)
uint32_t tox2_interval = tox_iteration_interval(tox2);
uint32_t tox3_interval = tox_iteration_interval(tox3);

c_sleep(MIN(tox1_interval, MIN(tox2_interval, tox3_interval)));
c_sleep(min_u32(tox1_interval, min_u32(tox2_interval, tox3_interval)));
}

printf("Starting file 0 transfer test.\n");
Expand Down Expand Up @@ -397,7 +397,7 @@ static void file_transfer_test(void)
uint32_t tox2_interval = tox_iteration_interval(tox2);
uint32_t tox3_interval = tox_iteration_interval(tox3);

c_sleep(MIN(tox1_interval, MIN(tox2_interval, tox3_interval)));
c_sleep(min_u32(tox1_interval, min_u32(tox2_interval, tox3_interval)));
}

printf("file_transfer_test succeeded, took %llu seconds\n", time(nullptr) - cur_time);
Expand Down
3 changes: 3 additions & 0 deletions auto_tests/monolith_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ void check_size(char const *type) {
* switch on the PRINT_SIZE above and copy the number into this function.
*/
int main(int argc, char *argv[]) {
static_assert(sizeof(uint64_t) >= sizeof(size_t),
"Assumption violated: size_t is more than 64 bits wide");

#if defined(__x86_64__) && defined(__LP64__)
// toxcore/DHT
CHECK_SIZE(Client_data, 496);
Expand Down
4 changes: 2 additions & 2 deletions auto_tests/network_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ START_TEST(test_ip_equal)
ip2.ip.v6.uint32[2] = net_htonl(0xFFFF);
ip2.ip.v6.uint32[3] = net_htonl(0x7F000001);

ck_assert_msg(IPV6_IPV4_IN_V6(ip2.ip.v6) != 0,
"IPV6_IPV4_IN_V6(::ffff:127.0.0.1): expected != 0, got 0.");
ck_assert_msg(ipv6_ipv4_in_v6(ip2.ip.v6) != 0,
"ipv6_ipv4_in_v6(::ffff:127.0.0.1): expected != 0, got 0.");

res = ip_equal(&ip1, &ip2);
ck_assert_msg(res != 0, "ip_equal( {TOX_AF_INET, 127.0.0.1}, {TOX_AF_INET6, ::ffff:127.0.0.1} ): "
Expand Down
7 changes: 7 additions & 0 deletions toxav/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ cc_test(
],
)

cc_library(
name = "pair",
hdrs = ["pair.h"],
)

cc_library(
name = "audio",
srcs = ["audio.c"],
hdrs = ["audio.h"],
deps = [
":pair",
":public",
":rtp",
"//c-toxcore/toxcore:network",
Expand All @@ -78,6 +84,7 @@ cc_library(
],
deps = [
":audio",
":pair",
":public",
"//c-toxcore/toxcore:network",
"@libvpx",
Expand Down
1 change: 1 addition & 0 deletions toxav/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ libtoxav_la_SOURCES = ../toxav/rtp.h \
../toxav/video.c \
../toxav/bwcontroller.h \
../toxav/bwcontroller.c \
../toxav/pair.h \
../toxav/ring_buffer.h \
../toxav/ring_buffer.c \
../toxav/toxav.h \
Expand Down
1 change: 1 addition & 0 deletions toxav/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "../toxcore/logger.h"
#include "../toxcore/util.h"
#include "pair.h"

#include <opus.h>
#include <pthread.h>
Expand Down
6 changes: 6 additions & 0 deletions toxav/pair.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef C_TOXCORE_TOXAV_PAIR_H
#define C_TOXCORE_TOXAV_PAIR_H

#define PAIR(TYPE1__, TYPE2__) struct { TYPE1__ first; TYPE2__ second; }

#endif // C_TOXCORE_TOXAV_PAIR_H
4 changes: 4 additions & 0 deletions toxav/toxav.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ void toxav_iterate(ToxAV *av)
ac_iterate(i->audio.second);
vc_iterate(i->video.second);

// TODO(iphydf): Find out what MIN-semantics are desired here and
// use a min_* function from util.h.
#define MIN(a,b) (((a)<(b))?(a):(b))

if (i->msi_call->self_capabilities & msi_CapRAudio &&
i->msi_call->peer_capabilities & msi_CapSAudio) {
rc = MIN(i->audio.second->lp_frame_duration, rc);
Expand Down
1 change: 1 addition & 0 deletions toxav/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "../toxcore/logger.h"
#include "../toxcore/util.h"
#include "pair.h"

#include <vpx/vpx_decoder.h>
#include <vpx/vpx_encoder.h>
Expand Down
4 changes: 2 additions & 2 deletions toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ uint32_t addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key)
uint32_t used = 0;

/* convert IPv4-in-IPv6 to IPv4 */
if (net_family_is_ipv6(ip_port.ip.family) && IPV6_IPV4_IN_V6(ip_port.ip.ip.v6)) {
if (net_family_is_ipv6(ip_port.ip.family) && ipv6_ipv4_in_v6(ip_port.ip.ip.v6)) {
ip_port.ip.family = net_family_ipv4;
ip_port.ip.ip.v4.uint32 = ip_port.ip.ip.v6.uint32[3];
}
Expand Down Expand Up @@ -1272,7 +1272,7 @@ static bool update_client_data(Client_data *array, size_t size, IP_Port ip_port,
static void returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const uint8_t *nodepublic_key)
{
/* convert IPv4-in-IPv6 to IPv4 */
if (net_family_is_ipv6(ip_port.ip.family) && IPV6_IPV4_IN_V6(ip_port.ip.ip.v6)) {
if (net_family_is_ipv6(ip_port.ip.family) && ipv6_ipv4_in_v6(ip_port.ip.ip.v6)) {
ip_port.ip.family = net_family_ipv4;
ip_port.ip.ip.v4.uint32 = ip_port.ip.ip.v6.uint32[3];
}
Expand Down
39 changes: 21 additions & 18 deletions toxcore/LAN_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@

/* TODO: multiple threads might concurrently try to set these, and it isn't clear that this couldn't lead to undesirable
* behaviour. Consider storing the data in per-instance variables instead. */
//!TOKSTYLE-
// No global mutable state in Tokstyle.
static int broadcast_count = -1;
static IP_Port broadcast_ip_ports[MAX_INTERFACES];
//!TOKSTYLE+

#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)

Expand Down Expand Up @@ -76,9 +79,9 @@ static void fetch_broadcast_info(uint16_t port)
int count = 0;
IP_Port ip_ports[MAX_INTERFACES];

int ret;
const int ret = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen);

if ((ret = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR) {
if (ret == NO_ERROR) {
IP_ADAPTER_INFO *pAdapter = pAdapterInfo;

while (pAdapter) {
Expand All @@ -93,7 +96,7 @@ static void fetch_broadcast_info(uint16_t port)
uint32_t broadcast_ip = gateway_ip + ~subnet_ip - 1;
ip_port->ip.ip.v4.uint32 = net_htonl(broadcast_ip);
ip_port->port = port;
count++;
++count;

if (count >= MAX_INTERFACES) {
break;
Expand All @@ -111,7 +114,7 @@ static void fetch_broadcast_info(uint16_t port)

broadcast_count = count;

for (uint32_t i = 0; i < count; i++) {
for (uint32_t i = 0; i < count; ++i) {
broadcast_ip_ports[i] = ip_ports[i];
}
}
Expand Down Expand Up @@ -149,11 +152,11 @@ static void fetch_broadcast_info(uint16_t port)
struct ifreq i_faces[MAX_INTERFACES];
memset(i_faces, 0, sizeof(struct ifreq) * MAX_INTERFACES);

struct ifconf ifconf;
ifconf.ifc_buf = (char *)i_faces;
ifconf.ifc_len = sizeof(i_faces);
struct ifconf ifc;
ifc.ifc_buf = (char *)i_faces;
ifc.ifc_len = sizeof(i_faces);

if (ioctl(sock.socket, SIOCGIFCONF, &ifconf) < 0) {
if (ioctl(sock.socket, SIOCGIFCONF, &ifc) < 0) {
kill_sock(sock);
return;
}
Expand All @@ -165,14 +168,14 @@ static void fetch_broadcast_info(uint16_t port)
int count = 0;
IP_Port ip_ports[MAX_INTERFACES];

/* ifconf.ifc_len is set by the ioctl() to the actual length used;
/* ifc.ifc_len is set by the ioctl() to the actual length used;
* on usage of the complete array the call should be repeated with
* a larger array, not done (640kB and 16 interfaces shall be
* enough, for everybody!)
*/
int n = ifconf.ifc_len / sizeof(struct ifreq);
int n = ifc.ifc_len / sizeof(struct ifreq);

for (int i = 0; i < n; i++) {
for (int i = 0; i < n; ++i) {
/* there are interfaces with are incapable of broadcast */
if (ioctl(sock.socket, SIOCGIFBRDADDR, &i_faces[i]) < 0) {
continue;
Expand All @@ -198,14 +201,14 @@ static void fetch_broadcast_info(uint16_t port)
}

ip_port->port = port;
count++;
++count;
}

kill_sock(sock);

broadcast_count = count;

for (uint32_t i = 0; i < count; i++) {
for (uint32_t i = 0; i < count; ++i) {
broadcast_ip_ports[i] = ip_ports[i];
}
}
Expand Down Expand Up @@ -235,7 +238,7 @@ static uint32_t send_broadcasts(Networking_Core *net, uint16_t port, const uint8
return 0;
}

for (int i = 0; i < broadcast_count; i++) {
for (int i = 0; i < broadcast_count; ++i) {
sendpacket(net, broadcast_ip_ports[i], data, length);
}

Expand All @@ -259,11 +262,11 @@ static IP broadcast_ip(Family family_socket, Family family_broadcast)
ip.ip.v6.uint8[15] = 0x01;
} else if (net_family_is_ipv4(family_broadcast)) {
ip.family = net_family_ipv6;
ip.ip.v6 = IP6_BROADCAST;
ip.ip.v6 = ip6_broadcast;
}
} else if (net_family_is_ipv4(family_socket) && net_family_is_ipv4(family_broadcast)) {
ip.family = net_family_ipv4;
ip.ip.v4 = IP4_BROADCAST;
ip.ip.v4 = ip4_broadcast;
}

return ip;
Expand All @@ -281,7 +284,7 @@ bool ip_is_local(IP ip)
}
} else {
/* embedded IPv4-in-IPv6 */
if (IPV6_IPV4_IN_V6(ip.ip.v6)) {
if (ipv6_ipv4_in_v6(ip.ip.v6)) {
IP ip4;
ip4.family = net_family_ipv4;
ip4.ip.v4.uint32 = ip.ip.v6.uint32[3];
Expand Down Expand Up @@ -345,7 +348,7 @@ int ip_is_lan(IP ip)
}

/* embedded IPv4-in-IPv6 */
if (IPV6_IPV4_IN_V6(ip.ip.v6)) {
if (ipv6_ipv4_in_v6(ip.ip.v6)) {
IP ip4;
ip4.family = net_family_ipv4;
ip4.ip.v4.uint32 = ip.ip.v6.uint32[3];
Expand Down
9 changes: 6 additions & 3 deletions toxcore/Messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,9 @@ int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf,
return -1;
}

int msglen = MIN(maxlen, m->friendlist[friendnumber].statusmessage_length);
// TODO(iphydf): This should be uint16_t and min_u16. If maxlen exceeds
// uint16_t's range, it won't affect the result.
uint32_t msglen = min_u32(maxlen, m->friendlist[friendnumber].statusmessage_length);

memcpy(buf, m->friendlist[friendnumber].statusmessage, msglen);
memset(buf + msglen, 0, maxlen - msglen);
Expand Down Expand Up @@ -2855,9 +2857,10 @@ static uint32_t friends_list_save(const Messenger *m, uint8_t *data)
memcpy(temp.real_pk, m->friendlist[i].real_pk, CRYPTO_PUBLIC_KEY_SIZE);

if (temp.status < 3) {
// TODO(iphydf): Use uint16_t and min_u16 here.
const size_t friendrequest_length =
MIN(m->friendlist[i].info_size,
MIN(SAVED_FRIEND_REQUEST_SIZE, MAX_FRIEND_REQUEST_DATA_SIZE));
min_u32(m->friendlist[i].info_size,
min_u32(SAVED_FRIEND_REQUEST_SIZE, MAX_FRIEND_REQUEST_DATA_SIZE));
memcpy(temp.info, m->friendlist[i].info, friendrequest_length);

temp.info_size = net_htons(m->friendlist[i].info_size);
Expand Down
Loading

0 comments on commit 364742e

Please sign in to comment.