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 virtual ~HTTPNodeClient() {}
24
25 virtual 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((char*)ser_res.data(), ser_res.size());
48 LOG_DEBUG_FMT("Request failed: {}", str);
49 }
50
51 return rs == HTTP_STATUS_OK;
52 }
53 };
54}
Definition http_node_client.h:12
virtual bool make_request(::http::Request &request) override
Definition http_node_client.h:25
HTTPNodeClient(std::shared_ptr< ccf::RPCMap > rpc_map, ccf::crypto::KeyPairPtr 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
virtual ~HTTPNodeClient()
Definition http_node_client.h:23
Definition node_client.h:13
ccf::crypto::KeyPairPtr 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:118
std::vector< uint8_t > build_request(bool header_only=false) const
Definition http_builder.h:177
#define LOG_DEBUG_FMT
Definition logger.h:357
std::shared_ptr< KeyPair > KeyPairPtr
Definition key_pair.h:145
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:392