address issue loki-project#547, remove client.ini, update ini defaults, and clean up help message

This commit is contained in:
Ryan Tharp 2019-04-23 14:50:49 -07:00
parent c5c64731e7
commit 8cf6a77c1d
2 changed files with 50 additions and 88 deletions

View File

@ -30,7 +30,7 @@ handle_signal(int sig)
int
printHelp(const char *argv0, int code = 1)
{
std::cout << "usage: " << argv0 << " [-h] [-v] [-g|-c] config.ini"
std::cout << "usage: " << argv0 << " [-h] [-v] [-g|-r [-f]] [config.ini]"
<< std::endl;
return code;
}
@ -106,13 +106,13 @@ main(int argc, char *argv[])
// clang-format off
cxxopts::Options options(
"lokinet",
"Lokinet is a private, decentralized and IP based overlay network for the internet"
"LokiNET is a free, open source, private, decentralized, "market based sybil resistant" and IP based onion routing network"
);
options.add_options()
("v,verbose", "Verbose", cxxopts::value<bool>())
("h,help", "help", cxxopts::value<bool>())
("g,generate", "generate config", cxxopts::value<bool>())
("r,router", "run as router", cxxopts::value<bool>())
("g,generate", "generate client config", cxxopts::value<bool>())
("r,router", "generate router config", cxxopts::value<bool>())
("f,force", "overwrite", cxxopts::value<bool>())
("config","path to configuration file", cxxopts::value<std::string>());

View File

