Added RsConfig class which will in the future support most of the interface from rsinit.h & rsiface.h

* Moved rsnetwork.h => rsconfig.h
 * Implemented Network functions (call p3NetMgr) in RsConfig.
 * Implemented UserLevel (New/Basic/Casual/Power) Levels
 * added p3PeerMgr::haveOnceConnected() function, for UserLevel support.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-netupgrade@4431 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-07-11 18:48:56 +00:00
parent 4792d7c878
commit c2a0309f05
9 changed files with 574 additions and 96 deletions

View File

@ -24,7 +24,7 @@
*/
#include "dht/connectstatebox.h"
#include "retroshare/rsnetwork.h"
#include "retroshare/rsconfig.h"
#include <iostream>
#include <sstream>

View File

@ -147,7 +147,7 @@ PUBLIC_HEADERS = retroshare/rsblogs.h \
retroshare/rsturtle.h \
retroshare/rstypes.h \
retroshare/rsdht.h \
retroshare/rsnetwork.h
retroshare/rsconfig.h
HEADERS += plugins/pluginmanager.h \
plugins/dlfcn_win32.h \
@ -377,7 +377,8 @@ HEADERS += rsserver/p3discovery.h \
rsserver/p3msgs.h \
rsserver/p3peers.h \
rsserver/p3photo.h \
rsserver/p3status.h
rsserver/p3status.h \
rsserver/p3serverconfig.h
HEADERS += serialiser/rsbaseitems.h \
serialiser/rsbaseserial.h \
@ -499,7 +500,8 @@ SOURCES += rsserver/p3discovery.cc \
rsserver/rsiface.cc \
rsserver/rsinit.cc \
rsserver/rsloginhandler.cc \
rsserver/rstypes.cc
rsserver/rstypes.cc \
rsserver/p3serverconfig.cc
SOURCES += plugins/pluginmanager.cc \
plugins/dlfcn_win32.cc \

View File

@ -320,18 +320,36 @@ int p3PeerMgr::getConnectAddresses(const std::string &id,
return 1;
}
/****************************
* Update state,
* trigger retry if necessary,
*
* remove from DHT?
*
*/
/******************************** Feedback ...... *********************************
* From various sources
*/
bool p3PeerMgr::haveOnceConnected()
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* check for existing */
std::map<std::string, peerState>::iterator it;
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
{
if (it->second.lastcontact > 0)
{
#ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::haveOnceConnected() lastcontact: ";
std::cerr << time(NULL) - it->second.lastcontact << " for id: " << it->first;
std::cerr << std::endl;
#endif
return true;
}
}
#ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::haveOnceConnected() all Last Contacts = 0";
std::cerr << std::endl;
#endif
return false;
}
/*******************************************************************/

View File

@ -170,6 +170,8 @@ int getConnectAddresses(const std::string &id,
struct sockaddr_in &lAddr, struct sockaddr_in &eAddr,
pqiIpAddrSet &histAddrs, std::string &dyndns);
bool haveOnceConnected();
/**************** handle monitors *****************/
void addMonitor(pqiMonitor *mon);
void removeMonitor(pqiMonitor *mon);

View File

