mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-28 17:09:34 -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("set_state_string", this, &PeersHandler::handleSetStateString);
|
||||||
addResourceHandler("get_custom_state_string", this, &PeersHandler::handleGetCustomStateString);
|
addResourceHandler("get_custom_state_string", this, &PeersHandler::handleGetCustomStateString);
|
||||||
addResourceHandler("set_custom_state_string", this, &PeersHandler::handleSetCustomStateString);
|
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);
|
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()
|
StateToken PeersHandler::getCurrentStateToken()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
@ -41,6 +41,9 @@ private:
|
|||||||
void handleGetCustomStateString(Request& req, Response& resp);
|
void handleGetCustomStateString(Request& req, Response& resp);
|
||||||
void handleSetCustomStateString(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
|
// a helper which ensures proper mutex locking
|
||||||
StateToken getCurrentStateToken();
|
StateToken getCurrentStateToken();
|
||||||
|
|
||||||
|
@ -24,7 +24,9 @@ RsControlModule::RsControlModule(int argc, char **argv, StateTokenServer* sts, A
|
|||||||
mDataMtx("RsControlModule::mDataMtx"),
|
mDataMtx("RsControlModule::mDataMtx"),
|
||||||
mRunState(WAITING_INIT),
|
mRunState(WAITING_INIT),
|
||||||
mAutoLoginNextTime(false),
|
mAutoLoginNextTime(false),
|
||||||
mWantPassword(false)
|
mWantPassword(false),
|
||||||
|
mPassword(""),
|
||||||
|
mPrevIsBad(false)
|
||||||
{
|
{
|
||||||
mStateToken = sts->getNewToken();
|
mStateToken = sts->getNewToken();
|
||||||
this->argc = argc;
|
this->argc = argc;
|
||||||
@ -56,11 +58,14 @@ bool RsControlModule::processShouldExit()
|
|||||||
return mProcessShouldExit;
|
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 ;
|
cancelled = false ;
|
||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mDataMtx); // ********** LOCKED **********
|
RS_STACK_MUTEX(mDataMtx); // ********** LOCKED **********
|
||||||
|
|
||||||
|
mPrevIsBad = prev_is_bad;
|
||||||
|
|
||||||
if(mFixedPassword != "")
|
if(mFixedPassword != "")
|
||||||
{
|
{
|
||||||
password = mFixedPassword;
|
password = mFixedPassword;
|
||||||
@ -70,25 +75,31 @@ bool RsControlModule::askForPassword(const std::string &title, const std::string
|
|||||||
mWantPassword = true;
|
mWantPassword = true;
|
||||||
mTitle = title;
|
mTitle = title;
|
||||||
mKeyName = key_details;
|
mKeyName = key_details;
|
||||||
mPassword = "";
|
|
||||||
|
if(mPassword != "")
|
||||||
|
{
|
||||||
|
password = mPassword;
|
||||||
|
mWantPassword = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
mStateTokenServer->replaceToken(mStateToken);
|
mStateTokenServer->replaceToken(mStateToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wait = true;
|
int i = 0;
|
||||||
while(wait)
|
while(i<100)
|
||||||
{
|
{
|
||||||
usleep(5*1000);
|
usleep(5*1000);
|
||||||
|
|
||||||
RS_STACK_MUTEX(mDataMtx); // ********** LOCKED **********
|
RS_STACK_MUTEX(mDataMtx); // ********** LOCKED **********
|
||||||
wait = mWantPassword;
|
|
||||||
if(!wait && mPassword != "")
|
if(mPassword != "")
|
||||||
{
|
{
|
||||||
password = mPassword;
|
password = mPassword;
|
||||||
mPassword = "";
|
|
||||||
mWantPassword = false;
|
mWantPassword = false;
|
||||||
mStateTokenServer->replaceToken(mStateToken);
|
mStateTokenServer->replaceToken(mStateToken);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -125,6 +136,11 @@ void RsControlModule::run()
|
|||||||
bool login_ok = false;
|
bool login_ok = false;
|
||||||
while(!login_ok)
|
while(!login_ok)
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mDataMtx); // ********** LOCKED **********
|
||||||
|
mPassword = "";
|
||||||
|
}
|
||||||
|
|
||||||
// skip account selection if autologin is available
|
// skip account selection if autologin is available
|
||||||
if(initResult != RS_INIT_HAVE_ACCOUNT)
|
if(initResult != RS_INIT_HAVE_ACCOUNT)
|
||||||
setRunState(WAITING_ACCOUNT_SELECT);
|
setRunState(WAITING_ACCOUNT_SELECT);
|
||||||
@ -175,6 +191,17 @@ void RsControlModule::run()
|
|||||||
std::cerr << "RsControlModule::run() LockAndLoadCertificates failed. Unexpected switch value: " << retVal << std::endl;
|
std::cerr << "RsControlModule::run() LockAndLoadCertificates failed. Unexpected switch value: " << retVal << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mDataMtx); // ********** LOCKED **********
|
||||||
|
mLoadPeerId.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mDataMtx); // ********** LOCKED **********
|
||||||
|
mFixedPassword = mPassword;
|
||||||
|
mPassword = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
setRunState(WAITING_STARTUP);
|
setRunState(WAITING_STARTUP);
|
||||||
@ -302,12 +329,12 @@ void RsControlModule::handlePassword(Request &req, Response &resp)
|
|||||||
mPassword = passwd;
|
mPassword = passwd;
|
||||||
mWantPassword = false;
|
mWantPassword = false;
|
||||||
mStateTokenServer->replaceToken(mStateToken);
|
mStateTokenServer->replaceToken(mStateToken);
|
||||||
mFixedPassword = passwd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.mDataStream
|
resp.mDataStream
|
||||||
<< makeKeyValueReference("want_password", mWantPassword)
|
<< makeKeyValueReference("want_password", mWantPassword)
|
||||||
<< makeKeyValueReference("key_name", mKeyName);
|
<< makeKeyValueReference("key_name", mKeyName)
|
||||||
|
<< makeKeyValueReference("prev_is_bad", mPrevIsBad);
|
||||||
resp.mStateToken = mStateToken;
|
resp.mStateToken = mStateToken;
|
||||||
resp.setOk();
|
resp.setOk();
|
||||||
}
|
}
|
||||||
|
@ -77,6 +77,7 @@ private:
|
|||||||
// to notify that a password callback is waiting
|
// to notify that a password callback is waiting
|
||||||
// to answer the request, clear the flag and set the password
|
// to answer the request, clear the flag and set the password
|
||||||
bool mWantPassword;
|
bool mWantPassword;
|
||||||
|
bool mPrevIsBad;
|
||||||
std::string mTitle;
|
std::string mTitle;
|
||||||
std::string mKeyName;
|
std::string mKeyName;
|
||||||
std::string mPassword;
|
std::string mPassword;
|
||||||
|
Loading…
Reference in New Issue
Block a user