Merge pull request #2132 from sehraf/pr_add_i2p_sam3

Replace I2P BOB with SAMv3
This commit is contained in:
csoler 2021-10-24 20:39:22 +02:00 committed by GitHub
commit 3ddf3d0853
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 1797 additions and 1863 deletions

View file

@ -43,7 +43,7 @@
class p3heartbeat;
class p3discovery2;
class p3I2pBob;
class p3I2pSam3;
/* GXS Classes - just declare the classes.
so we don't have to totally recompile to switch */
@ -161,8 +161,8 @@ public:
p3ChatService *chatSrv;
p3StatusService *mStatusSrv;
p3GxsTunnelService *mGxsTunnels;
#ifdef RS_USE_I2P_BOB
p3I2pBob *mI2pBob;
#ifdef RS_USE_I2P_SAM3
p3I2pSam3 *mI2pSam3;
#endif
// This list contains all threaded services. It will be used to shut them down properly.

View file

@ -170,7 +170,7 @@ struct RsInitConfig
std::string hiddenNodeAddress;
uint16_t hiddenNodePort;
bool hiddenNodeI2PBOB;
bool hiddenNodeI2P;
/* Logging */
bool haveLogFile;
@ -664,13 +664,13 @@ void RsInit::setAutoLogin(bool autoLogin){
}
/* Setup Hidden Location; */
void RsInit::SetHiddenLocation(const std::string& hiddenaddress, uint16_t port, bool useBob)
void RsInit::SetHiddenLocation(const std::string& hiddenaddress, uint16_t port, bool useI2p)
{
/* parse the bugger (todo) */
rsInitConfig->hiddenNodeSet = true;
rsInitConfig->hiddenNodeAddress = hiddenaddress;
rsInitConfig->hiddenNodePort = port;
rsInitConfig->hiddenNodeI2PBOB = useBob;
rsInitConfig->hiddenNodeI2P = useI2p;
}
@ -717,7 +717,7 @@ RsGRouter *rsGRouter = NULL ;
# include "rs_upnp/upnphandler_miniupnp.h"
#endif // def RS_USE_LIBUPNP
#include "services/autoproxy/p3i2pbob.h"
#include "services/autoproxy/p3i2psam3.h"
#include "services/autoproxy/rsautoproxymonitor.h"
#include "services/p3gxsreputation.h"
@ -923,9 +923,9 @@ int RsServer::StartupRetroShare()
mNetMgr->setManagers(mPeerMgr, mLinkMgr);
rsAutoProxyMonitor *autoProxy = rsAutoProxyMonitor::instance();
#ifdef RS_USE_I2P_BOB
mI2pBob = new p3I2pBob(mPeerMgr);
autoProxy->addProxy(autoProxyType::I2PBOB, mI2pBob);
#ifdef RS_USE_I2P_SAM3
mI2pSam3 = new p3I2pSam3(mPeerMgr);
autoProxy->addProxy(autoProxyType::I2PSAM3, mI2pSam3);
#endif
//load all the SSL certs as friends
@ -1655,8 +1655,9 @@ int RsServer::StartupRetroShare()
mConfigMgr->addConfiguration("wire.cfg", wire_ns);
#endif
#endif //RS_ENABLE_GXS
#ifdef RS_USE_I2P_BOB
mConfigMgr->addConfiguration("I2PBOB.cfg", mI2pBob);
#ifdef RS_USE_I2P_SAM3
// to make migration easiert, SAM will use BOBs configuration, as they are compatible / the same.
mConfigMgr->addConfiguration("I2PBOB.cfg", mI2pSam3);
#endif
mPluginsManager->addConfigurations(mConfigMgr) ;
@ -1709,34 +1710,33 @@ int RsServer::StartupRetroShare()
{
std::cout << "RsServer::StartupRetroShare setting up hidden locations" << std::endl;
if (rsInitConfig->hiddenNodeI2PBOB) {
std::cout << "RsServer::StartupRetroShare setting up BOB" << std::endl;
if (rsInitConfig->hiddenNodeI2P) {
std::cout << "RsServer::StartupRetroShare setting up SAMv3" << std::endl;
// we need a local port!
mNetMgr->checkNetAddress();
// add i2p proxy
// bob will use this address
sockaddr_storage i2pInstance;
sockaddr_storage_ipv4_aton(i2pInstance, rsInitConfig->hiddenNodeAddress.c_str());
mPeerMgr->setProxyServerAddress(RS_HIDDEN_TYPE_I2P, i2pInstance);
std::string addr; // will be set by auto proxy service
uint16_t port = rsInitConfig->hiddenNodePort; // unused by bob
uint16_t port; // unused by SAM
bool r = autoProxy->initialSetup(autoProxyType::I2PBOB, addr, port);
bool r = autoProxy->initialSetup(autoProxyType::I2PSAM3, addr, port);
if (r && !addr.empty()) {
mPeerMgr->setupHiddenNode(addr, port);
// now enable bob
bobSettings bs;
autoProxy->taskSync(autoProxyType::I2PBOB, autoProxyTask::getSettings, &bs);
bs.enable = true;
autoProxy->taskSync(autoProxyType::I2PBOB, autoProxyTask::setSettings, &bs);
// now enable SAM
samSettings ss;
autoProxy->taskSync(autoProxyType::I2PSAM3, autoProxyTask::getSettings, &ss);
ss.enable = true;
autoProxy->taskSync(autoProxyType::I2PSAM3, autoProxyTask::setSettings, &ss);
} else {
std::cerr << "RsServer::StartupRetroShare failed to receive keys" << std::endl;
/// TODO add notify for failed bob setup
/// TODO add notify for failed i2p setup
}
} else {
mPeerMgr->setupHiddenNode(rsInitConfig->hiddenNodeAddress, rsInitConfig->hiddenNodePort);
@ -1758,19 +1758,17 @@ int RsServer::StartupRetroShare()
if (rsInitConfig->hiddenNodeSet) {
// newly created location
// mNetMgr->checkNetAddress() will setup ports for us
#if 0 // this was used for BOB but is not requires for SAMv3
// trigger updates for auto proxy services
std::vector<autoProxyType::autoProxyType_enum> types;
// i2p bob need to rebuild its command map
types.push_back(autoProxyType::I2PBOB);
rsAutoProxyMonitor::taskSync(types, autoProxyTask::reloadConfig);
#endif
}
/**************************************************************************/
/* startup (stuff dependent on Ids/peers is after this point) */
/**************************************************************************/
autoProxy->startAll();
pqih->init_listener();
@ -1803,8 +1801,8 @@ int RsServer::StartupRetroShare()
/**************************************************************************/
// auto proxy threads
#ifdef RS_USE_I2P_BOB
startServiceThread(mI2pBob, "I2P-BOB");
#ifdef RS_USE_I2P_SAM3
startServiceThread(mI2pSam3, "I2P-SAM3");
#endif
#ifdef RS_ENABLE_GXS