Browse Source

Fix for #42, #26

pull/82/head
nonlin-lin-chaos-order-etc-etal 2 years ago
parent
commit
1bf471fdfa
  1. 5
      src/DelayedSaveManagerImpl.cpp
  2. 1
      src/DelayedSaveManagerImpl.h
  3. 14
      src/TunnelConfig.h
  4. 5
      src/mainwindow.cpp
  5. 37
      src/mainwindow.h

5
src/DelayedSaveManagerImpl.cpp

@ -51,6 +51,11 @@ bool DelayedSaveManagerImpl::appExiting() { @@ -51,6 +51,11 @@ bool DelayedSaveManagerImpl::appExiting() {
return true;
}
void DelayedSaveManagerImpl::saveNow() {
assert(isSaverValid());
saver->save(isReloadAfterSave(), FocusEnum::noFocus);
}
DelayedSaveThread::DelayedSaveThread(DelayedSaveManagerImpl* delayedSaveManagerImpl_):
delayedSaveManagerImpl(delayedSaveManagerImpl_),
mutex(new QMutex()),

1
src/DelayedSaveManagerImpl.h

@ -53,6 +53,7 @@ public: @@ -53,6 +53,7 @@ public:
virtual void setSaver(Saver* saver);
virtual void start();
virtual void delayedSave(bool reloadAfterSave, DATA_SERIAL_TYPE dataSerial, FocusEnum focusOn, std::string tunnelNameToFocus, QWidget* widgetToFocus);
void saveNow();
virtual bool appExiting();
typedef DelayedSaveThread::TIMESTAMP_TYPE TIMESTAMP_TYPE;

14
src/TunnelConfig.h

@ -81,13 +81,15 @@ class TunnelConfig { @@ -81,13 +81,15 @@ class TunnelConfig {
*/
QString type;
std::string name;
int _tunnelId;
TunnelPane* tunnelPane;
int cryptoType;
public:
TunnelConfig(std::string name_, QString& type_, I2CPParameters& i2cpParameters_, int cryptoType_):
type(type_), name(name_), cryptoType(cryptoType_), i2cpParameters(i2cpParameters_) {}
TunnelConfig(int tunnelId, std::string name_, QString& type_, I2CPParameters& i2cpParameters_, int cryptoType_):
type(type_), name(name_), _tunnelId(tunnelId), cryptoType(cryptoType_), i2cpParameters(i2cpParameters_) {}
virtual ~TunnelConfig(){}
const QString& getType(){return type;}
int get_TunnelId(){return _tunnelId;}
const std::string& getName(){return name;}
int getcryptoType(){return cryptoType;}
void setType(const QString& type_){type=type_;}
@ -135,14 +137,14 @@ class ClientTunnelConfig : public TunnelConfig { @@ -135,14 +137,14 @@ class ClientTunnelConfig : public TunnelConfig {
int destinationPort;
i2p::data::SigningKeyType sigType;
public:
ClientTunnelConfig(std::string name_, QString type_, I2CPParameters& i2cpParameters_,
ClientTunnelConfig(int tunnelId, std::string name_, QString type_, I2CPParameters& i2cpParameters_,
std::string dest_,
int port_,
std::string keys_,
std::string address_,
int destinationPort_,
i2p::data::SigningKeyType sigType_,
int cryptoType_): TunnelConfig(name_, type_, i2cpParameters_, cryptoType_),
int cryptoType_): TunnelConfig(tunnelId, name_, type_, i2cpParameters_, cryptoType_),
dest(dest_),
port(port_),
keys(keys_),
@ -205,7 +207,7 @@ class ServerTunnelConfig : public TunnelConfig { @@ -205,7 +207,7 @@ class ServerTunnelConfig : public TunnelConfig {
std::string address;
bool isUniqueLocal;
public:
ServerTunnelConfig(std::string name_, QString type_, I2CPParameters& i2cpParameters_,
ServerTunnelConfig(int tunnelId, std::string name_, QString type_, I2CPParameters& i2cpParameters_,
std::string host_,
int port_,
std::string keys_,
@ -217,7 +219,7 @@ public: @@ -217,7 +219,7 @@ public:
i2p::data::SigningKeyType sigType_,
std::string address_,
bool isUniqueLocal_,
int cryptoType_): TunnelConfig(name_, type_, i2cpParameters_, cryptoType_),
int cryptoType_): TunnelConfig(tunnelId, name_, type_, i2cpParameters_, cryptoType_),
host(host_),
port(port_),
keys(keys_),

5
src/mainwindow.cpp

@ -68,6 +68,7 @@ MainWindow::MainWindow(std::shared_ptr<std::iostream> logStream_, QWidget *paren @@ -68,6 +68,7 @@ MainWindow::MainWindow(std::shared_ptr<std::iostream> logStream_, QWidget *paren
,confpath()
,tunconfpath()
,tunnelConfigs()
,tunnelConfigsById()
,tunnelsPageUpdateListener(this)
,preventSaveTunnelsBool(false)
,saverPtr(
@ -601,7 +602,7 @@ void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) { @@ -601,7 +602,7 @@ void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) {
setVisible(!isVisible());
break;
default:
qDebug() << "MainWindow::iconActivated(): unknown reason: " << reason << endl;
qDebug() << "MainWindow::iconActivated(): unknown reason: " << reason << Qt::endl;
break;
}
}
@ -973,7 +974,7 @@ void MainWindow::TunnelsPageUpdateListenerMainWindowImpl::updated(std::string ol @@ -973,7 +974,7 @@ void MainWindow::TunnelsPageUpdateListenerMainWindowImpl::updated(std::string ol
std::map<std::string,TunnelConfig*>::const_iterator it=mainWindow->tunnelConfigs.find(oldName);
if(it!=mainWindow->tunnelConfigs.end())mainWindow->tunnelConfigs.erase(it);
mainWindow->tunnelConfigs[tunConf->getName()]=tunConf;
mainWindow->saveAllConfigs(true, FocusEnum::focusOnTunnelName, tunConf->getName());
mainWindow->saveAllConfigs(false, FocusEnum::focusOnTunnelName, tunConf->getName());
}
else
mainWindow->saveAllConfigs(false, FocusEnum::noFocus);

37
src/mainwindow.h

@ -244,8 +244,7 @@ public: @@ -244,8 +244,7 @@ public:
virtual ~LogDestinationComboBoxItem(){}
virtual void loadFromConfigOption(){
MainWindowItem::loadFromConfigOption();
const char * ld = boost::any_cast<std::string>(optionValue).c_str();
comboBox->setCurrentText(QString(ld));
comboBox->setCurrentText(QString(boost::any_cast<std::string>(optionValue).c_str()));
}
virtual void saveToStringStream(std::stringstream& out){
std::string logDest = comboBox->currentText().toStdString();
@ -262,8 +261,7 @@ public: @@ -262,8 +261,7 @@ public:
virtual ~LogLevelComboBoxItem(){}
virtual void loadFromConfigOption(){
MainWindowItem::loadFromConfigOption();
const char * ll = boost::any_cast<std::string>(optionValue).c_str();
comboBox->setCurrentText(QString(ll));
comboBox->setCurrentText(QString(boost::any_cast<std::string>(optionValue).c_str()));
}
virtual void saveToStringStream(std::stringstream& out){
optionValue=comboBox->currentText().toStdString();
@ -573,6 +571,7 @@ private: @@ -573,6 +571,7 @@ private:
QString tunconfpath;
std::map<std::string, TunnelConfig*> tunnelConfigs;
std::map<int, TunnelConfig*> tunnelConfigsById;
std::list<TunnelPane*> tunnelPanes;
void appendTunnelForms(std::string tunnelNameToFocus);
@ -661,9 +660,11 @@ private: @@ -661,9 +660,11 @@ private:
TunnelConfig* tc=it->second;
deleteTunnelFromUI(name, tc);
tunnelConfigs.erase(it);
tunnelConfigsById.erase(tc->get_TunnelId());
delete tc;
}
saveAllConfigs(true, FocusEnum::noFocus);
delayedSaveManagerPtr->saveNow();
}
std::string GenerateNewTunnelName() {
@ -677,7 +678,16 @@ private: @@ -677,7 +678,16 @@ private:
}
}
int GenerateNewTunnelId() {
int i=1;
while(true){
if(tunnelConfigsById.find(i)==tunnelConfigsById.end())return i;
++i;
}
}
void CreateDefaultClientTunnel() {//TODO dedup default values with ReadTunnelsConfig() and with ClientContext.cpp::ReadTunnels ()
int tunnelId=GenerateNewTunnelId();
std::string name=GenerateNewTunnelName();
std::string type = I2P_TUNNELS_SECTION_TYPE_CLIENT;
std::string dest = "127.0.0.1";
@ -691,7 +701,9 @@ private: @@ -691,7 +701,9 @@ private:
I2CPParameters i2cpParameters;
CreateDefaultI2CPOptions (i2cpParameters);
tunnelConfigs[name]=new ClientTunnelConfig(name, QString(type.c_str()), i2cpParameters,
tunnelConfigs[name]=tunnelConfigsById[tunnelId]=new ClientTunnelConfig(
tunnelId,
name, QString(type.c_str()), i2cpParameters,
dest,
port,
keys,
@ -701,9 +713,11 @@ private: @@ -701,9 +713,11 @@ private:
cryptoType);
saveAllConfigs(true, FocusEnum::focusOnTunnelName, name);
delayedSaveManagerPtr->saveNow();
}
void CreateDefaultServerTunnel() {//TODO dedup default values with ReadTunnelsConfig() and with ClientContext.cpp::ReadTunnels ()
int tunnelId=GenerateNewTunnelId();
std::string name=GenerateNewTunnelName();
std::string type=I2P_TUNNELS_SECTION_TYPE_SERVER;
std::string host = "127.0.0.1";
@ -723,7 +737,9 @@ private: @@ -723,7 +737,9 @@ private:
I2CPParameters i2cpParameters;
CreateDefaultI2CPOptions (i2cpParameters);
tunnelConfigs[name]=new ServerTunnelConfig(name, QString(type.c_str()), i2cpParameters,
tunnelConfigs[name]=tunnelConfigsById[tunnelId]=new ServerTunnelConfig(
tunnelId,
name, QString(type.c_str()), i2cpParameters,
host,
port,
keys,
@ -739,6 +755,7 @@ private: @@ -739,6 +755,7 @@ private:
saveAllConfigs(true, FocusEnum::focusOnTunnelName, name);
delayedSaveManagerPtr->saveNow();
}
void ReadTunnelsConfig() //TODO deduplicate the code with ClientContext.cpp::ReadTunnels ()
@ -797,8 +814,10 @@ private: @@ -797,8 +814,10 @@ private:
std::map<std::string, std::string> options;
I2CPParameters i2cpParameters;
ReadI2CPOptions (section, options, i2cpParameters);
int tunnelId=GenerateNewTunnelId();
tunnelConfigs[name]=new ClientTunnelConfig(name, QString(type.c_str()), i2cpParameters,
tunnelConfigs[name]=tunnelConfigsById[tunnelId]=
new ClientTunnelConfig(tunnelId,name, QString(type.c_str()), i2cpParameters,
dest,
port,
keys,
@ -831,6 +850,7 @@ private: @@ -831,6 +850,7 @@ private:
std::map<std::string, std::string> options;
I2CPParameters i2cpParameters;
ReadI2CPOptions (section, options, i2cpParameters);
int tunnelId=GenerateNewTunnelId();
/*
std::set<i2p::data::IdentHash> idents;
@ -848,7 +868,8 @@ private: @@ -848,7 +868,8 @@ private:
while (comma != std::string::npos);
}
*/
tunnelConfigs[name]=new ServerTunnelConfig(name, QString(type.c_str()), i2cpParameters,
tunnelConfigs[name]=tunnelConfigsById[tunnelId]=
new ServerTunnelConfig(tunnelId,name, QString(type.c_str()), i2cpParameters,
host,
port,
keys,

Loading…
Cancel
Save