CCF
Loading...
Searching...
No Matches
http_node_client.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include "node/node_client.h"
6
7#include <chrono>
8
9namespace ccf
10{
12 {
13 public:
15 std::shared_ptr<ccf::RPCMap> rpc_map,
17 const ccf::crypto::Pem& self_signed_node_cert_,
18 const std::optional<ccf::crypto::Pem>& endorsed_node_cert_) :
20 rpc_map, node_sign_kp, self_signed_node_cert_, endorsed_node_cert_)
21 {}
22
23 ~HTTPNodeClient() override = default;
24
25 bool make_request(::http::Request& request) override
26 {
27 const auto& node_cert = endorsed_node_cert.has_value() ?
28 endorsed_node_cert.value() :
30
31 std::vector<uint8_t> packed = request.build_request();
32
33 auto node_session = std::make_shared<ccf::SessionContext>(
34 ccf::InvalidSessionId, node_cert.raw());
35 auto ctx = ccf::make_rpc_context(node_session, packed);
36
37 std::shared_ptr<ccf::RpcHandler> search =
38 ::http::fetch_rpc_handler(ctx, rpc_map);
39
40 search->process(ctx);
41
42 auto rs = ctx->get_response_status();
43
44 if (rs != HTTP_STATUS_OK)
45 {
46 auto ser_res = ctx->serialise_response();
47 std::string str(
48 reinterpret_cast<char*>(ser_res.data()), ser_res.size());
49 LOG_DEBUG_FMT("Request failed: {}", str);
50 }
51
52 return rs == HTTP_STATUS_OK;
53 }
54 };
55}
Definition http_node_client.h:12
HTTPNodeClient(std::shared_ptr< ccf::RPCMap > rpc_map, ccf::crypto::ECKeyPairPtr node_sign_kp, const ccf::crypto::Pem &self_signed_node_cert_, const std::optional< ccf::crypto::Pem > &endorsed_node_cert_)
Definition http_node_client.h:14
~HTTPNodeClient() override=default
bool make_request(::http::Request &request) override
Definition http_node_client.h:25
Definition node_client.h:13
ccf::crypto::ECKeyPairPtr node_sign_kp
Definition node_client.h:16
const ccf::crypto::Pem & self_signed_node_cert
Definition node_client.h:17
std::shared_ptr< ccf::RPCMap > rpc_map
Definition node_client.h:15
const std::optional< ccf::crypto::Pem > & endorsed_node_cert
Definition node_client.h:18
Definition pem.h:18
Definition http_builder.h:117
std::vector< uint8_t > build_request(bool header_only=false) const
Definition http_builder.h:175
#define LOG_DEBUG_FMT
Definition internal_logger.h:14
std::shared_ptr< ECKeyPair > ECKeyPairPtr
Definition ec_key_pair.h:144
Definition app_interface.h:14
std::shared_ptr<::http::HttpRpcContext > make_rpc_context(std::shared_ptr< ccf::SessionContext > s, const std::vector< uint8_t > &packed)
Definition http_rpc_context.h:374