@ -0,0 +1,241 @@
#ifndef RETROSHARE_CONFIG_GUI_INTERFACE_H
#define RETROSHARE_CONFIG_GUI_INTERFACE_H
/*
* libretroshare/src/retroshare: rsconfig.h
*
* RetroShare C++ Interface.
*
* Copyright 2011-2011 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include <inttypes.h>
#include <string>
#include <list>
/* The New Config Interface Class */
class RsServerConfig;
extern RsServerConfig *rsConfig;
#define RSNET_NETWORK_UNKNOWN 1
#define RSNET_NETWORK_RESTARTING 2
#define RSNET_NETWORK_OFFLINE 3
#define RSNET_NETWORK_LOCALNET 4
#define RSNET_NETWORK_BEHINDNAT 5
#define RSNET_NETWORK_EXTERNALIP 6
// WHAT TYPE OF FIREWALL?
#define RSNET_NATTYPE_NONE 1
#define RSNET_NATTYPE_UNKNOWN 2
#define RSNET_NATTYPE_SYMMETRIC 3
#define RSNET_NATTYPE_RESTRICTED_CONE 4
#define RSNET_NATTYPE_FULL_CONE 5
#define RSNET_NATTYPE_OTHER 6
// WHAT TYPE OF HOLE?
#define RSNET_NATHOLE_UNKNOWN 0
#define RSNET_NATHOLE_NONE 1
#define RSNET_NATHOLE_UPNP 2
#define RSNET_NATHOLE_NATPMP 3
#define RSNET_NATHOLE_FORWARDED 4
// Types of Connections.
#define RSNET_CONNECT_NONE 0x0000
#define RSNET_CONNECT_ACCEPT_TCP 0x0001
#define RSNET_CONNECT_OUTGOING_TCP 0x0002
#define RSNET_CONNECT_DIRECT_UDP 0x0100
#define RSNET_CONNECT_PROXY_UDP 0x0200
#define RSNET_CONNECT_RELAY_UDP 0x0400
// net state (good, okay, bad)
// BAD. (RED)
#define RSNET_NETSTATE_BAD_UNKNOWN 1
#define RSNET_NETSTATE_BAD_OFFLINE 2
#define RSNET_NETSTATE_BAD_NATSYM 3
#define RSNET_NETSTATE_BAD_NODHT_NAT 4
// CAUTION. (ORANGE)
#define RSNET_NETSTATE_WARNING_RESTART 5
#define RSNET_NETSTATE_WARNING_NATTED 6
#define RSNET_NETSTATE_WARNING_NODHT 7
// GOOD (GREEN)
// NAT with forwarded port, or EXT port.
#define RSNET_NETSTATE_GOOD 8
// ADVANCED MODE (BLUE)
// If the user knows what they are doing... we cannot confirm this.
#define RSNET_NETSTATE_ADV_FORWARD 9
#define RSNET_NETSTATE_ADV_DARK_FORWARD 10
/* matched to the uPnP states */
#define UPNP_STATE_UNINITIALISED 0
#define UPNP_STATE_UNAVAILABILE 1
#define UPNP_STATE_READY 2
#define UPNP_STATE_FAILED_TCP 3
#define UPNP_STATE_FAILED_UDP 4
#define UPNP_STATE_ACTIVE 5
/************************** Indicate How experienced the RsUser is... based on Friends / Firewall status ******/
#define RSCONFIG_USER_LEVEL_NEW 0x0001 /* no friends */
#define RSCONFIG_USER_LEVEL_BASIC 0x0002 /* no connections */
#define RSCONFIG_USER_LEVEL_CASUAL 0x0003 /* firewalled */
#define RSCONFIG_USER_LEVEL_POWER 0x0004 /* good! */
#define RSCONFIG_USER_LEVEL_OVERRIDE 0x0005 /* forced to POWER level */
class RsConfigStartup
{
public:
RsConfigStartup()
{
promptAtBoot = 1;
}
int promptAtBoot; /* popup the password prompt */
};
class RsConfigDataRates
{
public:
RsConfigDataRates()
{
maxDownloadDataRate = 0;
maxUploadDataRate = 0;
maxIndivDataRate = 0;
}
int maxDownloadDataRate; /* kb */
int maxUploadDataRate; /* kb */
int maxIndivDataRate; /* kb */
};
class RsConfigNetStatus
{
public:
RsConfigNetStatus()
{
localPort = extPort = 0 ;
firewalled = forwardPort = false ;
DHTActive = uPnPActive = netLocalOk = netUpnpOk = netDhtOk = netStunOk = netExtraAddressOk = false ;
uPnPState = DHTPeers = 0 ;
}
std::string ownId;
std::string ownName;
std::string localAddr;
int localPort;
std::string extAddr;
int extPort;
std::string extName;
bool firewalled;
bool forwardPort;
/* older data types */
bool DHTActive;
bool uPnPActive;
int uPnPState;
int DHTPeers;
/* Flags for Network Status */
bool netLocalOk; /* That we've talked to someone! */
bool netUpnpOk; /* upnp is enabled and active */
bool netDhtOk; /* response from dht */
bool netStunOk; /* recvd stun / udp packets */
bool netExtraAddressOk; /* recvd ip address with external finder*/
uint32_t netDhtNetSize; /* response from dht */
uint32_t netDhtRsNetSize; /* response from dht */
};
/*********
* This is a new style RsConfig Interface.
* It should contain much of the information for the Options/Config Window.
*
* To start with, I'm going to move the stuff from RsIface::RsConfig into here.
*
*/
class RsServerConfig
{
public:
RsServerConfig() { return; }
virtual ~RsServerConfig() { return; }
/* From RsIface::RsConfig */
// Implemented Only this one!
virtual int getConfigNetStatus(RsConfigNetStatus &status) = 0;
// NOT IMPLEMENTED YET!
//virtual int getConfigStartup(RsConfigStartup &params) = 0;
//virtual int getConfigDataRates(RsConfigDataRates &params) = 0;
/* From RsInit */
// NOT IMPLEMENTED YET!
//virtual std::string RsConfigDirectory() = 0;
//virtual std::string RsConfigKeysDirectory() = 0;
//virtual std::string RsProfileConfigDirectory() = 0;
//virtual bool getStartMinimised() = 0;
//virtual std::string getRetroShareLink() = 0;
//virtual bool getAutoLogin() = 0;
//virtual void setAutoLogin(bool autoLogin) = 0;
//virtual bool RsClearAutoLogin() = 0;
//virtual std::string getRetroshareDataDirectory() = 0;
/* New Stuff */
virtual uint32_t getUserLevel() = 0;
virtual uint32_t getNetState() = 0;
virtual uint32_t getNetworkMode() = 0;
virtual uint32_t getNatTypeMode() = 0;
virtual uint32_t getNatHoleMode() = 0;
virtual uint32_t getConnectModes() = 0;
};
#endif

