i2p: bob: convert bobSettings to i2p::settings

This commit is contained in:
sehraf 2020-05-08 16:33:47 +02:00
parent 4b6e12ca45
commit 6136416b56
No known key found for this signature in database
GPG Key ID: DF09F6EAE356B2C6
4 changed files with 35 additions and 53 deletions

View File

@ -1724,7 +1724,7 @@ int RsServer::StartupRetroShare()
// now enable bob // now enable bob
bobSettings bs; bobSettings bs;
autoProxy->taskSync(autoProxyType::I2PBOB, autoProxyTask::getSettings, &bs); autoProxy->taskSync(autoProxyType::I2PBOB, autoProxyTask::getSettings, &bs);
bs.enableBob = true; bs.enable = true;
autoProxy->taskSync(autoProxyType::I2PBOB, autoProxyTask::setSettings, &bs); autoProxy->taskSync(autoProxyType::I2PBOB, autoProxyTask::setSettings, &bs);
} else { } else {
std::cerr << "RsServer::StartupRetroShare failed to receive keys" << std::endl; std::cerr << "RsServer::StartupRetroShare failed to receive keys" << std::endl;

View File

@ -74,15 +74,7 @@ p3I2pBob::p3I2pBob(p3PeerMgr *peerMgr)
mProcessing(NULL), mLock("I2P-BOB") mProcessing(NULL), mLock("I2P-BOB")
{ {
// set defaults // set defaults
mSetting.enableBob = kDefaultBOBEnable; mSetting.initDefault();
mSetting.keys = "";
mSetting.addr = "";
mSetting.inLength = kDefaultLength;
mSetting.inQuantity = kDefaultQuantity;
mSetting.inVariance = kDefaultVariance;
mSetting.outLength = kDefaultLength;
mSetting.outQuantity = kDefaultQuantity;
mSetting.outVariance = kDefaultVariance;
mCommands.clear(); mCommands.clear();
} }
@ -90,7 +82,7 @@ p3I2pBob::p3I2pBob(p3PeerMgr *peerMgr)
bool p3I2pBob::isEnabled() bool p3I2pBob::isEnabled()
{ {
RS_STACK_MUTEX(mLock); RS_STACK_MUTEX(mLock);
return mSetting.enableBob; return mSetting.enable;
} }
bool p3I2pBob::initialSetup(std::string &addr, uint16_t &/*port*/) bool p3I2pBob::initialSetup(std::string &addr, uint16_t &/*port*/)
@ -151,7 +143,7 @@ bool p3I2pBob::initialSetup(std::string &addr, uint16_t &/*port*/)
{ {
RS_STACK_MUTEX(mLock); RS_STACK_MUTEX(mLock);
addr = mSetting.addr; addr = mSetting.address.base32;
} }
std::cout << "p3I2pBob::initialSetup addr '" << addr << "'" << std::endl; std::cout << "p3I2pBob::initialSetup addr '" << addr << "'" << std::endl;
@ -324,12 +316,12 @@ int p3I2pBob::stateMachineBOB()
switch (mBOBState) { switch (mBOBState) {
case bsNewkeysN: case bsNewkeysN:
key = answer.substr(3, answer.length()-3); key = answer.substr(3, answer.length()-3);
mSetting.addr = i2p::keyToBase32Addr(key); mSetting.address.base32 = i2p::keyToBase32Addr(key);
IndicateConfigChanged(); IndicateConfigChanged();
break; break;
case bsGetkeys: case bsGetkeys:
key = answer.substr(3, answer.length()-3); key = answer.substr(3, answer.length()-3);
mSetting.keys = key; mSetting.address.privateKey = key;
IndicateConfigChanged(); IndicateConfigChanged();
break; break;
default: default:
@ -465,7 +457,7 @@ int p3I2pBob::stateMachineController_locked_idle()
mProcessing = mPending.front(); mProcessing = mPending.front();
mPending.pop(); mPending.pop();
if (!mSetting.enableBob && ( if (!mSetting.enable && (
mProcessing->task == autoProxyTask::start || mProcessing->task == autoProxyTask::start ||
mProcessing->task == autoProxyTask::stop || mProcessing->task == autoProxyTask::stop ||
mProcessing->task == autoProxyTask::proxyStatusCheck)) { mProcessing->task == autoProxyTask::proxyStatusCheck)) {
@ -539,7 +531,7 @@ int p3I2pBob::stateMachineController_locked_connected()
switch (mTask) { switch (mTask) {
case ctRunSetUp: case ctRunSetUp:
// when we have a key use it for server tunnel! // when we have a key use it for server tunnel!
if(mSetting.keys.empty()) { if(mSetting.address.privateKey.empty()) {
rslog(RsLog::Debug_Basic, &i2pBobLogInfo, "stateMachineController_locked_connected: setting mBOBState = setnickC"); rslog(RsLog::Debug_Basic, &i2pBobLogInfo, "stateMachineController_locked_connected: setting mBOBState = setnickC");
mBOBState = bsSetnickC; mBOBState = bsSetnickC;
} else { } else {
@ -750,9 +742,9 @@ bool p3I2pBob::saveList(bool &cleanup, std::list<RsItem *> &lst)
RsTlvKeyValue kv; RsTlvKeyValue kv;
RS_STACK_MUTEX(mLock); RS_STACK_MUTEX(mLock);
addKVS(vitem, kv, kConfigKeyBOBEnable, mSetting.enableBob ? "TRUE" : "FALSE") addKVS(vitem, kv, kConfigKeyBOBEnable, mSetting.enable ? "TRUE" : "FALSE")
addKVS(vitem, kv, kConfigKeyBOBKey, mSetting.keys) addKVS(vitem, kv, kConfigKeyBOBKey, mSetting.address.privateKey)
addKVS(vitem, kv, kConfigKeyBOBAddr, mSetting.addr) addKVS(vitem, kv, kConfigKeyBOBAddr, mSetting.address.base32)
addKVSInt(vitem, kv, kConfigKeyInLength, mSetting.inLength) addKVSInt(vitem, kv, kConfigKeyInLength, mSetting.inLength)
addKVSInt(vitem, kv, kConfigKeyInQuantity, mSetting.inQuantity) addKVSInt(vitem, kv, kConfigKeyInQuantity, mSetting.inQuantity)
addKVSInt(vitem, kv, kConfigKeyInVariance, mSetting.inVariance) addKVSInt(vitem, kv, kConfigKeyInVariance, mSetting.inVariance)
@ -786,11 +778,11 @@ bool p3I2pBob::loadList(std::list<RsItem *> &load)
RS_STACK_MUTEX(mLock); RS_STACK_MUTEX(mLock);
for(std::list<RsTlvKeyValue>::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit) { for(std::list<RsTlvKeyValue>::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit) {
if (kit->key == kConfigKeyBOBEnable) if (kit->key == kConfigKeyBOBEnable)
mSetting.enableBob = kit->value == "TRUE"; mSetting.enable = kit->value == "TRUE";
else if (kit->key == kConfigKeyBOBKey) else if (kit->key == kConfigKeyBOBKey)
mSetting.keys = kit->value; mSetting.address.privateKey = kit->value;
else if (kit->key == kConfigKeyBOBAddr) else if (kit->key == kConfigKeyBOBAddr)
mSetting.addr = kit->value; mSetting.address.base32 = kit->value;
getKVSUInt(kit, kConfigKeyInLength, mSetting.inLength) getKVSUInt(kit, kConfigKeyInLength, mSetting.inLength)
getKVSUInt(kit, kConfigKeyInQuantity, mSetting.inQuantity) getKVSUInt(kit, kConfigKeyInQuantity, mSetting.inQuantity)
getKVSUInt(kit, kConfigKeyInVariance, mSetting.inVariance) getKVSUInt(kit, kConfigKeyInVariance, mSetting.inVariance)
@ -958,7 +950,7 @@ void p3I2pBob::finalizeSettings_locked()
sockaddr_storage_setport(mI2PProxyAddr, 2827); sockaddr_storage_setport(mI2PProxyAddr, 2827);
rslog(RsLog::Debug_Basic, &i2pBobLogInfo, "finalizeSettings_locked using " + sockaddr_storage_tostring(mI2PProxyAddr)); rslog(RsLog::Debug_Basic, &i2pBobLogInfo, "finalizeSettings_locked using " + sockaddr_storage_tostring(mI2PProxyAddr));
rslog(RsLog::Debug_Basic, &i2pBobLogInfo, "finalizeSettings_locked using " + mSetting.addr); rslog(RsLog::Debug_Basic, &i2pBobLogInfo, "finalizeSettings_locked using " + mSetting.address.base32);
peerState ps; peerState ps;
mPeerMgr->getOwnNetStatus(ps); mPeerMgr->getOwnNetStatus(ps);
@ -980,7 +972,7 @@ void p3I2pBob::finalizeSettings_locked()
const std::string getnick = "getnick RetroShare-" + location; const std::string getnick = "getnick RetroShare-" + location;
const std::string newkeys = "newkeys"; const std::string newkeys = "newkeys";
const std::string getkeys = "getkeys"; const std::string getkeys = "getkeys";
const std::string setkeys = "setkeys " + mSetting.keys; const std::string setkeys = "setkeys " + mSetting.address.privateKey;
const std::string inhost = "inhost " + sockaddr_storage_iptostring(proxy); const std::string inhost = "inhost " + sockaddr_storage_iptostring(proxy);
const std::string inport = toString("inport ", sockaddr_storage_port(proxy)); const std::string inport = toString("inport ", sockaddr_storage_port(proxy));
const std::string outhost = "outhost " + sockaddr_storage_iptostring(ps.localaddr); const std::string outhost = "outhost " + sockaddr_storage_iptostring(ps.localaddr);
@ -1049,7 +1041,7 @@ void p3I2pBob::updateSettings_locked()
peerState ps; peerState ps;
mPeerMgr->getOwnNetStatus(ps); mPeerMgr->getOwnNetStatus(ps);
const std::string setkeys = "setkeys " + mSetting.keys; const std::string setkeys = "setkeys " + mSetting.address.privateKey;
const std::string inhost = "inhost " + sockaddr_storage_iptostring(proxy); const std::string inhost = "inhost " + sockaddr_storage_iptostring(proxy);
const std::string inport = toString("inport ", sockaddr_storage_port(proxy)); const std::string inport = toString("inport ", sockaddr_storage_port(proxy));
const std::string outhost = "outhost " + sockaddr_storage_iptostring(ps.localaddr); const std::string outhost = "outhost " + sockaddr_storage_iptostring(ps.localaddr);

View File

@ -163,19 +163,7 @@ struct bobStateInfo {
bobState nextState; bobState nextState;
}; };
struct bobSettings { struct bobSettings : i2p::settings {};
bool enableBob; ///< This field is used by the pqi subsystem to determinine whether SOCKS proxy or BOB is used for I2P connections
std::string keys; ///< (optional) server keys
std::string addr; ///< (optional) hidden service addr. in base32 form
int8_t inLength;
int8_t inQuantity;
int8_t inVariance;
int8_t outLength;
int8_t outQuantity;
int8_t outVariance;
};
/// ///
/// \brief The bobStates struct /// \brief The bobStates struct

View File

@ -23,6 +23,7 @@
#include <gui/notifyqt.h> #include <gui/notifyqt.h>
#include "rshare.h" #include "rshare.h"
#include "rsharesettings.h" #include "rsharesettings.h"
#include "util/i2pcommon.h"
#include "util/RsNetUtil.h" #include "util/RsNetUtil.h"
#include "util/misc.h" #include "util/misc.h"
@ -1352,7 +1353,7 @@ void ServerPage::updateInProxyIndicator()
ui.iconlabel_service_incoming->setMovie(movie); ui.iconlabel_service_incoming->setMovie(movie);
movie->start(); movie->start();
if (mHiddenType == RS_HIDDEN_TYPE_I2P && mBobSettings.enableBob) { if (mHiddenType == RS_HIDDEN_TYPE_I2P && mBobSettings.enable) {
QTcpSocket tcpSocket; QTcpSocket tcpSocket;
@ -1439,15 +1440,16 @@ void ServerPage::getNewKey()
void ServerPage::loadKey() void ServerPage::loadKey()
{ {
mBobSettings.keys = ui.pteBobServerKey->toPlainText().toStdString(); mBobSettings.address.privateKey = ui.pteBobServerKey->toPlainText().toStdString();
mBobSettings.addr = p3I2pBob::keyToBase32Addr(mBobSettings.keys); mBobSettings.address.publicKey = i2p::publicKeyFromPrivate(mBobSettings.address.privateKey);
mBobSettings.address.base32 = i2p::keyToBase32Addr(mBobSettings.address.publicKey);
rsAutoProxyMonitor::taskSync(autoProxyType::I2PBOB, autoProxyTask::setSettings, &mBobSettings); rsAutoProxyMonitor::taskSync(autoProxyType::I2PBOB, autoProxyTask::setSettings, &mBobSettings);
} }
void ServerPage::enableBob(bool checked) void ServerPage::enableBob(bool checked)
{ {
mBobSettings.enableBob = checked; mBobSettings.enable = checked;
rsAutoProxyMonitor::taskSync(autoProxyType::I2PBOB, autoProxyTask::setSettings, &mBobSettings); rsAutoProxyMonitor::taskSync(autoProxyType::I2PBOB, autoProxyTask::setSettings, &mBobSettings);
@ -1487,7 +1489,7 @@ void ServerPage::toggleBobAdvancedSettings(bool checked)
{ {
ui.swBobAdvanced->setCurrentIndex(checked ? 1 : 0); ui.swBobAdvanced->setCurrentIndex(checked ? 1 : 0);
if (!mBobSettings.keys.empty()) { if (!mBobSettings.address.privateKey.empty()) {
if (checked) { if (checked) {
ui.pbBobGenAddr->show(); ui.pbBobGenAddr->show();
} else { } else {
@ -1578,9 +1580,9 @@ void ServerPage::loadCommon()
whileBlocking(ui.hiddenpage_proxyPort_i2p_2)->setValue(proxyport); // this one is for bob tab whileBlocking(ui.hiddenpage_proxyPort_i2p_2)->setValue(proxyport); // this one is for bob tab
// don't use whileBlocking here // don't use whileBlocking here
ui.cb_enableBob->setChecked(mBobSettings.enableBob); ui.cb_enableBob->setChecked(mBobSettings.enable);
if (!mBobSettings.keys.empty()) { if (!mBobSettings.address.privateKey.empty()) {
ui.lBobB32Addr->show(); ui.lBobB32Addr->show();
ui.leBobB32Addr->show(); ui.leBobB32Addr->show();
} }
@ -1623,13 +1625,13 @@ void ServerPage::saveBob()
void ServerPage::updateStatusBob() void ServerPage::updateStatusBob()
{ {
QString addr = QString::fromStdString(mBobSettings.addr); QString addr = QString::fromStdString(mBobSettings.address.base32);
if (ui.leBobB32Addr->text() != addr) { if (ui.leBobB32Addr->text() != addr) {
ui.leBobB32Addr->setText(addr); ui.leBobB32Addr->setText(addr);
ui.hiddenpage_serviceAddress->setText(addr); ui.hiddenpage_serviceAddress->setText(addr);
ui.pteBobServerKey->setPlainText(QString::fromStdString(mBobSettings.keys)); ui.pteBobServerKey->setPlainText(QString::fromStdString(mBobSettings.address.privateKey));
if (!mBobSettings.keys.empty()) { if (!mBobSettings.address.privateKey.empty()) {
// we have an addr -> show fields // we have an addr -> show fields
ui.lBobB32Addr->show(); ui.lBobB32Addr->show();
ui.leBobB32Addr->show(); ui.leBobB32Addr->show();
@ -1655,7 +1657,7 @@ void ServerPage::updateStatusBob()
QString bobSimpleText = QString(); QString bobSimpleText = QString();
bobSimpleText.append(tr("RetroShare uses BOB to set up a %1 tunnel at %2:%3 (named %4)\n\n" bobSimpleText.append(tr("RetroShare uses BOB to set up a %1 tunnel at %2:%3 (named %4)\n\n"
"When changing options (e.g. port) use the buttons at the bottom to restart BOB.\n\n"). "When changing options (e.g. port) use the buttons at the bottom to restart BOB.\n\n").
arg(mBobSettings.keys.empty() ? tr("client") : tr("server"), arg(mBobSettings.address.privateKey.empty() ? tr("client") : tr("server"),
ui.hiddenpage_proxyAddress_i2p_2->text(), ui.hiddenpage_proxyAddress_i2p_2->text(),
ui.hiddenpage_proxyPort_i2p_2->text(), ui.hiddenpage_proxyPort_i2p_2->text(),
bs.tunnelName.empty() ? tr("unknown") : bs.tunnelName.empty() ? tr("unknown") :
@ -1777,15 +1779,15 @@ void ServerPage::updateStatusBob()
void ServerPage::setUpBobElements() void ServerPage::setUpBobElements()
{ {
ui.gbBob->setEnabled(mBobSettings.enableBob); ui.gbBob->setEnabled(mBobSettings.enable);
if (mBobSettings.enableBob) { if (mBobSettings.enable) {
ui.hiddenpage_proxyAddress_i2p->setEnabled(false); ui.hiddenpage_proxyAddress_i2p->setEnabled(false);
ui.hiddenpage_proxyAddress_i2p->setToolTip("Use I2P/BOB settings to change this value"); ui.hiddenpage_proxyAddress_i2p->setToolTip("Use I2P/BOB settings to change this value");
ui.hiddenpage_proxyPort_i2p->setEnabled(false); ui.hiddenpage_proxyPort_i2p->setEnabled(false);
ui.hiddenpage_proxyPort_i2p->setToolTip("Use I2P/BOB settings to change this value"); ui.hiddenpage_proxyPort_i2p->setToolTip("Use I2P/BOB settings to change this value");
ui.leBobB32Addr->setText(QString::fromStdString(mBobSettings.addr)); ui.leBobB32Addr->setText(QString::fromStdString(mBobSettings.address.base32));
ui.pteBobServerKey->setPlainText(QString::fromStdString(mBobSettings.keys)); ui.pteBobServerKey->setPlainText(QString::fromStdString(mBobSettings.address.privateKey));
// cast to int to avoid problems // cast to int to avoid problems
int li, lo, qi, qo, vi, vo; int li, lo, qi, qo, vi, vo;