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