|
|
@@ -45,7 +45,7 @@ impl RequestHandler<()> for DarkIrc {
|
|
|
"dnet.subscribe_events" => self.dnet_subscribe_events(req.id, req.params).await,
|
|
|
"p2p.get_info" => self.p2p_get_info(req.id, req.params).await,
|
|
|
"p2p.set_outbound_connections" => {
|
|
|
- self.set_outbound_connections(req.id, req.params).await
|
|
|
+ self.p2p_set_outbound_connections(req.id, req.params).await
|
|
|
}
|
|
|
|
|
|
"deg.switch" => self.deg_switch(req.id, req.params).await,
|
|
|
@@ -89,36 +89,6 @@ impl DarkIrc {
|
|
|
JsonResponse::new(JsonValue::Boolean(true), 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 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()
|
|
|
- }
|
|
|
-
|
|
|
// RPCAPI:
|
|
|
// Initializes a subscription to p2p dnet events.
|
|
|
// Once a subscription is established, `darkirc` will send JSON-RPC notifications of
|