mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-28 08:54:13 -04:00
mods to support hidden node: setup & cert sharing.
Also removed old configuration mode from p3cfgmgr git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-initdev@6720 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
683e75aeef
commit
bfd915864b
13 changed files with 387 additions and 919 deletions
|
@ -107,6 +107,10 @@ std::string RsPeerNetModeString(uint32_t netModel)
|
|||
{
|
||||
str = "UDP Mode";
|
||||
}
|
||||
else if (netModel == RS_NETMODE_HIDDEN)
|
||||
{
|
||||
str = "Hidden";
|
||||
}
|
||||
else if (netModel == RS_NETMODE_UNREACHABLE)
|
||||
{
|
||||
str = "UDP Mode (Unreachable)";
|
||||
|
@ -302,31 +306,47 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
|||
d.authcode = "AUTHCODE";
|
||||
|
||||
/* fill from pcs */
|
||||
|
||||
d.localAddr = rs_inet_ntoa(ps.localaddr.sin_addr);
|
||||
d.localPort = ntohs(ps.localaddr.sin_port);
|
||||
d.extAddr = rs_inet_ntoa(ps.serveraddr.sin_addr);
|
||||
d.extPort = ntohs(ps.serveraddr.sin_port);
|
||||
d.dyndns = ps.dyndns;
|
||||
d.lastConnect = ps.lastcontact;
|
||||
d.connectPeriod = 0;
|
||||
|
||||
std::list<pqiIpAddress>::iterator it;
|
||||
for(it = ps.ipAddrs.mLocal.mAddrs.begin();
|
||||
it != ps.ipAddrs.mLocal.mAddrs.end(); it++)
|
||||
if (ps.hiddenNode)
|
||||
{
|
||||
std::string toto;
|
||||
rs_sprintf(toto, "%u %ld sec", ntohs(it->mAddr.sin_port), time(NULL) - it->mSeenTime);
|
||||
d.ipAddressList.push_back("L:" + rs_inet_ntoa(it->mAddr.sin_addr) + ":" + toto);
|
||||
d.isHiddenNode = true;
|
||||
rs_sprintf(d.hiddenNodeAddress, "%s:%u", ps.hiddenDomain.c_str(), ps.hiddenPort);
|
||||
d.localAddr = "hidden";
|
||||
d.localPort = 0;
|
||||
d.extAddr = "hidden";
|
||||
d.extPort = 0;
|
||||
d.dyndns = "";
|
||||
}
|
||||
for(it = ps.ipAddrs.mExt.mAddrs.begin();
|
||||
it != ps.ipAddrs.mExt.mAddrs.end(); it++)
|
||||
else
|
||||
{
|
||||
std::string toto;
|
||||
rs_sprintf(toto, "%u %ld sec", ntohs(it->mAddr.sin_port), time(NULL) - it->mSeenTime);
|
||||
d.ipAddressList.push_back("E:" + rs_inet_ntoa(it->mAddr.sin_addr) + ":" + toto);
|
||||
}
|
||||
d.isHiddenNode = false;
|
||||
d.hiddenNodeAddress = "";
|
||||
|
||||
d.localAddr = rs_inet_ntoa(ps.localaddr.sin_addr);
|
||||
d.localPort = ntohs(ps.localaddr.sin_port);
|
||||
d.extAddr = rs_inet_ntoa(ps.serveraddr.sin_addr);
|
||||
d.extPort = ntohs(ps.serveraddr.sin_port);
|
||||
d.dyndns = ps.dyndns;
|
||||
|
||||
std::list<pqiIpAddress>::iterator it;
|
||||
for(it = ps.ipAddrs.mLocal.mAddrs.begin();
|
||||
it != ps.ipAddrs.mLocal.mAddrs.end(); it++)
|
||||
{
|
||||
std::string toto;
|
||||
rs_sprintf(toto, "%u %ld sec", ntohs(it->mAddr.sin_port), time(NULL) - it->mSeenTime);
|
||||
d.ipAddressList.push_back("L:" + rs_inet_ntoa(it->mAddr.sin_addr) + ":" + toto);
|
||||
}
|
||||
for(it = ps.ipAddrs.mExt.mAddrs.begin();
|
||||
it != ps.ipAddrs.mExt.mAddrs.end(); it++)
|
||||
{
|
||||
std::string toto;
|
||||
rs_sprintf(toto, "%u %ld sec", ntohs(it->mAddr.sin_port), time(NULL) - it->mSeenTime);
|
||||
d.ipAddressList.push_back("E:" + rs_inet_ntoa(it->mAddr.sin_addr) + ":" + toto);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch(ps.netMode & RS_NET_MODE_ACTUAL)
|
||||
{
|
||||
|
@ -339,6 +359,9 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
|||
case RS_NET_MODE_UDP:
|
||||
d.netMode = RS_NETMODE_UDP;
|
||||
break;
|
||||
case RS_NET_MODE_HIDDEN:
|
||||
d.netMode = RS_NETMODE_HIDDEN;
|
||||
break;
|
||||
case RS_NET_MODE_UNREACHABLE:
|
||||
case RS_NET_MODE_UNKNOWN:
|
||||
default:
|
||||
|
@ -706,6 +729,53 @@ bool p3Peers::getAllowServerIPDetermination()
|
|||
return mNetMgr->getIPServersEnabled() ;
|
||||
}
|
||||
|
||||
bool p3Peers::setLocation(const std::string &ssl_id, const std::string &location)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::setLocation() " << ssl_id << std::endl;
|
||||
#endif
|
||||
|
||||
return mPeerMgr->setLocation(ssl_id, location);
|
||||
}
|
||||
|
||||
bool p3Peers::setHiddenNode(const std::string &id, const std::string &hidden_node_address)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::setHiddenNode() " << id << std::endl;
|
||||
#endif
|
||||
|
||||
size_t cpos = hidden_node_address.rfind(':');
|
||||
if (cpos == std::string::npos)
|
||||
{
|
||||
std::cerr << "p3Peers::setHiddenNode() Failed to parse (:) " << hidden_node_address << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
int lenport = hidden_node_address.length() - (cpos + 1); // +1 to skip over : char.
|
||||
if (lenport <= 0)
|
||||
{
|
||||
std::cerr << "p3Peers::setHiddenNode() Missing Port: " << hidden_node_address << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string domain = hidden_node_address.substr(0, cpos);
|
||||
std::string port = hidden_node_address.substr(cpos + 1, std::string::npos);
|
||||
int portint = atoi(port.c_str());
|
||||
|
||||
if ((portint < 0) || (portint > 65535))
|
||||
{
|
||||
std::cerr << "p3Peers::setHiddenNode() Invalid Port: " << hidden_node_address << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cerr << "p3Peers::setHiddenNode() Domain: " << domain << " Port: " << portint;
|
||||
std::cerr << std::endl;
|
||||
|
||||
mPeerMgr->setNetworkMode(id, RS_NET_MODE_HIDDEN);
|
||||
mPeerMgr->setHiddenDomainPort(id, domain, (uint16_t) portint);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Peers::setLocalAddress(const std::string &id, const std::string &addr_str, uint16_t port)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
|
@ -731,14 +801,6 @@ bool p3Peers::setLocalAddress(const std::string &id, const std::string &addr_st
|
|||
return false;
|
||||
}
|
||||
|
||||
bool p3Peers::setLocation(const std::string &ssl_id, const std::string &location)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::setLocation() " << ssl_id << std::endl;
|
||||
#endif
|
||||
|
||||
return mPeerMgr->setLocation(ssl_id, location);
|
||||
}
|
||||
bool p3Peers::setExtAddress(const std::string &id, const std::string &addr_str, uint16_t port)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
|
@ -791,6 +853,9 @@ bool p3Peers::setNetworkMode(const std::string &id, uint32_t extNetMode)
|
|||
case RS_NETMODE_UDP:
|
||||
netMode = RS_NET_MODE_UDP;
|
||||
break;
|
||||
case RS_NETMODE_HIDDEN:
|
||||
netMode = RS_NET_MODE_HIDDEN;
|
||||
break;
|
||||
case RS_NETMODE_UNREACHABLE:
|
||||
netMode = RS_NET_MODE_UNREACHABLE;
|
||||
break;
|
||||
|
@ -923,13 +988,22 @@ bool p3Peers::loadDetailsFromStringCert(const std::string &certstr, RsPeerDetai
|
|||
|
||||
pd.id = cert.sslid_string() ;
|
||||
pd.location = cert.location_name_string();
|
||||
pd.localAddr = cert.loc_ip_string();
|
||||
pd.localPort = cert.loc_port_us();
|
||||
pd.extAddr = cert.ext_ip_string();
|
||||
pd.extPort = cert.ext_port_us();
|
||||
pd.dyndns = cert.dns_string() ;
|
||||
|
||||
pd.isOnlyGPGdetail = pd.id.empty();
|
||||
pd.service_perm_flags = RS_SERVICE_PERM_ALL ;
|
||||
|
||||
if (pd.isHiddenNode)
|
||||
{
|
||||
pd.hiddenNodeAddress = cert.hidden_node_string();
|
||||
}
|
||||
else
|
||||
{
|
||||
pd.localAddr = cert.loc_ip_string();
|
||||
pd.localPort = cert.loc_port_us();
|
||||
pd.extAddr = cert.ext_ip_string();
|
||||
pd.extPort = cert.ext_port_us();
|
||||
pd.dyndns = cert.dns_string() ;
|
||||
}
|
||||
}
|
||||
catch(uint32_t e)
|
||||
{
|
||||
|
|
|
@ -84,6 +84,8 @@ virtual bool removeFriendLocation(const std::string &sslId);
|
|||
/* Network Stuff */
|
||||
virtual bool connectAttempt(const std::string &id);
|
||||
virtual bool setLocation(const std::string &ssl_id, const std::string &location);//location is shown in the gui to differentiate ssl certs
|
||||
virtual bool setHiddenNode(const std::string &id, const std::string &hidden_node_address);
|
||||
|
||||
virtual bool setLocalAddress(const std::string &id, const std::string &addr, uint16_t port);
|
||||
virtual bool setExtAddress(const std::string &id, const std::string &addr, uint16_t port);
|
||||
virtual bool setDynDNS(const std::string &id, const std::string &dyndns);
|
||||
|
|
|
@ -125,6 +125,11 @@ class RsInitConfig
|
|||
static unsigned short port;
|
||||
static std::string inet ;
|
||||
|
||||
/* v0.6 features */
|
||||
static bool forceApiUpgrade;
|
||||
static std::string hiddenNodeAddress;
|
||||
static uint16_t hiddenNodePort;
|
||||
|
||||
/* Logging */
|
||||
static bool haveLogFile;
|
||||
static bool outStderr;
|
||||
|
@ -185,6 +190,11 @@ bool RsInitConfig::forceLocalAddr;
|
|||
unsigned short RsInitConfig::port;
|
||||
std::string RsInitConfig::inet;
|
||||
|
||||
/* v0.6 features */
|
||||
bool RsInitConfig::forceApiUpgrade = false;
|
||||
std::string RsInitConfig::hiddenNodeAddress;
|
||||
uint16_t RsInitConfig::hiddenNodePort;
|
||||
|
||||
/* Logging */
|
||||
bool RsInitConfig::haveLogFile;
|
||||
bool RsInitConfig::outStderr;
|
||||
|
@ -1437,6 +1447,8 @@ bool RsInit::setupAccount(const std::string& accountdir)
|
|||
|
||||
|
||||
/***************************** FINAL LOADING OF SETUP *************************/
|
||||
|
||||
|
||||
/* Login SSL */
|
||||
bool RsInit::LoadPassword(const std::string& id, const std::string& inPwd)
|
||||
{
|
||||
|
@ -1708,6 +1720,16 @@ void RsInit::setAutoLogin(bool autoLogin){
|
|||
RsInitConfig::autoLogin = autoLogin;
|
||||
}
|
||||
|
||||
/* Setup Hidden Location; */
|
||||
bool RsInit::SetHiddenLocation(const std::string& hiddenaddress, uint16_t port)
|
||||
{
|
||||
/* parse the bugger (todo) */
|
||||
RsInitConfig::hiddenNodeAddress = hiddenaddress;
|
||||
RsInitConfig::hiddenNodePort = port;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Init Part of RsServer... needs the private
|
||||
|
@ -1891,19 +1913,71 @@ int RsServer::StartupRetroShare()
|
|||
emergencySaveDir += "Downloads";
|
||||
emergencyPartialsDir += "Partials";
|
||||
|
||||
/**************************************************************************/
|
||||
/* setup Configuration */
|
||||
/**************************************************************************/
|
||||
std::cerr << "Load Configuration" << std::endl;
|
||||
|
||||
mConfigMgr = new p3ConfigMgr(RsInitConfig::configDir);
|
||||
mGeneralConfig = new p3GeneralConfig();
|
||||
|
||||
// Add General.cfg, and load - this allows key early options.
|
||||
mConfigMgr->addConfiguration("general.cfg", mGeneralConfig);
|
||||
std::string dummy2("dummy");
|
||||
mGeneralConfig->loadConfiguration(dummy2);
|
||||
|
||||
// NOTE: if we lose GeneralConfiguration - then RS will fail to start.
|
||||
// as API_VERSION won't exist. Furthermore HIDDEN node status will be lost.
|
||||
// We can potentially detect HIDDEN node cofig from "peers.cfg",
|
||||
// If this is lost too - in real trouble.
|
||||
|
||||
#define RS_API_VERSION_OPT "RS_API"
|
||||
#define RS_API_VERSION_STRING "0.6.0"
|
||||
|
||||
#define RS_HIDDEN_NODE_OPT "HIDDEN_NODE"
|
||||
#define RS_HIDDEN_NODE_YES "YES"
|
||||
|
||||
bool forceApiUpgrade = false;
|
||||
if ((RsInitConfig::firsttime_run) || (forceApiUpgrade))
|
||||
{
|
||||
mGeneralConfig->setSetting(RS_API_VERSION_OPT, RS_API_VERSION_STRING);
|
||||
}
|
||||
|
||||
bool setupHiddenNode = false;
|
||||
if (!RsInitConfig::hiddenNodeAddress.empty())
|
||||
{
|
||||
setupHiddenNode = true;
|
||||
mGeneralConfig->setSetting(RS_HIDDEN_NODE_OPT, RS_HIDDEN_NODE_YES);
|
||||
}
|
||||
|
||||
// BASIC COMPARISION FOR NOW... can be extended later if needed.
|
||||
std::string version = mGeneralConfig->getSetting(RS_API_VERSION_OPT);
|
||||
if (version != RS_API_VERSION_STRING)
|
||||
{
|
||||
std::cerr << "Aborting: Old Retroshare Configuration";
|
||||
std::cerr << std::endl;
|
||||
abort();
|
||||
}
|
||||
bool isHiddenNode = false;
|
||||
if (RS_HIDDEN_NODE_YES == mGeneralConfig->getSetting(RS_HIDDEN_NODE_OPT))
|
||||
{
|
||||
isHiddenNode = true;
|
||||
std::cerr << "Retroshare: Hidden Node";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* setup classes / structures */
|
||||
/**************************************************************************/
|
||||
std::cerr << "setup classes / structures" << std::endl;
|
||||
|
||||
|
||||
|
||||
/* History Manager */
|
||||
mHistoryMgr = new p3HistoryMgr();
|
||||
mPeerMgr = new p3PeerMgrIMPL( AuthSSL::getAuthSSL()->OwnId(),
|
||||
AuthGPG::getAuthGPG()->getGPGOwnId(),
|
||||
AuthGPG::getAuthGPG()->getGPGOwnName(),
|
||||
AuthSSL::getAuthSSL()->getOwnLocation());
|
||||
AuthGPG::getAuthGPG()->getGPGOwnId(),
|
||||
AuthGPG::getAuthGPG()->getGPGOwnName(),
|
||||
AuthSSL::getAuthSSL()->getOwnLocation());
|
||||
mNetMgr = new p3NetMgrIMPL();
|
||||
mLinkMgr = new p3LinkMgrIMPL(mPeerMgr, mNetMgr);
|
||||
|
||||
|
@ -1913,7 +1987,8 @@ int RsServer::StartupRetroShare()
|
|||
|
||||
mPeerMgr->setManagers(mLinkMgr, mNetMgr);
|
||||
mNetMgr->setManagers(mPeerMgr, mLinkMgr);
|
||||
|
||||
|
||||
|
||||
//load all the SSL certs as friends
|
||||
// std::list<std::string> sslIds;
|
||||
// AuthSSL::getAuthSSL()->getAuthenticatedList(sslIds);
|
||||
|
@ -2117,9 +2192,6 @@ int RsServer::StartupRetroShare()
|
|||
rsFiles = ftserver;
|
||||
|
||||
|
||||
mConfigMgr = new p3ConfigMgr(RsInitConfig::configDir, "rs-v0.5.cfg", "rs-v0.5.sgn");
|
||||
mGeneralConfig = new p3GeneralConfig();
|
||||
|
||||
/* create Cache Services */
|
||||
std::string config_dir = RsInitConfig::configDir;
|
||||
std::string localcachedir = config_dir + "/cache/local";
|
||||
|
@ -2139,7 +2211,6 @@ int RsServer::StartupRetroShare()
|
|||
mPluginsManager = new RsPluginManager(RsInitConfig::main_executable_hash) ;
|
||||
rsPlugins = mPluginsManager ;
|
||||
mConfigMgr->addConfiguration("plugins.cfg", mPluginsManager);
|
||||
|
||||
mPluginsManager->loadConfiguration() ;
|
||||
|
||||
// These are needed to load plugins: plugin devs might want to know the place of
|
||||
|
@ -2456,7 +2527,6 @@ int RsServer::StartupRetroShare()
|
|||
mConfigMgr->loadConfiguration();
|
||||
|
||||
mConfigMgr->addConfiguration("peers.cfg", mPeerMgr);
|
||||
mConfigMgr->addConfiguration("general.cfg", mGeneralConfig);
|
||||
mConfigMgr->addConfiguration("cache.cfg", mCacheStrapper);
|
||||
mConfigMgr->addConfiguration("msgs.cfg", msgSrv);
|
||||
mConfigMgr->addConfiguration("chat.cfg", chatSrv);
|
||||
|
@ -2519,6 +2589,12 @@ int RsServer::StartupRetroShare()
|
|||
|
||||
}
|
||||
|
||||
if (setupHiddenNode)
|
||||
{
|
||||
mPeerMgr->setupHiddenNode(RsInitConfig::hiddenNodeAddress, RsInitConfig::hiddenNodePort);
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
/* must load the trusted_peer before setting up the pqipersongrp */
|
||||
if (firsttime_run)
|
||||
|
@ -2641,6 +2717,7 @@ int RsServer::StartupRetroShare()
|
|||
{
|
||||
msgSrv->loadWelcomeMsg();
|
||||
ftserver->shareDownloadDirectory(true);
|
||||
mGeneralConfig->saveConfiguration();
|
||||
}
|
||||
|
||||
// load up the help page
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue