Implemented BenchClient.
This commit is contained in:
parent
36c1cb23e0
commit
79c96418c7
9 changed files with 200 additions and 18 deletions
|
@ -1,6 +1,7 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -18,6 +19,14 @@
|
|||
|
||||
|
||||
#include "base/net/http/HttpData.h"
|
||||
#include "3rdparty/http-parser/http_parser.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "3rdparty/rapidjson/error/en.h"
|
||||
#include "base/io/json/Json.h"
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
@ -42,3 +51,46 @@ bool xmrig::HttpData::isJSON() const
|
|||
|
||||
return type == kApplicationJson || type == kTextPlain;
|
||||
}
|
||||
|
||||
|
||||
const char *xmrig::HttpData::methodName() const
|
||||
{
|
||||
return http_method_str(static_cast<http_method>(method));
|
||||
}
|
||||
|
||||
|
||||
const char *xmrig::HttpData::statusName() const
|
||||
{
|
||||
if (status < 0) {
|
||||
return uv_strerror(status);
|
||||
}
|
||||
|
||||
return http_status_str(static_cast<http_status>(status));
|
||||
}
|
||||
|
||||
|
||||
rapidjson::Document xmrig::HttpData::json() const
|
||||
{
|
||||
if (status < 0) {
|
||||
throw std::runtime_error(statusName());
|
||||
}
|
||||
|
||||
if (!isJSON()) {
|
||||
throw std::runtime_error("the response is not a valid JSON response");
|
||||
}
|
||||
|
||||
using namespace rapidjson;
|
||||
Document doc;
|
||||
if (doc.Parse(body.c_str()).HasParseError()) {
|
||||
throw std::runtime_error(GetParseError_En(doc.GetParseError()));
|
||||
}
|
||||
|
||||
if (doc.IsObject() && !doc.ObjectEmpty()) {
|
||||
const char *error = Json::getString(doc, "error");
|
||||
if (error) {
|
||||
throw std::runtime_error(error);
|
||||
}
|
||||
}
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -28,6 +22,7 @@
|
|||
#define XMRIG_HTTPDATA_H
|
||||
|
||||
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
|
@ -63,6 +58,9 @@ public:
|
|||
virtual void write(std::string &&data, bool close) = 0;
|
||||
|
||||
bool isJSON() const;
|
||||
const char *methodName() const;
|
||||
const char *statusName() const;
|
||||
rapidjson::Document json() const;
|
||||
|
||||
int method = 0;
|
||||
int status = 0;
|
||||
|
@ -70,6 +68,7 @@ public:
|
|||
std::map<const std::string, const std::string> headers;
|
||||
std::string body;
|
||||
std::string url;
|
||||
uint64_t rpcId = 0;
|
||||
|
||||
private:
|
||||
const uint64_t m_id;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue