Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
PanoptesDatabase Class Reference

#include <database.hpp>

Public Member Functions

std::string UpdateEntry (std::string key, std::string entry)
BOOL AddEntry (std::string key, std::string entry)
std::string GetEntry (std::string hash)
ERRORCODE InitializeDatabase ()
 PanoptesDatabase ()

Static Public Member Functions

static void CloseDatabase ()
 Flushes and closes the database. Safe to call if it was never opened.

Detailed Description

Definition at line 7 of file database.hpp.

Constructor & Destructor Documentation

◆ PanoptesDatabase()

PanoptesDatabase::PanoptesDatabase ( )

Definition at line 85 of file database.cpp.

85 {
86 m_options.IncreaseParallelism();
87 m_options.OptimizeLevelStyleCompaction();
88 m_options.create_if_missing = true;
89}
rocksdb::Options m_options
Definition database.cpp:22

References m_options.

Member Function Documentation

◆ AddEntry()

BOOL PanoptesDatabase::AddEntry ( std::string key,
std::string entry )

Definition at line 50 of file database.cpp.

50 {
51 Status s = m_database->Put(WriteOptions(), key, entry);
52 if (s.ok()) {
53 return true;
54 }
55 else {
56 return false;
57 }
58}
rocksdb::DB * m_database
Definition database.cpp:21

References m_database.

◆ CloseDatabase()

void PanoptesDatabase::CloseDatabase ( )
static

Flushes and closes the database. Safe to call if it was never opened.

Definition at line 40 of file database.cpp.

40 {
41 if (m_database == NULL) {
42 return;
43 }
44
45 m_database->Close();
46 delete m_database;
47 m_database = NULL;
48}

References m_database.

◆ GetEntry()

std::string PanoptesDatabase::GetEntry ( std::string hash)

Definition at line 60 of file database.cpp.

60 {
61 std::string value;
62 Status s = m_database->Get(ReadOptions(), hash, &value);
63 return value;
64}

References m_database.

Referenced by UpdateEntry().

◆ InitializeDatabase()

ERRORCODE PanoptesDatabase::InitializeDatabase ( )

Definition at line 24 of file database.cpp.

24 {
25#ifdef _DEBUG
26 std::string databasePath = GetExecutableDirectory() + "\\database";
27#else
28 std::string databasePath = PANOPTES_DATABASE_PATH;
29#endif // _DEBUG
30
31 Status s = rocksdb::DB::Open(m_options, databasePath, &m_database);
32 if (s.ok()) {
33 return PANO_SUCCESS;
34 }
35 else {
36 return DB_INITIALIZATION;
37 }
38}
#define PANO_SUCCESS
#define DB_INITIALIZATION
#define PANOPTES_DATABASE_PATH
std::string GetExecutableDirectory()
Definition utils.cpp:71

References DB_INITIALIZATION, ERRORCODE, GetExecutableDirectory(), m_database, m_options, PANO_SUCCESS, and PANOPTES_DATABASE_PATH.

◆ UpdateEntry()

std::string PanoptesDatabase::UpdateEntry ( std::string key,
std::string entry )

Definition at line 66 of file database.cpp.

66 {
67 std::string dbEntryStr = GetEntry(key);
68 nlohmann::json dbEntry = nlohmann::json::parse(dbEntryStr);
69 nlohmann::json entryToMerge = nlohmann::json::parse(entry);
70 dbEntry.merge_patch(entryToMerge);
71 std::string combinedEntry = dbEntry.dump();
72 WriteBatch batch;
73
74 batch.Delete(key);
75 batch.Put(key, combinedEntry);
76 Status s = m_database->Write(WriteOptions(), &batch);
77 if (s.ok()) {
78 return combinedEntry;
79 }
80 else {
81 return "";
82 }
83}
std::string GetEntry(std::string hash)
Definition database.cpp:60

References GetEntry(), and m_database.


The documentation for this class was generated from the following files: