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>
2015-11-26 20:40:06 -05:00
# include <gxstunnel/p3gxstunnel.h>
2014-03-29 10:18:05 -04:00
# define ENABLE_GROUTER
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
2014-03-29 10:18:05 -04:00
# ifdef ENABLE_GROUTER
2013-11-02 10:35:33 -04:00
# 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
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-08-25 17:07:07 -04:00
RsFileHash main_executable_hash ;
2014-01-17 21:32:55 -05:00
2010-04-30 10:34:48 -04:00
# ifdef WINDOWS_SYS
2014-08-25 17:07:07 -04:00
bool portable ;
bool isWindowsXP ;
2010-04-30 10:34:48 -04:00
# endif
2014-08-25 17:07:07 -04:00
rs_lock_handle_t lockHandle ;
2010-07-01 16:30:36 -04:00
2014-08-25 17:07:07 -04:00
std : : string passwd ;
std : : string gxs_passwd ;
2009-07-30 17:27:47 -04:00
2014-08-25 17:07:07 -04:00
bool autoLogin ; /* autoLogin allowed */
bool startMinimised ; /* Icon or Full Window */
2009-07-30 17:27:47 -04:00
2014-08-25 17:07:07 -04:00
/* Key Parameters that must be set before
* RetroShare will start up :
*/
2009-07-30 17:27:47 -04:00
2014-08-25 17:07:07 -04:00
/* Listening Port */
bool forceExtPort ;
bool forceLocalAddr ;
unsigned short port ;
std : : string inet ;
2009-07-30 17:27:47 -04:00
2013-09-08 22:10:49 -04:00
/* v0.6 features */
2014-08-25 17:07:07 -04:00
bool hiddenNodeSet ;
std : : string hiddenNodeAddress ;
uint16_t hiddenNodePort ;
2013-09-08 22:10:49 -04:00
2014-08-25 17:07:07 -04:00
/* Logging */
bool haveLogFile ;
bool outStderr ;
int debugLevel ;
std : : string logfname ;
2009-07-30 17:27:47 -04:00
2014-08-25 17:07:07 -04:00
bool load_trustedpeer ;
std : : string load_trustedpeer_file ;
2009-07-30 17:27:47 -04:00
2014-08-25 17:07:07 -04:00
bool udpListenerOnly ;
2011-04-14 17:59:51 -04:00
2014-08-25 17:07:07 -04:00
std : : string RetroShareLink ;
2009-07-30 17:27:47 -04:00
} ;
2014-08-25 17:07:07 -04:00
static RsInitConfig * rsInitConfig = NULL ;
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-08-25 17:07:07 -04:00
void RsInit : : InitRsConfig ( )
{
rsInitConfig = new RsInitConfig ;
2009-02-08 09:30:28 -05:00
2014-08-25 17:07:07 -04:00
/* Directories */
2010-04-30 10:34:48 -04:00
# ifdef WINDOWS_SYS
2014-08-25 17:07:07 -04:00
rsInitConfig - > portable = false ;
rsInitConfig - > isWindowsXP = false ;
2010-04-30 10:34:48 -04:00
# endif
2014-08-25 17:07:07 -04:00
/* v0.6 features */
rsInitConfig - > hiddenNodeSet = false ;
2009-02-08 09:30:28 -05:00
2007-11-14 22:18:48 -05:00
# ifndef WINDOWS_SYS
2014-08-25 17:07:07 -04:00
rsInitConfig - > lockHandle = - 1 ;
2007-11-14 22:18:48 -05:00
# else
2014-08-25 17:07:07 -04:00
rsInitConfig - > lockHandle = NULL ;
2007-11-14 22:18:48 -05:00
# endif
2014-08-25 17:07:07 -04:00
rsInitConfig - > load_trustedpeer = false ;
rsInitConfig - > port = 0 ;
rsInitConfig - > forceLocalAddr = false ;
rsInitConfig - > haveLogFile = false ;
rsInitConfig - > outStderr = false ;
rsInitConfig - > forceExtPort = false ;
2009-07-30 17:27:47 -04:00
2014-08-25 17:07:07 -04:00
rsInitConfig - > inet = std : : string ( " 127.0.0.1 " ) ;
2009-07-30 17:27:47 -04:00
2014-08-25 17:07:07 -04:00
rsInitConfig - > autoLogin = false ; // .
rsInitConfig - > startMinimised = false ;
rsInitConfig - > passwd = " " ;
rsInitConfig - > debugLevel = PQL_WARNING ;
rsInitConfig - > udpListenerOnly = false ;
2009-07-30 17:27:47 -04:00
2010-04-30 10:34:48 -04:00
/* setup the homePath (default save location) */
2014-08-25 17:07:07 -04: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
2014-08-25 17:07:07 -04:00
rsInitConfig - > portable = true ;
2010-04-30 10:34:48 -04:00
}
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 */
2014-08-25 17:07:07 -04:00
rsInitConfig - > isWindowsXP = true ;
2010-10-07 07:17:42 -04:00
} 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 */
2014-08-25 17:07:07 -04:00
rsInitConfig - > isWindowsXP = true ;
2010-10-07 07:17:42 -04:00
}
}
}
}
2014-08-25 17:07:07 -04:00
if ( rsInitConfig - > isWindowsXP ) {
2010-10-07 07:17:42 -04:00
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
2015-11-30 00:02:44 -05: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 .
*/
2014-08-25 17:07:07 -04:00
//rsInitConfig->logfname = "" ;
//rsInitConfig->inet = "" ;
2013-08-06 13:01:38 -04:00
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
2014-08-25 17:07:07 -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. " )
2013-08-06 13:01:38 -04:00
2014-08-25 17:07:07 -04:00
> > 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 )
2014-08-25 17:07:07 -04:00
> > parameter ( ' r ' , " link " , rsInitConfig - > RetroShareLink , " retroshare://... " , " Use a given Retroshare Link " , false )
2013-08-06 13:01:38 -04:00
# ifdef LOCALNET_TESTING
> > parameter ( ' R ' , " restrict-port " , portRestrictions , " port1-port2 " , " Apply port restriction " , false )
# endif
2015-11-20 11:10:59 -05:00
# ifdef __APPLE__
> > help ( ' h ' , " help " , " Display this Help " ) ;
# else
2013-08-06 13:01:38 -04:00
> > help ( ) ;
2015-11-20 11:10:59 -05:00
# endif
2013-08-06 13:01:38 -04:00
as . defaultErrorHandling ( true ) ;
2014-08-25 17:07:07 -04:00
if ( rsInitConfig - > autoLogin ) rsInitConfig - > startMinimised = true ;
if ( rsInitConfig - > outStderr ) rsInitConfig - > haveLogFile = false ;
if ( ! rsInitConfig - > logfname . empty ( ) ) rsInitConfig - > haveLogFile = true ;
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
2014-08-25 17:07:07 -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...
2014-08-25 17:07:07 -04:00
// if (rsInitConfig->haveDebugLevel)
2013-08-06 13:01:38 -04:00
// {
2014-08-25 17:07:07 -04:00
// if ((rsInitConfig->debugLevel > 0) &&
// (rsInitConfig->debugLevel <= PQL_DEBUG_ALL))
2013-08-06 13:01:38 -04:00
// {
// std::cerr << "Setting Debug Level to: ";
2014-08-25 17:07:07 -04:00
// std::cerr << rsInitConfig->debugLevel;
2013-08-06 13:01:38 -04:00
// std::cerr << std::endl;
// }
// else
// {
// std::cerr << "Ignoring Invalid Debug Level: ";
2014-08-25 17:07:07 -04:00
// std::cerr << rsInitConfig->debugLevel;
2013-08-06 13:01:38 -04:00
// std::cerr << std::endl;
// }
// }
2007-11-14 22:18:48 -05:00
// set the debug file.
2014-08-25 17:07:07 -04:00
if ( rsInitConfig - > haveLogFile )
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 ;
2014-08-25 17:07:07 -04:00
if ( ! RsDirUtil : : getFileHash ( argv [ 0 ] , rsInitConfig - > main_executable_hash , tmp_size , NULL ) )
2012-09-09 09:59:21 -04:00
std : : cerr < < " Cannot hash executable! Plugins will not be loaded correctly. " < < std : : endl ;
else
2014-08-25 17:07:07 -04:00
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 ( ) ;
2015-03-25 04:19:45 -04:00
AuthSSL : : getAuthSSL ( ) - > InitAuth ( NULL , NULL , NULL , " " ) ;
2009-07-30 17:27:47 -04:00
2014-08-25 17:07:07 -04:00
rsAccounts = new RsAccountsDetail ( ) ;
2009-07-30 17:27:47 -04:00
// first check config directories, and set bootstrap values.
2014-08-25 17:07:07 -04: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.
2014-08-25 17:07:07 -04:00
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.
2014-08-25 17:07:07 -04:00
if ( ! rsAccounts - > loadAccounts ( ) )
2014-01-17 21:32:55 -05:00
{
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-08-25 17:07:07 -04: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-08-25 17:07:07 -04:00
bool existingUser = rsAccounts - > getPreferredAccountId ( preferredId ) ;
2010-04-10 18:06:11 -04:00
2007-11-14 22:18:48 -05:00
if ( existingUser )
{
2014-08-25 17:07:07 -04: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-08-25 17:07:07 -04: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
2014-08-25 17:07:07 -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 ( )
{
2014-08-25 17:07:07 -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
{
2014-08-25 17:07:07 -04:00
rsInitConfig - > passwd = inPwd ;
2009-07-30 17:27:47 -04:00
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-08-25 17:07:07 -04:00
if ( ! rsAccounts - > lockPreferredAccount ( ) )
2014-01-17 21:32:55 -05:00
{
return 3 ; // invalid PreferredAccount.
}
2014-11-08 14:31:16 -05:00
int retVal = 0 ;
2014-01-17 21:32:55 -05:00
// Logic that used to be external to RsInit...
2014-03-17 16:56:06 -04:00
RsPeerId accountId ;
2014-08-25 17:07:07 -04:00
if ( ! rsAccounts - > getPreferredAccountId ( accountId ) )
2014-01-17 21:32:55 -05:00
{
2014-11-08 14:31:16 -05:00
retVal = 3 ; // invalid PreferredAccount;
2014-01-17 21:32:55 -05:00
}
2014-03-17 16:56:06 -04:00
RsPgpId pgpId ;
std : : string pgpName , pgpEmail , location ;
2014-11-08 14:31:16 -05:00
if ( retVal = = 0 & & ! rsAccounts - > getAccountDetails ( accountId , pgpId , pgpName , pgpEmail , location ) )
retVal = 3 ; // invalid PreferredAccount;
2014-01-17 21:32:55 -05:00
2014-11-08 14:31:16 -05:00
if ( retVal = = 0 & & ! rsAccounts - > SelectPGPAccount ( pgpId ) )
retVal = 3 ; // PGP Error.
2014-01-17 21:32:55 -05:00
2014-11-08 14:31:16 -05:00
if ( retVal = = 0 )
retVal = LockConfigDirectory ( rsAccounts - > PathAccountDirectory ( ) , lockFilePath ) ;
2010-07-01 16:30:36 -04:00
2014-11-08 14:31:16 -05:00
if ( retVal = = 0 & & LoadCertificates ( autoLoginNT ) ! = 1 )
{
2010-07-01 16:30:36 -04:00
UnlockConfigDirectory ( ) ;
2014-11-08 14:31:16 -05:00
retVal = 3 ;
}
if ( retVal ! = 0 )
{
rsAccounts - > unlockPreferredAccount ( ) ;
2010-07-01 16:30:36 -04:00
}
2014-11-08 14:31:16 -05:00
return retVal ;
2010-07-01 16:30:36 -04:00
}
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-08-25 17:07:07 -04:00
if ( ! rsAccounts - > getPreferredAccountId ( preferredId ) )
2014-01-17 21:32:55 -05:00
{
std : : cerr < < " No Account Selected " < < std : : endl ;
return 0 ;
}
2014-08-25 17:07:07 -04:00
if ( rsAccounts - > PathCertFile ( ) = = " " )
2009-07-30 17:27:47 -04:00
{
std : : cerr < < " RetroShare needs a certificate " < < std : : endl ;
return 0 ;
}
2014-08-25 17:07:07 -04: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
2014-08-25 17:07:07 -04:00
if ( rsInitConfig - > passwd = = " " ) {
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-08-25 17:07:07 -04: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-08-25 17:07:07 -04:00
std : : cerr < < " rsAccounts->PathKeyFile() : " < < rsAccounts - > PathKeyFile ( ) < < std : : endl ;
2010-04-08 08:02:46 -04:00
2015-03-25 04:19:45 -04:00
if ( 0 = = AuthSSL : : getAuthSSL ( ) - > InitAuth ( rsAccounts - > PathCertFile ( ) . c_str ( ) , rsAccounts - > PathKeyFile ( ) . c_str ( ) , rsInitConfig - > passwd . c_str ( ) , rsAccounts - > LocationName ( ) ) )
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-08-25 17:07:07 -04:00
RsLoginHandler : : enableAutoLogin ( preferredId , rsInitConfig - > passwd ) ;
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
2014-08-25 17:07:07 -04:00
rsInitConfig - > gxs_passwd = rsInitConfig - > passwd ;
rsInitConfig - > passwd = " " ;
2014-01-17 21:32:55 -05:00
2014-08-25 17:07:07 -04: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-08-25 17:07:07 -04: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
2014-08-25 17:07:07 -04:00
return rsInitConfig - > portable ;
2010-05-02 18:28:33 -04:00
# 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
2014-08-25 17:07:07 -04:00
return rsInitConfig - > isWindowsXP ;
2010-10-07 07:17:42 -04:00
# 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
{
2014-08-25 17:07:07 -04:00
return rsInitConfig - > startMinimised ;
2009-07-30 17:27:47 -04:00
}
2011-04-14 17:59:51 -04:00
std : : string RsInit : : getRetroShareLink ( )
{
2014-08-25 17:07:07 -04:00
return rsInitConfig - > RetroShareLink ;
2011-04-14 17:59:51 -04:00
}
2010-04-08 08:02:46 -04:00
int RsInit : : getSslPwdLen ( ) {
return SSLPWD_LEN ;
}
bool RsInit : : getAutoLogin ( ) {
2014-08-25 17:07:07 -04:00
return rsInitConfig - > autoLogin ;
2010-04-08 08:02:46 -04:00
}
void RsInit : : setAutoLogin ( bool autoLogin ) {
2014-08-25 17:07:07 -04:00
rsInitConfig - > autoLogin = autoLogin ;
2010-04-08 08:02:46 -04:00
}
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-08-25 17:07:07 -04:00
rsInitConfig - > hiddenNodeSet = true ;
rsInitConfig - > hiddenNodeAddress = hiddenaddress ;
rsInitConfig - > hiddenNodePort = port ;
2013-09-08 22:10:49 -04:00
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 ;
2015-10-04 23:14:49 -04:00
RsReputations * rsReputations = NULL ;
2014-03-29 10:18:05 -04:00
# ifdef ENABLE_GROUTER
2013-11-02 10:35:33 -04:00
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
2015-10-04 23:14:49 -04:00
# include "services/p3gxsreputation.h"
2014-03-21 23:53:44 -04:00
# include "services/p3serviceinfo.h"
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"
2010-04-15 06:47:48 -04:00
# include "services/p3statusservice.h"
2014-11-11 11:10:54 -05:00
2009-07-30 17:27:47 -04:00
# include "turtle/p3turtle.h"
2014-11-11 11:10:54 -05:00
# include "chat/p3chatservice.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
2014-04-27 09:14:07 -04:00
# include "pgp/pgpauxutils.h"
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
2015-03-25 04:19:45 -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 ;
2014-08-25 17:07:07 -04:00
if ( ( ! rsInitConfig - > haveLogFile ) & & ( ! rsInitConfig - > outStderr ) )
2007-11-14 22:18:48 -05:00
{
2014-08-25 17:07:07 -04:00
std : : string crashfile = rsAccounts - > PathAccountDirectory ( ) ;
2014-01-17 21:32:55 -05:00
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 ;
2014-08-25 17:07:07 -04:00
if ( rsInitConfig - > udpListenerOnly )
2009-07-30 17:27:47 -04:00
{
flags | = PQIPERSON_NO_LISTENER ;
}
2007-11-14 22:18:48 -05:00
2015-06-03 19:03:03 -04:00
/* check account directory */
if ( ! rsAccounts - > checkAccountDirectory ( ) )
{
std : : cerr < < " RsServer::StartupRetroShare() - Fatal Error..... " < < std : : endl ;
std : : cerr < < " checkAccount failed! " < < std : : endl ;
std : : cerr < < std : : endl ;
return 0 ;
}
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-08-25 17:07:07 -04: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-08-25 17:07:07 -04: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 ;
2014-08-25 17:07:07 -04:00
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);
2014-10-24 18:07:26 -04:00
// for (std::list<std::string>::iterator sslIdsIt = sslIds.begin(); sslIdsIt != sslIds.end(); ++sslIdsIt) {
2012-09-09 09:59:21 -04:00
// mConnMgr->addFriend(*sslIdsIt);
// }
2014-08-25 17:07:07 -04:00
//p3DhtMgr *mDhtMgr = new OpenDHTMgr(ownId, mConnMgr, rsInitConfig->configDir);
2012-09-09 09:59:21 -04:00
/**************************** BITDHT ***********************************/
2010-07-31 14:14:10 -04:00
// Make up an address. XXX
struct sockaddr_in tmpladdr ;
sockaddr_clear ( & tmpladdr ) ;
2014-08-25 17:07:07 -04: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"
2015-05-25 10:02:45 -04:00
# define BITDHT_FILTERED_IP_FILENAME "bdfilter.txt"
2010-10-28 18:59:46 -04:00
2014-08-25 17:07:07 -04: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 ;
2015-05-25 10:02:45 -04:00
std : : string filteredipfile = rsAccounts - > PathAccountDirectory ( ) ;
if ( filteredipfile ! = " " )
filteredipfile + = " / " ;
filteredipfile + = BITDHT_FILTERED_IP_FILENAME ;
std : : cerr < < " Checking for DHT bootstrap file: " < < bootstrapfile < < std : : endl ;
2010-10-28 18:59:46 -04:00
/* check if bootstrap file exists...
* if not . . . copy from dataDirectory
*/
2014-03-29 10:18:05 -04:00
uint64_t tmp_size ;
if ( ! RsDirUtil : : checkFile ( bootstrapfile , tmp_size , true ) )
2010-10-28 18:59:46 -04:00
{
std : : cerr < < " DHT bootstrap file not in ConfigDir: " < < bootstrapfile < < std : : endl ;
2014-08-25 17:07:07 -04: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 ;
2014-03-29 10:18:05 -04:00
if ( ( installfile ! = " " ) & & ( RsDirUtil : : checkFile ( installfile , tmp_size ) ) )
2010-10-28 18:59:46 -04:00
{
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.
2015-05-25 10:02:45 -04:00
p3BitDht * mBitDht = new p3BitDht ( ownId , mLinkMgr , mNetMgr , mDhtStack , bootstrapfile , filteredipfile ) ;
2015-05-27 17:30:40 -04:00
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.
2014-08-25 17:07:07 -04:00
// uint16_t rndport = rsInitConfig->port + 3;
2012-09-09 09:59:21 -04:00
// 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
2014-03-28 23:57:44 -04:00
p3ServiceControl * serviceCtrl = new p3ServiceControl ( mLinkMgr ) ;
2014-03-22 02:28:59 -04:00
rsServiceControl = serviceCtrl ;
2007-11-14 22:18:48 -05:00
2015-06-17 04:49:43 -04:00
pqih = new pqisslpersongrp ( serviceCtrl , 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 **** !!! */
2014-03-28 23:57:44 -04:00
ftServer * ftserver = new ftServer ( mPeerMgr , serviceCtrl ) ;
2014-08-25 17:07:07 -04: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 ( ) ;
2014-03-28 23:57:44 -04:00
//CacheTransfer *mCacheTransfer = ftserver->getCacheTransfer();
2009-07-30 17:27:47 -04:00
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-08-25 17:07:07 -04: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
2015-09-06 08:19:21 -04:00
plugins_directories . push_back ( std : : string ( PLUGIN_DIR ) ) ;
2011-06-17 15:59:01 -04:00
# endif
2014-08-25 17:07:07 -04:00
std : : string extensions_dir = rsAccounts - > PathBaseDirectory ( ) + " /extensions6/ " ;
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
2014-08-25 17:07:07 -04: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 ) ;
2014-04-20 10:20:13 -04:00
mPluginsManager - > setServiceControl ( serviceCtrl ) ;
2011-06-16 17:59:26 -04:00
2014-08-25 17:07:07 -04:00
// std::cerr << "rsinitconf (core 1) = " << (void*)rsInitConfig<<std::endl;
// std::cerr << "gxs_passwd (core 1) = " << (void*)&rsInitConfig->gxs_passwd<<" \"" << rsInitConfig->gxs_passwd << "\""<< std::endl;
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 ) ;
2014-08-25 17:07:07 -04:00
// std::cerr << "rsinitconf (core 1) = " << (void*)rsInitConfig<<std::endl;
// std::cerr << "gxs_passwd (core 2) = " << (void*)&rsInitConfig->gxs_passwd<< " \"" << rsInitConfig->gxs_passwd << "\""<< std::endl;
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 ) ;
2012-12-16 10:04:52 -05:00
# ifdef RS_ENABLE_GXS
2012-08-06 17:00:38 -04:00
2014-08-25 17:07:07 -04:00
std : : string currGxsDir = rsAccounts - > PathAccountDirectory ( ) + " /gxs " ;
2012-11-24 14:49:23 -05:00
RsDirUtil : : checkCreateDirectory ( currGxsDir ) ;
2012-10-21 15:45:35 -04:00
2014-03-28 23:57:44 -04:00
RsNxsNetMgr * nxsMgr = new RsNxsNetMgrImpl ( serviceCtrl ) ;
2012-10-21 15:45:35 -04:00
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 " ,
2014-08-25 17:07:07 -04:00
RS_SERVICE_GXS_TYPE_GXSID , NULL , rsInitConfig - > gxs_passwd ) ;
2012-10-28 19:13:15 -04:00
// init gxs services
2014-04-27 09:14:07 -04:00
PgpAuxUtils * pgpAuxUtils = new PgpAuxUtilsImpl ( ) ;
2014-12-21 15:52:34 -05:00
p3IdService * mGxsIdService = new p3IdService ( gxsid_ds , NULL , pgpAuxUtils ) ;
2012-10-28 19:13:15 -04:00
2014-04-27 09:14:07 -04:00
// circles created here, as needed by Ids.
2013-06-04 17:00:43 -04:00
RsGeneralDataService * gxscircles_ds = new RsDataService ( currGxsDir + " / " , " gxscircles_db " ,
2014-08-25 17:07:07 -04:00
RS_SERVICE_GXS_TYPE_GXSCIRCLE , NULL , rsInitConfig - > gxs_passwd ) ;
2013-06-04 17:00:43 -04:00
2014-04-21 06:13:35 -04:00
// create GxsCircles - early, as IDs need it.
2014-12-21 15:52:34 -05:00
p3GxsCircles * mGxsCircles = new p3GxsCircles ( gxscircles_ds , NULL , mGxsIdService , pgpAuxUtils ) ;
2013-06-04 17:00:43 -04:00
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 (
2014-03-29 11:34:37 -04:00
RS_SERVICE_GXS_TYPE_GXSID , gxsid_ds , nxsMgr ,
2014-03-21 23:53:44 -04:00
mGxsIdService , mGxsIdService - > getServiceInfo ( ) ,
mGxsIdService , mGxsCircles ,
2014-04-27 09:14:07 -04:00
pgpAuxUtils ,
2015-06-30 04:12:51 -04:00
false , false ) ; // don't synchronise group automatic (need explicit group request)
// don't sync messages at all.
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 ****/
// create GXS Circle service
RsGxsNetService * gxscircles_ns = new RsGxsNetService (
2014-03-29 11:34:37 -04:00
RS_SERVICE_GXS_TYPE_GXSCIRCLE , gxscircles_ds , nxsMgr ,
2014-03-21 23:53:44 -04:00
mGxsCircles , mGxsCircles - > getServiceInfo ( ) ,
2014-04-27 09:14:07 -04:00
mGxsIdService , mGxsCircles ,
pgpAuxUtils ) ;
2012-10-28 19:13:15 -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 " ,
2014-03-29 11:34:37 -04:00
RS_SERVICE_GXS_TYPE_POSTED ,
2014-08-25 17:07:07 -04:00
NULL , rsInitConfig - > gxs_passwd ) ;
2012-08-06 17:00:38 -04:00
2014-12-21 15:52:34 -05:00
p3Posted * 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 (
2014-03-29 11:34:37 -04:00
RS_SERVICE_GXS_TYPE_POSTED , posted_ds , nxsMgr ,
2014-03-21 23:53:44 -04:00
mPosted , mPosted - > getServiceInfo ( ) ,
2014-04-27 09:14:07 -04:00
mGxsIdService , mGxsCircles ,
pgpAuxUtils ) ;
2012-08-06 17:00:38 -04:00
2014-10-07 17:42:44 -04:00
mPosted - > setNetworkExchangeService ( posted_ns ) ;
2015-10-04 23:14:49 -04:00
/**** Reputation system ****/
p3GxsReputation * mReputations = new p3GxsReputation ( mLinkMgr ) ;
rsReputations = mReputations ;
2012-10-31 18:43:23 -04:00
/**** Wiki GXS service ****/
2016-01-01 06:01:49 -05:00
# ifdef RS_USE_WIKI
2012-11-24 14:49:23 -05:00
RsGeneralDataService * wiki_ds = new RsDataService ( currGxsDir + " / " , " wiki_db " ,
2014-03-29 11:34:37 -04:00
RS_SERVICE_GXS_TYPE_WIKI ,
2014-08-25 17:07:07 -04:00
NULL , rsInitConfig - > gxs_passwd ) ;
2012-10-31 18:43:23 -04:00
2014-12-21 15:52:34 -05:00
p3Wiki * mWiki = new p3Wiki ( wiki_ds , NULL , mGxsIdService ) ;
2015-09-04 11:52:25 -04:00
// create GXS wiki service
2012-10-31 18:43:23 -04:00
RsGxsNetService * wiki_ns = new RsGxsNetService (
2014-03-29 11:34:37 -04:00
RS_SERVICE_GXS_TYPE_WIKI , wiki_ds , nxsMgr ,
2014-03-21 23:53:44 -04:00
mWiki , mWiki - > getServiceInfo ( ) ,
2014-04-27 09:14:07 -04:00
mGxsIdService , mGxsCircles ,
pgpAuxUtils ) ;
2012-11-08 19:56:07 -05:00
2014-10-07 17:42:44 -04:00
mWiki - > setNetworkExchangeService ( wiki_ns ) ;
2015-09-04 11:52:25 -04:00
# endif
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 " ,
2014-08-25 17:07:07 -04:00
RS_SERVICE_GXS_TYPE_FORUMS , NULL , rsInitConfig - > gxs_passwd ) ;
2012-11-08 19:56:07 -05:00
2014-12-21 15:52:34 -05:00
p3GxsForums * mGxsForums = new p3GxsForums ( gxsforums_ds , NULL , mGxsIdService ) ;
2012-11-08 19:56:07 -05:00
// create GXS photo service
RsGxsNetService * gxsforums_ns = new RsGxsNetService (
2014-03-29 11:34:37 -04:00
RS_SERVICE_GXS_TYPE_FORUMS , gxsforums_ds , nxsMgr ,
2014-03-21 23:53:44 -04:00
mGxsForums , mGxsForums - > getServiceInfo ( ) ,
2014-04-27 09:14:07 -04:00
mGxsIdService , mGxsCircles ,
pgpAuxUtils ) ;
2012-09-25 17:04:04 -04:00
2014-10-07 17:42:44 -04:00
mGxsForums - > setNetworkExchangeService ( gxsforums_ns ) ;
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 " ,
2014-08-25 17:07:07 -04:00
RS_SERVICE_GXS_TYPE_CHANNELS , NULL , rsInitConfig - > gxs_passwd ) ;
2013-03-04 15:26:48 -05:00
2014-12-21 15:52:34 -05:00
p3GxsChannels * mGxsChannels = new p3GxsChannels ( gxschannels_ds , NULL , mGxsIdService ) ;
2013-03-04 15:26:48 -05:00
// create GXS photo service
RsGxsNetService * gxschannels_ns = new RsGxsNetService (
2014-03-29 11:34:37 -04:00
RS_SERVICE_GXS_TYPE_CHANNELS , gxschannels_ds , nxsMgr ,
2014-03-21 23:53:44 -04:00
mGxsChannels , mGxsChannels - > getServiceInfo ( ) ,
2014-04-27 09:14:07 -04:00
mGxsIdService , mGxsCircles ,
pgpAuxUtils ) ;
2012-10-21 15:45:35 -04:00
2014-10-05 15:14:05 -04:00
mGxsChannels - > setNetworkExchangeService ( gxschannels_ns ) ;
2014-03-29 11:34:37 -04:00
#if 0 // PHOTO IS DISABLED FOR THE MOMENT
/**** Photo service ****/
RsGeneralDataService * photo_ds = new RsDataService ( currGxsDir + " / " , " photoV2_db " ,
2014-08-25 17:07:07 -04:00
RS_SERVICE_GXS_TYPE_PHOTO , NULL , rsInitConfig - > gxs_passwd ) ;
2014-03-29 11:34:37 -04:00
// init gxs services
mPhoto = new p3PhotoService ( photo_ds , NULL , mGxsIdService ) ;
// create GXS photo service
RsGxsNetService * photo_ns = new RsGxsNetService (
RS_SERVICE_GXS_TYPE_PHOTO , photo_ds , nxsMgr ,
mPhoto , mPhoto - > getServiceInfo ( ) ,
2014-04-27 09:14:07 -04:00
mGxsIdService , mGxsCircles ,
pgpAuxUtils ) ;
2014-03-29 11:34:37 -04:00
# endif
#if 0 // WIRE IS DISABLED FOR THE MOMENT
/**** Wire GXS service ****/
RsGeneralDataService * wire_ds = new RsDataService ( currGxsDir + " / " , " wire_db " ,
RS_SERVICE_GXS_TYPE_WIRE ,
2014-08-25 17:07:07 -04:00
NULL , rsInitConfig - > gxs_passwd ) ;
2014-03-29 11:34:37 -04:00
mWire = new p3Wire ( wire_ds , NULL , mGxsIdService ) ;
// create GXS photo service
RsGxsNetService * wire_ns = new RsGxsNetService (
RS_SERVICE_GXS_TYPE_WIRE , wire_ds , nxsMgr ,
mWire , mWire - > getServiceInfo ( ) ,
2014-04-27 09:14:07 -04:00
mGxsIdService , mGxsCircles ,
pgpAuxUtils ) ;
2014-03-29 11:34:37 -04:00
# endif
2012-10-21 15:45:35 -04:00
// now add to p3service
2014-03-21 23:53:44 -04:00
pqih - > addService ( gxsid_ns , true ) ;
pqih - > addService ( gxscircles_ns , true ) ;
pqih - > addService ( posted_ns , true ) ;
2015-09-04 11:52:25 -04:00
# ifdef RS_USE_WIKI
2014-03-21 23:53:44 -04:00
pqih - > addService ( wiki_ns , true ) ;
2015-09-04 11:52:25 -04:00
# endif
2014-03-21 23:53:44 -04:00
pqih - > addService ( gxsforums_ns , true ) ;
pqih - > addService ( gxschannels_ns , true ) ;
2014-03-29 11:34:37 -04:00
//pqih->addService(photo_ns, true);
2012-10-21 15:45:35 -04:00
2013-06-20 15:50:25 -04:00
// remove pword from memory
2014-08-25 17:07:07 -04:00
rsInitConfig - > gxs_passwd = " " ;
2013-06-20 15:50:25 -04:00
2012-12-16 10:04:52 -05:00
# endif // RS_ENABLE_GXS.
2012-06-13 20:27:28 -04:00
2014-03-29 10:18:05 -04:00
/* create Services */
p3ServiceInfo * serviceInfo = new p3ServiceInfo ( serviceCtrl ) ;
mDisc = new p3discovery2 ( mPeerMgr , mLinkMgr , mNetMgr , serviceCtrl ) ;
mHeart = new p3heartbeat ( serviceCtrl , pqih ) ;
msgSrv = new p3MsgService ( serviceCtrl , mGxsIdService ) ;
2014-06-12 06:28:23 -04:00
chatSrv = new p3ChatService ( serviceCtrl , mGxsIdService , mLinkMgr , mHistoryMgr ) ;
2014-03-29 10:18:05 -04:00
mStatusSrv = new p3StatusService ( serviceCtrl ) ;
# ifdef ENABLE_GROUTER
2015-01-11 17:18:28 -05:00
p3GRouter * gr = new p3GRouter ( serviceCtrl , mGxsIdService ) ;
2014-03-29 10:18:05 -04:00
rsGRouter = gr ;
pqih - > addService ( gr , true ) ;
# endif
2014-03-29 19:03:04 -04:00
p3turtle * tr = new p3turtle ( serviceCtrl , mLinkMgr ) ;
2014-03-29 10:18:05 -04:00
rsTurtle = tr ;
pqih - > addService ( tr , true ) ;
pqih - > addService ( ftserver , true ) ;
2015-11-27 23:37:39 -05:00
mGxsTunnels = new p3GxsTunnelService ( mGxsIdService ) ;
2015-11-28 18:02:57 -05:00
mGxsTunnels - > connectToTurtleRouter ( tr ) ;
2015-11-27 23:37:39 -05:00
rsGxsTunnel = mGxsTunnels ;
2015-11-26 20:40:06 -05:00
2014-03-29 10:18:05 -04:00
rsDisc = mDisc ;
rsMsgs = new p3Msgs ( msgSrv , chatSrv ) ;
// connect components to turtle router.
ftserver - > connectToTurtleRouter ( tr ) ;
2015-11-27 23:37:39 -05:00
chatSrv - > connectToGxsTunnelService ( mGxsTunnels ) ;
2015-01-11 17:18:28 -05:00
gr - > connectToTurtleRouter ( tr ) ;
2014-03-29 10:18:05 -04:00
# ifdef ENABLE_GROUTER
msgSrv - > connectToGlobalRouter ( gr ) ;
# endif
pqih - > addService ( serviceInfo , true ) ;
pqih - > addService ( mHeart , true ) ;
pqih - > addService ( mDisc , true ) ;
pqih - > addService ( msgSrv , true ) ;
pqih - > addService ( chatSrv , true ) ;
2015-11-26 20:40:06 -05:00
pqih - > addService ( mStatusSrv , true ) ;
2015-11-28 18:02:57 -05:00
pqih - > addService ( mGxsTunnels , true ) ;
2015-10-04 23:14:49 -04:00
pqih - > addService ( mReputations , true ) ;
2014-03-29 10:18:05 -04: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 ;
interfaces . mNotify = mNotify ;
2015-12-15 13:56:49 -05:00
interfaces . mServiceControl = serviceCtrl ;
interfaces . mPluginHandler = mPluginsManager ;
2014-08-25 17:07:07 -04:00
// gxs
interfaces . mGxsDir = currGxsDir ;
interfaces . mIdentity = mGxsIdService ;
interfaces . mRsNxsNetMgr = nxsMgr ;
interfaces . mGxsIdService = mGxsIdService ;
interfaces . mGxsCirlces = mGxsCircles ;
interfaces . mPgpAuxUtils = pgpAuxUtils ;
2014-11-23 18:24:41 -05:00
interfaces . mGxsForums = mGxsForums ;
interfaces . mGxsChannels = mGxsChannels ;
2015-11-28 18:02:57 -05:00
interfaces . mGxsTunnels = mGxsTunnels ;
2015-10-04 23:14:49 -04:00
interfaces . mReputations = mReputations ;
2015-11-28 18:02:57 -05:00
2014-03-29 10:18:05 -04:00
mPluginsManager - > setInterfaces ( interfaces ) ;
// now add plugin objects inside the loop:
// - client services provided by plugins.
// - cache services provided by plugins.
//
mPluginsManager - > registerClientServices ( pqih ) ;
mPluginsManager - > registerCacheServices ( ) ;
2012-07-27 11:03:16 -04:00
2013-09-29 03:11:02 -04:00
# ifdef RS_RTT
2014-03-28 23:57:44 -04:00
p3rtt * mRtt = new p3rtt ( serviceCtrl ) ;
2014-03-21 23:53:44 -04:00
pqih - > addService ( mRtt , true ) ;
2013-09-29 03:11:02 -04:00
rsRtt = mRtt ;
2011-08-03 13:43:26 -04:00
# endif
2011-11-24 19:58:01 -05:00
// new services to test.
2015-05-27 17:30:40 -04:00
p3BanList * mBanList = new p3BanList ( serviceCtrl , mNetMgr ) ;
rsBanList = mBanList ;
2014-03-21 23:53:44 -04:00
pqih - > addService ( mBanList , true ) ;
2011-11-24 19:58:01 -05:00
mBitDht - > setupPeerSharer ( mBanList ) ;
2012-06-21 19:23:46 -04:00
p3BandwidthControl * mBwCtrl = new p3BandwidthControl ( pqih ) ;
2014-03-21 23:53:44 -04:00
pqih - > addService ( mBwCtrl , true ) ;
2012-06-21 19:23:46 -04:00
2013-12-22 12:10:56 -05:00
# ifdef SERVICES_DSDV
2014-03-28 23:57:44 -04:00
p3Dsdv * mDsdv = new p3Dsdv ( serviceCtrl ) ;
2014-03-21 23:53:44 -04:00
pqih - > addService ( mDsdv , true ) ;
2011-11-24 19:58:01 -05:00
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 ) ;
2014-03-22 23:30:59 -04:00
mLinkMgr - > addMonitor ( serviceCtrl ) ;
mLinkMgr - > addMonitor ( serviceInfo ) ;
2014-03-28 23:57:44 -04:00
// NOTE these were added in ftServer (was added twice).
//mLinkMgr->addMonitor(mCacheStrapper);
//mLinkMgr->addMonitor(((ftController *) mCacheTransfer));
2007-11-14 22:18:48 -05:00
2014-03-22 23:30:59 -04:00
// Services that have been changed to pqiServiceMonitor
2014-03-28 23:57:44 -04:00
serviceCtrl - > registerServiceMonitor ( msgSrv , msgSrv - > getServiceInfo ( ) . mServiceType ) ;
2014-03-22 23:30:59 -04:00
serviceCtrl - > registerServiceMonitor ( mDisc , mDisc - > getServiceInfo ( ) . mServiceType ) ;
2014-04-19 12:02:11 -04:00
serviceCtrl - > registerServiceMonitor ( mStatusSrv , mStatusSrv - > getServiceInfo ( ) . mServiceType ) ;
serviceCtrl - > registerServiceMonitor ( chatSrv , chatSrv - > getServiceInfo ( ) . mServiceType ) ;
2014-03-28 23:57:44 -04:00
serviceCtrl - > registerServiceMonitor ( mBwCtrl , mDisc - > getServiceInfo ( ) . mServiceType ) ;
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 ) ;
mConfigMgr - > addConfiguration ( " msgs.cfg " , msgSrv ) ;
2015-10-04 23:14:49 -04:00
mConfigMgr - > addConfiguration ( " chat.cfg " , chatSrv ) ;
mConfigMgr - > addConfiguration ( " p3History.cfg " , mHistoryMgr ) ;
mConfigMgr - > addConfiguration ( " p3Status.cfg " , mStatusSrv ) ;
mConfigMgr - > addConfiguration ( " turtle.cfg " , tr ) ;
mConfigMgr - > addConfiguration ( " banlist.cfg " , mBanList ) ;
mConfigMgr - > addConfiguration ( " servicecontrol.cfg " , serviceCtrl ) ;
mConfigMgr - > addConfiguration ( " reputations.cfg " , mReputations ) ;
2014-03-29 10:18:05 -04:00
# ifdef ENABLE_GROUTER
2013-12-28 16:47:15 -05:00
mConfigMgr - > addConfiguration ( " grouter.cfg " , gr ) ;
# endif
2015-03-25 18:21:01 -04:00
mConfigMgr - > addConfiguration ( " p3identity.cfg " , mGxsIdService ) ;
2011-06-16 17:59:26 -04:00
2011-12-19 21:07:00 -05:00
# ifdef RS_USE_BITDHT
2015-05-30 15:34:30 -04:00
mConfigMgr - > addConfiguration ( " bitdht.cfg " , mBitDht ) ;
2011-12-19 21:07:00 -05:00
# 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 ) ;
2015-09-04 11:52:25 -04:00
# ifdef RS_USE_WIKI
2013-12-20 09:48:32 -05:00
mConfigMgr - > addConfiguration ( " wiki.cfg " , wiki_ns ) ;
2015-09-04 11:52:25 -04:00
# endif
2014-03-29 11:34:37 -04:00
//mConfigMgr->addConfiguration("photo.cfg", photo_ns);
//mConfigMgr->addConfiguration("wire.cfg", wire_ns);
2013-12-20 09:48:32 -05:00
# 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
/* 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
2014-03-29 01:20:57 -04:00
mConfigMgr - > addConfiguration ( " cache.cfg " , mCacheStrapper ) ;
mConfigMgr - > loadConfiguration ( ) ;
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
2014-08-25 17:07:07 -04:00
if ( rsInitConfig - > forceLocalAddr )
2009-07-30 17:27:47 -04:00
{
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 ;
2014-08-25 17:07:07 -04:00
lap - > sin_port = htons ( rsInitConfig - > port ) ;
2007-11-14 22:18:48 -05:00
2009-07-30 17:27:47 -04:00
// universal
2014-08-25 17:07:07 -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
2014-08-25 17:07:07 -04:00
if ( rsInitConfig - > forceExtPort )
2009-07-30 17:27:47 -04:00
{
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-08-25 17:07:07 -04:00
if ( rsInitConfig - > hiddenNodeSet )
2007-11-14 22:18:48 -05:00
{
2014-08-25 17:07:07 -04:00
mPeerMgr - > setupHiddenNode ( rsInitConfig - > hiddenNodeAddress , rsInitConfig - > hiddenNodePort ) ;
2013-09-08 22:10:49 -04:00
}
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.
2014-12-21 15:52:34 -05:00
rsIdentity = mGxsIdService ;
rsGxsCircles = mGxsCircles ;
2015-09-04 11:52:25 -04:00
# if RS_USE_WIKI
2014-12-21 15:52:34 -05:00
rsWiki = mWiki ;
2015-09-04 11:52:25 -04:00
# endif
2014-12-21 15:52:34 -05:00
rsPosted = mPosted ;
rsGxsForums = mGxsForums ;
rsGxsChannels = mGxsChannels ;
//rsPhoto = mPhoto;
//rsWire = mWire;
2013-03-04 15:26:48 -05:00
/*** start up GXS core runner ***/
2014-12-21 15:52:34 -05:00
startServiceThread ( mGxsIdService ) ;
startServiceThread ( mGxsCircles ) ;
startServiceThread ( mPosted ) ;
2015-09-04 11:52:25 -04:00
# if RS_USE_WIKI
2014-12-21 15:52:34 -05:00
startServiceThread ( mWiki ) ;
2015-09-04 11:52:25 -04:00
# endif
2014-12-21 15:52:34 -05:00
startServiceThread ( mGxsForums ) ;
startServiceThread ( mGxsChannels ) ;
2013-03-04 15:26:48 -05:00
2014-03-29 11:34:37 -04:00
//createThread(*mPhoto);
//createThread(*mWire);
2013-03-04 15:26:48 -05:00
// cores ready start up GXS net servers
2014-12-21 15:52:34 -05:00
startServiceThread ( gxsid_ns ) ;
startServiceThread ( gxscircles_ns ) ;
startServiceThread ( posted_ns ) ;
2015-09-04 11:52:25 -04:00
# if RS_USE_WIKI
2014-12-21 15:52:34 -05:00
startServiceThread ( wiki_ns ) ;
2015-09-04 11:52:25 -04:00
# endif
2014-12-21 15:52:34 -05:00
startServiceThread ( gxsforums_ns ) ;
startServiceThread ( gxschannels_ns ) ;
2013-03-04 15:26:48 -05:00
2014-03-29 11:34:37 -04:00
//createThread(*photo_ns);
//createThread(*wire_ns);
2013-03-04 15:26:48 -05:00
# 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 ;
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! */
2014-12-21 15:52:34 -05:00
start ( ) ;
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