begin adding set methods for network rpc
This commit is contained in:
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -89,6 +89,12 @@ dependencies = [
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.51"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203"
|
||||
|
||||
[[package]]
|
||||
name = "async-stream"
|
||||
version = "0.3.2"
|
||||
@ -2474,13 +2480,16 @@ dependencies = [
|
||||
name = "peach-jsonrpc-server"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"env_logger 0.9.0",
|
||||
"jsonrpc-core 18.0.0",
|
||||
"jsonrpc-http-server 18.0.0",
|
||||
"jsonrpc-test 18.0.0",
|
||||
"log 0.4.14",
|
||||
"miniserde",
|
||||
"peach-network",
|
||||
"peach-stats",
|
||||
"serde 1.0.130",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -15,7 +15,7 @@ mod error;
|
||||
mod params;
|
||||
|
||||
use crate::error::ServerError;
|
||||
use crate::params::{Iface, IfaceSsid};
|
||||
use crate::params::{Iface, IfaceSsid, WiFi};
|
||||
|
||||
/// Create JSON-RPC I/O handler, add RPC methods and launch HTTP server.
|
||||
pub fn run() -> Result<(), ServerError> {
|
||||
@ -185,32 +185,34 @@ pub fn run() -> Result<(), ServerError> {
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
// set - all network rpc methods for modifying state
|
||||
|
||||
io.add_method("activate_ap", move |_| {
|
||||
network::activate_ap()?;
|
||||
|
||||
Ok(Value::String("success".to_string()))
|
||||
});
|
||||
|
||||
io.add_method("activate_client", move |_| {
|
||||
network::activate_client()?;
|
||||
|
||||
Ok(Value::String("success".to_string()))
|
||||
});
|
||||
|
||||
io.add_method("add", move |params: Params| {
|
||||
let w: Result<WiFi, Error> = params.parse();
|
||||
match w {
|
||||
Ok(w) => match network::add(&w) {
|
||||
Ok(_) => Ok(Value::String("success".to_string())),
|
||||
Err(e) => Err(Error::from(e)),
|
||||
},
|
||||
Err(e) => Err(Error::from(NetworkError::MissingParams { e })),
|
||||
io.add_method("start_iface_service", |params: Params| async move {
|
||||
let parsed: Result<Iface, RpcCoreError> = params.parse();
|
||||
match parsed {
|
||||
Ok(i) => {
|
||||
let iface = i.iface;
|
||||
match network::start_iface_service(iface) {
|
||||
Ok(_) => Ok(Value::String("success".to_string())),
|
||||
Err(e) => Err(RpcCoreError::from(ServerError::Network(e))),
|
||||
}
|
||||
}
|
||||
Err(e) => Err(RpcCoreError::from(ServerError::MissingParameter(e))),
|
||||
}
|
||||
});
|
||||
|
||||
io.add_method("add", |params: Params| async move {
|
||||
let parsed: Result<WiFi, RpcCoreError> = params.parse();
|
||||
match parsed {
|
||||
Ok(w) => match network::add(wlan_iface: &w.wlan_iface, ssid: &w.ssid, pass: &w.pass) {
|
||||
Ok(_) => Ok(Value::String("success".to_string())),
|
||||
Err(e) => Err(RpcCoreError::from(ServerError::Network(e))),
|
||||
},
|
||||
Err(e) => Err(RpcCoreError::from(ServerError::MissingParameter(e))),
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
io.add_method("check_iface", move |_| {
|
||||
network::check_iface()?;
|
||||
|
||||
|
@ -21,3 +21,11 @@ pub struct IfaceSsid {
|
||||
pub iface: String,
|
||||
pub ssid: String,
|
||||
}
|
||||
|
||||
/// Wireless interface (for which the WiFi credentials will be added), SSID and password for a wireless access point.
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct WiFi {
|
||||
pub wlan_iface: String,
|
||||
pub ssid: String,
|
||||
pub pass: String,
|
||||
}
|
||||
|
Reference in New Issue
Block a user