Подписанная PGP ключом ДС Created сделка сначала должна отправляться по bitmessage, затем должна быть отдана МС.

This commit is contained in:
Преподобный Ален
2022-09-12 20:41:28 +03:00
parent fb2e9c5cb5
commit 3b69fc0889
3 changed files with 186 additions and 140 deletions

View File

@@ -55,8 +55,6 @@ namespace Apostol {
m_Status = psStopped; m_Status = psStopped;
CWebService::InitMethods(); CWebService::InitMethods();
InitServerList();
} }
//-------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------

View File

@@ -39,6 +39,9 @@ Author:
#define CONFIG_SECTION_NAME "module" #define CONFIG_SECTION_NAME "module"
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
#define NOT_FOUND_ACTIVE_CONNECTION "Not found active connection. Try again later."
//----------------------------------------------------------------------------------------------------------------------
extern "C++" { extern "C++" {
namespace Apostol { namespace Apostol {
@@ -490,6 +493,57 @@ namespace Apostol {
} }
//-------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------
CWebSocketClient *CWebSocketModule::GetConnectedClient(const CClientContext &Context) {
for (int i = 0; i < Context.ClientManager().Count(); i++) {
auto pClient = Context.ClientManager()[i];
if (pClient->Connected())
return pClient;
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------------------
int CWebSocketModule::CurrentContextIndex(const CString &Params) {
int index = 0;
while (index < m_Servers.Count()) {
const auto &caContext = m_Servers[index].Value();
if (caContext.Status() == Context::csRunning) {
if (Params.IsEmpty() || Params == caContext.URL().Origin()) {
auto pClient = GetConnectedClient(caContext);
if (pClient != nullptr)
return index;
}
}
index++;
}
return -1;
}
//--------------------------------------------------------------------------------------------------------------
CWebSocketClient *CWebSocketModule::GetConnectedClient(const CString &Params) {
int index = 0;
while (index < m_Servers.Count()) {
const auto &caContext = m_Servers[index].Value();
if (caContext.Status() == Context::csRunning) {
if (Params.IsEmpty() || Params == caContext.URL().Origin()) {
auto pClient = GetConnectedClient(caContext);
if (pClient != nullptr)
return pClient;
}
}
index++;
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------------------
void CWebSocketModule::DoClientConnected(CObject *Sender) { void CWebSocketModule::DoClientConnected(CObject *Sender) {
auto pConnection = dynamic_cast<CWebSocketClientConnection *>(Sender); auto pConnection = dynamic_cast<CWebSocketClientConnection *>(Sender);
if (pConnection != nullptr) { if (pConnection != nullptr) {
@@ -835,27 +889,12 @@ namespace Apostol {
if (!sPayload.IsEmpty()) if (!sPayload.IsEmpty())
Json.Object().AddPair("payload", base64_encode(sPayload)); Json.Object().AddPair("payload", base64_encode(sPayload));
int index = 0; auto pClient = GetConnectedClient(caServerParam);
while (index < m_Servers.Count()) {
const auto &Context = m_Servers[index].Value();
if (Context.Status() == Context::csRunning) {
if (caServerParam.IsEmpty()) {
break;
} else {
if (Context.URL().Origin() == caServerParam)
break;
}
}
}
if (index == m_Servers.Count()) { if (pClient == nullptr) {
throw Delphi::Exception::Exception("Not found active connection."); throw Delphi::Exception::Exception(NOT_FOUND_ACTIVE_CONNECTION);
} }
const auto &caContext = m_Servers[index].Value();
auto pClient = caContext.ClientManager().First();
pClient->Send(URI, Json, OnRequest); pClient->Send(URI, Json, OnRequest);
} }
//-------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------
@@ -885,25 +924,19 @@ namespace Apostol {
const auto &caHost = pServerRequest->Headers["host"]; const auto &caHost = pServerRequest->Headers["host"];
const auto &caOrigin = pServerRequest->Headers["origin"]; const auto &caOrigin = pServerRequest->Headers["origin"];
const auto& caUserAddress = pServerRequest->Params["address"];
const auto &address = pServerRequest->Params["address"];
const auto &code = pServerRequest->Params["code"];
const auto &caUserAddress = address.length() == 40 ? CString() : address;
const auto &caDealCode = !code.empty() ? code : address.length() == 40 ? address : CString();
const auto &pgpValue = pServerRequest->Params["pgp"]; const auto &pgpValue = pServerRequest->Params["pgp"];
const auto &caServerParam = pServerRequest->Params["server"]; const auto &caServerParam = pServerRequest->Params["server"];
int index = 0; const auto index = CurrentContextIndex(caServerParam);
while (index < m_Servers.Count()) { if (index == -1) {
const auto &Context = m_Servers[index].Value(); throw Delphi::Exception::Exception(NOT_FOUND_ACTIVE_CONNECTION);
if (Context.Status() == Context::csRunning) {
if (caServerParam.IsEmpty()) {
break;
} else {
if (Context.URL().Origin() == caServerParam)
break;
}
}
}
if (index == m_Servers.Count()) {
throw Delphi::Exception::Exception("Not found active connection.");
} }
const auto &caContext = m_Servers[index].Value(); const auto &caContext = m_Servers[index].Value();
@@ -1251,10 +1284,20 @@ namespace Apostol {
Json.Object().AddPair("module", Module); Json.Object().AddPair("module", Module);
Json.Object().AddPair("address", caUserAddress.IsEmpty() ? caModuleAddress : caUserAddress); Json.Object().AddPair("address", caUserAddress.IsEmpty() ? caModuleAddress : caUserAddress);
if (!caDealCode.IsEmpty()) {
CJSONValue Deal(jvtObject);
Deal.Object().AddPair("code", caDealCode);
Json.Object().AddPair("deal", Deal);
}
if (!sPayload.IsEmpty()) if (!sPayload.IsEmpty())
Json.Object().AddPair("payload", base64_encode(sPayload)); Json.Object().AddPair("payload", base64_encode(sPayload));
auto pClient = caContext.ClientManager().First(); auto pClient = GetConnectedClient(caContext);
if (pClient == nullptr) {
throw Delphi::Exception::Exception(NOT_FOUND_ACTIVE_CONNECTION);
}
pClient->Send(URI, Json, OnRequest); pClient->Send(URI, Json, OnRequest);
} }

View File

@@ -96,6 +96,11 @@ namespace Apostol {
void FetchOAuth2(CContext &Context); void FetchOAuth2(CContext &Context);
static CWebSocketClient *GetConnectedClient(const CClientContext &Context);
int CurrentContextIndex(const CString &Params);
CWebSocketClient *GetConnectedClient(const CString &Params);
protected: protected:
void Heartbeat(CDateTime Now) override; void Heartbeat(CDateTime Now) override;