Skip to content
Snippets Groups Projects
Commit 233ce5c1 authored by DeathwingTheBoss's avatar DeathwingTheBoss
Browse files

Revert JSON order requirements, adjust text and formatting

parent ff06b666
No related branches found
No related tags found
No related merge requests found
...@@ -1558,7 +1558,6 @@ version = "1.0.94" ...@@ -1558,7 +1558,6 @@ version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea" checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea"
dependencies = [ dependencies = [
"indexmap",
"itoa", "itoa",
"ryu", "ryu",
"serde", "serde",
......
...@@ -11,7 +11,7 @@ description = "A caching reverse-proxy application for the Hive blockchain." ...@@ -11,7 +11,7 @@ description = "A caching reverse-proxy application for the Hive blockchain."
actix-web = "4.3.1" actix-web = "4.3.1"
reqwest = { version = "0.11.14", features = ["blocking", "json"] } reqwest = { version = "0.11.14", features = ["blocking", "json"] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0.94", features = ["preserve_order"] } serde_json = "1.0.94"
lru_time_cache = "0.11.11" lru_time_cache = "0.11.11"
humantime = "2.1.0" humantime = "2.1.0"
config = "0.13.3" config = "0.13.3"
......
...@@ -46,7 +46,7 @@ OPERATOR_MESSAGE: Customizable message from the operator (default: "Drone by Dea ...@@ -46,7 +46,7 @@ OPERATOR_MESSAGE: Customizable message from the operator (default: "Drone by Dea
HAF_ENDPOINT: HAF Endpoint that Drone can connect to relay HAF related API calls. HAF_ENDPOINT: HAF Endpoint that Drone can connect to relay HAF related API calls.
HAFAH_ENDPOINT: HAFAH Endpoint that Drone can connect to relay HAFAH related API calls. HAFAH_ENDPOINT: HAFAH Endpoint that Drone can connect to relay HAFAH related API calls.
HIVEMIND_ENDPOINT: Hivemind Endpoint that Drone can connect to relay Hivemind related API calls. HIVEMIND_ENDPOINT: Hivemind Endpoint that Drone can connect to relay Hivemind related API calls.
ACTIX_CONNECTION_THREADS: Specifies the number of HTTP connections kept alive (default: 8). MIDDLEWARE_CONNECTION_THREADS: Specifies the number of HTTP connections to Hive endpoints kept alive (default: 8).
``` ```
## Usage ## Usage
......
...@@ -7,5 +7,5 @@ ...@@ -7,5 +7,5 @@
"HAF_ENDPOINT": "http://HAF:HAFPORT", "HAF_ENDPOINT": "http://HAF:HAFPORT",
"HAFAH_ENDPOINT": "http://HAFAH:HAFAHPORT", "HAFAH_ENDPOINT": "http://HAFAH:HAFAHPORT",
"HIVEMIND_ENDPOINT": "http://HIVEMIND:HIVEMINDPORT", "HIVEMIND_ENDPOINT": "http://HIVEMIND:HIVEMINDPORT",
"ACTIX_CONNECTION_THREADS": 8 "MIDDLEWARE_CONNECTION_THREADS": 8
} }
\ No newline at end of file
use actix_cors::Cors;
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder}; use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder};
use config::Config; use config::Config;
use lru_time_cache::LruCache; use lru_time_cache::LruCache;
...@@ -6,7 +7,6 @@ use serde::{Deserialize, Serialize, Serializer}; ...@@ -6,7 +7,6 @@ use serde::{Deserialize, Serialize, Serializer};
use serde_json::Value; use serde_json::Value;
use serde_with::{serde_as, DurationSeconds}; use serde_with::{serde_as, DurationSeconds};
use std::{sync::Mutex, time::Duration}; use std::{sync::Mutex, time::Duration};
use actix_cors::Cors;
const DRONE_VERSION: &str = env!("CARGO_PKG_VERSION"); const DRONE_VERSION: &str = env!("CARGO_PKG_VERSION");
...@@ -57,7 +57,7 @@ struct APIRequest { ...@@ -57,7 +57,7 @@ struct APIRequest {
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
enum ErrorField { enum ErrorField {
Object(Value), // JSON from Hived Object(Value), // JSON from Hived
Message(String), // Custom message Message(String), // Custom message
} }
...@@ -135,7 +135,7 @@ async fn handle_request( ...@@ -135,7 +135,7 @@ async fn handle_request(
"condenser_api.get_transaction" => Endpoints::HAFAH, "condenser_api.get_transaction" => Endpoints::HAFAH,
"condenser_api.get_account_history" => Endpoints::HAFAH, "condenser_api.get_account_history" => Endpoints::HAFAH,
"database_api.get_account_history" => Endpoints::HAFAH, "database_api.get_account_history" => Endpoints::HAFAH,
// HIVEMIND // HIVEMIND
_hive_endpoint if method.starts_with("hive.") => Endpoints::HIVEMIND, _hive_endpoint if method.starts_with("hive.") => Endpoints::HIVEMIND,
"condenser_api.get_content_replies" => Endpoints::HIVEMIND, "condenser_api.get_content_replies" => Endpoints::HIVEMIND,
"condenser_api.get_account_votes" => Endpoints::HIVEMIND, "condenser_api.get_account_votes" => Endpoints::HIVEMIND,
...@@ -223,8 +223,9 @@ async fn handle_request( ...@@ -223,8 +223,9 @@ async fn handle_request(
} }
let mut cacheable = true; let mut cacheable = true;
if json_body["result"].is_array() && json_body["result"].as_array().unwrap().is_empty() if json_body["result"].is_array() && json_body["result"].as_array().unwrap().is_empty()
|| json_body["result"].is_null() || json_body["result"]["blocks"].is_array() && || json_body["result"].is_null()
json_body["result"]["blocks"].as_array().unwrap().is_empty() || json_body["result"]["blocks"].is_array()
&& json_body["result"]["blocks"].as_array().unwrap().is_empty()
{ {
cacheable = false; cacheable = false;
} }
...@@ -248,7 +249,6 @@ async fn api_call( ...@@ -248,7 +249,6 @@ async fn api_call(
call: web::Json<APICall>, call: web::Json<APICall>,
data: web::Data<AppData>, data: web::Data<AppData>,
) -> impl Responder { ) -> impl Responder {
// Log the request, if there's Cloudflare header (CF-Connecting-IP) use that instead of peer_addr. // Log the request, if there's Cloudflare header (CF-Connecting-IP) use that instead of peer_addr.
let get_cloudflare_ip = req.headers().get("CF-Connecting-IP"); let get_cloudflare_ip = req.headers().get("CF-Connecting-IP");
...@@ -289,10 +289,12 @@ async fn api_call( ...@@ -289,10 +289,12 @@ async fn api_call(
return HttpResponse::InternalServerError().json(ErrorStructure { return HttpResponse::InternalServerError().json(ErrorStructure {
code: -32600, code: -32600,
message: "Request parameter error.".to_string(), message: "Request parameter error.".to_string(),
error: ErrorField::Message("Batch size too large, maximum allowed is 100.".to_string()), error: ErrorField::Message(
"Batch size too large, maximum allowed is 100.".to_string(),
),
}); });
} }
for request in requests { for request in requests {
let result = handle_request(&request, &data, &user_ip).await; let result = handle_request(&request, &data, &user_ip).await;
match result { match result {
...@@ -339,7 +341,7 @@ struct DroneConfig { ...@@ -339,7 +341,7 @@ struct DroneConfig {
haf_endpoint: String, haf_endpoint: String,
hafah_endpoint: String, hafah_endpoint: String,
hivemind_endpoint: String, hivemind_endpoint: String,
actix_connection_threads: usize, middleware_connection_threads: usize,
} }
#[actix_web::main] #[actix_web::main]
...@@ -361,7 +363,7 @@ async fn main() -> std::io::Result<()> { ...@@ -361,7 +363,7 @@ async fn main() -> std::io::Result<()> {
), ),
), ),
webclient: ClientBuilder::new() webclient: ClientBuilder::new()
.pool_max_idle_per_host(config.actix_connection_threads) .pool_max_idle_per_host(config.middleware_connection_threads)
.build() .build()
.unwrap(), .unwrap(),
config: config.clone(), config: config.clone(),
...@@ -371,10 +373,12 @@ async fn main() -> std::io::Result<()> { ...@@ -371,10 +373,12 @@ async fn main() -> std::io::Result<()> {
let cors = Cors::permissive(); let cors = Cors::permissive();
App::new() App::new()
.wrap(cors) .wrap(cors)
.app_data(web::JsonConfig::default() .app_data(
.content_type(|_| true) web::JsonConfig::default()
.content_type_required(false) .content_type(|_| true)
.limit(1024 * 100)) // 100kb .content_type_required(false)
.limit(1024 * 100),
) // 100kb
.app_data(_cache.clone()) .app_data(_cache.clone())
.route("/", web::get().to(index)) .route("/", web::get().to(index))
.route("/", web::post().to(api_call)) .route("/", web::post().to(api_call))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment