From a2d5d8077907bf527f27e25fa6a832abb71ee9b1 Mon Sep 17 00:00:00 2001 From: Michael Thorpe Date: Tue, 6 Nov 2018 22:48:17 +0000 Subject: [PATCH] Enable warnings as errors test criteria: - Built from clean on macOS --- CMakeLists.txt | 8 ++++---- Makefile | 4 ++-- crypto/libsodium/init.c | 3 ++- docker/debian.Dockerfile | 2 +- libabyss/include/abyss/server.hpp | 2 +- libutp/utp_internal.cpp | 23 +++++++++++++---------- llarp/ev.cpp | 7 +++++-- llarp/ev_epoll.hpp | 4 ++-- llarp/handlers/tun.cpp | 4 ++-- llarp/link/utp.cpp | 2 +- llarp/router.cpp | 2 +- llarp/router.hpp | 2 +- test/jsonrpc_unittest.cpp | 3 ++- 13 files changed, 37 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 284b54767..2ebce6aed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,9 +4,9 @@ cmake_minimum_required(VERSION 3.7.0) set(PROJECT_NAME lokinet) project(${PROJECT_NAME} C CXX ASM) -option(USE_LIBABYSS "enable libabyss" OFF) -option(USE_CXX17 "enable c++17 features" OFF) -option(USE_AVX2 "enable avx2 code" OFF) +option(USE_LIBABYSS "enable libabyss" ) +option(USE_CXX17 "enable c++17 features" ) +option(USE_AVX2 "enable avx2 code" ) # Require C++11 # or C++17 on win32 if (NOT WIN32) @@ -25,7 +25,7 @@ set(CMAKE_CXX_EXTENSIONS OFF) # turns off those annoying warnings for # target-specific crypto code paths not # applicable to the host's FPU -rick -add_compile_options(-Wall) +add_compile_options(-Wall -Werror -Wno-unknown-pragmas) add_compile_options($<$:-fpermissive>) add_compile_options(-Wno-unused-function -Wno-deprecated-declarations -Wno-unknown-pragmas) diff --git a/Makefile b/Makefile index 5904419db..bdaee85ce 100644 --- a/Makefile +++ b/Makefile @@ -31,8 +31,8 @@ TESTNET_CLIENTS ?= 50 TESTNET_SERVERS ?= 50 TESTNET_DEBUG ?= 0 -JSONRPC = OFF -CXX17 = ON +JSONRPC ?= OFF +CXX17 ?= ON BUILD_ROOT = $(REPO)/build diff --git a/crypto/libsodium/init.c b/crypto/libsodium/init.c index 4aac46a85..61a7aacd4 100644 --- a/crypto/libsodium/init.c +++ b/crypto/libsodium/init.c @@ -21,7 +21,6 @@ #include static volatile int initialized; -static volatile int locked; int sodium_init(void) @@ -56,6 +55,7 @@ sodium_init(void) static CRITICAL_SECTION _sodium_lock; static volatile LONG _sodium_lock_initialized; +static volatile int locked; int _sodium_crit_init(void) @@ -113,6 +113,7 @@ sodium_crit_leave(void) #elif defined(HAVE_PTHREAD) && !defined(__EMSCRIPTEN__) static pthread_mutex_t _sodium_lock = PTHREAD_MUTEX_INITIALIZER; +static volatile int locked; int sodium_crit_enter(void) diff --git a/docker/debian.Dockerfile b/docker/debian.Dockerfile index 375fe86ff..4256323b7 100644 --- a/docker/debian.Dockerfile +++ b/docker/debian.Dockerfile @@ -7,4 +7,4 @@ WORKDIR /src/ COPY . /src/ -RUN make -j 8 JSONRPC=ON +RUN make -j 8 JSONRPC=ON CXX17=OFF diff --git a/libabyss/include/abyss/server.hpp b/libabyss/include/abyss/server.hpp index a70806dad..7658f38a1 100644 --- a/libabyss/include/abyss/server.hpp +++ b/libabyss/include/abyss/server.hpp @@ -29,7 +29,7 @@ namespace abyss HandleJSONRPC(Method_t method, const Params& params, Response& response) = 0; - ~IRPCHandler(); + virtual ~IRPCHandler(); bool ShouldClose(llarp_time_t now) const; diff --git a/libutp/utp_internal.cpp b/libutp/utp_internal.cpp index 7d6fdc1aa..05a9c9d44 100644 --- a/libutp/utp_internal.cpp +++ b/libutp/utp_internal.cpp @@ -154,10 +154,6 @@ enum { ST_NUM_STATES, // used for bounds checking }; -static const cstr flagnames[] = { - "ST_DATA","ST_FIN","ST_STATE","ST_RESET","ST_SYN" -}; - enum CONN_STATE { CS_UNINITIALIZED = 0, CS_IDLE, @@ -169,10 +165,17 @@ enum CONN_STATE { CS_DESTROY }; +#if UTP_DEBUG_LOGGING +static const cstr flagnames[] = { + "ST_DATA","ST_FIN","ST_STATE","ST_RESET","ST_SYN" +}; + static const cstr statenames[] = { "UNINITIALIZED", "IDLE","SYN_SENT", "SYN_RECV", "CONNECTED","CONNECTED_FULL","DESTROY_DELAY","RESET","DESTROY" }; +#endif + struct OutgoingPacket { size_t length; size_t payload; @@ -1178,7 +1181,7 @@ void UTPSocket::check_timeouts() // Increase RTO const uint new_timeout = ignore_loss ? retransmit_timeout : retransmit_timeout * 2; - // They initiated the connection but failed to respond before the rto. + // They initiated the connection but failed to respond before the rto. // A malicious client can also spoof the destination address of a ST_SYN bringing us to this state. // Kill the connection and do not notify the upper layer if (state == CS_SYN_RECV) { @@ -1797,7 +1800,7 @@ size_t utp_process_incoming(UTPSocket *conn, const byte *packet, size_t len, boo // or a malicious attempt to attach the uTP implementation. // acking a packet that hasn't been sent yet! // SYN packets have an exception, since there are no previous packets - if ((pk_flags != ST_SYN || conn->state != CS_SYN_RECV) && + if ((pk_flags != ST_SYN || conn->state != CS_SYN_RECV) && (wrapping_compare_less(conn->seq_nr - 1, pk_ack_nr, ACK_NR_MASK) || wrapping_compare_less(pk_ack_nr, conn->seq_nr - 1 - curr_window, ACK_NR_MASK))) { #if UTP_DEBUG_LOGGING @@ -1966,7 +1969,7 @@ size_t utp_process_incoming(UTPSocket *conn, const byte *packet, size_t len, boo if (pkt == 0 || pkt->transmissions == 0) continue; assert((int)(pkt->payload) >= 0); acked_bytes += pkt->payload; - if (conn->mtu_probe_seq && seq == conn->mtu_probe_seq) { + if (conn->mtu_probe_seq && seq == static_cast< int >(conn->mtu_probe_seq)) { conn->mtu_floor = conn->mtu_probe_size; conn->mtu_search_update(); conn->log(UTP_LOG_MTU, "MTU [ACK] floor:%d ceiling:%d current:%d" @@ -2163,7 +2166,7 @@ size_t utp_process_incoming(UTPSocket *conn, const byte *packet, size_t len, boo // Outgoing connection completion if (pk_flags == ST_STATE && conn->state == CS_SYN_SENT) { conn->state = CS_CONNECTED; - + // If the user has defined the ON_CONNECT callback, use that to // notify the user that the socket is now connected. If ON_CONNECT // has not been defined, notify the user via ON_STATE_CHANGE. @@ -2173,7 +2176,7 @@ size_t utp_process_incoming(UTPSocket *conn, const byte *packet, size_t len, boo utp_call_on_state_change(conn->ctx, conn, UTP_STATE_CONNECT); // We've sent a fin, and everything was ACKed (including the FIN). - // cur_window_packets == acks means that this packet acked all + // cur_window_packets == acks means that this packet acked all // the remaining packets that were in-flight. } else if (conn->fin_sent && conn->cur_window_packets == acks) { conn->fin_sent_acked = true; @@ -3075,7 +3078,7 @@ static UTPSocket* parse_icmp_payload(utp_context *ctx, const byte *buffer, size_ // @len: buffer length // @to: destination address of the original UDP pakcet // @tolen: address length -// @next_hop_mtu: +// @next_hop_mtu: int utp_process_icmp_fragmentation(utp_context *ctx, const byte* buffer, size_t len, const struct sockaddr *to, socklen_t tolen, uint16 next_hop_mtu) { UTPSocket* conn = parse_icmp_payload(ctx, buffer, len, to, tolen); diff --git a/llarp/ev.cpp b/llarp/ev.cpp index 865719282..213e44580 100644 --- a/llarp/ev.cpp +++ b/llarp/ev.cpp @@ -1,6 +1,9 @@ #include #include #include + +#include + #include "mem.hpp" #define EV_TICK_INTERVAL 100 @@ -166,7 +169,7 @@ llarp_tcp_async_try_connect(struct llarp_ev_loop *loop, return; } const char *end = ptr; - while(*end && (end - begin) < sizeof(tcp->remote)) + while(*end && ((end - begin) < static_cast(sizeof tcp->remote))) { ++end; } @@ -242,4 +245,4 @@ namespace llarp return true; } -} // namespace llarp \ No newline at end of file +} // namespace llarp diff --git a/llarp/ev_epoll.hpp b/llarp/ev_epoll.hpp index 034fa208e..a56c383c9 100644 --- a/llarp/ev_epoll.hpp +++ b/llarp/ev_epoll.hpp @@ -135,9 +135,9 @@ namespace llarp socklen_t slen = sizeof(sockaddr_in6); sockaddr* addr = (sockaddr*)&src; ssize_t ret = ::recvfrom(fd, buf, sz, 0, addr, &slen); - if(ret == -1) + if(ret < 0) return -1; - if(ret > sz) + if(static_cast< size_t >(ret) > sz) return -1; udp->recvfrom(udp, addr, buf, ret); return 0; diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index 7750f289a..9b81ec06f 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -467,7 +467,7 @@ namespace llarp { // called in the isolated network thread TunEndpoint *self = static_cast< TunEndpoint * >(tun->user); - self->m_NetworkToUserPktQueue.Process([self, tun](net::IPv4Packet &pkt) { + self->m_NetworkToUserPktQueue.Process([tun](net::IPv4Packet &pkt) { if(!llarp_ev_tun_async_write(tun, pkt.buf, pkt.sz)) llarp::LogWarn("packet dropped"); }); @@ -489,7 +489,7 @@ namespace llarp TunEndpoint *self = static_cast< TunEndpoint * >(tun->user); llarp::LogDebug("got pkt ", sz, " bytes"); if(!self->m_UserToNetworkPktQueue.EmplaceIf( - [self, buf, sz](net::IPv4Packet &pkt) -> bool { + [buf, sz](net::IPv4Packet &pkt) -> bool { return pkt.Load(llarp::InitBuffer(buf, sz)) && pkt.Header()->version == 4; })) diff --git a/llarp/link/utp.cpp b/llarp/link/utp.cpp index 18f07d159..d4a6e54bb 100644 --- a/llarp/link/utp.cpp +++ b/llarp/link/utp.cpp @@ -125,7 +125,7 @@ namespace llarp llarp::LogDebug("utp_writev wrote=", s, " expect=", expect, " to=", remoteAddr); - while(s > vecq.front().iov_len) + while(s > static_cast< ssize_t >(vecq.front().iov_len)) { s -= vecq.front().iov_len; vecq.pop_front(); diff --git a/llarp/router.cpp b/llarp/router.cpp index 7a2f5ab9d..09d7f9733 100644 --- a/llarp/router.cpp +++ b/llarp/router.cpp @@ -494,7 +494,7 @@ llarp_router::Tick() if(inboundLinks.size() == 0) { - auto N = llarp_nodedb_num_loaded(nodedb); + size_t N = llarp_nodedb_num_loaded(nodedb); if(N < minRequiredRouters) { llarp::LogInfo("We need at least ", minRequiredRouters, diff --git a/llarp/router.hpp b/llarp/router.hpp index 2688bb90f..b12eb210c 100644 --- a/llarp/router.hpp +++ b/llarp/router.hpp @@ -82,7 +82,7 @@ struct llarp_router /// hard upperbound limit on the number of router to router connections size_t maxConnectedRouters = 2000; - int minRequiredRouters = 4; + size_t minRequiredRouters = 4; // should we be sending padded messages every interval? bool sendPadding = false; diff --git a/test/jsonrpc_unittest.cpp b/test/jsonrpc_unittest.cpp index 90fe6ce06..c852f69e0 100644 --- a/test/jsonrpc_unittest.cpp +++ b/test/jsonrpc_unittest.cpp @@ -184,7 +184,8 @@ TEST_F(AbyssTest, TestClientAndServer) params.SetObject(); QueueRPC(method, std::move(params), std::bind(&AbyssTest::NewConn, this, std::placeholders::_1)); + AsyncFlush(); RunLoop(); ASSERT_TRUE(called); -}; \ No newline at end of file +};