139 #include "Helpers.hpp"
169 #include <irrxml/irrXML.hpp>
181 #define SERVER_CONFIG_KEY "server"
182 #define SERVER_DATA_DIR "server_data"
183 #define SERVER_LOGFILE_FILENAME "log-server.log"
184 #define SERVER_PASSWORD_FOLDER ""
185 #define SERVER_PID_FILENAME "ot.pid"
193 void askInteractively(std::string& strContract, std::string& strServerID,
194 std::string& strCert, std::string& strNymID,
195 std::string& strCachedKey)
197 const char* szInstructions =
198 "\n\n ==> WARNING: Main file not found. To create it, continue this "
200 "REQUIREMENTS: You must already have a wallet, where you have created "
202 "This will be a temporary wallet only, for the purpose of generating "
204 "nym and the master key for that server nym. You can erase the "
206 "~/.ot/client_data folder once we are done with this process, and the "
208 "will just create a fresh wallet to replace it. In other words, don't "
210 "to use the temporary wallet as a REAL wallet, since it contains the "
212 "key and private key for your new server nym. We're using a temporary "
214 "wallet for the convenience of generating the server nym--we'll copy "
216 "the server side, and then we'll wipe the temp wallet and start with a "
218 "once this process is done.\n"
219 "(FYI, you can decode an armored wallet by using the 'opentxs decode' "
221 "-- You must also have the new Server Nym's \"NymID\", which should be "
222 "found in the\nwallet.\n"
223 "-- When you have created your server Nym (using your temp wallet) you "
225 "copy the credentials from the temp wallet to your new server:\n"
226 " cp -R ~/.ot/client_data/credentials ~/.ot/server_data/ \n"
227 "-- You must already have a signed server contract. (*** To get one, "
229 "UNSIGNED version of the sample server contract, which is named "
231 "and then change the tags as you see fit. Then use the same Nym, the "
233 "to sign the server contract, via the 'opentxs newserver' "
235 "You must also have the server ID for the above contract, which the "
237 "command will output at the same time it outputs the newly-signed "
239 "=> Note that the Nym who signs the server contract MUST be the same "
241 "provide HERE, for this process now...)\n"
242 "-- Finally, you must provide the cached key from the same wallet "
243 "where you brought\n"
244 "the Nym from (In this case, be careful to only copy the "
245 "base64-encoded portion\n"
246 "of the cached key from the wallet, and not the XML tags around it!) "
248 "recommend you create a blank wallet entirely for this purpose (of "
250 "that cached key and server Nym, to be used for your new OT server.) "
251 "Then erase it\nonce this process is done.\n"
252 " ==> WARNING: Main file not found. To create it, continue this "
256 OTLog::Output(0,
"Enter the ServerID for your server contract: ");
258 OTLog::Output(0,
"Enter the Server User ID (the NymID of the Nym who "
259 "signed the server contract): ");
261 OTLog::Output(0,
"Paste the cached key (ONLY the base64-encoded portion) "
262 "below, from wallet.xml for that Nym.\n"
263 "Terminate with '~' on a line by itself.\n\n");
266 OTLog::Output(0,
"Paste the contents of the server Nym's certfile, "
267 "including public/PRIVATE, below.\n"
268 "NOTE: LEAVE THIS BLANK unless you REALLY want to use the "
269 "OLD system. If you leave this\n"
270 "blank (preferred), it will instead use the new "
271 "credentials system. (Just make sure\n"
272 "you copied over the \"credentials\" folder, as described "
273 "above, since we're about to\n"
274 "use it, if you leave this blank.)\n"
275 "Terminate with '~' on a line by itself.\n\n");
279 OTLog::Output(0,
"Paste the complete, signed, server contract below. (You "
280 "must already have it.)\n"
281 "Terminate with '~' on a line by itself.\n\n");
289 int32_t OTCron::__trans_refill_amount =
292 int32_t OTCron::__cron_ms_between_process = 10000;
295 int32_t OTCron::__cron_max_items_per_nym = 10;
315 bool bAddedNumbers =
false;
321 int64_t lTransNum = 0;
323 m_nymServer, lTransNum,
false);
327 bAddedNumbers =
true;
352 return m_bShutdownFlag;
359 , userCommandProcessor_(this)
361 , m_bShutdownFlag(false)
362 , m_pServerContract()
379 if (!m_bReadOnly && bGetDataFolderSuccess) {
383 std::ofstream pid_outfile(strPIDPath.
Get());
385 if (pid_outfile.is_open()) {
386 uint32_t the_pid = 0;
387 pid_outfile << the_pid;
391 OTLog::vError(
"Failed trying to open data locking file (to wipe "
392 "PID back to 0): %s\n",
399 m_bReadOnly = readOnly;
415 if (bGetDataFolderSuccess) {
433 std::ifstream pid_infile(strPIDPath.
Get());
436 if (pid_infile.is_open()) {
437 uint32_t old_pid = 0;
438 pid_infile >> old_pid;
443 uint64_t lPID = old_pid;
445 "\n\n\nIS OPEN-TRANSACTIONS ALREADY RUNNING?\n\n"
446 "I found a PID (%llu) in the data lock file, located "
448 "If the OT process with PID %llu is truly not running "
450 "then just ERASE THAT FILE and then RESTART.\n",
451 lPID, strPIDPath.
Get(), lPID);
462 uint64_t the_pid = 0;
465 the_pid = GetCurrentProcessId();
471 std::ofstream pid_outfile(strPIDPath.
Get());
473 if (pid_outfile.is_open()) {
474 pid_outfile << the_pid;
479 "store PID %llu): %s\n",
480 the_pid, strPIDPath.
Get());
487 bool mainFileExists = m_strWalletFilename.
Exists()
491 if (!mainFileExists) {
494 "Error: Main file non-existent (%s). "
495 "Plus, unable to create, since read-only flag is set.\n",
496 m_strWalletFilename.
Get());
500 std::string strContract;
501 std::string strServerID;
503 std::string strNymID;
504 std::string strCachedKey;
505 askInteractively(strContract, strServerID, strCert, strNymID,
508 strContract, strServerID, strCert, strNymID, strCachedKey);
512 if (mainFileExists) {
530 bool OTServer::SendInstrumentToNym(
540 const char* szCommand)
543 !((
nullptr == pMsg) && (
nullptr == pPayment)),
544 "pMsg and pPayment -- these can't BOTH be nullptr.\n");
548 !((
nullptr != pMsg) && (
nullptr != pPayment)),
549 "pMsg and pPayment -- these can't BOTH be not-nullptr.\n");
553 ((
nullptr != pPayment) && pPayment->
IsValid()),
554 "OTServer::SendInstrumentToNym: You can only pass a valid "
560 if (
nullptr != pPayment) {
561 const bool bGotPaymentContents =
563 if (!bGotPaymentContents)
564 OTLog::vError(
"%s: Error GetPaymentContents Failed", __FUNCTION__);
566 const bool bDropped = DropMessageToNymbox(
567 SERVER_ID, SENDER_USER_ID, RECIPIENT_USER_ID,
569 (
nullptr != pMsg) ?
nullptr : &strPayment, szCommand);
635 bool OTServer::DropMessageToNymbox(
const OTIdentifier& SERVER_ID,
636 const OTIdentifier& SENDER_USER_ID,
637 const OTIdentifier& RECIPIENT_USER_ID,
639 OTMessage* pMsg,
const OTString* pstrMessage,
640 const char* szCommand)
646 !((
nullptr == pMsg) && (
nullptr == pstrMessage)),
647 "pMsg and pstrMessage -- these can't BOTH be nullptr.\n");
652 !((
nullptr != pMsg) && (
nullptr != pstrMessage)),
653 "pMsg and pstrMessage -- these can't BOTH be not-nullptr.\n");
656 const char* szFunc =
"OTServer::DropMessageToNymbox";
657 int64_t lTransNum = 0;
658 const bool bGotNextTransNum =
661 if (!bGotNextTransNum) {
663 "%s: Error: failed trying to get next transaction number.\n");
673 "%s: Unexpected transactionType passed here (expected message "
674 "or instrumentNotice.)\n",
681 std::unique_ptr<OTMessage> theMsgAngel;
685 pMsg =
new OTMessage;
686 theMsgAngel.reset(pMsg);
687 if (
nullptr != szCommand)
688 pMsg->m_strCommand = szCommand;
692 pMsg->m_strCommand =
"sendUserMessage";
695 pMsg->m_strCommand =
"sendUserInstrument";
701 pMsg->m_strServerID = m_strServerID;
702 pMsg->m_bSuccess =
true;
703 SENDER_USER_ID.GetString(pMsg->m_strNymID);
704 RECIPIENT_USER_ID.GetString(pMsg->m_strNymID2);
710 OTPseudonym nymRecipient(RECIPIENT_USER_ID);
713 nymRecipient.LoadPublicKey();
720 "%s: Failed trying to load public key for recipient.\n",
724 else if (!nymRecipient.VerifyPseudonym()) {
725 OTLog::vError(
"%s: Failed trying to verify Nym for recipient.\n",
729 const OTAsymmetricKey& thePubkey = nymRecipient.GetPublicEncrKey();
732 OTEnvelope theEnvelope;
734 pMsg->m_ascPayload.Release();
736 if ((
nullptr != pstrMessage) && pstrMessage->Exists() &&
737 theEnvelope.Seal(thePubkey, *pstrMessage) &&
741 theEnvelope.GetAsciiArmoredData(
746 pMsg->SignContract(m_nymServer);
747 pMsg->SaveContract();
751 "%s: Failed trying to seal envelope containing message "
752 "(or while grabbing the base64-encoded result.)\n",
769 const OTString strInMessage(*pMsg);
770 OTLedger theLedger(RECIPIENT_USER_ID, RECIPIENT_USER_ID,
773 if ((theLedger.LoadNymbox() &&
777 theLedger.VerifyContractID() &&
779 theLedger.VerifySignature(m_nymServer))) {
781 OTTransaction* pTransaction =
784 if (
nullptr != pTransaction)
794 pTransaction->SetReferenceToNum(lTransNum);
800 pTransaction->SetReferenceString(
805 pTransaction->SignContract(m_nymServer);
806 pTransaction->SaveContract();
807 theLedger.AddTransaction(*pTransaction);
812 theLedger.ReleaseSignatures();
813 theLedger.SignContract(m_nymServer);
814 theLedger.SaveContract();
815 theLedger.SaveNymbox();
827 pTransaction->SaveBoxReceipt(theLedger);
833 const OTString strRecipientUserID(RECIPIENT_USER_ID);
835 "%s: Failed while trying to generate transaction in order to "
836 "add a message to Nymbox: %s\n",
837 szFunc, strRecipientUserID.Get());
841 const OTString strRecipientUserID(RECIPIENT_USER_ID);
842 OTLog::vError(
"%s: Failed while trying to load or verify Nymbox: %s\n",
843 szFunc, strRecipientUserID.Get());
851 if (!m_pServerContract)
return false;
853 return m_pServerContract->GetConnectInfo(strHostname, nPort);
static EXPORT void vError(const char *szError,...)
EXPORT void AddTransactionNumber(const int64_t &lTransactionNum)
#define SERVER_PID_FILENAME
static EXPORT OTTransaction * GenerateTransaction(const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID, transactionType theType, int64_t lTransactionNum=0)
static EXPORT void Output(int32_t nVerbosity, const char *szOutput)
bool IsFlaggedForShutdown() const
bool issueNextTransactionNumber(OTPseudonym &nym, int64_t &txNumber, bool storeNumber=true)
#define OTDB_DEFAULT_PACKER
EXPORT bool InitDefaultStorage(StorageType eStoreType, PackType ePackType)
bool GetConnectInfo(OTString &hostname, int32_t &port) const
static EXPORT bool IsInitialized()
EXPORT bool Exists() const
static bool load(OTString &walletFilename)
bool LoadMainFile(bool readOnly=false)
EXPORT void Init(bool readOnly=false)
EXPORT void ActivateCron()
EXPORT bool GetPaymentContents(OTString &strOutput) const
EXPORT void ProcessCronItems()
const OTPseudonym & GetServerNym() const
EXPORT std::string OT_CLI_ReadLine()
#define OT_ASSERT_MSG(x, s)
EXPORT const char * Get() const
EXPORT bool IsValid() const
EXPORT int32_t GetTransactionCount() const
static int32_t GetCronRefillAmount()
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
bool CreateMainFile(const std::string &strContract, const std::string &strServerID, const std::string &strCert, const std::string &strNymID, const std::string &strCachedKey)
#define OTDB_DEFAULT_STORAGE
static EXPORT bool AppendFile(OTString &out_strPath, const OTString &strBasePath, const OTString &strFileName)
EXPORT std::string OT_CLI_ReadUntilEOF()
static EXPORT void vOutput(int32_t nVerbosity, const char *szOutput,...)
static EXPORT OTString Get()