Enable -Wextra

test criteria:
- test build on macOS
- test build in debian docker container
- test build in fedora docker container
This commit is contained in:
Michael Thorpe 2018-11-07 15:30:22 +00:00
parent 5ad0e9d4ba
commit 33bfaf7ecd
No known key found for this signature in database
GPG Key ID: 9E72CAE320D5817C
59 changed files with 587 additions and 401 deletions

27
.vscode/launch.json vendored
View File

@ -3,7 +3,18 @@
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
"configurations": [{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/lokinet",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
},
{
"name": "(gdb) Launch",
"type": "cppdbg",
@ -15,13 +26,11 @@
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
"setupCommands": [{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}]
}
]
}
}

View File

@ -68,6 +68,7 @@
"complex": "cpp",
"variant": "cpp",
"any": "cpp",
"tuntap.h": "c"
"tuntap.h": "c",
"hashtable": "cpp"
}
}

View File

@ -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 -Werror -Wno-unknown-pragmas)
add_compile_options(-Wall -Wextra -Werror -Wno-unknown-pragmas)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fpermissive>)
add_compile_options(-Wno-unused-function -Wno-deprecated-declarations -Wno-unknown-pragmas)

View File

@ -1,6 +1,6 @@
int
main(int argc, char* argv[])
main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
{
return 0;
}

View File

@ -400,7 +400,7 @@ mult96x16(__m256i h[192], const __m256i f[96], const __m256i g[96])
static void
transpose16(__m256i x[16])
{
const static int rev[4] = {0, 4, 2, 6};
static const int rev[4] = {0, 4, 2, 6};
int i;
__m256i y[16];
@ -449,7 +449,7 @@ transpose16(__m256i x[16])
static void
transpose32(__m256i x[32])
{
const static int rev[4] = {0, 8, 4, 12};
static const int rev[4] = {0, 8, 4, 12};
int i;
__m256i y[32];

View File

@ -62,7 +62,7 @@ typedef struct llarp_buffer_t
size_t sz;
#ifdef __cplusplus
const byte_t operator[](size_t x)
byte_t operator[](size_t x)
{
return *(this->base + x);
}

View File

@ -22,7 +22,7 @@ namespace llarp
struct DummyLock
{
DummyLock(const DummyMutex& mtx){};
DummyLock(__attribute__((unused)) const DummyMutex& mtx){};
~DummyLock()
{

View File

@ -111,7 +111,7 @@ namespace llarp
MapAddr(const PubKey& pk, ILinkSession* s);
virtual void
Tick(llarp_time_t now)
Tick(__attribute__((unused)) llarp_time_t now)
{
}

View File

@ -36,13 +36,14 @@ namespace llarp
}
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) override
DecodeKey(__attribute__((unused)) llarp_buffer_t key,
__attribute__((unused)) llarp_buffer_t* buf) override
{
return false;
}
bool
HandleMessage(llarp_router* router) const override
HandleMessage(__attribute__((unused)) llarp_router* router) const override
{
return true;
}

View File

@ -181,7 +181,8 @@ namespace llarp
llarp_router* r);
bool
HandleHiddenServiceFrame(const llarp::service::ProtocolFrame* frame)
HandleHiddenServiceFrame(__attribute__((unused))
const llarp::service::ProtocolFrame* frame)
{
/// TODO: implement me
llarp::LogWarn("Got hidden service data on transit hop");

View File

@ -46,10 +46,10 @@ namespace llarp
RemovePath(Path* path);
virtual void
HandlePathBuilt(Path* path);
HandlePathBuilt(__attribute__((unused)) Path* path);
virtual void
HandlePathBuildTimeout(Path* path);
HandlePathBuildTimeout(__attribute__((unused)) Path* path);
bool
GetNewestIntro(service::Introduction& intro) const;
@ -76,22 +76,23 @@ namespace llarp
/// return true if we should publish a new hidden service descriptor
virtual bool
ShouldPublishDescriptors(llarp_time_t now) const
{
(void)now;
return false;
}
/// override me in subtype
virtual bool
HandleGotIntroMessage(const llarp::dht::GotIntroMessage* msg)
ShouldPublishDescriptors(__attribute__((unused)) llarp_time_t now) const
{
return false;
}
/// override me in subtype
virtual bool
HandleGotRouterMessage(const llarp::dht::GotRouterMessage* msg)
HandleGotIntroMessage(__attribute__((unused))
const llarp::dht::GotIntroMessage* msg)
{
return false;
}
/// override me in subtype
virtual bool
HandleGotRouterMessage(__attribute__((unused))
const llarp::dht::GotRouterMessage* msg)
{
return false;
}
@ -128,7 +129,7 @@ namespace llarp
std::set< llarp::service::Introduction >& intros) const;
virtual bool
PublishIntroSet(llarp_router* r)
PublishIntroSet(__attribute__((unused)) llarp_router* r)
{
return false;
}

View File

@ -20,14 +20,14 @@ namespace llarp
}
RouterContact(const RouterContact &other)
: addrs(other.addrs)
: IBEncodeMessage()
, addrs(other.addrs)
, enckey(other.enckey)
, pubkey(other.pubkey)
, exits(other.exits)
, signature(other.signature)
, nickname(other.nickname)
, last_updated(other.last_updated)
{
version = other.version;
}

View File

@ -30,7 +30,8 @@ namespace llarp
*/
ServiceInfo(const ServiceInfo& other)
: enckey(other.enckey)
: IBEncodeMessage(other.version)
, enckey(other.enckey)
, signkey(other.signkey)
, vanity(other.vanity)
, m_CachedAddr(other.m_CachedAddr)

View File

@ -19,7 +19,7 @@ namespace llarp
uint64_t expiresAt = 0;
Introduction() = default;
Introduction(const Introduction& other)
Introduction(const Introduction& other) : IBEncodeMessage(other.version)
{
router = other.router;
pathID = other.pathID;

View File

@ -31,7 +31,7 @@ namespace llarp
IntroSet() = default;
IntroSet(IntroSet&& other)
IntroSet(IntroSet&& other) : IBEncodeMessage(other.version)
{
A = std::move(other.A);
I = std::move(other.I);
@ -43,7 +43,7 @@ namespace llarp
Z = std::move(other.Z);
}
IntroSet(const IntroSet& other)
IntroSet(const IntroSet& other) : IBEncodeMessage(other.version)
{
A = other.A;
I = other.I;

View File

@ -108,16 +108,18 @@ namespace llarp
HasPathToService(const Address& remote) const;
virtual huint32_t
ObtainIPForAddr(const llarp::service::Address& remote)
ObtainIPForAddr(__attribute__((unused))
const llarp::service::Address& remote)
{
return {0};
}
virtual bool
HasAddress(const Address& remote) const
HasAddress(__attribute__((unused)) const Address& remote) const
{
return false;
}
/// return true if we have a pending job to build to a hidden service but
/// it's not done yet
bool
@ -132,7 +134,7 @@ namespace llarp
HandleDataMessage(const PathID_t&, ProtocolMessage* msg);
virtual bool
ProcessDataMessage(ProtocolMessage* msg)
ProcessDataMessage(__attribute__((unused)) ProtocolMessage* msg)
{
return true;
}
@ -217,22 +219,17 @@ namespace llarp
};
virtual void
UpdateIntroSet(bool randomizePath = false){};
UpdateIntroSet(bool randomizePath = false) = 0;
virtual bool
MarkCurrentIntroBad(llarp_time_t now)
{
return true;
};
MarkCurrentIntroBad(llarp_time_t now) = 0;
private:
void
EncryptAndSendTo(llarp_buffer_t payload, ProtocolType t);
virtual void
AsyncGenIntro(llarp_buffer_t payload, ProtocolType t)
{
}
AsyncGenIntro(llarp_buffer_t payload, ProtocolType t) = 0;
};
static void
@ -332,7 +329,8 @@ namespace llarp
uint64_t timeoutMS, bool lookupOnRandomPath = false);
virtual bool
HandleAuthenticatedDataFrom(const Address& remote, llarp_buffer_t data)
HandleAuthenticatedDataFrom(__attribute__((unused)) const Address& remote,
__attribute__((unused)) llarp_buffer_t data)
{
/// TODO: imlement me
return true;

View File

@ -25,7 +25,8 @@ namespace llarp
/// handle lookup result
virtual bool
HandleResponse(const std::set< IntroSet >& results)
HandleResponse(__attribute__((unused))
const std::set< IntroSet >& results)
{
return false;
}

View File

@ -25,7 +25,7 @@ namespace llarp
/// a lock that does nothing
struct NullLock
{
NullLock(NullMutex& mtx)
NullLock(__attribute__((unused)) NullMutex& mtx)
{
}
};

View File

@ -11,7 +11,8 @@ struct DemoHandler : public abyss::httpd::IRPCHandler
}
bool
HandleJSONRPC(Method_t method, const Params& params, Response& resp)
HandleJSONRPC(Method_t method, __attribute__((unused)) const Params& params,
Response& resp) override
{
llarp::LogInfo("method: ", method);
resp.AddMember("result", abyss::json::Value().SetInt(1),
@ -28,7 +29,7 @@ struct DemoCall : public abyss::http::IRPCClientHandler
}
bool
HandleResponse(const abyss::http::RPC_Response& resp)
HandleResponse(const abyss::http::RPC_Response& resp) override
{
std::string body;
abyss::json::ToString(resp, body);
@ -37,12 +38,13 @@ struct DemoCall : public abyss::http::IRPCClientHandler
}
void
PopulateReqHeaders(abyss::http::Headers_t& hdr)
PopulateReqHeaders(__attribute__((unused))
abyss::http::Headers_t& hdr) override
{
}
void
HandleError()
HandleError() override
{
llarp::LogError("error while handling call: ", strerror(errno));
}
@ -81,7 +83,7 @@ struct DemoServer : public abyss::httpd::BaseReqHandler
};
int
main(int argc, char* argv[])
main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
{
// Ignore on Windows, we don't even get SIGPIPE (even though native *and*
// emulated UNIX pipes exist - CreatePipe(2), pipe(3))

View File

@ -67,7 +67,7 @@ namespace abyss
}
static void
OnTick(llarp_tcp_conn* conn)
OnTick(__attribute__((unused)) llarp_tcp_conn* conn)
{
}
@ -396,4 +396,4 @@ namespace abyss
}
} // namespace http
} // namespace abyss
} // namespace abyss

