Browse Source

Fix for #42, #26

pull/82/head
nonlin-lin-chaos-order-etc-etal 1 year 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() {
return true; return true;
} }
void DelayedSaveManagerImpl::saveNow() {
assert(isSaverValid());
saver->save(isReloadAfterSave(), FocusEnum::noFocus);
}
DelayedSaveThread::DelayedSaveThread(DelayedSaveManagerImpl* delayedSaveManagerImpl_): DelayedSaveThread::DelayedSaveThread(DelayedSaveManagerImpl* delayedSaveManagerImpl_):
delayedSaveManagerImpl(delayedSaveManagerImpl_), delayedSaveManagerImpl(delayedSaveManagerImpl_),
mutex(new QMutex()), mutex(new QMutex()),

1
src/DelayedSaveManagerImpl.h

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

14
src/TunnelConfig.h

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

5
src/mainwindow.cpp

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

37
src/mainwindow.h

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

Loading…
Cancel
Save