Merge pull request #391 from fireice-uk/fix-cli-questions

Fix cli questions
This commit is contained in:
psychocrypt
2017-12-09 00:06:24 +01:00
committed by GitHub
5 changed files with 124 additions and 48 deletions
+85 -11
View File
@@ -85,10 +85,13 @@ void help()
cout<<" --nvidia FILE NVIDIA backend miner config file"<<endl;
#endif
cout<<" "<<endl;
cout<<"The Following options temporary overwrites the config entries of \nthe pool with the highest weight:"<<endl;
cout<<"The following options can be used for automatic start without a guided config,"<<endl;
cout<<"If config exists then this pool will be top priority."<<endl;
cout<<" -o, --url URL pool url and port, e.g. pool.usxmrpool.com:3333"<<endl;
cout<<" -O, --tls-url URL TLS pool url and port, e.g. pool.usxmrpool.com:10443"<<endl;
cout<<" -u, --user USERNAME pool user name or wallet address"<<endl;
cout<<" -p, --pass PASSWD pool password, in the most cases x or empty \"\""<<endl;
cout<<" --use-nicehash the pool should run in nicehash mode"<<endl;
cout<<" \n"<<endl;
#ifdef _WIN32
cout<<"Environment variables:\n"<<endl;
@@ -162,7 +165,16 @@ std::string get_multipool_entry(bool& final)
", \"tls_fingerprint\" : \"\", \"pool_weight\" : " + std::to_string(pool_weight) + " },\n";
}
void do_guided_config(bool userSetPasswd)
inline void prompt_once(bool& prompted)
{
if(!prompted)
{
std::cout<<"Please enter:"<<std::endl;
prompted = true;
}
}
void do_guided_config()
{
using namespace xmrstak;
@@ -173,10 +185,13 @@ void do_guided_config(bool userSetPasswd)
configEditor configTpl{};
configTpl.set(std::string(tpl));
std::cout<<"Please enter:"<<std::endl;
bool prompted = false;
auto& currency = params::inst().currency;
if(currency.empty())
{
prompt_once(prompted);
std::string tmp;
#if defined(CONF_NO_AEON)
tmp = "monero";
@@ -196,6 +211,8 @@ void do_guided_config(bool userSetPasswd)
bool userSetPool = true;
if(pool.empty())
{
prompt_once(prompted);
userSetPool = false;
if(currency == "monero")
std::cout<<"- Pool address: e.g. pool.usxmrpool.com:3333"<<std::endl;
@@ -207,25 +224,44 @@ void do_guided_config(bool userSetPasswd)
auto& userName = params::inst().poolUsername;
if(userName.empty())
{
prompt_once(prompted);
std::cout<<"- Username (wallet address or pool login):"<<std::endl;
std::cin >> userName;
}
auto& passwd = params::inst().poolPasswd;
if(passwd.empty() && (!userSetPasswd))
if(passwd.empty() && !params::inst().userSetPwd)
{
prompt_once(prompted);
// clear everything from stdin to allow an empty password
std::cin.clear(); std::cin.ignore(INT_MAX,'\n');
std::cout<<"- Password (mostly empty or x):"<<std::endl;
getline(std::cin, passwd);
}
bool tls;
#ifdef CONF_NO_TLS
bool tls = false;
tls = false;
#else
bool tls = read_yes_no("- Does this pool port support TLS/SSL? Use no if unknown. (y/N)");
if(!userSetPool)
{
prompt_once(prompted);
tls = read_yes_no("- Does this pool port support TLS/SSL? Use no if unknown. (y/N)");
}
else
tls = params::inst().poolUseTls;
#endif
bool nicehash = read_yes_no("- Do you want to use nicehash on this pool? (y/n)");
bool nicehash;
if(!userSetPool)
{
prompt_once(prompted);
nicehash = read_yes_no("- Do you want to use nicehash on this pool? (y/n)");
}
else
nicehash = params::inst().nicehashMode;
bool multipool;
if(!userSetPool)
@@ -339,9 +375,16 @@ int main(int argc, char *argv[])
params::inst().executablePrefix += seperator;
}
bool userSetPasswd = false;
bool uacDialog = true;
for(int i = 1; i < argc; ++i)
bool pool_url_set = false;
for(size_t i = 1; i < argc-1; i++)
{
std::string opName(argv[i]);
if(opName == "-o" || opName == "-O" || opName == "--url" || opName == "--tls-url")
pool_url_set = true;
}
for(size_t i = 1; i < argc; ++i)
{
std::string opName(argv[i]);
if(opName.compare("-h") == 0 || opName.compare("--help") == 0)
@@ -428,9 +471,29 @@ int main(int argc, char *argv[])
return 1;
}
params::inst().poolURL = argv[i];
params::inst().poolUseTls = false;
}
else if(opName.compare("-O") == 0 || opName.compare("--tls-url") == 0)
{
++i;
if( i >=argc )
{
printer::inst()->print_msg(L0, "No argument for parameter '-O/--tls-url' given");
win_exit();
return 1;
}
params::inst().poolURL = argv[i];
params::inst().poolUseTls = true;
}
else if(opName.compare("-u") == 0 || opName.compare("--user") == 0)
{
if(!pool_url_set)
{
printer::inst()->print_msg(L0, "Pool address has to be set if you want to specify username and password.");
win_exit();
return 1;
}
++i;
if( i >=argc )
{
@@ -442,6 +505,13 @@ int main(int argc, char *argv[])
}
else if(opName.compare("-p") == 0 || opName.compare("--pass") == 0)
{
if(!pool_url_set)
{
printer::inst()->print_msg(L0, "Pool address has to be set if you want to specify username and password.");
win_exit();
return 1;
}
++i;
if( i >=argc )
{
@@ -449,9 +519,13 @@ int main(int argc, char *argv[])
win_exit();
return 1;
}
userSetPasswd = true;
params::inst().userSetPwd = true;
params::inst().poolPasswd = argv[i];
}
else if(opName.compare("--use-nicehash") == 0)
{
params::inst().nicehashMode = true;
}
else if(opName.compare("-c") == 0 || opName.compare("--config") == 0)
{
++i;
@@ -491,7 +565,7 @@ int main(int argc, char *argv[])
// check if we need a guided start
if(!configEditor::file_exist(params::inst().configFile))
do_guided_config(userSetPasswd);
do_guided_config();
if(!jconf::inst()->parse_config(params::inst().configFile.c_str()))
{
+2 -2
View File
@@ -152,8 +152,8 @@ bool jconf::GetPoolConfig(size_t id, pool_cfg& cfg)
size_t dlt = wt_max - wt_min;
if(dlt != 0)
{
/* Normalise weights between 0 and 9.9 */
cfg.weight = double(cfg.raw_weight - wt_min) * 9.9;
/* Normalise weights between 0 and 9.8 */
cfg.weight = double(cfg.raw_weight - wt_min) * 9.8;
cfg.weight /= dlt;
}
else /* Special case - user selected same weights for everything */
+34 -31
View File
@@ -497,8 +497,10 @@ void executor::ex_main()
set_timestamp();
size_t pc = jconf::inst()->GetPoolCount();
bool tls = true;
for(size_t i=0; i < pc; i++)
bool dev_tls = true;
bool already_have_cli_pool = false;
size_t i=0;
for(; i < pc; i++)
{
jconf::pool_cfg cfg;
jconf::inst()->GetPoolConfig(i, cfg);
@@ -509,49 +511,50 @@ void executor::ex_main()
win_exit();
}
#endif
if(!cfg.tls) tls = false;
pools.emplace_back(i+1, cfg.sPoolAddr, cfg.sWalletAddr, cfg.sPasswd, cfg.weight, false, cfg.tls, cfg.tls_fingerprint, cfg.nicehash);
if(!cfg.tls) dev_tls = false;
if(!xmrstak::params::inst().poolURL.empty() && xmrstak::params::inst().poolURL == cfg.sPoolAddr)
{
auto& params = xmrstak::params::inst();
already_have_cli_pool = true;
const char* wallet = params.poolUsername.empty() ? cfg.sWalletAddr : params.poolUsername.c_str();
const char* pwd = params.userSetPwd ? params.poolPasswd.c_str() : cfg.sPasswd;
bool nicehash = cfg.nicehash || params.nicehashMode;
pools.emplace_back(i+1, cfg.sPoolAddr, wallet, pwd, 9.9, false, params.poolUseTls, cfg.tls_fingerprint, nicehash);
}
else
pools.emplace_back(i+1, cfg.sPoolAddr, cfg.sWalletAddr, cfg.sPasswd, cfg.weight, false, cfg.tls, cfg.tls_fingerprint, cfg.nicehash);
}
if(!xmrstak::params::inst().poolURL.empty() && !already_have_cli_pool)
{
auto& params = xmrstak::params::inst();
if(params.poolUsername.empty())
{
printer::inst()->print_msg(L1, "ERROR: You didn't specify the username / wallet address for %s", xmrstak::params::inst().poolURL.c_str());
win_exit();
}
pools.emplace_back(i+1, params.poolURL.c_str(), params.poolUsername.c_str(), params.poolPasswd.c_str(), 9.9, false, params.poolUseTls, "", params.nicehashMode);
}
if(jconf::inst()->IsCurrencyMonero())
{
if(tls)
if(dev_tls)
pools.emplace_front(0, "donate.xmr-stak.net:6666", "", "", 0.0, true, true, "", false);
else
pools.emplace_front(0, "donate.xmr-stak.net:3333", "", "", 0.0, true, false, "", false);
}
else
{
if(tls)
if(dev_tls)
pools.emplace_front(0, "donate.xmr-stak.net:7777", "", "", 0.0, true, true, "", true);
else
pools.emplace_front(0, "donate.xmr-stak.net:4444", "", "", 0.0, true, false, "", true);
}
/* find the pool with the highest weighting to allow overwriting of the
* pool settings via command line options.
*/
std::vector<jpsock*> sorted_pools;
sorted_pools.reserve(pools.size());
for(jpsock& pool : pools)
sorted_pools.emplace_back(&pool);
std::sort(sorted_pools.begin(), sorted_pools.end(), [](jpsock* a, jpsock* b) { return b->get_pool_weight(true) < a->get_pool_weight(true); });
// overwrite pool address if cli option is used
auto& poolURL = xmrstak::params::inst().poolURL;
if(!poolURL.empty())
{
sorted_pools[0]->set_pool_addr(poolURL.c_str());
}
// overwrite user pool login name if cli option is used
auto& poolUsername = xmrstak::params::inst().poolUsername;
if(!poolUsername.empty())
sorted_pools[0]->set_user_login(poolUsername.c_str());
// overwrite user pool login password if cli option is used
auto& poolPasswd = xmrstak::params::inst().poolPasswd;
if(!poolPasswd.empty())
sorted_pools[0]->set_user_passwd(poolPasswd.c_str());
ex_event ev;
std::thread clock_thd(&executor::ex_clock_thd, this);
@@ -565,7 +568,7 @@ void executor::ex_main()
if(jconf::inst()->GetVerboseLevel() >= 4)
push_timed_event(ex_event(EV_HASHRATE_LOOP), jconf::inst()->GetAutohashTime());
size_t cnt = 0, i;
size_t cnt = 0;
while (true)
{
ev = oEventQ.pop();
-4
View File
@@ -59,10 +59,6 @@ public:
inline const char* get_tls_fp() { return tls_fp.c_str(); }
inline bool is_nicehash() { return nicehash; }
inline void set_pool_addr(const char* sAddr) { net_addr = sAddr; }
inline void set_user_login(const char* sLogin) { usr_login = sLogin; }
inline void set_user_passwd(const char* sPassword) { usr_pass = sPassword; }
bool get_pool_motd(std::string& strin);
std::string&& get_call_error();
+3
View File
@@ -24,9 +24,12 @@ struct params
bool useNVIDIA;
bool useCPU;
bool poolUseTls = false;
std::string poolURL;
bool userSetPwd = false;
std::string poolPasswd;
std::string poolUsername;
bool nicehashMode = false;
std::string currency;