Skip to content

Commit

Permalink
WIP Add REST-like API calls for daemon, hardware info (#145)
Browse files Browse the repository at this point in the history
* add rest-like api for daemon

* add transactions by payment_id to rest-like api

* add transaction info in JSON by hash

renamed k_transaction_details_by_hash to gettransaction

* bugfixes

* Update version.h.in

* add brain sources

* minor codestyle fixes

* Add mempool to Restful like Api & improve get_transactions_by_heights Method

* Add mempool_details to restful like Api
Renamed f_mempool_json to get_mempool_detailed

* version.h.in aktualisiert

* Avoid needing of parsing on end device

* Add fee to get_transactions_by_heights & adjusted REST API Mempool

* Fix internal error to search for a block heigher than actuall chain height

* Update Currency.cpp

* Increase nextDiffV5 to pre6 Version

* add rest-like api for daemon

* add transactions by payment_id to rest-like api

* add transaction info in JSON by hash

renamed k_transaction_details_by_hash to gettransaction

* bugfixes

* add brain sources

* minor codestyle fixes

* Add mempool to Restful like Api & improve get_transactions_by_heights Method

* Add mempool_details to restful like Api
Renamed f_mempool_json to get_mempool_detailed

* Avoid needing of parsing on end device

* Add fee to get_transactions_by_heights & adjusted REST API Mempool

* Fix internal error to search for a block heigher than actuall chain height

* Bum Version

* Bump Version

* Fix output indices

* Cleanup RPC a bit

* Add method to get txs by height

* Add improved onGetRawTransactionsByHeights

from @aivve

* Add HardwareInfo

* Update Checkpoints.h, CryptoNoteConfig.h, and version.h.in

* Update CMakeLists.txt

* Update NetNode.cpp

* add core/threadCount on Windows and MacOS

* Add architecture to RPCServer, changed output to string

* Add Memory to HardwareInfo and RPCServer

* Add Storage to HardwareInfo, cleanup gethardwareinfo RPC command

* Update HardwareInfo.cpp

Co-authored-by: ExploShot <[email protected]>
  • Loading branch information
nnian and ExploShot authored Mar 21, 2021
1 parent 62cc2fd commit 0f2d234
Show file tree
Hide file tree
Showing 21 changed files with 5,830 additions and 4,474 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ if(BUILD_WITH_TOOLS)
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/src")
endif()

if(BUILD_WITH_TESTS)
#[[if(BUILD_WITH_TESTS)
enable_testing()
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/tests")
endif()
endif()]]

if(BUILD_WITH_PACKAGE)
include(project/CPackConfig)
Expand Down
2 changes: 1 addition & 1 deletion cmake/find/FindBoost.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ function(_Boost_COMPONENT_DEPENDENCIES component _ret)
set(_Boost_WAVE_DEPENDENCIES filesystem serialization thread chrono date_time atomic)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
endif()
if(NOT Boost_VERSION VERSION_LESS 107100)
if(NOT Boost_VERSION VERSION_LESS 107300)
message(WARNING "New Boost version may have incorrect or missing dependencies and imported targets")
endif()
endif()
Expand Down
3 changes: 2 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ set(QwertycoinFramework_Common_SOURCES
"${CMAKE_CURRENT_LIST_DIR}/Common/int-util.h"
"${CMAKE_CURRENT_LIST_DIR}/Common/pod-class.h"
"${CMAKE_CURRENT_LIST_DIR}/Common/static_assert.h"
)
"${CMAKE_CURRENT_LIST_DIR}/Common/HardwareInfo.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Common/HardwareInfo.h")

set(QwertycoinFramework_Common_LIBS
Threads::Threads
Expand Down
143 changes: 143 additions & 0 deletions lib/Common/HardwareInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
//
// Created by exploshot on 12.10.20.
//

#ifndef _WIN32

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <string>
#include <sys/utsname.h>
#include <unistd.h>

#endif

#ifdef _WIN32

#define WIN32_LEAN_AND_MEAN
#include <thread>
#include <windows.h>

#endif

#if __APPLE__
#include <sys/param.h>
#include <sys/sysctl.h>
#endif

#include <vector>

#include <Common/HardwareInfo.h>

using namespace Tools::CPU;

#ifdef _WIN32

static std::vector<SYSTEM_LOGICAL_PROCESSOR_INFORMATION> cpuinfoBuffer()
{
std::vector<SYSTEM_LOGICAL_PROCESSOR_INFORMATION> buffer;

DWORD byte_count = 0;
GetLogicalProcessorInformation(nullptr, &byte_count);
buffer.resize(byte_count / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION));
GetLogicalProcessorInformation(buffer.data(), &byte_count);

return buffer;
}

#endif

std::string Tools::CPU::architecture() noexcept
{
#ifdef _WIN32
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);

switch (sysInfo.wProcessorArchitecture)
{
case PROCESSOR_ARCHITECTURE_AMD64:
return "x64";
case PROCESSOR_ARCHITECTURE_ARM:
return "ARM";
case PROCESSOR_ARCHITECTURE_IA64:
return "Itanium";
case PROCESSOR_ARCHITECTURE_INTEL:
return "x86";
default:
return "unknown";
}
#endif

#ifndef _WIN32
utsname buf;
if (uname(&buf) == -1) {
return "unknown";
}

if (!strcmp(buf.machine, "x86_64"))
return "x64";
else if (strstr(buf.machine, "arm") == buf.machine)
return "ARM";
else if (!strcmp(buf.machine, "ia64") || !strcmp(buf.machine, "IA64"))
return "Itanium";
else if (!strcmp(buf.machine, "i686"))
return "x86";
else
return "unknown";
#endif
}

Tools::CPU::Quantities Tools::CPU::quantities()
{
Quantities ret{};

#ifdef _WIN32
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
ret.logical = sysinfo.dwNumberOfProcessors;
ret.physical = ret.logical / 2;
#elif __APPLE__
int nm[2];
size_t len = 4;
uint32_t count;

nm[0] = CTL_HW; nm[1] = HW_AVAILCPU;
sysctl(nm, 2, &count, &len, NULL, 0);

if(count < 1) {
nm[1] = HW_NCPU;
sysctl(nm, 2, &count, &len, NULL, 0);
if(count < 1) { count = 1; }
}
ret.logical = count;
ret.physical = ret.logical / 2;
#else
ret.logical = sysconf(_SC_NPROCESSORS_ONLN);

std::ifstream cpuinfo("/proc/cpuinfo");

if (!cpuinfo.is_open() || !cpuinfo) {
return ret;
}

std::vector<unsigned int> packageIds;
for (std::string line; std::getline(cpuinfo, line);) {
if (line.find("physical id") == 0) {
const auto physicalId = std::strtoul(line.c_str() + line.find_first_of("1234567890"), nullptr, 10);
if (std::find(packageIds.begin(), packageIds.end(), physicalId) == packageIds.end()) {
packageIds.emplace_back(physicalId);
}
}
}

ret.packages = packageIds.size();
ret.physical = ret.logical / ret.packages;
#endif
return ret;
}




Loading

0 comments on commit 0f2d234

Please sign in to comment.