View File

@ -23,8 +23,8 @@
#ifndef __UTP_HASH_H__
#define __UTP_HASH_H__
#include <string.h> // memset
#include <stdlib.h> // malloc
#include <string.h> // memset
#include <stdlib.h> // malloc
#include "utp_types.h"
#include "utp_templates.h"
@ -33,12 +33,14 @@
typedef uint32 utp_link_t;
#ifdef _MSC_VER
// Silence the warning about the C99-compliant zero-length array at the end of the structure
#pragma warning (disable: 4200)
// Silence the warning about the C99-compliant zero-length array at the end of
// the structure
#pragma warning(disable : 4200)
#endif
typedef uint32 (*utp_hash_compute_t)(const void *keyp, size_t keysize);
typedef uint (*utp_hash_equal_t)(const void *key_a, const void *key_b, size_t keysize);
typedef uint (*utp_hash_equal_t)(const void *key_a, const void *key_b,
size_t keysize);
// In memory the HashTable is laid out as follows:
// ---------------------------- low
@ -74,73 +76,132 @@ typedef uint (*utp_hash_equal_t)(const void *key_a, const void *key_b, size_t ke
//
// N is the number of buckets.
//
struct utp_hash_t {
utp_link_t N;
byte K;
byte E;
size_t count;
utp_hash_compute_t hash_compute;
utp_hash_equal_t hash_equal;
utp_link_t allocated;
utp_link_t used;
utp_link_t free;
utp_link_t inits[0];
struct utp_hash_t
{
utp_link_t N;
byte K;
byte E;
size_t count;
utp_hash_compute_t hash_compute;
utp_hash_equal_t hash_equal;
utp_link_t allocated;
utp_link_t used;
utp_link_t free;
utp_link_t inits[0];
};
#ifdef _MSC_VER
#pragma warning (default: 4200)
#pragma warning(default : 4200)
#endif
struct utp_hash_iterator_t {
utp_link_t bucket;
utp_link_t elem;
struct utp_hash_iterator_t
{
utp_link_t bucket;
utp_link_t elem;
utp_hash_iterator_t() : bucket(0xffffffff), elem(0xffffffff) {}
utp_hash_iterator_t() : bucket(0xffffffff), elem(0xffffffff)
{
}
};
uint utp_hash_mem(const void *keyp, size_t keysize);
uint utp_hash_comp(const void *key_a, const void *key_b, size_t keysize);
uint
utp_hash_mem(const void *keyp, size_t keysize);
uint
utp_hash_comp(const void *key_a, const void *key_b, size_t keysize);
utp_hash_t *utp_hash_create(int N, int key_size, int total_size, int initial, utp_hash_compute_t hashfun = utp_hash_mem, utp_hash_equal_t eqfun = NULL);
void *utp_hash_lookup(utp_hash_t *hash, const void *key);
void *utp_hash_add(utp_hash_t **hashp, const void *key);
void *utp_hash_del(utp_hash_t *hash, const void *key);
utp_hash_t *
utp_hash_create(int N, int key_size, int total_size, int initial,
utp_hash_compute_t hashfun = utp_hash_mem,
utp_hash_equal_t eqfun = NULL);
void *
utp_hash_lookup(utp_hash_t *hash, const void *key);
void *
utp_hash_add(utp_hash_t **hashp, const void *key);
void *
utp_hash_del(utp_hash_t *hash, const void *key);
void *utp_hash_iterate(utp_hash_t *hash, utp_hash_iterator_t *iter);
void utp_hash_free_mem(utp_hash_t *hash);
void *
utp_hash_iterate(utp_hash_t *hash, utp_hash_iterator_t *iter);
void
utp_hash_free_mem(utp_hash_t *hash);
/*
This HashTable requires that T have at least sizeof(K)+sizeof(utp_link_t) bytes.
Usually done like this:
This HashTable requires that T have at least
sizeof(K)+sizeof(utp_link_t) bytes. Usually done like this:
struct K {
int whatever;
};
struct K {
int whatever;
};
struct T {
K wtf;
utp_link_t link; // also wtf
};
struct T {
K wtf;
utp_link_t link; // also wtf
};
*/
template<typename K, typename T> class utpHashTable {
utp_hash_t *hash;
public:
static uint compare(const void *k1, const void *k2, size_t ks) {
return *((K*)k1) == *((K*)k2);
}
static uint32 compute_hash(const void *k, size_t ks) {
return ((K*)k)->compute_hash();
}
void Init() { hash = NULL; }
bool Allocated() { return (hash != NULL); }
void Free() { utp_hash_free_mem(hash); hash = NULL; }
void Create(int N, int initial) { hash = utp_hash_create(N, sizeof(K), sizeof(T), initial, &compute_hash, &compare); }
T *Lookup(const K &key) { return (T*)utp_hash_lookup(hash, &key); }
T *Add(const K &key) { return (T*)utp_hash_add(&hash, &key); }
T *Delete(const K &key) { return (T*)utp_hash_del(hash, &key); }
T *Iterate(utp_hash_iterator_t &iterator) { return (T*)utp_hash_iterate(hash, &iterator); }
size_t GetCount() { return hash->count; }
template < typename K, typename T >
class utpHashTable
{
utp_hash_t *hash;
public:
static uint
compare(const void *k1, const void *k2, __attribute__((unused)) size_t ks)
{
return *((K *)k1) == *((K *)k2);
}
static uint32
compute_hash(const void *k, __attribute__((unused)) size_t ks)
{
return ((K *)k)->compute_hash();
}
void
Init()
{
hash = NULL;
}
bool
Allocated()
{
return (hash != NULL);
}
void
Free()
{
utp_hash_free_mem(hash);
hash = NULL;
}
void
Create(int N, int initial)
{
hash = utp_hash_create(N, sizeof(K), sizeof(T), initial, &compute_hash,
&compare);
}
T *
Lookup(const K &key)
{
return (T *)utp_hash_lookup(hash, &key);
}
T *
Add(const K &key)
{
return (T *)utp_hash_add(&hash, &key);
}
T *
Delete(const K &key)
{
return (T *)utp_hash_del(hash, &key);
}
T *
Iterate(utp_hash_iterator_t &iterator)
{
return (T *)utp_hash_iterate(hash, &iterator);
}
size_t
GetCount()
{
return hash->count;
}
};
#endif //__UTP_HASH_H__
#endif //__UTP_HASH_H__

View File

@ -3487,6 +3487,7 @@ utp_socket_stats* utp_get_stats(utp_socket *socket)
socket->_stats.mtu_guess = socket->mtu_last ? socket->mtu_last : socket->mtu_ceiling;
return &socket->_stats;
#else
(void)socket;
return NULL;
#endif
}

View File

@ -27,25 +27,25 @@
#ifdef WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#else //!WIN32
#include <time.h>
#include <sys/time.h> // Linux needs both time.h and sys/time.h
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#else //! WIN32
#include <time.h>
#include <sys/time.h> // Linux needs both time.h and sys/time.h
#endif
#if defined(__APPLE__)
#include <mach/mach_time.h>
#include <mach/mach_time.h>
#endif
#include "utp_utils.h"
#ifdef WIN32
typedef ULONGLONG (WINAPI GetTickCount64Proc)(void);
typedef ULONGLONG(WINAPI GetTickCount64Proc)(void);
static GetTickCount64Proc *pt2GetTickCount64;
static GetTickCount64Proc *pt2RealGetTickCount;
@ -54,160 +54,189 @@ static uint64 startGetTickCount;
// MSVC 6 standard doesn't like division with uint64s
static double counterPerMicrosecond;
static uint64 UTGetTickCount64()
static uint64
UTGetTickCount64()
{
if (pt2GetTickCount64) {
return pt2GetTickCount64();
}
if (pt2RealGetTickCount) {
uint64 v = pt2RealGetTickCount();
// fix return value from GetTickCount
return (DWORD)v | ((v >> 0x18) & 0xFFFFFFFF00000000);
}
return (uint64)GetTickCount();
if(pt2GetTickCount64)
{
return pt2GetTickCount64();
}
if(pt2RealGetTickCount)
{
uint64 v = pt2RealGetTickCount();
// fix return value from GetTickCount
return (DWORD)v | ((v >> 0x18) & 0xFFFFFFFF00000000);
}
return (uint64)GetTickCount();
}
static void Time_Initialize()
static void
Time_Initialize()
{
HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
pt2GetTickCount64 = (GetTickCount64Proc*)GetProcAddress(kernel32, "GetTickCount64");
// not a typo. GetTickCount actually returns 64 bits
pt2RealGetTickCount = (GetTickCount64Proc*)GetProcAddress(kernel32, "GetTickCount");
HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
pt2GetTickCount64 =
(GetTickCount64Proc *)GetProcAddress(kernel32, "GetTickCount64");
// not a typo. GetTickCount actually returns 64 bits
pt2RealGetTickCount =
(GetTickCount64Proc *)GetProcAddress(kernel32, "GetTickCount");
uint64 frequency;
QueryPerformanceCounter((LARGE_INTEGER*)&startPerformanceCounter);
QueryPerformanceFrequency((LARGE_INTEGER*)&frequency);
counterPerMicrosecond = (double)frequency / 1000000.0f;
startGetTickCount = UTGetTickCount64();
uint64 frequency;
QueryPerformanceCounter((LARGE_INTEGER *)&startPerformanceCounter);
QueryPerformanceFrequency((LARGE_INTEGER *)&frequency);
counterPerMicrosecond = (double)frequency / 1000000.0f;
startGetTickCount = UTGetTickCount64();
}
static int64 abs64(int64 x) { return x < 0 ? -x : x; }
static uint64 __GetMicroseconds()
static int64
abs64(int64 x)
{
static bool time_init = false;
if (!time_init) {
time_init = true;
Time_Initialize();
}
uint64 counter;
uint64 tick;
QueryPerformanceCounter((LARGE_INTEGER*) &counter);
tick = UTGetTickCount64();
// unfortunately, QueryPerformanceCounter is not guaranteed
// to be monotonic. Make it so.
int64 ret = (int64)(((int64)counter - (int64)startPerformanceCounter) / counterPerMicrosecond);
// if the QPC clock leaps more than one second off GetTickCount64()
// something is seriously fishy. Adjust QPC to stay monotonic
int64 tick_diff = tick - startGetTickCount;
if (abs64(ret / 100000 - tick_diff / 100) > 10) {
startPerformanceCounter -= (uint64)((int64)(tick_diff * 1000 - ret) * counterPerMicrosecond);
ret = (int64)((counter - startPerformanceCounter) / counterPerMicrosecond);
}
return ret;
return x < 0 ? -x : x;
}
static inline uint64 UTP_GetMilliseconds()
static uint64
__GetMicroseconds()
{
return GetTickCount();
static bool time_init = false;
if(!time_init)
{
time_init = true;
Time_Initialize();
}
uint64 counter;
uint64 tick;
QueryPerformanceCounter((LARGE_INTEGER *)&counter);
tick = UTGetTickCount64();
// unfortunately, QueryPerformanceCounter is not guaranteed
// to be monotonic. Make it so.
int64 ret = (int64)(((int64)counter - (int64)startPerformanceCounter)
/ counterPerMicrosecond);
// if the QPC clock leaps more than one second off GetTickCount64()
// something is seriously fishy. Adjust QPC to stay monotonic
int64 tick_diff = tick - startGetTickCount;
if(abs64(ret / 100000 - tick_diff / 100) > 10)
{
startPerformanceCounter -=
(uint64)((int64)(tick_diff * 1000 - ret) * counterPerMicrosecond);
ret = (int64)((counter - startPerformanceCounter) / counterPerMicrosecond);
}
return ret;
}
#else //!WIN32
static inline uint64 UTP_GetMicroseconds(void);
static inline uint64 UTP_GetMilliseconds()
static inline uint64
UTP_GetMilliseconds()
{
return UTP_GetMicroseconds() / 1000;
return GetTickCount();
}
#else //! WIN32
static inline uint64
UTP_GetMicroseconds(void);
static inline uint64
UTP_GetMilliseconds()
{
return UTP_GetMicroseconds() / 1000;
}
#if defined(__APPLE__)
static uint64 __GetMicroseconds()
static uint64
__GetMicroseconds()
{
// http://developer.apple.com/mac/library/qa/qa2004/qa1398.html
// http://www.macresearch.org/tutorial_performance_and_time
static mach_timebase_info_data_t sTimebaseInfo;
static uint64_t start_tick = 0;
uint64_t tick;
// Returns a counter in some fraction of a nanoseconds
tick = mach_absolute_time();
if (sTimebaseInfo.denom == 0) {
// Get the timer ratio to convert mach_absolute_time to nanoseconds
mach_timebase_info(&sTimebaseInfo);
start_tick = tick;
}
// Calculate the elapsed time, convert it to microseconds and return it.
return ((tick - start_tick) * sTimebaseInfo.numer) / (sTimebaseInfo.denom * 1000);
// http://developer.apple.com/mac/library/qa/qa2004/qa1398.html
// http://www.macresearch.org/tutorial_performance_and_time
static mach_timebase_info_data_t sTimebaseInfo;
static uint64_t start_tick = 0;
uint64_t tick;
// Returns a counter in some fraction of a nanoseconds
tick = mach_absolute_time();
if(sTimebaseInfo.denom == 0)
{
// Get the timer ratio to convert mach_absolute_time to nanoseconds
mach_timebase_info(&sTimebaseInfo);
start_tick = tick;
}
// Calculate the elapsed time, convert it to microseconds and return it.
return ((tick - start_tick) * sTimebaseInfo.numer)
/ (sTimebaseInfo.denom * 1000);
}
#else // !__APPLE__
#else // !__APPLE__
#if ! (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0 && defined(CLOCK_MONOTONIC))
#warning "Using non-monotonic function gettimeofday() in UTP_GetMicroseconds()"
#if !(defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0 && defined(CLOCK_MONOTONIC))
#warning "Using non-monotonic function gettimeofday() in UTP_GetMicroseconds()"
#endif
/* Unfortunately, #ifdef CLOCK_MONOTONIC is not enough to make sure that
POSIX clocks work -- we could be running a recent libc with an ancient
kernel (think OpenWRT). -- jch */
static uint64_t __GetMicroseconds()
static uint64_t
__GetMicroseconds()
{
struct timeval tv;
struct timeval tv;
#if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0 && defined(CLOCK_MONOTONIC)
static int have_posix_clocks = -1;
int rc;
#if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0 && defined(CLOCK_MONOTONIC)
static int have_posix_clocks = -1;
int rc;
if (have_posix_clocks < 0) {
struct timespec ts;
rc = clock_gettime(CLOCK_MONOTONIC, &ts);
if (rc < 0) {
have_posix_clocks = 0;
} else {
have_posix_clocks = 1;
}
}
if(have_posix_clocks < 0)
{
struct timespec ts;
rc = clock_gettime(CLOCK_MONOTONIC, &ts);
if(rc < 0)
{
have_posix_clocks = 0;
}
else
{
have_posix_clocks = 1;
}
}
if (have_posix_clocks) {
struct timespec ts;
rc = clock_gettime(CLOCK_MONOTONIC, &ts);
return uint64(ts.tv_sec) * 1000000 + uint64(ts.tv_nsec) / 1000;
}
#endif
if(have_posix_clocks)
{
struct timespec ts;
rc = clock_gettime(CLOCK_MONOTONIC, &ts);
return uint64(ts.tv_sec) * 1000000 + uint64(ts.tv_nsec) / 1000;
}
#endif
gettimeofday(&tv, NULL);
return uint64(tv.tv_sec) * 1000000 + tv.tv_usec;
gettimeofday(&tv, NULL);
return uint64(tv.tv_sec) * 1000000 + tv.tv_usec;
}
#endif //!__APPLE__
#endif //!__APPLE__
#endif //!WIN32
#endif //! WIN32
/*
* Whew. Okay. After that #ifdef maze above, we now know we have a working
* __GetMicroseconds() implementation on all platforms.
*
*
* Because there are a number of assertions in libutp that will cause a crash
* if monotonic time isn't monotonic, now apply some safety checks. While in
* principle we're already protecting ourselves in cases where non-monotonic
* time is likely to happen, this protects all versions.
*/
static inline uint64 UTP_GetMicroseconds()
static inline uint64
UTP_GetMicroseconds()
{
static uint64 offset = 0, previous = 0;
static uint64 offset = 0, previous = 0;
uint64 now = __GetMicroseconds() + offset;
if (previous > now) {
/* Eek! */
offset += previous - now;
now = previous;
}
previous = now;
return now;
uint64 now = __GetMicroseconds() + offset;
if(previous > now)
{
/* Eek! */
offset += previous - now;
now = previous;
}
previous = now;
return now;
}
#define ETHERNET_MTU 1500
@ -227,30 +256,47 @@ static inline uint64 UTP_GetMicroseconds()
#define UDP_IPV6_OVERHEAD (IPV6_HEADER_SIZE + UDP_HEADER_SIZE)
#define UDP_TEREDO_OVERHEAD (UDP_IPV4_OVERHEAD + UDP_IPV6_OVERHEAD)
#define UDP_IPV4_MTU (ETHERNET_MTU - IPV4_HEADER_SIZE - UDP_HEADER_SIZE - GRE_HEADER_SIZE - PPPOE_HEADER_SIZE - MPPE_HEADER_SIZE - FUDGE_HEADER_SIZE)
#define UDP_IPV6_MTU (ETHERNET_MTU - IPV6_HEADER_SIZE - UDP_HEADER_SIZE - GRE_HEADER_SIZE - PPPOE_HEADER_SIZE - MPPE_HEADER_SIZE - FUDGE_HEADER_SIZE)
#define UDP_IPV4_MTU \
(ETHERNET_MTU - IPV4_HEADER_SIZE - UDP_HEADER_SIZE - GRE_HEADER_SIZE \
- PPPOE_HEADER_SIZE - MPPE_HEADER_SIZE - FUDGE_HEADER_SIZE)
#define UDP_IPV6_MTU \
(ETHERNET_MTU - IPV6_HEADER_SIZE - UDP_HEADER_SIZE - GRE_HEADER_SIZE \
- PPPOE_HEADER_SIZE - MPPE_HEADER_SIZE - FUDGE_HEADER_SIZE)
#define UDP_TEREDO_MTU (TEREDO_MTU - IPV6_HEADER_SIZE - UDP_HEADER_SIZE)
uint64 utp_default_get_udp_mtu(utp_callback_arguments *args) {
// Since we don't know the local address of the interface,
// be conservative and assume all IPv6 connections are Teredo.
return (args->address->sa_family == AF_INET6) ? UDP_TEREDO_MTU : UDP_IPV4_MTU;
uint64
utp_default_get_udp_mtu(utp_callback_arguments *args)
{
// Since we don't know the local address of the interface,
// be conservative and assume all IPv6 connections are Teredo.
return (args->address->sa_family == AF_INET6) ? UDP_TEREDO_MTU : UDP_IPV4_MTU;
}
uint64 utp_default_get_udp_overhead(utp_callback_arguments *args) {
// Since we don't know the local address of the interface,
// be conservative and assume all IPv6 connections are Teredo.
return (args->address->sa_family == AF_INET6) ? UDP_TEREDO_OVERHEAD : UDP_IPV4_OVERHEAD;
uint64
utp_default_get_udp_overhead(utp_callback_arguments *args)
{
// Since we don't know the local address of the interface,
// be conservative and assume all IPv6 connections are Teredo.
return (args->address->sa_family == AF_INET6) ? UDP_TEREDO_OVERHEAD
: UDP_IPV4_OVERHEAD;
}
uint64 utp_default_get_random(utp_callback_arguments *args) {
return rand();
uint64
utp_default_get_random(__attribute__((unused)) utp_callback_arguments *args)
{
return rand();
}
uint64 utp_default_get_milliseconds(utp_callback_arguments *args) {
return UTP_GetMilliseconds();
uint64
utp_default_get_milliseconds(__attribute__((unused))
utp_callback_arguments *args)
{
return UTP_GetMilliseconds();
}
uint64 utp_default_get_microseconds(utp_callback_arguments *args) {
return UTP_GetMicroseconds();
uint64
utp_default_get_microseconds(__attribute__((unused))
utp_callback_arguments *args)
{
return UTP_GetMicroseconds();
}

View File

@ -112,7 +112,7 @@ namespace llarp
}
bool
Context::PutDatabase(struct llarp::RouterContact &rc)
Context::PutDatabase(__attribute__((unused)) struct llarp::RouterContact &rc)
{
// FIXME
// return llarp_nodedb_put_rc(nodedb, rc);
@ -120,7 +120,7 @@ namespace llarp
}
llarp::RouterContact *
Context::GetDatabase(const byte_t *pk)
Context::GetDatabase(__attribute__((unused)) const byte_t *pk)
{
// FIXME
// return llarp_nodedb_get_rc(nodedb, pk);
@ -379,7 +379,7 @@ extern "C"
}
llarp::RouterContact *
llarp_main_getLocalRC(struct llarp_main *ptr)
llarp_main_getLocalRC(__attribute__((unused)) struct llarp_main *ptr)
{
//
/*
@ -402,7 +402,8 @@ extern "C"
}
void
llarp_main_checkOnline(void *u, uint64_t orig, uint64_t left)
llarp_main_checkOnline(void *u, __attribute__((unused)) uint64_t orig,
uint64_t left)
{
// llarp::Info("checkOnline - check ", left);
if(left)

View File

@ -104,7 +104,9 @@ namespace llarp
}
void
Context::handle_cleaner_timer(void *u, uint64_t orig, uint64_t left)
Context::handle_cleaner_timer(void *u,
__attribute__((unused)) uint64_t orig,
uint64_t left)
{
if(left)
return;
@ -397,7 +399,7 @@ namespace llarp
LocalServiceAddressLookup(const PathID_t &pathid, uint64_t txid,
const service::Address &addr, Context *ctx,
const Key_t &askpeer)
__attribute__((unused)) const Key_t &askpeer)
: ServiceAddressLookup(TXOwner{ctx->OurKey(), txid}, addr, ctx, 5,
nullptr)
, localPath(pathid)
@ -568,13 +570,14 @@ namespace llarp
}
bool
GetNextPeer(Key_t &nextpeer, const std::set< Key_t > &exclude)
GetNextPeer(__attribute__((unused)) Key_t &nextpeer,
__attribute__((unused)) const std::set< Key_t > &exclude)
{
return false;
}
void
DoNextRequest(const Key_t &nextPeer)
DoNextRequest(__attribute__((unused)) const Key_t &nextPeer)
{
}
@ -718,14 +721,15 @@ namespace llarp
}
bool
GetNextPeer(Key_t &next, const std::set< Key_t > &exclude)
GetNextPeer(__attribute__((unused)) Key_t &next,
__attribute__((unused)) const std::set< Key_t > &exclude)
{
// TODO: implement iterative (?)
return false;
}
void
DoNextRequest(const Key_t &next)
DoNextRequest(__attribute__((unused)) const Key_t &next)
{
}

View File

@ -21,6 +21,7 @@ namespace llarp
bool
GotIntroMessage::HandleMessage(
llarp_dht_context *ctx,
__attribute__((unused))
std::vector< std::unique_ptr< IMessage > > &replies) const
{
auto &dht = ctx->impl;
@ -58,6 +59,7 @@ namespace llarp
bool
RelayedGotIntroMessage::HandleMessage(
llarp_dht_context *ctx,
__attribute__((unused))
std::vector< std::unique_ptr< IMessage > > &replies) const
{
// TODO: implement me better?

View File

@ -68,6 +68,7 @@ namespace llarp
bool
GotRouterMessage::HandleMessage(
llarp_dht_context *ctx,
__attribute__((unused))
std::vector< std::unique_ptr< IMessage > > &replies) const
{
auto &dht = ctx->impl;

View File

@ -31,7 +31,8 @@ std::unordered_map< std::string, struct dnsd_query_hook_response * >
loki_tld_lookup_cache;
void
llarp_dotlokilookup_checkQuery(void *u, uint64_t orig, uint64_t left)
llarp_dotlokilookup_checkQuery(void *u, __attribute__((unused)) uint64_t orig,
uint64_t left)
{
if(left)
return;

View File

@ -24,6 +24,7 @@ dns_iptracker_init()
// not sure we want tunGatewayIP... we'll know when we get further
bool
dns_iptracker_setup_dotLokiLookup(dotLokiLookup *dll,
__attribute__((unused))
llarp::huint32_t tunGatewayIp)
{
dll->ip_tracker = &g_dns_iptracker;

View File

@ -151,13 +151,14 @@ answer_request_alloc(struct dnsc_context *dnsc, void *sock, const char *url,
/// generic dnsc handler
void
generic_handle_dnsc_recvfrom(dnsc_answer_request *request,
const struct sockaddr *saddr, const void *buf,
ssize_t sz)
__attribute__((unused))
const struct sockaddr *saddr,
const void *buf, ssize_t sz)
{
// llarp::LogInfo("got a response, udp user is ", udp->user);
unsigned char *castBuf = (unsigned char *)buf;
char *const castBufc = (char *const)buf;
unsigned char *castBuf = (unsigned char *)buf;
const char *const castBufc = (const char *)buf;
// auto buffer = llarp::StackBuffer< decltype(castBuf) >(castBuf);
dns_msg_header *hdr = decode_hdr((const char *)castBuf);
@ -728,7 +729,7 @@ llarp_dnsc_init(struct dnsc_context *const dnsc,
}
bool
llarp_dnsc_stop(struct dnsc_context *const dnsc)
llarp_dnsc_stop(__attribute__((unused)) struct dnsc_context *const dnsc)
{
// delete(sockaddr_in *)dnsc->server; // deallocation
return true;

View File

@ -387,8 +387,8 @@ handle_dnsc_result(dnsc_answer_request *client_request)
// our generic version
void
handle_recvfrom(const char *buffer, ssize_t nbytes, const struct sockaddr *from,
dnsd_question_request *request)
handle_recvfrom(const char *buffer, __attribute__((unused)) ssize_t nbytes,
const struct sockaddr *from, dnsd_question_request *request)
{
const size_t HDR_OFFSET = 12;
const char *p_buffer = buffer;

View File

@ -317,7 +317,9 @@ namespace llarp
read(void* buf, size_t sz) = 0;
virtual int
sendto(const sockaddr* dst, const void* data, size_t sz)
sendto(__attribute__((unused)) const sockaddr* dst,
__attribute__((unused)) const void* data,
__attribute__((unused)) size_t sz)
{
return -1;
};

View File

@ -181,7 +181,9 @@ namespace llarp
};
int
sendto(const sockaddr* to, const void* data, size_t sz)
sendto(__attribute__((unused)) const sockaddr* to,
__attribute__((unused)) const void* data,
__attribute__((unused)) size_t sz)
{
return -1;
}

View File

@ -167,12 +167,12 @@ 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)
{
llarp::LogWarn("recvfrom failed");
return -1;
}
if(ret > sz)
if(static_cast< size_t >(ret) > sz)
{
llarp::LogWarn("ret > sz");
return -1;
@ -226,7 +226,9 @@ namespace llarp
, tunif(tuntap_init()){};
int
sendto(const sockaddr* to, const void* data, size_t sz)
sendto(__attribute__((unused)) const sockaddr* to,
__attribute__((unused)) const void* data,
__attribute__((unused)) size_t sz)
{
return -1;
}
@ -269,9 +271,9 @@ namespace llarp
read(void* buf, size_t sz)
{
#ifdef __APPLE__
const size_t offset = 4;
const ssize_t offset = 4;
#else
const size_t offset = 0;
const ssize_t offset = 0;
#endif
ssize_t ret = tuntap_read(tunif, buf, sz);
if(ret > offset && t->recvpkt)

View File

@ -51,7 +51,8 @@ namespace llarp
}
bool
ExitInfo::DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf)
ExitInfo::DecodeKey(__attribute__((unused)) llarp_buffer_t k,
__attribute__((unused)) llarp_buffer_t* buf)
{
bool read = false;
// TODO: implement me

View File

@ -457,7 +457,7 @@ namespace llarp
}
void
TunEndpoint::TickTun(llarp_time_t now)
TunEndpoint::TickTun(__attribute__((unused)) llarp_time_t now)
{
// called in the isolated thread
}

View File

@ -91,9 +91,9 @@ namespace llarp
}
static void
checksumDstIPv4TCP(byte_t *pld, size_t psz, size_t fragoff,
size_t chksumoff, nuint32_t oSrcIP, nuint32_t oDstIP,
nuint32_t nSrcIP, nuint32_t nDstIP)
checksumDstIPv4TCP(byte_t *pld, __attribute__((unused)) size_t psz,
size_t fragoff, size_t chksumoff, nuint32_t oSrcIP,
nuint32_t oDstIP, nuint32_t nSrcIP, nuint32_t nDstIP)
{
if(fragoff > chksumoff)
return;
@ -110,9 +110,9 @@ namespace llarp
}
static void
checksumDstIPv4UDP(byte_t *pld, size_t psz, size_t fragoff,
nuint32_t oSrcIP, nuint32_t oDstIP, nuint32_t nSrcIP,
nuint32_t nDstIP)
checksumDstIPv4UDP(byte_t *pld, __attribute__((unused)) size_t psz,
size_t fragoff, nuint32_t oSrcIP, nuint32_t oDstIP,
nuint32_t nSrcIP, nuint32_t nDstIP)
{
if(fragoff > 6)
return;
@ -179,8 +179,9 @@ namespace llarp
}
static void
checksumSrcIPv4TCP(byte_t *pld, size_t psz, size_t fragoff,
size_t chksumoff, nuint32_t oSrcIP, nuint32_t oDstIP)
checksumSrcIPv4TCP(byte_t *pld, __attribute__((unused)) size_t psz,
size_t fragoff, size_t chksumoff, nuint32_t oSrcIP,
nuint32_t oDstIP)
{
if(fragoff > chksumoff)
return;
@ -198,8 +199,8 @@ namespace llarp
}
static void
checksumSrcIPv4UDP(byte_t *pld, size_t psz, size_t fragoff,
nuint32_t oSrcIP, nuint32_t oDstIP)
checksumSrcIPv4UDP(byte_t *pld, __attribute__((unused)) size_t psz,
size_t fragoff, nuint32_t oSrcIP, nuint32_t oDstIP)
{
if(fragoff > 6)
return;

View File

@ -7,7 +7,7 @@ namespace llarp
namespace curvecp
{
std::unique_ptr< ILinkLayer >
NewServer(llarp_router* r)
NewServer(__attribute__((unused)) llarp_router* r)
{
return nullptr;
}

View File

@ -227,7 +227,7 @@ namespace llarp
}
void
TickImpl(llarp_time_t now)
TickImpl(__attribute__((unused)) llarp_time_t now)
{
}

View File

@ -17,7 +17,9 @@ namespace llarp
} // namespace llarp
void
llarp_mem_slab(struct llarp_alloc *mem, uint32_t *buf, size_t sz)
llarp_mem_slab(__attribute__((unused)) struct llarp_alloc *mem,
__attribute__((unused)) uint32_t *buf,
__attribute__((unused)) size_t sz)
{
// not implemented
abort();

View File

@ -977,7 +977,8 @@ namespace llarp
}
bool
IsBogonRange(const in6_addr& host, const in6_addr& netmask)
IsBogonRange(__attribute__((unused)) const in6_addr& host,
__attribute__((unused)) const in6_addr& netmask)
{
// TODO: implement me
return true;

View File

@ -153,7 +153,7 @@ namespace llarp
PathContext::GetByUpstream(const RouterID& remote, const PathID_t& id)
{
auto own = MapGet(m_OurPaths, id,
[](const PathSet* s) -> bool {
[](__attribute__((unused)) const PathSet* s) -> bool {
// TODO: is this right?
return true;
},
@ -559,16 +559,18 @@ namespace llarp
bool
Path::HandlePathTransferMessage(
const llarp::routing::PathTransferMessage* msg, llarp_router* r)
__attribute__((unused)) const llarp::routing::PathTransferMessage* msg,
__attribute__((unused)) llarp_router* r)
{
llarp::LogWarn("unwarrented path transfer message on tx=", TXID(),
llarp::LogWarn("unwarranted path transfer message on tx=", TXID(),
" rx=", RXID());
return false;
}
bool
Path::HandleDataDiscardMessage(
const llarp::routing::DataDiscardMessage* msg, llarp_router* r)
const llarp::routing::DataDiscardMessage* msg,
__attribute__((unused)) llarp_router* r)
{
if(m_DropHandler)
return m_DropHandler(this, msg->P, msg->S);
@ -577,7 +579,8 @@ namespace llarp
bool
Path::HandlePathConfirmMessage(
const llarp::routing::PathConfirmMessage* msg, llarp_router* r)
__attribute__((unused)) const llarp::routing::PathConfirmMessage* msg,
llarp_router* r)
{
auto now = r->Now();
if(_status == ePathBuilding)

View File

@ -10,7 +10,8 @@ namespace llarp
}
bool
PoW::DecodeKey(llarp_buffer_t k, llarp_buffer_t* val)
PoW::DecodeKey(__attribute__((unused)) llarp_buffer_t k,
__attribute__((unused)) llarp_buffer_t* val)
{
// TODO: implement me
return false;
@ -53,4 +54,4 @@ namespace llarp
return true;
}
} // namespace llarp
} // namespace llarp

View File

@ -875,7 +875,8 @@ llarp_router::InitServiceNode()
}
void
llarp_router::ConnectAll(void *user, uint64_t orig, uint64_t left)
llarp_router::ConnectAll(void *user, __attribute__((unused)) uint64_t orig,
uint64_t left)
{
if(left)
return;
@ -916,7 +917,7 @@ llarp_router::ConnectToRandomRouters(int want)
}
bool
llarp_router::ReloadConfig(const llarp_config *conf)
llarp_router::ReloadConfig(__attribute__((unused)) const llarp_config *conf)
{
return true;
}

View File

@ -22,7 +22,7 @@ namespace llarp
}
void
PopulateReqHeaders(abyss::http::Headers_t& hdr)
PopulateReqHeaders(__attribute__((unused)) abyss::http::Headers_t& hdr)
{
}
};
@ -43,7 +43,8 @@ namespace llarp
}
bool
HandleResponse(const ::abyss::http::RPC_Response& response)
HandleResponse(__attribute__((unused))
const ::abyss::http::RPC_Response& response)
{
handler(pk, true);
return true;
@ -139,7 +140,9 @@ namespace llarp
}
bool
HandleJSONRPC(Method_t method, const Params& params, Response& response)
HandleJSONRPC(Method_t method,
__attribute__((unused)) const Params& params,
Response& response)
{
if(method == "llarp.admin.link.neighboors")
{
@ -198,9 +201,10 @@ namespace llarp
#else
struct ServerImpl
{
ServerImpl(llarp_router* r){};
ServerImpl(__attribute__((unused)) llarp_router* r){};
bool
Start(const std::string& addr)
Start(__attribute__((unused)) const std::string& addr)
{
return true;
}
@ -208,7 +212,7 @@ namespace llarp
struct CallerImpl
{
CallerImpl(llarp_router* r)
CallerImpl(__attribute__((unused)) llarp_router* r)
{
}

View File

@ -135,7 +135,10 @@ namespace llarp
// HiddenServiceEndpoint(tunEndpoint, callback, addr,
// tunEndpoint->GenTXID());
return tunEndpoint->EnsurePathToService(
addr, [](Address addr, void *ctx) {}, 10000);
addr,
[](__attribute__((unused)) Address addr,
__attribute__((unused)) void *ctx) {},
10000);
}
huint32_t

View File

@ -180,7 +180,10 @@ namespace llarp
if(!HasPathToService(addr))
{
if(!EnsurePathToService(
addr, [](Address addr, OutboundContext* ctx) {}, 10000))
addr,
[](__attribute__((unused)) Address addr,
__attribute__((unused)) OutboundContext* ctx) {},
10000))
{
llarp::LogWarn("failed to ensure path to ", addr);
}
@ -780,7 +783,8 @@ namespace llarp
}
bool
Endpoint::HandleDataMessage(const PathID_t& src, ProtocolMessage* msg)
Endpoint::HandleDataMessage(__attribute__((unused)) const PathID_t& src,
ProtocolMessage* msg)
{
msg->sender.UpdateAddr();
PutIntroFor(msg->tag, msg->introReply);
@ -834,7 +838,8 @@ namespace llarp
}
bool
Endpoint::CheckPathIsDead(path::Path* p, llarp_time_t latency)
Endpoint::CheckPathIsDead(__attribute__((unused)) path::Path* p,
llarp_time_t latency)
{
if(latency >= m_MinPathLatency)
{
@ -874,7 +879,9 @@ namespace llarp
bool
Endpoint::EnsurePathToService(const Address& remote, PathEnsureHook hook,
llarp_time_t timeoutMS, bool randomPath)
__attribute__((unused))
llarp_time_t timeoutMS,
bool randomPath)
{
path::Path* path = nullptr;
if(randomPath)
@ -991,7 +998,8 @@ namespace llarp
}
bool
Endpoint::OutboundContext::OnIntroSetUpdate(const Address& addr,
Endpoint::OutboundContext::OnIntroSetUpdate(__attribute__((unused))
const Address& addr,
const IntroSet* i,
const RouterID& endpoint)
{
@ -1371,6 +1379,7 @@ namespace llarp
void
Endpoint::OutboundContext::AsyncGenIntro(llarp_buffer_t payload,
__attribute__((unused))
ProtocolType t)
{
auto path = m_PathSet->GetPathByRouter(remoteIntro.router);

View File

@ -385,7 +385,7 @@ namespace llarp
bool
ProtocolFrame::HandleMessage(llarp::routing::IMessageHandler* h,
llarp_router* r) const
__attribute__((unused)) llarp_router* r) const
{
return h->HandleHiddenServiceFrame(this);
}

View File

@ -193,8 +193,9 @@ struct llarp_threadpool
std::queue< llarp::thread::Pool::Job_t > jobs;
llarp_threadpool(int workers, const char *name, bool isolate,
setup_net_func setup = nullptr,
run_main_func runmain = nullptr, void *user = nullptr)
__attribute__((unused)) setup_net_func setup = nullptr,
__attribute__((unused)) run_main_func runmain = nullptr,
__attribute__((unused)) void *user = nullptr)
{
#ifdef NET_ISOLATION_SUPPORTED
if(isolate)
@ -245,7 +246,7 @@ llarp_threadpool_join(struct llarp_threadpool *pool)
}
void
llarp_threadpool_start(struct llarp_threadpool *pool)
llarp_threadpool_start(__attribute__((unused)) struct llarp_threadpool *pool)
{ /** no op */
}

View File

@ -133,15 +133,17 @@ namespace llarp
bool
TransitHop::HandlePathConfirmMessage(
const llarp::routing::PathConfirmMessage* msg, llarp_router* r)
__attribute__((unused)) const llarp::routing::PathConfirmMessage* msg,
__attribute__((unused)) llarp_router* r)
{
llarp::LogWarn("unwarrented path confirm message on ", info);
llarp::LogWarn("unwarranted path confirm message on ", info);
return false;
}
bool
TransitHop::HandleDataDiscardMessage(
const llarp::routing::DataDiscardMessage* msg, llarp_router* r)
__attribute__((unused)) const llarp::routing::DataDiscardMessage* msg,
__attribute__((unused)) llarp_router* r)
{
llarp::LogWarn("unwarranted path data discard message on ", info);
return false;

View File

@ -29,7 +29,7 @@ struct AbyssTestBase : public ::testing::Test
}
static void
CancelIt(void* u, uint64_t orig, uint64_t left)
CancelIt(void* u, __attribute__((unused)) uint64_t orig, uint64_t left)
{
if(left)
return;
@ -97,12 +97,13 @@ struct ClientHandler : public abyss::http::IRPCClientHandler
}
void
PopulateReqHeaders(abyss::http::Headers_t& hdr)
PopulateReqHeaders(__attribute__((unused)) abyss::http::Headers_t& hdr)
{
}
bool
HandleResponse(const abyss::http::RPC_Response& response)
HandleResponse(__attribute__((unused))
const abyss::http::RPC_Response& response)
{
test->Stop();
return true;
@ -118,7 +119,8 @@ struct ServerHandler : public abyss::httpd::IRPCHandler
}
bool
HandleJSONRPC(Method_t method, const Params& params, Response& response)
HandleJSONRPC(Method_t method, __attribute__((unused)) const Params& params,
__attribute__((unused)) Response& response)
{
test->AssertMethod(method);
test->called = true;

View File

@ -1,47 +1,47 @@
#include <gtest/gtest.h>
#include <llarp.h> // for llarp_main_init
#include <llarp/logic.h> // for threadpool/llarp_logic
#include <llarp.h> // for llarp_main_init
#include <llarp/logic.h> // for threadpool/llarp_logic
#include "llarp/net.hpp" // for llarp::Addr
#include "llarp/dns.hpp"
#include "llarp/dnsc.hpp"
struct DNSTest : public ::testing::Test
{
unsigned char buf[47] = {
0x00,0x01, // first short
0x01,0x00,0x00, // combined fields
0x01,0x00,0x01,0x00,0x00,0x00,0x00, // last 4 shorts
// question (is 18 bytes long)
0x04, // 4 letters
0x6C,0x6F,0x6B,0x69, // loki
0x07, // 7 letters
0x6E,0x65,0x74,0x77,0x6F,0x72,0x6B, // network
0x00, // end
0x00,0x01, // type (a 1/ptr 12)
0x00,0x01, // class (1 = internet)
// 30th byte
// Answer (is 16 bytes long)
0xc0, 0x0c, 0x00, 0x01, 0x00, 0x01, // name, type, class
0x00, 0x00, 0x08, 0x4b, // ttl 2123
0x00, 0x04, // rdLen
0x45, 0x10, 0xd1, 0x02, // an ip address
// extra
0x00 // null terminator (probably don't need this, just added it)
0x00, 0x01, // first short
0x01, 0x00, 0x00, // combined fields
0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, // last 4 shorts
// question (is 18 bytes long)
0x04, // 4 letters
0x6C, 0x6F, 0x6B, 0x69, // loki
0x07, // 7 letters
0x6E, 0x65, 0x74, 0x77, 0x6F, 0x72, 0x6B, // network
0x00, // end
0x00, 0x01, // type (a 1/ptr 12)
0x00, 0x01, // class (1 = internet)
// 30th byte
// Answer (is 16 bytes long)
0xc0, 0x0c, 0x00, 0x01, 0x00, 0x01, // name, type, class
0x00, 0x00, 0x08, 0x4b, // ttl 2123
0x00, 0x04, // rdLen
0x45, 0x10, 0xd1, 0x02, // an ip address
// extra
0x00 // null terminator (probably don't need this, just added it)
};
DNSTest()
{
}
void
SetUp()
{
llarp::SetLogLevel(llarp::eLogNone); // turn off logging to keep gtest output pretty
llarp::SetLogLevel(
llarp::eLogNone); // turn off logging to keep gtest output pretty
/*
const char *url = "loki.network";
struct dns_query *packet = build_dns_packet((char *)url, 1, 1); // id 1, type 1 (A)
struct dns_query *packet = build_dns_packet((char *)url, 1, 1); // id 1,
type 1 (A)
unsigned int length = packet->length;
char *buffer = (char *)packet->request;
@ -52,7 +52,6 @@ struct DNSTest : public ::testing::Test
printf("Generated [%u] bytes: [%s]\n", length, hex_buffer);
*/
}
};
// test puts/gets
@ -60,8 +59,8 @@ struct DNSTest : public ::testing::Test
TEST_F(DNSTest, TestDecodeDNSstring)
{
char *buffer = (char *)this->buf;
buffer += 12; // skip header
uint32_t pos = 0;
buffer += 12; // skip header
uint32_t pos = 0;
std::string res = getDNSstring(buffer, &pos);
ASSERT_TRUE(res == "loki.network");
}
@ -71,16 +70,17 @@ TEST_F(DNSTest, TestCodeDomain)
char buffer[16];
llarp::Zero(buffer, 16);
char *write_buffer = buffer;
std::string url = "bob.com";
std::string url = "bob.com";
code_domain(write_buffer, url);
char hex_buffer[16 * 3 + 1];
hex_buffer[16 * 3] = 0;
for(unsigned int j = 0; j < 16; j++)
sprintf(&hex_buffer[3 * j], "%02X ", ((const char *)buffer)[j]);
//printf("first 16 [%s]", hex_buffer);
// printf("first 16 [%s]", hex_buffer);
std::string expected_result = "03 62 6F 62 03 63 6F 6D 00 00 00 00 00 00 00 00 ";
std::string expected_result =
"03 62 6F 62 03 63 6F 6D 00 00 00 00 00 00 00 00 ";
ASSERT_TRUE(hex_buffer == expected_result);
}
@ -125,12 +125,12 @@ TEST_F(DNSTest, TestDecodeHdr)
TEST_F(DNSTest, TestDecodeQuestion)
{
char *buffer = (char *)this->buf;
buffer += 12; // skip header
uint32_t pos = 0;
buffer += 12; // skip header
uint32_t pos = 0;
dns_msg_question *question = decode_question(buffer, &pos);
//printf("name[%s]", question->name.c_str());
//printf("type[%d]", question->type);
//printf("qClass[%d]", question->qClass);
// printf("name[%s]", question->name.c_str());
// printf("type[%d]", question->type);
// printf("qClass[%d]", question->qClass);
std::string url = "loki.network";
ASSERT_TRUE(question->name == url);
ASSERT_TRUE(question->type == 1);
@ -139,10 +139,10 @@ TEST_F(DNSTest, TestDecodeQuestion)
TEST_F(DNSTest, TestDecodeAnswer)
{
const char * const buffer = (const char * const)this->buf;
uint32_t pos = 12;
std::string url = "loki.network";
pos += url.length() + 2 + 4; // skip question (string + 2 shorts)
const char *const buffer = (const char *)this->buf;
uint32_t pos = 12;
std::string url = "loki.network";
pos += url.length() + 2 + 4; // skip question (string + 2 shorts)
dns_msg_answer *answer = decode_answer(buffer, &pos);
/*
@ -150,7 +150,8 @@ TEST_F(DNSTest, TestDecodeAnswer)
printf("aClass[%d]", answer->aClass);
printf("ttl[%d]", answer->ttl);
printf("rdLen[%d]", answer->rdLen);
printf("[%hhu].[%hhu].[%hhu].[%hhu]", answer->rData[0], answer->rData[1], answer->rData[2], answer->rData[3]);
printf("[%hhu].[%hhu].[%hhu].[%hhu]", answer->rData[0], answer->rData[1],
answer->rData[2], answer->rData[3]);
*/
ASSERT_TRUE(answer->name == url);
ASSERT_TRUE(answer->type == 1);
@ -191,5 +192,4 @@ TEST_F(DNSTest, handleDNSrecvFrom)
llarp_handle_dns_recvfrom((llarp_udp_io *)&udp, &addr, buffer, sz);
// llarp_handle_dnsc_recvfrom
// llarp_handle_dnsd_recvfrom
}

View File

@ -1,19 +1,22 @@
#include <gtest/gtest.h>
#include <llarp.h> // for llarp_main_init
#include <llarp/logic.h> // for threadpool/llarp_logic
#include <llarp.h> // for llarp_main_init
#include <llarp/logic.h> // for threadpool/llarp_logic
#include "llarp/net.hpp" // for llarp::Addr
#include "llarp/dnsd.hpp"
unsigned int g_length = 0;
std::string g_result = "";
std::string g_result = "";
ssize_t test_sendto_dns_hook(void *sock, const struct sockaddr *from,
const void *buffer, size_t length) {
ssize_t
test_sendto_dns_hook(__attribute__((unused)) void *sock,
__attribute__((unused)) const struct sockaddr *from,
const void *buffer, size_t length)
{
char hex_buffer[length * 3 + 1];
hex_buffer[length * 3] = 0;
for(unsigned int j = 0; j < length; j++)
sprintf(&hex_buffer[3 * j], "%02X ", ((const char *)buffer)[j]);
//printf("Got [%zu] bytes: [%s]\n", length, hex_buffer);
// printf("Got [%zu] bytes: [%s]\n", length, hex_buffer);
g_result = hex_buffer;
g_length = length;
return length;
@ -22,34 +25,36 @@ ssize_t test_sendto_dns_hook(void *sock, const struct sockaddr *from,
struct llarpDNSdTest : public ::testing::Test
{
dnsd_question_request test_request;
llarpDNSdTest()
{
}
void
SetUp()
{
test_request.id = 0;
test_request.llarp = true; // we don't care about raw atm
test_request.from = nullptr;
test_request.context = nullptr;
test_request.sendto_hook = &test_sendto_dns_hook;
test_request.id = 0;
test_request.llarp = true; // we don't care about raw atm
test_request.from = nullptr;
test_request.context = nullptr;
test_request.sendto_hook = &test_sendto_dns_hook;
test_request.question.name = "loki.network";
test_request.question.type = 1;
test_request.question.qClass = 1;
g_result = ""; // reset test global
g_length = 0;
llarp::SetLogLevel(llarp::eLogNone); // turn off logging to keep gtest output pretty
g_result = ""; // reset test global
g_length = 0;
llarp::SetLogLevel(
llarp::eLogNone); // turn off logging to keep gtest output pretty
}
};
TEST_F(llarpDNSdTest, TestNxDomain)
{
write404_dnss_response(nullptr, &test_request);
ASSERT_TRUE(g_length == 55);
std::string expected_output = "00 00 FFF03 00 01 00 01 00 00 00 00 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 01 00 01 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 01 00 01 00 00 00 01 00 01 00 ";
std::string expected_output =
"00 00 FFF03 00 01 00 01 00 00 00 00 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 "
"6B 00 00 01 00 01 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 01 00 01 "
"00 00 00 01 00 01 00 ";
ASSERT_TRUE(expected_output == g_result);
}
@ -57,20 +62,25 @@ TEST_F(llarpDNSdTest, TestAResponse)
{
llarp::huint32_t hostRes;
llarp::Zero(&hostRes.h, sizeof(uint32_t));
//sockaddr hostRes;
//llarp::Zero(&hostRes, sizeof(sockaddr));
// sockaddr hostRes;
// llarp::Zero(&hostRes, sizeof(sockaddr));
writesend_dnss_response(&hostRes, nullptr, &test_request);
ASSERT_TRUE(g_length == 58);
std::string expected_output = "00 00 FFF00 00 01 00 01 00 00 00 00 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 01 00 01 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 01 00 01 00 00 00 01 00 04 00 00 00 00 ";
std::string expected_output =
"00 00 FFF00 00 01 00 01 00 00 00 00 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 "
"6B 00 00 01 00 01 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 01 00 01 "
"00 00 00 01 00 04 00 00 00 00 ";
ASSERT_TRUE(expected_output == g_result);
}
TEST_F(llarpDNSdTest, TestPTRResponse)
{
writesend_dnss_revresponse("loki.network", nullptr,
&test_request);
writesend_dnss_revresponse("loki.network", nullptr, &test_request);
ASSERT_TRUE(g_length == 68);
std::string expected_output = "00 00 FFF00 00 01 00 01 00 00 00 00 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 01 00 01 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 01 00 01 00 00 00 01 00 0E 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 ";
std::string expected_output =
"00 00 FFF00 00 01 00 01 00 00 00 00 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 "
"6B 00 00 01 00 01 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 01 00 01 "
"00 00 00 01 00 0E 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 ";
ASSERT_TRUE(expected_output == g_result);
}
@ -78,7 +88,12 @@ TEST_F(llarpDNSdTest, TestCname)
{
writecname_dnss_response("test.cname", nullptr, &test_request);
ASSERT_TRUE(g_length == 122);
std::string expected_output = "00 00 FFF00 00 01 00 01 00 01 00 01 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 01 00 01 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 05 00 01 00 00 00 01 00 0C 04 74 65 73 74 05 63 6E 61 6D 65 00 04 74 65 73 74 05 63 6E 61 6D 65 00 00 02 00 01 00 00 00 01 00 0A 03 6E 73 31 04 6C 6F 6B 69 00 03 6E 73 31 04 6C 6F 6B 69 00 00 01 00 01 00 00 00 01 00 04 7F 00 00 01 ";
std::string expected_output =
"00 00 FFF00 00 01 00 01 00 01 00 01 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 "
"6B 00 00 01 00 01 04 6C 6F 6B 69 07 6E 65 74 77 6F 72 6B 00 00 05 00 01 "
"00 00 00 01 00 0C 04 74 65 73 74 05 63 6E 61 6D 65 00 04 74 65 73 74 05 "
"63 6E 61 6D 65 00 00 02 00 01 00 00 00 01 00 0A 03 6E 73 31 04 6C 6F 6B "
"69 00 03 6E 73 31 04 6C 6F 6B 69 00 00 01 00 01 00 00 00 01 00 04 7F 00 "
"00 01 ";
ASSERT_TRUE(expected_output == g_result);
}

View File

@ -44,7 +44,7 @@ namespace cpp17
namespace filesystem
{
bool
create_directory(const path& s, std::error_code& ec)
create_directory(const path& s, __attribute__((unused)) std::error_code& ec)
{
if(s.empty())
{
@ -55,7 +55,8 @@ namespace cpp17
}
bool
create_directories(const path& s, std::error_code& ec)
create_directories(const path& s,
__attribute__((unused)) std::error_code& ec)
{
path p = s.parent_path();

View File

@ -292,14 +292,8 @@ namespace cpp17
// is this right
directory_iterator::directory_iterator(directory_iterator const& src)
: pimpl(new impl(src.pimpl->p.c_str()))
{
// printf("directory_iterator::directory_iterator copy - pimpl[%x]
// from[%s]\n", pimpl, src->path().c_str());
if(pimpl)
{
// delete pimpl;
}
pimpl = new impl(src.pimpl->p.c_str());
pimpl->seek(src.pimpl->pos);
}

View File

@ -182,7 +182,7 @@ namespace cpp17
}
bool
exists(const path& p, std::error_code& ec)
exists(const path& p, __attribute__((unused)) std::error_code& ec)
{
return exists(status(p));
}

View File

@ -45,7 +45,8 @@
#define UTUN_OPT_IFNAME 2
static int
fucky_tuntap_sys_start(struct device *dev, int mode, int tun)
fucky_tuntap_sys_start(struct device *dev, __attribute__((unused)) int mode,
int tun)
{
uint32_t namesz = IFNAMSIZ;
char name[IFNAMSIZ + 1];
@ -197,7 +198,9 @@ tuntap_sys_set_ipv4(struct device *dev, t_tun_in_addr *s4, uint32_t bits)
}
int
tuntap_sys_set_descr(struct device *dev, const char *descr, size_t len)
tuntap_sys_set_descr(__attribute__((unused)) struct device *dev,
__attribute__((unused)) const char *descr,
__attribute__((unused)) size_t len)
{
tuntap_log(TUNTAP_LOG_NOTICE,
"Your system does not support tuntap_set_descr()");

View File

@ -360,6 +360,7 @@ tuntap_set_debug(struct device *dev, int set)
}
return 0;
#else
(void)set;
tuntap_log(TUNTAP_LOG_NOTICE,
"Your system does not support tuntap_set_debug()");
return -1;

View File

@ -149,6 +149,7 @@ extern "C"
return -1;
}
#else
(void)daddr;
return tuntap_sys_set_ipv4(dev, &baddr4, mask);
#endif
}