Compare commits
2 Commits
b4e2dd2683
...
22e32a5715
Author | SHA1 | Date | |
---|---|---|---|
|
22e32a5715 | ||
|
6bbfb454de |
26
Cargo.lock
generated
26
Cargo.lock
generated
@ -1,6 +1,6 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 4
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "addr2line"
|
name = "addr2line"
|
||||||
@ -2483,7 +2483,7 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
"sha3",
|
"sha3",
|
||||||
"solar_client",
|
"tilde-client",
|
||||||
"toml",
|
"toml",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -2575,7 +2575,6 @@ dependencies = [
|
|||||||
"peach-stats",
|
"peach-stats",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rouille",
|
"rouille",
|
||||||
"solar_client",
|
|
||||||
"temporary",
|
"temporary",
|
||||||
"vnstat_parse",
|
"vnstat_parse",
|
||||||
"xdg",
|
"xdg",
|
||||||
@ -3445,16 +3444,6 @@ dependencies = [
|
|||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "solar_client"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"anyhow",
|
|
||||||
"jsonrpc_client",
|
|
||||||
"reqwest",
|
|
||||||
"serde_json",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "spidev"
|
name = "spidev"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
@ -3684,6 +3673,17 @@ dependencies = [
|
|||||||
"num_cpus",
|
"num_cpus",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tilde-client"
|
||||||
|
version = "0.0.1"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"async-std",
|
||||||
|
"serde 1.0.209",
|
||||||
|
"serde_json",
|
||||||
|
"serde_yaml",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "time"
|
name = "time"
|
||||||
version = "0.1.44"
|
version = "0.1.44"
|
||||||
|
@ -9,6 +9,7 @@ members = [
|
|||||||
"peach-monitor",
|
"peach-monitor",
|
||||||
"peach-stats",
|
"peach-stats",
|
||||||
"peach-jsonrpc-server",
|
"peach-jsonrpc-server",
|
||||||
"peach-dyndns-updater"
|
"peach-dyndns-updater",
|
||||||
|
"tilde-client"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ chrono = "0.4"
|
|||||||
dirs = "4.0"
|
dirs = "4.0"
|
||||||
fslock="0.1"
|
fslock="0.1"
|
||||||
kuska-ssb = { git = "https://github.com/Kuska-ssb/ssb" }
|
kuska-ssb = { git = "https://github.com/Kuska-ssb/ssb" }
|
||||||
solar_client = { path = "../../solarpub/solar_client" }
|
tilde-client = { path = "../tilde-client" }
|
||||||
jsonrpc-client-core = "0.5"
|
jsonrpc-client-core = "0.5"
|
||||||
jsonrpc-client-http = "0.5"
|
jsonrpc-client-http = "0.5"
|
||||||
jsonrpc-core = "8.0"
|
jsonrpc-core = "8.0"
|
||||||
|
@ -59,8 +59,8 @@ pub fn get_peach_config_defaults() -> HashMap<String, String> {
|
|||||||
("SSB_ADMIN_IDS", ""),
|
("SSB_ADMIN_IDS", ""),
|
||||||
("ADMIN_PASSWORD_HASH", "47"),
|
("ADMIN_PASSWORD_HASH", "47"),
|
||||||
("TEMPORARY_PASSWORD_HASH", ""),
|
("TEMPORARY_PASSWORD_HASH", ""),
|
||||||
("SOLAR_SBOT_DATADIR", "/home/peach/.local/share/local"),
|
("TILDE_SBOT_DATADIR", "/home/notplants/.local/share/tildefriends/"),
|
||||||
("SOLAR_SBOT_SERVICE", "solar-sbot.service"),
|
("TILDE_SBOT_SERVICE", "tilde-sbot.service"),
|
||||||
("PEACH_CONFIGDIR", "/var/lib/peachcloud"),
|
("PEACH_CONFIGDIR", "/var/lib/peachcloud"),
|
||||||
("PEACH_HOMEDIR", "/home/peach"),
|
("PEACH_HOMEDIR", "/home/peach"),
|
||||||
("PEACH_WEBDIR", "/usr/share/peach-web"),
|
("PEACH_WEBDIR", "/usr/share/peach-web"),
|
||||||
|
@ -13,3 +13,4 @@ pub use jsonrpc_client_core;
|
|||||||
pub use jsonrpc_core;
|
pub use jsonrpc_core;
|
||||||
pub use serde_json;
|
pub use serde_json;
|
||||||
pub use serde_yaml;
|
pub use serde_yaml;
|
||||||
|
pub use tilde_client;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use std::{fs, fs::File, io, io::Write, path::PathBuf, process::Command, str};
|
use std::{fs, fs::File, io, io::Write, path::PathBuf, process::Command, str};
|
||||||
use std::os::linux::raw::ino_t;
|
use std::os::linux::raw::ino_t;
|
||||||
use solar_client::{Client, SolarClient};
|
use tilde_client::{TildeClient, get_sbot_client};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
||||||
use crate::config_manager;
|
use crate::config_manager;
|
||||||
@ -68,9 +68,10 @@ impl SbotStatus {
|
|||||||
|
|
||||||
// note this command does not need to be run as sudo
|
// note this command does not need to be run as sudo
|
||||||
// because non-privileged users are able to run systemctl show
|
// because non-privileged users are able to run systemctl show
|
||||||
|
let service_name = config_manager::get_config_value("TILDE_SBOT_SERVICE")?;
|
||||||
let info_output = Command::new("systemctl")
|
let info_output = Command::new("systemctl")
|
||||||
.arg("show")
|
.arg("show")
|
||||||
.arg(config_manager::get_config_value("SOLAR_SBOT_SERVICE")?)
|
.arg(service_name)
|
||||||
.arg("--no-page")
|
.arg("--no-page")
|
||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
@ -92,7 +93,7 @@ impl SbotStatus {
|
|||||||
// because non-privileged users are able to run systemctl status
|
// because non-privileged users are able to run systemctl status
|
||||||
let status_output = Command::new("systemctl")
|
let status_output = Command::new("systemctl")
|
||||||
.arg("status")
|
.arg("status")
|
||||||
.arg(config_manager::get_config_value("SOLAR_SBOT_SERVICE")?)
|
.arg(config_manager::get_config_value("TILDE_SBOT_SERVICE")?)
|
||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
let service_status = str::from_utf8(&status_output.stdout)?;
|
let service_status = str::from_utf8(&status_output.stdout)?;
|
||||||
@ -130,10 +131,15 @@ impl SbotStatus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TOOD restore this
|
||||||
// get path to blobstore
|
// get path to blobstore
|
||||||
|
// let blobstore_path = format!(
|
||||||
|
// "{}/blobs/sha256",
|
||||||
|
// config_manager::get_config_value("TILDE_SBOT_DATADIR")?
|
||||||
|
// );
|
||||||
let blobstore_path = format!(
|
let blobstore_path = format!(
|
||||||
"{}/blobs/sha256",
|
"{}",
|
||||||
config_manager::get_config_value("SOLAR_SBOT_DATADIR")?
|
config_manager::get_config_value("TILDE_SBOT_DATADIR")?
|
||||||
);
|
);
|
||||||
|
|
||||||
// determine the size of the blobstore directory in bytes
|
// determine the size of the blobstore directory in bytes
|
||||||
@ -265,7 +271,7 @@ impl SbotConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Initialise an sbot client
|
/// Initialise an sbot client
|
||||||
pub async fn init_sbot() -> Result<Client, PeachError> {
|
pub async fn init_sbot() -> Result<TildeClient, PeachError> {
|
||||||
// read sbot config from config.toml
|
// read sbot config from config.toml
|
||||||
let sbot_config = SbotConfig::read().ok();
|
let sbot_config = SbotConfig::read().ok();
|
||||||
|
|
||||||
@ -277,6 +283,6 @@ pub async fn init_sbot() -> Result<Client, PeachError> {
|
|||||||
);
|
);
|
||||||
// TODO: read this from config
|
// TODO: read this from config
|
||||||
const SERVER_ADDR: &str = "http://127.0.0.1:3030";
|
const SERVER_ADDR: &str = "http://127.0.0.1:3030";
|
||||||
let sbot_client = Client::new(SERVER_ADDR.to_owned())?;
|
let sbot_client = get_sbot_client();
|
||||||
Ok(sbot_client)
|
Ok(sbot_client)
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,6 @@ chrono = "0.4"
|
|||||||
dirs = "4.0"
|
dirs = "4.0"
|
||||||
env_logger = "0.8"
|
env_logger = "0.8"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
solar_client = { path = "../../solarpub/solar_client" }
|
|
||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
maud = "0.23"
|
maud = "0.23"
|
||||||
|
@ -16,10 +16,10 @@ use peach_lib::config_manager;
|
|||||||
use peach_lib::sbot::SbotConfig;
|
use peach_lib::sbot::SbotConfig;
|
||||||
use peach_lib::sbot::init_sbot;
|
use peach_lib::sbot::init_sbot;
|
||||||
use peach_lib::ssb_messages::SsbMessageKVT;
|
use peach_lib::ssb_messages::SsbMessageKVT;
|
||||||
use solar_client::{Client, SolarClient};
|
|
||||||
use rouille::input::post::BufferedFile;
|
use rouille::input::post::BufferedFile;
|
||||||
use temporary::Directory;
|
use temporary::Directory;
|
||||||
use peach_lib::serde_json::json;
|
use peach_lib::serde_json::json;
|
||||||
|
use peach_lib::tilde_client::TildeClient;
|
||||||
use crate::{error::PeachWebError, utils::sbot};
|
use crate::{error::PeachWebError, utils::sbot};
|
||||||
|
|
||||||
// SBOT HELPER FUNCTIONS
|
// SBOT HELPER FUNCTIONS
|
||||||
@ -29,7 +29,7 @@ pub fn systemctl_sbot_cmd(cmd: &str) -> Result<Output, PeachWebError> {
|
|||||||
let output = Command::new("sudo")
|
let output = Command::new("sudo")
|
||||||
.arg("systemctl")
|
.arg("systemctl")
|
||||||
.arg(cmd)
|
.arg(cmd)
|
||||||
.arg(config_manager::get_config_value("SOLAR_SBOT_SERVICE")?)
|
.arg(config_manager::get_config_value("TILDE_SBOT_SERVICE")?)
|
||||||
.output()?;
|
.output()?;
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
@ -64,12 +64,12 @@ pub fn restart_sbot_process() -> (String, String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Initialise an sbot client with the given configuration parameters.
|
/// Initialise an sbot client with the given configuration parameters.
|
||||||
pub async fn init_sbot_client() -> Result<Client, PeachWebError> {
|
pub async fn init_sbot_client() -> Result<TildeClient, PeachWebError> {
|
||||||
debug!("Initialising an sbot client with configuration parameters");
|
debug!("Initialising an sbot client with configuration parameters");
|
||||||
// initialise sbot connection with ip:port and shscap from config file
|
// initialise sbot connection with ip:port and shscap from config file
|
||||||
let key_path = format!(
|
let key_path = format!(
|
||||||
"{}/secret.toml",
|
"{}/secret.toml",
|
||||||
config_manager::get_config_value("SOLAR_SBOT_DATADIR")?
|
config_manager::get_config_value("TILDE_SBOT_DATADIR")?
|
||||||
);
|
);
|
||||||
let sbot_client = init_sbot().await?;
|
let sbot_client = init_sbot().await?;
|
||||||
Ok(sbot_client)
|
Ok(sbot_client)
|
||||||
@ -386,7 +386,7 @@ pub fn block_peer(public_key: &str) -> Result<String, String> {
|
|||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
debug!("Blocking a Scuttlebutt peer");
|
debug!("Blocking a Scuttlebutt peer");
|
||||||
match sbot_client.blocks(public_key).await {
|
match sbot_client.create_block(public_key).await {
|
||||||
Ok(_) => Ok("Blocked peer".to_string()),
|
Ok(_) => Ok("Blocked peer".to_string()),
|
||||||
Err(e) => Err(format!("Failed to block peer: {}", e)),
|
Err(e) => Err(format!("Failed to block peer: {}", e)),
|
||||||
}
|
}
|
||||||
@ -421,7 +421,7 @@ pub fn get_blocks_list() -> Result<Vec<HashMap<String, String>>, Box<dyn Error>>
|
|||||||
|
|
||||||
let self_id = sbot_client.whoami().await?;
|
let self_id = sbot_client.whoami().await?;
|
||||||
|
|
||||||
let blocks = sbot_client.blocks(&self_id).await?;
|
let blocks = sbot_client.get_blocks(&self_id).await?;
|
||||||
|
|
||||||
if !blocks.is_empty() {
|
if !blocks.is_empty() {
|
||||||
for peer in blocks.iter() {
|
for peer in blocks.iter() {
|
||||||
@ -489,7 +489,7 @@ pub fn get_follows_list() -> Result<Vec<HashMap<String, String>>, Box<dyn Error>
|
|||||||
|
|
||||||
let self_id = sbot_client.whoami().await?;
|
let self_id = sbot_client.whoami().await?;
|
||||||
|
|
||||||
let follows = sbot_client.follows(&self_id).await?;
|
let follows = sbot_client.get_follows(&self_id).await?;
|
||||||
|
|
||||||
if !follows.is_empty() {
|
if !follows.is_empty() {
|
||||||
for peer in follows.iter() {
|
for peer in follows.iter() {
|
||||||
@ -520,7 +520,7 @@ pub fn get_friends_list() -> Result<Vec<HashMap<String, String>>, Box<dyn Error>
|
|||||||
|
|
||||||
let self_id = sbot_client.whoami().await?;
|
let self_id = sbot_client.whoami().await?;
|
||||||
|
|
||||||
let friends = sbot_client.friends(&self_id).await?;
|
let friends = sbot_client.get_friends(&self_id).await?;
|
||||||
|
|
||||||
if !friends.is_empty() {
|
if !friends.is_empty() {
|
||||||
for peer in friends.iter() {
|
for peer in friends.iter() {
|
||||||
|
2
tilde-client/.gitignore
vendored
Normal file
2
tilde-client/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/target
|
||||||
|
Cargo.lock
|
12
tilde-client/Cargo.toml
Normal file
12
tilde-client/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "tilde-client"
|
||||||
|
version = "0.0.1"
|
||||||
|
authors = ["Max Fowler <max@mfowler.info>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
async-std = "1.10"
|
||||||
|
anyhow = "1.0.86"
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
serde_json = "1.0"
|
||||||
|
serde_yaml = "0.8"
|
37
tilde-client/README.md
Normal file
37
tilde-client/README.md
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# peach-lib
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
JSON-RPC client library for the PeachCloud ecosystem.
|
||||||
|
|
||||||
|
`peach-lib` offers the ability to programmatically interact with the `peach-network`, `peach-oled` and `peach-stats` microservices.
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
The `peach-lib` crate bundles JSON-RPC client code for making requests to the three PeachCloud microservices which expose JSON-RPC servers (`peach-network`, `peach-oled` and `peach-menu`). The full list of available RPC APIs can be found in the READMEs of the respective microservices ([peach-network](https://github.com/peachcloud/peach-network), [peach-oled](https://github.com/peachcloud/peach-oled), [peach-menu](https://github.com/peachcloud/peach-menu)), or in the [developer documentation for PeachCloud](http://docs.peachcloud.org/software/microservices/index.html).
|
||||||
|
|
||||||
|
The library also includes a custom error type, `PeachError`, which bundles the underlying error types into three variants: `JsonRpcHttp`, `JsonRpcCore` and `Serde`. When used as the returned error type in a `Result` function response, this allows convenient use of the `?` operator (as illustrated in the example usage code below).
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Define the dependency in your `Cargo.toml` file:
|
||||||
|
|
||||||
|
`peach-lib = { git = "https://github.com/peachcloud/peach-lib", branch = "main" }`
|
||||||
|
|
||||||
|
Import the required client from the library:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
use peach_lib::network_client;
|
||||||
|
```
|
||||||
|
|
||||||
|
Call one of the exposed methods:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
network_client::ip("wlan0")?;
|
||||||
|
```
|
||||||
|
|
||||||
|
Further example usage can be found in the [`peach-menu`](https://github.com/peachcloud/peach-menu) code (see `src/states.rs`).
|
||||||
|
|
||||||
|
## Licensing
|
||||||
|
|
||||||
|
AGPL-3.0
|
18
tilde-client/src/error.rs
Normal file
18
tilde-client/src/error.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
|
use std::error::Error;
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
|
/// all tilde client errors
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct TildeError {
|
||||||
|
pub(crate) message: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for TildeError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "{}", self.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Error for TildeError {}
|
73
tilde-client/src/lib.rs
Normal file
73
tilde-client/src/lib.rs
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
// methods for interacting with tilde sbot
|
||||||
|
|
||||||
|
use crate::error::TildeError;
|
||||||
|
|
||||||
|
use serde_json::Value;
|
||||||
|
use std::process::{Command, exit};
|
||||||
|
|
||||||
|
mod error;
|
||||||
|
|
||||||
|
pub struct TildeClient {
|
||||||
|
name: String,
|
||||||
|
port: String
|
||||||
|
}
|
||||||
|
pub fn init_sbot() {
|
||||||
|
println!("++ init sbot!");
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_sbot_client() -> TildeClient {
|
||||||
|
TildeClient {
|
||||||
|
name: "name".to_string(),
|
||||||
|
port: "8009".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl TildeClient {
|
||||||
|
|
||||||
|
pub fn run_tilde_command(&self, command: &str) -> Result<String, TildeError> {
|
||||||
|
let output = Command::new("out/release/tildefriends.standalone")
|
||||||
|
.arg(command)
|
||||||
|
.output().map_err(|e| TildeError {
|
||||||
|
message: format!("Command execution failed: {}", e),
|
||||||
|
})?;
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
return Err(TildeError { message: format!("Command failed with status: {}", output.status) })
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = String::from_utf8_lossy(&output.stdout).to_string();
|
||||||
|
println!("Command output: {}", result);
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
pub async fn latest_description(&self, key: &str) -> Result<String, TildeError> {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn whoami(&self) -> Result<String, TildeError> {
|
||||||
|
self.run_tilde_command("get_identity")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn is_following(&self, from_id: &str, to_id: &str) -> Result<bool, TildeError> {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn create_block(&self, key: &str) -> Result<bool, TildeError> {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
pub async fn get_blocks(&self, key: &str) -> Result<Vec<String>, TildeError> {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_follows(&self, key: &str) -> Result<Vec<String>, TildeError> {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_friends(&self, key: &str) -> Result<Vec<String>, TildeError> {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn publish(&self, post: Value) -> Result<Vec<String>, TildeError> {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user