Add I2P BOB support to libretroashare and RetroShare GUI

This commit is contained in:
sehraf 2016-10-09 14:32:52 +02:00
parent 9ff81b9e93
commit a3ee85a30d
31 changed files with 4150 additions and 959 deletions

View file

@ -45,6 +45,8 @@ const int p3facemsgzone = 11453;
// TO SHUTDOWN THREADS.
#ifdef RS_ENABLE_GXS
#include "services/autoproxy/rsautoproxymonitor.h"
#include "services/p3idservice.h"
#include "services/p3gxscircles.h"
#include "services/p3wiki.h"
@ -89,6 +91,8 @@ void RsServer::rsGlobalShutDown()
mNetMgr->shutdown(); /* Handles UPnP */
rsAutoProxyMonitor::instance()->stopAllRSShutdown();
fullstop() ;
// kill all registered service threads

View file

@ -46,6 +46,7 @@
class p3heartbeat;
class p3discovery2;
class p3I2pBob;
/* GXS Classes - just declare the classes.
so we don't have to totally recompile to switch */
@ -129,7 +130,7 @@ class RsServer: public RsControl, public RsTickingThread
* This function is responsible for ensuring Retroshare exits in a legal state:
* i.e. releases all held resources and saves current configuration
*/
virtual void rsGlobalShutDown( );
virtual void rsGlobalShutDown( );
/****************************************/
@ -164,6 +165,7 @@ class RsServer: public RsControl, public RsTickingThread
p3ChatService *chatSrv;
p3StatusService *mStatusSrv;
p3GxsTunnelService *mGxsTunnels;
p3I2pBob *mI2pBob;
// This list contains all threaded services. It will be used to shut them down properly.

View file

@ -121,6 +121,8 @@ class RsInitConfig
std::string hiddenNodeAddress;
uint16_t hiddenNodePort;
bool hiddenNodeI2PBOB;
/* Logging */
bool haveLogFile;
bool outStderr;
@ -790,13 +792,13 @@ void RsInit::setAutoLogin(bool autoLogin){
}
/* Setup Hidden Location; */
bool RsInit::SetHiddenLocation(const std::string& hiddenaddress, uint16_t port)
void RsInit::SetHiddenLocation(const std::string& hiddenaddress, uint16_t port, bool useBob)
{
/* parse the bugger (todo) */
rsInitConfig->hiddenNodeSet = true;
rsInitConfig->hiddenNodeAddress = hiddenaddress;
rsInitConfig->hiddenNodePort = port;
return true;
rsInitConfig->hiddenNodeI2PBOB = useBob;
}
@ -850,7 +852,10 @@ RsGRouter *rsGRouter = NULL ;
#include "upnp/upnphandler_miniupnp.h"
#endif
#endif
#include "services/autoproxy/p3i2pbob.h"
#include "services/autoproxy/rsautoproxymonitor.h"
#include "services/p3gxsreputation.h"
#include "services/p3serviceinfo.h"
#include "services/p3heartbeat.h"
@ -1045,8 +1050,11 @@ int RsServer::StartupRetroShare()
mPeerMgr->setManagers(mLinkMgr, mNetMgr);
mNetMgr->setManagers(mPeerMgr, mLinkMgr);
rsAutoProxyMonitor *autoProxy = rsAutoProxyMonitor::instance();
mI2pBob = new p3I2pBob(mPeerMgr);
autoProxy->addProxy(autoProxyType::I2PBOB, mI2pBob);
//load all the SSL certs as friends
// std::list<std::string> sslIds;
// AuthSSL::getAuthSSL()->getAuthenticatedList(sslIds);
@ -1260,12 +1268,6 @@ int RsServer::StartupRetroShare()
rsFiles = ftserver;
/* create Cache Services */
std::string config_dir = rsAccounts->PathAccountDirectory();
std::string localcachedir = config_dir + "/cache/local";
std::string remotecachedir = config_dir + "/cache/remote";
std::vector<std::string> plugins_directories ;
#ifdef __APPLE__
@ -1672,6 +1674,7 @@ int RsServer::StartupRetroShare()
//mConfigMgr->addConfiguration("photo.cfg", photo_ns);
//mConfigMgr->addConfiguration("wire.cfg", wire_ns);
#endif
mConfigMgr->addConfiguration("I2PBOB.cfg", mI2pBob);
mPluginsManager->addConfigurations(mConfigMgr) ;
@ -1717,12 +1720,46 @@ int RsServer::StartupRetroShare()
{
mPeerMgr->setOwnNetworkMode(RS_NET_MODE_EXT);
mPeerMgr->setOwnVisState(RS_VS_DISC_FULL, RS_VS_DHT_FULL);
}
if (rsInitConfig->hiddenNodeSet)
{
mPeerMgr->setupHiddenNode(rsInitConfig->hiddenNodeAddress, rsInitConfig->hiddenNodePort);
std::cout << "RsServer::StartupRetroShare setting up hidden locations" << std::endl;
if (rsInitConfig->hiddenNodeI2PBOB) {
std::cout << "RsServer::StartupRetroShare setting up BOB" << 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
bool r = autoProxy->initialSetup(autoProxyType::I2PBOB, addr, port);
if (r && !addr.empty()) {
mPeerMgr->setupHiddenNode(addr, port);
// now enable bob
bobSettings bs;
autoProxy->taskSync(autoProxyType::I2PBOB, autoProxyTask::getSettings, &bs);
bs.enableBob = true;
autoProxy->taskSync(autoProxyType::I2PBOB, autoProxyTask::setSettings, &bs);
} else {
std::cerr << "RsServer::StartupRetroShare failed to receive keys" << std::endl;
/// TODO add notify for failed bob setup
}
} else {
mPeerMgr->setupHiddenNode(rsInitConfig->hiddenNodeAddress, rsInitConfig->hiddenNodePort);
}
std::cout << "RsServer::StartupRetroShare hidden location set up" << std::endl;
}
else if (isHiddenNode)
{
@ -1731,15 +1768,27 @@ int RsServer::StartupRetroShare()
mNetMgr -> checkNetAddress();
if (rsInitConfig->hiddenNodeSet) {
// newly created location
// mNetMgr->checkNetAddress() will setup ports for us
// 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);
}
/**************************************************************************/
/* startup (stuff dependent on Ids/peers is after this point) */
/**************************************************************************/
autoProxy->startAll();
pqih->init_listener();
mNetMgr->addNetListener(pqih); /* add listener so we can reset all sockets later */
/**************************************************************************/
/* load caches and secondary data */
/**************************************************************************/
@ -1766,8 +1815,10 @@ int RsServer::StartupRetroShare()
/* Start up Threads */
/**************************************************************************/
#ifdef RS_ENABLE_GXS
// auto proxy threads
startServiceThread(mI2pBob, "I2P-BOB");
#ifdef RS_ENABLE_GXS
// Must Set the GXS pointers before starting threads.
rsIdentity = mGxsIdService;
rsGxsCircles = mGxsCircles;