Merge remote-tracking branch 'origin/master' into ipv6-tun

pull/686/head
Jeff Becker 5 years ago
commit 4e355327d8
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -2,16 +2,21 @@ add_definitions(-DUNIX)
add_definitions(-DPOSIX) add_definitions(-DPOSIX)
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(FS_LIB stdc++fs)
get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-linux.c ABSOLUTE) get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-linux.c ABSOLUTE)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android") elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android")
set(FS_LIB stdc++fs)
get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-linux.c ABSOLUTE) get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-linux.c ABSOLUTE)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-openbsd.c ${TT_ROOT}/tuntap-unix-bsd.c) set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-openbsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD") elseif (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-netbsd.c ${TT_ROOT}/tuntap-unix-bsd.c) set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-netbsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "DragonFly") elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "DragonFly")
set(FS_LIB c++experimental)
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-freebsd.c ${TT_ROOT}/tuntap-unix-bsd.c) set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-freebsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(FS_LIB stdc++fs)
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-darwin.c ${TT_ROOT}/tuntap-unix-bsd.c) set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-darwin.c ${TT_ROOT}/tuntap-unix-bsd.c)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS") elseif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-sunos.c) set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-sunos.c)
@ -19,7 +24,6 @@ else()
message(FATAL_ERROR "Your operating system is not supported yet") message(FATAL_ERROR "Your operating system is not supported yet")
endif() endif()
set(FS_LIB stdc++fs)
set(EXE_LIBS ${STATIC_LIB} libutp) set(EXE_LIBS ${STATIC_LIB} libutp)

@ -25,18 +25,7 @@ namespace llarp
bool bool
SecretKey::LoadFromFile(const char* fname) SecretKey::LoadFromFile(const char* fname)
{ {
const fs::path fpath = std::string(fname); std::ifstream f(fname, std::ios::in | std::ios::binary);
std::error_code ec;
if(!fs::exists(fpath, ec))
{
return false;
}
auto optional_f = util::OpenFileStream< std::ifstream >(
fpath, std::ios::in | std::ios::binary);
if(!optional_f)
return false;
auto& f = optional_f.value();
if(!f.is_open()) if(!f.is_open())
{ {
return false; return false;
@ -72,15 +61,15 @@ namespace llarp
return false; return false;
} }
const fs::path fpath = std::string(fname); const fs::path fpath = std::string(fname);
auto optional_f = llarp::util::OpenFileStream< std::ofstream >( auto optional_f =
fpath, std::ios::binary | std::ios::out); llarp::util::OpenFileStream< std::ofstream >(fpath, std::ios::binary);
if(!optional_f) if(!optional_f)
return false; return false;
auto& f = optional_f.value(); auto& f = optional_f.value();
if(!f.is_open()) if(!f.is_open())
return false; return false;
f.write((char*)buf.base, buf.cur - buf.base); f.write((char*)buf.base, buf.cur - buf.base);
return true; return f.good();
} }
bool bool

@ -159,9 +159,9 @@ struct llarp_nodedb
static bool static bool
ensure_dir(const char *dir); ensure_dir(const char *dir);
private:
void void
SaveAll() LOCKS_EXCLUDED(access); SaveAll() LOCKS_EXCLUDED(access);
}; };
/// struct for async rc verification /// struct for async rc verification

@ -1361,6 +1361,14 @@ namespace llarp
{ {
dht()->impl->ExploreNetworkVia(dht::Key_t{rc.pubkey}); dht()->impl->ExploreNetworkVia(dht::Key_t{rc.pubkey});
} }
// explore via every conected peer
ForEachPeer([&](ILinkSession *s) {
if(!s->IsEstablished())
return;
const RouterContact rc = s->GetRemoteRC();
if(rc.IsPublicRouter())
dht()->impl->ExploreNetworkVia(dht::Key_t{rc.pubkey});
});
} }
else else
LogError("we have no bootstrap nodes specified"); LogError("we have no bootstrap nodes specified");