View File

@ -1,82 +0,0 @@
#ifndef RETROSHARE_NETWORK_GUI_INTERFACE_H
#define RETROSHARE_NETWORK_GUI_INTERFACE_H
/*
* libretroshare/src/retroshare: rsnetwork.h
*
* RetroShare C++ Interface.
*
* Copyright 2011-2011 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#define RSNET_NETWORK_UNKNOWN 1
#define RSNET_NETWORK_RESTARTING 2
#define RSNET_NETWORK_OFFLINE 3
#define RSNET_NETWORK_LOCALNET 4
#define RSNET_NETWORK_BEHINDNAT 5
#define RSNET_NETWORK_EXTERNALIP 6
// WHAT TYPE OF FIREWALL?
#define RSNET_NATTYPE_NONE 1
#define RSNET_NATTYPE_UNKNOWN 2
#define RSNET_NATTYPE_SYMMETRIC 3
#define RSNET_NATTYPE_RESTRICTED_CONE 4
#define RSNET_NATTYPE_FULL_CONE 5
#define RSNET_NATTYPE_OTHER 6
// WHAT TYPE OF HOLE?
#define RSNET_NATHOLE_UNKNOWN 0
#define RSNET_NATHOLE_NONE 1
#define RSNET_NATHOLE_UPNP 2
#define RSNET_NATHOLE_NATPMP 3
#define RSNET_NATHOLE_FORWARDED 4
// Types of Connections.
#define RSNET_CONNECT_NONE 0x0000
#define RSNET_CONNECT_ACCEPT_TCP 0x0001
#define RSNET_CONNECT_OUTGOING_TCP 0x0002
#define RSNET_CONNECT_DIRECT_UDP 0x0100
#define RSNET_CONNECT_PROXY_UDP 0x0200
#define RSNET_CONNECT_RELAY_UDP 0x0400
// net state (good, okay, bad)
// BAD. (RED)
#define RSNET_NETSTATE_BAD_UNKNOWN 1
#define RSNET_NETSTATE_BAD_OFFLINE 2
#define RSNET_NETSTATE_BAD_NATSYM 3
#define RSNET_NETSTATE_BAD_NODHT_NAT 4
// CAUTION. (ORANGE)
#define RSNET_NETSTATE_WARNING_RESTART 5
#define RSNET_NETSTATE_WARNING_NATTED 6
#define RSNET_NETSTATE_WARNING_NODHT 7
// GOOD (GREEN)
// NAT with forwarded port, or EXT port.
#define RSNET_NETSTATE_GOOD 8
// ADVANCED MODE (BLUE)
// If the user knows what they are doing... we cannot confirm this.
#define RSNET_NETSTATE_ADV_FORWARD 9
#define RSNET_NETSTATE_ADV_DARK_FORWARD 10
#endif

View File

@ -0,0 +1,208 @@
/*
* libretroshare/src/rsserver: p3serverconfig.h
*
* RetroShare C++ Interface.
*
* Copyright 2011-2011 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include "rsserver/p3serverconfig.h"
RsServerConfig *rsConfig = NULL;
p3ServerConfig::p3ServerConfig(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr, p3NetMgr *netMgr)
:configMtx("p3ServerConfig")
{
mPeerMgr = peerMgr;
mLinkMgr = linkMgr;
mNetMgr = netMgr;
mUserLevel = RSCONFIG_USER_LEVEL_NEW; /* START LEVEL */
rsConfig = this;
}
p3ServerConfig::~p3ServerConfig()
{
return;
}
/* From RsIface::RsConfig */
int p3ServerConfig::getConfigNetStatus(RsConfigNetStatus &status)
{
return 0;
}
int p3ServerConfig::getConfigStartup(RsConfigStartup &params)
{
return 0;
}
int p3ServerConfig::getConfigDataRates(RsConfigDataRates &params)
{
return 0;
}
/* From RsInit */
std::string p3ServerConfig::RsConfigDirectory()
{
return std::string();
}
std::string p3ServerConfig::RsConfigKeysDirectory()
{
return std::string();
}
std::string p3ServerConfig::RsProfileConfigDirectory()
{
return std::string();
}
bool p3ServerConfig::getStartMinimised()
{
return 0;
}
std::string p3ServerConfig::getRetroShareLink()
{
return std::string();
}
bool p3ServerConfig::getAutoLogin()
{
return 0;
}
void p3ServerConfig::setAutoLogin(bool autoLogin)
{
return;
}
bool p3ServerConfig::RsClearAutoLogin()
{
return 0;
}
std::string p3ServerConfig::getRetroshareDataDirectory()
{
return std::string();
}
/* New Stuff */
uint32_t p3ServerConfig::getUserLevel()
{
uint32_t userLevel = RSCONFIG_USER_LEVEL_NEW;
{
RsStackMutex stack(configMtx); /******* LOCKED MUTEX *****/
uint32_t userLevel = mUserLevel;
}
switch(userLevel)
{
case RSCONFIG_USER_LEVEL_OVERRIDE:
break;
#define MIN_BASIC_FRIENDS 2
// FALL THROUGH EVERYTHING.
default:
case RSCONFIG_USER_LEVEL_NEW:
{
if (mLinkMgr->getFriendCount() > MIN_BASIC_FRIENDS)
{
userLevel = RSCONFIG_USER_LEVEL_BASIC;
}
}
case RSCONFIG_USER_LEVEL_BASIC:
{
/* check that we have some lastConnect > 0 */
if (mPeerMgr->haveOnceConnected())
{
userLevel = RSCONFIG_USER_LEVEL_CASUAL;
}
}
case RSCONFIG_USER_LEVEL_CASUAL:
case RSCONFIG_USER_LEVEL_POWER:
{
/* check that the firewall is open */
uint32_t netMode = mNetMgr->getNetworkMode();
uint32_t firewallMode = mNetMgr->getNatHoleMode();
if ((RSNET_NETWORK_EXTERNALIP == netMode) ||
((RSNET_NETWORK_BEHINDNAT == netMode) &&
((RSNET_NATHOLE_UPNP == firewallMode) ||
(RSNET_NATHOLE_NATPMP == firewallMode) ||
(RSNET_NATHOLE_FORWARDED == firewallMode))))
{
userLevel = RSCONFIG_USER_LEVEL_POWER;
}
}
break; /* for all */
}
{
RsStackMutex stack(configMtx); /******* LOCKED MUTEX *****/
mUserLevel = userLevel;
}
return userLevel;
}
uint32_t p3ServerConfig::getNetState()
{
return mNetMgr->getNetStateMode();
}
uint32_t p3ServerConfig::getNetworkMode()
{
return mNetMgr->getNetworkMode();
}
uint32_t p3ServerConfig::getNatTypeMode()
{
return mNetMgr->getNatTypeMode();
}
uint32_t p3ServerConfig::getNatHoleMode()
{
return mNetMgr->getNatHoleMode();
}
uint32_t p3ServerConfig::getConnectModes()
{
return mNetMgr->getConnectModes();
}

