Github user achristianson commented on a diff in the pull request:
https://github.com/apache/nifi-minifi-cpp/pull/158#discussion_r147858619
--- Diff: extensions/http-curl/sitetosite/HTTPProtocol.h ---
@@ -0,0 +1,197 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __SITE2SITE_CLIENT_PROTOCOL_H__
+#define __SITE2SITE_CLIENT_PROTOCOL_H__
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <string>
+#include <errno.h>
+#include <chrono>
+#include <set>
+#include <thread>
+#include <algorithm>
+#include <uuid/uuid.h>
+#include "HTTPTransaction.h"
+#include "sitetosite/SiteToSite.h"
+#include "sitetosite/SiteToSiteClient.h"
+#include "core/Property.h"
+#include "properties/Configure.h"
+#include "FlowFileRecord.h"
+#include "core/logging/LoggerConfiguration.h"
+#include "core/ProcessContext.h"
+#include "core/ProcessSession.h"
+#include "io/CRCStream.h"
+#include "sitetosite/Peer.h"
+#include "utils/Id.h"
+#include "../client/HTTPClient.h"
+
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace sitetosite {
+
+/**
+ * Site2Site Peer
+ */
+typedef struct Site2SitePeerStatus {
+ std::string host_;
+ int port_;bool isSecure_;
+} Site2SitePeerStatus;
+
+// HttpSiteToSiteClient Class
+class HttpSiteToSiteClient : public sitetosite::SiteToSiteClient {
+
+ static constexpr char const* PROTOCOL_VERSION_HEADER =
"x-nifi-site-to-site-protocol-version";
+ public:
+
+ /*!
+ * Create a new http protocol
+ */
+ HttpSiteToSiteClient(std::string name, uuid_t uuid = 0)
+ : SiteToSiteClient(),
+ current_code(UNRECOGNIZED_RESPONSE_CODE),
+ logger_(logging::LoggerFactory<HttpSiteToSiteClient>::getLogger())
{
+ peer_state_ = READY;
+ }
+
+ /*!
+ * Create a new http protocol
+ */
+ HttpSiteToSiteClient(std::unique_ptr<SiteToSitePeer> peer)
+ : SiteToSiteClient(),
+ current_code(UNRECOGNIZED_RESPONSE_CODE),
+ logger_(logging::LoggerFactory<HttpSiteToSiteClient>::getLogger())
{
+ peer_ = std::move(peer);
+ peer_state_ = READY;
+ }
+ // Destructor
+ virtual ~HttpSiteToSiteClient() {
+
+ }
+
+ void setPeer(std::unique_ptr<SiteToSitePeer> peer) {
+ peer_ = std::move(peer);
+ }
+
+ virtual bool getPeerList(std::vector<PeerStatus> &peers);
+
+ /**
+ * Establish the protocol connection. Not needed for the HTTP
connection, so we simply
+ * return true.
+ */
+ virtual bool establish() {
+ return true;
+ }
+
+ virtual std::shared_ptr<Transaction> createTransaction(std::string
&transactionID, TransferDirection direction);
+
+ // Transfer flow files for the process session
+ //virtual bool transferFlowFiles(const
std::shared_ptr<core::ProcessContext> &context, const
std::shared_ptr<core::ProcessSession> &session);
+ //! Transfer string for the process session
+ virtual bool transmitPayload(const std::shared_ptr<core::ProcessContext>
&context, const std::shared_ptr<core::ProcessSession> &session, const
std::string &payload,
+ std::map<std::string, std::string>
attributes);
+ // deleteTransaction
+ void deleteTransaction(std::string transactionID);
+
+ protected:
+
+ /**
+ * Closes the transaction
+ * @param transactionID transaction id reference.
+ */
+ void closeTransaction(const std::string &transactionID);
+
+ virtual int readRespond(const std::shared_ptr<Transaction> &transaction,
RespondCode &code, std::string &message);
+ // write respond
+ virtual int writeRespond(const std::shared_ptr<Transaction>
&transaction, RespondCode code, std::string message);
+
+ /**
+ * Bootstrapping is not really required for the HTTP Site To Site so we
will set the peer state and return true.
+ */
+ virtual bool bootstrap() {
+ peer_state_ = READY;
+ return true;
+ }
+
+ /**
+ * Creates a connection for sending, returning an HTTP client that is
structured and configured
+ * to receive flow files.
+ * @param transaction transaction against which we are performing our
sends
+ * @return HTTP Client shared pointer.
+ */
+ std::shared_ptr<minifi::utils::HTTPClient>
openConnectionForSending(const std::shared_ptr<HttpTransaction> &transaction);
+
+ /**
+ * Creates a connection for receiving, returning an HTTP client that is
structured and configured
+ * to receive flow files.
+ * @param transaction transaction against which we are performing our
reads
+ * @return HTTP Client shared pointer.
+ */
+ std::shared_ptr<minifi::utils::HTTPClient>
openConnectionForReceive(const std::shared_ptr<HttpTransaction> &transaction);
+
+ const std::string getBaseURI() {
+ std::string uri = "http://";
+ uri.append(peer_->getHostName());
+ uri.append(":");
+ uri.append(std::to_string(peer_->getPort()));
+ uri.append("/nifi-api/");
+ return uri;
+ }
+
+ virtual void tearDown();
+
+ const std::string parseTransactionId(const std::string &uri);
+
+ std::unique_ptr<utils::HTTPClient> create_http_client(const std::string
&uri, const std::string method = "POST", bool setPropertyHeaders = false) {
--- End diff --
Make method a reference?
---