Skip to content
Permalink
Browse files

Add the user-agent to Nigel requests

  • Loading branch information...
brandonlehmann committed Sep 7, 2019
1 parent 567c50a commit aee75c09de0385c310b3f24e12f439697a128db1
Showing with 16 additions and 8 deletions.
  1. +13 −8 src/nigel/Nigel.cpp
  2. +3 −0 src/nigel/Nigel.h
@@ -11,6 +11,7 @@
#include <errors/ValidateParameters.h>
#include <logger/Logger.h>
#include <utilities/Utilities.h>
#include <version.h>

using json = nlohmann::json;

@@ -57,6 +58,10 @@ Nigel::Nigel(
m_daemonPort(daemonPort),
m_daemonSSL(daemonSSL)
{
std::stringstream userAgent;
userAgent << "Nigel/" << PROJECT_VERSION_LONG;

m_requestHeaders = {{"User-Agent", userAgent.str()}};
m_nodeClient = getClient(m_daemonHost, m_daemonPort, m_daemonSSL, m_timeout);
}

@@ -120,7 +125,7 @@ std::tuple<bool, std::vector<WalletTypes::WalletBlockInfo>, std::optional<Wallet
{"blockCount", m_blockCount.load()},
{"skipCoinbaseTransactions", skipCoinbaseTransactions}};

auto res = m_nodeClient->Post("/getwalletsyncdata", j.dump(), "application/json");
auto res = m_nodeClient->Post("/getwalletsyncdata", m_requestHeaders, j.dump(), "application/json");

if (res && res->status == 200)
{
@@ -183,7 +188,7 @@ bool Nigel::getDaemonInfo()
{
Logger::logger.log("Updating daemon info", Logger::DEBUG, {Logger::SYNC, Logger::DAEMON});

auto res = m_nodeClient->Get("/info");
auto res = m_nodeClient->Get("/info", m_requestHeaders);

if (res && res->status == 200)
{
@@ -237,7 +242,7 @@ bool Nigel::getFeeInfo()
{
Logger::logger.log("Fetching fee info", Logger::DEBUG, {Logger::DAEMON});

auto res = m_nodeClient->Get("/fee");
auto res = m_nodeClient->Get("/fee", m_requestHeaders);

if (res && res->status == 200)
{
@@ -324,7 +329,7 @@ bool Nigel::getTransactionsStatus(
{
json j = {{"transactionHashes", transactionHashes}};

auto res = m_nodeClient->Post("/get_transactions_status", j.dump(), "application/json");
auto res = m_nodeClient->Post("/get_transactions_status", m_requestHeaders, j.dump(), "application/json");

if (res && res->status == 200)
{
@@ -364,7 +369,7 @@ std::tuple<bool, std::vector<CryptoNote::RandomOuts>>

/* We also need to handle the request and response a bit
differently so we'll do this here */
auto res = m_nodeClient->Post("/randomOutputs", j.dump(), "application/json");
auto res = m_nodeClient->Post("/randomOutputs", m_requestHeaders, j.dump(), "application/json");

if (res && res->status == 200)
{
@@ -383,7 +388,7 @@ std::tuple<bool, std::vector<CryptoNote::RandomOuts>>
}
else
{
auto res = m_nodeClient->Post("/getrandom_outs", j.dump(), "application/json");
auto res = m_nodeClient->Post("/getrandom_outs", m_requestHeaders, j.dump(), "application/json");

if (res && res->status == 200)
{
@@ -413,7 +418,7 @@ std::tuple<bool, bool> Nigel::sendTransaction(const CryptoNote::Transaction tx)
{
json j = {{"tx_as_hex", Common::toHex(CryptoNote::toBinaryArray(tx))}};

auto res = m_nodeClient->Post("/sendrawtransaction", j.dump(), "application/json");
auto res = m_nodeClient->Post("/sendrawtransaction", m_requestHeaders, j.dump(), "application/json");

bool success = false;
bool connectionError = true;
@@ -449,7 +454,7 @@ std::tuple<bool, std::unordered_map<Crypto::Hash, std::vector<uint64_t>>>

json j = {{"startHeight", startHeight}, {"endHeight", endHeight}};

auto res = m_nodeClient->Post("/get_global_indexes_for_range", j.dump(), "application/json");
auto res = m_nodeClient->Post("/get_global_indexes_for_range", m_requestHeaders, j.dump(), "application/json");

if (res && res->status == 200)
{
@@ -101,6 +101,9 @@ class Nigel
and making our functions non const) */
std::shared_ptr<httplib::Client> m_nodeClient = nullptr;

/* Stores the HTTP headers included in all Nigel requests */
httplib::Headers m_requestHeaders;

/* Runs a background refresh on height, hashrate, etc */
std::thread m_backgroundThread;

0 comments on commit aee75c0

Please sign in to comment.
You can’t perform that action at this time.