diff --git a/i2psam/i2psam.h b/i2psam/i2psam.h index e2f85a4..e4a313f 100644 --- a/i2psam/i2psam.h +++ b/i2psam/i2psam.h @@ -372,6 +372,7 @@ public: const std::string& getOptions() const; bool isSick() const; + bool isReady () const { return socket_.isOk() && !isSick (); }; static std::ostream& getLogStream (); static void SetLogFile (const std::string& filename); diff --git a/src/i2p.cpp b/src/i2p.cpp index 00a93fb..2963ee5 100644 --- a/src/i2p.cpp +++ b/src/i2p.cpp @@ -84,7 +84,7 @@ StreamSessionAdapter::~StreamSessionAdapter() SAM::StreamSession::CloseLogFile (); } -void StreamSessionAdapter::StartSession ( +bool StreamSessionAdapter::StartSession ( const std::string& nickname, const std::string& SAMHost /*= SAM_DEFAULT_ADDRESS*/, uint16_t SAMPort /*= SAM_DEFAULT_PORT*/, @@ -96,7 +96,12 @@ void StreamSessionAdapter::StartSession ( std::cout << "Creating SAM session ..." << std::endl; auto s = std::make_shared(nickname, SAMHost, SAMPort, myDestination, i2pOptions, minVer, maxVer); sessionHolder_ = std::make_shared(s); - std::cout << "SAM session created" << std::endl; + bool isReady = s->isReady (); + if (isReady) + std::cout << "SAM session created" << std::endl; + else + std::cout << "SAM session failed" << std::endl; + return isReady; } void StreamSessionAdapter::StopSession () @@ -106,9 +111,9 @@ void StreamSessionAdapter::StopSession () 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_SAM_HOST_PARAM, I2P_SAM_HOST_DEFAULT), (uint16_t)GetArg(I2P_SAM_PORT_PARAM, I2P_SAM_PORT_DEFAULT), diff --git a/src/i2p.h b/src/i2p.h index 4bf99cd..57fa115 100644 --- a/src/i2p.h +++ b/src/i2p.h @@ -37,7 +37,7 @@ public: StreamSessionAdapter(); ~StreamSessionAdapter(); - void Start (); + bool Start (); void Stop (); SAM::SOCKET accept(bool silent); @@ -62,7 +62,7 @@ public: private: - void StartSession( + bool StartSession( const std::string& nickname, const std::string& SAMHost = SAM_DEFAULT_ADDRESS, uint16_t SAMPort = SAM_DEFAULT_PORT, diff --git a/src/init.cpp b/src/init.cpp index e532e84..34e9d32 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -555,7 +555,8 @@ bool AppInit2(boost::thread_group& threadGroup) // if (GetBoolArg("-i2p", false)) // { 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 diff --git a/src/main.cpp b/src/main.cpp index 1805967..ec650fe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -65,7 +65,7 @@ map > mapOrphanTransactionsByPrev; // Constant stuff for coinbase transactions we create: CScript COINBASE_FLAGS; -const string strMessageMagic = "Anoncoin Signed Message:\n"; +const string strMessageMagic = "Gostcoin Signed Message:\n"; double dHashesPerSec = 0.0; int64 nHPSTimerStart = 0; @@ -4665,7 +4665,7 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey) return false; //// 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()); pblock->print(); 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); if (pblock->hashPrevBlock != hashBestChain) - return error("AnoncoinMiner : generated block is stale"); + return error("GostcoinMiner : generated block is stale"); // Remove key from key pool 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 CValidationState state; if (!ProcessBlock(state, NULL, pblock)) - return error("AnoncoinMiner : ProcessBlock, block not accepted"); + return error("GostcoinMiner : ProcessBlock, block not accepted"); } return true; diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 361d72d..6ada37c 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -103,7 +103,7 @@ Value getnewaddress(const Array& params, bool fHelp) if (fHelp || params.size() > 1) throw runtime_error( "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 " "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) throw runtime_error( "getaccountaddress \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 string strAccount = AccountFromValue(params[0]); @@ -188,12 +188,12 @@ Value setaccount(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( - "setaccount \n" + "setaccount \n" "Sets the account associated with the given address."); CBitcoinAddress address(params[0].get_str()); 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; @@ -218,12 +218,12 @@ Value getaccount(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "getaccount \n" + "getaccount \n" "Returns the account associated with the given address."); CBitcoinAddress address(params[0].get_str()); 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; map::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) throw runtime_error( - "sendtoaddress [comment] [comment-to]\n" + "sendtoaddress [comment] [comment-to]\n" " is a real and is rounded to the nearest 0.00000001" + HelpRequiringPassphrase()); CBitcoinAddress address(params[0].get_str()); if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Anoncoin address"); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Gostcoin address"); // Amount int64 nAmount = AmountFromValue(params[1]); @@ -339,7 +339,7 @@ Value signmessage(const Array& params, bool fHelp) { if (fHelp || params.size() != 2) throw runtime_error( - "signmessage \n" + "signmessage \n" "Sign a message with the private key of an address"); EnsureWalletIsUnlocked(); @@ -374,7 +374,7 @@ Value verifymessage(const Array& params, bool fHelp) { if (fHelp || params.size() != 3) throw runtime_error( - "verifymessage \n" + "verifymessage \n" "Verify a signed message"); 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) throw runtime_error( - "getreceivedbyaddress [minconf=1]\n" - "Returns the total amount received by in transactions with at least [minconf] confirmations."); + "getreceivedbyaddress [minconf=1]\n" + "Returns the total amount received by in transactions with at least [minconf] confirmations."); // Bitcoin address CBitcoinAddress address = CBitcoinAddress(params[0].get_str()); CScript scriptPubKey; 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()); if (!IsMine(*pwalletMain,scriptPubKey)) return (double)0.0; @@ -632,14 +632,14 @@ Value sendfrom(const Array& params, bool fHelp) { if (fHelp || params.size() < 3 || params.size() > 6) throw runtime_error( - "sendfrom [minconf=1] [comment] [comment-to]\n" + "sendfrom [minconf=1] [comment] [comment-to]\n" " is a real and is rounded to the nearest 0.00000001" + HelpRequiringPassphrase()); string strAccount = AccountFromValue(params[0]); CBitcoinAddress address(params[1].get_str()); 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]); int nMinDepth = 1; if (params.size() > 3) @@ -695,7 +695,7 @@ Value sendmany(const Array& params, bool fHelp) { CBitcoinAddress address(s.name_); 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)) 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 <'[\"key\",\"key\"]'> [account]\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]."; throw runtime_error(msg); } @@ -816,7 +816,7 @@ Value createmultisig(const Array& params, bool fHelp) string msg = "createmultisig <'[\"key\",\"key\"]'>\n" "Creates a multi-signature address and returns a json object\n" "with keys:\n" - "address : anoncoin address\n" + "address : gostcoin address\n" "redeemScript : hex-encoded redemption script"; 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 // unencrypted private keys. So: 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 @@ -1513,8 +1513,8 @@ Value validateaddress(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "validateaddress \n" - "Return information about ."); + "validateaddress \n" + "Return information about ."); CBitcoinAddress address(params[0].get_str()); bool isValid = address.IsValid();