|
@@ -19,7 +19,7 @@
|
|
|
use async_trait::async_trait;
|
|
use async_trait::async_trait;
|
|
|
|
|
|
|
|
use super::{
|
|
use super::{
|
|
|
- jsonrpc::{ErrorCode, JsonError, JsonResponse, JsonResult},
|
|
|
|
|
|
|
+ jsonrpc::{JsonResponse, JsonResult},
|
|
|
util::*,
|
|
util::*,
|
|
|
};
|
|
};
|
|
|
use crate::net;
|
|
use crate::net;
|
|
@@ -57,35 +57,5 @@ pub trait HandlerP2p: Sync + Send {
|
|
|
JsonResponse::new(result, id).into()
|
|
JsonResponse::new(result, id).into()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // RPCAPI:
|
|
|
|
|
- // Set the number of outbound connections for the P2P stack.
|
|
|
|
|
- // Takes a positive integer representing the desired number of outbound connection slots.
|
|
|
|
|
- // Returns `true` on success. If the number is greater than current, new slots are added.
|
|
|
|
|
- // If the number is less than current, slots are removed (prioritizing empty slots).
|
|
|
|
|
- //
|
|
|
|
|
- // --> {"jsonrpc": "2.0", "method": "p2p.set_outbound_connections", "params": [5], "id": 42}
|
|
|
|
|
- // <-- {"jsonrpc": "2.0", "result": true, "id": 42}
|
|
|
|
|
- async fn p2p_set_outbound_connections(&self, id: u16, params: JsonValue) -> JsonResult {
|
|
|
|
|
- let Some(params) = params.get::<Vec<JsonValue>>() else {
|
|
|
|
|
- return JsonError::new(ErrorCode::InvalidParams, None, id).into()
|
|
|
|
|
- };
|
|
|
|
|
- if params.len() != 1 || !params[0].is_number() {
|
|
|
|
|
- return JsonError::new(ErrorCode::InvalidParams, None, id).into()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- let n_f64 = params[0].get::<f64>().unwrap();
|
|
|
|
|
- let n = *n_f64 as u32;
|
|
|
|
|
-
|
|
|
|
|
- if *n_f64 != n as f64 || n == 0 {
|
|
|
|
|
- return JsonError::new(ErrorCode::InvalidParams, None, id).into()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if let Err(e) = self.p2p().session_outbound().set_outbound_connections(n as usize).await {
|
|
|
|
|
- return JsonError::new(ErrorCode::InternalError, Some(e.to_string()), id).into()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- JsonResponse::new(JsonValue::Boolean(true), id).into()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
fn p2p(&self) -> net::P2pPtr;
|
|
fn p2p(&self) -> net::P2pPtr;
|
|
|
}
|
|
}
|