pull/230/head
Ryan Tharp 5 years ago
commit 1ba5b75082

@ -150,6 +150,7 @@ main(int argc, char *argv[])
fs::path basepath = homedir / fs::path(".lokinet");
fs::path fpath = basepath / "lokinet.ini";
llarp::LogDebug("Find or create ", basepath.string());
std::error_code ec;
// These paths are guaranteed to exist - $APPDATA or $HOME
// so only create .lokinet/*
@ -170,8 +171,12 @@ main(int argc, char *argv[])
}
if(genconfigOnly)
{
return 0;
}
// this is important, can downgrade from Info though
llarp::LogInfo("Using config file: ", conffname);
ctx = llarp_main_init(conffname.c_str(), multiThreaded);
int code = 1;
if(ctx)

@ -343,8 +343,8 @@ namespace tl
using enable_assign_forward = detail::enable_if_t<
!std::is_same< optional< T >, detail::decay_t< U > >::value
&& !detail::conjunction<
std::is_scalar< T >,
std::is_same< T, detail::decay_t< U > > >::value
std::is_scalar< T >,
std::is_same< T, detail::decay_t< U > > >::value
&& std::is_constructible< T, U >::value
&& std::is_assignable< T &, U >::value >;
@ -465,7 +465,7 @@ namespace tl
0))::value &&detail::swap_adl_tests::
is_std_swap_noexcept< T >::value)
|| (!decltype(detail::swap_adl_tests::uses_std< T, U >(
0))::value &&detail::swap_adl_tests::
0))::value &&detail::swap_adl_tests::
is_adl_swap_noexcept< T, U >::value)) >
{
};

@ -72,6 +72,8 @@ llarp_ensure_config(const char *fname, const char *basedir, bool overwrite,
#endif
}
llarp::LogInfo("Attempting to create config file ", fname);
// abort if client.ini already exists
if(!asRouter)
{

@ -4,12 +4,12 @@
//
// Next default values for new objects
//
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

@ -143,13 +143,54 @@ llarp_ev_udp_sendto(struct llarp_udp_io *udp, const sockaddr *to,
}
#ifndef _WIN32
#include <string.h>
bool
llarp_ev_add_tun(struct llarp_ev_loop *loop, struct llarp_tun_io *tun)
{
if(strcmp(tun->ifaddr, "") == 0 || strcmp(tun->ifaddr, "auto"))
{
std::string ifaddr = llarp::findFreePrivateRange();
std::string addr;
auto pos = ifaddr.find("/");
if(pos == std::string::npos)
{
llarp::LogWarn("Auto ifaddr didn't return a netmask: ", ifaddr);
return false;
}
int num;
std::string part = ifaddr.substr(pos + 1);
#if defined(ANDROID) || defined(RPI)
num = atoi(part.c_str());
#else
num = std::stoi(part);
#endif
if(num <= 0)
{
llarp::LogError("bad ifaddr netmask value: ", ifaddr);
return false;
}
tun->netmask = num;
addr = ifaddr.substr(0, pos);
strcpy(tun->ifaddr, addr.c_str());
llarp::LogInfo("IfAddr autodetect: ", tun->ifaddr, "/", tun->netmask);
}
if(strcmp(tun->ifname, "") == 0 || strcmp(tun->ifname, "auto"))
{
strcpy(tun->ifname, llarp::findFreeLokiTunIfName().c_str());
llarp::LogInfo("IfName autodetect: ", tun->ifname);
}
llarp::LogDebug("Tun Interface will use the following settings:");
llarp::LogDebug("IfAddr: ", tun->ifaddr);
llarp::LogDebug("IfName: ", tun->ifname);
llarp::LogDebug("IfNMsk: ", tun->netmask);
auto dev = loop->create_tun(tun);
tun->impl = dev;
if(dev)
{
return loop->add_ev(dev, false);
}
llarp::LogWarn("Loop could not create tun");
return false;
}
#else

@ -286,17 +286,33 @@ namespace llarp
setup()
{
llarp::LogDebug("set up tunif");
if(tuntap_start(tunif, TUNTAP_MODE_TUNNEL, TUNTAP_ID_ANY) == -1)
if(tuntap_start(tunif, TUNTAP_MODE_TUNNEL, 0) == -1)
{
llarp::LogWarn("Can't set tuntap to tunnel mode");
return false;
}
if(tuntap_up(tunif) == -1)
{
llarp::LogWarn("Can't bring up tuntap");
return false;
}
if(tuntap_set_ifname(tunif, t->ifname) == -1)
{
llarp::LogInfo("Can't set tun interface name to ", tunif->if_name);
return false;
llarp::LogInfo("set ", tunif->if_name, " to use address ", t->ifaddr);
}
// currently trying to set
llarp::LogInfo("setting ", tunif->if_name, " to use address ", t->ifaddr);
if(tuntap_set_ip(tunif, t->ifaddr, t->ifaddr, t->netmask) == -1)
{
llarp::LogWarn("Can't set tuntap ip on ", tunif->if_name, " to ",
t->ifaddr, " netmask ", t->netmask);
return false;
}
fd = tunif->tun_fd;
return fd != -1;
}
@ -370,6 +386,7 @@ struct llarp_kqueue_loop : public llarp_ev_loop
llarp::tun* t = new llarp::tun(tun, this);
if(t->setup())
return t;
llarp::LogWarn("Could not set up tun");
delete t;
return nullptr;
}
@ -432,13 +449,11 @@ struct llarp_kqueue_loop : public llarp_ev_loop
llarp::ev_io* ev = static_cast< llarp::ev_io* >(events[idx].udata);
if(ev)
{
if(events[idx].filter & EVFILT_WRITE)
ev->flush_write_buffers(events[idx].data);
if(events[idx].filter & EVFILT_READ)
ev->read(readbuf,
std::min(sizeof(readbuf), size_t(events[idx].data)));
if(events[idx].filter & EVFILT_WRITE)
{
ev->flush_write_buffers(events[idx].data);
}
}
++idx;
}

