CatapultServer
v0.5.0.1 (Elephant)
|
Go to the documentation of this file.
47 template<
typename TRequestPolicy,
typename TResponseCompatibilityChecker = detail::AlwaysCompatibleResponseCompatibilityChecker>
48 class BriefServerRequestor :
public std::enable_shared_from_this<BriefServerRequestor<TRequestPolicy, TResponseCompatibilityChecker>> {
63 const std::shared_ptr<thread::IoThreadPool>& pPool,
64 const TResponseCompatibilityChecker& compatibilityChecker,
77 NodeRequestResult::Failure_Timeout,
79 pTimedCallback->setTimeout(timeout);
84 m_callback = [pTimedCallback](
auto result,
const auto& response) {
85 pTimedCallback->callback(result, response);
93 <<
"' failed: " << connectCode;
94 complete(NodeRequestResult::Failure_Connection);
99 const auto& response = responseFuture.get();
101 return complete(NodeRequestResult::Failure_Incompatible);
108 complete(NodeRequestResult::Failure_Interaction);
118 m_callback(NodeRequestResult::Success, response);
123 std::shared_ptr<thread::IoThreadPool>
m_pPool;
134 const std::shared_ptr<thread::IoThreadPool>& pPool,
137 const TResponseCompatibilityChecker& responseCompatibilityChecker)
166 auto wrappedCallback = [pThis = this->shared_from_this(), callback](
auto result,
const auto& response) {
167 if (NodeRequestResult::Success == result)
168 ++pThis->m_numSuccessfulRequests;
170 callback(result, response);
175 pRequest->setTimeout(requestTimeout,
pSocket);
177 if (PeerConnectCode::Accepted != connectCode)
178 return pRequest->complete(connectCode);
180 TRequestPolicy::CreateFuture(*pSocket).then([
pSocket, pRequest](
auto&& responseFuture) {
181 pRequest->complete(std::move(responseFuture));
192 std::shared_ptr<thread::IoThreadPool>
m_pPool;
202 template<
typename TRequestor,
typename TResult = std::pair<NodeRequestResult,
typename TRequestor::ResponseType>>
204 auto pPromise = std::make_shared<thread::promise<TResult>>();
206 requestor.beginRequest(node, [pPromise](
auto result,
const auto& response) {
207 pPromise->set_value(std::make_pair(result, response));
210 return pPromise->get_future();
void setTimeout(const utils::TimeSpan &timeout, const std::shared_ptr< ionet::PacketSocket > &pSocket)
Definition: BriefServerRequestor.h:73
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
Definition: BriefServerRequestor.h:59
typename TRequestPolicy::ResponseType ResponseType
Remote node response type.
Definition: BriefServerRequestor.h:51
def debug(*args)
Definition: Parser.py:46
Settings used to configure connections.
Definition: ConnectionSettings.h:31
NodeRequestResult
Enumeration of possible results of a ping operation.
Definition: NodeRequestResult.h:44
PeerConnectCode
Enumeration of possible peer connection codes.
Definition: PeerConnectCode.h:44
A default compatibility checker that indicates all responses are compatible.
Definition: BriefServerRequestor.h:36
def warning(*args)
Definition: colorPrint.py:10
void shutdown()
Shuts down all connections.
Definition: BriefServerRequestor.h:187
std::shared_ptr< ServerConnector > CreateServerConnector(const std::shared_ptr< thread::IoThreadPool > &pPool, const crypto::KeyPair &keyPair, const ConnectionSettings &settings)
Creates a server connector for a server with a key pair of keyPair using pPool and configured with se...
Definition: ServerConnector.cpp:119
size_t numActiveConnections() const
Gets the number of active connections.
Definition: BriefServerRequestor.h:148
TResponseCompatibilityChecker m_compatibilityChecker
Definition: BriefServerRequestor.h:124
Represents a time duration.
Definition: TimeSpan.h:30
size_t numTotalRequests() const
Gets the number of total requests.
Definition: BriefServerRequestor.h:153
std::atomic< size_t > m_numTotalRequests
Definition: BriefServerRequestor.h:197
void complete(NodeRequestResult result)
Definition: BriefServerRequestor.h:113
Definition: BriefServerRequestor.h:48
void complete(const ResponseType &response)
Definition: BriefServerRequestor.h:117
constexpr bool isResponseCompatible(const ionet::Node &, const T &) const
Definition: BriefServerRequestor.h:39
static constexpr auto Friendly_Name
Definition: RemoteNodeApi.cpp:34
void complete(PeerConnectCode connectCode)
Definition: BriefServerRequestor.h:90
auto MakeTimedCallback(boost::asio::io_context &ioContext, TCallback callback, TCallbackArgs &&... timeoutArgs)
Definition: TimedCallback.h:170
Represents a pair of private key with associated public key.
Definition: KeyPair.h:33
std::atomic< size_t > m_numSuccessfulRequests
Definition: BriefServerRequestor.h:198
void beginRequest(const ionet::Node &node, const CallbackType &callback)
Initiates a request for data from node and calls callback on completion.
Definition: BriefServerRequestor.h:164
Provides a way to access the result of an asynchronous operation.
Definition: Future.h:29
utils::TimeSpan m_requestTimeout
Definition: BriefServerRequestor.h:194
void complete(thread::future< ResponseType > &&responseFuture)
Definition: BriefServerRequestor.h:97
std::shared_ptr< thread::IoThreadPool > m_pPool
Definition: BriefServerRequestor.h:192
ionet::Node m_requestNode
Definition: BriefServerRequestor.h:122
CallbackType m_callback
Definition: BriefServerRequestor.h:125
std::shared_ptr< thread::IoThreadPool > m_pPool
Definition: BriefServerRequestor.h:123
TResponseCompatibilityChecker m_responseCompatibilityChecker
Definition: BriefServerRequestor.h:193
NodeRequest(const ionet::Node &requestNode, const std::shared_ptr< thread::IoThreadPool > &pPool, const TResponseCompatibilityChecker &compatibilityChecker, const CallbackType &callback)
Definition: BriefServerRequestor.h:61
SocketPointer pSocket
Definition: PacketWriters.cpp:46
Definition: AddressExtractionExtension.cpp:28
BriefServerRequestor(const std::shared_ptr< thread::IoThreadPool > &pPool, const crypto::KeyPair &keyPair, const ConnectionSettings &settings, const TResponseCompatibilityChecker &responseCompatibilityChecker)
Definition: BriefServerRequestor.h:133
Base class for all catapult exceptions that derives from both std::exception and boost::exception.
Definition: exceptions.h:42
thread::future< TResult > BeginRequestFuture(TRequestor &requestor, const ionet::Node &node)
Initiates a request for data from node using requestor and returns a future.
Definition: BriefServerRequestor.h:203
A node in the catapult network.
Definition: Node.h:82
std::function< void(TArgs...)> consumer
A consumer function.
Definition: functions.h:35
consumer< NodeRequestResult, const ResponseType & > CallbackType
Request completion callback type.
Definition: BriefServerRequestor.h:54
size_t numSuccessfulRequests() const
Gets the number of successful requests.
Definition: BriefServerRequestor.h:158
std::shared_ptr< ServerConnector > m_pConnector
Definition: BriefServerRequestor.h:195