Browse Source

correct SAM session initialization

pull/5/head
orignal 7 years ago
parent
commit
bbe0d699f3
  1. 41
      src/i2p.cpp
  2. 25
      src/i2p.h
  3. 8
      src/init.cpp
  4. 9
      src/version.cpp

41
src/i2p.cpp

@ -74,7 +74,17 @@ void StreamSessionAdapter::SessionHolder::reborn() const @@ -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( @@ -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 @@ -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)
{

25
src/i2p.h

@ -33,17 +33,13 @@ namespace SAM @@ -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: @@ -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;

8
src/init.cpp

@ -137,6 +137,9 @@ void Shutdown() @@ -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) @@ -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) @@ -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())

9
src/version.cpp

@ -11,7 +11,7 @@ @@ -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"); @@ -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

Loading…
Cancel
Save