2007-11-14 22:18:48 -05:00
/*
2009-07-30 17:27:47 -04:00
* libretroshare / src / reserver rsinit . cc
2007-11-14 22:18:48 -05:00
*
* 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 " .
*
*/
2009-07-30 17:27:47 -04:00
/* This is an updated startup class. Class variables are hidden from
* the GUI / External via a hidden class * /
2008-11-02 06:38:11 -05:00
2009-07-30 17:27:47 -04:00
# include <unistd.h>
2010-07-01 16:30:36 -04:00
# ifndef WINDOWS_SYS
2012-10-09 19:07:51 -04:00
// for locking instances
2010-07-01 16:30:36 -04:00
# include <errno.h>
2012-10-09 19:07:51 -04:00
# else
# include "util/rswin.h"
2010-07-01 16:30:36 -04:00
# endif
2013-08-06 13:01:38 -04:00
# include "util/argstream.h"
2008-07-10 12:29:18 -04:00
# include "util/rsdebug.h"
2007-11-14 22:18:48 -05:00
# include "util/rsdir.h"
2011-02-01 18:27:53 -05:00
# include "util/rsrandom.h"
2011-04-03 19:11:38 -04:00
# include "util/folderiterator.h"
2011-10-01 09:12:28 -04:00
# include "util/rsstring.h"
2010-08-06 05:40:23 -04:00
# include "retroshare/rsinit.h"
2011-06-16 17:59:26 -04:00
# include "plugins/pluginmanager.h"
2014-01-17 21:32:55 -05:00
2011-02-01 18:27:53 -05:00
# include "rsserver/rsloginhandler.h"
2014-01-17 21:32:55 -05:00
# include "rsserver/rsaccounts.h"
2009-03-13 17:14:30 -04:00
2007-11-14 22:18:48 -05:00
# include <list>
# include <string>
2009-07-30 17:27:47 -04:00
# include <dirent.h>
# include <sys/types.h>
# include <sys/stat.h>
2013-09-23 16:55:34 -04:00
# include <openssl/rand.h>
2009-07-30 17:27:47 -04:00
# include <fcntl.h>
2012-02-19 15:05:41 -05:00
# if (defined(__unix__) || defined(unix)) && !defined(USG)
# include <sys/param.h>
# endif
2007-11-14 22:18:48 -05:00
// for blocking signals
# include <signal.h>
2013-09-26 19:53:06 -04:00
# include <openssl/ssl.h>
2010-01-13 15:52:31 -05:00
# include "pqi/authssl.h"
2010-06-26 08:31:24 -04:00
# include "pqi/sslfns.h"
2010-01-13 15:56:55 -05:00
# include "pqi/authgpg.h"
2008-01-25 02:58:29 -05:00
2013-11-02 10:35:33 -04:00
# ifdef GROUTER
# include "grouter/p3grouter.h"
# endif
2011-06-29 14:02:44 -04:00
# include "tcponudp/udpstunner.h"
2012-07-25 18:43:43 -04:00
// #define GPG_DEBUG
// #define AUTHSSL_DEBUG
// #define FIM_DEBUG
2009-07-30 17:27:47 -04:00
2014-01-17 21:32:55 -05:00
//std::map<std::string,std::vector<std::string> > RsInit::unsupported_keys ;
2009-07-30 17:27:47 -04:00
class RsInitConfig
{
public :
2014-01-17 21:32:55 -05:00
2014-03-17 16:56:06 -04:00
static RsFileHash main_executable_hash ;
2014-01-17 21:32:55 -05:00
2010-04-30 10:34:48 -04:00
# ifdef WINDOWS_SYS
static bool portable ;
2010-10-07 07:17:42 -04:00
static bool isWindowsXP ;
2010-04-30 10:34:48 -04:00
# endif
2012-06-14 18:53:02 -04:00
static rs_lock_handle_t lockHandle ;
2010-07-01 16:30:36 -04:00
2009-08-18 08:43:19 -04:00
static std : : string passwd ;
2013-06-20 15:50:25 -04:00
static std : : string gxs_passwd ;
2009-07-30 17:27:47 -04:00
static bool autoLogin ; /* autoLogin allowed */
static bool startMinimised ; /* Icon or Full Window */
/* Key Parameters that must be set before
* RetroShare will start up :
*/
/* Listening Port */
static bool forceExtPort ;
static bool forceLocalAddr ;
static unsigned short port ;
2013-08-06 13:01:38 -04:00
static std : : string inet ;
2009-07-30 17:27:47 -04:00
2013-09-08 22:10:49 -04:00
/* v0.6 features */
2014-01-17 21:32:55 -05:00
static bool hiddenNodeSet ;
2013-09-08 22:10:49 -04:00
static std : : string hiddenNodeAddress ;
static uint16_t hiddenNodePort ;
2009-07-30 17:27:47 -04:00
/* Logging */
static bool haveLogFile ;
static bool outStderr ;
static int debugLevel ;
2011-03-21 18:16:03 -04:00
static std : : string logfname ;
2009-07-30 17:27:47 -04:00
static bool load_trustedpeer ;
static std : : string load_trustedpeer_file ;
static bool udpListenerOnly ;
2011-04-14 17:59:51 -04:00
static std : : string RetroShareLink ;
2009-07-30 17:27:47 -04:00
} ;
2007-11-14 22:18:48 -05:00
const int p3facestartupzone = 47238 ;
// initial configuration bootstrapping...
2014-01-17 21:32:55 -05:00
//static const std::string configInitFile = "default_cert.txt";
//static const std::string configConfFile = "config.rs";
//static const std::string configCertDir = "friends";
//static const std::string configKeyDir = "keys";
//static const std::string configCaFile = "cacerts.pem";
//static const std::string configHelpName = "retro.htm";
2007-11-14 22:18:48 -05:00
static const std : : string configLogFileName = " retro.log " ;
2011-01-29 09:27:16 -05:00
static const int SSLPWD_LEN = 64 ;
2007-11-14 22:18:48 -05:00
2014-03-17 16:56:06 -04:00
RsFileHash RsInitConfig : : main_executable_hash ;
2009-07-30 17:27:47 -04:00
2012-06-14 18:53:02 -04:00
rs_lock_handle_t RsInitConfig : : lockHandle ;
2010-07-01 16:30:36 -04:00
2009-07-30 17:27:47 -04:00
std : : string RsInitConfig : : passwd ;
2013-06-20 15:50:25 -04:00
std : : string RsInitConfig : : gxs_passwd ;
2009-02-08 09:30:28 -05:00
2009-07-30 17:27:47 -04:00
bool RsInitConfig : : autoLogin ; /* autoLogin allowed */
bool RsInitConfig : : startMinimised ; /* Icon or Full Window */
2011-04-14 17:59:51 -04:00
std : : string RsInitConfig : : RetroShareLink ;
2009-02-08 09:30:28 -05:00
/* Directories */
2010-04-30 10:34:48 -04:00
# ifdef WINDOWS_SYS
bool RsInitConfig : : portable = false ;
2010-10-07 07:17:42 -04:00
bool RsInitConfig : : isWindowsXP = false ;
2010-04-30 10:34:48 -04:00
# endif
2009-02-08 09:30:28 -05:00
/* Listening Port */
2009-07-30 17:27:47 -04:00
bool RsInitConfig : : forceExtPort ;
bool RsInitConfig : : forceLocalAddr ;
unsigned short RsInitConfig : : port ;
2013-08-06 13:01:38 -04:00
std : : string RsInitConfig : : inet ;
2009-02-08 09:30:28 -05:00
2013-09-08 22:10:49 -04:00
/* v0.6 features */
2014-01-17 21:32:55 -05:00
bool RsInitConfig : : hiddenNodeSet = false ;
2013-09-08 22:10:49 -04:00
std : : string RsInitConfig : : hiddenNodeAddress ;
uint16_t RsInitConfig : : hiddenNodePort ;
2009-02-08 09:30:28 -05:00
/* Logging */
2009-07-30 17:27:47 -04:00
bool RsInitConfig : : haveLogFile ;
bool RsInitConfig : : outStderr ;
int RsInitConfig : : debugLevel ;
2011-03-21 18:16:03 -04:00
std : : string RsInitConfig : : logfname ;
2009-02-08 09:30:28 -05:00
2009-07-30 17:27:47 -04:00
bool RsInitConfig : : load_trustedpeer ;
std : : string RsInitConfig : : load_trustedpeer_file ;
2009-02-08 09:30:28 -05:00
2009-07-30 17:27:47 -04:00
bool RsInitConfig : : udpListenerOnly ;
2009-02-08 09:30:28 -05:00
2007-11-14 22:18:48 -05:00
2009-02-08 09:30:28 -05:00
void RsInit : : InitRsConfig ( )
2007-11-14 22:18:48 -05:00
{
# ifndef WINDOWS_SYS
2010-07-01 16:30:36 -04:00
RsInitConfig : : lockHandle = - 1 ;
2007-11-14 22:18:48 -05:00
# else
2010-09-29 20:27:23 -04:00
RsInitConfig : : lockHandle = NULL ;
2007-11-14 22:18:48 -05:00
# endif
2009-07-30 17:27:47 -04:00
RsInitConfig : : load_trustedpeer = false ;
2011-02-09 15:21:28 -05:00
RsInitConfig : : port = 0 ;
2009-07-30 17:27:47 -04:00
RsInitConfig : : forceLocalAddr = false ;
RsInitConfig : : haveLogFile = false ;
RsInitConfig : : outStderr = false ;
RsInitConfig : : forceExtPort = false ;
2013-08-06 13:01:38 -04:00
RsInitConfig : : inet = std : : string ( " 127.0.0.1 " ) ;
2009-07-30 17:27:47 -04:00
2010-04-08 08:02:46 -04:00
RsInitConfig : : autoLogin = false ; // .
2009-07-30 17:27:47 -04:00
RsInitConfig : : startMinimised = false ;
RsInitConfig : : passwd = " " ;
RsInitConfig : : debugLevel = PQL_WARNING ;
RsInitConfig : : udpListenerOnly = false ;
2010-04-30 10:34:48 -04:00
/* setup the homePath (default save location) */
2014-01-17 21:32:55 -05:00
// RsInitConfig::homePath = getHomePath();
2009-07-30 17:27:47 -04:00
2010-04-30 10:34:48 -04:00
# ifdef WINDOWS_SYS
// test for portable version
2012-06-09 20:29:46 -04:00
if ( GetFileAttributes ( L " portable " ) ! = ( DWORD ) - 1 ) {
2010-04-30 10:34:48 -04:00
// use portable version
RsInitConfig : : portable = true ;
}
2010-10-07 07:17:42 -04:00
// test for Windows XP
OSVERSIONINFOEX osvi ;
memset ( & osvi , 0 , sizeof ( osvi ) ) ;
osvi . dwOSVersionInfoSize = sizeof ( OSVERSIONINFOEX ) ;
if ( GetVersionEx ( ( OSVERSIONINFO * ) & osvi ) ) {
if ( osvi . dwMajorVersion = = 5 ) {
if ( osvi . dwMinorVersion = = 1 ) {
/* Windows XP */
RsInitConfig : : isWindowsXP = true ;
} else if ( osvi . dwMinorVersion = = 2 ) {
SYSTEM_INFO si ;
memset ( & si , 0 , sizeof ( si ) ) ;
GetSystemInfo ( & si ) ;
if ( osvi . wProductType = = VER_NT_WORKSTATION & & si . wProcessorArchitecture = = PROCESSOR_ARCHITECTURE_AMD64 ) {
/* Windows XP Professional x64 Edition */
RsInitConfig : : isWindowsXP = true ;
}
}
}
}
if ( RsInitConfig : : isWindowsXP ) {
std : : cerr < < " Running Windows XP " < < std : : endl ;
} else {
std : : cerr < < " Not running Windows XP " < < std : : endl ;
}
2010-04-30 10:34:48 -04:00
# endif
2007-11-14 22:18:48 -05:00
/* Setup the Debugging */
// setup debugging for desired zones.
setOutputLevel ( PQL_WARNING ) ; // default to Warnings.
// For Testing purposes.
// We can adjust everything under Linux.
//setZoneLevel(PQL_DEBUG_BASIC, 38422); // pqipacket.
//setZoneLevel(PQL_DEBUG_BASIC, 96184); // pqinetwork;
//setZoneLevel(PQL_DEBUG_BASIC, 82371); // pqiperson.
//setZoneLevel(PQL_DEBUG_BASIC, 34283); // pqihandler.
//setZoneLevel(PQL_DEBUG_BASIC, 44863); // discItems.
//setZoneLevel(PQL_DEBUG_BASIC, 1728); // pqi/p3proxy
//setZoneLevel(PQL_DEBUG_BASIC, 1211); // sslroot.
//setZoneLevel(PQL_DEBUG_BASIC, 37714); // pqissl.
//setZoneLevel(PQL_DEBUG_BASIC, 8221); // pqistreamer.
//setZoneLevel(PQL_DEBUG_BASIC, 9326); // pqiarchive
//setZoneLevel(PQL_DEBUG_BASIC, 3334); // p3channel.
//setZoneLevel(PQL_DEBUG_BASIC, 354); // pqipersongrp.
//setZoneLevel(PQL_DEBUG_BASIC, 6846); // pqiudpproxy
//setZoneLevel(PQL_DEBUG_BASIC, 3144); // pqissludp;
//setZoneLevel(PQL_DEBUG_BASIC, 86539); // pqifiler.
//setZoneLevel(PQL_DEBUG_BASIC, 91393); // Funky_Browser.
//setZoneLevel(PQL_DEBUG_BASIC, 25915); // fltkserver
//setZoneLevel(PQL_DEBUG_BASIC, 47659); // fldxsrvr
//setZoneLevel(PQL_DEBUG_BASIC, 49787); // pqissllistener
}
2012-01-07 06:28:00 -05:00
/********
* LOCALNET_TESTING - allows port restrictions
2012-01-11 05:24:37 -05:00
*
* # define LOCALNET_TESTING 1
*
2012-01-07 06:28:00 -05:00
* * * * * * * */
# ifdef LOCALNET_TESTING
std : : string portRestrictions ;
bool doPortRestrictions = false ;
# endif
2008-06-14 09:22:39 -04:00
2007-11-14 22:18:48 -05:00
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
# ifndef WINDOWS_SYS
2010-05-08 17:44:08 -04:00
int RsInit : : InitRetroShare ( int argc , char * * argv , bool strictCheck )
2007-11-14 22:18:48 -05:00
{
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
# else
/* for static PThreads under windows... we need to init the library...
*/
# ifdef PTW32_STATIC_LIB
# include <pthread.h>
2008-09-21 16:30:34 -04:00
# endif
2007-11-14 22:18:48 -05:00
2010-05-08 17:44:08 -04:00
int RsInit : : InitRetroShare ( int argcIgnored , char * * argvIgnored , bool strictCheck )
2007-11-14 22:18:48 -05:00
{
/* THIS IS A HACK TO ALLOW WINDOWS TO ACCEPT COMMANDLINE ARGUMENTS */
int argc ;
2010-09-01 17:08:08 -04:00
int i ;
# ifdef USE_CMD_ARGS
char * * argv = argvIgnored ;
argc = argcIgnored ;
# else
const int MAX_ARGS = 32 ;
int j ;
2007-11-14 22:18:48 -05:00
char * argv [ MAX_ARGS ] ;
2009-02-08 09:30:28 -05:00
char * wholeline = ( char * ) GetCommandLine ( ) ;
2007-11-14 22:18:48 -05:00
int cmdlen = strlen ( wholeline ) ;
// duplicate line, so we can put in spaces..
char dupline [ cmdlen + 1 ] ;
strcpy ( dupline , wholeline ) ;
2008-09-21 16:30:34 -04:00
/* break wholeline down ....
* NB . This is very simplistic , and will not
2007-11-14 22:18:48 -05:00
* handle multiple spaces , or quotations etc , only for debugging purposes
*/
argv [ 0 ] = dupline ;
for ( i = 1 , j = 0 ; ( j + 1 < cmdlen ) & & ( i < MAX_ARGS ) ; )
{
2010-09-01 17:08:08 -04:00
/* find next space. */
for ( ; ( j + 1 < cmdlen ) & & ( dupline [ j ] ! = ' ' ) ; j + + ) ;
if ( j + 1 < cmdlen )
{
dupline [ j ] = ' \0 ' ;
argv [ i + + ] = & ( dupline [ j + 1 ] ) ;
}
2007-11-14 22:18:48 -05:00
}
argc = i ;
2010-09-01 17:08:08 -04:00
# endif
2007-11-14 22:18:48 -05:00
for ( i = 0 ; i < argc ; i + + )
2014-01-15 15:18:21 -05:00
printf ( " %d: %s \n " , i , argv [ i ] ) ;
2010-09-01 17:08:08 -04:00
2007-11-14 22:18:48 -05:00
/* for static PThreads under windows... we need to init the library...
*/
# ifdef PTW32_STATIC_LIB
pthread_win32_process_attach_np ( ) ;
2008-09-21 16:30:34 -04:00
# endif
2007-11-14 22:18:48 -05:00
# endif
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
2014-01-17 21:32:55 -05:00
std : : string prefUserString = " " ;
std : : string opt_base_dir ;
2013-08-08 10:10:45 -04:00
2010-04-10 18:06:11 -04:00
/* getopt info: every availiable option is listed here. if it is followed by a ':' it
needs an argument . If it is followed by a ' : : ' the argument is optional .
*/
2013-08-06 13:01:38 -04:00
//RsInitConfig::logfname = "" ;
//RsInitConfig::inet = "" ;
2013-08-27 22:11:52 -04:00
# ifdef __APPLE__
/* HACK to avoid stupid OSX Finder behaviour
* remove the commandline arguments - if we detect we are launched from Finder ,
* and we have the unparsable " -psn_0_12332 " option .
* this is okay , as you cannot pass commandline arguments via Finder anyway
*/
if ( ( argc > = 2 ) & & ( 0 = = strncmp ( argv [ 1 ] , " -psn " , 4 ) ) )
{
argc = 1 ;
}
# endif
2013-08-06 13:01:38 -04:00
argstream as ( argc , argv ) ;
2013-08-27 22:11:52 -04:00
2013-08-06 13:01:38 -04:00
as > > option ( ' a ' , " auto-login " , RsInitConfig : : autoLogin , " AutoLogin (Windows Only) + StartMinimised " )
> > option ( ' m ' , " minimized " , RsInitConfig : : startMinimised , " Start minimized. " )
> > option ( ' s ' , " stderr " , RsInitConfig : : outStderr , " output to stderr instead of log file. " )
> > option ( ' u ' , " udp " , RsInitConfig : : udpListenerOnly , " Only listen to UDP. " )
> > option ( ' e ' , " external-port " , RsInitConfig : : forceExtPort , " Use a forwarded external port. " )
> > parameter ( ' l ' , " log-file " , RsInitConfig : : logfname , " logfile " , " Set Log filename. " , false )
> > parameter ( ' d ' , " debug-level " , RsInitConfig : : debugLevel , " level " , " Set debug level. " , false )
> > parameter ( ' w ' , " password " , RsInitConfig : : passwd , " password " , " Set Login Password. " , false )
> > parameter ( ' i ' , " ip-address " , RsInitConfig : : inet , " nnn.nnn.nnn.nnn " , " Set IP address to use. " , false )
> > parameter ( ' p ' , " port " , RsInitConfig : : port , " port " , " Set listenning port to use. " , false )
2014-01-17 21:32:55 -05:00
> > parameter ( ' c ' , " base-dir " , opt_base_dir , " directory " , " Set base directory. " , false )
2013-08-06 13:01:38 -04:00
> > parameter ( ' U ' , " user-id " , prefUserString , " ID " , " [User Name/GPG id/SSL id] Sets Account to Use, Useful when Autologin is enabled " , false )
> > parameter ( ' r ' , " link " , RsInitConfig : : RetroShareLink , " retroshare://... " , " Use a given Retroshare Link " , false )
# ifdef LOCALNET_TESTING
> > parameter ( ' R ' , " restrict-port " , portRestrictions , " port1-port2 " , " Apply port restriction " , false )
# endif
> > help ( ) ;
as . defaultErrorHandling ( true ) ;
if ( RsInitConfig : : autoLogin ) RsInitConfig : : startMinimised = true ;
if ( RsInitConfig : : outStderr ) RsInitConfig : : haveLogFile = false ;
if ( ! RsInitConfig : : logfname . empty ( ) ) RsInitConfig : : haveLogFile = true ;
2013-08-08 10:10:45 -04:00
if ( RsInitConfig : : inet ! = " 127.0.0.1 " ) RsInitConfig : : forceLocalAddr = true ;
2013-08-06 13:01:38 -04:00
# ifdef LOCALNET_TESTING
if ( ! portRestrictions . empty ( ) ) doPortRestrictions = true ;
# endif
# ifdef SUSPENDED_CODE
2012-01-07 06:28:00 -05:00
# ifdef LOCALNET_TESTING
while ( ( c = getopt ( argc , argv , " hesamui:p:c:w:l:d:U:r:R: " ) ) ! = - 1 )
# else
2011-04-14 17:59:51 -04:00
while ( ( c = getopt ( argc , argv , " hesamui:p:c:w:l:d:U:r: " ) ) ! = - 1 )
2012-01-07 06:28:00 -05:00
# endif
2010-04-10 18:06:11 -04:00
{
switch ( c )
{
case ' h ' :
std : : cerr < < " Help: " < < std : : endl ;
std : : cerr < < " The commandline options are for retroshare-nogui, a headless server in a shell, or systems without QT. " < < std : : endl < < std : : endl ;
std : : cerr < < " -l [logfile] Set the logfilename " < < std : : endl ;
std : : cerr < < " -w [password] Set the password " < < std : : endl ;
std : : cerr < < " -i [ip_adress] Set IP Adress to use " < < std : : endl ;
std : : cerr < < " -p [port] Set the Port to listen on " < < std : : endl ;
std : : cerr < < " -c [basedir] Set the config basdir " < < std : : endl ;
std : : cerr < < " -s Output to Stderr " < < std : : endl ;
std : : cerr < < " -d [debuglevel] Set the debuglevel " < < std : : endl ;
std : : cerr < < " -a AutoLogin (Windows Only) + StartMinimised " < < std : : endl ;
std : : cerr < < " -m StartMinimised " < < std : : endl ;
std : : cerr < < " -u Only listen to UDP " < < std : : endl ;
2010-06-27 12:28:44 -04:00
std : : cerr < < " -e Use a forwarded external Port " < < std : : endl ;
std : : cerr < < " -U [User Name/GPG id/SSL id] Sets Account to Use, Useful when Autologin is enabled. " < < std : : endl ;
2011-04-14 17:59:51 -04:00
std : : cerr < < " -r link Use RetroShare link. " < < std : : endl ;
2012-01-07 06:28:00 -05:00
# ifdef LOCALNET_TESTING
std : : cerr < < " -R <lport-uport> Port Restrictions. " < < std : : endl ;
# endif
2010-04-10 18:06:11 -04:00
exit ( 1 ) ;
break ;
default :
2011-04-14 17:59:51 -04:00
if ( strictCheck ) {
2010-05-08 17:44:08 -04:00
std : : cerr < < " Unknown Option! " < < std : : endl ;
std : : cerr < < " Use '-h' for help. " < < std : : endl ;
exit ( 1 ) ;
2011-04-14 17:59:51 -04:00
}
2010-04-10 18:06:11 -04:00
}
}
2013-08-06 13:01:38 -04:00
# endif
2007-11-14 22:18:48 -05:00
2013-08-06 13:01:38 -04:00
setOutputLevel ( RsInitConfig : : debugLevel ) ;
2007-11-14 22:18:48 -05:00
2013-08-06 13:01:38 -04:00
// // set the default Debug Level...
// if (RsInitConfig::haveDebugLevel)
// {
// if ((RsInitConfig::debugLevel > 0) &&
// (RsInitConfig::debugLevel <= PQL_DEBUG_ALL))
// {
// std::cerr << "Setting Debug Level to: ";
// std::cerr << RsInitConfig::debugLevel;
// std::cerr << std::endl;
// }
// else
// {
// std::cerr << "Ignoring Invalid Debug Level: ";
// std::cerr << RsInitConfig::debugLevel;
// std::cerr << std::endl;
// }
// }
2007-11-14 22:18:48 -05:00
// set the debug file.
2009-07-30 17:27:47 -04:00
if ( RsInitConfig : : haveLogFile )
2011-03-21 18:16:03 -04:00
setDebugFile ( RsInitConfig : : logfname . c_str ( ) ) ;
2007-11-14 22:18:48 -05:00
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
# ifndef WINDOWS_SYS
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
# else
// Windows Networking Init.
WORD wVerReq = MAKEWORD ( 2 , 2 ) ;
WSADATA wsaData ;
if ( 0 ! = WSAStartup ( wVerReq , & wsaData ) )
{
std : : cerr < < " Failed to Startup Windows Networking " ;
std : : cerr < < std : : endl ;
}
else
{
std : : cerr < < " Started Windows Networking " ;
std : : cerr < < std : : endl ;
}
# endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
// SWITCH off the SIGPIPE - kills process on Linux.
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
# ifndef WINDOWS_SYS
struct sigaction sigact ;
sigact . sa_handler = SIG_IGN ;
sigact . sa_flags = 0 ;
2009-10-29 20:45:40 -04:00
sigset_t set ;
sigemptyset ( & set ) ;
//sigaddset(&set, SIGINT); // or whatever other signal
sigact . sa_mask = set ;
2007-11-14 22:18:48 -05:00
if ( 0 = = sigaction ( SIGPIPE , & sigact , NULL ) )
{
2013-11-29 17:09:13 -05:00
std : : cerr < < " RetroShare:: Successfully installed the SIGPIPE Block " < < std : : endl ;
2007-11-14 22:18:48 -05:00
}
else
{
2013-11-29 17:09:13 -05:00
std : : cerr < < " RetroShare:: Failed to install the SIGPIPE Block " < < std : : endl ;
2007-11-14 22:18:48 -05:00
}
# endif
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
2012-09-09 09:59:21 -04:00
// Hash the main executable.
uint64_t tmp_size ;
std : : string tmp_name ;
if ( ! RsDirUtil : : getFileHash ( argv [ 0 ] , RsInitConfig : : main_executable_hash , tmp_size , NULL ) )
std : : cerr < < " Cannot hash executable! Plugins will not be loaded correctly. " < < std : : endl ;
else
std : : cerr < < " Hashed main executable: " < < RsInitConfig : : main_executable_hash < < std : : endl ;
2008-11-09 11:52:14 -05:00
2009-07-30 17:27:47 -04:00
/* At this point we want to.
* 1 ) Load up Dase Directory .
* 3 ) Get Prefered Id .
* 2 ) Get List of Available Accounts .
* 4 ) Get List of GPG Accounts .
2008-11-09 11:52:14 -05:00
*/
2010-07-04 06:42:17 -04:00
/* create singletons */
2012-12-26 13:12:19 -05:00
AuthSSL : : AuthSSLInit ( ) ;
2012-04-09 13:03:47 -04:00
AuthSSL : : getAuthSSL ( ) - > InitAuth ( NULL , NULL , NULL ) ;
2009-07-30 17:27:47 -04:00
// first check config directories, and set bootstrap values.
2014-01-17 21:32:55 -05:00
if ( ! rsAccounts . setupBaseDirectory ( opt_base_dir ) )
2011-12-06 18:00:42 -05:00
return RS_INIT_BASE_DIR_ERROR ;
2014-01-17 21:32:55 -05:00
// Setup PGP stuff.
std : : string pgp_dir = rsAccounts . PathPGPDirectory ( ) ;
2013-07-25 16:05:31 -04:00
2012-06-09 17:01:22 -04:00
if ( ! RsDirUtil : : checkCreateDirectory ( pgp_dir ) )
throw std : : runtime_error ( " Cannot create pgp directory " + pgp_dir ) ;
2012-06-20 17:59:04 -04:00
AuthGPG : : init ( pgp_dir + " /retroshare_public_keyring.gpg " ,
pgp_dir + " /retroshare_secret_keyring.gpg " ,
pgp_dir + " /retroshare_trustdb.gpg " ,
pgp_dir + " /lock " ) ;
2012-04-09 13:03:47 -04:00
2014-01-17 21:32:55 -05:00
// load Accounts.
if ( ! rsAccounts . loadAccounts ( ) )
{
2012-06-09 17:01:22 -04:00
return RS_INIT_NO_KEYRING ;
2014-01-17 21:32:55 -05:00
}
2012-06-09 17:01:22 -04:00
2014-01-17 21:32:55 -05:00
// choose alternative account.
2010-06-27 12:28:44 -04:00
if ( prefUserString ! = " " )
{
2014-01-17 21:32:55 -05:00
if ( ! rsAccounts . selectAccountByString ( prefUserString ) )
2010-06-27 12:28:44 -04:00
{
2014-01-17 21:32:55 -05:00
std : : cerr < < " Invalid User name/GPG id/SSL id: not found in list " ;
std : : cerr < < std : : endl ;
2011-12-06 18:00:42 -05:00
return RS_INIT_AUTH_FAILED ;
2010-06-27 12:28:44 -04:00
}
}
2010-04-10 18:06:11 -04:00
2014-01-17 21:32:55 -05:00
/* check that we have selected someone */
2014-03-17 16:56:06 -04:00
RsPeerId preferredId ;
2014-01-17 21:32:55 -05:00
bool existingUser = rsAccounts . getPreferredAccountId ( preferredId ) ;
2010-04-10 18:06:11 -04:00
2007-11-14 22:18:48 -05:00
if ( existingUser )
{
2011-02-01 18:27:53 -05:00
if ( RsInitConfig : : passwd ! = " " )
2007-11-14 22:18:48 -05:00
{
2010-11-03 18:54:34 -04:00
return RS_INIT_HAVE_ACCOUNT ;
2007-11-14 22:18:48 -05:00
}
2010-04-08 08:02:46 -04:00
2014-01-17 21:32:55 -05:00
if ( RsLoginHandler : : getSSLPassword ( preferredId , false , RsInitConfig : : passwd ) )
2007-11-14 22:18:48 -05:00
{
2010-04-08 08:02:46 -04:00
RsInit : : setAutoLogin ( true ) ;
2011-01-29 09:27:16 -05:00
std : : cerr < < " Autologin has succeeded " < < std : : endl ;
2010-11-03 18:54:34 -04:00
return RS_INIT_HAVE_ACCOUNT ;
2007-11-14 22:18:48 -05:00
}
}
2010-11-03 18:54:34 -04:00
return RS_INIT_OK ;
2007-11-14 22:18:48 -05:00
}
2008-09-21 16:30:34 -04:00
2010-07-01 16:30:36 -04:00
/*
* To prevent several running instances from using the same directory
* simultaneously we have to use a global lock .
* We use a lock file on Unix systems .
*
* Return value :
* 0 : Success
* 1 : Another instance already has the lock
* 2 : Unexpected error
*/
2011-03-16 19:25:57 -04:00
int RsInit : : LockConfigDirectory ( const std : : string & accountDir , std : : string & lockFilePath )
2010-07-01 16:30:36 -04:00
{
2011-05-15 08:42:55 -04:00
const std : : string lockFile = accountDir + " / " + " lock " ;
2011-08-12 16:02:00 -04:00
lockFilePath = lockFile ;
2010-09-29 20:27:23 -04:00
2012-06-12 16:31:13 -04:00
return RsDirUtil : : createLockFile ( lockFile , RsInitConfig : : lockHandle ) ;
2010-07-01 16:30:36 -04:00
}
/*
* Unlock the currently locked profile , if there is one .
* For Unix systems we simply close the handle of the lock file .
*/
void RsInit : : UnlockConfigDirectory ( )
{
2012-06-12 16:31:13 -04:00
RsDirUtil : : releaseLockFile ( RsInitConfig : : lockHandle ) ;
2010-07-01 16:30:36 -04:00
}
2008-02-09 07:47:45 -05:00
2013-09-23 16:55:34 -04:00
bool RsInit : : collectEntropy ( uint32_t n )
{
RAND_seed ( & n , 4 ) ;
return true ;
}
2008-01-25 02:58:29 -05:00
2009-07-30 17:27:47 -04:00
/***************************** FINAL LOADING OF SETUP *************************/
/* Login SSL */
2014-01-17 21:32:55 -05:00
bool RsInit : : LoadPassword ( const std : : string & inPwd )
2009-07-30 17:27:47 -04:00
{
RsInitConfig : : passwd = inPwd ;
return true ;
}
2010-07-01 16:30:36 -04:00
/**
* Locks the profile directory and tries to finalize the login procedure
*
* Return value :
* 0 : success
* 1 : another instance is already running
* 2 : unexpected error while locking
* 3 : unexpected error while loading certificates
*/
2011-03-16 19:25:57 -04:00
int RsInit : : LockAndLoadCertificates ( bool autoLoginNT , std : : string & lockFilePath )
2010-07-01 16:30:36 -04:00
{
2014-01-17 21:32:55 -05:00
if ( ! rsAccounts . lockPreferredAccount ( ) )
{
return 3 ; // invalid PreferredAccount.
}
// Logic that used to be external to RsInit...
2014-03-17 16:56:06 -04:00
RsPeerId accountId ;
2014-01-17 21:32:55 -05:00
if ( ! rsAccounts . getPreferredAccountId ( accountId ) )
{
return 3 ; // invalid PreferredAccount;
}
2014-03-17 16:56:06 -04:00
RsPgpId pgpId ;
std : : string pgpName , pgpEmail , location ;
2014-01-17 21:32:55 -05:00
if ( ! rsAccounts . getAccountDetails ( accountId , pgpId , pgpName , pgpEmail , location ) )
return 3 ; // invalid PreferredAccount;
if ( ! rsAccounts . SelectPGPAccount ( pgpId ) )
return 3 ; // PGP Error.
int retVal = LockConfigDirectory ( rsAccounts . PathAccountDirectory ( ) , lockFilePath ) ;
2010-07-01 16:30:36 -04:00
if ( retVal ! = 0 )
return retVal ;
retVal = LoadCertificates ( autoLoginNT ) ;
if ( retVal ! = 1 ) {
UnlockConfigDirectory ( ) ;
return 3 ;
}
return 0 ;
}
2009-07-30 17:27:47 -04:00
2010-07-01 16:30:36 -04:00
/** *************************** FINAL LOADING OF SETUP *************************
2009-07-30 17:27:47 -04:00
* Requires :
* PGPid to be selected ( Password not required ) .
* CertId to be selected ( Password Required ) .
2010-07-01 16:30:36 -04:00
*
* Return value :
* 0 : unexpected error
* 1 : success
2009-07-30 17:27:47 -04:00
*/
int RsInit : : LoadCertificates ( bool autoLoginNT )
{
2014-03-17 16:56:06 -04:00
RsPeerId preferredId ;
2014-01-17 21:32:55 -05:00
if ( ! rsAccounts . getPreferredAccountId ( preferredId ) )
{
std : : cerr < < " No Account Selected " < < std : : endl ;
return 0 ;
}
if ( rsAccounts . PathCertFile ( ) = = " " )
2009-07-30 17:27:47 -04:00
{
std : : cerr < < " RetroShare needs a certificate " < < std : : endl ;
return 0 ;
}
2014-01-17 21:32:55 -05:00
if ( rsAccounts . PathKeyFile ( ) = = " " )
2009-07-30 17:27:47 -04:00
{
std : : cerr < < " RetroShare needs a key " < < std : : endl ;
return 0 ;
}
2009-08-18 08:43:19 -04:00
//check if password is already in memory
2011-02-01 18:27:53 -05:00
2011-08-05 16:45:09 -04:00
if ( RsInitConfig : : passwd = = " " ) {
2014-01-17 21:32:55 -05:00
if ( RsLoginHandler : : getSSLPassword ( preferredId , true , RsInitConfig : : passwd ) = = false ) {
2011-08-05 16:45:09 -04:00
std : : cerr < < " RsLoginHandler::getSSLPassword() Failed! " ;
return 0 ;
}
} else {
2014-01-17 21:32:55 -05:00
if ( RsLoginHandler : : checkAndStoreSSLPasswdIntoGPGFile ( preferredId , RsInitConfig : : passwd ) = = false ) {
2011-08-05 16:45:09 -04:00
std : : cerr < < " RsLoginHandler::checkAndStoreSSLPasswdIntoGPGFile() Failed! " ;
return 0 ;
}
}
2010-04-08 08:02:46 -04:00
2014-01-17 21:32:55 -05:00
std : : cerr < < " rsAccounts.PathKeyFile() : " < < rsAccounts . PathKeyFile ( ) < < std : : endl ;
2010-04-08 08:02:46 -04:00
2014-01-17 21:32:55 -05:00
if ( 0 = = AuthSSL : : getAuthSSL ( ) - > InitAuth ( rsAccounts . PathCertFile ( ) . c_str ( ) , rsAccounts . PathKeyFile ( ) . c_str ( ) , RsInitConfig : : passwd . c_str ( ) ) )
2009-05-23 11:07:35 -04:00
{
std : : cerr < < " SSL Auth Failed! " ;
2011-02-01 18:27:53 -05:00
return 0 ;
2009-05-23 11:07:35 -04:00
}
2007-11-14 22:18:48 -05:00
2011-02-01 18:27:53 -05:00
if ( autoLoginNT )
2007-11-14 22:18:48 -05:00
{
2011-02-01 18:27:53 -05:00
std : : cerr < < " RetroShare will AutoLogin next time " ;
std : : cerr < < std : : endl ;
2007-11-14 22:18:48 -05:00
2014-01-17 21:32:55 -05:00
RsLoginHandler : : enableAutoLogin ( preferredId , RsInitConfig : : passwd ) ;
2011-02-01 18:27:53 -05:00
RsInitConfig : : autoLogin = true ;
2007-11-14 22:18:48 -05:00
}
2011-02-01 18:27:53 -05:00
/* wipe out password */
2013-06-20 15:50:25 -04:00
// store pword to allow gxs use it to services' key their databases
// ideally gxs should have its own password
RsInitConfig : : gxs_passwd = RsInitConfig : : passwd ;
2011-02-01 18:27:53 -05:00
RsInitConfig : : passwd = " " ;
2014-01-17 21:32:55 -05:00
rsAccounts . storePreferredAccount ( ) ;
2011-02-01 18:27:53 -05:00
return 1 ;
}
2011-08-12 16:02:00 -04:00
2011-02-01 18:27:53 -05:00
bool RsInit : : RsClearAutoLogin ( )
{
2014-03-17 16:56:06 -04:00
RsPeerId preferredId ;
2014-01-17 21:32:55 -05:00
if ( ! rsAccounts . getPreferredAccountId ( preferredId ) )
2007-11-14 22:18:48 -05:00
{
2014-01-17 21:32:55 -05:00
std : : cerr < < " RsInit::RsClearAutoLogin() No Account Selected " < < std : : endl ;
return 0 ;
2007-11-14 22:18:48 -05:00
}
2014-01-17 21:32:55 -05:00
return RsLoginHandler : : clearAutoLogin ( preferredId ) ;
2009-07-30 17:27:47 -04:00
}
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
2010-04-30 10:34:48 -04:00
bool RsInit : : isPortable ( )
{
2010-05-02 18:28:33 -04:00
# ifdef WINDOWS_SYS
return RsInitConfig : : portable ;
# else
return false ;
# endif
2010-04-30 10:34:48 -04:00
}
2010-10-07 07:17:42 -04:00
bool RsInit : : isWindowsXP ( )
{
# ifdef WINDOWS_SYS
return RsInitConfig : : isWindowsXP ;
# else
return false ;
# endif
}
2014-01-17 21:32:55 -05:00
2011-04-14 17:59:51 -04:00
bool RsInit : : getStartMinimised ( )
2009-07-30 17:27:47 -04:00
{
return RsInitConfig : : startMinimised ;
}
2011-04-14 17:59:51 -04:00
std : : string RsInit : : getRetroShareLink ( )
{
return RsInitConfig : : RetroShareLink ;
}
2010-04-08 08:02:46 -04:00
int RsInit : : getSslPwdLen ( ) {
return SSLPWD_LEN ;
}
bool RsInit : : getAutoLogin ( ) {
return RsInitConfig : : autoLogin ;
}
void RsInit : : setAutoLogin ( bool autoLogin ) {
RsInitConfig : : autoLogin = autoLogin ;
}
2009-07-30 17:27:47 -04:00
2013-09-08 22:10:49 -04:00
/* Setup Hidden Location; */
bool RsInit : : SetHiddenLocation ( const std : : string & hiddenaddress , uint16_t port )
{
/* parse the bugger (todo) */
2014-01-17 21:32:55 -05:00
RsInitConfig : : hiddenNodeSet = true ;
2013-09-08 22:10:49 -04:00
RsInitConfig : : hiddenNodeAddress = hiddenaddress ;
RsInitConfig : : hiddenNodePort = port ;
return true ;
}
2009-07-30 17:27:47 -04:00
/*
*
* Init Part of RsServer . . . needs the private
* variables so in the same file .
*
*/
# include <unistd.h>
//#include <getopt.h>
# include "dbase/cachestrapper.h"
# include "ft/ftserver.h"
# include "ft/ftcontroller.h"
2010-08-06 05:40:23 -04:00
# include "retroshare/rsiface.h"
# include "retroshare/rsturtle.h"
2009-07-30 17:27:47 -04:00
/* global variable now points straight to
* ft / code so variable defined here .
*/
RsFiles * rsFiles = NULL ;
RsTurtle * rsTurtle = NULL ;
2013-11-02 10:35:33 -04:00
# ifdef GROUTER
RsGRouter * rsGRouter = NULL ;
# endif
2009-07-30 17:27:47 -04:00
# include "pqi/pqipersongrp.h"
# include "pqi/pqisslpersongrp.h"
# include "pqi/pqiloopback.h"
# include "pqi/p3cfgmgr.h"
2011-09-29 05:20:09 -04:00
# include "pqi/p3historymgr.h"
2009-07-30 17:27:47 -04:00
# include "util/rsdebug.h"
# include "util/rsdir.h"
2011-07-09 20:41:39 -04:00
# include "util/rsrandom.h"
2011-12-13 11:19:37 -05:00
# ifdef RS_ENABLE_ZEROCONF
# include "zeroconf/p3zeroconf.h"
2012-01-14 11:41:00 -05:00
# endif
# ifdef RS_ENABLE_ZCNATASSIST
# include "zeroconf/p3zcnatassist.h"
2011-12-13 11:19:37 -05:00
# else
2012-10-28 12:51:00 -04:00
# ifdef RS_USE_LIBUPNP
# include "upnp/upnphandler_linux.h"
# else
# include "upnp/upnphandler_miniupnp.h"
# endif
2011-12-13 11:19:37 -05:00
# endif
2013-09-28 04:09:59 -04:00
# include "services/p3heartbeat.h"
# include "services/p3discovery2.h"
2009-07-30 17:27:47 -04:00
# include "services/p3msgservice.h"
# include "services/p3chatservice.h"
2010-04-15 06:47:48 -04:00
# include "services/p3statusservice.h"
2009-07-30 17:27:47 -04:00
# include "turtle/p3turtle.h"
2010-06-24 14:06:10 -04:00
2012-12-16 10:04:52 -05:00
# ifdef RS_ENABLE_GXS
// NEW GXS SYSTEMS.
2012-08-06 17:00:38 -04:00
# include "gxs/rsdataservice.h"
# include "gxs/rsgxsnetservice.h"
2013-02-28 16:58:38 -05:00
# include "retroshare/rsgxsflags.h"
2012-08-06 17:00:38 -04:00
2012-02-13 13:22:35 -05:00
# include "services/p3idservice.h"
2012-12-16 10:04:52 -05:00
# include "services/p3gxscircles.h"
# include "services/p3wiki.h"
2012-07-01 19:00:54 -04:00
# include "services/p3posted.h"
2012-12-16 10:04:52 -05:00
# include "services/p3photoservice.h"
# include "services/p3gxsforums.h"
2013-03-04 15:26:48 -05:00
# include "services/p3gxschannels.h"
2012-12-16 10:04:52 -05:00
# include "services/p3wire.h"
# endif // RS_ENABLE_GXS
2012-02-04 09:16:39 -05:00
2011-08-03 13:43:26 -04:00
2009-07-30 17:27:47 -04:00
# include <list>
# include <string>
2009-05-23 11:07:35 -04:00
2009-07-30 17:27:47 -04:00
// for blocking signals
# include <signal.h>
2009-05-23 11:07:35 -04:00
2009-07-30 17:27:47 -04:00
/* Implemented Rs Interfaces */
# include "rsserver/p3face.h"
# include "rsserver/p3peers.h"
# include "rsserver/p3msgs.h"
2010-04-15 06:47:48 -04:00
# include "rsserver/p3status.h"
2011-09-29 05:20:09 -04:00
# include "rsserver/p3history.h"
2011-07-11 14:48:56 -04:00
# include "rsserver/p3serverconfig.h"
2009-05-23 11:07:35 -04:00
2009-07-30 17:27:47 -04:00
# include "pqi/p3notify.h" // HACK - moved to pqi for compilation order.
2009-05-23 11:07:35 -04:00
2011-07-09 14:39:34 -04:00
# include "pqi/p3peermgr.h"
# include "pqi/p3linkmgr.h"
# include "pqi/p3netmgr.h"
2010-07-31 14:14:10 -04:00
# include "tcponudp/tou.h"
# include "tcponudp/rsudpstack.h"
2011-07-09 14:39:34 -04:00
2010-07-31 14:14:10 -04:00
# ifdef RS_USE_BITDHT
# include "dht/p3bitdht.h"
2011-07-09 20:41:39 -04:00
# include "dht/stunaddrassist.h"
2010-07-31 14:14:10 -04:00
# include "udp/udpstack.h"
2011-06-29 14:02:44 -04:00
# include "tcponudp/udppeer.h"
# include "tcponudp/udprelay.h"
2010-07-31 14:14:10 -04:00
# endif
2009-05-23 11:07:35 -04:00
2009-07-30 17:27:47 -04:00
/****
2011-08-03 13:43:26 -04:00
* # define RS_RELEASE 1
2013-09-29 03:11:02 -04:00
* # define RS_RTT 1
2009-07-30 17:27:47 -04:00
* * * */
2009-05-23 11:07:35 -04:00
2013-09-29 03:11:02 -04:00
# define RS_RELEASE 1
# define RS_RTT 1
# ifdef RS_RTT
# include "services/p3rtt.h"
# endif
2009-05-23 11:07:35 -04:00
2011-11-24 19:58:01 -05:00
# include "services/p3banlist.h"
2012-06-21 19:23:46 -04:00
# include "services/p3bwctrl.h"
2013-12-22 12:10:56 -05:00
# ifdef SERVICES_DSDV
2011-11-24 19:58:01 -05:00
# include "services/p3dsdv.h"
2013-12-22 12:10:56 -05:00
# endif
2011-11-24 19:58:01 -05:00
2014-01-07 17:51:22 -05:00
RsControl * RsControl : : instance ( )
2009-07-30 17:27:47 -04:00
{
2014-01-07 17:51:22 -05:00
static RsServer * rsicontrol = NULL ;
if ( rsicontrol = = NULL )
rsicontrol = new RsServer ( ) ;
return rsicontrol ;
2009-07-30 17:27:47 -04:00
}
2009-07-12 12:11:09 -04:00
2009-07-30 17:27:47 -04:00
/*
* The Real RetroShare Startup Function .
*/
int RsServer : : StartupRetroShare ( )
{
/**************************************************************************/
/* STARTUP procedure */
/**************************************************************************/
/**************************************************************************/
/* (1) Load up own certificate (DONE ALREADY) - just CHECK */
/**************************************************************************/
2009-05-23 11:07:35 -04:00
2012-09-09 09:59:21 -04:00
if ( 1 ! = AuthSSL : : getAuthSSL ( ) - > InitAuth ( NULL , NULL , NULL ) )
2007-11-14 22:18:48 -05:00
{
2009-07-30 17:27:47 -04:00
std : : cerr < < " main() - Fatal Error..... " < < std : : endl ;
std : : cerr < < " Invalid Certificate configuration! " < < std : : endl ;
std : : cerr < < std : : endl ;
2011-12-06 18:00:42 -05:00
return false ;
2007-11-14 22:18:48 -05:00
}
2014-03-17 16:56:06 -04:00
RsPeerId ownId = AuthSSL : : getAuthSSL ( ) - > OwnId ( ) ;
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
/**************************************************************************/
/* Any Initial Configuration (Commandline Options) */
/**************************************************************************/
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
/* set the debugging to crashMode */
2012-09-09 09:59:21 -04:00
std : : cerr < < " set the debugging to crashMode. " < < std : : endl ;
if ( ( ! RsInitConfig : : haveLogFile ) & & ( ! RsInitConfig : : outStderr ) )
2007-11-14 22:18:48 -05:00
{
2014-01-17 21:32:55 -05:00
std : : string crashfile = rsAccounts . PathAccountDirectory ( ) ;
crashfile + = " / " + configLogFileName ;
2009-07-30 17:27:47 -04:00
setDebugCrashMode ( crashfile . c_str ( ) ) ;
2007-11-14 22:18:48 -05:00
}
2009-07-30 17:27:47 -04:00
unsigned long flags = 0 ;
if ( RsInitConfig : : udpListenerOnly )
{
flags | = PQIPERSON_NO_LISTENER ;
}
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
/**************************************************************************/
// Load up Certificates, and Old Configuration (if present)
2012-09-09 09:59:21 -04:00
std : : cerr < < " Load up Certificates, and Old Configuration (if present). " < < std : : endl ;
2008-09-21 16:30:34 -04:00
2014-01-17 21:32:55 -05:00
std : : string emergencySaveDir = rsAccounts . PathAccountDirectory ( ) ;
std : : string emergencyPartialsDir = rsAccounts . PathAccountDirectory ( ) ;
2010-06-26 08:31:24 -04:00
if ( emergencySaveDir ! = " " )
2007-11-14 22:18:48 -05:00
{
2009-07-30 17:27:47 -04:00
emergencySaveDir + = " / " ;
emergencyPartialsDir + = " / " ;
}
emergencySaveDir + = " Downloads " ;
emergencyPartialsDir + = " Partials " ;
2007-11-14 22:18:48 -05:00
2013-09-08 22:10:49 -04:00
/**************************************************************************/
/* setup Configuration */
/**************************************************************************/
std : : cerr < < " Load Configuration " < < std : : endl ;
2014-01-17 21:32:55 -05:00
mConfigMgr = new p3ConfigMgr ( rsAccounts . PathAccountDirectory ( ) ) ;
2013-09-08 22:10:49 -04:00
mGeneralConfig = new p3GeneralConfig ( ) ;
2014-01-17 21:32:55 -05:00
// Get configuration options from rsAccounts.
bool isHiddenNode = false ;
bool isFirstTimeRun = false ;
rsAccounts . getAccountOptions ( isHiddenNode , isFirstTimeRun ) ;
2013-09-08 22:10:49 -04:00
2009-07-30 17:27:47 -04:00
/**************************************************************************/
/* setup classes / structures */
/**************************************************************************/
2012-09-09 09:59:21 -04:00
std : : cerr < < " setup classes / structures " < < std : : endl ;
2007-11-14 22:18:48 -05:00
2011-09-29 05:20:09 -04:00
/* History Manager */
mHistoryMgr = new p3HistoryMgr ( ) ;
2012-12-26 13:12:19 -05:00
mPeerMgr = new p3PeerMgrIMPL ( AuthSSL : : getAuthSSL ( ) - > OwnId ( ) ,
2013-09-08 22:10:49 -04:00
AuthGPG : : getAuthGPG ( ) - > getGPGOwnId ( ) ,
AuthGPG : : getAuthGPG ( ) - > getGPGOwnName ( ) ,
AuthSSL : : getAuthSSL ( ) - > getOwnLocation ( ) ) ;
2011-07-13 10:22:25 -04:00
mNetMgr = new p3NetMgrIMPL ( ) ;
mLinkMgr = new p3LinkMgrIMPL ( mPeerMgr , mNetMgr ) ;
2011-10-08 13:47:36 -04:00
2012-09-09 09:59:21 -04:00
/* Setup Notify Early - So we can use it. */
rsPeers = new p3Peers ( mLinkMgr , mPeerMgr , mNetMgr ) ;
2011-10-08 13:47:36 -04:00
2012-02-14 17:55:14 -05:00
mPeerMgr - > setManagers ( mLinkMgr , mNetMgr ) ;
2011-07-09 14:39:34 -04:00
mNetMgr - > setManagers ( mPeerMgr , mLinkMgr ) ;
2013-09-08 22:10:49 -04:00
2012-09-09 09:59:21 -04:00
//load all the SSL certs as friends
// std::list<std::string> sslIds;
// AuthSSL::getAuthSSL()->getAuthenticatedList(sslIds);
// for (std::list<std::string>::iterator sslIdsIt = sslIds.begin(); sslIdsIt != sslIds.end(); sslIdsIt++) {
// mConnMgr->addFriend(*sslIdsIt);
// }
//p3DhtMgr *mDhtMgr = new OpenDHTMgr(ownId, mConnMgr, RsInitConfig::configDir);
/**************************** BITDHT ***********************************/
2010-07-31 14:14:10 -04:00
// Make up an address. XXX
struct sockaddr_in tmpladdr ;
sockaddr_clear ( & tmpladdr ) ;
2011-02-01 18:27:53 -05:00
tmpladdr . sin_port = htons ( RsInitConfig : : port ) ;
2012-01-07 06:28:00 -05:00
# ifdef LOCALNET_TESTING
rsUdpStack * mDhtStack = new rsUdpStack ( UDP_TEST_RESTRICTED_LAYER , tmpladdr ) ;
/* parse portRestrictions */
unsigned int lport , uport ;
if ( doPortRestrictions )
{
if ( 2 = = sscanf ( portRestrictions . c_str ( ) , " %u-%u " , & lport , & uport ) )
{
std : : cerr < < " Adding Port Restriction ( " < < lport < < " - " < < uport < < " ) " ;
std : : cerr < < std : : endl ;
}
else
{
std : : cerr < < " Failed to parse Port Restrictions ... exiting " ;
std : : cerr < < std : : endl ;
exit ( 1 ) ;
}
RestrictedUdpLayer * url = ( RestrictedUdpLayer * ) mDhtStack - > getUdpLayer ( ) ;
url - > addRestrictedPortRange ( lport , uport ) ;
}
# else
2011-07-09 20:41:39 -04:00
rsUdpStack * mDhtStack = new rsUdpStack ( tmpladdr ) ;
2012-01-07 06:28:00 -05:00
# endif
2010-07-31 14:14:10 -04:00
# ifdef RS_USE_BITDHT
2010-10-28 18:59:46 -04:00
# define BITDHT_BOOTSTRAP_FILENAME "bdboot.txt"
2014-01-17 21:32:55 -05:00
std : : string bootstrapfile = rsAccounts . PathAccountDirectory ( ) ;
2010-10-01 15:48:53 -04:00
if ( bootstrapfile ! = " " )
{
bootstrapfile + = " / " ;
}
2010-10-28 18:59:46 -04:00
bootstrapfile + = BITDHT_BOOTSTRAP_FILENAME ;
std : : cerr < < " Checking for DHT bootstrap file: " < < bootstrapfile < < std : : endl ;
/* check if bootstrap file exists...
* if not . . . copy from dataDirectory
*/
2012-08-06 13:04:43 -04:00
if ( ! RsDirUtil : : checkFile ( bootstrapfile , true ) )
2010-10-28 18:59:46 -04:00
{
std : : cerr < < " DHT bootstrap file not in ConfigDir: " < < bootstrapfile < < std : : endl ;
2014-01-17 21:32:55 -05:00
std : : string installfile = rsAccounts . PathDataDirectory ( ) ;
2011-05-15 08:42:55 -04:00
installfile + = " / " ;
2010-10-28 18:59:46 -04:00
installfile + = BITDHT_BOOTSTRAP_FILENAME ;
std : : cerr < < " Checking for Installation DHT bootstrap file " < < installfile < < std : : endl ;
if ( ( installfile ! = " " ) & & ( RsDirUtil : : checkFile ( installfile ) ) )
{
std : : cerr < < " Copying Installation DHT bootstrap file... " < < std : : endl ;
if ( RsDirUtil : : copyFile ( installfile , bootstrapfile ) )
{
std : : cerr < < " Installed DHT bootstrap file in configDir " < < std : : endl ;
}
else
{
std : : cerr < < " Failed Installation DHT bootstrap file... " < < std : : endl ;
}
}
else
{
std : : cerr < < " No Installation DHT bootstrap file to copy " < < std : : endl ;
}
}
2010-07-31 14:14:10 -04:00
2011-06-29 14:02:44 -04:00
/* construct the rest of the stack, important to build them in the correct order! */
/* MOST OF THIS IS COMMENTED OUT UNTIL THE REST OF libretroshare IS READY FOR IT! */
2011-07-14 10:56:33 -04:00
UdpSubReceiver * udpReceivers [ RSUDP_NUM_TOU_RECVERS ] ;
int udpTypes [ RSUDP_NUM_TOU_RECVERS ] ;
2011-06-29 14:02:44 -04:00
// FIRST DHT STUNNER.
2011-07-09 20:41:39 -04:00
UdpStunner * mDhtStunner = new UdpStunner ( mDhtStack ) ;
mDhtStunner - > setTargetStunPeriod ( 300 ) ; /* slow (5mins) */
mDhtStack - > addReceiver ( mDhtStunner ) ;
2011-06-29 14:02:44 -04:00
2012-01-07 06:28:00 -05:00
# ifdef LOCALNET_TESTING
mDhtStunner - > SetAcceptLocalNet ( ) ;
# endif
2011-06-29 14:02:44 -04:00
// NEXT BITDHT.
2011-07-09 20:41:39 -04:00
p3BitDht * mBitDht = new p3BitDht ( ownId , mLinkMgr , mNetMgr , mDhtStack , bootstrapfile ) ;
2011-07-06 09:04:50 -04:00
/* install external Pointer for Interface */
rsDht = mBitDht ;
2012-09-09 09:59:21 -04:00
2011-06-29 14:02:44 -04:00
// NEXT THE RELAY (NEED to keep a reference for installing RELAYS)
2011-07-09 20:41:39 -04:00
UdpRelayReceiver * mRelay = new UdpRelayReceiver ( mDhtStack ) ;
2011-07-14 10:56:33 -04:00
udpReceivers [ RSUDP_TOU_RECVER_RELAY_IDX ] = mRelay ; /* RELAY Connections (DHT Port) */
udpTypes [ RSUDP_TOU_RECVER_RELAY_IDX ] = TOU_RECEIVER_TYPE_UDPRELAY ;
mDhtStack - > addReceiver ( udpReceivers [ RSUDP_TOU_RECVER_RELAY_IDX ] ) ;
2012-09-09 09:59:21 -04:00
2011-06-29 14:02:44 -04:00
// LAST ON THIS STACK IS STANDARD DIRECT TOU
2011-07-14 10:56:33 -04:00
udpReceivers [ RSUDP_TOU_RECVER_DIRECT_IDX ] = new UdpPeerReceiver ( mDhtStack ) ; /* standard DIRECT Connections (DHT Port) */
udpTypes [ RSUDP_TOU_RECVER_DIRECT_IDX ] = TOU_RECEIVER_TYPE_UDPPEER ;
mDhtStack - > addReceiver ( udpReceivers [ RSUDP_TOU_RECVER_DIRECT_IDX ] ) ;
2011-06-29 14:02:44 -04:00
// NOW WE BUILD THE SECOND STACK.
// Create the Second UdpStack... Port should be random (but openable!).
2013-09-24 01:30:01 -04:00
// We do this by binding to xx.xx.xx.xx:0 which which gives us a random port.
2012-09-09 09:59:21 -04:00
2011-07-09 20:41:39 -04:00
struct sockaddr_in sndladdr ;
sockaddr_clear ( & sndladdr ) ;
2012-01-11 05:24:37 -05:00
2013-09-24 01:30:01 -04:00
# ifdef LOCALNET_TESTING
2012-09-09 09:59:21 -04:00
// // HACK Proxy Port near Dht Port - For Relay Testing.
// uint16_t rndport = RsInitConfig::port + 3;
// sndladdr.sin_port = htons(rndport);
2012-01-07 06:28:00 -05:00
rsFixedUdpStack * mProxyStack = new rsFixedUdpStack ( UDP_TEST_RESTRICTED_LAYER , sndladdr ) ;
/* portRestrictions already parsed */
if ( doPortRestrictions )
{
RestrictedUdpLayer * url = ( RestrictedUdpLayer * ) mProxyStack - > getUdpLayer ( ) ;
url - > addRestrictedPortRange ( lport , uport ) ;
}
# else
2011-07-09 20:41:39 -04:00
rsFixedUdpStack * mProxyStack = new rsFixedUdpStack ( sndladdr ) ;
2012-01-07 06:28:00 -05:00
# endif
2011-06-29 14:02:44 -04:00
// FIRSTLY THE PROXY STUNNER.
2011-07-09 20:41:39 -04:00
UdpStunner * mProxyStunner = new UdpStunner ( mProxyStack ) ;
mProxyStunner - > setTargetStunPeriod ( 300 ) ; /* slow (5mins) */
2012-09-09 09:59:21 -04:00
mProxyStack - > addReceiver ( mProxyStunner ) ;
2012-01-07 06:28:00 -05:00
# ifdef LOCALNET_TESTING
mProxyStunner - > SetAcceptLocalNet ( ) ;
# endif
2012-09-09 09:59:21 -04:00
2011-06-29 14:02:44 -04:00
// FINALLY THE PROXY UDP CONNECTIONS
2011-07-14 10:56:33 -04:00
udpReceivers [ RSUDP_TOU_RECVER_PROXY_IDX ] = new UdpPeerReceiver ( mProxyStack ) ; /* PROXY Connections (Alt UDP Port) */
udpTypes [ RSUDP_TOU_RECVER_PROXY_IDX ] = TOU_RECEIVER_TYPE_UDPPEER ;
mProxyStack - > addReceiver ( udpReceivers [ RSUDP_TOU_RECVER_PROXY_IDX ] ) ;
2012-09-09 09:59:21 -04:00
2011-07-09 20:41:39 -04:00
// REAL INITIALISATION - WITH THREE MODES
2011-07-14 10:56:33 -04:00
tou_init ( ( void * * ) udpReceivers , udpTypes , RSUDP_NUM_TOU_RECVERS ) ;
2010-07-31 14:14:10 -04:00
2011-07-09 20:41:39 -04:00
mBitDht - > setupConnectBits ( mDhtStunner , mProxyStunner , mRelay ) ;
2012-09-09 09:59:21 -04:00
2011-07-09 20:41:39 -04:00
mNetMgr - > setAddrAssist ( new stunAddrAssist ( mDhtStunner ) , new stunAddrAssist ( mProxyStunner ) ) ;
2011-07-06 09:04:50 -04:00
# else
/* install NULL Pointer for rsDht Interface */
rsDht = NULL ;
2010-07-31 14:14:10 -04:00
# endif
2012-09-09 09:59:21 -04:00
/**************************** BITDHT ***********************************/
2010-07-31 14:14:10 -04:00
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
SecurityPolicy * none = secpolicy_create ( ) ;
2011-07-09 20:41:39 -04:00
pqih = new pqisslpersongrp ( none , flags , mPeerMgr ) ;
2009-07-30 17:27:47 -04:00
//pqih = new pqipersongrpDummy(none, flags);
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
/****** New Ft Server **** !!! */
2013-10-01 04:11:15 -04:00
ftServer * ftserver = new ftServer ( mPeerMgr , mLinkMgr ) ;
2014-01-17 21:32:55 -05:00
ftserver - > setConfigDirectory ( rsAccounts . PathAccountDirectory ( ) ) ;
2007-11-14 22:18:48 -05:00
2014-01-07 17:51:22 -05:00
ftserver - > SetupFtServer ( ) ;
2009-07-30 17:27:47 -04:00
CacheStrapper * mCacheStrapper = ftserver - > getCacheStrapper ( ) ;
CacheTransfer * mCacheTransfer = ftserver - > getCacheTransfer ( ) ;
2011-07-09 14:39:34 -04:00
/* setup any extra bits (Default Paths) */
ftserver - > setPartialsDirectory ( emergencyPartialsDir ) ;
ftserver - > setDownloadDirectory ( emergencySaveDir ) ;
2009-07-30 17:27:47 -04:00
/* This should be set by config ... there is no default */
2011-07-09 14:39:34 -04:00
//ftserver->setSharedDirectories(fileList);
2012-09-09 09:59:21 -04:00
2009-07-30 17:27:47 -04:00
rsFiles = ftserver ;
2008-09-21 16:30:34 -04:00
2007-11-14 22:18:48 -05:00
2011-06-16 17:59:26 -04:00
/* create Cache Services */
2014-01-17 21:32:55 -05:00
std : : string config_dir = rsAccounts . PathAccountDirectory ( ) ;
2011-06-16 17:59:26 -04:00
std : : string localcachedir = config_dir + " /cache/local " ;
std : : string remotecachedir = config_dir + " /cache/remote " ;
std : : vector < std : : string > plugins_directories ;
2011-06-17 15:59:01 -04:00
# ifndef WINDOWS_SYS
plugins_directories . push_back ( std : : string ( " /usr/lib/retroshare/extensions/ " ) ) ;
# endif
2014-02-01 09:16:15 -05:00
std : : string extensions_dir = rsAccounts . PathBaseDirectory ( ) + " /extensions/ " ;
2013-09-06 18:04:47 -04:00
plugins_directories . push_back ( extensions_dir ) ;
if ( ! RsDirUtil : : checkCreateDirectory ( extensions_dir ) )
std : : cerr < < " (EE) Cannot create extensions directory " + extensions_dir + " . This is not mandatory, but you probably have a permission problem. " < < std : : endl ;
2011-06-23 14:55:15 -04:00
# ifdef DEBUG_PLUGIN_SYSTEM
2011-06-16 17:59:26 -04:00
plugins_directories . push_back ( " . " ) ; // this list should be saved/set to some correct value.
2012-09-09 09:59:21 -04:00
// possible entries include: /usr/lib/retroshare, ~/.retroshare/extensions/, etc.
2011-06-23 14:55:15 -04:00
# endif
2011-06-16 17:59:26 -04:00
2012-12-16 14:17:11 -05:00
mPluginsManager = new RsPluginManager ( RsInitConfig : : main_executable_hash ) ;
2011-06-16 17:59:26 -04:00
rsPlugins = mPluginsManager ;
2011-07-05 16:29:07 -04:00
mConfigMgr - > addConfiguration ( " plugins.cfg " , mPluginsManager ) ;
mPluginsManager - > loadConfiguration ( ) ;
2011-06-16 17:59:26 -04:00
// These are needed to load plugins: plugin devs might want to know the place of
// cache directories, get pointers to cache strapper, or access ownId()
//
mPluginsManager - > setCacheDirectories ( localcachedir , remotecachedir ) ;
mPluginsManager - > setFileServer ( ftserver ) ;
2012-02-19 10:03:07 -05:00
mPluginsManager - > setLinkMgr ( mLinkMgr ) ;
2011-06-16 17:59:26 -04:00
// Now load the plugins. This parses the available SO/DLL files for known symbols.
//
mPluginsManager - > loadPlugins ( plugins_directories ) ;
2011-12-22 15:17:59 -05:00
// Also load some plugins explicitly. This is helpful for
// - developping plugins
//
std : : vector < RsPlugin * > programatically_inserted_plugins ;
2012-09-09 09:59:21 -04:00
2011-12-22 15:17:59 -05:00
// Push your own plugins into this list, before the call:
//
// programatically_inserted_plugins.push_back(myCoolPlugin) ;
//
mPluginsManager - > loadPlugins ( programatically_inserted_plugins ) ;
2009-07-30 17:27:47 -04:00
/* create Services */
2013-09-28 04:09:59 -04:00
mDisc = new p3discovery2 ( mPeerMgr , mLinkMgr , mNetMgr ) ;
mHeart = new p3heartbeat ( mLinkMgr , pqih ) ;
2011-07-09 14:39:34 -04:00
msgSrv = new p3MsgService ( mLinkMgr ) ;
2011-09-29 05:20:09 -04:00
chatSrv = new p3ChatService ( mLinkMgr , mHistoryMgr ) ;
2011-07-09 14:39:34 -04:00
mStatusSrv = new p3StatusService ( mLinkMgr ) ;
2007-11-14 22:18:48 -05:00
2013-11-02 10:35:33 -04:00
# ifdef GROUTER
p3GRouter * gr = new p3GRouter ( mLinkMgr ) ;
rsGRouter = gr ;
pqih - > addService ( gr ) ;
# endif
2013-04-10 04:52:52 -04:00
p3turtle * tr = new p3turtle ( mLinkMgr ) ;
2009-07-30 17:27:47 -04:00
rsTurtle = tr ;
pqih - > addService ( tr ) ;
2013-10-01 04:11:15 -04:00
pqih - > addService ( ftserver ) ;
2013-04-08 17:25:32 -04:00
2014-02-01 09:16:15 -05:00
rsDisc = mDisc ;
2013-12-15 14:35:14 -05:00
rsMsgs = new p3Msgs ( msgSrv , chatSrv ) ;
// connect components to turtle router.
2009-07-30 17:27:47 -04:00
ftserver - > connectToTurtleRouter ( tr ) ;
2013-04-08 17:25:32 -04:00
chatSrv - > connectToTurtleRouter ( tr ) ;
2013-12-27 15:06:47 -05:00
# ifdef GROUTER
msgSrv - > connectToGlobalRouter ( gr ) ;
# endif
2013-05-01 17:13:40 -04:00
msgSrv - > connectToTurtleRouter ( tr ) ;
2007-11-14 22:18:48 -05:00
2013-09-28 04:09:59 -04:00
pqih - > addService ( mHeart ) ;
pqih - > addService ( mDisc ) ;
2009-07-30 17:27:47 -04:00
pqih - > addService ( msgSrv ) ;
pqih - > addService ( chatSrv ) ;
2010-04-15 06:47:48 -04:00
pqih - > addService ( mStatusSrv ) ;
2007-11-14 22:18:48 -05:00
2014-01-03 10:05:48 -05:00
// set interfaces for plugins
//
RsPlugInInterfaces interfaces ;
interfaces . mFiles = rsFiles ;
interfaces . mPeers = rsPeers ;
interfaces . mMsgs = rsMsgs ;
interfaces . mTurtle = rsTurtle ;
interfaces . mDisc = rsDisc ;
interfaces . mDht = rsDht ;
2014-02-01 09:16:15 -05:00
// don't exist no more.
//interfaces.mForums = mForums;
2014-01-10 15:27:51 -05:00
interfaces . mNotify = mNotify ;
2014-01-03 10:05:48 -05:00
mPluginsManager - > setInterfaces ( interfaces ) ;
2011-06-16 17:59:26 -04:00
// now add plugin objects inside the loop:
// - client services provided by plugins.
// - cache services provided by plugins.
//
mPluginsManager - > registerClientServices ( pqih ) ;
mPluginsManager - > registerCacheServices ( ) ;
2013-06-20 17:17:57 -04:00
2012-12-16 10:04:52 -05:00
# ifdef RS_ENABLE_GXS
2012-08-06 17:00:38 -04:00
2012-11-24 14:49:23 -05:00
// The idea is that if priorGxsDir is non
// empty and matches an exist directory location
// the given ssl user id then this directory is cleaned
// and deleted
2014-03-17 16:56:06 -04:00
std : : string priorGxsDir = " ./ " + mLinkMgr - > getOwnId ( ) . toStdString ( ) + " / " ;
2014-01-17 21:32:55 -05:00
std : : string currGxsDir = rsAccounts . PathAccountDirectory ( ) + " /GXS_phase2 " ;
2013-02-10 10:40:07 -05:00
# ifdef GXS_DEV_TESTNET // Different Directory for testing.
2014-03-20 07:26:53 -04:00
currGxsDir + = " _TESTNET10 " ;
2013-02-10 10:40:07 -05:00
# endif
2012-11-24 14:49:23 -05:00
if ( ! priorGxsDir . empty ( ) )
2014-03-17 16:56:06 -04:00
RsDirUtil : : checkDirectory ( priorGxsDir ) ;
2012-11-24 14:49:23 -05:00
2013-09-26 06:09:40 -04:00
std : : set < std : : string > filesToKeep ;
2012-11-24 14:49:23 -05:00
bool cleanUpSuccess = RsDirUtil : : cleanupDirectory ( priorGxsDir , filesToKeep ) ;
if ( ! cleanUpSuccess )
std : : cerr < < " RsInit::StartupRetroShare() Clean up of Old Gxs Dir Failed! " ;
else
rmdir ( priorGxsDir . c_str ( ) ) ;
2012-10-21 15:45:35 -04:00
// TODO: temporary to store GXS service data, remove
2012-11-24 14:49:23 -05:00
RsDirUtil : : checkCreateDirectory ( currGxsDir ) ;
2012-10-21 15:45:35 -04:00
RsNxsNetMgr * nxsMgr = new RsNxsNetMgrImpl ( mLinkMgr ) ;
2012-10-28 19:13:15 -04:00
/**** Identity service ****/
2012-11-24 14:49:23 -05:00
RsGeneralDataService * gxsid_ds = new RsDataService ( currGxsDir + " / " , " gxsid_db " ,
2013-06-20 15:50:25 -04:00
RS_SERVICE_GXSV2_TYPE_GXSID , NULL , RsInitConfig : : gxs_passwd ) ;
2012-10-28 19:13:15 -04:00
2013-02-10 10:40:07 -05:00
# ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
2012-10-28 19:13:15 -04:00
gxsid_ds - > resetDataStore ( ) ;
2013-02-10 10:40:07 -05:00
# endif
2012-10-28 19:13:15 -04:00
// init gxs services
mGxsIdService = new p3IdService ( gxsid_ds , NULL ) ;
2013-06-04 17:00:43 -04:00
RsGeneralDataService * gxscircles_ds = new RsDataService ( currGxsDir + " / " , " gxscircles_db " ,
2013-06-20 15:50:25 -04:00
RS_SERVICE_GXSV2_TYPE_GXSCIRCLE , NULL , RsInitConfig : : gxs_passwd ) ;
2013-06-04 17:00:43 -04:00
mGxsCircles = new p3GxsCircles ( gxscircles_ds , NULL , mGxsIdService ) ;
2014-02-01 09:16:15 -05:00
// create GXS ID service
2012-10-28 19:13:15 -04:00
RsGxsNetService * gxsid_ns = new RsGxsNetService (
2013-06-04 17:00:43 -04:00
RS_SERVICE_GXSV2_TYPE_GXSID , gxsid_ds , nxsMgr ,
2013-11-03 18:46:34 -05:00
mGxsIdService , mGxsIdService , mGxsCircles ,
2014-03-17 16:56:06 -04:00
true ) ; // don't synchronise group automatic (need explicit group request)
2012-10-28 19:13:15 -04:00
2013-11-04 09:09:32 -05:00
mGxsIdService - > setNes ( gxsid_ns ) ;
2012-11-30 19:16:24 -05:00
/**** GxsCircle service ****/
2013-06-04 17:00:43 -04:00
2012-11-30 19:16:24 -05:00
2013-02-10 10:40:07 -05:00
# ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
2012-11-30 19:16:24 -05:00
gxscircles_ds - > resetDataStore ( ) ;
2013-02-10 10:40:07 -05:00
# endif
2012-11-30 19:16:24 -05:00
// init gxs services
mGxsCircles = new p3GxsCircles ( gxscircles_ds , NULL , mGxsIdService ) ;
// create GXS Circle service
RsGxsNetService * gxscircles_ns = new RsGxsNetService (
2013-06-04 17:00:43 -04:00
RS_SERVICE_GXSV2_TYPE_GXSCIRCLE , gxscircles_ds , nxsMgr ,
mGxsCircles , mGxsIdService , mGxsCircles ) ;
2012-11-30 19:16:24 -05:00
2012-10-28 19:13:15 -04:00
2012-10-21 15:45:35 -04:00
/**** Photo service ****/
2012-11-24 14:49:23 -05:00
RsGeneralDataService * photo_ds = new RsDataService ( currGxsDir + " / " , " photoV2_db " ,
2013-06-20 15:50:25 -04:00
RS_SERVICE_GXSV2_TYPE_PHOTO , NULL , RsInitConfig : : gxs_passwd ) ;
2012-09-09 09:59:21 -04:00
2013-02-10 10:40:07 -05:00
# ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
2012-10-21 15:45:35 -04:00
photo_ds - > resetDataStore ( ) ; //TODO: remove, new service data per RS session, for testing
2013-02-10 10:40:07 -05:00
# endif
2012-09-09 09:59:21 -04:00
2012-09-25 17:04:04 -04:00
// init gxs services
2013-03-24 15:21:30 -04:00
mPhoto = new p3PhotoService ( photo_ds , NULL , mGxsIdService ) ;
2012-09-09 09:59:21 -04:00
2012-10-21 15:45:35 -04:00
// create GXS photo service
2012-09-25 17:04:04 -04:00
RsGxsNetService * photo_ns = new RsGxsNetService (
2013-06-04 17:00:43 -04:00
RS_SERVICE_GXSV2_TYPE_PHOTO , photo_ds , nxsMgr , mPhoto , mGxsIdService , mGxsCircles ) ;
2012-08-06 17:00:38 -04:00
2012-10-21 15:45:35 -04:00
/**** Posted GXS service ****/
2012-08-06 17:00:38 -04:00
2012-12-11 17:26:11 -05:00
2012-08-06 17:00:38 -04:00
2012-11-24 14:49:23 -05:00
RsGeneralDataService * posted_ds = new RsDataService ( currGxsDir + " / " , " posted_db " ,
2013-06-20 15:50:25 -04:00
RS_SERVICE_GXSV2_TYPE_POSTED , NULL , RsInitConfig : : gxs_passwd ) ;
2012-08-06 17:00:38 -04:00
2013-03-16 08:47:31 -04:00
# ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
2012-10-21 15:45:35 -04:00
posted_ds - > resetDataStore ( ) ; //TODO: remove, new service data per RS session, for testing
2013-03-16 08:47:31 -04:00
# endif
2012-08-06 17:00:38 -04:00
2013-03-11 16:40:28 -04:00
mPosted = new p3Posted ( posted_ds , NULL , mGxsIdService ) ;
2012-08-06 17:00:38 -04:00
2012-10-21 15:45:35 -04:00
// create GXS photo service
RsGxsNetService * posted_ns = new RsGxsNetService (
2013-06-04 17:00:43 -04:00
RS_SERVICE_GXSV2_TYPE_POSTED , posted_ds , nxsMgr , mPosted , mGxsIdService , mGxsCircles ) ;
2012-09-25 17:04:04 -04:00
2012-08-06 17:00:38 -04:00
2012-10-31 18:43:23 -04:00
/**** Wiki GXS service ****/
2012-12-11 17:26:11 -05:00
2012-10-31 18:43:23 -04:00
2012-11-24 14:49:23 -05:00
RsGeneralDataService * wiki_ds = new RsDataService ( currGxsDir + " / " , " wiki_db " ,
2013-06-04 17:00:43 -04:00
RS_SERVICE_GXSV2_TYPE_WIKI ,
2013-06-20 15:50:25 -04:00
NULL , RsInitConfig : : gxs_passwd ) ;
2012-10-31 18:43:23 -04:00
2013-02-10 10:40:07 -05:00
# ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
2012-10-31 18:43:23 -04:00
wiki_ds - > resetDataStore ( ) ; //TODO: remove, new service data per RS session, for testing
2013-02-10 10:40:07 -05:00
# endif
2012-10-31 18:43:23 -04:00
2013-02-10 12:52:50 -05:00
mWiki = new p3Wiki ( wiki_ds , NULL , mGxsIdService ) ;
2012-10-31 18:43:23 -04:00
// create GXS photo service
RsGxsNetService * wiki_ns = new RsGxsNetService (
2013-06-04 17:00:43 -04:00
RS_SERVICE_GXSV2_TYPE_WIKI , wiki_ds , nxsMgr , mWiki , mGxsIdService , mGxsCircles ) ;
2012-11-08 19:56:07 -05:00
2012-11-26 17:53:44 -05:00
/**** Wire GXS service ****/
RsGeneralDataService * wire_ds = new RsDataService ( currGxsDir + " / " , " wire_db " ,
2013-06-20 15:50:25 -04:00
RS_SERVICE_GXSV2_TYPE_WIRE , NULL , RsInitConfig : : gxs_passwd ) ;
2012-11-26 17:53:44 -05:00
2013-02-10 10:40:07 -05:00
# ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
2012-11-26 17:53:44 -05:00
wire_ds - > resetDataStore ( ) ; //TODO: remove, new service data per RS session, for testing
2013-02-10 10:40:07 -05:00
# endif
2012-11-26 17:53:44 -05:00
2013-03-24 15:21:30 -04:00
mWire = new p3Wire ( wire_ds , NULL , mGxsIdService ) ;
2012-11-26 17:53:44 -05:00
// create GXS photo service
RsGxsNetService * wire_ns = new RsGxsNetService (
2013-06-04 17:00:43 -04:00
RS_SERVICE_GXSV2_TYPE_WIRE , wire_ds , nxsMgr , mWire , mGxsIdService , mGxsCircles ) ;
2012-11-26 17:53:44 -05:00
2012-11-08 19:56:07 -05:00
/**** Forum GXS service ****/
2012-11-24 14:49:23 -05:00
RsGeneralDataService * gxsforums_ds = new RsDataService ( currGxsDir + " / " , " gxsforums_db " ,
2013-06-20 15:50:25 -04:00
RS_SERVICE_GXSV2_TYPE_FORUMS , NULL , RsInitConfig : : gxs_passwd ) ;
2012-11-08 19:56:07 -05:00
2013-02-10 10:40:07 -05:00
# ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
2012-11-08 19:56:07 -05:00
gxsforums_ds - > resetDataStore ( ) ; //TODO: remove, new service data per RS session, for testing
2013-02-10 10:40:07 -05:00
# endif
2012-11-08 19:56:07 -05:00
2013-02-10 13:41:15 -05:00
mGxsForums = new p3GxsForums ( gxsforums_ds , NULL , mGxsIdService ) ;
2012-11-08 19:56:07 -05:00
// create GXS photo service
RsGxsNetService * gxsforums_ns = new RsGxsNetService (
2013-06-04 17:00:43 -04:00
RS_SERVICE_GXSV2_TYPE_FORUMS , gxsforums_ds , nxsMgr ,
mGxsForums , mGxsIdService , mGxsCircles ) ;
2012-09-25 17:04:04 -04:00
2012-10-15 14:52:47 -04:00
2013-03-04 15:26:48 -05:00
/**** Channel GXS service ****/
RsGeneralDataService * gxschannels_ds = new RsDataService ( currGxsDir + " / " , " gxschannels_db " ,
2013-06-20 15:50:25 -04:00
RS_SERVICE_GXSV2_TYPE_CHANNELS , NULL , RsInitConfig : : gxs_passwd ) ;
2013-03-04 15:26:48 -05:00
2013-03-16 08:47:31 -04:00
# ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
gxschannels_ds - > resetDataStore ( ) ; //TODO: remove, new service data per RS session, for testing
# endif
2013-03-04 15:26:48 -05:00
mGxsChannels = new p3GxsChannels ( gxschannels_ds , NULL , mGxsIdService ) ;
// create GXS photo service
RsGxsNetService * gxschannels_ns = new RsGxsNetService (
2013-06-04 17:00:43 -04:00
RS_SERVICE_GXSV2_TYPE_CHANNELS , gxschannels_ds , nxsMgr ,
mGxsChannels , mGxsIdService , mGxsCircles ) ;
2012-10-21 15:45:35 -04:00
// now add to p3service
2012-10-28 19:13:15 -04:00
pqih - > addService ( gxsid_ns ) ;
2013-06-04 17:00:43 -04:00
pqih - > addService ( gxscircles_ns ) ;
pqih - > addService ( photo_ns ) ;
2012-10-21 15:45:35 -04:00
pqih - > addService ( posted_ns ) ;
2012-10-31 18:43:23 -04:00
pqih - > addService ( wiki_ns ) ;
2012-11-08 19:56:07 -05:00
pqih - > addService ( gxsforums_ns ) ;
2013-03-04 15:26:48 -05:00
pqih - > addService ( gxschannels_ns ) ;
2012-10-21 15:45:35 -04:00
2013-06-20 15:50:25 -04:00
// remove pword from memory
RsInitConfig : : gxs_passwd = " " ;
2012-12-16 10:04:52 -05:00
# endif // RS_ENABLE_GXS.
2012-06-13 20:27:28 -04:00
2012-07-27 11:03:16 -04:00
2013-09-29 03:11:02 -04:00
# ifdef RS_RTT
p3rtt * mRtt = new p3rtt ( mLinkMgr ) ;
pqih - > addService ( mRtt ) ;
rsRtt = mRtt ;
2011-08-03 13:43:26 -04:00
# endif
2011-11-24 19:58:01 -05:00
// new services to test.
p3BanList * mBanList = new p3BanList ( mLinkMgr , mNetMgr ) ;
pqih - > addService ( mBanList ) ;
mBitDht - > setupPeerSharer ( mBanList ) ;
2012-06-21 19:23:46 -04:00
p3BandwidthControl * mBwCtrl = new p3BandwidthControl ( pqih ) ;
2012-06-21 19:52:39 -04:00
pqih - > addService ( mBwCtrl ) ;
2012-06-21 19:23:46 -04:00
2013-12-22 12:10:56 -05:00
# ifdef SERVICES_DSDV
2011-11-24 19:58:01 -05:00
p3Dsdv * mDsdv = new p3Dsdv ( mLinkMgr ) ;
pqih - > addService ( mDsdv ) ;
rsDsdv = mDsdv ;
mDsdv - > addTestService ( ) ;
2011-12-01 12:21:52 -05:00
# endif
2011-11-24 19:58:01 -05:00
2009-07-30 17:27:47 -04:00
/**************************************************************************/
2007-11-14 22:18:48 -05:00
2010-07-31 14:14:10 -04:00
# ifdef RS_USE_BITDHT
2011-07-09 14:39:34 -04:00
mNetMgr - > addNetAssistConnect ( 1 , mBitDht ) ;
2011-07-09 20:41:39 -04:00
mNetMgr - > addNetListener ( mDhtStack ) ;
mNetMgr - > addNetListener ( mProxyStack ) ;
2010-07-31 14:14:10 -04:00
# endif
2011-12-13 11:19:37 -05:00
# ifdef RS_ENABLE_ZEROCONF
2012-01-06 07:48:04 -05:00
p3ZeroConf * mZeroConf = new p3ZeroConf (
2012-09-09 09:59:21 -04:00
AuthGPG : : getAuthGPG ( ) - > getGPGOwnId ( ) , ownId ,
mLinkMgr , mNetMgr , mPeerMgr ) ;
2011-12-13 11:19:37 -05:00
mNetMgr - > addNetAssistConnect ( 2 , mZeroConf ) ;
mNetMgr - > addNetListener ( mZeroConf ) ;
2012-01-14 11:41:00 -05:00
# endif
2011-12-13 11:19:37 -05:00
2012-01-14 11:41:00 -05:00
# ifdef RS_ENABLE_ZCNATASSIST
2011-12-13 11:19:37 -05:00
// Apple's UPnP & NAT-PMP assistance.
2012-01-14 11:41:00 -05:00
p3zcNatAssist * mZcNatAssist = new p3zcNatAssist ( ) ;
mNetMgr - > addNetAssistFirewall ( 1 , mZcNatAssist ) ;
2011-12-13 11:19:37 -05:00
# else
// Original UPnP Interface.
pqiNetAssistFirewall * mUpnpMgr = new upnphandler ( ) ;
2011-07-09 14:39:34 -04:00
mNetMgr - > addNetAssistFirewall ( 1 , mUpnpMgr ) ;
2011-12-13 11:19:37 -05:00
# endif
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
/**************************************************************************/
/* need to Monitor too! */
2011-07-09 14:39:34 -04:00
mLinkMgr - > addMonitor ( pqih ) ;
mLinkMgr - > addMonitor ( mCacheStrapper ) ;
2013-09-28 04:09:59 -04:00
mLinkMgr - > addMonitor ( mDisc ) ;
2011-07-09 14:39:34 -04:00
mLinkMgr - > addMonitor ( msgSrv ) ;
mLinkMgr - > addMonitor ( mStatusSrv ) ;
mLinkMgr - > addMonitor ( chatSrv ) ;
2012-06-21 19:23:46 -04:00
mLinkMgr - > addMonitor ( mBwCtrl ) ;
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
/* must also add the controller as a Monitor...
* a little hack to get it to work .
*/
2011-07-09 14:39:34 -04:00
mLinkMgr - > addMonitor ( ( ( ftController * ) mCacheTransfer ) ) ;
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
/**************************************************************************/
2009-05-07 17:36:17 -04:00
2009-07-30 17:27:47 -04:00
//mConfigMgr->addConfiguration("ftserver.cfg", ftserver);
//
2012-04-08 10:52:01 -04:00
mConfigMgr - > addConfiguration ( " gpg_prefs.cfg " , AuthGPG : : getAuthGPG ( ) ) ;
2011-12-12 11:07:38 -05:00
mConfigMgr - > loadConfiguration ( ) ;
2010-01-13 16:26:30 -05:00
2011-07-09 20:41:39 -04:00
mConfigMgr - > addConfiguration ( " peers.cfg " , mPeerMgr ) ;
2009-07-30 17:27:47 -04:00
mConfigMgr - > addConfiguration ( " general.cfg " , mGeneralConfig ) ;
2010-08-31 16:00:49 -04:00
mConfigMgr - > addConfiguration ( " cache.cfg " , mCacheStrapper ) ;
2009-07-30 17:27:47 -04:00
mConfigMgr - > addConfiguration ( " msgs.cfg " , msgSrv ) ;
mConfigMgr - > addConfiguration ( " chat.cfg " , chatSrv ) ;
2011-09-29 05:20:09 -04:00
mConfigMgr - > addConfiguration ( " p3History.cfg " , mHistoryMgr ) ;
2010-08-31 16:00:49 -04:00
mConfigMgr - > addConfiguration ( " p3Status.cfg " , mStatusSrv ) ;
2009-07-30 17:27:47 -04:00
mConfigMgr - > addConfiguration ( " turtle.cfg " , tr ) ;
2013-12-28 16:47:15 -05:00
# ifdef GROUTER
mConfigMgr - > addConfiguration ( " grouter.cfg " , gr ) ;
# endif
2011-06-16 17:59:26 -04:00
2011-12-19 21:07:00 -05:00
# ifdef RS_USE_BITDHT
mConfigMgr - > addConfiguration ( " bitdht.cfg " , mBitDht ) ;
# endif
2013-12-20 09:48:32 -05:00
# ifdef RS_ENABLE_GXS
mConfigMgr - > addConfiguration ( " identity.cfg " , gxsid_ns ) ;
mConfigMgr - > addConfiguration ( " gxsforums.cfg " , gxsforums_ns ) ;
mConfigMgr - > addConfiguration ( " gxschannels.cfg " , gxschannels_ns ) ;
mConfigMgr - > addConfiguration ( " gxscircles.cfg " , gxscircles_ns ) ;
mConfigMgr - > addConfiguration ( " posted.cfg " , posted_ns ) ;
mConfigMgr - > addConfiguration ( " wire.cfg " , wire_ns ) ;
mConfigMgr - > addConfiguration ( " wiki.cfg " , wiki_ns ) ;
mConfigMgr - > addConfiguration ( " photo.cfg " , photo_ns ) ;
# endif
2011-06-16 17:59:26 -04:00
mPluginsManager - > addConfigurations ( mConfigMgr ) ;
2009-05-07 17:36:17 -04:00
2009-07-30 17:27:47 -04:00
ftserver - > addConfiguration ( mConfigMgr ) ;
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
/**************************************************************************/
/* (2) Load configuration files */
/**************************************************************************/
2012-09-09 09:59:21 -04:00
std : : cerr < < " (2) Load configuration files " < < std : : endl ;
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
mConfigMgr - > loadConfiguration ( ) ;
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
/* NOTE: CacheStrapper's load causes Cache Files to be
* loaded into all the CacheStores / Sources . This happens
* after all the other configurations have happened .
*/
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
/**************************************************************************/
/* trigger generalConfig loading for classes that require it */
/**************************************************************************/
2012-11-25 15:25:34 -05:00
p3ServerConfig * serverConfig = new p3ServerConfig ( mPeerMgr , mLinkMgr , mNetMgr , pqih , mGeneralConfig ) ;
serverConfig - > load_config ( ) ;
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
/**************************************************************************/
/* Force Any Configuration before Startup (After Load) */
/**************************************************************************/
2012-09-09 09:59:21 -04:00
std : : cerr < < " Force Any Configuration before Startup (After Load) " < < std : : endl ;
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
if ( RsInitConfig : : forceLocalAddr )
{
2013-09-13 10:35:19 -04:00
struct sockaddr_storage laddr ;
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
/* clean sockaddr before setting values (MaxOSX) */
2013-09-13 10:35:19 -04:00
sockaddr_storage_clear ( laddr ) ;
2012-09-09 09:59:21 -04:00
2013-09-13 10:35:19 -04:00
struct sockaddr_in * lap = ( struct sockaddr_in * ) & laddr ;
lap - > sin_family = AF_INET ;
lap - > sin_port = htons ( RsInitConfig : : port ) ;
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
// universal
2013-09-13 10:35:19 -04:00
lap - > sin_addr . s_addr = inet_addr ( RsInitConfig : : inet . c_str ( ) ) ;
2007-11-14 22:18:48 -05:00
2011-07-09 20:41:39 -04:00
mPeerMgr - > setLocalAddress ( ownId , laddr ) ;
2009-07-30 17:27:47 -04:00
}
2008-09-21 16:30:34 -04:00
2009-07-30 17:27:47 -04:00
if ( RsInitConfig : : forceExtPort )
{
2011-07-09 20:41:39 -04:00
mPeerMgr - > setOwnNetworkMode ( RS_NET_MODE_EXT ) ;
2013-09-28 04:09:59 -04:00
mPeerMgr - > setOwnVisState ( RS_VS_DISC_FULL , RS_VS_DHT_FULL ) ;
2011-07-09 20:41:39 -04:00
2007-11-14 22:18:48 -05:00
}
2009-07-30 17:27:47 -04:00
2014-01-17 21:32:55 -05:00
if ( RsInitConfig : : hiddenNodeSet )
2007-11-14 22:18:48 -05:00
{
2013-09-08 22:10:49 -04:00
mPeerMgr - > setupHiddenNode ( RsInitConfig : : hiddenNodeAddress , RsInitConfig : : hiddenNodePort ) ;
}
2014-01-17 21:32:55 -05:00
else if ( isHiddenNode )
2007-11-14 22:18:48 -05:00
{
2014-01-17 21:32:55 -05:00
mPeerMgr - > forceHiddenNode ( ) ;
2007-11-14 22:18:48 -05:00
}
2011-07-09 20:41:39 -04:00
mNetMgr - > checkNetAddress ( ) ;
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
/**************************************************************************/
/* startup (stuff dependent on Ids/peers is after this point) */
/**************************************************************************/
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
pqih - > init_listener ( ) ;
2011-07-09 20:41:39 -04:00
mNetMgr - > addNetListener ( pqih ) ; /* add listener so we can reset all sockets later */
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
/**************************************************************************/
/* load caches and secondary data */
/**************************************************************************/
2007-11-14 22:18:48 -05:00
2010-05-23 12:35:42 -04:00
// Clear the News Feeds that are generated by Initial Cache Loading.
/* Peer stuff is up to date */
//getPqiNotify()->ClearFeedItems(RS_FEED_ITEM_CHAT_NEW);
2014-01-07 17:51:22 -05:00
mNotify - > ClearFeedItems ( RS_FEED_ITEM_MESSAGE ) ;
2010-05-23 12:35:42 -04:00
//getPqiNotify()->ClearFeedItems(RS_FEED_ITEM_FILES_NEW);
2010-10-13 12:15:26 -04:00
/**************************************************************************/
/* Add AuthGPG services */
/**************************************************************************/
2013-09-28 04:09:59 -04:00
AuthGPG : : getAuthGPG ( ) - > addService ( mDisc ) ;
2010-10-13 12:15:26 -04:00
2009-07-30 17:27:47 -04:00
/**************************************************************************/
/* Force Any Last Configuration Options */
/**************************************************************************/
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
/**************************************************************************/
/* Start up Threads */
/**************************************************************************/
2007-11-14 22:18:48 -05:00
2013-03-04 15:26:48 -05:00
# ifdef RS_ENABLE_GXS
// Must Set the GXS pointers before starting threads.
rsIdentity = mGxsIdService ;
rsGxsCircles = mGxsCircles ;
rsWiki = mWiki ;
rsPosted = mPosted ;
rsPhoto = mPhoto ;
rsGxsForums = mGxsForums ;
rsGxsChannels = mGxsChannels ;
rsWire = mWire ;
/*** start up GXS core runner ***/
createThread ( * mGxsIdService ) ;
createThread ( * mGxsCircles ) ;
2013-06-04 17:00:43 -04:00
createThread ( * mPhoto ) ;
2013-03-04 15:26:48 -05:00
createThread ( * mPosted ) ;
createThread ( * mWiki ) ;
createThread ( * mWire ) ;
createThread ( * mGxsForums ) ;
createThread ( * mGxsChannels ) ;
// cores ready start up GXS net servers
createThread ( * gxsid_ns ) ;
createThread ( * gxscircles_ns ) ;
createThread ( * photo_ns ) ;
createThread ( * posted_ns ) ;
createThread ( * wiki_ns ) ;
createThread ( * wire_ns ) ;
createThread ( * gxsforums_ns ) ;
createThread ( * gxschannels_ns ) ;
# endif // RS_ENABLE_GXS
2011-03-08 18:29:21 -05:00
ftserver - > StartupThreads ( ) ;
2009-07-30 17:27:47 -04:00
ftserver - > ResumeTransfers ( ) ;
2007-11-14 22:18:48 -05:00
2012-09-09 09:59:21 -04:00
//mDhtMgr->start();
2010-07-31 14:14:10 -04:00
# ifdef RS_USE_BITDHT
2012-09-09 09:59:21 -04:00
mBitDht - > start ( ) ;
2010-07-31 14:14:10 -04:00
# endif
2007-11-14 22:18:48 -05:00
2011-01-29 20:37:59 -05:00
/**************************************************************************/
2009-07-30 17:27:47 -04:00
// create loopback device, and add to pqisslgrp.
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
SearchModule * mod = new SearchModule ( ) ;
pqiloopback * ploop = new pqiloopback ( ownId ) ;
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
mod - > peerid = ownId ;
mod - > pqi = ploop ;
mod - > sp = secpolicy_create ( ) ;
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
pqih - > AddSearchModule ( mod ) ;
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
/* Setup GUI Interfaces. */
2007-11-14 22:18:48 -05:00
2014-02-01 09:16:15 -05:00
// rsDisc & RsMsgs done already.
2012-06-21 19:23:46 -04:00
rsBandwidthControl = mBwCtrl ;
2012-11-25 15:25:34 -05:00
rsConfig = serverConfig ;
2007-11-14 22:18:48 -05:00
2013-09-03 10:51:23 -04:00
2010-04-20 13:10:45 -04:00
rsStatus = new p3Status ( mStatusSrv ) ;
2011-09-29 05:20:09 -04:00
rsHistory = new p3History ( mHistoryMgr ) ;
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
/* put a welcome message in! */
2014-01-17 21:32:55 -05:00
if ( isFirstTimeRun )
2007-11-14 22:18:48 -05:00
{
2009-07-30 17:27:47 -04:00
msgSrv - > loadWelcomeMsg ( ) ;
2011-03-08 18:29:21 -05:00
ftserver - > shareDownloadDirectory ( true ) ;
2013-09-08 22:10:49 -04:00
mGeneralConfig - > saveConfiguration ( ) ;
2007-11-14 22:18:48 -05:00
}
2009-07-30 17:27:47 -04:00
/* Startup this thread! */
2010-12-14 16:56:37 -05:00
createThread ( * this ) ;
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
return 1 ;
2007-11-14 22:18:48 -05:00
}
2014-03-17 16:56:06 -04:00
void chris_test ( )
{
std : : cout < < " tested \n " ;
}