Jan_31_2024-Dev

This commit is contained in:
Ned Wright
2024-01-31 17:34:53 +00:00
parent 752a5785f0
commit 6d67818a94
376 changed files with 8101 additions and 7064 deletions

View File

@@ -1,95 +0,0 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (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 __HTTP_ENCODER_H__
#define __HTTP_ENCODER_H__
#include <string>
#include "messaging/http_core.h"
class HTTPRequest
{
public:
HTTPRequest() = default;
HTTPRequest(const std::string &_method_statement);
HTTPRequest(const std::string &_method_statement, const std::string &_host, const bool to_proxy);
HTTPRequest & insertHeader(const std::string &header_key, const std::string &header_val);
HTTPRequest & insertHeader(const std::string &header);
HTTPRequest & insertHeaders(const std::string &rec_headers);
HTTPRequest & insertBody(const std::string &body);
std::string toString() const;
private:
std::string method_statement;
HTTPHeaders headers;
std::string body;
};
class ConnectRequest: public HTTPRequest
{
public:
ConnectRequest(const std::string &_host, const std::string &_port);
};
class PostRequest: public HTTPRequest
{
public:
PostRequest(const std::string &_post_path, const std::string &_host, bool to_proxy);
};
class PutRequest : public HTTPRequest
{
public:
PutRequest(const std::string &_put_path, const std::string &_host, bool to_proxy);
};
class GetRequest: public HTTPRequest
{
public:
GetRequest(const std::string &_get_path, const std::string &_host, bool to_proxy);
};
class PatchRequest: public HTTPRequest
{
public:
PatchRequest(const std::string &_patch_path, const std::string &_host, bool to_proxy);
};
class HTTPEncoder
{
public:
HTTPEncoder(const std::string &_host, const std::string &_port);
HTTPRequest & Connect();
HTTPRequest & Post(const std::string &post_path);
HTTPRequest & Put(const std::string &put_path);
HTTPRequest & Patch(const std::string &patch_path);
HTTPRequest & Get(const std::string &get_path);
HTTPEncoder & isOverProxy();
HTTPEncoder & isOverSSL();
std::string build() const { return request.toString(); }
private:
HTTPRequest request;
std::string host;
std::string port;
bool over_ssl = false;
bool over_proxy = false;
};
#endif // __HTTP_ENCODER_H__

0
core/include/internal/ioctl_is.h Executable file → Normal file
View File

0
core/include/internal/mainloop/mainloop_metric.h Executable file → Normal file
View File

View File

@@ -11,44 +11,43 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __PROTO_MESSAGE_COMP_H__
#define __PROTO_MESSAGE_COMP_H__
#ifndef __MESSAGING_H__
#define __MESSAGING_H__
#include <memory>
#include <string>
#include "singleton.h"
#include "i_mainloop.h"
#include "i_encryptor.h"
#include "i_messaging.h"
#include "i_agent_details.h"
#include "i_environment.h"
#include "i_rest_api.h"
#include "i_messaging_buffer.h"
#include "i_shell_cmd.h"
#include "i_proxy_configuration.h"
#include "component.h"
class ProtoMessageComp
#include "component.h"
#include "singleton.h"
#include "i_environment.h"
#include "i_proxy_configuration.h"
#include "i_agent_details.h"
#include "i_mainloop.h"
#include "i_time_get.h"
#include "i_encryptor.h"
#include "i_shell_cmd.h"
#include "i_instance_awareness.h"
#include "config.h"
class Messaging
:
public Component,
Singleton::Provide<I_Messaging>,
Singleton::Consume<I_MainLoop>,
Singleton::Consume<I_TimeGet>,
Singleton::Consume<I_AgentDetails>,
Singleton::Consume<I_Encryptor>,
Singleton::Consume<I_ProxyConfiguration>,
Singleton::Consume<I_Environment>,
Singleton::Consume<I_MessagingBuffer>,
Singleton::Consume<I_Encryptor>,
Singleton::Consume<I_AgentDetails>,
Singleton::Consume<I_TimeGet>,
Singleton::Consume<I_ShellCmd>,
Singleton::Consume<I_ProxyConfiguration>
Singleton::Consume<I_MainLoop>,
Singleton::Consume<I_InstanceAwareness>
{
public:
ProtoMessageComp();
~ProtoMessageComp();
Messaging();
~Messaging();
void init();
void fini();
void preload();
private:
@@ -56,4 +55,4 @@ private:
std::unique_ptr<Impl> pimpl;
};
#endif // __PROTO_MESSAGE_COMP_H__
#endif // __MESSAGING_H__

View File

@@ -1,52 +0,0 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (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 __MESSAGING_BUFFER_H__
#define __MESSAGING_BUFFER_H__
#include <memory>
#include "i_messaging_buffer.h"
#include "i_time_get.h"
#include "i_instance_awareness.h"
#include "singleton.h"
#include "i_encryptor.h"
#include "i_environment.h"
#include "i_mainloop.h"
#include "component.h"
class MessagingBuffer
:
public Component,
Singleton::Provide<I_MessagingBuffer>,
Singleton::Consume<I_TimeGet>,
Singleton::Consume<I_InstanceAwareness>,
Singleton::Consume<I_Encryptor>,
Singleton::Consume<I_Environment>,
Singleton::Consume<I_MainLoop>
{
public:
MessagingBuffer();
~MessagingBuffer();
void preload();
void init();
void fini();
private:
class Impl;
std::unique_ptr<Impl> pimpl;
};
#endif // __MESSAGING_BUFFER_H__

View File

@@ -1,58 +0,0 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (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 __BUCKET_MANAGER_H__
#define __BUCKET_MANAGER_H__
#include <unordered_map>
#include <iterator>
#include <string>
#include "event_queue.h"
#include "instance_awareness.h"
#include "i_time_get.h"
#include "i_encryptor.h"
using bucketName = std::string;
class BucketManager
{
public:
void init(const std::string &service_name);
void fini();
bool doesExist(const bucketName &);
void push(const bucketName &, std::string &&);
bool handleNextBucket();
bool hasValue();
EventQueue & peek();
void flush();
private:
std::string resolveFilesName(const std::string &file_name);
std::string buffer_directory = "";
std::string next_bucket = "";
std::string service_name = "";
std::string management_file_path = "";
uint buffer_max_size = 0; // in MB
uint max_buffer_files = 0;
EventQueue iterator;
std::unordered_map<bucketName, EventQueue> buckets;
I_InstanceAwareness *instance_awareness = nullptr;
I_Encryptor *encryptor = nullptr;
};
#endif // __BUCKET_MANAGER_H__

View File

@@ -1,125 +0,0 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (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 __EVENT_QUEUE_H__
#define __EVENT_QUEUE_H__
#include <boost/range/iterator_range.hpp>
#include <cstring>
#include <iostream>
#include <fstream>
#include <memory>
#include <list>
#include <chrono>
#include "i_time_get.h"
#include "maybe_res.h"
USE_DEBUG_FLAG(D_EVENT_BUFFER);
class EventQueueFile
{
public:
EventQueueFile(const std::string &_file_path)
:
file_path(_file_path)
{}
EventQueueFile(
const std::string &file_location_path,
const std::string &file_extention,
bool is_file_compressed);
EventQueueFile(const EventQueueFile &other_event, int _num_of_events_in_file, uint64_t _size_of_file)
:
file_path(other_event.file_path),
suffix(other_event.suffix),
num_of_events_in_file(_num_of_events_in_file),
size_of_file(_size_of_file)
{}
static const std::string zip_file_suffix;
const std::string & getFilePath() const { return file_path; }
bool isCompressed() const { return is_compressed; }
int getSuffix() const { return suffix; }
int getNumOfEvents() const { return num_of_events_in_file; }
uint64_t getFileSizeInBytes() const { return size_of_file; }
void restoreNumberOfLines();
void incFileSize(uint64_t size_to_add);
void handleCompression(int size_of_files_list);
void decompress(const std::string &infilename, const std::string &outfilename, bool remove_old = true);
void compress();
private:
std::string file_path;
int suffix = -1;
bool is_compressed = false;
int num_of_events_in_file = 0;
size_t size_of_file = 0;
};
class EventQueue
{
public:
EventQueue() = default;
~EventQueue();
void init(const std::string &path, uint max_buff_size);
void fini();
bool isEmpty() const;
const std::string & peek();
void push(std::string &&event_data);
void reloadEventsIntoList(const std::string &path);
Maybe<void> refreshBufferFile();
void refreshReadBuff();
void trim();
void flush();
private:
void rotate();
void updateReadFile();
void setReaderFileAndOpen(const EventQueueFile &file);
void sortEventFilesBySuffix(std::vector<EventQueueFile> &tmp_vec);
void pushNewEventQueueFile(EventQueueFile &eventFile, std::vector<EventQueueFile> &tmp_vec);
double getSizeMB(double size_in_B) const;
Maybe<void> writeCachesToFile();
void enforceMaxNumberOfFiles();
// File management
std::list<EventQueueFile> files; //front is write, back is read
std::ifstream reader;
std::ofstream writer;
// Read & write management
double max_size; // in MB
uint64_t size_on_disk; // in B
uint64_t write_cache_size; // in B
uint64_t read_cache_size; // in B
std::list<std::string> write_cache_buff;
std::list<std::string> read_cache_buff;
unsigned int num_of_events_on_disk;
unsigned int read_events_on_disk;
// Timing management
std::chrono::microseconds next_sync_freq_in_sec;
I_TimeGet *timer = nullptr;
bool is_pending_rotate = false;
bool is_pending_write = false;
};
#endif // __EVENT_QUEUE_H__

View File

@@ -1,120 +0,0 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (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 __HTTP_REQUEST_EVENT_H__
#define __HTTP_REQUEST_EVENT_H__
#include <string>
#include "cereal/archives/json.hpp"
class HTTPRequestSignature
{
public:
HTTPRequestSignature() = default;
HTTPRequestSignature(const std::string &_method, const std::string &_url, const std::string &_tag)
:
method(_method),
url(_url),
tag(_tag)
{
}
bool
operator<(const HTTPRequestSignature &other) const
{
return getSignature() < other.getSignature();
}
std::string getSignature() const { return method + url + tag; }
const std::string & getMethod() const { return method; }
const std::string & getURL() const { return url; }
const std::string & getTag() const { return tag; }
template<class Archive>
void load(Archive &ar)
{
try {
ar(cereal::make_nvp("tag", tag));
} catch(...) {
tag = "buffered messages";
ar.setNextName(nullptr);
}
ar(method, url);
}
template<class Archive>
void save(Archive &ar) const
{
ar(cereal::make_nvp("tag", tag));
ar(method, url);
}
private:
std::string method;
std::string url;
std::string tag;
};
class HTTPRequestEvent : public HTTPRequestSignature
{
public:
HTTPRequestEvent() = default;
HTTPRequestEvent(
const std::string &_method,
const std::string &_url,
const std::string &_headers,
const std::string &&_body,
const std::string &_tag = "buffered messages")
:
HTTPRequestSignature(_method, _url, _tag),
headers(_headers),
body(std::move(_body))
{
}
HTTPRequestEvent(
const HTTPRequestSignature &&sig,
const std::string &_headers,
const std::string &&_body)
:
HTTPRequestSignature(std::move(sig)),
headers(_headers),
body(std::move(_body))
{
}
template<class Archive>
void load(Archive &ar)
{
HTTPRequestSignature::load(ar);
ar(headers, body);
}
template<class Archive>
void save(Archive &ar) const
{
HTTPRequestSignature::save(ar);
ar(headers, body);
}
const std::string & getHeaders() const { return headers; }
const std::string & getBody() const { return body; }
private:
std::string headers;
std::string body;
};
#endif // __HTTP_REQUEST_EVENT_H__

0
core/include/internal/shell_cmd.h Executable file → Normal file
View File

0
core/include/internal/trap_handler.h Executable file → Normal file
View File