1
0
mirror of https://github.com/GOSTSec/gostcoin synced 2025-03-13 05:41:11 +00:00

correct SAM session initialization

This commit is contained in:
orignal 2017-04-12 19:33:57 -04:00
parent 89d4bc25a6
commit bbe0d699f3
4 changed files with 56 additions and 27 deletions

View File

@ -74,7 +74,17 @@ void StreamSessionAdapter::SessionHolder::reborn() const
//--------------------------------------------------------------------------------------------------
StreamSessionAdapter::StreamSessionAdapter(
StreamSessionAdapter::StreamSessionAdapter()
{
SAM::StreamSession::SetLogFile ((GetDataDir() / "sam.log").string ());
}
StreamSessionAdapter::~StreamSessionAdapter()
{
SAM::StreamSession::CloseLogFile ();
}
void StreamSessionAdapter::StartSession (
const std::string& nickname,
const std::string& SAMHost /*= SAM_DEFAULT_ADDRESS*/,
uint16_t SAMPort /*= SAM_DEFAULT_PORT*/,
@ -83,16 +93,32 @@ StreamSessionAdapter::StreamSessionAdapter(
const std::string& minVer /*= SAM_DEFAULT_MIN_VER*/,
const std::string& maxVer /*= SAM_DEFAULT_MAX_VER*/)
{
SAM::StreamSession::SetLogFile ((GetDataDir() / "sam.log").string ());
std::cout << "Creating SAM session ..." << std::endl;
auto s = std::make_shared<SAM::StreamSession>(nickname, SAMHost, SAMPort, myDestination, i2pOptions, minVer, maxVer);
sessionHolder_ = std::make_shared<SessionHolder>(s);
std::cout << "SAM session created" << std::endl;
}
StreamSessionAdapter::~StreamSessionAdapter()
void StreamSessionAdapter::StopSession ()
{
SAM::StreamSession::CloseLogFile ();
std::cout << "Terminating SAM session ..." << std::endl;
sessionHolder_ = nullptr;
std::cout << "SAM session terminated" << std::endl;
}
void StreamSessionAdapter::Start ()
{
StartSession(
GetArg(I2P_SESSION_NAME_PARAM, I2P_SESSION_NAME_DEFAULT),
GetArg(I2P_SAM_HOST_PARAM, I2P_SAM_HOST_DEFAULT),
(uint16_t)GetArg(I2P_SAM_PORT_PARAM, I2P_SAM_PORT_DEFAULT),
GetArg(I2P_SAM_MY_DESTINATION_PARAM, I2P_SAM_MY_DESTINATION_DEFAULT),
GetArg(I2P_SAM_I2P_OPTIONS_PARAM, SAM_DEFAULT_I2P_OPTIONS));
}
void StreamSessionAdapter::Stop ()
{
StopSession ();
}
SAM::SOCKET StreamSessionAdapter::accept(bool silent)
@ -186,17 +212,12 @@ const std::string& StreamSessionAdapter::getOptions() const
//--------------------------------------------------------------------------------------------------
I2PSession::I2PSession()
: SAM::StreamSessionAdapter(
GetArg(I2P_SESSION_NAME_PARAM, I2P_SESSION_NAME_DEFAULT),
GetArg(I2P_SAM_HOST_PARAM, I2P_SAM_HOST_DEFAULT),
(uint16_t)GetArg(I2P_SAM_PORT_PARAM, I2P_SAM_PORT_DEFAULT),
GetArg(I2P_SAM_MY_DESTINATION_PARAM, I2P_SAM_MY_DESTINATION_DEFAULT),
GetArg(I2P_SAM_I2P_OPTIONS_PARAM, SAM_DEFAULT_I2P_OPTIONS))
{}
I2PSession::~I2PSession()
{}
/*static*/
std::string I2PSession::GenerateB32AddressFromDestination(const std::string& destination)
{

View File

@ -33,17 +33,13 @@ namespace SAM
class StreamSessionAdapter
{
public:
StreamSessionAdapter(
const std::string& nickname,
const std::string& SAMHost = SAM_DEFAULT_ADDRESS,
uint16_t SAMPort = SAM_DEFAULT_PORT,
const std::string& myDestination = SAM_GENERATE_MY_DESTINATION,
const std::string& i2pOptions = SAM_DEFAULT_I2P_OPTIONS,
const std::string& minVer = SAM_DEFAULT_MIN_VER,
const std::string& maxVer = SAM_DEFAULT_MAX_VER);
StreamSessionAdapter();
~StreamSessionAdapter();
void Start ();
void Stop ();
SAM::SOCKET accept(bool silent);
SAM::SOCKET connect(const std::string& destination, bool silent);
bool forward(const std::string& host, uint16_t port, bool silent);
@ -64,6 +60,19 @@ public:
const std::string& getSAMVersion() const;
const std::string& getOptions() const;
private:
void StartSession(
const std::string& nickname,
const std::string& SAMHost = SAM_DEFAULT_ADDRESS,
uint16_t SAMPort = SAM_DEFAULT_PORT,
const std::string& myDestination = SAM_GENERATE_MY_DESTINATION,
const std::string& i2pOptions = SAM_DEFAULT_I2P_OPTIONS,
const std::string& minVer = SAM_DEFAULT_MIN_VER,
const std::string& maxVer = SAM_DEFAULT_MAX_VER);
void StopSession ();
private:
class SessionHolder;

View File

@ -137,6 +137,9 @@ void Shutdown()
UnregisterWallet(pwalletMain);
if (pwalletMain)
delete pwalletMain;
I2PSession::Instance ().Stop ();
printf("Shutdown : done\n");
}
@ -550,8 +553,10 @@ bool AppInit2(boost::thread_group& threadGroup)
#endif
#endif
// ********************************************************* Step 2: parameter interactions
uiInterface.InitMessage(_("Creating SAM session..."));
I2PSession::Instance ().Start ();
// ********************************************************* Step 2: parameter interactions
if (GetBoolArg(I2P_SAM_GENERATE_DESTINATION_PARAM))
{
@ -1184,6 +1189,7 @@ bool AppInit2(boost::thread_group& threadGroup)
printf("Loaded %i addresses from peers.dat %" PRI64d "ms\n",
addrman.size(), GetTimeMillis() - nStart);
// ********************************************************* Step 11: start node
if (!CheckDiskSpace())

View File

@ -11,7 +11,7 @@
const std::string CLIENT_NAME("GOST");
// Client version number
#define CLIENT_VERSION_SUFFIX "-beta"
#define CLIENT_VERSION_SUFFIX ""
// The following part of the code determines the CLIENT_BUILD variable.
@ -33,13 +33,6 @@ const std::string CLIENT_NAME("GOST");
# include "build.h"
#endif
// git will put "#define GIT_ARCHIVE 1" on the next line inside archives.
#define GIT_ARCHIVE 1
#ifdef GIT_ARCHIVE
# define GIT_COMMIT_ID "c0b7034"
# define GIT_COMMIT_DATE "Tue, 24 Dec 2013 20:07:16 +0100"
#endif
#define BUILD_DESC_FROM_COMMIT(maj,min,rev,build,commit) \
"v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-g" commit