mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 16:39:29 -05:00
Merge pull request #770 from Sonetio/fix_reselecting_accounts
Fixed: Re-selecting accounts via RsControlModule;
This commit is contained in:
commit
98e1a6d74c
@ -119,6 +119,8 @@ PeersHandler::PeersHandler(StateTokenServer* sts, RsNotify* notify, RsPeers *pee
|
||||
addResourceHandler("set_state_string", this, &PeersHandler::handleSetStateString);
|
||||
addResourceHandler("get_custom_state_string", this, &PeersHandler::handleGetCustomStateString);
|
||||
addResourceHandler("set_custom_state_string", this, &PeersHandler::handleSetCustomStateString);
|
||||
addResourceHandler("get_pgp_options", this, &PeersHandler::handleGetPGPOptions);
|
||||
addResourceHandler("set_pgp_options", this, &PeersHandler::handleSetPGPOptions);
|
||||
addResourceHandler("examine_cert", this, &PeersHandler::handleExamineCert);
|
||||
}
|
||||
|
||||
@ -529,6 +531,120 @@ void PeersHandler::handleExamineCert(Request &req, Response &resp)
|
||||
}
|
||||
}
|
||||
|
||||
void PeersHandler::handleGetPGPOptions(Request& req, Response& resp)
|
||||
{
|
||||
std::string pgp_id;
|
||||
req.mStream << makeKeyValueReference("pgp_id", pgp_id);
|
||||
|
||||
RsPgpId pgp(pgp_id);
|
||||
RsPeerDetails detail;
|
||||
|
||||
if(!mRsPeers->getGPGDetails(pgp, detail))
|
||||
{
|
||||
resp.setFail();
|
||||
return;
|
||||
}
|
||||
|
||||
std::string pgp_key = mRsPeers->getPGPKey(detail.gpg_id, false);
|
||||
|
||||
resp.mDataStream << makeKeyValue("pgp_fingerprint", detail.fpr.toStdString());
|
||||
resp.mDataStream << makeKeyValueReference("pgp_key", pgp_key);
|
||||
|
||||
resp.mDataStream << makeKeyValue("direct_transfer", detail.service_perm_flags & RS_NODE_PERM_DIRECT_DL);
|
||||
resp.mDataStream << makeKeyValue("allow_push", detail.service_perm_flags & RS_NODE_PERM_ALLOW_PUSH);
|
||||
resp.mDataStream << makeKeyValue("require_WL", detail.service_perm_flags & RS_NODE_PERM_REQUIRE_WL);
|
||||
|
||||
resp.mDataStream << makeKeyValue("own_sign", detail.ownsign);
|
||||
resp.mDataStream << makeKeyValue("trustLvl", detail.trustLvl);
|
||||
|
||||
uint32_t max_upload_speed = 0;
|
||||
uint32_t max_download_speed = 0;
|
||||
|
||||
mRsPeers->getPeerMaximumRates(pgp, max_upload_speed, max_download_speed);
|
||||
|
||||
resp.mDataStream << makeKeyValueReference("maxUploadSpeed", max_upload_speed);
|
||||
resp.mDataStream << makeKeyValueReference("maxDownloadSpeed", max_download_speed);
|
||||
|
||||
StreamBase& signersStream = resp.mDataStream.getStreamToMember("gpg_signers");
|
||||
|
||||
// mark as list (in case list is empty)
|
||||
signersStream.getStreamToMember();
|
||||
|
||||
for(std::list<RsPgpId>::const_iterator it(detail.gpgSigners.begin()); it != detail.gpgSigners.end(); ++it)
|
||||
{
|
||||
RsPeerDetails detail;
|
||||
if(!mRsPeers->getGPGDetails(*it, detail))
|
||||
continue;
|
||||
|
||||
std::string pgp_id = (*it).toStdString();
|
||||
std::string name = detail.name;
|
||||
|
||||
signersStream.getStreamToMember()
|
||||
<< makeKeyValueReference("pgp_id", pgp_id)
|
||||
<< makeKeyValueReference("name", name);
|
||||
}
|
||||
|
||||
resp.setOk();
|
||||
}
|
||||
|
||||
void PeersHandler::handleSetPGPOptions(Request& req, Response& resp)
|
||||
{
|
||||
std::string pgp_id;
|
||||
req.mStream << makeKeyValueReference("pgp_id", pgp_id);
|
||||
|
||||
RsPgpId pgp(pgp_id);
|
||||
RsPeerDetails detail;
|
||||
|
||||
if(!mRsPeers->getGPGDetails(pgp, detail))
|
||||
{
|
||||
resp.setFail();
|
||||
return;
|
||||
}
|
||||
|
||||
int trustLvl;
|
||||
req.mStream << makeKeyValueReference("trustLvl", trustLvl);
|
||||
|
||||
if(trustLvl != (int)detail.trustLvl)
|
||||
mRsPeers->trustGPGCertificate(pgp, trustLvl);
|
||||
|
||||
int max_upload_speed;
|
||||
int max_download_speed;
|
||||
|
||||
req.mStream << makeKeyValueReference("max_upload_speed", max_upload_speed);
|
||||
req.mStream << makeKeyValueReference("max_download_speed", max_download_speed);
|
||||
|
||||
mRsPeers->setPeerMaximumRates(pgp, (uint32_t)max_upload_speed, (uint32_t)max_download_speed);
|
||||
|
||||
bool direct_transfer;
|
||||
bool allow_push;
|
||||
bool require_WL;
|
||||
|
||||
req.mStream << makeKeyValueReference("direct_transfer", direct_transfer);
|
||||
req.mStream << makeKeyValueReference("allow_push", allow_push);
|
||||
req.mStream << makeKeyValueReference("require_WL", require_WL);
|
||||
|
||||
ServicePermissionFlags flags(0);
|
||||
|
||||
if(direct_transfer)
|
||||
flags = flags | RS_NODE_PERM_DIRECT_DL;
|
||||
if(allow_push)
|
||||
flags = flags | RS_NODE_PERM_ALLOW_PUSH;
|
||||
if(require_WL)
|
||||
flags = flags | RS_NODE_PERM_REQUIRE_WL;
|
||||
|
||||
mRsPeers->setServicePermissionFlags(pgp, flags);
|
||||
|
||||
bool own_sign;
|
||||
req.mStream << makeKeyValueReference("own_sign", own_sign);
|
||||
|
||||
if(own_sign)
|
||||
mRsPeers->signGPGCertificate(pgp);
|
||||
|
||||
resp.mStateToken = getCurrentStateToken();
|
||||
|
||||
resp.setOk();
|
||||
}
|
||||
|
||||
StateToken PeersHandler::getCurrentStateToken()
|
||||
{
|
||||
RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/
|
||||
|
@ -41,6 +41,9 @@ private:
|
||||
void handleGetCustomStateString(Request& req, Response& resp);
|
||||
void handleSetCustomStateString(Request& req, Response& resp);
|
||||
|
||||
void handleGetPGPOptions(Request& req, Response& resp);
|
||||
void handleSetPGPOptions(Request& req, Response& resp);
|
||||
|
||||
// a helper which ensures proper mutex locking
|
||||
StateToken getCurrentStateToken();
|
||||
|
||||
|
@ -24,7 +24,9 @@ RsControlModule::RsControlModule(int argc, char **argv, StateTokenServer* sts, A
|
||||
mDataMtx("RsControlModule::mDataMtx"),
|
||||
mRunState(WAITING_INIT),
|
||||
mAutoLoginNextTime(false),
|
||||
mWantPassword(false)
|
||||
mWantPassword(false),
|
||||
mPassword(""),
|
||||
mPrevIsBad(false)
|
||||
{
|
||||
mStateToken = sts->getNewToken();
|
||||
this->argc = argc;
|
||||
@ -56,13 +58,16 @@ bool RsControlModule::processShouldExit()
|
||||
return mProcessShouldExit;
|
||||
}
|
||||
|
||||
bool RsControlModule::askForPassword(const std::string &title, const std::string &key_details, bool /* prev_is_bad */, std::string &password, bool& cancelled)
|
||||
bool RsControlModule::askForPassword(const std::string &title, const std::string &key_details, bool prev_is_bad, std::string &password, bool& cancelled)
|
||||
{
|
||||
cancelled = false ;
|
||||
{
|
||||
RS_STACK_MUTEX(mDataMtx); // ********** LOCKED **********
|
||||
|
||||
mPrevIsBad = prev_is_bad;
|
||||
|
||||
if(mFixedPassword != "")
|
||||
{
|
||||
{
|
||||
password = mFixedPassword;
|
||||
return true;
|
||||
}
|
||||
@ -70,25 +75,31 @@ bool RsControlModule::askForPassword(const std::string &title, const std::string
|
||||
mWantPassword = true;
|
||||
mTitle = title;
|
||||
mKeyName = key_details;
|
||||
mPassword = "";
|
||||
|
||||
if(mPassword != "")
|
||||
{
|
||||
password = mPassword;
|
||||
mWantPassword = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
mStateTokenServer->replaceToken(mStateToken);
|
||||
}
|
||||
|
||||
bool wait = true;
|
||||
while(wait)
|
||||
int i = 0;
|
||||
while(i<100)
|
||||
{
|
||||
usleep(5*1000);
|
||||
|
||||
RS_STACK_MUTEX(mDataMtx); // ********** LOCKED **********
|
||||
wait = mWantPassword;
|
||||
if(!wait && mPassword != "")
|
||||
|
||||
if(mPassword != "")
|
||||
{
|
||||
password = mPassword;
|
||||
mPassword = "";
|
||||
password = mPassword;
|
||||
mWantPassword = false;
|
||||
mStateTokenServer->replaceToken(mStateToken);
|
||||
return true;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -125,6 +136,11 @@ void RsControlModule::run()
|
||||
bool login_ok = false;
|
||||
while(!login_ok)
|
||||
{
|
||||
{
|
||||
RsStackMutex stack(mDataMtx); // ********** LOCKED **********
|
||||
mPassword = "";
|
||||
}
|
||||
|
||||
// skip account selection if autologin is available
|
||||
if(initResult != RS_INIT_HAVE_ACCOUNT)
|
||||
setRunState(WAITING_ACCOUNT_SELECT);
|
||||
@ -175,8 +191,19 @@ void RsControlModule::run()
|
||||
std::cerr << "RsControlModule::run() LockAndLoadCertificates failed. Unexpected switch value: " << retVal << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
{
|
||||
RsStackMutex stack(mDataMtx); // ********** LOCKED **********
|
||||
mLoadPeerId.clear();
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
RsStackMutex stack(mDataMtx); // ********** LOCKED **********
|
||||
mFixedPassword = mPassword;
|
||||
mPassword = "";
|
||||
}
|
||||
|
||||
setRunState(WAITING_STARTUP);
|
||||
|
||||
std::cerr << "RsControlModule: login ok, starting Retroshare worker threads..." << std::endl;
|
||||
@ -302,12 +329,12 @@ void RsControlModule::handlePassword(Request &req, Response &resp)
|
||||
mPassword = passwd;
|
||||
mWantPassword = false;
|
||||
mStateTokenServer->replaceToken(mStateToken);
|
||||
mFixedPassword = passwd;
|
||||
}
|
||||
|
||||
resp.mDataStream
|
||||
<< makeKeyValueReference("want_password", mWantPassword)
|
||||
<< makeKeyValueReference("key_name", mKeyName);
|
||||
<< makeKeyValueReference("key_name", mKeyName)
|
||||
<< makeKeyValueReference("prev_is_bad", mPrevIsBad);
|
||||
resp.mStateToken = mStateToken;
|
||||
resp.setOk();
|
||||
}
|
||||
|
@ -77,6 +77,7 @@ private:
|
||||
// to notify that a password callback is waiting
|
||||
// to answer the request, clear the flag and set the password
|
||||
bool mWantPassword;
|
||||
bool mPrevIsBad;
|
||||
std::string mTitle;
|
||||
std::string mKeyName;
|
||||
std::string mPassword;
|
||||
|
Loading…
Reference in New Issue
Block a user