@ -106,13 +106,20 @@ namespace llarp
while(itr != conf.end())
{
if(!endpoint->SetOption(itr->first, itr->second))
{
llarp::LogWarn("Couldn't set option ", itr->first, " to ",
itr->second);
return false;
}
++itr;
}
}
// add endpoint
if(!endpoint->Start())
{
llarp::LogWarn("Couldn't start exit endpoint");
return false;
}
m_Exits.emplace(name, std::move(endpoint));
return true;
}

@ -207,9 +207,14 @@ namespace llarp
if(m_ShouldInitTun)
{
if(!llarp_ev_add_tun(GetRouter()->netloop, &m_Tun))
{
llarp::LogWarn("Could not create tunnel for exit endpoint");
return false;
}
if(m_UpstreamResolvers.size() == 0)
m_UpstreamResolvers.emplace_back("8.8.8.8", 53);
llarp::LogInfo("Trying to start resolver ",
m_LocalResolverAddr.ToString());
return m_Resolver.Start(m_LocalResolverAddr, m_UpstreamResolvers);
}
return true;

@ -55,6 +55,8 @@ namespace llarp
bool
TunEndpoint::SetOption(const std::string &k, const std::string &v)
{
// Name won't be set because we need to read the config before we can read
// the keyfile
if(k == "exit-node")
{
llarp::RouterID exitRouter;
@ -82,7 +84,7 @@ namespace llarp
dnsport = std::atoi(v.substr(pos + 1).c_str());
}
m_LocalResolverAddr = llarp::Addr(resolverAddr, dnsport);
llarp::LogInfo(Name(), " local dns set to ", m_LocalResolverAddr);
llarp::LogInfo(Name(), " binding DNS server to ", m_LocalResolverAddr);
}
if(k == "upstream-dns")
{
@ -95,7 +97,7 @@ namespace llarp
dnsport = std::atoi(v.substr(pos + 1).c_str());
}
m_UpstreamResolvers.emplace_back(resolverAddr, dnsport);
llarp::LogInfo(Name(), " adding upstream dns set to ", resolverAddr,
llarp::LogInfo(Name(), " adding upstream DNS server ", resolverAddr,
":", dnsport);
}
if(k == "mapaddr")
@ -360,7 +362,10 @@ namespace llarp
TunEndpoint::Start()
{
if(!Endpoint::Start())
{
llarp::LogWarn("Couldn't start endpoint");
return false;
}
return SetupNetworking();
}
@ -376,7 +381,9 @@ namespace llarp
{
if(!llarp_ev_add_tun(EndpointNetLoop(), &tunif))
{
llarp::LogError(Name(), " failed to set up tun interface");
llarp::LogError(Name(),
" failed to set up tun interface: ", tunif.ifaddr,
" on ", tunif.ifname);
return false;
}

@ -36,7 +36,8 @@ namespace llarp
constexpr size_t FragmentBufferSize =
FragmentOverheadSize + FragmentBodySize;
static_assert(FragmentBufferSize == 1120, "Buffer size invalid");
static_assert(FragmentBufferSize == 1120,
"Fragement Buffer Size is not 1120");
/// buffer for a single utp fragment
using FragmentBuffer = llarp::AlignedBuffer< FragmentBufferSize >;

@ -100,9 +100,9 @@ namespace llarp
lock_t lock(m_ProfilesMutex);
size_t sz = (m_Profiles.size() * (RouterProfile::MaxSize + 32 + 8)) + 8;
std::vector<byte_t> tmp(sz, 0);
auto buf = llarp::Buffer(tmp);
auto res = BEncode(&buf);
std::vector< byte_t > tmp(sz, 0);
auto buf = llarp::Buffer(tmp);
auto res = BEncode(&buf);
if(res)
{
buf.sz = buf.cur - buf.base;

@ -389,14 +389,14 @@ namespace llarp
{
if(!EnsureEncryptionKey())
return false;
return llarp_findOrCreateIdentity(&crypto, ident_keyfile, identity);
return llarp_findOrCreateIdentity(&crypto, ident_keyfile, this->identity);
}
bool
Router::EnsureEncryptionKey()
{
return llarp_findOrCreateEncryption(&crypto, encryption_keyfile,
encryption);
this->encryption);
}
void
@ -1084,12 +1084,17 @@ namespace llarp
llarp::LogError("failed to regenerate keys and sign RC");
return false;
}
// generate default hidden service
llarp::LogInfo("setting up default network endpoint");
if(!CreateDefaultHiddenService())
// don't create default if we already have some defined
if(this->ShouldCreateDefaultHiddenService())
{
llarp::LogError("failed to set up default network endpoint");
return false;
// generate default hidden service
llarp::LogInfo("setting up default network endpoint");
if(!CreateDefaultHiddenService())
{
llarp::LogError("failed to set up default network endpoint");
return false;
}
}
}
@ -1130,6 +1135,84 @@ namespace llarp
link->Stop();
}
bool
Router::ShouldCreateDefaultHiddenService()
{
std::string defaultIfAddr = "auto";
std::string defaultIfName = "auto";
std::string enabledOption = "auto";
auto itr = netConfig.find("defaultIfAddr");
if(itr != netConfig.end())
{
defaultIfAddr = itr->second;
}
itr = netConfig.find("defaultIfName");
if(itr != netConfig.end())
{
defaultIfName = itr->second;
}
itr = netConfig.find("enabled");
if(itr != netConfig.end())
{
enabledOption = itr->second;
}
llarp::LogDebug("IfName: ", defaultIfName, " IfAddr: ", defaultIfAddr,
" Enabled: ", enabledOption);
// llarp::LogInfo("IfAddr: ", itr->second);
// llarp::LogInfo("IfName: ", itr->second);
if(enabledOption == "false")
{
llarp::LogInfo("Disabling default hidden service");
return false;
}
else if(enabledOption == "auto")
{
// auto detect if we have any pre-defined endpoints
// no if we have a endpoints
if(hiddenServiceContext.hasEndpoints())
{
llarp::LogInfo("Auto mode detected and we have endpoints");
netConfig.emplace(std::make_pair("enabled", "false"));
return false;
}
netConfig.emplace(std::make_pair("enabled", "true"));
}
// ev.cpp llarp_ev_add_tun now handles this
/*
// so basically enabled at this point
if(defaultIfName == "auto")
{
// we don't have any endpoints, auto configure settings
// set a default IP range
defaultIfAddr = llarp::findFreePrivateRange();
if(defaultIfAddr == "")
{
llarp::LogError(
"Could not find any free lokitun interface names, can't
auto set up " "default HS context for client"); defaultIfAddr = "no";
netConfig.emplace(std::make_pair("defaultIfAddr", defaultIfAddr));
return false;
}
netConfig.emplace(std::make_pair("defaultIfAddr", defaultIfAddr));
}
if(defaultIfName == "auto")
{
// pick an ifName
defaultIfName = llarp::findFreeLokiTunIfName();
if(defaultIfName == "")
{
llarp::LogError(
"Could not find any free private ip ranges, can't auto
set up " "default HS context for client"); defaultIfName = "no";
netConfig.emplace(std::make_pair("defaultIfName", defaultIfName));
return false;
}
netConfig.emplace(std::make_pair("defaultIfName", defaultIfName));
}
*/
return true;
}
void
Router::Stop()
{
@ -1545,6 +1628,14 @@ namespace llarp
{
self->transport_keyfile = val;
}
if(StrEq(key, "identity-privkey"))
{
llarp::LogWarn(
"Deprecated INI key identity-privkey detected, please rename it to "
"ident-privkey");
// FIXME: use the config writer to fix it
self->ident_keyfile = val;
}
if(StrEq(key, "ident-privkey"))
{
self->ident_keyfile = val;

@ -156,6 +156,9 @@ namespace llarp
bool
CreateDefaultHiddenService();
bool
ShouldCreateDefaultHiddenService();
const std::string DefaultRPCBindAddr = "127.0.0.1:1190";
bool enableRPCServer = true;
std::unique_ptr< llarp::rpc::Server > rpcServer;

@ -49,9 +49,9 @@ namespace llarp
CloseExitMessage C;
};
IMessage * msg = nullptr;
IMessage* msg = nullptr;
MessageHolder m_Holder;
};
}
}
} // namespace routing
} // namespace llarp
#endif