View File

@ -0,0 +1,86 @@
#ifndef LIBRETROSHARE_CONFIG_IMPLEMENTATION_H
#define LIBRETROSHARE_CONFIG_IMPLEMENTATION_H
/*
* libretroshare/src/rsserver: p3serverconfig.h
*
* RetroShare C++ Interface.
*
* Copyright 2011-2011 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include "retroshare/rsconfig.h"
#include "pqi/p3peermgr.h"
#include "pqi/p3linkmgr.h"
#include "pqi/p3netmgr.h"
class p3ServerConfig: public RsServerConfig
{
public:
p3ServerConfig(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr, p3NetMgr *netMgr);
virtual ~p3ServerConfig();
/* From RsIface::RsConfig */
virtual int getConfigNetStatus(RsConfigNetStatus &status);
virtual int getConfigStartup(RsConfigStartup &params);
virtual int getConfigDataRates(RsConfigDataRates &params);
/* From RsInit */
virtual std::string RsConfigDirectory();
virtual std::string RsConfigKeysDirectory();
virtual std::string RsProfileConfigDirectory();
virtual bool getStartMinimised();
virtual std::string getRetroShareLink();
virtual bool getAutoLogin();
virtual void setAutoLogin(bool autoLogin);
virtual bool RsClearAutoLogin();
virtual std::string getRetroshareDataDirectory();
/* New Stuff */
virtual uint32_t getUserLevel();
virtual uint32_t getNetState();
virtual uint32_t getNetworkMode();
virtual uint32_t getNatTypeMode();
virtual uint32_t getNatHoleMode();
virtual uint32_t getConnectModes();
/********************* ABOVE is RsConfig Interface *******/
private:
p3PeerMgr *mPeerMgr;
p3LinkMgr *mLinkMgr;
p3NetMgr *mNetMgr;
RsMutex configMtx;
uint32_t mUserLevel; // store last one... will later be a config Item too.
};
#endif

View File

@ -1732,6 +1732,8 @@ RsTurtle *rsTurtle = NULL ;
#include "rsserver/p3discovery.h"
#include "rsserver/p3photo.h"
#include "rsserver/p3status.h"
#include "rsserver/p3serverconfig.h"
#include "retroshare/rsgame.h"
#include "pqi/p3notify.h" // HACK - moved to pqi for compilation order.
@ -2300,6 +2302,7 @@ int RsServer::StartupRetroShare()
rsPeers = new p3Peers(mLinkMgr, mPeerMgr, mNetMgr);
rsDisc = new p3Discovery(ad);
rsConfig = new p3ServerConfig(mPeerMgr, mLinkMgr, mNetMgr);
#ifndef MINIMAL_LIBRS
rsMsgs = new p3Msgs(msgSrv, chatSrv);