|
@@ -44,6 +44,9 @@ impl RequestHandler<()> for DarkIrc {
|
|
|
"dnet.switch" => self.dnet_switch(req.id, req.params).await,
|
|
"dnet.switch" => self.dnet_switch(req.id, req.params).await,
|
|
|
"dnet.subscribe_events" => self.dnet_subscribe_events(req.id, req.params).await,
|
|
"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.get_info" => self.p2p_get_info(req.id, req.params).await,
|
|
|
|
|
+ "p2p.set_outbound_connections" => {
|
|
|
|
|
+ self.set_outbound_connections(req.id, req.params).await
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
"deg.switch" => self.deg_switch(req.id, req.params).await,
|
|
"deg.switch" => self.deg_switch(req.id, req.params).await,
|
|
|
"deg.subscribe_events" => self.deg_subscribe_events(req.id, req.params).await,
|
|
"deg.subscribe_events" => self.deg_subscribe_events(req.id, req.params).await,
|
|
@@ -84,6 +87,34 @@ impl DarkIrc {
|
|
|
JsonResponse::new(JsonValue::Boolean(true), id).into()
|
|
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 params = params.get::<Vec<JsonValue>>().unwrap();
|
|
|
|
|
+ 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:
|
|
// RPCAPI:
|
|
|
// Initializes a subscription to p2p dnet events.
|
|
// Initializes a subscription to p2p dnet events.
|
|
|
// Once a subscription is established, `darkirc` will send JSON-RPC notifications of
|
|
// Once a subscription is established, `darkirc` will send JSON-RPC notifications of
|