@ -55,5 +55,5 @@ namespace llarp
latency = 0;
expiresAt = 0;
}
}
}
} // namespace service
} // namespace llarp

@ -262,10 +262,13 @@ namespace llarp
}
// extract type
std::string endpointType = "tun";
std::string keyfile = "";
for(const auto &option : conf.second)
{
if(option.first == "type")
endpointType = option.second;
if(option.first == "keyfile")
keyfile = option.second;
}
std::unique_ptr< llarp::service::Endpoint > service;
@ -295,6 +298,14 @@ namespace llarp
// construct
service.reset(itr->second(conf.first, m_Router));
if(keyfile != "")
{
llarp::LogInfo("Found keyfile, prestarting endpoint");
service->SetOption("keyfile", keyfile);
// load keyfile, so we have the correct name for logging
service->LoadKeyFile(); // only start endpoint not tun
llarp::LogInfo("Endpoint prestarted");
}
}
// configure
for(const auto &option : conf.second)

@ -486,18 +486,28 @@ namespace llarp
}
bool
Endpoint::Start()
Endpoint::LoadKeyFile()
{
auto crypto = &m_Router->crypto;
if(m_Keyfile.size())
{
if(!m_Identity.EnsureKeys(m_Keyfile, crypto))
{
llarp::LogWarn("Can't ensure keyfile [", m_Keyfile, "]");
return false;
}
}
else
{
m_Identity.RegenerateKeys(crypto);
}
return true;
}
bool
Endpoint::Start()
{
this->LoadKeyFile();
if(!m_DataHandler)
{
m_DataHandler = this;
@ -508,7 +518,10 @@ namespace llarp
if(m_OnInit.front()())
m_OnInit.pop_front();
else
{
llarp::LogWarn("Can't call init of network isolation");
return false;
}
}
return true;
}

@ -71,6 +71,9 @@ namespace llarp
return m_Router;
}
virtual bool
LoadKeyFile();
virtual bool
Start();

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# this shell script will be replaced by a proper program in the future (probably)
#
# from https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

@ -30,20 +30,11 @@ TEST_P(DHT, constructor)
}
}
static constexpr Array emptyArray{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static constexpr Array fullArray{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
static constexpr Array seqArray{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
static constexpr Array emptyArray {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
static constexpr Array fullArray {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
static constexpr Array seqArray {{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F}};
static const Array data[] = {emptyArray, fullArray, seqArray};

Loading…
Cancel
Save