mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-23 22:01:05 -05:00
i2p: bob: convert bobSettings to i2p::settings
This commit is contained in:
parent
4b6e12ca45
commit
6136416b56
@ -1724,7 +1724,7 @@ int RsServer::StartupRetroShare()
|
||||
// now enable bob
|
||||
bobSettings bs;
|
||||
autoProxy->taskSync(autoProxyType::I2PBOB, autoProxyTask::getSettings, &bs);
|
||||
bs.enableBob = true;
|
||||
bs.enable = true;
|
||||
autoProxy->taskSync(autoProxyType::I2PBOB, autoProxyTask::setSettings, &bs);
|
||||
} else {
|
||||
std::cerr << "RsServer::StartupRetroShare failed to receive keys" << std::endl;
|
||||
|
@ -74,15 +74,7 @@ p3I2pBob::p3I2pBob(p3PeerMgr *peerMgr)
|
||||
mProcessing(NULL), mLock("I2P-BOB")
|
||||
{
|
||||
// set defaults
|
||||
mSetting.enableBob = kDefaultBOBEnable;
|
||||
mSetting.keys = "";
|
||||
mSetting.addr = "";
|
||||
mSetting.inLength = kDefaultLength;
|
||||
mSetting.inQuantity = kDefaultQuantity;
|
||||
mSetting.inVariance = kDefaultVariance;
|
||||
mSetting.outLength = kDefaultLength;
|
||||
mSetting.outQuantity = kDefaultQuantity;
|
||||
mSetting.outVariance = kDefaultVariance;
|
||||
mSetting.initDefault();
|
||||
|
||||
mCommands.clear();
|
||||
}
|
||||
@ -90,7 +82,7 @@ p3I2pBob::p3I2pBob(p3PeerMgr *peerMgr)
|
||||
bool p3I2pBob::isEnabled()
|
||||
{
|
||||
RS_STACK_MUTEX(mLock);
|
||||
return mSetting.enableBob;
|
||||
return mSetting.enable;
|
||||
}
|
||||
|
||||
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);
|
||||
addr = mSetting.addr;
|
||||
addr = mSetting.address.base32;
|
||||
}
|
||||
|
||||
std::cout << "p3I2pBob::initialSetup addr '" << addr << "'" << std::endl;
|
||||
@ -324,12 +316,12 @@ int p3I2pBob::stateMachineBOB()
|
||||
switch (mBOBState) {
|
||||
case bsNewkeysN:
|
||||
key = answer.substr(3, answer.length()-3);
|
||||
mSetting.addr = i2p::keyToBase32Addr(key);
|
||||
mSetting.address.base32 = i2p::keyToBase32Addr(key);
|
||||
IndicateConfigChanged();
|
||||
break;
|
||||
case bsGetkeys:
|
||||
key = answer.substr(3, answer.length()-3);
|
||||
mSetting.keys = key;
|
||||
mSetting.address.privateKey = key;
|
||||
IndicateConfigChanged();
|
||||
break;
|
||||
default:
|
||||
@ -465,7 +457,7 @@ int p3I2pBob::stateMachineController_locked_idle()
|
||||
mProcessing = mPending.front();
|
||||
mPending.pop();
|
||||
|
||||
if (!mSetting.enableBob && (
|
||||
if (!mSetting.enable && (
|
||||
mProcessing->task == autoProxyTask::start ||
|
||||
mProcessing->task == autoProxyTask::stop ||
|
||||
mProcessing->task == autoProxyTask::proxyStatusCheck)) {
|
||||
@ -539,7 +531,7 @@ int p3I2pBob::stateMachineController_locked_connected()
|
||||
switch (mTask) {
|
||||
case ctRunSetUp:
|
||||
// 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");
|
||||
mBOBState = bsSetnickC;
|
||||
} else {
|
||||
@ -750,9 +742,9 @@ bool p3I2pBob::saveList(bool &cleanup, std::list<RsItem *> &lst)
|
||||
RsTlvKeyValue kv;
|
||||
|
||||
RS_STACK_MUTEX(mLock);
|
||||
addKVS(vitem, kv, kConfigKeyBOBEnable, mSetting.enableBob ? "TRUE" : "FALSE")
|
||||
addKVS(vitem, kv, kConfigKeyBOBKey, mSetting.keys)
|
||||
addKVS(vitem, kv, kConfigKeyBOBAddr, mSetting.addr)
|
||||
addKVS(vitem, kv, kConfigKeyBOBEnable, mSetting.enable ? "TRUE" : "FALSE")
|
||||
addKVS(vitem, kv, kConfigKeyBOBKey, mSetting.address.privateKey)
|
||||
addKVS(vitem, kv, kConfigKeyBOBAddr, mSetting.address.base32)
|
||||
addKVSInt(vitem, kv, kConfigKeyInLength, mSetting.inLength)
|
||||
addKVSInt(vitem, kv, kConfigKeyInQuantity, mSetting.inQuantity)
|
||||
addKVSInt(vitem, kv, kConfigKeyInVariance, mSetting.inVariance)
|
||||
@ -786,11 +778,11 @@ bool p3I2pBob::loadList(std::list<RsItem *> &load)
|
||||
RS_STACK_MUTEX(mLock);
|
||||
for(std::list<RsTlvKeyValue>::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit) {
|
||||
if (kit->key == kConfigKeyBOBEnable)
|
||||
mSetting.enableBob = kit->value == "TRUE";
|
||||
mSetting.enable = kit->value == "TRUE";
|
||||
else if (kit->key == kConfigKeyBOBKey)
|
||||
mSetting.keys = kit->value;
|
||||
mSetting.address.privateKey = kit->value;
|
||||
else if (kit->key == kConfigKeyBOBAddr)
|
||||
mSetting.addr = kit->value;
|
||||
mSetting.address.base32 = kit->value;
|
||||
getKVSUInt(kit, kConfigKeyInLength, mSetting.inLength)
|
||||
getKVSUInt(kit, kConfigKeyInQuantity, mSetting.inQuantity)
|
||||
getKVSUInt(kit, kConfigKeyInVariance, mSetting.inVariance)
|
||||
@ -958,7 +950,7 @@ void p3I2pBob::finalizeSettings_locked()
|
||||
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 " + mSetting.addr);
|
||||
rslog(RsLog::Debug_Basic, &i2pBobLogInfo, "finalizeSettings_locked using " + mSetting.address.base32);
|
||||
|
||||
peerState ps;
|
||||
mPeerMgr->getOwnNetStatus(ps);
|
||||
@ -980,7 +972,7 @@ void p3I2pBob::finalizeSettings_locked()
|
||||
const std::string getnick = "getnick RetroShare-" + location;
|
||||
const std::string newkeys = "newkeys";
|
||||
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 inport = toString("inport ", sockaddr_storage_port(proxy));
|
||||
const std::string outhost = "outhost " + sockaddr_storage_iptostring(ps.localaddr);
|
||||
@ -1049,7 +1041,7 @@ void p3I2pBob::updateSettings_locked()
|
||||
peerState 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 inport = toString("inport ", sockaddr_storage_port(proxy));
|
||||
const std::string outhost = "outhost " + sockaddr_storage_iptostring(ps.localaddr);
|
||||
|
@ -163,19 +163,7 @@ struct bobStateInfo {
|
||||
bobState nextState;
|
||||
};
|
||||
|
||||
struct bobSettings {
|
||||
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;
|
||||
};
|
||||
struct bobSettings : i2p::settings {};
|
||||
|
||||
///
|
||||
/// \brief The bobStates struct
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <gui/notifyqt.h>
|
||||
#include "rshare.h"
|
||||
#include "rsharesettings.h"
|
||||
#include "util/i2pcommon.h"
|
||||
#include "util/RsNetUtil.h"
|
||||
#include "util/misc.h"
|
||||
|
||||
@ -1352,7 +1353,7 @@ void ServerPage::updateInProxyIndicator()
|
||||
ui.iconlabel_service_incoming->setMovie(movie);
|
||||
movie->start();
|
||||
|
||||
if (mHiddenType == RS_HIDDEN_TYPE_I2P && mBobSettings.enableBob) {
|
||||
if (mHiddenType == RS_HIDDEN_TYPE_I2P && mBobSettings.enable) {
|
||||
|
||||
QTcpSocket tcpSocket;
|
||||
|
||||
@ -1439,15 +1440,16 @@ void ServerPage::getNewKey()
|
||||
|
||||
void ServerPage::loadKey()
|
||||
{
|
||||
mBobSettings.keys = ui.pteBobServerKey->toPlainText().toStdString();
|
||||
mBobSettings.addr = p3I2pBob::keyToBase32Addr(mBobSettings.keys);
|
||||
mBobSettings.address.privateKey = ui.pteBobServerKey->toPlainText().toStdString();
|
||||
mBobSettings.address.publicKey = i2p::publicKeyFromPrivate(mBobSettings.address.privateKey);
|
||||
mBobSettings.address.base32 = i2p::keyToBase32Addr(mBobSettings.address.publicKey);
|
||||
|
||||
rsAutoProxyMonitor::taskSync(autoProxyType::I2PBOB, autoProxyTask::setSettings, &mBobSettings);
|
||||
}
|
||||
|
||||
void ServerPage::enableBob(bool checked)
|
||||
{
|
||||
mBobSettings.enableBob = checked;
|
||||
mBobSettings.enable = checked;
|
||||
|
||||
rsAutoProxyMonitor::taskSync(autoProxyType::I2PBOB, autoProxyTask::setSettings, &mBobSettings);
|
||||
|
||||
@ -1487,7 +1489,7 @@ void ServerPage::toggleBobAdvancedSettings(bool checked)
|
||||
{
|
||||
ui.swBobAdvanced->setCurrentIndex(checked ? 1 : 0);
|
||||
|
||||
if (!mBobSettings.keys.empty()) {
|
||||
if (!mBobSettings.address.privateKey.empty()) {
|
||||
if (checked) {
|
||||
ui.pbBobGenAddr->show();
|
||||
} else {
|
||||
@ -1578,9 +1580,9 @@ void ServerPage::loadCommon()
|
||||
whileBlocking(ui.hiddenpage_proxyPort_i2p_2)->setValue(proxyport); // this one is for bob tab
|
||||
|
||||
// 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.leBobB32Addr->show();
|
||||
}
|
||||
@ -1623,13 +1625,13 @@ void ServerPage::saveBob()
|
||||
|
||||
void ServerPage::updateStatusBob()
|
||||
{
|
||||
QString addr = QString::fromStdString(mBobSettings.addr);
|
||||
QString addr = QString::fromStdString(mBobSettings.address.base32);
|
||||
if (ui.leBobB32Addr->text() != addr) {
|
||||
ui.leBobB32Addr->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
|
||||
ui.lBobB32Addr->show();
|
||||
ui.leBobB32Addr->show();
|
||||
@ -1655,7 +1657,7 @@ void ServerPage::updateStatusBob()
|
||||
QString bobSimpleText = QString();
|
||||
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").
|
||||
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_proxyPort_i2p_2->text(),
|
||||
bs.tunnelName.empty() ? tr("unknown") :
|
||||
@ -1777,15 +1779,15 @@ void ServerPage::updateStatusBob()
|
||||
|
||||
void ServerPage::setUpBobElements()
|
||||
{
|
||||
ui.gbBob->setEnabled(mBobSettings.enableBob);
|
||||
if (mBobSettings.enableBob) {
|
||||
ui.gbBob->setEnabled(mBobSettings.enable);
|
||||
if (mBobSettings.enable) {
|
||||
ui.hiddenpage_proxyAddress_i2p->setEnabled(false);
|
||||
ui.hiddenpage_proxyAddress_i2p->setToolTip("Use I2P/BOB settings to change this value");
|
||||
ui.hiddenpage_proxyPort_i2p->setEnabled(false);
|
||||
ui.hiddenpage_proxyPort_i2p->setToolTip("Use I2P/BOB settings to change this value");
|
||||
|
||||
ui.leBobB32Addr->setText(QString::fromStdString(mBobSettings.addr));
|
||||
ui.pteBobServerKey->setPlainText(QString::fromStdString(mBobSettings.keys));
|
||||
ui.leBobB32Addr->setText(QString::fromStdString(mBobSettings.address.base32));
|
||||
ui.pteBobServerKey->setPlainText(QString::fromStdString(mBobSettings.address.privateKey));
|
||||
|
||||
// cast to int to avoid problems
|
||||
int li, lo, qi, qo, vi, vo;
|
||||
|
Loading…
Reference in New Issue
Block a user