mirror of
https://github.com/GOSTSec/gostcoin
synced 2025-01-30 16:34:29 +00:00
check if SAM session is connected
This commit is contained in:
parent
bf77a952ee
commit
d410d7b4b5
@ -372,6 +372,7 @@ public:
|
|||||||
const std::string& getOptions() const;
|
const std::string& getOptions() const;
|
||||||
|
|
||||||
bool isSick() const;
|
bool isSick() const;
|
||||||
|
bool isReady () const { return socket_.isOk() && !isSick (); };
|
||||||
|
|
||||||
static std::ostream& getLogStream ();
|
static std::ostream& getLogStream ();
|
||||||
static void SetLogFile (const std::string& filename);
|
static void SetLogFile (const std::string& filename);
|
||||||
|
11
src/i2p.cpp
11
src/i2p.cpp
@ -84,7 +84,7 @@ StreamSessionAdapter::~StreamSessionAdapter()
|
|||||||
SAM::StreamSession::CloseLogFile ();
|
SAM::StreamSession::CloseLogFile ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StreamSessionAdapter::StartSession (
|
bool StreamSessionAdapter::StartSession (
|
||||||
const std::string& nickname,
|
const std::string& nickname,
|
||||||
const std::string& SAMHost /*= SAM_DEFAULT_ADDRESS*/,
|
const std::string& SAMHost /*= SAM_DEFAULT_ADDRESS*/,
|
||||||
uint16_t SAMPort /*= SAM_DEFAULT_PORT*/,
|
uint16_t SAMPort /*= SAM_DEFAULT_PORT*/,
|
||||||
@ -96,7 +96,12 @@ void StreamSessionAdapter::StartSession (
|
|||||||
std::cout << "Creating SAM session ..." << std::endl;
|
std::cout << "Creating SAM session ..." << std::endl;
|
||||||
auto s = std::make_shared<SAM::StreamSession>(nickname, SAMHost, SAMPort, myDestination, i2pOptions, minVer, maxVer);
|
auto s = std::make_shared<SAM::StreamSession>(nickname, SAMHost, SAMPort, myDestination, i2pOptions, minVer, maxVer);
|
||||||
sessionHolder_ = std::make_shared<SessionHolder>(s);
|
sessionHolder_ = std::make_shared<SessionHolder>(s);
|
||||||
|
bool isReady = s->isReady ();
|
||||||
|
if (isReady)
|
||||||
std::cout << "SAM session created" << std::endl;
|
std::cout << "SAM session created" << std::endl;
|
||||||
|
else
|
||||||
|
std::cout << "SAM session failed" << std::endl;
|
||||||
|
return isReady;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StreamSessionAdapter::StopSession ()
|
void StreamSessionAdapter::StopSession ()
|
||||||
@ -106,9 +111,9 @@ void StreamSessionAdapter::StopSession ()
|
|||||||
std::cout << "SAM session terminated" << std::endl;
|
std::cout << "SAM session terminated" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StreamSessionAdapter::Start ()
|
bool StreamSessionAdapter::Start ()
|
||||||
{
|
{
|
||||||
StartSession(
|
return StartSession(
|
||||||
GetArg(I2P_SESSION_NAME_PARAM, I2P_SESSION_NAME_DEFAULT),
|
GetArg(I2P_SESSION_NAME_PARAM, I2P_SESSION_NAME_DEFAULT),
|
||||||
GetArg(I2P_SAM_HOST_PARAM, I2P_SAM_HOST_DEFAULT),
|
GetArg(I2P_SAM_HOST_PARAM, I2P_SAM_HOST_DEFAULT),
|
||||||
(uint16_t)GetArg(I2P_SAM_PORT_PARAM, I2P_SAM_PORT_DEFAULT),
|
(uint16_t)GetArg(I2P_SAM_PORT_PARAM, I2P_SAM_PORT_DEFAULT),
|
||||||
|
@ -37,7 +37,7 @@ public:
|
|||||||
StreamSessionAdapter();
|
StreamSessionAdapter();
|
||||||
~StreamSessionAdapter();
|
~StreamSessionAdapter();
|
||||||
|
|
||||||
void Start ();
|
bool Start ();
|
||||||
void Stop ();
|
void Stop ();
|
||||||
|
|
||||||
SAM::SOCKET accept(bool silent);
|
SAM::SOCKET accept(bool silent);
|
||||||
@ -62,7 +62,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void StartSession(
|
bool StartSession(
|
||||||
const std::string& nickname,
|
const std::string& nickname,
|
||||||
const std::string& SAMHost = SAM_DEFAULT_ADDRESS,
|
const std::string& SAMHost = SAM_DEFAULT_ADDRESS,
|
||||||
uint16_t SAMPort = SAM_DEFAULT_PORT,
|
uint16_t SAMPort = SAM_DEFAULT_PORT,
|
||||||
|
@ -555,7 +555,8 @@ bool AppInit2(boost::thread_group& threadGroup)
|
|||||||
// if (GetBoolArg("-i2p", false))
|
// if (GetBoolArg("-i2p", false))
|
||||||
// {
|
// {
|
||||||
uiInterface.InitMessage(_("Creating SAM session..."));
|
uiInterface.InitMessage(_("Creating SAM session..."));
|
||||||
I2PSession::Instance ().Start ();
|
if (!I2PSession::Instance ().Start () && IsI2POnly())
|
||||||
|
return InitError("Can't connect to SAM\n");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// ********************************************************* Step 2: parameter interactions
|
// ********************************************************* Step 2: parameter interactions
|
||||||
|
@ -65,7 +65,7 @@ map<uint256, set<uint256> > mapOrphanTransactionsByPrev;
|
|||||||
// Constant stuff for coinbase transactions we create:
|
// Constant stuff for coinbase transactions we create:
|
||||||
CScript COINBASE_FLAGS;
|
CScript COINBASE_FLAGS;
|
||||||
|
|
||||||
const string strMessageMagic = "Anoncoin Signed Message:\n";
|
const string strMessageMagic = "Gostcoin Signed Message:\n";
|
||||||
|
|
||||||
double dHashesPerSec = 0.0;
|
double dHashesPerSec = 0.0;
|
||||||
int64 nHPSTimerStart = 0;
|
int64 nHPSTimerStart = 0;
|
||||||
@ -4665,7 +4665,7 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
//// debug print
|
//// debug print
|
||||||
printf("AnoncoinMiner:\n");
|
printf("GostcoinMiner:\n");
|
||||||
printf("proof-of-work found \n hash: %s \ntarget: %s\n", hash.GetHex().c_str(), hashTarget.GetHex().c_str());
|
printf("proof-of-work found \n hash: %s \ntarget: %s\n", hash.GetHex().c_str(), hashTarget.GetHex().c_str());
|
||||||
pblock->print();
|
pblock->print();
|
||||||
printf("generated %s\n", FormatMoney(pblock->vtx[0].vout[0].nValue).c_str());
|
printf("generated %s\n", FormatMoney(pblock->vtx[0].vout[0].nValue).c_str());
|
||||||
@ -4674,7 +4674,7 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
|
|||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
if (pblock->hashPrevBlock != hashBestChain)
|
if (pblock->hashPrevBlock != hashBestChain)
|
||||||
return error("AnoncoinMiner : generated block is stale");
|
return error("GostcoinMiner : generated block is stale");
|
||||||
|
|
||||||
// Remove key from key pool
|
// Remove key from key pool
|
||||||
reservekey.KeepKey();
|
reservekey.KeepKey();
|
||||||
@ -4688,7 +4688,7 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
|
|||||||
// Process this block the same as if we had received it from another node
|
// Process this block the same as if we had received it from another node
|
||||||
CValidationState state;
|
CValidationState state;
|
||||||
if (!ProcessBlock(state, NULL, pblock))
|
if (!ProcessBlock(state, NULL, pblock))
|
||||||
return error("AnoncoinMiner : ProcessBlock, block not accepted");
|
return error("GostcoinMiner : ProcessBlock, block not accepted");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -103,7 +103,7 @@ Value getnewaddress(const Array& params, bool fHelp)
|
|||||||
if (fHelp || params.size() > 1)
|
if (fHelp || params.size() > 1)
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"getnewaddress [account]\n"
|
"getnewaddress [account]\n"
|
||||||
"Returns a new Anoncoin address for receiving payments. "
|
"Returns a new Gostcoin address for receiving payments. "
|
||||||
"If [account] is specified (recommended), it is added to the address book "
|
"If [account] is specified (recommended), it is added to the address book "
|
||||||
"so payments received with the address will be credited to [account].");
|
"so payments received with the address will be credited to [account].");
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ Value getaccountaddress(const Array& params, bool fHelp)
|
|||||||
if (fHelp || params.size() != 1)
|
if (fHelp || params.size() != 1)
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"getaccountaddress <account>\n"
|
"getaccountaddress <account>\n"
|
||||||
"Returns the current Anoncoin address for receiving payments to this account.");
|
"Returns the current Gostcoin address for receiving payments to this account.");
|
||||||
|
|
||||||
// Parse the account first so we don't generate a key if there's an error
|
// Parse the account first so we don't generate a key if there's an error
|
||||||
string strAccount = AccountFromValue(params[0]);
|
string strAccount = AccountFromValue(params[0]);
|
||||||
@ -188,12 +188,12 @@ Value setaccount(const Array& params, bool fHelp)
|
|||||||
{
|
{
|
||||||
if (fHelp || params.size() < 1 || params.size() > 2)
|
if (fHelp || params.size() < 1 || params.size() > 2)
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"setaccount <anoncoinaddress> <account>\n"
|
"setaccount <gostcoinaddress> <account>\n"
|
||||||
"Sets the account associated with the given address.");
|
"Sets the account associated with the given address.");
|
||||||
|
|
||||||
CBitcoinAddress address(params[0].get_str());
|
CBitcoinAddress address(params[0].get_str());
|
||||||
if (!address.IsValid())
|
if (!address.IsValid())
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Anoncoin address");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Gostcoin address");
|
||||||
|
|
||||||
|
|
||||||
string strAccount;
|
string strAccount;
|
||||||
@ -218,12 +218,12 @@ Value getaccount(const Array& params, bool fHelp)
|
|||||||
{
|
{
|
||||||
if (fHelp || params.size() != 1)
|
if (fHelp || params.size() != 1)
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"getaccount <anoncoinaddress>\n"
|
"getaccount <gostcoinaddress>\n"
|
||||||
"Returns the account associated with the given address.");
|
"Returns the account associated with the given address.");
|
||||||
|
|
||||||
CBitcoinAddress address(params[0].get_str());
|
CBitcoinAddress address(params[0].get_str());
|
||||||
if (!address.IsValid())
|
if (!address.IsValid())
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Anoncoin address");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Gostcoin address");
|
||||||
|
|
||||||
string strAccount;
|
string strAccount;
|
||||||
map<CTxDestination, string>::iterator mi = pwalletMain->mapAddressBook.find(address.Get());
|
map<CTxDestination, string>::iterator mi = pwalletMain->mapAddressBook.find(address.Get());
|
||||||
@ -276,13 +276,13 @@ Value sendtoaddress(const Array& params, bool fHelp)
|
|||||||
{
|
{
|
||||||
if (fHelp || params.size() < 2 || params.size() > 4)
|
if (fHelp || params.size() < 2 || params.size() > 4)
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"sendtoaddress <anoncoinaddress> <amount> [comment] [comment-to]\n"
|
"sendtoaddress <gostcoinaddress> <amount> [comment] [comment-to]\n"
|
||||||
"<amount> is a real and is rounded to the nearest 0.00000001"
|
"<amount> is a real and is rounded to the nearest 0.00000001"
|
||||||
+ HelpRequiringPassphrase());
|
+ HelpRequiringPassphrase());
|
||||||
|
|
||||||
CBitcoinAddress address(params[0].get_str());
|
CBitcoinAddress address(params[0].get_str());
|
||||||
if (!address.IsValid())
|
if (!address.IsValid())
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Anoncoin address");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Gostcoin address");
|
||||||
|
|
||||||
// Amount
|
// Amount
|
||||||
int64 nAmount = AmountFromValue(params[1]);
|
int64 nAmount = AmountFromValue(params[1]);
|
||||||
@ -339,7 +339,7 @@ Value signmessage(const Array& params, bool fHelp)
|
|||||||
{
|
{
|
||||||
if (fHelp || params.size() != 2)
|
if (fHelp || params.size() != 2)
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"signmessage <anoncoinaddress> <message>\n"
|
"signmessage <gostcoinaddress> <message>\n"
|
||||||
"Sign a message with the private key of an address");
|
"Sign a message with the private key of an address");
|
||||||
|
|
||||||
EnsureWalletIsUnlocked();
|
EnsureWalletIsUnlocked();
|
||||||
@ -374,7 +374,7 @@ Value verifymessage(const Array& params, bool fHelp)
|
|||||||
{
|
{
|
||||||
if (fHelp || params.size() != 3)
|
if (fHelp || params.size() != 3)
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"verifymessage <anoncoinaddress> <signature> <message>\n"
|
"verifymessage <gostcoinaddress> <signature> <message>\n"
|
||||||
"Verify a signed message");
|
"Verify a signed message");
|
||||||
|
|
||||||
string strAddress = params[0].get_str();
|
string strAddress = params[0].get_str();
|
||||||
@ -411,14 +411,14 @@ Value getreceivedbyaddress(const Array& params, bool fHelp)
|
|||||||
{
|
{
|
||||||
if (fHelp || params.size() < 1 || params.size() > 2)
|
if (fHelp || params.size() < 1 || params.size() > 2)
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"getreceivedbyaddress <anoncoinaddress> [minconf=1]\n"
|
"getreceivedbyaddress <gostcoinaddress> [minconf=1]\n"
|
||||||
"Returns the total amount received by <anoncoinaddress> in transactions with at least [minconf] confirmations.");
|
"Returns the total amount received by <gostcoinaddress> in transactions with at least [minconf] confirmations.");
|
||||||
|
|
||||||
// Bitcoin address
|
// Bitcoin address
|
||||||
CBitcoinAddress address = CBitcoinAddress(params[0].get_str());
|
CBitcoinAddress address = CBitcoinAddress(params[0].get_str());
|
||||||
CScript scriptPubKey;
|
CScript scriptPubKey;
|
||||||
if (!address.IsValid())
|
if (!address.IsValid())
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Anoncoin address");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Gostcoin address");
|
||||||
scriptPubKey.SetDestination(address.Get());
|
scriptPubKey.SetDestination(address.Get());
|
||||||
if (!IsMine(*pwalletMain,scriptPubKey))
|
if (!IsMine(*pwalletMain,scriptPubKey))
|
||||||
return (double)0.0;
|
return (double)0.0;
|
||||||
@ -632,14 +632,14 @@ Value sendfrom(const Array& params, bool fHelp)
|
|||||||
{
|
{
|
||||||
if (fHelp || params.size() < 3 || params.size() > 6)
|
if (fHelp || params.size() < 3 || params.size() > 6)
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"sendfrom <fromaccount> <toanoncoinaddress> <amount> [minconf=1] [comment] [comment-to]\n"
|
"sendfrom <fromaccount> <togostcoinaddress> <amount> [minconf=1] [comment] [comment-to]\n"
|
||||||
"<amount> is a real and is rounded to the nearest 0.00000001"
|
"<amount> is a real and is rounded to the nearest 0.00000001"
|
||||||
+ HelpRequiringPassphrase());
|
+ HelpRequiringPassphrase());
|
||||||
|
|
||||||
string strAccount = AccountFromValue(params[0]);
|
string strAccount = AccountFromValue(params[0]);
|
||||||
CBitcoinAddress address(params[1].get_str());
|
CBitcoinAddress address(params[1].get_str());
|
||||||
if (!address.IsValid())
|
if (!address.IsValid())
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Anoncoin address");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Gostcoin address");
|
||||||
int64 nAmount = AmountFromValue(params[2]);
|
int64 nAmount = AmountFromValue(params[2]);
|
||||||
int nMinDepth = 1;
|
int nMinDepth = 1;
|
||||||
if (params.size() > 3)
|
if (params.size() > 3)
|
||||||
@ -695,7 +695,7 @@ Value sendmany(const Array& params, bool fHelp)
|
|||||||
{
|
{
|
||||||
CBitcoinAddress address(s.name_);
|
CBitcoinAddress address(s.name_);
|
||||||
if (!address.IsValid())
|
if (!address.IsValid())
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Anoncoin address: ")+s.name_);
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Gostcoin address: ")+s.name_);
|
||||||
|
|
||||||
if (setAddress.count(address))
|
if (setAddress.count(address))
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+s.name_);
|
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+s.name_);
|
||||||
@ -791,7 +791,7 @@ Value addmultisigaddress(const Array& params, bool fHelp)
|
|||||||
{
|
{
|
||||||
string msg = "addmultisigaddress <nrequired> <'[\"key\",\"key\"]'> [account]\n"
|
string msg = "addmultisigaddress <nrequired> <'[\"key\",\"key\"]'> [account]\n"
|
||||||
"Add a nrequired-to-sign multisignature address to the wallet\"\n"
|
"Add a nrequired-to-sign multisignature address to the wallet\"\n"
|
||||||
"each key is a Anoncoin address or hex-encoded public key\n"
|
"each key is a Gostcoin address or hex-encoded public key\n"
|
||||||
"If [account] is specified, assign address to [account].";
|
"If [account] is specified, assign address to [account].";
|
||||||
throw runtime_error(msg);
|
throw runtime_error(msg);
|
||||||
}
|
}
|
||||||
@ -816,7 +816,7 @@ Value createmultisig(const Array& params, bool fHelp)
|
|||||||
string msg = "createmultisig <nrequired> <'[\"key\",\"key\"]'>\n"
|
string msg = "createmultisig <nrequired> <'[\"key\",\"key\"]'>\n"
|
||||||
"Creates a multi-signature address and returns a json object\n"
|
"Creates a multi-signature address and returns a json object\n"
|
||||||
"with keys:\n"
|
"with keys:\n"
|
||||||
"address : anoncoin address\n"
|
"address : gostcoin address\n"
|
||||||
"redeemScript : hex-encoded redemption script";
|
"redeemScript : hex-encoded redemption script";
|
||||||
throw runtime_error(msg);
|
throw runtime_error(msg);
|
||||||
}
|
}
|
||||||
@ -1471,7 +1471,7 @@ Value encryptwallet(const Array& params, bool fHelp)
|
|||||||
// slack space in .dat files; that is bad if the old data is
|
// slack space in .dat files; that is bad if the old data is
|
||||||
// unencrypted private keys. So:
|
// unencrypted private keys. So:
|
||||||
StartShutdown();
|
StartShutdown();
|
||||||
return "wallet encrypted; Anoncoin server stopping, restart to run with encrypted wallet. The keypool has been flushed, you need to make a new backup.";
|
return "wallet encrypted; Gostcoin server stopping, restart to run with encrypted wallet. The keypool has been flushed, you need to make a new backup.";
|
||||||
}
|
}
|
||||||
|
|
||||||
class DescribeAddressVisitor : public boost::static_visitor<Object>
|
class DescribeAddressVisitor : public boost::static_visitor<Object>
|
||||||
@ -1513,8 +1513,8 @@ Value validateaddress(const Array& params, bool fHelp)
|
|||||||
{
|
{
|
||||||
if (fHelp || params.size() != 1)
|
if (fHelp || params.size() != 1)
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"validateaddress <anoncoinaddress>\n"
|
"validateaddress <gostcoinaddress>\n"
|
||||||
"Return information about <anoncoinaddress>.");
|
"Return information about <gostcoinaddress>.");
|
||||||
|
|
||||||
CBitcoinAddress address(params[0].get_str());
|
CBitcoinAddress address(params[0].get_str());
|
||||||
bool isValid = address.IsValid();
|
bool isValid = address.IsValid();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user