2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* "$Id: p3face-config.cc,v 1.4 2007-05-05 16:10:05 rmf24 Exp $"
|
|
|
|
*
|
|
|
|
* RetroShare C++ Interface.
|
|
|
|
*
|
|
|
|
* Copyright 2004-2006 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/p3face.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
2010-01-13 15:56:55 -05:00
|
|
|
#include "pqi/authssl.h"
|
2010-01-13 16:22:52 -05:00
|
|
|
#include "pqi/authgpg.h"
|
2010-08-06 05:40:23 -04:00
|
|
|
#include "retroshare/rsinit.h"
|
2008-07-10 12:29:18 -04:00
|
|
|
#include "util/rsdebug.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
const int p3facemsgzone = 11453;
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************/
|
|
|
|
/* RsIface Config */
|
|
|
|
/* Config */
|
|
|
|
|
2009-06-08 13:09:00 -04:00
|
|
|
int RsServer::ConfigSetDataRates( int totalDownload, int totalUpload ) /* in kbrates */
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
/* fill the rsiface class */
|
|
|
|
RsIface &iface = getIface();
|
|
|
|
|
|
|
|
/* lock Mutexes */
|
|
|
|
lockRsCore(); /* LOCK */
|
|
|
|
iface.lockData(); /* LOCK */
|
|
|
|
|
2009-06-08 13:09:00 -04:00
|
|
|
pqih -> setMaxRate(true, totalDownload);
|
|
|
|
pqih -> setMaxRate(false, totalUpload);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-04-04 08:19:50 -04:00
|
|
|
pqih -> save_config();
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* unlock Mutexes */
|
|
|
|
iface.unlockData(); /* UNLOCK */
|
|
|
|
unlockRsCore(); /* UNLOCK */
|
|
|
|
|
|
|
|
/* does its own locking */
|
|
|
|
UpdateAllConfig();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-09 20:47:24 -04:00
|
|
|
int RsServer::ConfigGetDataRates( float &inKb, float &outKb ) /* in kbrates */
|
|
|
|
{
|
|
|
|
/* fill the rsiface class */
|
|
|
|
RsIface &iface = getIface();
|
|
|
|
|
|
|
|
/* lock Mutexes */
|
|
|
|
lockRsCore(); /* LOCK */
|
|
|
|
iface.lockData(); /* LOCK */
|
|
|
|
|
|
|
|
pqih -> getCurrentRates(inKb, outKb);
|
|
|
|
|
|
|
|
/* unlock Mutexes */
|
|
|
|
iface.unlockData(); /* UNLOCK */
|
|
|
|
unlockRsCore(); /* UNLOCK */
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
int RsServer::ConfigSetBootPrompt( bool on )
|
|
|
|
{
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int RsServer::UpdateAllConfig()
|
|
|
|
{
|
|
|
|
/* fill the rsiface class */
|
|
|
|
RsIface &iface = getIface();
|
|
|
|
|
|
|
|
/* lock Mutexes */
|
|
|
|
lockRsCore(); /* LOCK */
|
|
|
|
iface.lockData(); /* LOCK */
|
|
|
|
|
|
|
|
RsConfig &config = iface.mConfig;
|
|
|
|
|
2010-01-13 15:58:58 -05:00
|
|
|
config.ownId = AuthSSL::getAuthSSL()->OwnId();
|
2010-01-13 16:22:52 -05:00
|
|
|
config.ownName = AuthGPG::getAuthGPG()->getGPGOwnName();
|
2008-01-25 02:58:29 -05:00
|
|
|
peerConnectState pstate;
|
2010-01-13 16:22:52 -05:00
|
|
|
mConnMgr->getOwnNetStatus(pstate);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* ports */
|
2010-07-10 16:34:03 -04:00
|
|
|
config.localAddr = rs_inet_ntoa(pstate.currentlocaladdr.sin_addr);
|
2009-11-11 11:43:51 -05:00
|
|
|
config.localPort = ntohs(pstate.currentlocaladdr.sin_port);
|
2008-04-06 16:57:36 -04:00
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
config.firewalled = true;
|
|
|
|
config.forwardPort = true;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-07-10 16:34:03 -04:00
|
|
|
config.extAddr = rs_inet_ntoa(pstate.currentserveraddr.sin_addr);
|
2009-11-11 11:43:51 -05:00
|
|
|
config.extPort = ntohs(pstate.currentserveraddr.sin_port);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* data rates */
|
2009-06-08 13:09:00 -04:00
|
|
|
config.maxDownloadDataRate = (int) pqih -> getMaxRate(true); /* kb */
|
|
|
|
config.maxUploadDataRate = (int) pqih -> getMaxRate(false); /* kb */
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
config.promptAtBoot = true; /* popup the password prompt */
|
|
|
|
|
2008-10-18 12:02:06 -04:00
|
|
|
/* update network configuration */
|
|
|
|
|
2010-07-04 06:42:17 -04:00
|
|
|
pqiNetStatus status;
|
|
|
|
mConnMgr->getNetStatus(status);
|
2010-10-31 09:53:28 -04:00
|
|
|
|
2010-07-04 06:42:17 -04:00
|
|
|
config.netLocalOk = status.mLocalAddrOk;
|
|
|
|
config.netUpnpOk = status.mUpnpOk;
|
|
|
|
config.netStunOk = false;
|
|
|
|
config.netExtraAddressOk = status.mExtAddrOk;
|
2008-10-18 12:02:06 -04:00
|
|
|
|
2010-10-31 09:53:28 -04:00
|
|
|
config.netDhtOk = status.mDhtOk;
|
|
|
|
config.netDhtNetSize = status.mDhtNetworkSize;
|
|
|
|
config.netDhtRsNetSize = status.mDhtRsNetworkSize;
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* update DHT/UPnP config */
|
2008-01-25 02:58:29 -05:00
|
|
|
|
|
|
|
config.uPnPState = mConnMgr->getUPnPState();
|
|
|
|
config.uPnPActive = mConnMgr->getUPnPEnabled();
|
|
|
|
config.DHTPeers = 20;
|
2008-06-09 20:47:24 -04:00
|
|
|
config.DHTActive = mConnMgr->getDHTEnabled();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* Notify of Changes */
|
2009-02-22 12:36:39 -05:00
|
|
|
// iface.setChanged(RsIface::Config);
|
|
|
|
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_CONFIG, NOTIFY_TYPE_MOD);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* unlock Mutexes */
|
|
|
|
iface.unlockData(); /* UNLOCK */
|
|
|
|
unlockRsCore(); /* UNLOCK */
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
void RsServer::ConfigFinalSave()
|
|
|
|
{
|
2008-11-13 18:03:46 -05:00
|
|
|
/* force saving of transfers TODO */
|
2008-11-02 06:38:11 -05:00
|
|
|
//ftserver->saveFileTransferStatus();
|
2010-04-08 08:02:46 -04:00
|
|
|
if(!RsInit::getAutoLogin())
|
|
|
|
RsInit::RsClearAutoLogin();
|
2008-02-08 07:39:40 -05:00
|
|
|
|
2010-01-13 16:22:52 -05:00
|
|
|
//AuthSSL::getAuthSSL()->FinalSaveCertificates();
|
2008-02-07 11:18:34 -05:00
|
|
|
mConfigMgr->completeConfiguration();
|
|
|
|
}
|
|
|
|
|
2008-04-06 16:57:36 -04:00
|
|
|
void RsServer::rsGlobalShutDown()
|
|
|
|
{
|
2010-05-08 12:10:34 -04:00
|
|
|
// TODO: cache should also clean up old files
|
2010-12-18 14:35:07 -05:00
|
|
|
|
2008-04-06 16:57:36 -04:00
|
|
|
ConfigFinalSave(); // save configuration before exit
|
2008-04-09 08:54:15 -04:00
|
|
|
mConnMgr->shutdown(); /* Handles UPnP */
|
|
|
|
|
2010-05-29 11:14:25 -04:00
|
|
|
join();
|
|
|
|
ftserver->StopThreads();
|
2010-09-30 15:05:43 -04:00
|
|
|
|
2011-04-03 12:20:47 -04:00
|
|
|
// stop the p3distrib threads
|
|
|
|
#ifndef MINIMAL_LIBRS
|
|
|
|
mForums->join();
|
|
|
|
mChannels->join();
|
|
|
|
|
|
|
|
#ifdef RS_USE_BLOGS
|
|
|
|
mBlogs->join();
|
|
|
|
#endif
|
|
|
|
#endif // MINIMAL_LIBRS
|
|
|
|
|
2010-09-30 15:05:43 -04:00
|
|
|
AuthGPGExit();
|
2010-05-29 11:14:25 -04:00
|
|
|
}
|