working on tild integration

This commit is contained in:
notplants 2025-02-19 13:39:10 -05:00
parent b4e2dd2683
commit 6bbfb454de
12 changed files with 151 additions and 25 deletions

26
Cargo.lock generated
View File

@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
version = 4
[[package]]
name = "addr2line"
@ -2483,7 +2483,7 @@ dependencies = [
"serde_json",
"serde_yaml",
"sha3",
"solar_client",
"tilde-client",
"toml",
]
@ -2575,7 +2575,6 @@ dependencies = [
"peach-stats",
"reqwest",
"rouille",
"solar_client",
"temporary",
"vnstat_parse",
"xdg",
@ -3445,16 +3444,6 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "solar_client"
version = "0.1.0"
dependencies = [
"anyhow",
"jsonrpc_client",
"reqwest",
"serde_json",
]
[[package]]
name = "spidev"
version = "0.3.0"
@ -3684,6 +3673,17 @@ dependencies = [
"num_cpus",
]
[[package]]
name = "tilde-client"
version = "0.0.1"
dependencies = [
"anyhow",
"async-std",
"serde 1.0.209",
"serde_json",
"serde_yaml",
]
[[package]]
name = "time"
version = "0.1.44"

View File

@ -9,6 +9,7 @@ members = [
"peach-monitor",
"peach-stats",
"peach-jsonrpc-server",
"peach-dyndns-updater"
"peach-dyndns-updater",
"tilde-client"
]

View File

@ -10,7 +10,7 @@ chrono = "0.4"
dirs = "4.0"
fslock="0.1"
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-http = "0.5"
jsonrpc-core = "8.0"

View File

@ -13,3 +13,4 @@ pub use jsonrpc_client_core;
pub use jsonrpc_core;
pub use serde_json;
pub use serde_yaml;
pub use tilde_client;

View File

@ -2,7 +2,7 @@
use std::{fs, fs::File, io, io::Write, path::PathBuf, process::Command, str};
use std::os::linux::raw::ino_t;
use solar_client::{Client, SolarClient};
use tilde_client::{TildeClient, get_sbot_client};
use log::debug;
use crate::config_manager;
@ -265,7 +265,7 @@ impl SbotConfig {
}
/// 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
let sbot_config = SbotConfig::read().ok();
@ -277,6 +277,6 @@ pub async fn init_sbot() -> Result<Client, PeachError> {
);
// TODO: read this from config
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)
}

View File

@ -39,7 +39,6 @@ chrono = "0.4"
dirs = "4.0"
env_logger = "0.8"
futures = "0.3"
solar_client = { path = "../../solarpub/solar_client" }
lazy_static = "1.4"
log = "0.4"
maud = "0.23"

View File

@ -16,10 +16,10 @@ use peach_lib::config_manager;
use peach_lib::sbot::SbotConfig;
use peach_lib::sbot::init_sbot;
use peach_lib::ssb_messages::SsbMessageKVT;
use solar_client::{Client, SolarClient};
use rouille::input::post::BufferedFile;
use temporary::Directory;
use peach_lib::serde_json::json;
use peach_lib::tilde_client::TildeClient;
use crate::{error::PeachWebError, utils::sbot};
// SBOT HELPER FUNCTIONS
@ -64,7 +64,7 @@ pub fn restart_sbot_process() -> (String, String) {
}
/// 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");
// initialise sbot connection with ip:port and shscap from config file
let key_path = format!(
@ -386,7 +386,7 @@ pub fn block_peer(public_key: &str) -> Result<String, String> {
.map_err(|e| e.to_string())?;
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()),
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 blocks = sbot_client.blocks(&self_id).await?;
let blocks = sbot_client.get_blocks(&self_id).await?;
if !blocks.is_empty() {
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 follows = sbot_client.follows(&self_id).await?;
let follows = sbot_client.get_follows(&self_id).await?;
if !follows.is_empty() {
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 friends = sbot_client.friends(&self_id).await?;
let friends = sbot_client.get_friends(&self_id).await?;
if !friends.is_empty() {
for peer in friends.iter() {

2
tilde-client/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
Cargo.lock

12
tilde-client/Cargo.toml Normal file
View 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
View File

@ -0,0 +1,37 @@
# peach-lib
![Generic badge](https://img.shields.io/badge/version-1.2.9-<COLOR>.svg)
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
View File

@ -0,0 +1,18 @@
#![warn(missing_docs)]
use std::error::Error;
use std::fmt;
/// all tilde client errors
#[derive(Debug)]
pub struct TildeError {
message: String,
}
impl fmt::Display for TildeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.message)
}
}
impl Error for TildeError {}

56
tilde-client/src/lib.rs Normal file
View File

@ -0,0 +1,56 @@
// methods for interacting with tilde sbot
use crate::error::TildeError;
use serde_json::Value;
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 async fn latest_description(&self, key: &str) -> Result<String, TildeError> {
todo!();
}
pub async fn whoami(&self) -> Result<String, TildeError> {
todo!();
}
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!();
}
}