@ -3,6 +3,7 @@
#include <util/buffer.hpp> #include <util/buffer.hpp>
#include <util/bencode.h> #include <util/bencode.h>
#include <util/fs.hpp>
#include <util/logger.hpp> #include <util/logger.hpp>
#include <util/mem.hpp> #include <util/mem.hpp>
@ -356,8 +357,12 @@ namespace llarp
return false; return false;
buf.sz = buf.cur - buf.base; buf.sz = buf.cur - buf.base;
{ {
std::ofstream f; const fs::path path = std::string(fpath);
f.open(fpath); auto optional_f =
llarp::util::OpenFileStream< std::ofstream >(path, std::ios::binary);
if(!optional_f)
return false;
auto& f = optional_f.value();
if(!f.is_open()) if(!f.is_open())
return false; return false;
f.write((char*)buf.base, buf.sz); f.write((char*)buf.base, buf.sz);

@ -3,34 +3,60 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <system_error> #include <system_error>
#include <util/logger.hpp>
namespace llarp namespace llarp
{ {
namespace util namespace util
{ {
static std::error_code
errno_error()
{
int e = errno;
errno = 0;
return std::make_error_code(static_cast< std::errc >(e));
}
error_code_t error_code_t
EnsurePrivateFile(fs::path pathname) EnsurePrivateFile(fs::path pathname)
{ {
auto str = pathname.string(); const auto str = pathname.string();
error_code_t ec; errno = 0;
error_code_t ec = errno_error();
if(fs::exists(pathname, ec)) // file exists if(fs::exists(pathname, ec)) // file exists
{ {
fs::permissions(pathname, auto st = fs::status(pathname, ec);
~fs::perms::group_all | ~fs::perms::others_all if(ec)
| fs::perms::owner_read | fs::perms::owner_write, return ec;
ec); auto perms = st.permissions();
if((perms & fs::perms::others_exec) != fs::perms::none)
perms ^= fs::perms::others_exec;
if((perms & fs::perms::others_write) != fs::perms::none)
perms ^= fs::perms::others_write;
if((perms & fs::perms::others_write) != fs::perms::none)
perms ^= fs::perms::others_write;
if((perms & fs::perms::group_read) != fs::perms::none)
perms ^= fs::perms::group_read;
if((perms & fs::perms::others_read) != fs::perms::none)
perms ^= fs::perms::others_read;
if((perms & fs::perms::owner_exec) != fs::perms::none)
perms ^= fs::perms::owner_exec;
fs::permissions(pathname, perms, ec);
if(ec)
llarp::LogError("failed to set permissions on ", pathname);
} }
else if(!ec) // file is not there else if(!ec) // file is not there
{ {
int fd = ::open(str.c_str(), O_WRONLY | O_CREAT, 0600); errno = 0;
int e = errno; int fd = ::open(str.c_str(), O_RDWR | O_CREAT, 0600);
ec = errno_error();
if(fd != -1) if(fd != -1)
{ {
::close(fd); ::close(fd);
} }
ec = std::error_code(e, std::generic_category());
errno = 0;
} }
if(ec)
llarp::LogError("failed to ensure ", str, ", ", ec.message());
return ec; return ec;
} }
} // namespace util } // namespace util

@ -35,11 +35,10 @@ namespace llarp
OpenFileStream(fs::path pathname, std::ios::openmode mode) OpenFileStream(fs::path pathname, std::ios::openmode mode)
{ {
if(EnsurePrivateFile(pathname)) if(EnsurePrivateFile(pathname))
{ return {};
std::string f = pathname.string();
return T{pathname, mode}; std::string f = pathname.string();
} return T{pathname, mode};
return {};
} }
using PathVisitor = std::function< bool(const fs::path &) >; using PathVisitor = std::function< bool(const fs::path &) >;

Loading…
Cancel
Save