@ -94,6 +94,7 @@ namespace llarp
} // namespace llarp
/// fname should be a relative path (from CWD) or absolute path to the config file
extern "C" bool
llarp_ensure_config(const char *fname, const char *basedir, bool overwrite,
bool asRouter)
@ -122,13 +123,13 @@ llarp_ensure_config(const char *fname, const char *basedir, bool overwrite,
llarp::LogInfo("Attempting to create config file ", fname);
// abort if client.ini already exists
// abort if config already exists
if(!asRouter)
{
if(fs::exists(basepath + "client.ini", ec) && !overwrite)
if(fs::exists(fname, ec) && !overwrite)
{
llarp::LogError(
basepath, "client.ini currently exists, please use -f to overwrite");
fname, " currently exists, please use -f to overwrite");
return true;
}
if(ec)
@ -179,7 +180,7 @@ llarp_generic_ensure_config(std::ofstream &f, std::string basepath)
f << std::endl;
f << "# uncomment following line to set router nickname to 'lokinet'"
<< std::endl;
f << "# nickname=lokinet" << std::endl;
f << "#nickname=lokinet" << std::endl;
f << std::endl << std::endl;
// logging
@ -200,21 +201,15 @@ llarp_generic_ensure_config(std::ofstream &f, std::string basepath)
f << "# admin api (disabled by default)" << std::endl;
f << "[api]" << std::endl;
f << "enabled=false" << std::endl;
f << "# authkey=insertpubkey1here" << std::endl;
f << "# authkey=insertpubkey2here" << std::endl;
f << "# authkey=insertpubkey3here" << std::endl;
f << "#authkey=insertpubkey1here" << std::endl;
f << "#authkey=insertpubkey2here" << std::endl;
f << "#authkey=insertpubkey3here" << std::endl;
f << "bind=127.0.0.1:1190" << std::endl;
f << std::endl << std::endl;
f << "# system settings for privileges and such" << std::endl;
f << "[system]" << std::endl;
#ifdef _WIN32
f << "# ";
#endif
f << "user=" << DEFAULT_LOKINET_USER << std::endl;
#ifdef _WIN32
f << "# ";
#endif
f << "group=" << DEFAULT_LOKINET_GROUP << std::endl;
f << "pidfile=" << basepath << "lokinet.pid" << std::endl;
f << std::endl << std::endl;
@ -251,8 +246,9 @@ llarp_generic_ensure_config(std::ofstream &f, std::string basepath)
<< std::endl;
f << "# if we don't have any peers we connect to this router" << std::endl;
f << "add-node=" << basepath << "bootstrap.signed" << std::endl;
f << "# add another bootstrap node" << std::endl;
f << "#add-node=/path/to/alternative/self.signed" << std::endl;
// we only process one of these...
//f << "# add another bootstrap node" << std::endl;
//f << "#add-node=/path/to/alternative/self.signed" << std::endl;
f << std::endl << std::endl;
}
@ -268,13 +264,14 @@ llarp_ensure_router_config(std::ofstream &f, std::string basepath)
f << "# network settings " << std::endl;
f << "[network]" << std::endl;
f << "profiles=" << basepath << "profiles.dat" << std::endl;
f << "ifaddr=10.105.0.1/16" << std::endl;
f << "ifname=lokitun0" << std::endl;
// better to let the routers auto-configure
f << "ifaddr=auto" << std::endl;
f << "ifname=auto" << std::endl;
f << "enabled=true" << std::endl;
f << "exit=false" << std::endl;
f << "# exit-blacklist=tcp:25" << std::endl;
f << "# exit-whitelist=tcp:*" << std::endl;
f << "# exit-whitelist=udp:*" << std::endl;
f << "#exit-blacklist=tcp:25" << std::endl;
f << "#exit-whitelist=tcp:*" << std::endl;
f << "#exit-whitelist=udp:*" << std::endl;
f << std::endl;
f << "# ROUTERS ONLY: publish network interfaces for handling inbound traffic"
<< std::endl;
@ -285,7 +282,7 @@ llarp_ensure_router_config(std::ofstream &f, std::string basepath)
f << ifname << "=1090" << std::endl;
else
f << "# could not autodetect network interface" << std::endl
<< "# eth0=1090" << std::endl;
<< "#eth0=1090" << std::endl;
f << std::endl;
}
@ -293,39 +290,47 @@ llarp_ensure_router_config(std::ofstream &f, std::string basepath)
bool
llarp_ensure_client_config(std::ofstream &f, std::string basepath)
{
// write snapp-example.ini
const std::string snappExample_fpath = basepath + "snapp-example.ini";
// done with fname.ini
// start client.ini
// write fname ini
{
std::ofstream clientini_f(snappExample_fpath,
std::ofstream example_f(snappExample_fpath,
std::ios::binary | std::ios::out);
if(f.is_open())
{
clientini_f << "# this is an example configuration for a snapp"
// pick ip
std::string ip = llarp::findFreePrivateRange();
if(ip == "")
{
llarp::LogError(
"Couldn't easily detect a private range to map lokinet onto");
return false;
}
example_f << "# this is an example configuration for a snapp"
<< std::endl;
clientini_f << "[example-snapp]" << std::endl;
clientini_f << "# keyfile is the path to the private key of the snapp"
example_f << "[example-snapp]" << std::endl;
example_f << "# keyfile is the path to the private key of the snapp, your .loki is tied to this key, DON'T LOSE IT"
<< std::endl;
clientini_f << "keyfile=" << basepath << "example-snap-keyfile.private"
example_f << "keyfile=" << basepath << "example-snap-keyfile.private"
<< std::endl;
clientini_f << "# ifaddr is the ip range to allocate to this snapp"
example_f << "# ifaddr is the ip range to allocate to this snapp"
<< std::endl;
clientini_f << "ifaddr=10.55.0.0/16" << std::endl;
clientini_f << "# ifname is the name to try and give to the network "
example_f << "ifaddr=" << ip << std::endl;
// probably fine to leave this (and not-auto-detect it) I'm not worried about any collisions
example_f << "# ifname is the name to try and give to the network "
"interface this snap owns"
<< std::endl;
clientini_f << "ifname=snapp-tun0" << std::endl;
example_f << "ifname=snapp-tun0" << std::endl;
}
else
{
llarp::LogError("failed to write ", snappExample_fpath);
}
}
// now do up fname
f << std::endl << std::endl;
f << "# snapps configuration section" << std::endl;
f << "[services]";
f << "# uncomment next line to enable persistant snapp" << std::endl;
f << "# uncomment next line to enable a snapp" << std::endl;
f << "#example-snapp=" << snappExample_fpath << std::endl;
f << std::endl << std::endl;
@ -339,57 +344,14 @@ llarp_ensure_client_config(std::ofstream &f, std::string basepath)
f << "# uncomment next line to use router with pubkey as an exit node"
<< std::endl;
f << "#exit-node=pubkey" << std::endl;
// pick ip
std::string ip = llarp::findFreePrivateRange();
/*
struct privatesInUse ifsInUse = llarp_getPrivateIfs();
std::string ip = "";
if(!ifsInUse.ten)
{
ip = "10.10.0.1/24";
}
else if(!ifsInUse.oneSeven)
{
ip = "172.16.10.1/24";
}
else if(!ifsInUse.oneNine)
{
ip = "192.168.10.1/24";
}
else
{
llarp::LogError(
"Couldn't easily detect a private range to map lokinet onto");
return false;
}
*/
if(ip == "")
{
llarp::LogError(
"Couldn't easily detect a private range to map lokinet onto");
return false;
}
llarp::LogDebug("Detected " + ip
+ " is available for use, configuring as such");
// clientini_f << "ifaddr=" << ip << std::endl;
// pick interface name
std::string ifName = llarp::findFreeLokiTunIfName();
if(ifName == "")
{
llarp::LogError("Could not find any free lokitun interface names");
return false;
}
/*
clientini_f << "ifname=lokinum" << std::to_string(num) << std::endl;
// prefetch-tags=test
// enable netns?
llarp::LogInfo("Generated hidden service client as " + basepath
+ "client.ini");
*/
f << "ifname=" << ifName << std::endl;
f << "ifaddr=" << ip << std::endl;
// better to set them to auto then to hard code them now
// operating environment may change over time and this will help adapt
f << "ifname=auto" << std::endl;
f << "ifaddr=auto" << std::endl;
// should this also be auto? or not declared?
// probably auto in case they want to set up a hidden service
f << "enabled=true" << std::endl;
return true;
}