From f9e9227e19b6511d4a31d7b2c5608fd11b0e24ef Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 2 Aug 2019 10:27:27 +0100 Subject: [PATCH] Fix gcc trunk warnings --- CMakeLists.txt | 3 ++ libabyss/src/client.cpp | 2 +- libutp/utp_internal.h | 5 ++- llarp/dht/key.hpp | 6 ++-- llarp/dht/localrouterlookup.cpp | 4 +-- llarp/dht/localtaglookup.cpp | 4 +-- llarp/dht/recursiverouterlookup.cpp | 6 ++-- llarp/ev/ev.hpp | 12 +++---- llarp/ev/ev_libuv.cpp | 10 ++++-- llarp/exit/session.cpp | 26 +++++++------- llarp/handlers/tun.cpp | 6 ++-- llarp/net/net_addr.cpp | 6 ---- llarp/net/net_addr.hpp | 2 -- llarp/path/pathbuilder.cpp | 32 ++++++++--------- llarp/path/pathbuilder.hpp | 2 +- llarp/router/outbound_session_maker.cpp | 4 +-- llarp/routing/dht_message.cpp | 6 ++-- llarp/service/async_key_exchange.cpp | 6 ++-- llarp/service/async_key_exchange.hpp | 2 +- llarp/service/endpoint.cpp | 6 ++-- llarp/service/endpoint_state.cpp | 4 +-- llarp/service/info.hpp | 12 ------- llarp/service/lookup.cpp | 2 +- llarp/service/lookup.hpp | 2 +- llarp/service/protocol.cpp | 10 +++--- llarp/service/tag_lookup_job.cpp | 4 +-- llarp/service/tag_lookup_job.hpp | 4 +-- llarp/util/aligned.hpp | 12 +++---- llarp/util/metrics_types.hpp | 6 ++-- test/dht/test_llarp_dht_tx.cpp | 4 +-- test/util/test_llarp_util_object.cpp | 38 +++++++++++---------- test/util/test_llarp_util_timerqueue.cpp | 36 +++++++++---------- vendor/libtuntap-master/tuntap-unix-linux.c | 8 ++--- vendor/libtuntap-master/tuntap-unix.c | 4 +-- 34 files changed, 142 insertions(+), 154 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3df472c18..428b39950 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,9 @@ endif(WIN32) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_C_STANDARD 99) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS OFF) if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND SHADOW) message( FATAL_ERROR "shadow-framework is Linux only" ) diff --git a/libabyss/src/client.cpp b/libabyss/src/client.cpp index 4c1e7e788..7352e5dca 100644 --- a/libabyss/src/client.cpp +++ b/libabyss/src/client.cpp @@ -416,7 +416,7 @@ namespace abyss bool JSONRPC::RunAsync(llarp_ev_loop_ptr loop, const std::string& remote) { - strncpy(m_connect.remote, remote.c_str(), sizeof(m_connect.remote)); + strncpy(m_connect.remote, remote.c_str(), sizeof(m_connect.remote) - 1); // TODO: ipv6 m_connect.connected = &JSONRPC::OnConnected; m_connect.error = &JSONRPC::OnConnectFail; diff --git a/libutp/utp_internal.h b/libutp/utp_internal.h index 61ad9b490..01597f811 100644 --- a/libutp/utp_internal.h +++ b/libutp/utp_internal.h @@ -83,10 +83,9 @@ struct UTPSocketKey uint32 recv_id; // "conn_seed", "conn_id" UTPSocketKey(const PackedSockAddr &_addr, uint32 _recv_id) + : addr(_addr) + , recv_id(_recv_id) { - memset(this, 0, sizeof(*this)); - addr = _addr; - recv_id = _recv_id; } bool diff --git a/llarp/dht/key.hpp b/llarp/dht/key.hpp index 075373a57..869a39c7b 100644 --- a/llarp/dht/key.hpp +++ b/llarp/dht/key.hpp @@ -16,12 +16,12 @@ namespace llarp { } - explicit Key_t(const Data& val) : AlignedBuffer< SIZE >(val) + explicit Key_t(const Data& data) : AlignedBuffer< SIZE >(data) { } - explicit Key_t(const AlignedBuffer< SIZE >& val) - : AlignedBuffer< SIZE >(val) + explicit Key_t(const AlignedBuffer< SIZE >& data) + : AlignedBuffer< SIZE >(data) { } diff --git a/llarp/dht/localrouterlookup.cpp b/llarp/dht/localrouterlookup.cpp index d7df15d09..717834d33 100644 --- a/llarp/dht/localrouterlookup.cpp +++ b/llarp/dht/localrouterlookup.cpp @@ -13,9 +13,9 @@ namespace llarp namespace dht { LocalRouterLookup::LocalRouterLookup(const PathID_t &path, uint64_t txid, - const RouterID &target, + const RouterID &_target, AbstractContext *ctx) - : RecursiveRouterLookup(TXOwner{ctx->OurKey(), txid}, target, ctx, + : RecursiveRouterLookup(TXOwner{ctx->OurKey(), txid}, _target, ctx, nullptr) , localPath(path) { diff --git a/llarp/dht/localtaglookup.cpp b/llarp/dht/localtaglookup.cpp index 85ecef839..ec223d24c 100644 --- a/llarp/dht/localtaglookup.cpp +++ b/llarp/dht/localtaglookup.cpp @@ -11,9 +11,9 @@ namespace llarp namespace dht { LocalTagLookup::LocalTagLookup(const PathID_t &path, uint64_t txid, - const service::Tag &target, + const service::Tag &_target, AbstractContext *ctx) - : TagLookup(TXOwner{ctx->OurKey(), txid}, target, ctx, 0) + : TagLookup(TXOwner{ctx->OurKey(), txid}, _target, ctx, 0) , localPath(path) { } diff --git a/llarp/dht/recursiverouterlookup.cpp b/llarp/dht/recursiverouterlookup.cpp index 46407869a..11468d659 100644 --- a/llarp/dht/recursiverouterlookup.cpp +++ b/llarp/dht/recursiverouterlookup.cpp @@ -8,11 +8,11 @@ namespace llarp { namespace dht { - RecursiveRouterLookup::RecursiveRouterLookup(const TXOwner &whoasked, - const RouterID &target, + RecursiveRouterLookup::RecursiveRouterLookup(const TXOwner &_whoasked, + const RouterID &_target, AbstractContext *ctx, RouterLookupHandler result) - : TX< RouterID, RouterContact >(whoasked, target, ctx) + : TX< RouterID, RouterContact >(_whoasked, _target, ctx) , resultHandler(result) { diff --git a/llarp/ev/ev.hpp b/llarp/ev/ev.hpp index a6492c610..e53e125b3 100644 --- a/llarp/ev/ev.hpp +++ b/llarp/ev/ev.hpp @@ -538,8 +538,8 @@ namespace llarp } /// inbound - tcp_conn(llarp_ev_loop* loop, int fd) - : ev_io(fd, new LosslessWriteQueue_t{}), _conn(nullptr) + tcp_conn(llarp_ev_loop* loop, int _fd) + : ev_io(_fd, new LosslessWriteQueue_t{}), _conn(nullptr) { tcp.impl = this; tcp.loop = loop; @@ -551,9 +551,9 @@ namespace llarp } /// outbound - tcp_conn(llarp_ev_loop* loop, int fd, const sockaddr* addr, + tcp_conn(llarp_ev_loop* loop, int _fd, const sockaddr* addr, llarp_tcp_connecter* conn) - : ev_io(fd, new LosslessWriteQueue_t{}), _conn(conn) + : ev_io(_fd, new LosslessWriteQueue_t{}), _conn(conn) { socklen_t slen = sizeof(sockaddr_in); if(addr->sa_family == AF_INET6) @@ -645,8 +645,8 @@ namespace llarp { llarp_ev_loop* loop; llarp_tcp_acceptor* tcp; - tcp_serv(llarp_ev_loop* l, int fd, llarp_tcp_acceptor* t) - : ev_io(fd), loop(l), tcp(t) + tcp_serv(llarp_ev_loop* l, int _fd, llarp_tcp_acceptor* t) + : ev_io(_fd), loop(l), tcp(t) { tcp->impl = this; } diff --git a/llarp/ev/ev_libuv.cpp b/llarp/ev/ev_libuv.cpp index 9a97a8cdf..14ea90e78 100644 --- a/llarp/ev/ev_libuv.cpp +++ b/llarp/ev/ev_libuv.cpp @@ -1,5 +1,7 @@ -#include "ev_libuv.hpp" -#include "net/net_addr.hpp" +#include +#include + +#include namespace libuv { @@ -517,7 +519,9 @@ namespace libuv bool Init(uv_loop_t* loop) { - strncpy(m_Device->if_name, m_Tun->ifname, sizeof(m_Device->if_name)); + std::copy(std::begin(m_Tun->ifname), std::end(m_Tun->ifname), + m_Device->if_name); + memcpy(m_Device->if_name, m_Tun->ifname, sizeof(m_Device->if_name)); if(tuntap_start(m_Device, TUNTAP_MODE_TUNNEL, 0) == -1) { llarp::LogError("failed to start up ", m_Tun->ifname); diff --git a/llarp/exit/session.cpp b/llarp/exit/session.cpp index 1ef714e0e..9ae0b5d01 100644 --- a/llarp/exit/session.cpp +++ b/llarp/exit/session.cpp @@ -12,11 +12,11 @@ namespace llarp namespace exit { BaseSession::BaseSession( - const llarp::RouterID& router, + const llarp::RouterID& routerId, std::function< bool(const llarp_buffer_t&) > writepkt, AbstractRouter* r, size_t numpaths, size_t hoplen, bool bundleRC) : llarp::path::Builder(r, numpaths, hoplen) - , m_ExitRouter(router) + , m_ExitRouter(routerId) , m_WritePacket(writepkt) , m_Counter(0) , m_LastUse(0) @@ -82,7 +82,7 @@ namespace llarp { if(db->Get(m_ExitRouter, cur)) return true; - router->LookupRouter(m_ExitRouter, nullptr); + m_router->LookupRouter(m_ExitRouter, nullptr); return false; } @@ -113,7 +113,7 @@ namespace llarp llarp::LogError("Failed to sign exit request"); return; } - if(p->SendExitRequest(obtain, router)) + if(p->SendExitRequest(obtain, m_router)) llarp::LogInfo("asking ", m_ExitRouter, " for exit"); else llarp::LogError("failed to send exit request"); @@ -128,7 +128,7 @@ namespace llarp bool BaseSession::HandleGotExit(llarp::path::Path_ptr p, llarp_time_t b) { - m_LastUse = router->Now(); + m_LastUse = m_router->Now(); if(b == 0) { llarp::LogInfo("obtained an exit via ", p->Endpoint()); @@ -164,7 +164,7 @@ namespace llarp { llarp::LogInfo(p->Name(), " closing exit path"); routing::CloseExitMessage msg; - if(msg.Sign(m_ExitIdentity) && p->SendExitClose(msg, router)) + if(msg.Sign(m_ExitIdentity) && p->SendExitClose(msg, m_router)) { p->ClearRoles(roles); } @@ -185,12 +185,12 @@ namespace llarp { LogInfo(p->Name(), " closing exit path"); routing::CloseExitMessage msg; - if(!(msg.Sign(m_ExitIdentity) && p->SendExitClose(msg, router))) + if(!(msg.Sign(m_ExitIdentity) && p->SendExitClose(msg, m_router))) LogWarn(p->Name(), " failed to send exit close message"); } }; ForEachPath(sendExitClose); - router->pathContext().RemovePathSet(shared_from_this()); + m_router->pathContext().RemovePathSet(shared_from_this()); return path::Builder::Stop(); } @@ -204,7 +204,7 @@ namespace llarp if(!pkt.Load(buf)) return false; m_Downstream.emplace(counter, pkt); - m_LastUse = router->Now(); + m_LastUse = m_router->Now(); return true; } @@ -217,7 +217,7 @@ namespace llarp { llarp::LogError("dropped traffic on exit ", m_ExitRouter, " S=", s, " P=", path); - p->EnterState(path::ePathIgnore, router->Now()); + p->EnterState(path::ePathIgnore, m_router->Now()); return true; } @@ -269,7 +269,7 @@ namespace llarp bool BaseSession::FlushUpstream() { - auto now = router->Now(); + auto now = m_router->Now(); auto path = PickRandomEstablishedPath(llarp::path::ePathRoleExit); if(path) { @@ -282,7 +282,7 @@ namespace llarp if(path) { msg.S = path->NextSeqNo(); - if(path->SendRoutingMessage(msg, router)) + if(path->SendRoutingMessage(msg, m_router)) m_LastUse = now; } queue.pop_front(); @@ -302,7 +302,7 @@ namespace llarp m_Upstream.clear(); if(numHops == 1) { - auto r = router; + auto r = m_router; RouterContact rc; if(r->nodedb()->Get(m_ExitRouter, rc)) r->TryConnectAsync(rc, 5); diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index b575289d8..d796fd033 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -125,7 +125,7 @@ namespace llarp } RouterContact rc; - if(!router->nodedb()->Get(connect, rc)) + if(!m_router->nodedb()->Get(connect, rc)) { LogError(Name(), " we don't have the RC for ", v, " so we can't use it in strict-connect"); @@ -152,8 +152,8 @@ namespace llarp } m_Exit = std::make_shared< llarp::exit::ExitSession >( exitRouter, - util::memFn(&TunEndpoint::QueueInboundPacketForExit, this), router, - numPaths, numHops, ShouldBundleRC()); + util::memFn(&TunEndpoint::QueueInboundPacketForExit, this), + m_router, numPaths, numHops, ShouldBundleRC()); llarp::LogInfo(Name(), " using exit at ", exitRouter); } if(k == "local-dns") diff --git a/llarp/net/net_addr.cpp b/llarp/net/net_addr.cpp index b90604482..de2387e51 100644 --- a/llarp/net/net_addr.cpp +++ b/llarp/net/net_addr.cpp @@ -23,12 +23,6 @@ namespace llarp { } - Addr::Addr(const Addr& other) - { - memcpy(&_addr, &other._addr, sizeof(sockaddr_in6)); - memcpy(&_addr4, &other._addr4, sizeof(sockaddr_in)); - } - void Addr::port(uint16_t port) { diff --git a/llarp/net/net_addr.hpp b/llarp/net/net_addr.hpp index 8ee0691d0..75e137b87 100644 --- a/llarp/net/net_addr.hpp +++ b/llarp/net/net_addr.hpp @@ -21,8 +21,6 @@ namespace llarp Addr(); - Addr(const Addr& other); - Addr(string_view str); Addr(string_view str, const uint16_t p_port); diff --git a/llarp/path/pathbuilder.cpp b/llarp/path/pathbuilder.cpp index e0d1b4b11..63669d4f0 100644 --- a/llarp/path/pathbuilder.cpp +++ b/llarp/path/pathbuilder.cpp @@ -150,7 +150,7 @@ namespace llarp namespace path { Builder::Builder(AbstractRouter* p_router, size_t pathNum, size_t hops) - : path::PathSet(pathNum), _run(true), router(p_router), numHops(hops) + : path::PathSet(pathNum), _run(true), m_router(p_router), numHops(hops) { CryptoManager::instance()->encryption_keygen(enckey); } @@ -168,7 +168,7 @@ namespace llarp ExpirePaths(now); if(ShouldBuildMore(now)) BuildOne(); - TickPaths(now, router); + TickPaths(now, m_router); if(m_BuildStats.attempts > 50) { if(m_BuildStats.SuccsessRatio() <= BuildStats::MinGoodRatio @@ -204,14 +204,14 @@ namespace llarp size_t tries = 10; if(hop == 0) { - if(router->NumberOfConnectedRouters() == 0) + if(m_router->NumberOfConnectedRouters() == 0) { // persist connection - router->ConnectToRandomRouters(1); + m_router->ConnectToRandomRouters(1); return false; } bool got = false; - router->ForEachPeer( + m_router->ForEachPeer( [&](const ILinkSession* s, bool isOutbound) { if(s && s->IsEstablished() && isOutbound && !got) { @@ -234,7 +234,7 @@ namespace llarp if(db->select_random_hop_excluding(cur, excluding)) { excluding.insert(cur.pubkey); - if(!router->routerProfiling().IsBadForPath(cur.pubkey)) + if(!m_router->routerProfiling().IsBadForPath(cur.pubkey)) return true; } } while(tries > 0); @@ -285,7 +285,7 @@ namespace llarp Builder::BuildOne(PathRole roles) { std::vector< RouterContact > hops(numHops); - if(SelectHops(router->nodedb(), hops, roles)) + if(SelectHops(m_router->nodedb(), hops, roles)) Build(hops, roles); } @@ -299,7 +299,7 @@ namespace llarp std::vector< RouterContact >& hops) { const auto aligned = - router->pathContext().FindOwnedPathsWithEndpoint(remote); + m_router->pathContext().FindOwnedPathsWithEndpoint(remote); /// pick the lowest latency path that aligns to remote /// note: peer exhaustion is made worse happen here Path_ptr p; @@ -332,7 +332,7 @@ namespace llarp std::set< RouterID > routers{remote}; hops.resize(numHops); - auto nodedb = router->nodedb(); + auto nodedb = m_router->nodedb(); for(size_t idx = 0; idx < hops.size(); idx++) { hops[idx].Clear(); @@ -341,7 +341,7 @@ namespace llarp // last hop if(!nodedb->Get(remote, hops[idx])) { - router->LookupRouter(remote, nullptr); + m_router->LookupRouter(remote, nullptr); return false; } } @@ -365,7 +365,7 @@ namespace llarp { std::vector< RouterContact > hops; /// if we really need this path build it "dangerously" - if(UrgentBuild(router->Now())) + if(UrgentBuild(m_router->Now())) { if(!DoUrgentBuildAlignedTo(remote, hops)) { @@ -411,7 +411,7 @@ namespace llarp llarp_time_t Builder::Now() const { - return router->Now(); + return m_router->Now(); } void @@ -422,13 +422,13 @@ namespace llarp lastBuild = Now(); // async generate keys auto ctx = std::make_shared< AsyncPathKeyExchangeContext >(); - ctx->router = router; + ctx->router = m_router; ctx->pathset = GetSelf(); auto path = std::make_shared< path::Path >(hops, this, roles); LogInfo(Name(), " build ", path->HopsString()); path->SetBuildResultHook( [this](Path_ptr p) { this->HandlePathBuilt(p); }); - ctx->AsyncGenerateKeys(path, router->logic(), router->threadpool(), + ctx->AsyncGenerateKeys(path, m_router->logic(), m_router->threadpool(), &PathBuilderKeysGenerated); } @@ -436,7 +436,7 @@ namespace llarp Builder::HandlePathBuilt(Path_ptr p) { buildIntervalLimit = MIN_PATH_BUILD_INTERVAL; - router->routerProfiling().MarkPathSuccess(p.get()); + m_router->routerProfiling().MarkPathSuccess(p.get()); LogInfo(p->Name(), " built latency=", p->intro.latency); m_BuildStats.success++; } @@ -462,7 +462,7 @@ namespace llarp void Builder::HandlePathBuildTimeout(Path_ptr p) { - router->routerProfiling().MarkPathFail(p.get()); + m_router->routerProfiling().MarkPathFail(p.get()); PathSet::HandlePathBuildTimeout(p); DoPathBuildBackoff(); } diff --git a/llarp/path/pathbuilder.hpp b/llarp/path/pathbuilder.hpp index 9d17ea561..fe49954f5 100644 --- a/llarp/path/pathbuilder.hpp +++ b/llarp/path/pathbuilder.hpp @@ -39,7 +39,7 @@ namespace llarp std::vector< RouterContact >& hops); public: - AbstractRouter* router; + AbstractRouter* m_router; SecretKey enckey; size_t numHops; llarp_time_t lastBuild = 0; diff --git a/llarp/router/outbound_session_maker.cpp b/llarp/router/outbound_session_maker.cpp index 0fc3b7171..5a52a0aba 100644 --- a/llarp/router/outbound_session_maker.cpp +++ b/llarp/router/outbound_session_maker.cpp @@ -22,8 +22,8 @@ namespace llarp size_t attemptCount = 0; - PendingSession(const RouterContact &rc, LinkLayer_ptr link) - : rc(rc), link(link) + PendingSession(const RouterContact &_rc, LinkLayer_ptr _link) + : rc(_rc), link(_link) { } }; diff --git a/llarp/routing/dht_message.cpp b/llarp/routing/dht_message.cpp index 2d9a65acb..c02709dc0 100644 --- a/llarp/routing/dht_message.cpp +++ b/llarp/routing/dht_message.cpp @@ -10,11 +10,11 @@ namespace llarp bool DHTMessage::DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) { - llarp::dht::Key_t from; - from.Zero(); + llarp::dht::Key_t fromKey; + fromKey.Zero(); if(key == "M") { - return llarp::dht::DecodeMesssageList(from, val, M, true); + return llarp::dht::DecodeMesssageList(fromKey, val, M, true); } if(key == "S") { diff --git a/llarp/service/async_key_exchange.cpp b/llarp/service/async_key_exchange.cpp index b06b1172b..a788e24e3 100644 --- a/llarp/service/async_key_exchange.cpp +++ b/llarp/service/async_key_exchange.cpp @@ -17,7 +17,7 @@ namespace llarp IDataHandler* h, const ConvoTag& t, ProtocolType proto) : logic(l) - , remote(r) + , m_remote(r) , m_LocalIdentity(localident) , introPubKey(introsetPubKey) , remoteIntro(remote) @@ -32,7 +32,7 @@ namespace llarp { AsyncKeyExchange* self = static_cast< AsyncKeyExchange* >(user); // put values - self->handler->PutSenderFor(self->msg.tag, self->remote, false); + self->handler->PutSenderFor(self->msg.tag, self->m_remote, false); self->handler->PutCachedSessionKeyFor(self->msg.tag, self->sharedKey); self->handler->PutIntroFor(self->msg.tag, self->remoteIntro); self->handler->PutReplyIntroFor(self->msg.tag, self->msg.introReply); @@ -55,7 +55,7 @@ namespace llarp SharedSecret sharedSecret; path_dh_func dh_client = util::memFn(&Crypto::dh_client, crypto); if(!self->m_LocalIdentity.KeyExchange(dh_client, sharedSecret, - self->remote, self->frame.N)) + self->m_remote, self->frame.N)) { LogError("failed to derive x25519 shared key component"); } diff --git a/llarp/service/async_key_exchange.hpp b/llarp/service/async_key_exchange.hpp index 77d3d3e49..a555632f4 100644 --- a/llarp/service/async_key_exchange.hpp +++ b/llarp/service/async_key_exchange.hpp @@ -15,7 +15,7 @@ namespace llarp { std::shared_ptr< Logic > logic; SharedSecret sharedKey; - ServiceInfo remote; + ServiceInfo m_remote; const Identity& m_LocalIdentity; ProtocolMessage msg; ProtocolFrame frame; diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index e42519e0d..f00fb9e9d 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -191,8 +191,8 @@ namespace llarp { if(!EnsurePathToService( addr, - [](ABSL_ATTRIBUTE_UNUSED Address addr, - ABSL_ATTRIBUTE_UNUSED OutboundContext* ctx) {}, + [](ABSL_ATTRIBUTE_UNUSED Address _addr, + ABSL_ATTRIBUTE_UNUSED OutboundContext* _ctx) {}, 10000)) { LogWarn("failed to ensure path to ", addr); @@ -893,7 +893,7 @@ namespace llarp Endpoint::OnLookup(const Address& addr, const IntroSet* introset, const RouterID& endpoint) { - const auto now = router->Now(); + const auto now = Router()->Now(); auto& fails = m_state->m_ServiceLookupFails; auto& lookups = m_state->m_PendingServiceLookups; if(introset == nullptr || introset->IsExpired(now)) diff --git a/llarp/service/endpoint_state.cpp b/llarp/service/endpoint_state.cpp index 63b52aedf..0e0e31c00 100644 --- a/llarp/service/endpoint_state.cpp +++ b/llarp/service/endpoint_state.cpp @@ -43,7 +43,7 @@ namespace llarp if(k == "paths") { const auto val = atoi(v.c_str()); - if(val >= 1 && val <= static_cast(path::PathSet::max_paths)) + if(val >= 1 && val <= static_cast< int >(path::PathSet::max_paths)) { ep.numPaths = val; LogInfo(name, " set number of paths to ", ep.numHops); @@ -56,7 +56,7 @@ namespace llarp if(k == "hops") { const auto val = atoi(v.c_str()); - if(val >= 1 && val <= static_cast(path::max_len)) + if(val >= 1 && val <= static_cast< int >(path::max_len)) { ep.numHops = val; LogInfo(name, " set number of hops to ", ep.numHops); diff --git a/llarp/service/info.hpp b/llarp/service/info.hpp index 2effc74fa..a22da5257 100644 --- a/llarp/service/info.hpp +++ b/llarp/service/info.hpp @@ -66,18 +66,6 @@ namespace llarp return !(*this == other); } - ServiceInfo& - operator=(const ServiceInfo& other) - { - enckey = other.enckey; - signkey = other.signkey; - version = other.version; - vanity = other.vanity; - version = other.version; - UpdateAddr(); - return *this; - } - bool operator<(const ServiceInfo& other) const { diff --git a/llarp/service/lookup.cpp b/llarp/service/lookup.cpp index 16b45b971..51f9cfbbf 100644 --- a/llarp/service/lookup.cpp +++ b/llarp/service/lookup.cpp @@ -13,7 +13,7 @@ namespace llarp { IServiceLookup::IServiceLookup(ILookupHolder *p, uint64_t tx, const std::string &n) - : parent(p), txid(tx), name(n) + : m_parent(p), txid(tx), name(n) { m_created = time_now_ms(); p->PutLookup(this, tx); diff --git a/llarp/service/lookup.hpp b/llarp/service/lookup.hpp index b54438def..25c2dba68 100644 --- a/llarp/service/lookup.hpp +++ b/llarp/service/lookup.hpp @@ -53,7 +53,7 @@ namespace llarp bool SendRequestViaPath(path::Path_ptr p, AbstractRouter* r); - ILookupHolder* parent; + ILookupHolder* m_parent; uint64_t txid; const std::string name; RouterID endpoint; diff --git a/llarp/service/protocol.cpp b/llarp/service/protocol.cpp index d45fdcccd..c3d0b245e 100644 --- a/llarp/service/protocol.cpp +++ b/llarp/service/protocol.cpp @@ -405,10 +405,10 @@ namespace llarp LogError("failed to decrypt message"); return false; } - msg->handler = handler; - const PathID_t from = F; + msg->handler = handler; + const PathID_t fromPath = F; logic->queue_func( - [=]() { ProtocolMessage::ProcessAsync(recvPath, from, msg); }); + [=]() { ProtocolMessage::ProcessAsync(recvPath, fromPath, msg); }); return true; } @@ -420,7 +420,7 @@ namespace llarp } bool - ProtocolFrame::Verify(const ServiceInfo& from) const + ProtocolFrame::Verify(const ServiceInfo& svc) const { ProtocolFrame copy(*this); // save signature @@ -439,7 +439,7 @@ namespace llarp buf.sz = buf.cur - buf.base; buf.cur = buf.base; // verify - return from.Verify(buf, Z); + return svc.Verify(buf, Z); } bool diff --git a/llarp/service/tag_lookup_job.cpp b/llarp/service/tag_lookup_job.cpp index 65868ac52..7187ec680 100644 --- a/llarp/service/tag_lookup_job.cpp +++ b/llarp/service/tag_lookup_job.cpp @@ -11,7 +11,7 @@ namespace llarp bool CachedTagResult::HandleResponse(const std::set< IntroSet >& introsets) { - auto now = parent->Now(); + auto now = m_parent->Now(); for(const auto& introset : introsets) if(result.insert(introset).second) @@ -47,7 +47,7 @@ namespace llarp { auto msg = std::make_shared< routing::DHTMessage >(); msg->M.emplace_back(std::make_unique< dht::FindIntroMessage >(tag, txid)); - lastRequest = parent->Now(); + lastRequest = m_parent->Now(); return msg; } diff --git a/llarp/service/tag_lookup_job.hpp b/llarp/service/tag_lookup_job.hpp index fcc8a700a..f061df504 100644 --- a/llarp/service/tag_lookup_job.hpp +++ b/llarp/service/tag_lookup_job.hpp @@ -22,9 +22,9 @@ namespace llarp llarp_time_t lastModified = 0; std::set< IntroSet > result; Tag tag; - Endpoint* parent; + Endpoint* m_parent; - CachedTagResult(const Tag& t, Endpoint* p) : tag(t), parent(p) + CachedTagResult(const Tag& t, Endpoint* p) : tag(t), m_parent(p) { } diff --git a/llarp/util/aligned.hpp b/llarp/util/aligned.hpp index da23cfe5b..fafd99a95 100644 --- a/llarp/util/aligned.hpp +++ b/llarp/util/aligned.hpp @@ -33,13 +33,13 @@ namespace llarp AlignedBuffer() { - new(&val) Data; + new(&m_val) Data; Zero(); } explicit AlignedBuffer(const byte_t* data) { - new(&val) Data; + new(&m_val) Data; auto& b = as_array(); for(size_t idx = 0; idx < sz; ++idx) { @@ -49,7 +49,7 @@ namespace llarp explicit AlignedBuffer(const Data& buf) { - new(&val) Data; + new(&m_val) Data; std::copy(buf.begin(), buf.end(), begin()); } @@ -164,13 +164,13 @@ namespace llarp Data& as_array() { - return reinterpret_cast< Data& >(val); + return reinterpret_cast< Data& >(m_val); } const Data& as_array() const { - return reinterpret_cast< const Data& >(val); + return reinterpret_cast< const Data& >(m_val); } byte_t* @@ -282,7 +282,7 @@ namespace llarp using AlignedStorage = typename std::aligned_storage< sizeof(Data), alignof(uint64_t) >:: type; // why did we align to the nearest double-precision float - AlignedStorage val; + AlignedStorage m_val; }; } // namespace llarp diff --git a/llarp/util/metrics_types.hpp b/llarp/util/metrics_types.hpp index c4cb5262c..78836e18d 100644 --- a/llarp/util/metrics_types.hpp +++ b/llarp/util/metrics_types.hpp @@ -569,10 +569,10 @@ namespace llarp print(std::ostream &stream, int level, int spaces) const { Printer::PrintFunction< absl::Duration > durationPrinter = - [](std::ostream &stream, const absl::Duration &duration, int, + [](std::ostream &os, const absl::Duration &duration, int, int) -> std::ostream & { - stream << duration; - return stream; + os << duration; + return os; }; Printer printer(stream, level, spaces); printer.printAttribute("records", m_records); diff --git a/test/dht/test_llarp_dht_tx.cpp b/test/dht/test_llarp_dht_tx.cpp index 5a99cc468..7303ae510 100644 --- a/test/dht/test_llarp_dht_tx.cpp +++ b/test/dht/test_llarp_dht_tx.cpp @@ -35,10 +35,10 @@ struct TestTx final : public dht::TX< dht::Key_t, Val_t > struct TestDhtTx : public Test { dht::TXOwner asker; - dht::Key_t key; + dht::Key_t m_key; TestTx tx; - TestDhtTx() : tx(asker, key, nullptr) + TestDhtTx() : tx(asker, m_key, nullptr) { } }; diff --git a/test/util/test_llarp_util_object.cpp b/test/util/test_llarp_util_object.cpp index ad188428f..7f4b46321 100644 --- a/test/util/test_llarp_util_object.cpp +++ b/test/util/test_llarp_util_object.cpp @@ -75,22 +75,22 @@ TEST(Catalog, Iterator) for(size_t i = 0; i < THREAD_COUNT; ++i) { threads[i] = std::thread( - [](Barrier *barrier, Cat *catalog, int32_t id) { - barrier->Block(); - for(size_t i = 0; i < ITERATION_COUNT; ++i) + [](Barrier *b, Cat *cat, int32_t id) { + b->Block(); + for(size_t j = 0; j < ITERATION_COUNT; ++j) { - int32_t handle = catalog->add(id); - absl::optional< int32_t > res = catalog->find(handle); + int32_t handle = cat->add(id); + absl::optional< int32_t > res = cat->find(handle); ASSERT_TRUE(res); ASSERT_EQ(res.value(), id); - ASSERT_TRUE(catalog->replace(MAX - id, handle)); - res = catalog->find(handle); + ASSERT_TRUE(cat->replace(MAX - id, handle)); + res = cat->find(handle); ASSERT_TRUE(res); ASSERT_EQ(MAX - id, res.value()); int32_t removed = 0; - ASSERT_TRUE(catalog->remove(handle, &removed)); + ASSERT_TRUE(cat->remove(handle, &removed)); ASSERT_EQ(removed, MAX - id); - ASSERT_FALSE(catalog->find(handle)); + ASSERT_FALSE(cat->find(handle)); } }, &barrier, &catalog, i); @@ -98,11 +98,11 @@ TEST(Catalog, Iterator) // Verify the length constraint is never violated threads[THREAD_COUNT] = std::thread( - [](Barrier *barrier, Cat *catalog) { - barrier->Block(); + [](Barrier *b, Cat *cat) { + b->Block(); for(size_t i = 0; i < ITERATION_COUNT; ++i) { - size_t size = catalog->size(); + size_t size = cat->size(); ASSERT_LE(size, THREAD_COUNT); } }, @@ -110,13 +110,13 @@ TEST(Catalog, Iterator) // Verify that iteration always produces a valid state threads[THREAD_COUNT + 1] = std::thread( - [](Barrier *barrier, Cat *catalog) { - barrier->Block(); + [](Barrier *b, Cat *cat) { + b->Block(); for(size_t i = 0; i < ITERATION_COUNT; ++i) { int32_t arr[100]; size_t size = 0; - for(Iterator it(catalog); it; ++it) + for(Iterator it(cat); it; ++it) { arr[size++] = it().second; } @@ -133,6 +133,8 @@ TEST(Catalog, Iterator) } } + (void)present; + // no duplicate should be there for(size_t k = j + 1; k < size; k++) { @@ -145,11 +147,11 @@ TEST(Catalog, Iterator) // And that we don't have an invalid catalog threads[THREAD_COUNT + 2] = std::thread( - [](Barrier *barrier, Cat *catalog) { - barrier->Block(); + [](Barrier *b, Cat *cat) { + b->Block(); for(size_t i = 0; i < ITERATION_COUNT; ++i) { - catalog->verify(); + cat->verify(); } }, &barrier, &catalog); diff --git a/test/util/test_llarp_util_timerqueue.cpp b/test/util/test_llarp_util_timerqueue.cpp index 901345a45..55a030e1d 100644 --- a/test/util/test_llarp_util_timerqueue.cpp +++ b/test/util/test_llarp_util_timerqueue.cpp @@ -272,41 +272,41 @@ TEST(TimerQueue, ThreadSafety) info[i].first = i; info[i].second = &items[i]; threads[i] = std::thread( - [](Info* info, absl::Barrier* barrier, StringQueue* queue) { - const int THREAD_ID = info->first; - std::vector< StringItem >* vPtr = info->second; + [](Info* nfo, absl::Barrier* b, StringQueue* q) { + const int THREAD_ID = nfo->first; + std::vector< StringItem >* vPtr = nfo->second; // We stagger the removeAll steps among the threads. - const int STEP_REMOVE_ALL = THREAD_ID * NUM_REMOVE_ALL / NUM_THREADS; + const unsigned int STEP_REMOVE_ALL = THREAD_ID * NUM_REMOVE_ALL / NUM_THREADS; std::ostringstream oss; oss << THREAD_ID; Data V(oss.str()); - barrier->Block(); + b->Block(); size_t newSize; absl::Time newMinTime; StringItem item; - for(size_t i = 0; i < NUM_ITERATIONS; ++i) + for(size_t j = 0; j < NUM_ITERATIONS; ++j) { const absl::Time TIME = - absl::Time() + absl::Seconds((i * (i + 3)) % NUM_ITERATIONS); - int h = queue->add(TIME, V); - queue->update(h, TIME); - if(queue->popFront(&item, &newSize, &newMinTime)) + absl::Time() + absl::Seconds((j * (j + 3)) % NUM_ITERATIONS); + int h = q->add(TIME, V); + q->update(h, TIME); + if(q->popFront(&item, &newSize, &newMinTime)) { vPtr->push_back(item); } - h = queue->add(newMinTime, V); - queue->popLess(newMinTime, vPtr); - if(queue->remove(h, &item, &newSize, &newMinTime)) + h = q->add(newMinTime, V); + q->popLess(newMinTime, vPtr); + if(q->remove(h, &item, &newSize, &newMinTime)) { vPtr->push_back(item); } - if(i % NUM_REMOVE_ALL == STEP_REMOVE_ALL) + if(j % NUM_REMOVE_ALL == STEP_REMOVE_ALL) { - queue->removeAll(vPtr); + q->removeAll(vPtr); } } }, @@ -314,11 +314,11 @@ TEST(TimerQueue, ThreadSafety) } threads[NUM_THREADS] = std::thread( - [](absl::Barrier* barrier, StringQueue* queue) { - barrier->Block(); + [](absl::Barrier* b, StringQueue* q) { + b->Block(); for(size_t i = 0; i < NUM_ITERATIONS; ++i) { - size_t size = queue->size(); + size_t size = q->size(); ASSERT_GE(size, 0); ASSERT_LE(size, NUM_THREADS); } diff --git a/vendor/libtuntap-master/tuntap-unix-linux.c b/vendor/libtuntap-master/tuntap-unix-linux.c index 56a1151bd..1bb718e1e 100644 --- a/vendor/libtuntap-master/tuntap-unix-linux.c +++ b/vendor/libtuntap-master/tuntap-unix-linux.c @@ -36,10 +36,10 @@ int tuntap_sys_start(struct device *dev, int mode, int tun) { - + int fd; int persist; - char *ifname; + char *ifname = NULL; struct ifreq ifr; /* Get the persistence bit */ @@ -92,7 +92,7 @@ tuntap_sys_start(struct device *dev, int mode, int tun) } return fd; } - else + else { /* Open the clonable interface */ if((fd = open("/dev/net/tun", O_RDWR)) == -1) @@ -202,7 +202,7 @@ tuntap_sys_set_ipv6(struct device *dev, t_tun_in6_addr *s6, uint32_t bits) { struct ifreq ifr; struct sockaddr_in6 sai; - int sockfd; + int sockfd; struct in6_ifreq ifr6; sockfd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_IP); diff --git a/vendor/libtuntap-master/tuntap-unix.c b/vendor/libtuntap-master/tuntap-unix.c index cf8354af0..2dffbfd40 100644 --- a/vendor/libtuntap-master/tuntap-unix.c +++ b/vendor/libtuntap-master/tuntap-unix.c @@ -157,7 +157,7 @@ tuntap_set_ifname(struct device *dev, const char *ifname) } len = strlen(ifname); - if(len > IF_NAMESIZE) + if(len >= IF_NAMESIZE) { tuntap_log(TUNTAP_LOG_ERR, "Parameter 'ifname' is too long"); return -1; @@ -169,7 +169,7 @@ tuntap_set_ifname(struct device *dev, const char *ifname) } (void)memset(dev->if_name, 0, IF_NAMESIZE); - (void)strncpy(dev->if_name, ifname, len); + (void)strncpy(dev->if_name, ifname, len + 1); return 0; }